Beispiel #1
0
        public ActionResult PaymentDelete(int id)
        {
            ActionResult actionResult;

            try
            {
                LedgerPosting postingObj = this.postingService.GetById(new int?(id));
                foreach (LedgerPosting item in this.postingService.GetAll(postingObj.VoucherNo, true))
                {
                    item.IsActive = false;
                    this.postingService.Update(item, item.Id);
                }
                PartyBalanceService partyBalanceService = this.partyBalanceService;
                int?         ledgerId   = postingObj.LedgerId;
                PartyBalance paymentObj = partyBalanceService.GetByVoucher((ledgerId.HasValue ? ledgerId.GetValueOrDefault() : 0), postingObj.VoucherNo);
                this.partyBalanceService.Delete(paymentObj.PartyBalanceId);
                AccountLedger   customer        = this.accledgerService.GetById(postingObj.LedgerId);
                CustomerService customerService = new CustomerService();
                ledgerId = postingObj.LedgerId;
                rptIndividualLedger_Result due = customerService.GetBalance((ledgerId.HasValue ? ledgerId.GetValueOrDefault() : 0));
                string  balanceText            = "";
                decimal?balance = due.Balance;
                decimal num     = new decimal();
                if ((balance.GetValueOrDefault() < num ? !balance.HasValue : true))
                {
                    balance     = due.Balance;
                    balanceText = string.Concat("Balance with Dada Rice Tk=", string.Format("{0:#,#.}", decimal.Round((balance.HasValue ? balance.GetValueOrDefault() : decimal.Zero)), ""), "=");
                }
                else
                {
                    decimal minusOne = decimal.MinusOne;
                    balance     = due.Balance;
                    balanceText = string.Concat("Balance with Dada Rice Tk=", string.Format("{0:#,#.}", minusOne * decimal.Round((balance.HasValue ? balance.GetValueOrDefault() : decimal.Zero)), ""), "=");
                }
                var isSendSMS = false;
                if (isSendSMS)
                {
                    SMSEmailService sMSEmailService = new SMSEmailService();
                    string[]        ledgerName      = new string[] { "Dear ", customer.LedgerName, ",Tk=", null, null, null, null, null, null };
                    balance       = postingObj.Credit;
                    ledgerName[3] = string.Format("{0:#,#.}", decimal.Round((balance.HasValue ? balance.GetValueOrDefault() : decimal.Zero)), "");
                    ledgerName[4] = " payment was wrong posted. Your Ref No:";
                    ledgerName[5] = postingObj.VoucherNo;
                    ledgerName[6] = " has been deleted,";
                    ledgerName[7] = balanceText;
                    ledgerName[8] = " Dada Rice.";
                    sMSEmailService.SendOneToOneSingleSms("01739110321", string.Concat(ledgerName));
                }
                actionResult = base.Json("Sucess", 0);
            }
            catch (Exception exception)
            {
                actionResult = base.Json(exception.Message, 0);
            }
            return(actionResult);
        }
        public ActionResult Edit(Supplier model, decimal OpeningBalance, string CrOrDr, int create)
        {
            if (model == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Supplier supplier = db.GetById(model.Id);

            if (supplier == null)
            {
                return(HttpNotFound());
            }
            supplier.Address            = model.Address;
            supplier.City               = model.City;
            supplier.Code               = model.Code;
            supplier.Name               = model.Name;
            supplier.Phone              = model.Phone;
            supplier.ContactPersonName  = model.ContactPersonName;
            supplier.ContactPersonPhone = model.ContactPersonPhone;
            supplier.Email              = model.Email;
            supplier.IsActive           = true;
            supplier.UpdateDate         = DateTime.Now;
            supplier.UpdateBy           = CurrentSession.GetCurrentSession().UserName;
            db.Update(supplier, model.Id);

            //account ledger update
            AccountLedger ledger = new AccountLedgerService().GetById(supplier.LedgerId);

            ledger.Address           = supplier.Address;
            ledger.BankAccountNumber = "";
            ledger.BillByBill        = true;
            ledger.BranchCode        = "";
            ledger.BranchName        = "";
            ledger.CreditLimit       = 0.0m;
            ledger.CreditPeriod      = 1;
            ledger.Email             = supplier.Email;
            ledger.IsDefault         = false;
            ledger.LedgerName        = supplier.Name;

            ledger.Extra2         = supplier.Code;
            ledger.Mobile         = supplier.ContactPersonPhone;
            ledger.Phone          = supplier.Phone;
            ledger.OpeningBalance = OpeningBalance;
            var saved = Accounts.Update(ledger, supplier.LedgerId ?? 0);

            if (OpeningBalance > 0.0m)
            {
                var           party = new PartyBalanceService().GetAll().Where(a => a.VoucherTypeId == 1 && a.LedgerId == supplier.LedgerId).FirstOrDefault();
                LedgerPosting post  = new LedgerPostingService().GetAll().Where(a => a.VoucherTypeId == 1 && a.LedgerId == supplier.LedgerId).FirstOrDefault();
                if (post == null)
                {
                    if (party == null)
                    {
                        party = new PartyBalance();
                    }
                    post             = new LedgerPosting();
                    post.LedgerId    = supplier.LedgerId;
                    post.PostingDate = DateTime.Now;
                    if (CrOrDr == "Cr")
                    {
                        post.Credit  = ledger.OpeningBalance;
                        party.Credit = ledger.OpeningBalance;
                    }
                    if (CrOrDr == "Dr")
                    {
                        party.Debit = ledger.OpeningBalance;
                        post.Debit  = ledger.OpeningBalance;
                    }
                    post.VoucherTypeId = 1;
                    post.VoucherNo     = ledger.Id.ToString();
                    post.InvoiceNo     = ledger.Id.ToString();
                    var postingResult = postingService.Save(post);
                    party.AgainstInvoiceNo = postingResult.Id.ToString();
                }
                else
                {
                    if (party == null)
                    {
                        party = new PartyBalance();
                    }
                    if (CrOrDr == "Cr")
                    {
                        post.Credit  = ledger.OpeningBalance;
                        party.Credit = ledger.OpeningBalance;
                    }
                    if (CrOrDr == "Dr")
                    {
                        party.Debit = ledger.OpeningBalance;
                        post.Debit  = ledger.OpeningBalance;
                    }
                    postingService.Update(post, post.Id);
                }
                if (party == null || party.PartyBalanceId == 0)
                {
                    party = new PartyBalance();
                    if (CrOrDr == "Cr")
                    {
                        post.Credit  = ledger.OpeningBalance;
                        party.Credit = ledger.OpeningBalance;
                    }
                    if (CrOrDr == "Dr")
                    {
                        party.Debit = ledger.OpeningBalance;
                        post.Debit  = ledger.OpeningBalance;
                    }
                    party.LedgerId        = supplier.LedgerId ?? 0;
                    party.CreditPeriod    = 60;
                    party.FinancialYearId = CurrentSession.GetCurrentSession().FinancialYear;
                    party.PostingDate     = DateTime.Now;
                    party.VoucherTypeId   = 1;
                    party.extra1          = "Opening Balance";
                    partyBalanceService.Save(party);
                }
                else
                {
                    if (CrOrDr == "Cr")
                    {
                        post.Credit  = ledger.OpeningBalance;
                        party.Credit = ledger.OpeningBalance;
                    }
                    if (CrOrDr == "Dr")
                    {
                        party.Debit = ledger.OpeningBalance;
                        post.Debit  = ledger.OpeningBalance;
                    }

                    party.PostingDate = DateTime.Now;
                    party.Balance     = party.Balance + OpeningBalance;
                    partyBalanceService.Update(party, party.PartyBalanceId);
                }
            }
            return(Json("Updated", JsonRequestBehavior.AllowGet));
            //return View();
        }