public ActionResult Create(Supplier supplier, decimal OpeningBalance, string CrOrDr, int create)
        {
            try
            {
                var result = supplier;
                if (ModelState.IsValid)
                {
                    supplier.CreationDate = DateTime.Now;
                    supplier.UpdateDate   = DateTime.Now;
                    supplier.Creator      = CurrentSession.GetCurrentSession().UserName;
                    supplier.IsActive     = true;
                    AccountLedger ledger = new AccountLedger();

                    var accountGroup = new AccountGroupService().GetById(22); //sundry creditor
                    ledger.AccountGroupId    = 22;
                    ledger.Address           = supplier.Address;
                    ledger.BankAccountNumber = "";
                    ledger.BillByBill        = true;
                    ledger.BranchCode        = "";
                    ledger.BranchName        = "";
                    ledger.CreditLimit       = 0.0m;
                    ledger.CreditPeriod      = 1;
                    ledger.CrOrDr            = Accounts.CheckDrOrCr(accountGroup.Nature);
                    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.Save(ledger);
                    supplier.LedgerId = saved.Id;
                    result            = db.Save(supplier);
                    if (ledger.OpeningBalance > 0.0m)
                    {
                        var           party = new PartyBalance();
                        LedgerPosting post  = new LedgerPosting();
                        post.InvoiceNo   = "";
                        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();
                        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);
                    }
                }
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(ex, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #2
0
        public ActionResult Authorize(PaymentAuthorizationRequest request)
        {
            var payment = _paymentService.GetPaymentById(request.Id);

            if (payment == null)
            {
                return(Json("Failed:Payment not found to authorized!!", JsonRequestBehavior.AllowGet));
            }
            decimal?credit;

            //credit
            foreach (var details in payment.PaymentDetails)
            {
                var item = new LedgerPosting();
                item.LedgerId      = details.LedgerId;
                item.CreatedBy     = CurrentSession.GetCurrentSession().UserId;
                item.Credit        = 0;
                item.Debit         = request.Amount;
                item.InvoiceNo     = payment.InvoiceNo;
                item.VoucherNo     = payment.VoucherNo;
                item.PostingDate   = payment.LedgerDate;
                item.ChequeDate    = details.ChequeDate;
                item.ChequeNo      = details.ChequeNo;
                item.VoucherTypeId = payment.VoucherTypeId;
                item.Extra1        = "Voucher:" + payment.VoucherNo + " " + payment.Narration + "|" + request.Notes;
                postingService.Save(item);
                break;
            }
            //debit
            LedgerPosting posting = new LedgerPosting();

            posting.ChequeDate    = DateTime.Now;
            posting.VoucherNo     = payment.VoucherNo;
            posting.ChequeNo      = "";
            posting.VoucherTypeId = (int)BAL.VoucherTypeEnum.PaymentVoucher;
            posting.LedgerId      = payment.LedgerId;
            posting.PostingDate   = payment.LedgerDate;
            posting.Credit        = request.Amount;
            posting.Debit         = 0;
            posting.Extra1        = "Voucher:" + payment.VoucherNo + " " + request.Notes;
            postingService.Save(posting);
            //balance
            //party balance
            PartyBalance balance = new PartyBalance();

            balance.AgainstVoucherTypeId = 4;
            balance.VoucherNo            = payment.VoucherNo;
            balance.PostingDate          = payment.LedgerDate;
            balance.LedgerId             = payment.LedgerId ?? 0;
            balance.Debit         = request.Amount;
            balance.Credit        = 0;
            balance.VoucherTypeId = (int)BAL.VoucherTypeEnum.PaymentVoucher;
            balance.extra1        = "Payment Invoice: " + payment.VoucherNo + " Notes:" + request.Notes;
            balance.extra2        = posting.Id.ToString();

            partyBalanceService.Save(balance);

            //isSendSMS = false;
            //if (isSendSMS)
            //{
            //    SMSEmailService sMSEmailService = new SMSEmailService();
            //    string phone = supplierInfo.Phone;
            //    rptIndividualLedger_Result due = customerService.GetBalance((supplierInfo.LedgerId ?? 0));

            //    string balanceText = "";
            //    credit = due.Balance;
            //    var num = new decimal();
            //    if ((credit.GetValueOrDefault() < num ? !credit.HasValue : true))
            //    {
            //        credit = due.Balance;
            //        balanceText = string.Concat("Your Present Balance With Dada Rice Tk=", string.Format("{0:#,#.}", decimal.Round((credit.HasValue ? credit.GetValueOrDefault() : decimal.Zero)), ""), "/=.");
            //    }
            //    else
            //    {
            //        decimal minusOne = decimal.MinusOne;
            //        credit = due.Balance;
            //        balanceText = string.Concat("Your Present Balance With Dada Rice Tk=", string.Format("{0:#,#.}", minusOne * decimal.Round((credit.HasValue ? credit.GetValueOrDefault() : decimal.Zero)), ""), "/= Thanks.");
            //    }
            //    balanceText = "";
            //    string[] name = new string[] { "Dear ", supplierInfo.Name, " Tk=", null, null, null };
            //    credit = balance.Credit;
            //    name[3] = string.Format("{0:#,#.}", decimal.Round((posting.Credit.HasValue ? posting.Credit.GetValueOrDefault() : decimal.Zero)), "");
            //    name[4] = "/- has been Deposited to your Account. Ref:No-" + voucherNo + ", Dated:" + voucherDate.ToString("dd-MM-yyyy") + ". Thanks with Dada Rice";
            //    sMSEmailService.SendOneToOneSingleSms("01979110321", string.Concat(string.Concat(name), balanceText), false);
            //}
            //updated au authorized
            payment.ApprovedBy    = DateTime.Now;
            payment.ApprovedNotes = request.Notes;
            payment.IsApproved    = true;
            _paymentService.Update(payment, payment.Id);
            foreach (var item in payment.PaymentDetails)
            {
                payment.ApprovedBy    = DateTime.Now;
                payment.ApprovedNotes = request.Notes;
                payment.IsApproved    = true;
                _paymentService.Update(item, item.Id);
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }
        public ActionResult ReceivePayment(string voucherNo, int supplierId, DateTime voucherDate, string notes, List <LedgerPosting> ledgerPosting, bool isSendSMS)
        {
            decimal?credit;
            var     supplierInfo = supplierService.GetById(supplierId);

            if (supplierInfo == null)
            {
                return(Json("error", JsonRequestBehavior.AllowGet));
            }
            //credit
            foreach (var item in ledgerPosting)
            {
                item.Credit        = 0;
                item.VoucherNo     = voucherNo;
                item.PostingDate   = voucherDate;
                item.ChequeDate    = DateTime.Now;
                item.ChequeNo      = "";
                item.VoucherTypeId = (int)BAL.VoucherType.PaymentVoucher;
                item.Extra1        = "Voucher:" + voucherNo + " " + notes;
                postingService.Save(item);
            }
            //debit
            LedgerPosting posting = new LedgerPosting();

            posting.ChequeDate    = DateTime.Now;
            posting.VoucherNo     = voucherNo;
            posting.ChequeNo      = "";
            posting.VoucherTypeId = (int)BAL.VoucherType.PaymentVoucher;
            posting.LedgerId      = supplierInfo.LedgerId;
            posting.PostingDate   = voucherDate;
            posting.Credit        = ledgerPosting.Sum(a => a.Debit).Value;
            posting.Debit         = 0;
            posting.Extra1        = "Voucher:" + voucherNo + " " + notes;
            postingService.Save(posting);
            //balance
            //party balance
            PartyBalance balance = new PartyBalance();

            balance.AgainstVoucherTypeId = 4;
            balance.VoucherNo            = voucherNo;
            balance.PostingDate          = voucherDate;
            balance.LedgerId             = supplierInfo.LedgerId ?? 0;
            balance.Debit         = posting.Credit;
            balance.Credit        = 0;
            balance.VoucherTypeId = (int)BAL.VoucherType.PaymentVoucher;
            balance.extra1        = "Payment Invoice: " + voucherNo + " Notes:" + notes;
            balance.extra2        = posting.Id.ToString();

            partyBalanceService.Save(balance);

            if (isSendSMS)
            {
                SMSEmailService            sMSEmailService = new SMSEmailService();
                string                     phone           = supplierInfo.Phone;
                rptIndividualLedger_Result due             = customerService.GetBalance((supplierInfo.LedgerId ?? 0));

                string balanceText = "";
                credit = due.Balance;
                var num = new decimal();
                if ((credit.GetValueOrDefault() < num ? !credit.HasValue : true))
                {
                    credit      = due.Balance;
                    balanceText = string.Concat("Your Present Balance With Dada Rice Tk=", string.Format("{0:#,#.}", decimal.Round((credit.HasValue ? credit.GetValueOrDefault() : decimal.Zero)), ""), "/=.");
                }
                else
                {
                    decimal minusOne = decimal.MinusOne;
                    credit      = due.Balance;
                    balanceText = string.Concat("Your Present Balance With Dada Rice Tk=", string.Format("{0:#,#.}", minusOne * decimal.Round((credit.HasValue ? credit.GetValueOrDefault() : decimal.Zero)), ""), "/= Thanks.");
                }
                balanceText = "";
                string[] name = new string[] { "Dear ", supplierInfo.Name, " Tk=", null, null, null };
                credit  = balance.Credit;
                name[3] = string.Format("{0:#,#.}", decimal.Round((posting.Credit.HasValue ? posting.Credit.GetValueOrDefault() : decimal.Zero)), "");
                name[4] = "/- has been Deposited to your Account. Ref:No-" + voucherNo + ", Dated:" + voucherDate.ToString("dd-MM-yyyy") + ". Thanks with Dada Rice";
                sMSEmailService.SendOneToOneSingleSms("01979110321", string.Concat(string.Concat(name), balanceText), false);
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }
Exemple #4
0
        public ActionResult Create(Customer customer, decimal OpeningBalance, string CrOrDr, int create)
        {
            var result = customer;

            if (ModelState.IsValid)
            {
                var sesssion = CurrentSession.GetCurrentSession();
                if (sesssion != null)
                {
                }
                var lastId = db.LastId();
                if (string.IsNullOrEmpty(customer.Area))
                {
                    return(Json(new { Id = 2, message = "Area Empty" }, JsonRequestBehavior.AllowGet));
                }
                customer.Code        = customer.District.Substring(0, 2).ToUpper() + "_" + customer.Area.Substring(0, 2).ToUpper() + "_" + db.LastId();
                customer.CreatedDate = DateTime.Now;
                customer.UpdatedDate = DateTime.Now;
                customer.CreatedBy   = CurrentSession.GetCurrentSession().UserName;
                customer.IsActive    = true;
                AccountLedger ledger       = new AccountLedger();
                var           accountGroup = new AccountGroupService().GetById(26); //sundry debitor
                ledger.AccountGroupId    = 26;
                ledger.Address           = customer.Address;
                ledger.BankAccountNumber = "";
                ledger.BillByBill        = true;
                ledger.BranchCode        = "";
                ledger.BranchName        = "";
                ledger.CreditLimit       = 0.0m;
                ledger.CreditPeriod      = 1;
                ledger.CrOrDr            = Accounts.CheckDrOrCr(accountGroup.Nature);
                ledger.Email             = customer.Email;
                ledger.IsDefault         = false;
                ledger.LedgerName        = customer.Name;
                ledger.Extra2            = customer.Code;
                ledger.Mobile            = customer.ContactPersonPhone;
                ledger.Phone             = customer.Phone;
                ledger.OpeningBalance    = OpeningBalance;
                var saved = Accounts.Save(ledger);
                customer.LedgerId = saved.Id;
                result            = db.Save(customer);
                if (ledger.OpeningBalance > 0.0m)
                {
                    var           party = new PartyBalance();
                    LedgerPosting post  = new LedgerPosting();
                    post.InvoiceNo   = "";
                    post.LedgerId    = customer.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();
                    party.LedgerId         = customer.LedgerId ?? 0;
                    party.CreditPeriod     = 60;
                    party.FinancialYearId  = CurrentSession.GetCurrentSession().FinancialYear;
                    party.PostingDate      = DateTime.Now;
                    party.VoucherTypeId    = 1;
                    party.extra1           = "Opening Balance";
                    partyBalanceService.Save(party);
                }
            }

            return(Json(new { Id = 1, message = "Customer Saved Sucess" }, JsonRequestBehavior.AllowGet));
        }