public ARNManager(string elt_acct) : base(elt_acct) { IVChManager = new IVChargeItemsManager(elt_account_number); IVCostManager = new IVCostItemsManager(elt_account_number); bdMgr = new BillDetailManager(elt_account_number); aajMgr = new AllAccountsJournalManager(elt_account_number); }
public bool insertBillRecord(ref BillRecord bRec, string tran_type) { bRec.replaceQuote(); bool return_val = false; int bill_number = getNewbillNumber(); bRec.Bill_number = bill_number; int next_item_id = bdMgr.getNextItemIDForBill(bill_number); if (bRec.All_accounts_journal_list != null) { setTranNoForAllAccountsJournalEntries(bRec.All_accounts_journal_list, bill_number); } for (int i = 0; i < bRec.BillDetailList.Count; i++) { ((BillDetailRecord)bRec.BillDetailList[i]).bill_number = bill_number; } ArrayList bdList = bRec.BillDetailList; ArrayList AAJEntryList = bRec.All_accounts_journal_list; if (bRec.All_accounts_journal_list != null) { for (int i = 0; i < AAJEntryList.Count; i++) { AAJMgr.checkInitial_Acct_Record((AllAccountsJournalRecord)AAJEntryList[i]); } } int next_tran_seq_no = AAJMgr.getNextTranSeqNumber(); Cmd = new SqlCommand(); Cmd.Connection = Con; Con.Open(); SqlTransaction trans = Con.BeginTransaction(); Cmd.Transaction = trans; try { //Keept the ID from OPERATION/UPDATE BILL DETAILS SINCE BILL_DETAIL CAN BE ALREAY EXISTING/ generated From MB/ for (int i = 0; i < bdList.Count; i++) { BillDetailRecord bDRec = (BillDetailRecord)bdList[i]; bDRec.bill_number = bill_number; if (bDRec.item_id != -1 && bDRec.item_id != 0) { SQL = "UPDATE [bill_detail] "; SQL += "set elt_account_number= '" + elt_account_number + "',"; SQL += "item_ap= '" + bDRec.item_ap + "',"; SQL += "item_id= '" + bDRec.item_id + "',"; SQL += "item_no= '" + bDRec.item_no + "',"; SQL += "item_amt= '" + bDRec.item_amt + "',"; SQL += "is_manual= '" + bDRec.is_manual + "',"; SQL += "item_expense_acct= '" + bDRec.item_expense_acct + "',"; SQL += "tran_date= '" + bDRec.tran_date + "',"; //--------------here is where update can be effective for the bill_detail at AP Queue if (bDRec.Is_checked) { SQL += "bill_number= '" + bDRec.bill_number + "',"; } else { SQL += "bill_number= 0,"; bDRec.bill_number = 0; } //-------------- SQL += "invoice_no= '" + bDRec.invoice_no + "',"; SQL += "agent_debit_no= '" + bDRec.agent_debit_no + "',"; SQL += "mb_no= '" + bDRec.mb_no + "',"; SQL += "ref= '" + bDRec.ref_no + "',"; SQL += "iType= '" + bDRec.iType + "',"; SQL += "vendor_number= '" + bDRec.vendor_number + "'"; SQL += "WHERE elt_account_number = " + elt_account_number; SQL += " AND invoice_no = " + bDRec.invoice_no; SQL += " AND item_id=" + bDRec.item_id; Cmd.CommandText = SQL; Cmd.ExecuteNonQuery(); } else { bDRec.item_id = next_item_id++; SQL = "INSERT INTO [bill_detail] "; SQL += "( elt_account_number, "; SQL += "item_ap,"; SQL += "item_id,"; SQL += "item_no,"; SQL += "item_amt,"; SQL += "is_manual,"; SQL += "item_expense_acct,"; SQL += "tran_date,"; SQL += "bill_number,"; SQL += "invoice_no,"; SQL += "agent_debit_no,"; SQL += "mb_no,"; SQL += "ref,"; SQL += "iType,"; SQL += "vendor_number)"; SQL += "VALUES"; SQL += "('" + elt_account_number; SQL += "','" + bDRec.item_ap; SQL += "','" + bDRec.item_id; SQL += "','" + bDRec.item_no; SQL += "','" + bDRec.item_amt; SQL += "','" + bDRec.is_manual; SQL += "','" + bDRec.item_expense_acct; SQL += "','" + bDRec.tran_date; SQL += "','" + bDRec.bill_number; SQL += "','" + bDRec.invoice_no; SQL += "','" + bDRec.agent_debit_no; SQL += "','" + bDRec.mb_no; SQL += "','" + bDRec.ref_no; SQL += "','" + bDRec.iType; SQL += "','" + bDRec.vendor_number; SQL += "')"; Cmd.CommandText = SQL; Cmd.ExecuteNonQuery(); } } if (bRec.All_accounts_journal_list != null) { for (int i = 0; i < AAJEntryList.Count; i++) { ((AllAccountsJournalRecord)AAJEntryList[i]).replaceQuote(); ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num = bill_number; SQL = "INSERT INTO [all_accounts_journal] "; SQL += "( elt_account_number, "; SQL += "tran_num,"; SQL += "gl_account_number,"; SQL += "gl_account_name,"; SQL += "tran_seq_num,"; SQL += "tran_type,"; SQL += "tran_date,"; SQL += "Customer_Number,"; SQL += "Customer_Name,"; SQL += "debit_amount,"; SQL += "credit_amount,"; SQL += "balance,"; SQL += "previous_balance,"; SQL += "gl_balance,"; SQL += "gl_previous_balance)"; SQL += "VALUES"; SQL += "('" + elt_account_number; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_name; SQL += "','" + next_tran_seq_no++; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_type; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_date; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_number; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_name; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).debit_amount; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).credit_amount; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).balance; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).previous_balance; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_balance; SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_previous_balance; SQL += "')"; Cmd.CommandText = SQL; Cmd.ExecuteNonQuery(); } } SQL = "INSERT INTO [bill] "; SQL += "(elt_account_number,"; SQL += "bill_number,"; SQL += "bill_type,"; SQL += "vendor_number,"; SQL += "vendor_name,"; SQL += "bill_date,"; SQL += "bill_due_date,"; SQL += "bill_amt,"; SQL += "bill_amt_paid,"; SQL += "bill_amt_due,"; SQL += "ref_no,"; SQL += "bill_expense_acct,"; SQL += "bill_ap,"; SQL += "bill_status,"; SQL += "print_id,"; SQL += "lock,"; SQL += "pmt_method,"; SQL += "is_org_merged)"; SQL += "VALUES"; SQL += "('" + elt_account_number; SQL += "','" + bRec.Bill_number; SQL += "','" + bRec.Bill_type; SQL += "','" + bRec.Vendor_number; SQL += "','" + bRec.Vendor_name; SQL += "','" + bRec.Bill_date; SQL += "','" + bRec.Bill_due_date; SQL += "','" + bRec.Bill_amt; SQL += "','" + bRec.Bill_amt_paid; SQL += "','" + bRec.Bill_amt_due; SQL += "','" + bRec.Ref_no; SQL += "','" + bRec.Bill_expense_acct; SQL += "','" + bRec.Bill_ap; SQL += "','" + bRec.Bill_status; SQL += "','" + bRec.Print_id; SQL += "','" + bRec.Lock; SQL += "','" + bRec.Pmt_method; SQL += "','" + bRec.Is_org_merged; SQL += "')"; Cmd.CommandText = SQL; Cmd.ExecuteNonQuery(); SQL = "Delete FROM bill_detail WHERE elt_account_number = " + elt_account_number + " AND bill_number = " + bill_number + " AND item_amt = " + 0; Cmd.CommandText = SQL; Cmd.ExecuteNonQuery(); trans.Commit(); return_val = true; } catch (Exception ex) { trans.Rollback(); throw ex; } finally { Con.Close(); } MBCostItemsManager MBCostItemMgr = new MBCostItemsManager(elt_account_number); IVCostItemsManager IVCostItemMgr = new IVCostItemsManager(elt_account_number); int invoice_no = 0; string mb_no = ""; int item_id = 0; for (int i = 0; i < bdList.Count; i++) { if (((BillDetailRecord)bdList[i]).bill_number == 0) { if (((BillDetailRecord)bdList[i]).mb_no != "") { mb_no = ((BillDetailRecord)bdList[i]).mb_no; item_id = ((BillDetailRecord)bdList[i]).item_id; MBCostItemMgr.resetAPLock(mb_no, item_id, "N"); } if (((BillDetailRecord)bdList[i]).invoice_no != 0) { invoice_no = ((BillDetailRecord)bdList[i]).invoice_no; item_id = ((BillDetailRecord)bdList[i]).item_id; IVCostItemMgr.resetAPLock(invoice_no, item_id, "N"); } } else { if (((BillDetailRecord)bdList[i]).mb_no != "") { mb_no = ((BillDetailRecord)bdList[i]).mb_no; item_id = ((BillDetailRecord)bdList[i]).item_id; MBCostItemMgr.resetAPLock(mb_no, item_id, "Y"); } if (((BillDetailRecord)bdList[i]).invoice_no != 0) { invoice_no = ((BillDetailRecord)bdList[i]).invoice_no; item_id = ((BillDetailRecord)bdList[i]).item_id; IVCostItemMgr.resetAPLock(invoice_no, item_id, "Y"); } } } return(return_val); }