Beispiel #1
0
        public void update_Cancelled(Guid Id, string CancelNotes)
        {
            WebDBConnection.Update(db.Database, "Payments",
                                   DBConnection.getSqlParameter(PaymentsModel.COL_Id.Name, Id),
                                   DBConnection.getSqlParameter(PaymentsModel.COL_Cancelled.Name, 1),
                                   DBConnection.getSqlParameter(PaymentsModel.COL_CancelNotes.Name, CancelNotes)
                                   );
            ActivityLogsController.AddEditLog(db, Session, Id, string.Format(PaymentsModel.COL_CancelNotes.LogDisplay, CancelNotes));

            //Adjust sale invoice due amount
            List <PaymentItemsModel> paymentItems = PaymentItemsController.get(null, Id);
            List <SaleInvoicesModel> saleInvoices;

            foreach (PaymentItemsModel paymentitem in paymentItems)
            {
                saleInvoices = SaleInvoicesController.get(Session, paymentitem.ReferenceId.ToString());
                if (saleInvoices.Count > 0)
                {
                    WebDBConnection.Update(db.Database, "SaleInvoices",
                                           DBConnection.getSqlParameter(SaleInvoicesModel.COL_Id.Name, saleInvoices[0].Id),
                                           DBConnection.getSqlParameter(SaleInvoicesModel.COL_Due.Name, saleInvoices[0].Due + paymentitem.Amount)
                                           );
                }
            }

            db.SaveChanges();
        }
Beispiel #2
0
        public ActionResult setCreateViewBagsAndReturn(string saleInvoiceIdList)
        {
            List <SaleInvoiceItemsModel> SaleInvoiceItems = SaleInvoiceItemsController.get(null, null, saleInvoiceIdList, null, null, null, null, null, null, null)
                                                            .OrderBy(x => x.SaleInvoices_No)
                                                            .ThenBy(x => x.RowNo)
                                                            .ToList();

            ViewBag.TotalAmount = SaleInvoiceItems.Sum(x => x.TotalAmount);

            List <SaleInvoicesModel> saleinvoices = SaleInvoicesController.get(Session, saleInvoiceIdList);

            ViewBag.DueAmount = saleinvoices.Sum(x => x.Due);

            ViewBag.id = saleInvoiceIdList;
            //BanksController.setDropDownListViewBag(this);
            ConsignmentsController.setDropDownListViewBag(this);

            return(View(SaleInvoiceItems));
        }
Beispiel #3
0
        public ActionResult Create(string id, string JsonPayments)
        {
            List <SaleInvoicesModel> saleinvoices = SaleInvoicesController.get(Session, id).OrderBy(x => x.Timestamp).ToList();

            if (ModelState.IsValid)
            {
                PaymentsModel payment = JsonConvert.DeserializeObject <PaymentsModel>(JsonPayments);
                payment.Id        = Guid.NewGuid();
                payment.No        = Util.incrementHexNumber(getLastNo());
                payment.Timestamp = Helper.getCurrentDateTime();

                if (payment.DebitAmount == 0)
                {
                    payment.DebitBank      = null;
                    payment.DebitNumber    = null;
                    payment.DebitOwnerName = null;
                    payment.DebitRefNo     = null;
                }

                if (payment.ConsignmentAmount == 0)
                {
                    payment.Consignments_Id = null;
                }

                //create payment items and update sale invoice due amount
                int RemainingPaymentAmount = payment.DebitAmount + payment.CashAmount + payment.ConsignmentAmount;
                int paymentItemAmount      = 0;
                int dueBefore = 0;
                int dueAfter  = 0;
                foreach (SaleInvoicesModel saleinvoice in saleinvoices)
                {
                    dueBefore = saleinvoice.Due;
                    dueAfter  = saleinvoice.Due;
                    if (RemainingPaymentAmount == 0)
                    {
                        break;
                    }
                    else
                    {
                        if (RemainingPaymentAmount >= saleinvoice.Due)
                        {
                            paymentItemAmount = saleinvoice.Due;
                        }
                        else
                        {
                            paymentItemAmount = RemainingPaymentAmount;
                        }

                        RemainingPaymentAmount -= paymentItemAmount;
                        dueAfter -= paymentItemAmount;

                        SaleInvoicesController.update_Due(Session, db, saleinvoice.Id, saleinvoice.Due, saleinvoice.Due - paymentItemAmount);
                        saleinvoice.Due -= paymentItemAmount;
                    }

                    PaymentItemsController.add(db, payment.Id, new PaymentItemsModel {
                        Id          = Guid.NewGuid(),
                        Payments_Id = payment.Id,
                        ReferenceId = saleinvoice.Id,
                        Amount      = paymentItemAmount,
                        DueBefore   = dueBefore,
                        DueAfter    = dueAfter
                    });
                }

                //create petty cash
                if (payment.CashAmount > 0)
                {
                    PettyCashRecordsController.add(db, new PettyCashRecordsModel
                    {
                        Id          = Guid.NewGuid(),
                        Branches_Id = Helper.getActiveBranchId(Session),
                        ReferenceId = payment.Id,
                        No          = "",
                        Timestamp   = payment.Timestamp,
                        PettyCashRecordsCategories_Id = SettingsController.get().AutoEntryForCashPayments.Value,
                        Notes                = "Cash Payment [" + payment.No + "]",
                        Amount               = payment.CashAmount,
                        Approved             = false,
                        UserAccounts_Id      = (Guid)UserAccountsController.getUserId(Session),
                        ExpenseCategories_Id = null
                    });
                }

                add(payment);

                return(RedirectToAction(nameof(Print), new { id = payment.Id }));
            }

            return(setCreateViewBagsAndReturn(id));
        }