def on_get(self, req, resp, login_id, session):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Error)
                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:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            list_of_booking_query = (
                "select distinct q.portName, q.country, q.vessel_id, q.vessel_no \
                                    from ship_logistic_providers_quotation_list_view as q\
                                    join logistic_providers on q.supplier_login_id = logistic_providers.login_id\
                                    where q.supplier_login_id ='" + login_id +
                "'")
            cursor.execute(list_of_booking_query)
            row = cursor.fetchall()
            if (cursor.rowcount > 0):
                list_values = list(row)
                result_json = json.dumps(list_values)
                resp.status = falcon.HTTP_200
                resp.body = result_json

            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Country is not found"}
                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 pymysql.IntegrityError 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()
Beispiel #2
0
    def on_get(self, req, resp, login_id, session):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Error)
                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:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            # Query to display all data from this tbl
            list_of_booking_query = ("select *\
                        from ship_admin_order_list_view")
            cursor.execute(list_of_booking_query)
            row = cursor.fetchall()
            if (cursor.rowcount > 0):
                list_values = row
                resp.status = falcon.HTTP_200
                # Convert dict data to string json
                result_json = json.dumps(list_values,
                                         sort_keys=True,
                                         default=str)
                resp.body = result_json

            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Order is not found"}
                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 pymysql.IntegrityError 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()
 def on_get(self, req, resp, login_id, session,quotation_id):
     try:
         if (MemcacheFunctions.IsSessionValid(login_id,session) is False):
             resp.status = falcon.HTTP_401
             Err = {"Reason": "Invalid Login Credentials or Session is Expired"}
             result_json = json.dumps(Err)
             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:
         # Connecting the database
         database_connection = get_db_connection()
         cursor = database_connection.cursor()
         cursor.execute("select amount,charges_description from ship_quotation_sea_freight_charges where quotation_id ='"+quotation_id+"'")
         part_a = cursor.fetchall()
         part_a_block = dict()
         part_a_block['part_a'] = part_a
         resp.status = falcon.HTTP_200
         result_json = json.dumps(part_a_block)
         resp.body = result_json
     except ValueError as err:
         raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)
     except pymysql.IntegrityError 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()
Beispiel #4
0
    def on_patch(self, req, resp, login_id, session):
        #Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Error)
                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, 'Error', err.args)
            
        
        try :
            # Reading Json
            raw_json = req.stream.read(req.content_length or 0).decode('utf-8')
            resultdict_json = json.loads(raw_json, object_pairs_hook=OrderedDict, encoding='utf-8')
            # Json value
            quotation_id = resultdict_json['quotation_id']
            old_status = resultdict_json['current_quotation_status']
            desired_status = resultdict_json['quotation_status']
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            # Check the quotation status
            cursor.execute("select q.quotation_status, l.official_email\
                            from ship_quotations q\
                            join logistic_providers l on q.supplier_login_id = l.login_id\
                            where q.quotation_id = '"+quotation_id+"'")
            row = cursor.fetchone()
            if (cursor.rowcount > 0):
                book_status_dict = Tools.QuotationStatus(desired_status,old_status)
                print(book_status_dict)
                book_status_list = book_status_dict['current_quotation_status']
                if(old_status in book_status_list):
                    index_code = book_status_list.index(old_status)
                    Tools.ChangeQuotationStatus(quotation_id, desired_status,cursor,database_connection)
                    resp.status = falcon.HTTP_200
                    resp.body = ("200")
                    if(desired_status == 'CLOSED'):
                        EmailTools.QTClosedEmailNotify(row['official_email'],quotation_id,10)
                else:
                    resp.status = falcon.HTTP_202
                    resp.body = ("202")
            else:
                resp.status = falcon.HTTP_204
                resp.body = ("204")
        

        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)
        except pymysql.IntegrityError 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()
    def on_get(self, req, resp, login_id, session):
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Err = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Err)
                resp.body = (result_json)
                return
        except Exception as ex:
            raise falcon.HTTPError(falcon.HTTP_400, 'Error', ex.message)

        try:
            # Get list of industry,business & country
            industry_list = IntugloApp.GlobalIndustryList
            business_list = IntugloApp.GlobalBusinessList
            country_list = IntugloApp.GlobalCountryList

            country_business_and_industry = {
                'businesses': business_list,
                'industries': industry_list,
                'countries': country_list
            }
            result_json = json.dumps(country_business_and_industry,
                                     sort_keys=True)
            resp.body = result_json
            resp.status = falcon.HTTP_200
        except Exception as ex:
            raise falcon.HTTPError(falcon.HTTP_400, 'Error', ex.message)
    def on_get(self, req, resp, login_id, session):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session)):
                resp.status = falcon.HTTP_401
                Err = {
                    "status": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Err)
                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)
        try:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            # Query to display custom agent data from this tbl w given custom_agent_login_id
            cursor.execute(
                "select custom_agent.agent_name,custom_agent.company_name,custom_agent.company_registration_no,custom_agent.mobile_no,\
                            custom_agent.address_line_one,custom_agent.address_line_two,custom_agent.official_email,custom_agent.website,\
                            custom_agent.office_phone,custom_agent.office_fax,custom_agent.association_club,custom_agent.nature_of_business,\
                            custom_agent.import_export_license,custom_agent.business_license,custom_agent.city,custom_agent.postal_code,custom_agent.state,\
                            custom_agent.country_code,custom_agent.business_id,custom_agent.industry_id,custom_agent.business_size,custom_agent.timezone, l.merchant_id \
                            from custom_agent as custom_agent\
                            join logins l on custom_agent.login_id = l.login_id\
                            where custom_agent.login_id = '" + login_id + "'")
            row = cursor.fetchall()
            if (cursor.rowcount > 0):
                list_values = list(row)
                resp.status = falcon.HTTP_200
                result_json = json.dumps(list_values, sort_keys=True)
                resp.body = result_json

            else:
                resp.status = falcon.HTTP_204
                message = {"message": "Custom agent details not found!"}
                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 pymysql.IntegrityError 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()
Beispiel #7
0
    def on_get(self, req, resp, login_id, session):
        # Authentication / Function call memcacheResource.py
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Err = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Err)
                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)

        # If Authentication = true runs below
        try:
            # Database Connection
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            list_of_hscode = (
                "select hs_code_id as ID,CONCAT(hs_code_header,'.',hs_code_sub) AS Code,hs_code_sub AS SUB,description as 'Desc',cast(gst_percentage AS CHAR) as GST from hs_code"
            )
            cursor.execute(list_of_hscode)
            row = cursor.fetchall()
            if (cursor.rowcount > 0):
                # Json response
                hs_code_detail_dictionary = row
                resp.status = falcon.HTTP_200
                result_json = json.dumps(hs_code_detail_dictionary,
                                         default=str,
                                         sort_keys=True)
                resp.body = (result_json)
            else:
                resp.status = falcon.HTTP_204
                message = {"message": "HSCode details not found"}
                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 pymysql.IntegrityError 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()
Beispiel #8
0
    def on_get(self, req, resp, login_id, session, route_id):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Error)
                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:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            route_list = (
                "select distinct vessel_id,vessel_name from ship_logistic_providers_quotation_list_view where route_id = '"
                + route_id + "'")
            cursor.execute(route_list)
            row = cursor.fetchall()
            if (cursor.rowcount > 0):
                list_values = row
                result_json = json.dumps(list_values,
                                         sort_keys=True,
                                         default=str)
                resp.status = falcon.HTTP_200
                resp.body = result_json

            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Vessel is not found"}
                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 pymysql.IntegrityError 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()
Beispiel #9
0
    def on_patch(self, req, resp, login_id, session):
        #Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_400
                Error = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Error)
                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, 'Error', err.args)

        try:
            # Database Connection
            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')
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            affected_row = list()
            for x in result_dictionary_json:
                affected_row.append(
                    cursor.execute("UPDATE ship_orders SET duties_and_tax = " +
                                   str(x['duties_and_tax']) +
                                   " WHERE order_id = '" + x['order_id'] +
                                   "'"))
            database_connection.commit()
            if 1 in affected_row:
                resp.status = falcon.HTTP_200
                Error = {"Reason": "Update success"}
                result_json = json.dumps(Error)
                resp.body = result_json
            else:
                resp.status = falcon.HTTP_200
                Error = {"Reason": "Update Aborted"}
                result_json = json.dumps(Error)
                resp.body = result_json
        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)
        except pymysql.IntegrityError 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()
    def on_post(self, req, resp, login_id, session, order_id):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) == False):
                resp.status = falcon.HTTP_401
                Err = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Err)
                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:
            # Reading JSON from Restlet
            raw_json = req.stream.read(req.content_length or 0).decode('utf-8')
            resultdict_json = json.loads(raw_json,
                                         object_pairs_hook=OrderedDict,
                                         encoding='utf-8')
            list_values = [
                result_value for result_value in resultdict_json.values()
            ]
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            args = (list_values[0], list_values[1], list_values[2], order_id)
            cursor.execute(
                "insert into ship_custom_documents(custom_documents_id,file_name,file_title,order_id) \
                            values(%s,%s,%s,%s)", args)
            database_connection.commit()
            # JSON Response
            resp.status = falcon.HTTP_200
            message = {'Status': 'The file is uploaded successfully'}
            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 mysql.connector.Error 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()
    def on_get(self, req, resp, login_id, session, quotation_id):
        try:
            # Authenticate login id and session availability.
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Error)
                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:
            # Database Connection
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            # quotation_path = {}
            # Getting Absolute Path Of Quotation's from DB
            # Tools.py - Contains GetQuotationFilePath() to extract Paths from config table
            # quotation_path = Tools.GetQuotationFilePath()
            # os.chdir(quotation_path['quotation_files'])
            # Changing Working Directory to Quotations Path
            # sys.path.append(quotation_path['quotation_files'])
            # Serving URL
            cursor.execute("select config_value from config where config_key = 's3-bucket-quotation' ")
            bucket = cursor.fetchone()
            BUCKET_NAME = bucket['config_value']
            cursor.execute("select config_value from config where config_key = 'serving-url-s3'")
            row = cursor.fetchone()
            # Getting File-Name 
            serve = row['config_value']
            cursor.execute("select file_name from ship_quotations where quotation_id = '"+quotation_id+"' ")
            row = cursor.fetchone()
            if(cursor.rowcount > 0):
                filename = row['file_name']
                # Joining ServeURL , API, and Filename
                # For API_PATH Declaration Please Refer IntugloAPP
                # http://localhost:8000/quotations*
                #        *SERVE_URL*    *API_PATH*
                result_json = os.path.join(*[serve,BUCKET_NAME,quotation_id,filename])
                resp.status = falcon.HTTP_200
                resp.body = result_json
            else:
                resp.status = falcon.HTTP_204
                resp.body = ("204")
        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)
        except pymysql.IntegrityError 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()
    def on_get(self, req, resp, login_id, session, vessel_id):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Error)
                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:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
           
            # SQL to display list of payment
            sql = ("select DATE_FORMAT(o.booking_date,'%d/%m/%Y') as booking_date,o.created_on,\
                    q.quotation_id, o.order_id , c.customer_name, o.closing_price_total, o.closing_price_gst,\
                    q.supplier_login_id,q.vessel_id\
                    from ship_orders o\
                    JOIN ship_quotations q ON o.quotation_id = q.quotation_id\
                    JOIN logistic_providers l ON q.supplier_login_id = l.login_id\
                    JOIN customers c ON o.login_id = c.login_id\
                    where q.supplier_login_id = '"+login_id+"' and q.vessel_id = '"+vessel_id+"' and o.cargo_status_code = 'LOCKEDIN'")
            cursor.execute(sql)
            row = cursor.fetchall()


            if(cursor.rowcount > 0):
                list_values = row
                result_json = json.dumps(list_values,default=str)
                resp.status = falcon.HTTP_200
                resp.body = result_json
                
            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Payment list is not found"}
                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 pymysql.IntegrityError 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()
    def on_get(self, req, resp, login_id, session, quotation_id):
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Err = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Err)
                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:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            cursor.execute(
                "select charges_description,amount,charges_location,unit_of_measure_id from ship_quotation_handling_charges where quotation_id ='"
                + quotation_id + "'")
            charges_blocks = cursor.fetchall()
            print(charges_blocks)
            quotation_charges_block = dict()
            quotation_charges_block['location_D'] = list()
            quotation_charges_block['location_A'] = list()
            for x in charges_blocks:
                if x['charges_location'] == 'D':
                    quotation_charges_block['location_D'].append(x)
                elif x['charges_location'] == 'A':
                    quotation_charges_block['location_A'].append(x)
            resp.status = falcon.HTTP_200
            result_json = json.dumps(quotation_charges_block)
            resp.body = result_json
        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)
        except pymysql.IntegrityError 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()
    def on_get(self, req, resp, login_id, session, merchant_id):
        #Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Error)
                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, 'Error', err.args)

        try:
            # Connecting DB
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            # Query to display data from this tbl w given merchantID parameter
            cursor.execute("SELECT verified_user AS Status\
                            FROM logins\
                            WHERE merchant_id ='" + merchant_id + "'")
            row = cursor.fetchone()
            if (cursor.rowcount > 0):
                UserDetails = row
                resp.status = falcon.HTTP_200
                result_json = json.dumps(UserDetails, sort_keys=True)
                resp.body = result_json

            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Status is not found"}
                result_json = json.dumps(message)
                resp.body = result_json
        except ValueError as err:
            raise resp.HTTPError(falcon.HTTP_400,
                                 traceback.print_exc(file=sys.stdout),
                                 err.args)
        except pymysql.IntegrityError as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)
        except Exception as err:
            raise resp.HTTPError(falcon.HTTP_400,
                                 traceback.print_exc(file=sys.stdout),
                                 err.args)
        finally:
            cursor.close()
            database_connection.close()
    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()]
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            if (len(order_id) is 1):
                cursor.execute(
                    "update ship_orders set order_status_code = 'ORDERDROPPED' where order_id = '"
                    + order_id[0] + "'")
                database_connection.commit()
                resp.status = falcon.HTTP_200
                resp.body = ("200")
            else:
                resp.status = falcon.HTTP_204
                resp.body = ("204")
        except ValueError as err:
            raise resp.HTTPError(falcon.HTTP_400,
                                 traceback.print_exc(file=sys.stdout),
                                 err.args)
        except pymysql.IntegrityError as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)
        except Exception as err:
            raise resp.HTTPError(falcon.HTTP_400,
                                 traceback.print_exc(file=sys.stdout),
                                 err.args)
        finally:
            cursor.close()
            database_connection.close()
Beispiel #16
0
    def on_patch(self, req, resp, login_id, session, order_id):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id,session) == False):
                resp.status = falcon.HTTP_401
                Err = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Err)
                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')
            # Get dict values from JSON passed parameter that contained multi keys
            list_values = [v for v in result_dictionary_json.values()]
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            # Query to update data from this tbl based on given JSON passed parameter
            query = ("update ship_orders set consignor_delivery_address='" + list_values[0] + "',four_digit_hs_code='" + list_values[1][:4] + "'," \
                    "cargo_description='"+list_values[2]+"',confirmation_date= CURRENT_TIMESTAMP(),"\
                    "consignor_merchandise_value='" + list_values[3] + "'"\
                    "where order_id ='"+order_id+"' and login_id ='"+login_id+"'")
            cursor.execute(query)
            database_connection.commit()
            if(cursor.rowcount > 0):
                resp.status = falcon.HTTP_200
                message = {"Update": "Booking order updated successfully"}
                result_json = json.dumps(message)
                resp.body = result_json
            else:
                resp.status = falcon.HTTP_204   
                message = {"Status": "Order is not found."}
                result_json = json.dumps(message)
                resp.body = result_json
            cursor.close()
            database_connection.close

        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)
        except pymysql.IntegrityError 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()
Beispiel #17
0
    def on_get(self, req, resp, login_id, session):
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Err = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Err)
                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:
            # user_type 1-Supplier 3-CustomAgent
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            cursor.execute(
                "select verified_user from logins where login_id ='" +
                login_id + "'")
            row = cursor.fetchone()
            if cursor.rowcount > 0:
                resp.status = falcon.HTTP_200
                result_json = json.dumps(row)
                resp.body = (result_json)
            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "User status is empty"}
                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 pymysql.IntegrityError 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()
    def on_patch(self, req, resp, login_id, session):
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Error)
                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 ex:
            raise falcon.HTTPError(falcon.HTTP_400, 'Error', ex.message)
        # if Authentication true the code below runs

        try:
            raw_json = req.stream.read(req.content_length or 0).decode('utf-8')
            result_dict_json = json.loads(raw_json,
                                          object_pairs_hook=OrderedDict,
                                          encoding='utf-8')
            list_values = [v for v in result_dict_json.values()]
            order_id = str(list_values[0])
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            cursor.execute("update ship_orders set cargo_status_code='" +
                           list_values[1] + "'\
                            where login_id = '" + login_id +
                           "' and order_id ='" + order_id + "' ")
            database_connection.commit()
            resp.status = falcon.HTTP_200
            message = {"Update": "Customer order status is updated"}
            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 mysql.connector.Error 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()
    def on_get(self, req, resp, login_id, session, order_id):
        #Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Error)
                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, 'Error', err.args)

        try:
            # Database Connection
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            cursor.execute("select custom_documents_id,file_name\
                           from ship_custom_documents\
                           where order_id='" + order_id + "'")
            row = cursor.fetchall()
            if (cursor.rowcount > 0):
                list_values = row
                result_json = json.dumps(list_values, sort_keys=True)
                resp.status = falcon.HTTP_200
                resp.body = result_json
            else:
                # JSON response
                resp.status = falcon.HTTP_204
                resp.body = ("204")
        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400,
                                   traceback.print_exc(file=sys.stdout),
                                   err.args)
        except mysql.connector.Error 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()
    def on_get(self, req, resp, login_id, session):
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Err = {
                    "Reason": "Invalid Login Credentials or Session is Expired"
                }
                result_json = json.dumps(Err)
                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 ex:
            raise falcon.HTTPError(falcon.HTTP_400, 'Error', ex.message)

        try:
            # Database connection
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            cursor.execute(
                "select module1,module2,module3,module4,module5,module6,module7,module8\
                            from modules where login_id = '" + login_id + "'")
            row = cursor.fetchall()
            if (cursor.rowcount > 0):
                list_values = row
                result_json = json.dumps(list_values, sort_keys=True)
                resp.status = falcon.HTTP_200
                resp.body = result_json
            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Module is not found"}
                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 pymysql.IntegrityError 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()
    def on_patch(self, req, resp, login_id, session, quotation_id):
        #Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Error)
                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 ex:
            raise falcon.HTTPError(falcon.HTTP_400, 'Error', ex.message)
            
        
        try :
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            # Check the quotation status
            cursor.execute("select quotation_status from ship_quotations where quotation_id = '"+quotation_id+"'")
            row = cursor.fetchone()
            if (cursor.rowcount > 0):
                quotation_list = row
                if (quotation_list['quotation_status']== "DRAFT"):
                    # Update quotation status
                    cursor.execute("update ship_quotations set quotation_status ='PENDINGAPPROVAL'\
                                     where quotation_id = '"+quotation_id+"'")
                    database_connection.commit()
                    resp.status = falcon.HTTP_200
                    message = {"Update": "Quotation ID status is updated to pending approval."}
                    result_json = json.dumps(message)
                    resp.body = result_json
                else:
                    resp.status = falcon.HTTP_200
                    Err = {"Reason": "It is not allowed to make a request for approval."}
                    result_json = json.dumps(Err)
                    resp.body = (result_json)


        except ValueError as err:
            raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)
        except pymysql.IntegrityError 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()
    def on_get(self, req, resp, login_id, session):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Error)
                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:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            list_of_booking_query = ("select container_id, vessel, consignor_company_name, consignor_email, DATE_FORMAT(booking_date, '%d/%m/%Y') as bookingDate, DATE_FORMAT(confirmation_date, '%d/%m/%Y') as confirmDate, order_id,\
            container_no, portFrom, portTo, supplier_login_id, DATE_FORMAT(eta, '%d/%m/%Y') as ETA, DATE_FORMAT(etd, '%d/%m/%Y') as ETD, hs_code,\
            country, quotation_id, tracking_number, weight, cbm, merchant_value, commercial_value, cargo_status_code,button_code,cargo_status_description,payment_status_description,custom_status_description,payment_status_code,custom_status_code\
            from ship_logistic_providers_order_list_view\
            where supplier_login_id = '" + login_id + "'")
            cursor.execute(list_of_booking_query)
            row = cursor.fetchall()
            if(cursor.rowcount > 0):
                list_values = list(row)
                resp.status = falcon.HTTP_200
                result_json = json.dumps(list_values)
                resp.body = result_json
                
            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Order is not found"}
                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 pymysql.IntegrityError 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()
Beispiel #23
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)
    def on_get(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
                Error = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Error)
                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:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            list_of_quotation_list_query = ("select supplier_login_id, quotation_id, quotationRef, part_a, part_b, incoterm_code,\
            quotationStatus, portName, shipper_type, freight, DATE_FORMAT(departure_date, '%m-%d-%Y') as etd,\
            country, vessel_id, vessel_no\
            from ship_logistic_providers_quotation_list_view\
            where supplier_login_id = '" + login_id + "' AND quotationStatus != 'Deleted'")
            cursor.execute(list_of_quotation_list_query)
            row = cursor.fetchall()
            if(cursor.rowcount > 0):
                list_values = list(row)
                resp.status = falcon.HTTP_200
                result_json = json.dumps(list_values, sort_keys=True, default=str)
                resp.body = result_json

            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Quotation is not found"}
                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 pymysql.IntegrityError 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()
Beispiel #25
0
    def on_get(self, req, resp, login_id, session):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Error)
                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:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            # Query to display all data from this tbl w verifed_user is active
            agent_list = ("select * \
                        from custom_agent c\
                        left join logins l on l.login_id = c.login_id\
                        where l.verified_user =1")
            cursor.execute(agent_list)
            row = cursor.fetchall()
            if(cursor.rowcount > 0):
                list_values = row
                result_json = json.dumps(list_values,sort_keys=True,default=str)
                resp.status = falcon.HTTP_200
                resp.body = result_json
                
            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Custom Agent is not found"}
                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 pymysql.IntegrityError 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()
    def on_get(self, req, resp, login_id, session):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Error)
                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:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            # Query to display these data from tbl and group them by their country
            country_list = ("select country_code_dep_name\
                            from ship_admin_quotation_list_view\
                            group by country_code_departure\
                            order by count(*) desc")
            cursor.execute(country_list)
            row = cursor.fetchall()
            if(cursor.rowcount > 0):
                list_values = row
                result_json = json.dumps(list_values,sort_keys=True)
                resp.status = falcon.HTTP_200
                resp.body = result_json
                
            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Country is not found"}
                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 pymysql.IntegrityError 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()
Beispiel #27
0
    def on_get(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
            else:
                resp.status = falcon.HTTP_200
                resp.body = ("200")

        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)
    def on_get(self, req, resp, login_id, session, quotation_id):
        # Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Error)
                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:
            # Connecting the database
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            list_of_container_query = ("SELECT distinct s.container_id, s.container_no, s.quotation_id, c.number_people_sharing \
                                    FROM ship_logistic_providers_order_list_view s \
                                    LEFT JOIN ship_containers c on c.container_id = s.container_id \
                                    WHERE  s.quotation_id = '"+quotation_id+"'")
            cursor.execute(list_of_container_query)
            row = cursor.fetchall()
            if(cursor.rowcount > 0):
                list_values = list(row)
                resp.status = falcon.HTTP_200
                result_json = json.dumps(list_values)
                resp.body = result_json
                
            else:
                resp.status = falcon.HTTP_204
                message = {"Message": "Container is not found"}
                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 pymysql.IntegrityError 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()
 def on_get(self, req, resp, login_id, session):
     # Authenticate login id and session availability.
     try:
         if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
             resp.status = falcon.HTTP_401
             Err = {"Reason": "Invalid Login Credentials or Session is Expired"}
             result_json = json.dumps(Err)
             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)
     # if Authentication true the code below runs
     # Gets Customer data
     try:
         # Declaration
         list_values = list()
         # DB connection
         database_connection = get_db_connection()
         cursor = database_connection.cursor()
         cursor.execute("select order_id from ship_orders where login_id = '" + login_id + "'")
         row = cursor.fetchone()
         if(cursor.rowcount > 0):
             for x in row.values():
                 list_values.append(x)
             order_details = list_values
             columns = ['OrderId']
             invoice_dictionary = dict(zip(columns,order_details))
             resp.status = falcon.HTTP_200
             result_json = json.dumps(invoice_dictionary)
             resp.body = result_json
         else:
             resp.status = falcon.HTTP_204
             result_json = json.dumps("Order Id not found")
             resp.body = result_json
     except ValueError as err:
         raise falcon.HTTPError(falcon.HTTP_400, traceback.print_exc(file=sys.stdout) , err.args)
     except pymysql.IntegrityError 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()
Beispiel #30
0
    def on_get(self, req, resp, login_id, session, container_id):
        #Authenticate login id and session availability.
        try:
            if (MemcacheFunctions.IsSessionValid(login_id, session) is False):
                resp.status = falcon.HTTP_401
                Error = {"Reason": "Invalid Login Credentials or Session is Expired"}
                result_json = json.dumps(Error)
                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, 'Error', err.args)
        
        try:
            # Database Connection
            database_connection = get_db_connection()
            cursor = database_connection.cursor()
            cursor.execute("select o.consignor_company_name,o.consignor_email,c.container_no,o.order_id,o.duties_and_tax as zduties_and_tax\
                            from ship_orders as o\
                            inner join ship_containers as c on c.container_id = o.container_id \
                            where o.container_id= '"+str(container_id)+"'")
            row = cursor.fetchall()
            if (cursor.rowcount > 0):
                container_details = row
                result_json = json.dumps(container_details,default=str,sort_keys=True)
                resp.status = falcon.HTTP_200
                resp.body = result_json

            else:
                resp.status = falcon.HTTP_204
                message = {"message": "Container ID is not found in the database."}
                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 pymysql.IntegrityError 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()