Example #1
0
        public IActionResult SaveReceipt([FromBody] dynamic receiptDto)
        {
            string[] errors = null;

            try
            {
                if (!ModelState.IsValid)
                {
                    errors = new string[ModelState.ErrorCount];
                    foreach (var val in ModelState.Values)
                    {
                        for (int i = 0; i < ModelState.ErrorCount; i++)
                        {
                            errors[i] = val.Errors[i].ErrorMessage;
                        }
                    }

                    return(new BadRequestObjectResult(errors));
                }

                var bank = _financialService.GetCashAndBanks().Where(id => id.Id == (int)receiptDto.AccountToDebitId).FirstOrDefault();

                var salesReceipt = new Core.Domain.Sales.SalesReceiptHeader();
                salesReceipt.Date             = receiptDto.ReceiptDate;
                salesReceipt.CustomerId       = receiptDto.CustomerId;
                salesReceipt.AccountToDebitId = bank.AccountId;
                salesReceipt.Amount           = receiptDto.Amount;

                var customer = _salesService.GetCustomerById((int)receiptDto.CustomerId);
                if (customer.CustomerAdvancesAccountId != (int)receiptDto.AccountToCreditId)
                {
                    throw new Exception("Invalid account.");
                }

                var salesReceiptLine = new Core.Domain.Sales.SalesReceiptLine();
                salesReceiptLine.AccountToCreditId = receiptDto.AccountToCreditId;
                salesReceiptLine.AmountPaid        = receiptDto.Amount;
                salesReceiptLine.Amount            = receiptDto.Amount;
                salesReceiptLine.Quantity          = 1;

                salesReceipt.SalesReceiptLines.Add(salesReceiptLine);

                _salesService.AddSalesReceiptNoInvoice(salesReceipt);

                return(new ObjectResult(Ok()));
            }
            catch (Exception ex)
            {
                errors = new string[1] {
                    ex.InnerException != null ? ex.InnerException.Message : ex.Message
                };
                return(new BadRequestObjectResult(errors));
            }
        }
Example #2
0
        public ActionResult SaveReceipt(Models.ViewModels.Sales.AddSalesReceipt model)
        {
            if (model.AccountToDebitId.Value == -1 || model.CustomerId.Value == -1)
                return View(model);

            var receipt = new SalesReceiptHeader()
            {
                AccountToDebitId = model.AccountToDebitId,
                CustomerId = model.CustomerId.Value,
                Date = model.Date,
                CreatedBy = User.Identity.Name,
                CreatedOn = DateTime.Now,
                ModifiedBy = User.Identity.Name,
                ModifiedOn = DateTime.Now,
                Amount = model.PaymentAmount
            };

            receipt.SalesReceiptLines.Add(new SalesReceiptLine()
            {
                AccountToCreditId = model.AccountToCreditId,
                Amount = model.Amount,
                AmountPaid = model.PaymentAmount,
                CreatedBy = User.Identity.Name,
                CreatedOn = DateTime.Now,
                ModifiedBy = User.Identity.Name,
                ModifiedOn = DateTime.Now,
            });

            _salesService.AddSalesReceiptNoInvoice(receipt);
            return RedirectToAction("Receipts");
        }
Example #3
0
        public ActionResult SaveSalesReceipt(Models.ViewModels.Sales.AddSalesReceipt model)
        {
            var receipt = new SalesReceiptHeader()
            {
                AccountToDebitId = model.AccountToDebitId,
                //SalesInvoiceHeaderId = model.SalesInvoiceId,
                CustomerId = model.CustomerId.Value,
                Date = model.Date,
                CreatedBy = User.Identity.Name,
                CreatedOn = DateTime.Now,
                ModifiedBy = User.Identity.Name,
                ModifiedOn = DateTime.Now,
            };
            foreach(var line in model.AddSalesReceiptLines)
            {
                if(line.AmountToPay > line.Amount)
                    return RedirectToAction("SalesInvoices");

                receipt.SalesReceiptLines.Add(new SalesReceiptLine()
                {
                    SalesInvoiceLineId = line.SalesInvoiceLineId,
                    ItemId = line.ItemId,
                    MeasurementId = line.MeasurementId,
                    Quantity = line.Quantity,
                    Discount = line.Discount,
                    Amount = line.Amount,
                    AmountPaid = line.AmountToPay,
                    CreatedBy = User.Identity.Name,
                    CreatedOn = DateTime.Now,
                    ModifiedBy = User.Identity.Name,
                    ModifiedOn = DateTime.Now,
                });
            }
            _salesService.AddSalesReceipt(receipt);
            return RedirectToAction("SalesInvoices");
        }
Example #4
0
 public void UpdateSalesReceipt(SalesReceiptHeader salesReceipt)
 {
     _salesReceiptRepo.Update(salesReceipt);
 }
Example #5
0
        public void AddSalesReceiptNoInvoice(SalesReceiptHeader salesReceipt)
        {
            var customer = _customerRepo.GetById(salesReceipt.CustomerId);
            var glHeader = _financialService.CreateGeneralLedgerHeader(DocumentTypes.SalesReceipt, salesReceipt.Date, string.Empty);
            var debit = _financialService.CreateGeneralLedgerLine(TransactionTypes.Dr, salesReceipt.AccountToDebitId.Value, salesReceipt.Amount);
            glHeader.GeneralLedgerLines.Add(debit);

            foreach (var line in salesReceipt.SalesReceiptLines)
            {
                var credit = _financialService.CreateGeneralLedgerLine(TransactionTypes.Cr, line.AccountToCreditId.Value, line.AmountPaid);
                glHeader.GeneralLedgerLines.Add(credit);
            }

            if (_financialService.ValidateGeneralLedgerEntry(glHeader))
            {
                salesReceipt.GeneralLedgerHeader = glHeader;

                salesReceipt.No = GetNextNumber(SequenceNumberTypes.SalesReceipt).ToString();
                _salesReceiptRepo.Insert(salesReceipt);
            }
        }
Example #6
0
        public void AddSalesReceipt(SalesReceiptHeader salesReceipt)
        {
            var customer = _customerRepo.GetById(salesReceipt.CustomerId);
            var glHeader = _financialService.CreateGeneralLedgerHeader(DocumentTypes.SalesReceipt, salesReceipt.Date, string.Empty);
            var debit = _financialService.CreateGeneralLedgerLine(DrOrCrSide.Dr, salesReceipt.AccountToDebitId.Value, salesReceipt.SalesReceiptLines.Sum(i => i.AmountPaid));
            var credit = _financialService.CreateGeneralLedgerLine(DrOrCrSide.Cr, customer.AccountsReceivableAccountId.Value, salesReceipt.SalesReceiptLines.Sum(i => i.AmountPaid));
            glHeader.GeneralLedgerLines.Add(debit);
            glHeader.GeneralLedgerLines.Add(credit);

            if (_financialService.ValidateGeneralLedgerEntry(glHeader))
            {
                salesReceipt.GeneralLedgerHeader = glHeader;

                salesReceipt.No = GetNextNumber(SequenceNumberTypes.SalesReceipt).ToString();
                _salesReceiptRepo.Insert(salesReceipt);
            }
        }