def insertDemandTable(connection, spare_id, quantity_todemand): global NOW # Create a survey entry with 'NA' as the survey_number query = f"""INSERT INTO data_postsurvey (spare_id, survey_number, quantity_surveyed, survey_number_date, survey_report_date, remarks) VALUES ('{spare_id}', 'NA', '{quantity_todemand}', '{NOW}', '{NOW}', 'CONSUMABLE SPARE');""" db.execute(connection, query, False) survey_number_id = getMaximumPostSurveyId() query = f""" INSERT INTO data_demand(spare_id, quantity_todemand, survey_entry_id) VALUES ('{spare_id}', '{quantity_todemand}', '{survey_number_id}'); """ db.execute(connection, query, False)
def insertIssueListTable(connection, delta): # Fetch the spare with maximum id spare_id = getMaximumSpareId() # Create an issue entry for the spare query = f""" INSERT INTO data_issue(spare_id, username, quantity_issued, remarks) VALUES ('{spare_id}', 'DEFAULT_USER', '{delta}', ' Onoard held quantity is less than authorised quantity.'); """ db.execute(connection, query, False) issue_id = getMaximumIssueId() # Insert into the issuelist table query = f""" INSERT INTO data_issuelist(issue_entry_id, quantity_toreturn) VALUES ('{issue_id}', '{delta}'); """ db.execute(connection, query, False) # Insert into survey/demand table if (row[labels['category']] == "CONSUMABLE"): insertDemandTable(connection, spare_id, delta) else: insertSurveyTable(connection, spare_id, delta)
def insertSurveyTable(connection, spare_id, quantity_tosurvey): query = f""" INSERT INTO data_survey(spare_id, quantity_tosurvey) VALUES ({spare_id}, {quantity_tosurvey}); """ db.execute(connection, query, False)
def getMaximumPostSurveyId(): query = f"""SELECT MAX(id) FROM data_postsurvey;""" result = db.execute(connection, query, True) return result[0][0]
def getMaximumIssueId(): query = f"""SELECT MAX(id) FROM data_issue;""" result = db.execute(connection, query, True) return result[0][0]
pattern_number = row[labels['pattern number']] spare_class = row[labels['class of spare']] equipment_class = row[ labels['class of equipments/valves/fittings/pll as per d787j']] # Ignore entry if spare_class or equipment_class missing if (not spare_class or not equipment_class): print( "Spare class or equipment class missing. Ignoring entry.") continue # Check if an entry corresponding to a pattern number exists if (pattern_number): check_query = f"""SELECT count(*) FROM data_spares WHERE pattern_number='{pattern_number}'""" result = db.execute(connection, check_query, True) if result[0][0] != 0: print( "Entry corresponding to pattern number: %s already exists. Ignoring this entry." % pattern_number) continue # Insert if entry not found insert_query = f""" INSERT INTO data_spares( pattern_number, spare_class, equipment_class, description, category, critical,