Exemplo n.º 1
0
    def on_patch(self, req, resp, login_id, session):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id,session) == False):
                resp.status = falcon.HTTP_401
                message = {"status": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(message)
                resp.body = (result_json)
                return
        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)
        except Exception as err:
            raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)

        try:
            raw_json = req.stream.read(req.content_length or 0).decode('utf-8')
            result_dictionary_json = json.loads(raw_json, object_pairs_hook=OrderedDict, encoding='utf-8')
            order_id = [v for v in result_dictionary_json.values()]
            row = Tools.getOrderStatusAndButtonCode(order_id[0])
 
            if row:
                order_status=list(row)
                if((order_status[0] == "CARGOSENT") or (order_status[0] == "CARGOPICKUP")):
                    order_status_code = "ORDERCONFIRMED"
                    actual_button_code = order_status[1]
                    # Here 8 deducted because cargo sent button code is 8, which is the fourth position of the binary number
                    # thats why the value will be 2 to power of 3 which is 8
                    current_button_code = actual_button_code - 8
                    Tools.ChangeBookingStatus(order_id[0],order_status_code,current_button_code)
                    resp.status = falcon.HTTP_200
                    message = {"status": "Credit block of this order has been approved"}
                    result_json = json.dumps(message)
                    resp.body = result_json
                else:
                    resp.status = falcon.HTTP_202
                    message = {"status": "You need to confirm your order first to block your credit for approval"}
                    result_json = json.dumps(message)
                    resp.body = result_json
            else:
                resp.status = falcon.HTTP_202
                message = {"status": "Something happend wrong. Please login and try again"}
                result_json = json.dumps(message)
                resp.body = (result_json)
        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)
        except Exception as err:
            raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)
Exemplo n.º 2
0
    def on_patch(self, req, resp, login_id, session):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) == False):
                resp.status = falcon.HTTP_401
                message = {
                    "status": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(message)
                resp.body = result_json
                return
        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)
        except Exception as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)

        try:
            raw_json = req.stream.read(req.content_length or 0).decode('utf-8')
            result_dictionary_json = json.loads(raw_json,
                                                object_pairs_hook=OrderedDict,
                                                encoding='utf-8')
            list_values = [v for v in result_dictionary_json.values()]
            order_id = list_values[0]
            old_status = list_values[1]
            old_button_code = list_values[2]
            desired_status = list_values[3]

            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            cursor.execute("select s.official_email\
                            from ship_orders o\
                            join ship_quotations q on o.quotation_id = q.quotation_id\
                            join logistic_providers s on q.supplier_login_id = s.login_id\
                            where o.order_id = '" + order_id + "'")
            row = cursor.fetchone()
            supplier_email = row['official_email']
            cursor.execute("select c.official_email,o.payment_id\
                            from ship_orders o\
                            join ship_quotations q on o.quotation_id = q.quotation_id\
                            join customers c  on o.login_id = c.login_id\
                            where o.order_id = '" + order_id + "'")
            row = cursor.fetchone()
            customer_email = row['official_email']
            paymentID = row['payment_id']
            print(old_status)
            print(desired_status)

            if (desired_status == 'CARGOSENT'):
                print("inside cargo")
                book_status_dict = Tools.CargoStatus(desired_status,
                                                     old_button_code)
                current_booking_status = book_status_dict[
                    'current_order_status']
                current_payment_status = book_status_dict['payment_status']
                button_code_list = book_status_dict['future_button_code']
                print("before payment execute")
                cursor.execute(
                    "select payment_status_code from ship_orders where order_id = '"
                    + order_id + "'")
                row = cursor.fetchone()
                if (old_status in current_booking_status):
                    index_code = current_booking_status.index(old_status)
                    print(current_payment_status)
                    if (row['payment_status_code'] in current_payment_status):
                        print(current_payment_status)
                        print("Before Tools")
                        Tools.ChangeBookingStatus(order_id, desired_status,
                                                  button_code_list[index_code],
                                                  cursor, database_connection)
                        print("After tools")
                        resp.status = falcon.HTTP_200
                        message = {
                            "Message": "Status is changed successfully."
                        }
                        result_json = json.dumps(message)
                        resp.body = result_json
                        EmailTools.CargoSendingAndCustomClearEmailNotify(
                            supplier_email, 7)

                    else:
                        print("else")
                        resp.status = falcon.HTTP_404
                        message = {"Message": "Creditblocked is not approved."}
                        result_json = json.dumps(message)
                        resp.body = result_json
                else:
                    resp.status = falcon.HTTP_202
                    resp.body = ("202")

            elif (desired_status == 'CARGOREADYFORPICKUP'):
                book_status_dict = Tools.CargoStatus(desired_status,
                                                     old_button_code)
                current_booking_status = book_status_dict[
                    'current_order_status']
                current_payment_status = book_status_dict['payment_status']
                button_code_list = book_status_dict['future_button_code']
                cursor.execute(
                    "select payment_status_code from ship_orders where order_id = '"
                    + order_id + "'")
                row = cursor.fetchone()

                if (old_status in current_booking_status):
                    index_code = current_booking_status.index(old_status)
                    print(current_payment_status)
                    if (row['payment_status_code'] in current_payment_status):
                        print(current_payment_status)
                        print("Before Tools")
                        Tools.ChangeBookingStatus(order_id, desired_status,
                                                  button_code_list[index_code],
                                                  cursor, database_connection)
                        print("After tools")
                        resp.status = falcon.HTTP_200
                        message = {
                            "Message": "Status is changed successfully."
                        }
                        result_json = json.dumps(message)
                        resp.body = result_json
                    else:
                        print("else")
                        resp.status = falcon.HTTP_404
                        message = {"Message": "Creditblocked is not approved."}
                        result_json = json.dumps(message)
                        resp.body = result_json
                else:
                    resp.status = falcon.HTTP_202
                    resp.body = ("202")

            elif (desired_status == 'CARGOSHIPPED'):
                book_status_dict = Tools.CargoStatus(desired_status,
                                                     old_button_code)
                current_booking_status = book_status_dict[
                    'current_order_status']
                current_payment_status = book_status_dict['payment_status']
                button_code_list = book_status_dict['future_button_code']
                cursor.execute(
                    "select payment_status_code from ship_orders where order_id = '"
                    + order_id + "'")
                row = cursor.fetchone()
                row1 = row['payment_status_code']
                print(row1)
                if (old_status in current_booking_status):
                    index_code = current_booking_status.index(old_status)
                    print(current_payment_status)
                    if (row['payment_status_code'] in current_payment_status):
                        print(current_payment_status)
                        print("Before Tools")
                        Tools.ChangeBookingStatus(order_id, desired_status,
                                                  button_code_list[index_code],
                                                  cursor, database_connection)
                        print("After tools")
                        resp.status = falcon.HTTP_200
                        message = {
                            "Message": "Status is changed successfully."
                        }
                        result_json = json.dumps(message)
                        resp.body = result_json
                    else:
                        print("else")
                        resp.status = falcon.HTTP_404
                        message = {
                            "Message": "CreditDeducted is not approved."
                        }
                        result_json = json.dumps(message)
                        resp.body = result_json
                else:
                    resp.status = falcon.HTTP_202
                    resp.body = ("202")

            elif (desired_status == 'LOCKEDIN'):
                print(desired_status)
                # hardcoded_email = "*****@*****.**"
                book_status_dict = Tools.CargoStatus(desired_status,
                                                     old_button_code)
                book_status_list = book_status_dict['current_order_status']
                print(book_status_list)
                button_code_list = book_status_dict['future_button_code']
                action_by = book_status_dict['action_by']
                print("before if 1")
                if (old_status in book_status_list):
                    index_code = book_status_list.index(old_status)
                    print("before tools changebookingstatus")
                    Tools.ChangeBookingStatus(order_id, desired_status,
                                              button_code_list[index_code],
                                              cursor, database_connection)
                    EmailTools.FinalShipmentConfirmationEmailNotify(
                        order_id, email)
                    print("After emailtools")
                    resp.status = falcon.HTTP_200
                    resp.body = ("200")
                elif desired_status == "ORDERDROPPED":
                    Tools.ChangeBookingStatus(order_id, desired_status,
                                              '16777215', cursor,
                                              database_connection)
                    resp.status = falcon.HTTP_200
                    resp.body = ("200")
                else:
                    resp.status = falcon.HTTP_202
                    resp.body = ("202")

            else:
                book_status_dict = Tools.CargoStatus(desired_status,
                                                     old_button_code)
                book_status_list = book_status_dict['current_order_status']
                print(book_status_list)
                button_code_list = book_status_dict['future_button_code']
                action_by = book_status_dict['action_by']
                if (old_status in book_status_list):
                    index_code = book_status_list.index(old_status)
                    Tools.ChangeBookingStatus(order_id, desired_status,
                                              button_code_list[index_code],
                                              cursor, database_connection)
                    resp.status = falcon.HTTP_200
                    resp.body = ("200")
                    if (desired_status == 'ORDERPLACED'):
                        EmailTools.UponOrderEmailNotify(
                            customer_email, paymentID)
                elif desired_status == "ORDERDROPPED":
                    Tools.ChangeBookingStatus(order_id, desired_status,
                                              '16777215', cursor,
                                              database_connection)
                    resp.status = falcon.HTTP_200
                    resp.body = ("200")
                else:
                    resp.status = falcon.HTTP_202
                    resp.body = ("202")

        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)
        except Exception as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)
        finally:
            cursor.close()
            database_connection.close()
Exemplo n.º 3
0
    def on_patch(self, req, resp, login_id, session):
        # Authenticate login id and session availability.
        # try:
        #     if (MemcacheFunctions.IsSessionValid(login_id,session) == False):
        #         resp.status = falcon.HTTP_400
        #         message = {"status": "Invalid Login Credentials or Session is Expired"}
        #         result_json = json.dumps(message)
        #         resp.body = (result_json)
        #         return
        # except ValueError as err:
        #     raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)
        # except Exception as err:
        #     raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)

        try:
            # Get DB connection
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            raw_json = req.stream.read(req.content_length or 0).decode('utf-8')
            result_dictionary_json = json.loads(raw_json,
                                                object_pairs_hook=OrderedDict,
                                                encoding='utf-8')
            order_id = [v for v in result_dictionary_json.values()]
            execute_price_leverage = False
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            row = Tools.getOrderStatusAndButtonCode(order_id[0], cursor)

            if row:
                order_status = row
                if (order_status['cargo_status_code'] == "ORDERBOOKED"
                        or order_status['cargo_status_code'] == "ORDERPLACED"):
                    order_status_code = "ORDERCANCELLED"
                    # Here setting button value 0 after cancellation of any order.
                    # that means we don't want to display any button of this order

                    database_connection.begin()
                    cursor.execute(
                        "SELECT o.cbm,q.total_req_cbm_per_shipment,q.total_people_per_shipment,c.total_cbm, c.remaining_cbm,c.halal_status,c.number_people_sharing,c.percentage_full,c.hs_set_id, \
                                    o.quotation_id,o.container_id,o.weight,c.remaining_weight \
                                    FROM ship_orders o \
                                    LEFT JOIN ship_quotations q ON o.quotation_id = q.quotation_id \
                                    LEFT JOIN ship_containers c ON o.container_id = c.container_id \
                                    where o.order_id = '" + str(order_id[0]) +
                        "'")
                    data = cursor.fetchone()
                    requested_cbm = int(data['cbm'])
                    total_req_cbm_quotation = int(
                        data['total_req_cbm_per_shipment'])
                    total_people_per_shipment = int(
                        data['total_people_per_shipment'])
                    cont_remaining_cbm = int(data['remaining_cbm'])
                    cont_total_cbm = int(data['total_cbm'])
                    cont_number_people_sharing = int(
                        data['number_people_sharing'])
                    cont_hs_set_id = data['hs_set_id']
                    cont_halal_stat = data['halal_status']
                    req_weight = int(data['weight'])
                    remaning_weight = int(data['remaining_weight'])

                    if cont_number_people_sharing >= 2:
                        total_people_per_shipment = total_people_per_shipment - 1
                        total_req_cbm_quotation = total_req_cbm_quotation - requested_cbm
                        cont_remaining_cbm = cont_remaining_cbm + requested_cbm
                        percentage_full = 100 - (
                            (cont_remaining_cbm / cont_total_cbm) * 100)
                        cont_number_people_sharing = cont_number_people_sharing - 1
                        weight = remaning_weight + req_weight
                        sql_quotation = (
                            "update ship_quotations set total_people_per_shipment=%s,total_req_cbm_per_shipment=%s where quotation_id = %s"
                        )
                        sql_container = (
                            "update ship_containers set remaining_cbm = %s,number_people_sharing = %s, percentage_full = %s, remaining_weight = %s where container_id = %s"
                        )
                        args_quotation = (total_people_per_shipment,
                                          total_req_cbm_quotation,
                                          data['quotation_id'])
                        args_container = (cont_remaining_cbm,
                                          cont_number_people_sharing,
                                          percentage_full, weight,
                                          data['container_id'])
                        execute_price_leverage = True
                    elif cont_number_people_sharing == 1:
                        print("entering elif")
                        total_people_per_shipment = total_people_per_shipment - 1
                        total_req_cbm_quotation = total_req_cbm_quotation - requested_cbm
                        cont_remaining_cbm = cont_remaining_cbm + requested_cbm
                        percentage_full = 100 - (
                            (cont_remaining_cbm / cont_total_cbm) * 100)
                        cont_number_people_sharing = cont_number_people_sharing - 1
                        weight = remaning_weight + req_weight
                        cont_hs_set_id = 'HSX'
                        cont_halal_stat = 'U'
                        container_new_id = Tools.GetContainerID(
                            "DUMMY", 1, cursor, database_connection,
                            data['container_id'], cont_hs_set_id,
                            cont_halal_stat)
                        sql_quotation = (
                            "update ship_quotations set total_people_per_shipment = %s,total_req_cbm_per_shipment=%s where quotation_id = %s"
                        )
                        sql_container = (
                            "update ship_containers set remaining_cbm = %s,number_people_sharing = %s, percentage_full = %s,hs_set_id = %s,halal_status = %s,container_id=%s, remaining_weight = %s where container_id = %s"
                        )
                        args_quotation = (total_people_per_shipment,
                                          total_req_cbm_quotation,
                                          data['quotation_id'])
                        args_container = (cont_remaining_cbm,
                                          cont_number_people_sharing,
                                          percentage_full, cont_hs_set_id,
                                          cont_halal_stat, container_new_id,
                                          weight, data['container_id'])
                        execute_price_leverage = False
                    cursor.execute(sql_quotation, args_quotation)
                    cursor.execute(sql_container, args_container)
                    if execute_price_leverage:
                        print("Leveraging")
                        PriveLeveraging(data['quotation_id'], cursor)
                    database_connection.commit()
                    current_button_code = 0
                    Tools.ChangeBookingStatus(order_id[0], order_status_code,
                                              current_button_code, cursor,
                                              database_connection)
                    resp.status = falcon.HTTP_200
                    message = {
                        "status":
                        "Booking Status has been cancelled successfully"
                    }
                    result_json = json.dumps(message)
                    resp.body = (result_json)
                else:
                    resp.status = falcon.HTTP_200
                    message = {
                        "status":
                        "You are not allowed to cancel the booking status of this booking"
                    }
                    result_json = json.dumps(message)
                    resp.body = (result_json)
            else:
                resp.status = falcon.HTTP_400
                message = {"status": "Please login and try again"}
                result_json = json.dumps(message)
                resp.body = (result_json)

        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)
        except Exception as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)