Ejemplo n.º 1
0
 public ActionResult CustomerInvoicePayment([FromBody] CustomerInvoicePaymentModel customerInvoicePaymentModel)
 {
     return(Ok(_salesService.Payment(customerInvoicePaymentModel)));
 }
Ejemplo n.º 2
0
        public int Payment(CustomerInvoicePaymentModel customerInvoicePaymentModel)
        {
            int Id = 0;

            _serverContext.Database.BeginTransaction();
            var Invoice = (from a in _serverContext.LedgerMasters
                           where a.SubsidiaryLedgerAccountId == customerInvoicePaymentModel.CustomerId
                           select new { a.SubsidiaryLedgerAccountId });

            try
            {
                InvoicePayment invoice = new InvoicePayment();
                //invoice.LedgerMasterId = customerInvoicePaymentModel.LedgerMasterId;
                invoice.SubsidiaryLedgerAccountId = customerInvoicePaymentModel.CustomerId;
                invoice.InvoicePaymentAmount      = customerInvoicePaymentModel.InvoiceAmount;
                invoice.ChartOfAccountId          = customerInvoicePaymentModel.ChartOfAccountId;
                invoice.InvoicePaymentReferenceNo = customerInvoicePaymentModel.ReferenceNo;
                invoice.InvoicePaymentDate        = customerInvoicePaymentModel.PaymentDate;
                invoice.InvoicePaymentCreatedDate = DateTime.Now;
                _serverContext.InvoicePayments.Add(invoice);
                invoice.InvoicePaymentModifiedDate = DateTime.Now;
                _serverContext.SaveChanges();
                Id = invoice.Id;
                foreach (CustomerInvoicePostPaymentItemModel item in customerInvoicePaymentModel.Items)
                {
                    InvoicePaymentDetail invoicePaymentDetail = new InvoicePaymentDetail();
                    invoicePaymentDetail.InvoicePaymentId           = Id;
                    invoicePaymentDetail.LedgerMasterId             = item.Id;
                    invoicePaymentDetail.InvoicePaymentDetailAmount = item.Amount;
                    _serverContext.InvoicePaymentDetails.Add(invoicePaymentDetail);
                    _serverContext.SaveChanges();
                }

                foreach (var item in customerInvoicePaymentModel.Items)
                {
                    GeneralLedger generalLedger = new GeneralLedger
                    {
                        SubsidiaryLedgerAccountId = customerInvoicePaymentModel.CustomerId,
                        GeneralLedgerInvoiceNo    = string.Empty,
                        GeneralLedgerDate         = customerInvoicePaymentModel.PaymentDate,
                        GeneralLedgerReferenceNo  = customerInvoicePaymentModel.ReferenceNo,
                        GeneralLedgerType         = "PI",
                        LedgerMasterId            = item.Id
                    };
                    _serverContext.GeneralLedgers.Add(generalLedger);
                    _serverContext.SaveChanges();
                    GeneralLedgerDetail generalLedgerDetailDebit = new GeneralLedgerDetail();
                    generalLedgerDetailDebit.ChartOfAccountId               = customerInvoicePaymentModel.ChartOfAccountId;
                    generalLedgerDetailDebit.GeneralLedgerDetailMode        = "D";
                    generalLedgerDetailDebit.GeneralLedgerId                = generalLedger.Id;
                    generalLedgerDetailDebit.GeneralLedgerDetailAmount      = item.Amount;
                    generalLedgerDetailDebit.GeneralLedgerDetailDescription = string.Empty;
                    _serverContext.GeneralLedgerDetails.Add(generalLedgerDetailDebit);
                    _serverContext.SaveChanges();
                    GeneralLedgerDetail generalLedgerDetailCredit = new GeneralLedgerDetail();
                    generalLedgerDetailCredit.ChartOfAccountId               = ARTradeKey;
                    generalLedgerDetailCredit.GeneralLedgerDetailMode        = "C";
                    generalLedgerDetailCredit.GeneralLedgerId                = generalLedger.Id;
                    generalLedgerDetailCredit.GeneralLedgerDetailAmount      = item.Amount;
                    generalLedgerDetailCredit.GeneralLedgerDetailDescription = string.Empty;
                    _serverContext.GeneralLedgerDetails.Add(generalLedgerDetailCredit);
                    _serverContext.SaveChanges();
                }
                _serverContext.Database.CommitTransaction();
            }
            catch (Exception ex)
            {
                _serverContext.Database.RollbackTransaction();
            }
            return(Id);
        }