Esempio n. 1
0
        public ActionResult Transfer(int ledgerPostingId, int toLedgerId)
        {
            var transferMessage = "";
            var ledgerPost      = postingService.GetById(ledgerPostingId);

            if (ledgerPost != null)
            {
                var partybalance = partyBalanceService.GetByLedgerPostingId(ledgerPost.LedgerId ?? 0, ledgerPost.Id.ToString(), ledgerPost.VoucherNo, ledgerPost.InvoiceNo);
                if (partybalance != null)
                {
                    partybalance.extra1 += "Transfer from " + partybalance.LedgerId;
                    ledgerPost.Extra1   += "Transfer from " + partybalance.LedgerId;

                    partybalance.LedgerId = toLedgerId;
                    partyBalanceService.Update(partybalance, partybalance.PartyBalanceId);

                    ledgerPost.LedgerId = toLedgerId;
                    postingService.Update(ledgerPost, ledgerPost.Id);
                    transferMessage = "Sucess";
                }
                else
                {
                    transferMessage = "Transfer Not possible";
                }
            }
            else
            {
                transferMessage = "Transfer Not possible";
            }
            return(Json(transferMessage, JsonRequestBehavior.AllowGet));
        }
        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();
        }