public bool Save <T>(T item) where T : IContract { var result = 0; var cbreceipt = (CBReceipt)(object)item; if (currentTransaction == null) { connection = db.CreateConnection(); connection.Open(); } var transaction = (currentTransaction == null ? connection.BeginTransaction() : currentTransaction); try { var savecommand = db.GetStoredProcCommand(DBRoutine.SAVECBRECEIPT); db.AddInParameter(savecommand, "DocumentNo", System.Data.DbType.String, cbreceipt.DocumentNo); db.AddInParameter(savecommand, "DocumentDate", System.Data.DbType.DateTime, cbreceipt.DocumentDate); db.AddInParameter(savecommand, "BranchID", System.Data.DbType.Int16, cbreceipt.BranchID); db.AddInParameter(savecommand, "ReceiptType", System.Data.DbType.String, cbreceipt.ReceiptType); db.AddInParameter(savecommand, "BankCode", System.Data.DbType.String, cbreceipt.BankCode); db.AddInParameter(savecommand, "DebtorCode", System.Data.DbType.String, cbreceipt.DebtorCode); db.AddInParameter(savecommand, "PayerName", System.Data.DbType.String, cbreceipt.PayerName ?? ""); db.AddInParameter(savecommand, "BankAccount", System.Data.DbType.String, cbreceipt.BankAccount ?? ""); db.AddInParameter(savecommand, "BankChargesAccount", System.Data.DbType.String, cbreceipt.BankChargesAccount ?? ""); db.AddInParameter(savecommand, "DebtorAccount", System.Data.DbType.String, cbreceipt.DebtorAccount ?? ""); db.AddInParameter(savecommand, "ChequeNo", System.Data.DbType.String, cbreceipt.ChequeNo ?? ""); db.AddInParameter(savecommand, "ChequeDate", System.Data.DbType.DateTime, cbreceipt.ChequeDate.ToString("dd-MM-yyyy") == "01-01-0001" ? (object)DBNull.Value : cbreceipt.ChequeDate); db.AddInParameter(savecommand, "CurrencyCode", System.Data.DbType.String, cbreceipt.CurrencyCode ?? "THB"); db.AddInParameter(savecommand, "ExchangeRate", System.Data.DbType.Decimal, cbreceipt.ExchangeRate); db.AddInParameter(savecommand, "BaseReceiptAmount", System.Data.DbType.Decimal, cbreceipt.BaseReceiptAmount); db.AddInParameter(savecommand, "BaseApplyAmount", System.Data.DbType.Decimal, cbreceipt.BaseApplyAmount); db.AddInParameter(savecommand, "LocalReceiptAmount", System.Data.DbType.Decimal, cbreceipt.LocalReceiptAmount); db.AddInParameter(savecommand, "LocalApplyAmount", System.Data.DbType.Decimal, cbreceipt.LocalApplyAmount); db.AddInParameter(savecommand, "LocalBankChargesAmount", System.Data.DbType.Decimal, cbreceipt.LocalBankChargesAmount); db.AddInParameter(savecommand, "Remark", System.Data.DbType.String, cbreceipt.Remark ?? ""); db.AddInParameter(savecommand, "AccountDate", System.Data.DbType.DateTime, cbreceipt.AccountDate.ToString("dd-MM-yyyy") == "01-01-0001" ? (object)DBNull.Value : cbreceipt.AccountDate); db.AddInParameter(savecommand, "Source", System.Data.DbType.String, cbreceipt.Source ?? "CB"); db.AddInParameter(savecommand, "IsWHTax", System.Data.DbType.Boolean, cbreceipt.IsWHTax); db.AddInParameter(savecommand, "WHPercent", System.Data.DbType.Int16, cbreceipt.WHPercent); db.AddInParameter(savecommand, "WHAmount", System.Data.DbType.Decimal, cbreceipt.WHAmount); db.AddInParameter(savecommand, "IsVAT", System.Data.DbType.Boolean, cbreceipt.IsVAT); db.AddInParameter(savecommand, "TaxAmount", System.Data.DbType.Decimal, cbreceipt.TaxAmount); db.AddInParameter(savecommand, "TotalAmount", System.Data.DbType.Decimal, cbreceipt.TotalAmount); db.AddInParameter(savecommand, "CreatedBy", System.Data.DbType.String, cbreceipt.CreatedBy); db.AddInParameter(savecommand, "ModifiedBy", System.Data.DbType.String, cbreceipt.ModifiedBy); db.AddInParameter(savecommand, "PrintRemarks", System.Data.DbType.String, cbreceipt.PrintRemarks ?? ""); db.AddOutParameter(savecommand, "NewDocumentNo", System.Data.DbType.String, 25); result = db.ExecuteNonQuery(savecommand, transaction); if (result > 0) { var cbReceiptDetailsItemDAL = new CBReceiptDetailDAL(); var cbReceiptDetailsSetOffItemDAL = new CBReceiptSetOffDetailDAL(); var cbreceiptgldetailsItemDAL = new CBReceiptGlDetailDAL(); var cbreceiptgltransactionItemDAL = new GLTransactionDAL(); short detailitem = 1; cbreceipt.DocumentNo = savecommand.Parameters["@NewDocumentNo"].Value.ToString(); if (cbreceipt.CBReceiptSetOffDetails != null) { result = Convert.ToInt16(cbReceiptDetailsSetOffItemDAL.Delete(cbreceipt.DocumentNo, transaction)); cbreceipt.CBReceiptSetOffDetails.ForEach(dt => { dt.DocumentNo = cbreceipt.DocumentNo; dt.CreatedBy = cbreceipt.CreatedBy; dt.ModifiedBy = cbreceipt.ModifiedBy; dt.CurrencyCode = cbreceipt.CurrencyCode; dt.MatchDocumentDate = cbreceipt.DocumentDate; dt.DebtorCode = cbreceipt.DebtorCode; dt.SetOffDate = cbreceipt.DocumentDate; dt.ItemNo = detailitem++; }); result = cbReceiptDetailsSetOffItemDAL.SaveList(cbreceipt.CBReceiptSetOffDetails, transaction) == true ? 1 : 0; } /* Save CBPaymentGLDetails if the CBPayment Type ='CREDITOR' */ detailitem = 1; if (cbreceipt.CBReceiptGLDetails != null) { result = Convert.ToInt16(cbreceiptgldetailsItemDAL.Delete(cbreceipt.DocumentNo, transaction)); cbreceipt.CBReceiptGLDetails.ForEach(dt => { dt.DocumentNo = cbreceipt.DocumentNo; dt.TransactionType = "REC"; dt.ItemNo = detailitem++; }); result = cbreceiptgldetailsItemDAL.SaveList(cbreceipt.CBReceiptGLDetails, transaction) == true ? 1 : 0; } if (cbreceipt.ReceiptType == "DEBTOR") { cbreceipt.GLTransactionDetails = new List <GLTransaction>(); cbreceipt.CBReceiptGLDetails.ForEach(gl => { var gltransaction = new GLTransaction(); gltransaction.AccountCode = gl.AccountCode; gltransaction.AccountDate = cbreceipt.DocumentDate; gltransaction.BankInSlipNo = ""; gltransaction.BankStatementPgNo = 0; gltransaction.BankStatementTotalPgNo = 0; gltransaction.BaseAmount = gl.TotalAmount; gltransaction.BranchID = cbreceipt.BranchID; gltransaction.ChequeNo = ""; gltransaction.CreditAmount = 0; gltransaction.CreditorCode = ""; gltransaction.CurrencyCode = cbreceipt.CurrencyCode; gltransaction.DebitAmount = 0; gltransaction.DebitCredit = ""; gltransaction.DebtorCode = cbreceipt.DebtorCode; gltransaction.DetailRemark = cbreceipt.Remark; gltransaction.DocumentType = "REC"; gltransaction.DocumentNo = cbreceipt.DocumentNo; gltransaction.DocumentDate = cbreceipt.DocumentDate; gltransaction.Amount = gl.TotalAmount; gltransaction.Remark = cbreceipt.Remark; gltransaction.ItemNo = Convert.ToInt16(gl.ItemNo); gltransaction.Source = "CB"; gltransaction.AccountDate = cbreceipt.DocumentDate; gltransaction.ExchangeRate = 0; gltransaction.Status = true; gltransaction.Year = 0; cbreceipt.GLTransactionDetails.Add(gltransaction); }); } if (cbreceipt.CBReceiptDetails != null) { result = Convert.ToInt16(cbReceiptDetailsItemDAL.Delete(cbreceipt.DocumentNo, transaction)); detailitem = 1; cbreceipt.CBReceiptDetails.ForEach(dt => { dt.ItemNo = detailitem++; dt.DocumentNo = cbreceipt.DocumentNo; }); result = cbReceiptDetailsItemDAL.SaveList(cbreceipt.CBReceiptDetails, transaction) == true ? 1 : 0; } if (cbreceipt.GLTransactionDetails != null) { detailitem = 1; if (cbreceipt.ReceiptType != "DEBTOR") { cbreceipt.GLTransactionDetails.ForEach(dt => { dt.DocumentNo = cbreceipt.DocumentNo; dt.CurrencyCode = cbreceipt.CurrencyCode; dt.DebtorCode = cbreceipt.DebtorCode; dt.DocumentDate = cbreceipt.DocumentDate; dt.BankInSlipNo = ""; dt.Amount = dt.CreditAmount > 0 ? dt.CreditAmount : dt.DebitAmount; dt.BaseAmount = dt.CreditAmount > 0 ? dt.CreditAmount : dt.DebitAmount; dt.Remark = dt.Remark ?? dt.DetailRemark; dt.ItemNo = detailitem++; dt.Source = "CB"; dt.BranchID = cbreceipt.BranchID; dt.AccountDate = cbreceipt.DocumentDate; dt.DocumentType = "REC"; }); } //result = Convert.ToInt16(cbPaymentgltransactionItemDAL.Delete(cbpayment.DocumentNo, transaction)); result = cbreceiptgltransactionItemDAL.SaveList(cbreceipt.GLTransactionDetails, transaction) == true ? 1 : 0; } } if (result > 0) { transaction.Commit(); } else { transaction.Rollback(); } } catch (Exception ex) { if (currentTransaction == null) { transaction.Rollback(); } throw; } return(result > 0 ? true : false); }
public bool Save<T>(T item) where T : IContract { var result = 0; var apinvoice = (APInvoice)(object)item; if (currentTransaction == null) { connection = db.CreateConnection(); connection.Open(); } var transaction = (currentTransaction == null ? connection.BeginTransaction() : currentTransaction); try { var savecommand = db.GetStoredProcCommand(DBRoutine.SAVEAPINVOICE); db.AddInParameter(savecommand, "DocumentNo", System.Data.DbType.String, apinvoice.DocumentNo); db.AddInParameter(savecommand, "DocumentDate", System.Data.DbType.DateTime, apinvoice.DocumentDate); db.AddInParameter(savecommand, "BranchID", System.Data.DbType.Int16, apinvoice.BranchID); db.AddInParameter(savecommand, "ReferenceNo", System.Data.DbType.String, apinvoice.ReferenceNo==null? "":apinvoice.ReferenceNo); db.AddInParameter(savecommand, "CreditorCode", System.Data.DbType.String, apinvoice.CreditorCode); db.AddInParameter(savecommand, "CreditTerm", System.Data.DbType.String, apinvoice.CreditTerm==null?"0":apinvoice.CreditTerm); db.AddInParameter(savecommand, "CurrencyCode", System.Data.DbType.String, apinvoice.CurrencyCode); db.AddInParameter(savecommand, "ExchangeRate", System.Data.DbType.Decimal, apinvoice.ExchangeRate); db.AddInParameter(savecommand, "BaseAmount", System.Data.DbType.Decimal, apinvoice.BaseAmount); db.AddInParameter(savecommand, "LocalAmount", System.Data.DbType.Decimal, apinvoice.LocalAmount); db.AddInParameter(savecommand, "DiscountAmount", System.Data.DbType.Decimal, apinvoice.DiscountAmount); db.AddInParameter(savecommand, "PaymentAmount", System.Data.DbType.Decimal, apinvoice.PaymentAmount); db.AddInParameter(savecommand, "IsVAT", System.Data.DbType.Boolean, apinvoice.IsVAT); db.AddInParameter(savecommand, "TaxAmount", System.Data.DbType.Decimal, apinvoice.TaxAmount); db.AddInParameter(savecommand, "IsWHTax", System.Data.DbType.Boolean, apinvoice.IsWHTax); db.AddInParameter(savecommand, "WHPercent", System.Data.DbType.Int16, 0); db.AddInParameter(savecommand, "WHAmount", System.Data.DbType.Decimal, apinvoice.WHAmount); db.AddInParameter(savecommand, "TotalAmount", System.Data.DbType.Decimal, apinvoice.TotalAmount); db.AddInParameter(savecommand, "Remark", System.Data.DbType.String, apinvoice.Remark==null?"":apinvoice.Remark); db.AddInParameter(savecommand, "Source", System.Data.DbType.String, apinvoice.Source); db.AddInParameter(savecommand, "CreatedBy", System.Data.DbType.String, apinvoice.CreatedBy); db.AddInParameter(savecommand, "ModifiedBy", System.Data.DbType.String, apinvoice.ModifiedBy); db.AddOutParameter(savecommand, "NewDocumentNo", System.Data.DbType.String, 25); result = db.ExecuteNonQuery(savecommand, transaction); if (result > 0) { var apDetailsItemDAL = new APInvoiceDetailDAL(); var glTransactionDAL = new GLTransactionDAL(); // Get the New Quotation No. apinvoice.DocumentNo = savecommand.Parameters["@NewDocumentNo"].Value.ToString(); short itr = 1; apinvoice.APInvoiceDetails.Where(dt=> dt.Status==true).ToList().ForEach(dt => { dt.DocumentNo = apinvoice.DocumentNo; dt.CreatedBy = apinvoice.CreatedBy; dt.ModifiedBy = apinvoice.ModifiedBy; dt.Discount = 0; dt.DiscountType = ""; dt.ChargeCode = ""; dt.ItemNo = itr++; }); itr = 1; var firstDayOfMonth = new DateTime(apinvoice.DocumentDate.Year, apinvoice.DocumentDate.Month, 1); apinvoice.GLTransactionDetails.Where(dt => dt.Status == true).ToList().ForEach(dt => { dt.DocumentNo = apinvoice.DocumentNo; dt.Source = apinvoice.Source; dt.BankInSlipNo = ""; dt.BankStatementPgNo = 0; dt.BankStatementTotalPgNo = 0; dt.ChequeNo = ""; dt.BranchID = apinvoice.BranchID; dt.DocumentDate = apinvoice.DocumentDate; dt.DocumentType = "INV"; dt.DebtorCode = ""; dt.CreditorCode = apinvoice.CreditorCode; dt.CurrencyCode = "THB"; dt.AccountDate = firstDayOfMonth; dt.ItemNo = itr++; }); result = Convert.ToInt16(apDetailsItemDAL.Delete(apinvoice.DocumentNo, transaction)); result = apDetailsItemDAL.SaveList(apinvoice.APInvoiceDetails, transaction) == true ? 1 : 0; result = glTransactionDAL.SaveList(apinvoice.GLTransactionDetails, transaction) == true ? 1 : 0; } if (result > 0) transaction.Commit(); else transaction.Rollback(); } catch (Exception ex) { if (currentTransaction == null) transaction.Rollback(); throw ex; } return (result > 0 ? true : false); }
public bool Save <T>(T item) where T : IContract { var result = 0; var glopening = (GLOpening)(object)item; var connection = db.CreateConnection(); connection.Open(); var transaction = connection.BeginTransaction(); try { var savecommand = db.GetStoredProcCommand(DBRoutine.SAVEGLOPENING); db.AddInParameter(savecommand, "DocumentNo", System.Data.DbType.String, glopening.DocumentNo); db.AddInParameter(savecommand, "FinancialYear", System.Data.DbType.Int32, glopening.FinancialYear); db.AddInParameter(savecommand, "BranchID", System.Data.DbType.Int16, glopening.BranchID); db.AddInParameter(savecommand, "AccountDate", System.Data.DbType.DateTime, glopening.AccountDate); db.AddInParameter(savecommand, "TotalDebitAmount", System.Data.DbType.Decimal, glopening.TotalDebitAmount); db.AddInParameter(savecommand, "TotalCreditAmount", System.Data.DbType.Decimal, glopening.TotalCreditAmount); db.AddInParameter(savecommand, "CreatedBy", System.Data.DbType.String, glopening.CreatedBy); db.AddInParameter(savecommand, "ModifiedBy", System.Data.DbType.String, glopening.ModifiedBy); db.AddOutParameter(savecommand, "NewDocumentNo", System.Data.DbType.String, 25); result = db.ExecuteNonQuery(savecommand, transaction); if (result > 0) { var glopeningdetailsDAL = new GLOpeningDetailDAL(); var glTransactionDAL = new GLTransactionDAL(); // Get the New Quotation No. glopening.DocumentNo = savecommand.Parameters["@NewDocumentNo"].Value.ToString(); short itr = 1; glopening.GLOpenDetails.ForEach(dt => { dt.DocumentNo = glopening.DocumentNo; dt.Remark = ""; } ); result = Convert.ToInt16(glopeningdetailsDAL.Delete(glopening.DocumentNo, transaction)); result = glopeningdetailsDAL.SaveList(glopening.GLOpenDetails, transaction) == true ? 1 : 0; var firstDayOfMonth = new DateTime(glopening.AccountDate.Year, glopening.AccountDate.Month, 1); glopening.GLOpenDetails.ForEach(dt => { glopening.GLTransactionDetails.Add(new GLTransaction { ItemNo = itr++, BranchID = glopening.BranchID, AccountCode = dt.AccountCode, AccountDate = firstDayOfMonth, Source = "GL", DocumentType = "OB", DocumentNo = glopening.DocumentNo, DocumentDate = glopening.AccountDate, DebtorCode = "", CreditorCode = "", ChequeNo = "", BankInSlipNo = "", BankStatementPgNo = 0, CurrencyCode = "THB", ExchangeRate = 0, BaseAmount = 0, LocalAmount = 0, CreditAmount = dt.CreditAmount, DebitAmount = dt.DebitAmount, Remark = "", BankStatementTotalPgNo = 0, }); }); result = glTransactionDAL.SaveList(glopening.GLTransactionDetails, transaction) == true ? 1 : 0; } if (result > 0) { transaction.Commit(); } else { transaction.Rollback(); } } catch (Exception) { if (currentTransaction == null) { transaction.Rollback(); } throw; } return(result > 0 ? true : false); }
public bool Save <T>(T item) where T : IContract { var result = 0; var gljournal = (GLJournal)(object)item; if (currentTransaction == null) { connection = db.CreateConnection(); connection.Open(); } var transaction = (currentTransaction == null ? connection.BeginTransaction() : currentTransaction); try { var lstActiveGLDetails = gljournal.GLJournalDetails.Where(x => x.Status == true).ToList(); gljournal.TotalCreditAmount = lstActiveGLDetails.Sum(x => x.BaseCreditAmount); gljournal.TotalDebitAmount = lstActiveGLDetails.Sum(x => x.BaseDebitAmount); var savecommand = db.GetStoredProcCommand(DBRoutine.SAVEGLJOURNAL); db.AddInParameter(savecommand, "Source", System.Data.DbType.String, gljournal.Source); db.AddInParameter(savecommand, "DocumentNo", System.Data.DbType.String, gljournal.DocumentNo); db.AddInParameter(savecommand, "DocumentDate", System.Data.DbType.DateTime, gljournal.DocumentDate); db.AddInParameter(savecommand, "BranchID", System.Data.DbType.Int16, gljournal.BranchID); db.AddInParameter(savecommand, "Remark", System.Data.DbType.String, gljournal.Remark); db.AddInParameter(savecommand, "CurrencyCode", System.Data.DbType.String, gljournal.CurrencyCode == null? "":gljournal.CurrencyCode); db.AddInParameter(savecommand, "ExchangeRate", System.Data.DbType.Decimal, gljournal.ExchangeRate); db.AddInParameter(savecommand, "TotalDebitAmount", System.Data.DbType.Decimal, gljournal.TotalDebitAmount); db.AddInParameter(savecommand, "TotalCreditAmount", System.Data.DbType.Decimal, gljournal.TotalCreditAmount); db.AddInParameter(savecommand, "CreatedBy", System.Data.DbType.String, gljournal.CreatedBy); db.AddInParameter(savecommand, "ModifiedBy", System.Data.DbType.String, gljournal.ModifiedBy); db.AddOutParameter(savecommand, "NewDocumentNo", System.Data.DbType.String, 25); result = db.ExecuteNonQuery(savecommand, transaction); if (result > 0) { var GLJournalDetailsItemDAL = new GLJournalDetailDAL(); var glTransactionDAL = new GLTransactionDAL(); // Get the New Quotation No. gljournal.DocumentNo = savecommand.Parameters["@NewDocumentNo"].Value.ToString(); short itr = 1; gljournal.GLJournalDetails.ForEach(dt => { dt.DocumentNo = gljournal.DocumentNo; dt.ItemNo = itr++; } ); result = Convert.ToInt16(GLJournalDetailsItemDAL.Delete(gljournal.DocumentNo, transaction)); result = GLJournalDetailsItemDAL.SaveList(lstActiveGLDetails, transaction) == true ? 1 : 0; var firstDayOfMonth = new DateTime(gljournal.DocumentDate.Year, gljournal.DocumentDate.Month, 1); gljournal.GLTransactionDetails = new List <GLTransaction>(); itr = 1; lstActiveGLDetails.ForEach(dt => { gljournal.GLTransactionDetails.Add(new GLTransaction { ItemNo = itr++, BranchID = gljournal.BranchID, AccountCode = dt.AccountCode, AccountDate = firstDayOfMonth, Source = "GL", DocumentType = "JV", DocumentNo = gljournal.DocumentNo, DocumentDate = DateTime.Now.Date, DebtorCode = "", CreditorCode = "", ChequeNo = "", BankInSlipNo = "", BankStatementPgNo = 0, CurrencyCode = "THB", ExchangeRate = 0, BaseAmount = 0, LocalAmount = 0, CreditAmount = dt.BaseCreditAmount, DebitAmount = dt.BaseDebitAmount, Remark = "", BankStatementTotalPgNo = 0, }); }); result = glTransactionDAL.Delete(gljournal.DocumentNo, gljournal.BranchID, transaction) == true ? 1 : 0; result = glTransactionDAL.SaveList(gljournal.GLTransactionDetails, transaction) == true ? 1 : 0; } if (result > 0) { transaction.Commit(); } else { transaction.Rollback(); } } catch (Exception ex) { if (currentTransaction == null) { transaction.Rollback(); } throw; } return(result > 0 ? true : false); }