def add_payment(transaction_type, amount, mode_of_payment, sub_folio, remark, parent): # Create Inn Folio Transaction Bundle ftb_doc = frappe.new_doc('Inn Folio Transaction Bundle') ftb_doc.transaction_type = transaction_type ftb_doc.insert() _, credit_account = get_accounts_from_id(transaction_type) debit_account = get_mode_of_payment_account(mode_of_payment) new_doc = frappe.new_doc('Inn Folio Transaction') new_doc.flag = 'Credit' new_doc.is_void = 0 new_doc.idx = get_idx(parent) new_doc.transaction_type = transaction_type new_doc.amount = amount new_doc.sub_folio = sub_folio new_doc.mode_of_payment = mode_of_payment new_doc.debit_account = debit_account new_doc.credit_account = credit_account new_doc.remark = remark new_doc.parent = parent new_doc.parenttype = 'Inn Folio' new_doc.parentfield = 'folio_transaction' new_doc.ftb_id = ftb_doc.name new_doc.insert() # Create Inn Folio Transaction Bundle Detail Item Payment ftbd_doc = frappe.new_doc('Inn Folio Transaction Bundle Detail') ftbd_doc.transaction_type = new_doc.transaction_type ftbd_doc.transaction_id = new_doc.name ftb_doc.append('transaction_detail', ftbd_doc) # Resave Bundle to save Detail ftb_doc.save() return new_doc.name
def post_individual_room_charges(parent_id, tobe_posted_list): return_value = '' room_charge_posting_doc = frappe.get_doc('Inn Room Charge Posting', parent_id) list_json = json.loads(tobe_posted_list) for item in list_json: # Create Inn Folio Transaction Bundle ftb_doc = frappe.new_doc('Inn Folio Transaction Bundle') ftb_doc.transaction_type = 'Room Charge' ftb_doc.insert() # Posting Room Charge item_doc = frappe.get_doc('Inn Room Charge To Be Posted', item) accumulated_amount = 0.00 room_charge_debit_account, room_charge_credit_account = get_accounts_from_id( 'Room Charge') reservation = frappe.get_doc('Inn Reservation', item_doc.reservation_id) room_charge_folio_trx = frappe.new_doc('Inn Folio Transaction') room_charge_folio_trx.flag = 'Debit' room_charge_folio_trx.is_void = 0 room_charge_folio_trx.idx = get_idx(item_doc.folio_id) room_charge_folio_trx.transaction_type = 'Room Charge' room_charge_folio_trx.amount = float( int(reservation.nett_actual_room_rate)) accumulated_amount += float(int(reservation.nett_actual_room_rate)) room_charge_folio_trx.debit_account = room_charge_debit_account room_charge_folio_trx.credit_account = room_charge_credit_account room_charge_folio_trx.remark = 'Room Charge: Room Rate (Nett): ' + item_doc.room_id + " - " + get_last_audit_date( ).strftime("%d-%m-%Y") room_charge_folio_trx.parent = item_doc.folio_id room_charge_folio_trx.parenttype = 'Inn Folio' room_charge_folio_trx.parentfield = 'folio_transaction' room_charge_folio_trx.ftb_id = ftb_doc.name room_charge_folio_trx.insert() return_value = return_value + '<li>' + room_charge_folio_trx.remark + '</li>' # Create Inn Folio Transaction Bundle Detail Item Room Charge ftbd_doc = frappe.new_doc('Inn Folio Transaction Bundle Detail') ftbd_doc.transaction_type = room_charge_folio_trx.transaction_type ftbd_doc.transaction_id = room_charge_folio_trx.name ftb_doc.append('transaction_detail', ftbd_doc) # Posting Room Charge Tax/Service room_tb_id, room_tb_amount, _ = calculate_inn_tax_and_charges( reservation.nett_actual_room_rate, reservation.actual_room_rate_tax) for index, room_tax_item_name in enumerate(room_tb_id): room_tax_doc = frappe.new_doc('Inn Folio Transaction') room_tax_doc.flag = 'Debit' room_tax_doc.is_void = 0 room_tax_doc.idx = get_idx(item_doc.folio_id) room_tax_doc.transaction_type = 'Room Charge Tax/Service' room_tax_doc.amount = room_tb_amount[index] accumulated_amount += room_tb_amount[index] room_tax_doc.credit_account = frappe.get_doc( 'Inn Tax Breakdown', room_tax_item_name).breakdown_account room_tax_doc.debit_account = room_charge_debit_account room_tax_doc.remark = 'Room Charge Tax Room Rate ' + room_tax_item_name + ' : ' + item_doc.room_id + " - " + get_last_audit_date( ).strftime("%d-%m-%Y") room_tax_doc.parent = item_doc.folio_id room_tax_doc.parenttype = 'Inn Folio' room_tax_doc.parentfield = 'folio_transaction' room_tax_doc.ftb_id = ftb_doc.name room_tax_doc.insert() # Create Inn Folio Transaction Bundle Detail Item Room Charge Tax/Service ftbd_doc = frappe.new_doc('Inn Folio Transaction Bundle Detail') ftbd_doc.transaction_type = room_tax_doc.transaction_type ftbd_doc.transaction_id = room_tax_doc.name ftb_doc.append('transaction_detail', ftbd_doc) # Posting Breakfast Charge breakfast_charge_debit_account, breakfast_charge_credit_account = get_accounts_from_id( 'Breakfast Charge') breakfast_charge_folio_trx = frappe.new_doc('Inn Folio Transaction') breakfast_charge_folio_trx.flag = 'Debit' breakfast_charge_folio_trx.is_void = 0 breakfast_charge_folio_trx.idx = get_idx(item_doc.folio_id) breakfast_charge_folio_trx.transaction_type = 'Breakfast Charge' breakfast_charge_folio_trx.amount = float( int(reservation.nett_actual_breakfast_rate)) accumulated_amount += float(int( reservation.nett_actual_breakfast_rate)) breakfast_charge_folio_trx.debit_account = breakfast_charge_debit_account breakfast_charge_folio_trx.credit_account = breakfast_charge_credit_account breakfast_charge_folio_trx.remark = 'Room Charge: Breakfast (Nett): ' + item_doc.room_id + " - " + get_last_audit_date( ).strftime("%d-%m-%Y") breakfast_charge_folio_trx.parent = item_doc.folio_id breakfast_charge_folio_trx.parenttype = 'Inn Folio' breakfast_charge_folio_trx.parentfield = 'folio_transaction' breakfast_charge_folio_trx.ftb_id = ftb_doc.name breakfast_charge_folio_trx.insert() # Create Inn Folio Transaction Bundle Detail Item Breakfast Charge ftbd_doc = frappe.new_doc('Inn Folio Transaction Bundle Detail') ftbd_doc.transaction_type = breakfast_charge_folio_trx.transaction_type ftbd_doc.transaction_id = breakfast_charge_folio_trx.name ftb_doc.append('transaction_detail', ftbd_doc) # Posting Breakfast Tax/Service breakfast_tb_id, breakfast_tb_amount, _ = calculate_inn_tax_and_charges( reservation.nett_actual_breakfast_rate, reservation.actual_breakfast_rate_tax) for index, breakfast_tax_item_name in enumerate(breakfast_tb_id): breakfast_tax_doc = frappe.new_doc('Inn Folio Transaction') breakfast_tax_doc.flag = 'Debit' breakfast_tax_doc.is_void = 0 breakfast_tax_doc.idx = get_idx(item_doc.folio_id) breakfast_tax_doc.transaction_type = 'Breakfast Charge Tax/Service' breakfast_tax_doc.amount = breakfast_tb_amount[index] accumulated_amount += breakfast_tb_amount[index] breakfast_tax_doc.credit_account = frappe.get_doc( 'Inn Tax Breakdown', breakfast_tax_item_name).breakdown_account breakfast_tax_doc.debit_account = breakfast_charge_debit_account breakfast_tax_doc.remark = 'Breakfast Charge Tax Room Rate ' + breakfast_tax_item_name + ' : ' + item_doc.room_id + " - " + get_last_audit_date( ).strftime("%d-%m-%Y") breakfast_tax_doc.parent = item_doc.folio_id breakfast_tax_doc.parenttype = 'Inn Folio' breakfast_tax_doc.parentfield = 'folio_transaction' breakfast_tax_doc.ftb_id = ftb_doc.name breakfast_tax_doc.insert() # Create Inn Folio Transaction Bundle Detail Item Breakfast Charge Tax/Service ftbd_doc = frappe.new_doc('Inn Folio Transaction Bundle Detail') ftbd_doc.transaction_type = breakfast_tax_doc.transaction_type ftbd_doc.transaction_id = breakfast_tax_doc.name ftb_doc.append('transaction_detail', ftbd_doc) print("accumulated amount = " + str(accumulated_amount)) print("math_ceil(accumulated amount) = " + str(math.ceil(accumulated_amount))) print("actual room rate = " + str(reservation.actual_room_rate)) print("abs = " + str( abs( math.ceil(accumulated_amount) - int(reservation.actual_room_rate)))) if abs( math.ceil(accumulated_amount) - int(reservation.actual_room_rate)) != 0: difference = math.ceil(accumulated_amount) - int( reservation.actual_room_rate) if difference > 0: last_adjusted = 'breakfast' adjusted_room_charge_amount = room_charge_folio_trx.amount adjusted_breakfast_charge_amount = breakfast_charge_folio_trx.amount for i in range(0, abs(difference)): if last_adjusted == 'room': adjusted_room_charge_amount = adjusted_room_charge_amount - 1.0 last_adjusted = 'breakfast' else: adjusted_breakfast_charge_amount = adjusted_breakfast_charge_amount - 1.0 last_adjusted = 'room' elif difference < 0: last_adjusted = 'room' adjusted_room_charge_amount = room_charge_folio_trx.amount adjusted_breakfast_charge_amount = breakfast_charge_folio_trx.amount for i in range(0, abs(difference)): if last_adjusted == 'room': adjusted_room_charge_amount = adjusted_room_charge_amount + 1.0 last_adjusted = 'breakfast' else: adjusted_breakfast_charge_amount = adjusted_breakfast_charge_amount + 1.0 last_adjusted = 'room' room_charge_folio_trx.amount = adjusted_room_charge_amount room_charge_folio_trx.save() breakfast_charge_folio_trx.amount = adjusted_breakfast_charge_amount breakfast_charge_folio_trx.save() # Resave Bundle to save Detail ftb_doc.save() posted = frappe.new_doc('Inn Room Charge Posted') posted.reservation_id = item_doc.reservation_id posted.folio_id = item_doc.folio_id posted.room_id = item_doc.room_id posted.customer_id = item_doc.customer_id posted.room_rate_id = item_doc.room_rate_id posted.actual_room_rate = item_doc.actual_room_rate posted.folio_transaction_id = room_charge_folio_trx.name posted.parent = parent_id posted.parentfield = 'already_posted' posted.parenttype = 'Inn Room Charge Posting' room_charge_posting_doc.append('already_posted', posted) frappe.delete_doc('Inn Room Charge To Be Posted', item_doc.name) room_charge_posting_doc.save() calculate_already_posted_total(room_charge_posting_doc.name) return return_value