Пример #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();
        }
Пример #2
0
        public JsonResult Ajax_GetDetails(Guid id)
        {
            UserAccountRolesModel access = UserAccountsController.getUserAccess(Session);

            List <PaymentItemsModel> models = PaymentItemsController.get(null, id);
            string content = string.Format(@"
                    <div class='table-responsive'>
                        <table class='table table-striped table-bordered'>
                            <thead>
                                <tr>
                                    <th>Invoice</th>
                                    <th class='text-right'>Due before</th>
                                    <th class='text-right'>Payment</th>
                                    <th class='text-right'>Due now</th>
                                </tr>
                            </thead>
                            <tbody>
                ");

            string saleInvoiceLink;

            foreach (PaymentItemsModel model in models)
            {
                saleInvoiceLink = !access.SaleInvoices_View ? model.SaleInvoices_No :
                                  string.Format("<a href='/SaleInvoices?FILTER_chkDateFrom=false&FILTER_chkDateTo=false&FILTER_Keyword={0}' target='_blank'>{0}</a>", model.SaleInvoices_No);

                content += string.Format(@"
                            <tr>
                                <td style='width:50px;'>{0}</td>
                                <td class='text-right'>{1:N0}</td>
                                <td class='text-right'><strong>{2:N0}</strong></td>
                                <td class='text-right'>{3:N0}</td>
                            </tr>
                        ",
                                         saleInvoiceLink,
                                         model.DueBefore,
                                         model.Amount,
                                         model.DueAfter
                                         );
            }

            PaymentsModel payment = get(id);

            content += string.Format(@"
                        </tbody></table></div>
                        <div class='mt-2'>
                            <div class='h3 ml-2 float-right font-weight-bold'>TOTAL: {0:N0}</div>
                        </div>
                    ",
                                     payment.CashAmount + payment.DebitAmount + payment.ConsignmentAmount
                                     );

            return(Json(new { content = content }, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        /* PRINT **********************************************************************************************************************************************/

        // GET: Payments/Print
        public ActionResult Print(Guid?id)
        {
            if (id == null || !UserAccountsController.getUserAccess(Session).Payments_View)
            {
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }

            PaymentsModel model = get((Guid)id);

            ViewBag.InvoiceHeaderText    = new BranchesController().get(Helper.getActiveBranchId(Session)).InvoiceHeaderText;
            ViewData["SaleInvoiceItems"] = SaleInvoiceItemsController.get(null, null, null, model.Id, null, null, null, null, null, null)
                                           .OrderBy(x => x.SaleInvoices_No)
                                           .ThenBy(x => x.RowNo)
                                           .ToList();
            ViewData["PaymentItems"] = PaymentItemsController.get(null, model.Id);
            ViewBag.TotalAmount      = model.CashAmount + model.ConsignmentAmount + model.DebitAmount;

            return(View(model));
        }
Пример #4
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));
        }