Ejemplo n.º 1
0
    def get_byid(self, order_id):
        try:
            # Setup connection to the DB
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()
            order = None
            args = [order_id]

            cadao = CustomerAddressDao()
            pdao = PaymentInfoDao()
            # Calls the stored procedure
            cursor.callproc('getRetailOrderByOrderID', args)

            # This loop iterates through the resultsets
            for result in cursor.stored_results():
                # This loop iterates through the rows in each resultset
                for x in result.fetchall():
                    order = RetailOrder()
                    order.order_id = x[0]
                    order.date_ordered = x[1]
                    order.discount = x[2]
                    order.total_price = x[3]
                    order.status = x[4]

                    u = User()
                    u.id = x[5]
                    u.first_name = x[6]
                    u.last_name = x[7]
                    order.customer = u

                    p = PaymentInfo()
                    p.card_id = x[8]
                    p.last_four = x[9]
                    p.card_issuer = x[10]
                    order.card = p

                    a = CustomerAddress()
                    a.address_id = x[11]
                    a.street = x[12]
                    a.city = x[13]
                    a.state_code = x[14]
                    a.zip_code = x[15]
                    order.shipping_address = a

            # Close the connection to the DB
            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)

        return order
Ejemplo n.º 2
0
    def getJanuaryOrders(self):
        orders = []
        try:
            # Setup connection to the DB
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()

            # Calls the stored procedure
            cursor.callproc('getJanuaryOrders')
            udao = UserDao()
            cadao = CustomerAddressDao()
            pdao = PaymentInfoDao()
            # This loop iterates through the resultsets
            for result in cursor.stored_results():
                # This loop iterates through the rows in each resultset
                for x in result.fetchall():
                    order = RetailOrder()
                    order.order_id = x[0]
                    order.date_ordered = x[1]
                    order.total_price = x[2]
                    order.discount = x[3]
                    order.customer = x[4]
                    orders.append(order)

            # Close the connection to the DB
            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)

        return orders
Ejemplo n.º 3
0
    def getOrdersByMnthYr(self, month, year):
        orders = []
        try:
            # Setup connection to the DB
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()
            args = (month, year)

            # Calls the stored procedure
            cursor.callproc('getOrdersByMnthYr', args)
            # This loop iterates through the resultsets
            for result in cursor.stored_results():
                # This loop iterates through the rows in each resultset
                for x in result.fetchall():
                    order = RetailOrder()
                    order.order_id = x[0]
                    order.date_ordered = x[1]
                    order.total_price = x[2]
                    order.discount = x[3]
                    order.customer = x[4]
                    orders.append(order)

            # Close the connection to the DB
            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)

        return orders
Ejemplo n.º 4
0
    def post(self, request):
        retail_order = RetailOrder()
        context = {}

        if 'place-order' in request.POST:
            try:
                # Get data from form
                retail_order.customer.customer_id = request.session['user_id']
                retail_order.shipping_address.address_id = request.POST[
                    'shipping_choice']
                retail_order.card.card_id = request.POST['payment_choice']
                retail_order.discount = request.session['discount']

                # Submit order information to server
                order_id = self.retail_order_dao.create(retail_order)

                context['notification'] = "Order made!"
            except:
                print("Error occured")
                context['notification'] = "Error!"

        return redirect(reverse('invoice', kwargs={'order_id': order_id}))
Ejemplo n.º 5
0
    def getOrdersByShippingAddressID(self, addresss_id):
        orders = []
        try:
            # Setup connection to the DB
            db_config = read_db_config()
            conn = MySQLConnection(**db_config)
            cursor = conn.cursor()

            args = [addresss_id]
            # Calls the stored procedure
            cursor.callproc('getOrdersByShippingAddressID', args)
            udao = UserDao()
            cadao = CustomerAddressDao()
            pdao = PaymentInfoDao()
            # This loop iterates through the resultsets
            for result in cursor.stored_results():
                # This loop iterates through the rows in each resultset
                for x in result.fetchall():
                    order = RetailOrder()
                    order.order_id = x[0]
                    order.date_ordered = x[1]
                    order.total_price = x[2]
                    order.discount = x[3]
                    order.customer = udao.get_byid(x[4])
                    order.shipping_address = cadao.get_byid(x[5])
                    order.card = pdao.get_byid(x[6])
                    order.status = x[7]
                    orders.append(order)
            # Close the connection to the DB
            cursor.close()
            conn.close()
        except Error as error:
            print(error)
        except Exception as e:
            print(e)

        return orders
Ejemplo n.º 6
0
 def __init__(self):
     self.order_id = RetailOrder()
     self.book = Book()
     self.quantity = None
     self.price = None
     self.discount = None