def download() -> None: """ Update all and the put the new updated timestamp """ download_individual() download_register_entry() download_memo_entry() download_memo_payments() download_memo_bills() download_gr_settle() download_account() db_connector.update()
def insert_partial_payment(entry: MemoEntry) -> None: """ Inserts partial payment between the account of supplier and party. """ # Open a new connection db, cursor = db_connector.cursor() sql = "INSERT INTO supplier_party_account (supplier_id, party_id, partial_amount) " \ "VALUES (%s, %s, %s)" val = (entry.supplier_id, entry.party_id, entry.amount) cursor.execute(sql, val) db_connector.add_stack_val(sql, val) db.commit() db.disconnect() db_connector.update()
def insert_memo_bills(entry: MemoBill) -> None: """ Insert all the bills attached to the same memo number. """ # Open a new connection db, cursor = db_connector.cursor() sql = "INSERT INTO memo_bills (memo_id, bill_number, type, amount) " \ "VALUES (%s, %s, %s, %s)" val = (entry.memo_id, entry.memo_number, entry.type, entry.amount) cursor.execute(sql, val) db_connector.add_stack_val(sql, val) db.commit() db.disconnect() db_connector.update()
def insert_register_entry(entry: RegisterEntry) -> None: """ Insert a register_entry into the database. """ # Open a new connection db, cursor = db_connector.cursor() sql = "INSERT INTO register_entry (supplier_id, party_id, register_date, amount, bill_number, status, " \ "d_amount, d_percent) " \ "VALUES (%s, %s, %s, %s, %s, %s, %s, %s)" val = (entry.supplier_id, entry.party_id, str(entry.date), entry.amount, entry.bill_number, entry.status, entry.d_amount, entry.d_percent) cursor.execute(sql, val) db_connector.add_stack_val(sql, val) db.commit() db.disconnect() db_connector.update()
def settle_gr(entry: Grentry) -> None: """ Use the the pending gr amount to settle the account between a party and supplier """ # Open a new connection db = db_connector.connect() cursor = db.cursor() sql = "INSERT INTO gr_settle (supplier_id, party_id, settle_amount, start_date, end_date) " \ "VALUES (%s, %s, %s, %s, %s)" val = (entry.supplier_id, entry.party_id, entry.amount, entry.start_date, entry.end_date) cursor.execute(sql, val) db.commit() db.disconnect() db_connector.update()
def add_partial_amount(supplier_id: int, party_id: int, amount: int) -> None: """ Add partial amount between a supplier and party """ # Open a new connection db, cursor = db_connector.cursor() partial_amount = int( retrieve_partial_payment.get_partial_payment(supplier_id, party_id)) amount += partial_amount query = "UPDATE supplier_party_account SET partial_amount = {} WHERE supplier_id = {} AND party_id = {}" \ .format(amount, supplier_id, party_id) cursor.execute(query) db.commit() db.disconnect() db_connector.update()
def update_register_entry_data(entry: RegisterEntry) -> None: """ Update changes made to the register entry by a memo_entry """ # Open a new connection db, cursor = db_connector.cursor() entry_id = retrieve_register_entry.get_register_entry_id( entry.supplier_id, entry.party_id, entry.bill_number) query = "UPDATE register_entry SET partial_amount = '{}', status = '{}', " \ "d_amount = '{}', d_percent = '{}', gr_amount = '{}' WHERE id = {}"\ .format(entry.part_payment, entry.status, entry.d_amount, entry.d_percent, entry.gr_amount, entry_id) cursor.execute(query) db_connector.add_stack(query) db.commit() db.disconnect() db_connector.update()
def download_online() -> None: """ take the queries from the offline stack and execute it to make changes into the online database """ local_database, local_cursor = db_connector.cursor() online_database, online_cursor = online_db_connector.cursor() # get the last update timestamp query = "select updated_at from last_update" local_cursor.execute(query) timestamp = (online_cursor.fetchall())[0][0] query = "select query, val from stack where updated_at >= CAST('{}' AS DATETIME)".format(timestamp) online_cursor.execute(query) data = online_cursor.fetchall() query_execute(data, local_cursor) local_database.commit() db_connector.update()
def insert_memo_payemts(entry: MemoEntry) -> None: """ Add the memo paymentns for the given memo_entry """ # Open a new connection db, cursor = db_connector.cursor() memo_id = retrieve_memo_entry.get_id_by_memo_number( entry.memo_number, entry.supplier_id, entry.party_id) payment_list = [(memo_id, retrieve_indivijual.get_bank_id_by_name(e[0]), int(e[1])) for e in entry.payment_info] sql = "INSERT INTO memo_payments (memo_id, bank_id, cheque_number) " \ "VALUES (%s, %s, %s)" cursor.executemany(sql, payment_list) db_connector.add_stack_val_multiple(sql, payment_list) db.commit() db.disconnect() db_connector.update()
def update_memo_entry_data(entry: MemoEntry) -> None: """ Update changes made to a memo_entry """ # Open a new connection db, cursor = db_connector.cursor() entry_id = retrieve_memo_entry.get_id_by_memo_number( entry.memo_number, entry.supplier_id, entry.party_id) if entry.mode != "Good Return": query = "UPDATE memo_entry SET amount = amount + '{}' " \ "WHERE id = {}"\ .format(entry.amount, entry_id) else: query = "UPDATE memo_entry SET gr_amount = gr_amount + '{}' " \ "WHERE id = {}" \ .format(entry.amount, entry_id) cursor.execute(query) db_connector.add_stack(query) db.commit() db.disconnect() db_connector.update()
def insert_memo_entry(entry: MemoEntry) -> None: # Open a new connection db, cursor = db_connector.cursor() if entry.mode == "Good Return": sql = "INSERT INTO memo_entry (supplier_id, party_id, register_date, memo_number, gr_amount) " \ "VALUES (%s, %s, %s, %s, %s)" val = (entry.supplier_id, entry.party_id, str(entry.date), entry.memo_number, entry.amount) db_connector.add_stack_val(sql, val) cursor.execute(sql, val) else: sql = "INSERT INTO memo_entry (supplier_id, party_id, register_date, memo_number, amount) " \ "VALUES (%s, %s, %s, %s, %s)" val = (entry.supplier_id, entry.party_id, str(entry.date), entry.memo_number, entry.amount) cursor.execute(sql, val) db_connector.add_stack_val(sql, val) db.commit() db.disconnect() db_connector.update()