Esempio n. 1
0
        public ActionResult LocalPaymentSave(decimal TotalAmount, List <PartyBalance> partyBalanceList, List <LedgerPosting> ledgerPostingList)
        {
            decimal a, b;

            foreach (var item in partyBalanceList)
            {
                PartyBalance pb = new PartyBalance();
                pb.PostingDate   = item.PostingDate;
                pb.LedgerId      = item.LedgerId;
                pb.VoucherTypeId = 13;
                pb.InvoiceNo     = item.InvoiceNo;
                a         = item.Debit ?? 0;
                b         = item.Credit ?? 0;
                pb.Debit  = a + b;
                pb.Credit = item.Balance;
                partyBalanceService.Save(pb);
            }

            foreach (var li in ledgerPostingList)
            {
                LedgerPosting lp = new LedgerPosting();
                lp.VoucherNo     = li.VoucherNo;
                lp.PostingDate   = li.ChequeDate;
                lp.VoucherTypeId = 13;
                lp.LedgerId      = li.LedgerId;
                lp.Debit         = li.Credit;
                lp.InvoiceNo     = "";
                lp.ChequeNo      = li.ChequeNo;
                lp.ChequeDate    = li.ChequeDate;
                postingService.Save(lp);
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public PartyBalance Update(PartyBalance t, int id)
        {
            var res = service.Update(t, id);

            if (t != null)
            {
                service.ExecuteNonQuery("Exec BalanceReconcilation " + t.LedgerId + "," + yearId + "");
            }
            return(res);
        }
Esempio n. 4
0
        public PartyBalance GetByLedgerPostingId(int ledgerId, string ledgerPostingId, string voucherNo, string invoiceNo)
        {
            PartyBalance partyBalance = this.service.GetAll((PartyBalance a) => a.LedgerId == ledgerId && a.extra2 == ledgerPostingId && a.FinancialYearId == yearId).FirstOrDefault <PartyBalance>();

            if (partyBalance == null)
            {
                partyBalance = this.service.GetAll((PartyBalance a) => a.LedgerId == ledgerId && (a.VoucherNo == voucherNo) && a.FinancialYearId == yearId).FirstOrDefault <PartyBalance>();
            }
            return(partyBalance);
        }
Esempio n. 5
0
        public PartyBalance Save(PartyBalance partyBalance)
        {
            var isExists = service.GetAll().Where(a => a.LedgerId == partyBalance.LedgerId).OrderByDescending(a => a.PartyBalanceId).FirstOrDefault();
            var max      = service.LastRow().OrderByDescending(a => a.PartyBalanceId).FirstOrDefault();

            if (max == null)
            {
                partyBalance.PartyBalanceId = 1;
            }
            else
            {
                partyBalance.PartyBalanceId = max.PartyBalanceId + 1;
            }

            if (isExists != null)
            {
                if (partyBalance.Credit > 0)
                {
                    var newbalance = isExists.Balance + partyBalance.Credit;
                    partyBalance.Balance = newbalance;
                }
                if (partyBalance.Debit > 0)
                {
                    var newbalance = isExists.Balance - partyBalance.Debit;
                    partyBalance.Balance = newbalance;
                }
            }
            else
            {
                if (partyBalance.Credit > 0)
                {
                    partyBalance.Balance = partyBalance.Credit;
                }
                if (partyBalance.Debit > 0)
                {
                    partyBalance.Balance = (-1) * partyBalance.Debit;
                }
            }
            partyBalance.FinancialYearId = CurrentSession.GetCurrentSession().FinancialYear;
            partyBalance.IsLastYear      = true;
            service.Save(partyBalance);
            //if (partyBalance != null)
            //{
            //    SqlParameter param = new SqlParameter("@LedgerId", partyBalance.LedgerId);
            //    List<SqlParameter> paramss = new List<SqlParameter>();

            //    paramss.Add(param);
            //    service.ExecuteProcedure("Exec BalanceReconcilation " + partyBalance.LedgerId + "",paramss,true);
            //}
            return(partyBalance);
        }
Esempio n. 6
0
        public int DeleteSales(SalesMaster salesMaster)
        {
            int num;

            try
            {
                IQueryable <SalesDetail> salesdetails = this.salesDetailsService.GetAll((SalesDetail a) => a.SalesMasterId == salesMaster.Id);
                foreach (SalesDetail item in salesdetails)
                {
                    (new DBService <SalesDetail>()).Delete(item.Id);
                }
                this.serviceSalesMaster.Delete(salesMaster.Id);
                foreach (SalesDetail salesDetail in salesMaster.SalesDetails)
                {
                    List <Inventory> existingItem = this.inventory.GetAll((Inventory a) => a.ProductId == salesDetail.ProductId && a.IsActive && a.QtyInBale == (int?)salesDetail.Qty && a.WarehouseId == salesDetail.WarehouseId).ToList <Inventory>();
                    if (existingItem.Count > 0)
                    {
                        foreach (Inventory inv in existingItem)
                        {
                            inv.UpdatedDate = new DateTime?(DateTime.Now);
                            inv.UpdatedBy   = "";
                            Inventory nullable = inv;
                            decimal?  salesQty = inv.SalesQty;
                            nullable.SalesQty = new decimal?((salesQty.HasValue ? salesQty.GetValueOrDefault() : 0 - salesDetail.Qty));
                            inv.BalanceQty    = inv.BalanceQty + salesDetail.Qty;
                            this.inventory.Update(inv, inv.Id);
                        }
                    }
                }
                Customer customer = this.customerService.GetById(new int?(salesMaster.CustomerID));
                foreach (LedgerPosting item in this.ledgerService.GetAll(salesMaster.SalesInvoice, true))
                {
                    item.IsActive = false;
                    this.ledgerService.Update(item, item.Id);
                }
                PartyBalanceService partyBalanceService = this.partyBalanceService;
                int?         ledgerId   = customer.LedgerId;
                PartyBalance paymentObj = partyBalanceService.GetByVoucher(customer.LedgerId ?? 0, salesMaster.SalesInvoice);
                this.partyBalanceService.Delete(paymentObj.PartyBalanceId);
                num = 1;
            }
            catch (Exception exception)
            {
                num = 0;
            }
            return(num);
        }
Esempio n. 7
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));
        }
Esempio n. 8
0
        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));
        }
Esempio n. 9
0
        public PartyBalance GetByInvoiceNo(int ledgerId, string invoiceNo)
        {
            PartyBalance partyBalance = this.service.GetAll((PartyBalance a) => a.LedgerId == ledgerId && a.InvoiceNo == invoiceNo && a.FinancialYearId == yearId).FirstOrDefault <PartyBalance>();

            return(partyBalance);
        }
Esempio n. 10
0
        public PartyBalance GetByVoucher(int ledgerId, string voucherNo)
        {
            PartyBalance partyBalance = this.service.GetAll((PartyBalance a) => a.LedgerId == ledgerId && a.VoucherNo == voucherNo && a.FinancialYearId == yearId).FirstOrDefault <PartyBalance>();

            return(partyBalance);
        }
Esempio n. 11
0
        public SalesMaster SaveSalesMaster(SalesMaster salesMaster)
        {
            salesMaster.YearId     = yearId;
            salesMaster.IsLastYear = true;
            SalesMaster result = this.serviceSalesMaster.Save(salesMaster);

            if ((result != null ? true : result.Id > 0))
            {
                //foreach (SalesDetail salesDetail in salesMaster.SalesDetails)
                //{

                //}
                Customer      customer  = this.customerService.GetById(new int?(salesMaster.CustomerID));
                LedgerPosting ledgerObj = new LedgerPosting()
                {
                    VoucherTypeId = new int?(19),
                    VoucherNo     = result.SalesInvoice,
                    PostingDate   = salesMaster.SalesDate,
                    LedgerId      = (int)DefaultLedger.SalesAccount,
                    InvoiceNo     = result.SalesInvoice,
                    Credit        = new decimal?(result.GrandTotal)
                };
                decimal num = new decimal();
                ledgerObj.Debit = new decimal?(num);
                this.ledgerService.Save(ledgerObj);
                LedgerPosting detailsLedger = new LedgerPosting()
                {
                    VoucherTypeId = (int)VoucherTypeEnum.SalesInvoice,
                    VoucherNo     = result.SalesInvoice,
                    PostingDate   = salesMaster.SalesDate,
                    LedgerId      = customer.LedgerId,
                    InvoiceNo     = result.SalesInvoice
                };
                num = new decimal();
                detailsLedger.Credit = new decimal?(num);
                detailsLedger.Debit  = new decimal?(salesMaster.GrandTotal - salesMaster.Discount);
                this.ledgerService.Save(detailsLedger);
                if (salesMaster.Discount > 0)
                {
                    LedgerPosting detailsLedgerDiscount = new LedgerPosting()
                    {
                        VoucherTypeId = (int)VoucherTypeEnum.SalesInvoice,
                        VoucherNo     = result.SalesInvoice,
                        PostingDate   = salesMaster.SalesDate,
                        LedgerId      = customer.LedgerId,
                        InvoiceNo     = result.SalesInvoice
                    };
                    num = new decimal();
                    detailsLedger.Credit = new decimal?(num);
                    detailsLedger.Debit  = new decimal?(salesMaster.Discount);
                    this.ledgerService.Save(detailsLedgerDiscount);
                }
                PartyBalance balance = new PartyBalance()
                {
                    AgainstInvoiceNo     = result.SalesInvoice,
                    AgainstVoucherNo     = result.SalesInvoice,
                    AgainstVoucherTypeId = new int?(19),
                    VoucherNo            = result.SalesInvoice,
                    PostingDate          = salesMaster.SalesDate
                };
                PartyBalance partyBalance = balance;
                int?         ledgerId     = customer.LedgerId;
                partyBalance.LedgerId = (ledgerId.HasValue ? ledgerId.GetValueOrDefault() : 0);
                balance.InvoiceNo     = result.SalesInvoice;
                balance.Debit         = new decimal?(salesMaster.GrandTotal - salesMaster.Discount);
                num                   = new decimal();
                balance.Credit        = new decimal?(num);
                balance.VoucherTypeId = (int)VoucherTypeEnum.SalesInvoice;
                balance.extra1        = string.Concat("Sales Invoice: ", salesMaster.SalesInvoice, " Challan:", salesMaster.Coutha);
                balance.extra2        = result.Id.ToString();
                this.partyBalanceService.Save(balance);
            }
            return(result);
        }
Esempio n. 12
0
        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));
            }
        }
Esempio n. 13
0
        public ReceiveMaster Save(ReceiveMaster cus, List <AdditionalCost> additionalCosts, int wareHouseId, int goodsType)
        {
            var avgAdditionalCost = cus.AdditionalCost / cus.ReceiveDetails.Select(a => a.Qty).Sum();
            var avgCostPrice      = 0.0m;
            var supplier          = supplierService.GetById(cus.SupplierID);

            cus.YearId = financialYearId;
            var result = service.Save(cus);

            if (result != null || result.Id > 0)
            {
                foreach (var item in cus.ReceiveDetails)
                {
                    var balance      = 0.0m;
                    var existingItem = _inventoryService.GetAll(a => a.ProductId == item.ProductId && a.IsActive == true && a.WarehouseId == wareHouseId && a.SizeId == item.SizeId && a.BrandId == item.BrandId && a.APIId == item.APIId).ToList();
                    if (existingItem.Count > 0)
                    {
                        foreach (var inv in existingItem)
                        {
                            var existingCosting = inv.BalanceQty * inv.Costprice ?? 0;
                            var totalAmount     = item.Amount + avgAdditionalCost * item.Qty + existingCosting;
                            avgCostPrice      = totalAmount / (item.Qty + inv.BalanceQty);
                            inv.Costprice     = avgCostPrice;
                            inv.PurchasePrice = item.Rate;
                            inv.UpdatedDate   = DateTime.Now;
                            inv.UpdatedBy     = "";
                            inv.BalanceQty    = inv.BalanceQty + item.Qty;
                            inv.ReceiveQty    = inv.ReceiveQty ?? 0 + item.Qty;
                            _inventoryService.Update(inv, inv.Id);
                            balance = inv.BalanceQty;
                        }
                    }
                    else
                    {
                        Inventory inv = new Inventory();
                        inv.IsActive      = true;
                        inv.CreatedDate   = DateTime.Now;
                        inv.CreatedBy     = "";
                        inv.ProductId     = item.ProductId;
                        inv.ReceiveQty    = item.Qty;
                        inv.SupplierId    = cus.SupplierID;
                        inv.WarehouseId   = wareHouseId;
                        inv.BrandId       = item.BrandId;
                        inv.SizeId        = item.SizeId;
                        inv.APIId         = item.APIId;
                        inv.Faulty        = 0;
                        inv.OpeningQty    = 0;
                        inv.BalanceQty    = item.Qty;
                        inv.PurchasePrice = item.Rate;
                        inv.Costprice     = avgCostPrice;
                        inv.SalesPrice    = 0;
                        inv.GoodsType     = goodsType.ToString();
                        _inventoryService.Save(inv);
                        balance = item.Qty;
                    }

                    var invTransaction = new InventoryTransaction()
                    {
                        APIId           = item.APIId,
                        BalanceQty      = balance,
                        BrandId         = item.BrandId,
                        CreatedBy       = CurrentSession.GetCurrentSession().UserName,
                        CreatedDate     = DateTime.Now,
                        GoodsType       = goodsType.ToString(),
                        InventoryGuid   = Guid.NewGuid().ToString(),
                        InvoiceNo       = cus.InvoiceNo,
                        IsActive        = true,
                        ProductId       = item.ProductId,
                        PurchasePrice   = item.Rate,
                        CostPrice       = avgCostPrice,
                        Qty             = item.Qty,
                        SalesPrice      = 0,
                        SizeId          = item.SizeId,
                        SupplierId      = cus.SupplierID,
                        TransactionType = (int)Util.TransactionType.ReceiveQty,
                        WarehouseId     = item.WarehouseId ?? 0
                    };
                    _invTransactionService.Save(invTransaction);
                }
                // Ledger posting debit to purchase account

                var ledgerObj = new LedgerPosting();
                ledgerObj.VoucherTypeId = (int)VoucherTypeEnum.PurchaseInvoice;
                ledgerObj.VoucherNo     = result.InvoiceNoPaper;
                ledgerObj.PostingDate   = cus.InvoiceDate;
                ledgerObj.LedgerId      = (int)DefaultLedger.PurchaseAccount;
                ledgerObj.InvoiceNo     = cus.InvoiceNo;
                ledgerObj.Credit        = 0;
                ledgerObj.Debit         = cus.GrandTotal;
                ledgerObj.MasterId      = result.Id;
                var save = ledgerService.Save(ledgerObj);

                //Ledger posting to customer ledger credit
                var detailsLedger = new LedgerPosting();
                detailsLedger.VoucherTypeId = (int)VoucherTypeEnum.PurchaseInvoice;
                detailsLedger.VoucherNo     = result.InvoiceNoPaper;
                detailsLedger.PostingDate   = cus.InvoiceDate;
                detailsLedger.LedgerId      = supplier.LedgerId;
                detailsLedger.InvoiceNo     = cus.InvoiceNo;
                detailsLedger.Credit        = cus.TotalAmount - cus.BillDiscount;
                detailsLedger.Debit         = 0;
                detailsLedger.MasterId      = result.Id;
                var detailsLedgerResult = ledgerService.Save(detailsLedger);

                //save addisitonalCost
                if (additionalCosts != null && additionalCosts.Count > 0)
                {
                    foreach (var item in additionalCosts)
                    {
                        item.CreatedBy     = CurrentSession.GetCurrentSession().UserId;
                        item.CreatedDate   = DateTime.Now;
                        item.LedgerId      = supplier.LedgerId;
                        item.VoucherNo     = cus.InvoiceNo;
                        item.Extra1        = cus.AdditionalCostPurpose;
                        item.VoucherTypeId = (int)VoucherTypeEnum.PurchaseInvoice;
                        var isSaved = _addCostService.Save(item);
                    }
                    //
                    var additionalCost = new LedgerPosting();
                    additionalCost.VoucherTypeId = (int)VoucherTypeEnum.AdditionalCost;
                    additionalCost.VoucherNo     = result.InvoiceNoPaper;
                    additionalCost.PostingDate   = cus.InvoiceDate;
                    additionalCost.LedgerId      = (int)DefaultLedger.AdditionalCost;
                    additionalCost.InvoiceNo     = cus.InvoiceNo;
                    additionalCost.Credit        = cus.AdditionalCost;
                    additionalCost.Debit         = 0;
                    additionalCost.MasterId      = result.Id;
                    var _ = ledgerService.Save(additionalCost);
                }

                var party = new PartyBalance();
                party.InvoiceNo       = result.InvoiceNo;
                party.LedgerId        = supplier.LedgerId ?? 0;
                party.Credit          = cus.TotalAmount - cus.BillDiscount;
                party.CreditPeriod    = 60;
                party.Debit           = 0;
                party.MasterId        = result.Id;
                party.FinancialYearId = CurrentSession.GetCurrentSession().FinancialYear;
                party.PostingDate     = cus.InvoiceDate;
                party.VoucherTypeId   = (int)VoucherTypeEnum.PurchaseInvoice;
                party.VoucherNo       = result.InvoiceNo;
                party.extra1          = "Purchase Invoice: " + cus.InvoiceNo + " Paper Invoice No:" + cus.InvoiceNoPaper;
                party.extra2          = result.Id.ToString();
                partyBalanceService.Save(party);
            }
            return(cus);
        }
Esempio n. 14
0
        public int Delete(ReceiveMaster master)
        {
            try
            {
                var salesdetails = serviceDetails.GetAll(a => a.ReceiveMasterId == master.Id).ToList();
                foreach (var item in salesdetails)
                {
                    try
                    {
                        var isdetails = new DBService <ReceiveDetail>().Delete(item.Id);
                    }
                    catch (Exception ex)
                    {
                    }
                }

                var isDeleted = service.Delete(master.Id);
                foreach (var item in master.ReceiveDetails)
                {
                    var existingItem = _inventoryService.GetAll(a => a.ProductId == item.ProductId && a.IsActive == true && a.WarehouseId == item.WarehouseId).ToList();
                    if (existingItem.Count > 0)
                    {
                        foreach (var inv in existingItem)
                        {
                            inv.UpdatedDate = DateTime.Now;
                            inv.UpdatedBy   = "";
                            inv.BalanceQty  = inv.BalanceQty - item.Qty;
                            inv.ReceiveQty  = inv.ReceiveQty ?? 0 - item.Qty;
                            _inventoryService.Update(inv, inv.Id);
                        }
                    }
                }
                var supplier = supplierService.GetById(master.SupplierID);

                foreach (LedgerPosting item in this.ledgerService.GetAllByInvoice(master.InvoiceNo, true))
                {
                    item.IsActive = false;
                    this.ledgerService.Update(item, item.Id);
                }
                PartyBalanceService partyBalanceService = this.partyBalanceService;
                int?         ledgerId   = supplier.LedgerId;
                PartyBalance paymentObj = partyBalanceService.GetByInvoiceNo(supplier.LedgerId ?? 0, master.InvoiceNo);
                this.partyBalanceService.Delete(paymentObj.PartyBalanceId);

                // Ledger Saves credit
                //var ledgerObj = new LedgerPosting();
                //ledgerObj.VoucherTypeId = (int)VoucherType.PurchaseInvoice;
                //ledgerObj.VoucherNo = master.InvoiceNoPaper;
                //ledgerObj.PostingDate = master.InvoiceDate;
                //ledgerObj.LedgerId = (int)DefaultLedger.PurchaseAccount;
                //ledgerObj.InvoiceNo = master.InvoiceNo;
                //ledgerObj.Debit = 0;
                //ledgerObj.Credit = master.GrandTotal;
                //ledgerObj.Extra1 = "Purchase Invoice Deleted: " + master.InvoiceNo;

                //var save = ledgerService.Save(ledgerObj);

                //Ledger posting to customer ledger credit
                //var detailsLedger = new LedgerPosting();
                //detailsLedger.VoucherTypeId = (int)VoucherType.PurchaseInvoice;
                //detailsLedger.VoucherNo = master.InvoiceNoPaper;
                //detailsLedger.PostingDate = master.InvoiceDate;
                //detailsLedger.LedgerId = supplier.LedgerId;
                //detailsLedger.InvoiceNo = master.InvoiceNo;
                //detailsLedger.Debit = master.GrandTotal;
                //detailsLedger.Credit = 0;
                //detailsLedger.Extra1 = "Purchase Invoice Deleted: " + master.InvoiceNo;
                //var detailsLedgerResult = ledgerService.Save(detailsLedger);

                //var party = new PartyBalance();
                //party.InvoiceNo = master.InvoiceNo;
                //party.LedgerId = supplier.LedgerId ?? 0;
                //party.Debit = master.GrandTotal;
                //party.CreditPeriod = 60;
                //party.Credit = 0;
                //party.FinancialYearId =CurrentSession.GetCurrentSession().FinancialYear;
                //party.PostingDate = master.InvoiceDate;
                //party.VoucherTypeId = (int)VoucherType.PurchaseInvoice;
                //party.extra1 = "Purchase Invoice Deleted: " + master.InvoiceNo;
                //partyBalanceService.Save(party);

                return(1);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
Esempio n. 15
0
        public ReceiveMaster Save(ReceiveMaster cus, int wareHouseId, int goodsType)
        {
            var supplier = supplierService.GetById(cus.SupplierID);

            cus.YearId = financialYearId;
            var result = service.Save(cus);

            if (result != null || result.Id > 0)
            {
                foreach (var item in cus.ReceiveDetails)
                {
                    var product = productService.GetById(item.ProductId);
                    if (product != null)
                    {
                        goodsType = product.ProductTypeId ?? 1;
                    }
                    var existingItem = inventory.GetAll(a => a.ProductId == item.ProductId && a.IsActive == true && a.WarehouseId == wareHouseId).ToList();
                    if (existingItem.Count > 0)
                    {
                        foreach (var inv in existingItem)
                        {
                            inv.UpdatedDate = DateTime.Now;
                            inv.UpdatedBy   = "";
                            inv.BalanceQty  = inv.BalanceQty + item.Qty;
                            inv.ReceiveQty  = inv.ReceiveQty ?? 0 + item.Qty;
                            inventory.Update(inv, inv.Id);
                        }
                    }
                    else
                    {
                        Inventory inv = new Inventory();
                        inv.IsActive    = true;
                        inv.ProductId   = item.ProductId;
                        inv.ReceiveQty  = item.Qty;
                        inv.QtyInBale   = 0;
                        inv.SupplierId  = cus.SupplierID;
                        inv.WarehouseId = wareHouseId;
                        inv.OpeningQty  = 0;
                        inv.BalanceQty  = item.Qty;
                        inv.GoodsType   = goodsType.ToString();
                        inventory.Save(inv);
                    }
                }
                // Ledger posting debit to purchase account

                var ledgerObj = new LedgerPosting();
                ledgerObj.VoucherTypeId = (int)VoucherType.PurchaseInvoice;
                ledgerObj.VoucherNo     = result.InvoiceNoPaper;
                ledgerObj.PostingDate   = cus.InvoiceDate;
                ledgerObj.LedgerId      = (int)DefaultLedger.PurchaseAccount;
                ledgerObj.InvoiceNo     = cus.InvoiceNo;
                ledgerObj.Credit        = 0;
                ledgerObj.Debit         = cus.GrandTotal;
                var save = ledgerService.Save(ledgerObj);

                //Ledger posting to customer ledger credit
                var detailsLedger = new LedgerPosting();
                detailsLedger.VoucherTypeId = (int)VoucherType.PurchaseInvoice;
                detailsLedger.VoucherNo     = result.InvoiceNoPaper;
                detailsLedger.PostingDate   = cus.InvoiceDate;
                detailsLedger.LedgerId      = supplier.LedgerId;
                detailsLedger.InvoiceNo     = cus.InvoiceNo;
                detailsLedger.Credit        = cus.GrandTotal;
                detailsLedger.Debit         = 0;
                var detailsLedgerResult = ledgerService.Save(detailsLedger);

                var party = new PartyBalance();
                party.InvoiceNo       = result.InvoiceNo;
                party.LedgerId        = supplier.LedgerId ?? 0;
                party.Credit          = cus.GrandTotal;
                party.CreditPeriod    = 60;
                party.Debit           = 0;
                party.FinancialYearId = CurrentSession.GetCurrentSession().FinancialYear;
                party.PostingDate     = cus.InvoiceDate;
                party.VoucherTypeId   = (int)VoucherType.PurchaseInvoice;
                party.VoucherNo       = result.InvoiceNo;
                party.extra1          = "Purchase Invoice: " + cus.InvoiceNo + " Coutha:" + cus.InvoiceNoPaper;
                partyBalanceService.Save(party);
            }
            return(cus);
        }
Esempio n. 16
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));
        }
Esempio n. 17
0
        public SalesMaster SaveSalesMaster(SalesMaster salesMaster)
        {
            salesMaster.YearId = yearId;
            SalesMaster result = this.serviceSalesMaster.Save(salesMaster);

            if ((result != null ? true : result.Id > 0))
            {
                foreach (SalesDetail salesDetail in salesMaster.SalesDetails)
                {
                    List <Inventory> existingItem = this.inventory.GetAll((Inventory a) => a.ProductId == salesDetail.ProductId && a.IsActive && a.WarehouseId == salesDetail.WarehouseId).ToList <Inventory>();
                    if (existingItem.Count > 0)
                    {
                        foreach (Inventory inv in existingItem)
                        {
                            inv.UpdatedDate = new DateTime?(DateTime.Now);
                            inv.UpdatedBy   = "";
                            Inventory nullable = inv;
                            decimal?  salesQty = inv.SalesQty;
                            nullable.SalesQty = new decimal?((salesQty.HasValue ? salesQty.GetValueOrDefault() : salesDetail.Qty));
                            inv.BalanceQty    = inv.BalanceQty - salesDetail.Qty;
                            this.inventory.Update(inv, inv.Id);
                        }
                    }
                }
                Customer      customer  = this.customerService.GetById(new int?(salesMaster.CustomerID));
                LedgerPosting ledgerObj = new LedgerPosting()
                {
                    VoucherTypeId = new int?(19),
                    VoucherNo     = result.SalesInvoice,
                    PostingDate   = salesMaster.SalesDate,
                    LedgerId      = new int?(10),
                    InvoiceNo     = result.SalesInvoice,
                    Credit        = new decimal?(result.GrandTotal)
                };
                decimal num = new decimal();
                ledgerObj.Debit = new decimal?(num);
                this.ledgerService.Save(ledgerObj);
                LedgerPosting detailsLedger = new LedgerPosting()
                {
                    VoucherTypeId = new int?(19),
                    VoucherNo     = result.SalesInvoice,
                    PostingDate   = salesMaster.SalesDate,
                    LedgerId      = customer.LedgerId,
                    InvoiceNo     = result.SalesInvoice
                };
                num = new decimal();
                detailsLedger.Credit = new decimal?(num);
                detailsLedger.Debit  = new decimal?(salesMaster.GrandTotal);
                this.ledgerService.Save(detailsLedger);
                PartyBalance balance = new PartyBalance()
                {
                    AgainstInvoiceNo     = result.SalesInvoice,
                    AgainstVoucherNo     = result.SalesInvoice,
                    AgainstVoucherTypeId = new int?(19),
                    VoucherNo            = result.SalesInvoice,
                    PostingDate          = salesMaster.SalesDate
                };
                PartyBalance partyBalance = balance;
                int?         ledgerId     = customer.LedgerId;
                partyBalance.LedgerId = (ledgerId.HasValue ? ledgerId.GetValueOrDefault() : 0);
                balance.InvoiceNo     = result.SalesInvoice;
                balance.Debit         = new decimal?(salesMaster.GrandTotal);
                num                   = new decimal();
                balance.Credit        = new decimal?(num);
                balance.VoucherTypeId = 19;
                balance.extra1        = string.Concat("Sales Invoice: ", salesMaster.SalesInvoice, " Challan:", salesMaster.Coutha);
                balance.extra2        = result.Id.ToString();
                this.partyBalanceService.Save(balance);
            }
            return(result);
        }
Esempio n. 18
0
        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();
        }
Esempio n. 19
0
        public ActionResult ReceivePayment(string voucherNo, int supplierId, DateTime voucherDate, string notes, List <LedgerPosting> ledgerPosting, bool isSendSMS)
        {
            ActionResult actionResult;
            decimal      num;
            decimal?     credit;
            int?         ledgerId;
            DateTime     now;
            Customer     supplierInfo = this.supplierService.GetById(new int?(supplierId));

            if (supplierInfo != null)
            {
                foreach (LedgerPosting item in ledgerPosting)
                {
                    num                = new decimal();
                    item.Debit         = new decimal?(num);
                    item.PostingDate   = new DateTime?(voucherDate);
                    item.VoucherNo     = voucherNo;
                    item.VoucherTypeId = new int?(5);
                    item.Extra1        = string.Concat("Voucher:", voucherNo, " ", notes);
                    this.postingService.Save(item);
                    credit      = item.Credit;
                    this.Amount = (credit.HasValue ? credit.GetValueOrDefault() : decimal.Zero);
                    this.ChkNo  = item.ChequeNo;
                    ledgerId    = item.LedgerId;
                    if ((ledgerId.GetValueOrDefault() == 1 ? !ledgerId.HasValue : true))
                    {
                        string[] str = new string[] { "Ref:No- TT-DR", voucherNo, ",Dated:", null, null };
                        now        = DateTime.Now;
                        str[3]     = now.ToString("dd-MM-yyyy");
                        str[4]     = ".";
                        this.ChkNo = string.Concat(str);
                    }
                    else
                    {
                        string[] strArrays = new string[] { "Ref:No- Cash-DR", voucherNo, ",Dated:", null, null };
                        now          = DateTime.Now;
                        strArrays[3] = now.ToString("dd-MM-yyyy");
                        strArrays[4] = ".";
                        this.ChkNo   = string.Concat(strArrays);
                    }
                }
                string        smsmsg  = this.ChkNo;
                LedgerPosting posting = new LedgerPosting()
                {
                    ChequeDate    = new DateTime?(DateTime.Now),
                    VoucherNo     = voucherNo,
                    ChequeNo      = "",
                    VoucherTypeId = new int?(5),
                    LedgerId      = supplierInfo.LedgerId,
                    PostingDate   = new DateTime?(voucherDate)
                };
                LedgerPosting nullable = posting;
                credit         = ledgerPosting.Sum <LedgerPosting>((LedgerPosting a) => a.Credit);
                nullable.Debit = new decimal?(credit.Value);
                num            = new decimal();
                posting.Credit = new decimal?(num);
                posting.Extra1 = string.Concat("Voucher:", voucherNo, " ", notes);
                this.postingService.Save(posting);
                PartyBalance balance = new PartyBalance()
                {
                    AgainstVoucherTypeId = new int?(5),
                    VoucherNo            = voucherNo,
                    PostingDate          = new DateTime?(voucherDate)
                };
                PartyBalance partyBalance = balance;
                ledgerId = supplierInfo.LedgerId;
                partyBalance.LedgerId = (ledgerId.HasValue ? ledgerId.GetValueOrDefault() : 0);
                num                   = new decimal();
                balance.Debit         = new decimal?(num);
                balance.Credit        = posting.Debit;
                balance.VoucherTypeId = 5;
                balance.extra1        = string.Concat("Recipt Invoice: ", voucherNo, " Notes:", notes);
                balance.extra2        = posting.Id.ToString();
                this.partyBalanceService.Save(balance);
                if (isSendSMS)
                {
                    Customer        customer        = (new CustomerService()).GetById(new int?(supplierId));
                    CustomerService customerService = new CustomerService();
                    ledgerId = customer.LedgerId;
                    rptIndividualLedger_Result due = customerService.GetBalance((ledgerId.HasValue ? ledgerId.GetValueOrDefault() : 0));
                    string balanceText             = "";
                    credit = due.Balance;
                    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)), ""), "/=.");
                    }
                    SMSEmailService sMSEmailService = new SMSEmailService();
                    string          phone           = supplierInfo.Phone;
                    string[]        name            = new string[] { "Dear ", customer.Name, " Tk=", null, null, null };
                    credit  = balance.Credit;
                    name[3] = string.Format("{0:#,#.}", decimal.Round((credit.HasValue ? credit.GetValueOrDefault() : decimal.Zero)), "");
                    name[4] = "/-Received With Thanks As ";
                    name[5] = smsmsg;
                    sMSEmailService.SendOneToOneSingleSms(phone, string.Concat(string.Concat(name), balanceText));
                }
                actionResult = Json("", 0);
            }
            else
            {
                actionResult = Json("error", 0);
            }
            return(actionResult);
        }