diff --git a/app/classes/customer.py b/app/classes/customer.py index d591634..2adc7be 100755 --- a/app/classes/customer.py +++ b/app/classes/customer.py @@ -84,3 +84,21 @@ class Customer_Payment_Credit_schema(ma.SQLAlchemyAutoSchema): +class Customer_Description(db.Model): + __tablename__ = 'customer_description' + __bind_key__ = 'eamco' + __table_args__ = {"schema": "public"} + + id = db.Column(db.Integer, + primary_key=True, + autoincrement=True, + unique=False) + customer_id = db.Column(db.INTEGER) + account_number = db.Column(db.VARCHAR(25)) + company_id = db.Column(db.INTEGER) + fill_location = db.Column(db.INTEGER) + description = db.Column(db.VARCHAR(2000)) + +class Customer_Description_schema(ma.SQLAlchemyAutoSchema): + class Meta: + model = Customer_Description diff --git a/app/customer/views.py b/app/customer/views.py index f9379a8..c022774 100755 --- a/app/customer/views.py +++ b/app/customer/views.py @@ -6,7 +6,9 @@ from datetime import datetime from app.classes.cards import Card_Card from app.classes.customer import \ Customer_Customer, \ - Customer_Customer_schema + Customer_Customer_schema,\ + Customer_Description, \ + Customer_Description_schema from app.classes.admin import Admin_Company from app.classes.auto import Auto_Delivery import string @@ -84,6 +86,7 @@ def create_customer(): customer_phone_number = request.json["customer_phone_number"] customer_address = request.json["customer_address"] customer_apt = request.json["customer_apt"] + customer_description_msg = request.json["customer_description"] if response_customer_automatic is True: auto_customer = 1 @@ -109,12 +112,20 @@ def create_customer(): customer_address=customer_address, customer_apt=customer_apt, company_id=1, - ) - db.session.add(new_customer) db.session.flush() + new_description = Customer_Description( + customer_id = new_customer.id, + account_number = made_account_number, + description = customer_description_msg, + fill_location=None, + company_id=1, + ) + db.session.add(new_description) + + new_auto = Auto_Delivery( customer_id = new_customer.id, account_number = made_account_number, @@ -154,8 +165,10 @@ def edit_customer(customer_id): .query(Customer_Customer) .filter(Customer_Customer.id == customer_id) .first()) - - + get_customer_description = (db.session + .query(Customer_Description) + .filter(Customer_Description.customer_id == customer_id) + .first()) response_customer_last_name = request.json["customer_last_name"] response_customer_first_name = request.json["customer_first_name"] response_customer_town = request.json["customer_town"] @@ -167,6 +180,12 @@ def edit_customer(customer_id): response_customer_address = request.json["customer_address"] response_customer_automatic = request.json["customer_automatic"] + response_customer_description = request.json["customer_description"] + + + + + if response_customer_automatic is True: get_auto = (db.session @@ -197,6 +216,10 @@ def edit_customer(customer_id): else: auto = 0 + if get_customer_description is not None: + get_customer_description.description = response_customer_description + + db.session.add(get_customer_description) get_customer.customer_address = response_customer_address @@ -290,6 +313,41 @@ def customer_automatic_status(customer_id): }), 200 +@customer.route("/description/", methods=["GET"]) +@login_required +def customer_description(customer_id): + """ + """ + get_customer = (db.session + .query(Customer_Customer) + .filter(Customer_Customer.id == customer_id) + .first()) + get_customer_description = (db.session + .query(Customer_Description) + .filter(Customer_Description.customer_id == customer_id) + .first()) + + + if get_customer_description is None: + new_description = Customer_Description( + customer_id = get_customer.id, + account_number = get_customer.account_number, + description = None, + fill_location=None, + company_id=1, + ) + db.session.add(new_description) + db.session.commit() + + + get_customer_description = (db.session + .query(Customer_Description) + .filter(Customer_Description.customer_id == customer_id) + .first()) + + customer_schema = Customer_Description_schema(many=False) + return jsonify(customer_schema.dump(get_customer_description)) + @customer.route("/automatic/assign/", methods=["GET"]) @login_required diff --git a/app/delivery/views.py b/app/delivery/views.py index de1a2b5..298bcdf 100755 --- a/app/delivery/views.py +++ b/app/delivery/views.py @@ -504,11 +504,32 @@ def create_a_delivery(user_id): dispatcher_notes_taken = request.json["dispatcher_notes_taken"] prime_info = request.json["prime"] same_day_info = request.json["same_day"] + delivery_driver_id = request.json["driver_employee_id"] + card_payment = request.json["credit"] cash_payment = request.json["cash"] + check_payment = request.json["check"] + other_payment = request.json["other"] + + # 0 = cash only + # 1 = credit only + # 2 = credit /cash + # 3 = check + # 4 = other + # 5 = unknown + if cash_payment is True: + delivery_payment_method = 0 + if card_payment is True: + delivery_payment_method = 1 + if card_payment is True and cash_payment is True: + delivery_payment_method = 2 + if check_payment is True: + delivery_payment_method = 3 + if other_payment is True: + delivery_payment_method = 4 + - delivery_driver_id = request.json["driver_employee_id"] get_driver = (db.session .query(Employee_Employee) @@ -537,20 +558,15 @@ def create_a_delivery(user_id): else: card_id_from_customer = None - # 0 = cash only - # 1 = credit only - # 2 = credit /cash - # 3 unknown - - if cash_payment is True and card_payment is False: - delivery_payment_method = 0 - elif card_payment is True and cash_payment is False: - delivery_payment_method = 1 - elif card_payment is True and cash_payment is True: - delivery_payment_method = 2 - else: - delivery_payment_method = 3 + + + + + + + + if customer_wants_fill is True: customer_fill_up = 1 diff --git a/app/delivery_data/views.py b/app/delivery_data/views.py index 6852e4b..5649ec8 100755 --- a/app/delivery_data/views.py +++ b/app/delivery_data/views.py @@ -20,7 +20,6 @@ def office_finalize_delivery(delivery_id): """ Finalizes a delivery from office """ - now = datetime.utcnow() get_delivery = db.session \ .query(Delivery_Delivery) \ @@ -36,6 +35,7 @@ def office_finalize_delivery(delivery_id): gallons_delivered = request.json["gallons_delivered"] card_payment = request.json["credit"] cash_payment = request.json["cash"] + if request.json["credit_card_id"]: card_payment_id = request.json["credit_card_id"] else: @@ -83,9 +83,15 @@ def office_finalize_delivery(delivery_id): get_delivery.delivery_status = 10 + + print(get_delivery.gallons_delivered) + print(get_delivery.payment_type) + print(get_delivery.delivery_status) + db.session.add(get_delivery) db.session.commit() + return jsonify({ "ok": True, 'delivery': { @@ -104,7 +110,6 @@ def driver_finalize_delivery(delivery_id): """ Finalizes a delivery from office """ - now = datetime.utcnow() get_delivery = (db.session @@ -214,9 +219,6 @@ def driver_finalize_delivery(delivery_id): else: get_delivery.delivery_status = 1 - print(get_stats.id) - print(get_stats.total_gallons_delivered) - print(get_stats.total_deliveries) db.session.add(get_stats) db.session.add(get_delivery)