Exemplo n.º 1
0
        public JsonResult GetCreditorOutStandingDocuments(string creditorCode, string bankCode, string matchDocumentNo)
        {
            var cbpaymentsetoffdetails = new NetStock.DataFactory.CBPaymentSetOffDetailDAL().GetCreditorOutStandingDocuments(creditorCode, matchDocumentNo);

            var bankaccount = new NetStock.BusinessFactory.BankBO().GetBank(new Bank {
                BankCode = bankCode
            }).BankAccount;

            var creditorAccount = new NetStock.BusinessFactory.CreditorBO().GetCreditor(new Creditor {
                CreditorCode = creditorCode
            }).CreditorAccount;
            /* Debit Credit Account start */
            var debitCreditObj = Utility.GetAccountType(creditorAccount);
            var creditorDC     = debitCreditObj != null ? (!string.IsNullOrWhiteSpace(debitCreditObj.DebitCredit) ? debitCreditObj.DebitCredit : "DEBIT") : "DEBIT";

            debitCreditObj = Utility.GetAccountType(bankaccount);
            var bankDC = debitCreditObj != null ? (!string.IsNullOrWhiteSpace(debitCreditObj.DebitCredit) ? debitCreditObj.DebitCredit : "DEBIT") : "DEBIT";

            debitCreditObj = Utility.GetAccountType(Utility.BANKCHARGESACCOUNTCODE);
            var bankChargesDC = debitCreditObj != null ? (!string.IsNullOrWhiteSpace(debitCreditObj.DebitCredit) ? debitCreditObj.DebitCredit : "DEBIT") : "DEBIT";

            /* Debit Credit Account end */

            return(Json(new {
                SetOffDetailsData = cbpaymentsetoffdetails,
                CreditorAccount = creditorAccount,
                BankAccount = bankaccount,
                CreditorDebitCredit = creditorDC,
                bankDebitCredit = bankDC,
                bankChargesDebitCredit = bankChargesDC
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public bool Save <T>(T item) where T : IContract
        {
            var result = 0;

            var cbpayment = (CBPayment)(object)item;

            if (currentTransaction == null)
            {
                connection = db.CreateConnection();
                connection.Open();
            }

            var transaction = (currentTransaction == null ? connection.BeginTransaction() : currentTransaction);


            try
            {
                var savecommand = db.GetStoredProcCommand(DBRoutine.SAVECBPAYMENT);

                db.AddInParameter(savecommand, "DocumentNo", System.Data.DbType.String, cbpayment.DocumentNo);
                db.AddInParameter(savecommand, "DocumentDate", System.Data.DbType.DateTime, cbpayment.DocumentDate);
                db.AddInParameter(savecommand, "BranchID", System.Data.DbType.Int16, cbpayment.BranchID);
                db.AddInParameter(savecommand, "PaymentType", System.Data.DbType.String, cbpayment.PaymentType ?? "");
                db.AddInParameter(savecommand, "BankCode", System.Data.DbType.String, cbpayment.BankCode);
                db.AddInParameter(savecommand, "CreditorCode", System.Data.DbType.String, cbpayment.CreditorCode ?? "");
                db.AddInParameter(savecommand, "PayeeName", System.Data.DbType.String, cbpayment.PayeeName ?? "");
                db.AddInParameter(savecommand, "BankAccount", System.Data.DbType.String, cbpayment.BankAccount ?? "");
                db.AddInParameter(savecommand, "BankChargesAccount", System.Data.DbType.String, cbpayment.BankChargesAccount ?? "");
                db.AddInParameter(savecommand, "CreditorAccount", System.Data.DbType.String, cbpayment.CreditorAccount ?? "");
                db.AddInParameter(savecommand, "ChequeNo", System.Data.DbType.String, cbpayment.ChequeNo ?? "");
                db.AddInParameter(savecommand, "ChequeDate", System.Data.DbType.DateTime, cbpayment.ChequeDate.ToString("dd-MM-yyyy") == "01-01-0001" ? (object)DBNull.Value : cbpayment.ChequeDate);
                db.AddInParameter(savecommand, "CurrencyCode", System.Data.DbType.String, cbpayment.CurrencyCode ?? "THB");
                db.AddInParameter(savecommand, "ExchangeRate", System.Data.DbType.Decimal, cbpayment.ExchangeRate);
                db.AddInParameter(savecommand, "BasePaymentAmount", System.Data.DbType.Decimal, cbpayment.BasePaymentAmount);
                db.AddInParameter(savecommand, "BaseApplyAmount", System.Data.DbType.Decimal, cbpayment.BaseApplyAmount);
                db.AddInParameter(savecommand, "LocalPaymentAmount", System.Data.DbType.Decimal, cbpayment.LocalPaymentAmount);
                db.AddInParameter(savecommand, "LocalApplyAmount", System.Data.DbType.Decimal, cbpayment.LocalApplyAmount);
                db.AddInParameter(savecommand, "LocalDiscountAmount", System.Data.DbType.Decimal, cbpayment.LocalDiscountAmount);
                db.AddInParameter(savecommand, "LocalBankChargesAmount", System.Data.DbType.Decimal, cbpayment.LocalBankChargesAmount);
                db.AddInParameter(savecommand, "Remark", System.Data.DbType.String, cbpayment.Remark ?? "");
                db.AddInParameter(savecommand, "AccountDate", System.Data.DbType.DateTime, cbpayment.AccountDate.ToString("dd-MM-yyyy") == "01-01-0001" ? (object)DBNull.Value : cbpayment.AccountDate);
                db.AddInParameter(savecommand, "Source", System.Data.DbType.String, cbpayment.Source);

                db.AddInParameter(savecommand, "IsWHTax", System.Data.DbType.Boolean, cbpayment.IsWHTax);
                db.AddInParameter(savecommand, "WHPercent", System.Data.DbType.Int16, cbpayment.WHPercent);
                db.AddInParameter(savecommand, "WHAmount", System.Data.DbType.Decimal, cbpayment.WHAmount);
                db.AddInParameter(savecommand, "IsVAT", System.Data.DbType.Boolean, cbpayment.IsVAT);
                db.AddInParameter(savecommand, "TaxAmount", System.Data.DbType.Decimal, cbpayment.TaxAmount);



                db.AddInParameter(savecommand, "NetAmount", System.Data.DbType.Decimal, cbpayment.NetAmount);


                db.AddInParameter(savecommand, "CreatedBy", System.Data.DbType.String, cbpayment.CreatedBy);
                db.AddInParameter(savecommand, "ModifiedBy", System.Data.DbType.String, cbpayment.ModifiedBy);
                db.AddOutParameter(savecommand, "NewDocumentNo", System.Data.DbType.String, 25);


                result = db.ExecuteNonQuery(savecommand, transaction);

                if (result > 0)
                {
                    var cbPaymentDetailsItemDAL       = new CBPaymentDetailDAL();
                    var cbPaymentDetailsSetOffItemDAL = new CBPaymentSetOffDetailDAL();
                    var cbpaymentgldetailsItemDAL     = new CBPaymentGlDetailDAL();
                    var cbPaymentgltransactionItemDAL = new GLTransactionDAL();

                    short detailitem = 1;


                    // Get the New Quotation No.
                    cbpayment.DocumentNo = savecommand.Parameters["@NewDocumentNo"].Value.ToString();

                    /* Save CBPaymentSetOffDetails if the CBPayment Type ='CREDITOR' */


                    if (cbpayment.CBPaymentSetOffDetails != null)
                    {
                        result = Convert.ToInt16(cbPaymentDetailsSetOffItemDAL.Delete(cbpayment.DocumentNo, transaction));

                        cbpayment.CBPaymentSetOffDetails.ForEach(dt =>
                        {
                            dt.DocumentNo        = cbpayment.DocumentNo;
                            dt.CreatedBy         = cbpayment.CreatedBy;
                            dt.ModifiedBy        = cbpayment.ModifiedBy;
                            dt.CurrencyCode      = cbpayment.CurrencyCode;
                            dt.MatchDocumentDate = cbpayment.DocumentDate;
                            dt.CreditorCode      = cbpayment.CreditorCode;
                            dt.SetOffDate        = cbpayment.DocumentDate;
                        });


                        result = cbPaymentDetailsSetOffItemDAL.SaveList(cbpayment.CBPaymentSetOffDetails, transaction) == true ? 1 : 0;
                    }



                    /* Save CBPaymentGLDetails if the CBPayment Type ='CREDITOR' */


                    if (cbpayment.CBPaymentGLDetails != null)
                    {
                        result = Convert.ToInt16(cbpaymentgldetailsItemDAL.Delete(cbpayment.DocumentNo, transaction));

                        cbpayment.CBPaymentGLDetails.ForEach(dt =>
                        {
                            dt.DocumentNo = cbpayment.DocumentNo;
                        });


                        result = cbpaymentgldetailsItemDAL.SaveList(cbpayment.CBPaymentGLDetails, transaction) == true ? 1 : 0;
                    }

                    if (cbpayment.PaymentType == "CREDITOR")
                    {
                        cbpayment.GLTransactionDetails = new List <GLTransaction>();


                        cbpayment.CBPaymentGLDetails.ForEach(gl =>
                        {
                            var gltransaction = new GLTransaction();

                            gltransaction.AccountCode            = gl.AccountCode;
                            gltransaction.AccountDate            = cbpayment.DocumentDate;
                            gltransaction.BankInSlipNo           = "";
                            gltransaction.BankStatementPgNo      = 0;
                            gltransaction.BankStatementTotalPgNo = 0;
                            gltransaction.BaseAmount             = gl.TotalAmount;
                            gltransaction.BranchID     = cbpayment.BranchID;
                            gltransaction.ChequeNo     = "";
                            gltransaction.CreditAmount = 0;
                            gltransaction.CreditorCode = cbpayment.CreditorCode;
                            gltransaction.CurrencyCode = cbpayment.CurrencyCode;
                            gltransaction.DebitAmount  = 0;
                            gltransaction.DebitCredit  = "";
                            gltransaction.DebtorCode   = "";
                            gltransaction.DetailRemark = cbpayment.Remark;
                            gltransaction.DocumentType = "PAY";
                            gltransaction.DocumentNo   = cbpayment.DocumentNo;
                            gltransaction.DocumentDate = cbpayment.DocumentDate;
                            gltransaction.Amount       = gl.TotalAmount;
                            gltransaction.Remark       = cbpayment.Remark;
                            gltransaction.ItemNo       = Convert.ToInt16(gl.ItemNo);
                            gltransaction.Source       = "CB";
                            gltransaction.AccountDate  = cbpayment.DocumentDate;
                            gltransaction.ExchangeRate = 0;
                            gltransaction.Status       = true;
                            gltransaction.Year         = 0;



                            cbpayment.GLTransactionDetails.Add(gltransaction);
                        });
                    }



                    if (cbpayment.CBPaymentDetails != null)
                    {
                        result = Convert.ToInt16(cbPaymentDetailsItemDAL.Delete(cbpayment.DocumentNo, transaction));

                        detailitem = 1;

                        cbpayment.CBPaymentDetails.ForEach(dt =>
                        {
                            dt.DocumentNo = cbpayment.DocumentNo;
                            dt.ItemNo     = detailitem++;
                        });

                        result = cbPaymentDetailsItemDAL.SaveList(cbpayment.CBPaymentDetails, transaction) == true ? 1 : 0;
                    }


                    if (cbpayment.GLTransactionDetails != null)
                    {
                        detailitem = 1;
                        if (cbpayment.PaymentType != "CREDITOR")
                        {
                            cbpayment.GLTransactionDetails.ForEach(dt =>
                            {
                                dt.DocumentNo   = cbpayment.DocumentNo;
                                dt.CurrencyCode = cbpayment.CurrencyCode;
                                dt.CreditorCode = cbpayment.CreditorCode;
                                dt.DocumentDate = cbpayment.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     = cbpayment.BranchID;
                                dt.AccountDate  = cbpayment.DocumentDate;
                                dt.DocumentType = "PAY";
                            });
                        }

                        //result = Convert.ToInt16(cbPaymentgltransactionItemDAL.Delete(cbpayment.DocumentNo, transaction));
                        result = cbPaymentgltransactionItemDAL.SaveList(cbpayment.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);
        }