Ejemplo n.º 1
0
 public ActionResult ChequeRealize(int inv, string Name, int cheid)
 {
     try
     {
         if (inv < 1 || string.IsNullOrEmpty(Name) || cheid < 1)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         else
         {
             IPChequeDetail chequeObj = db.IPChequeDetails.Find(cheid);
             Invoice        invObj    = db.Invoices.Find(inv);
             if (chequeObj != null && invObj != null)
             {
                 ChequeRealizeViewModel Obj = new ChequeRealizeViewModel();
                 Obj.AccountNo        = chequeObj.AccountNo;
                 Obj.Agents           = invObj.Agents;
                 Obj.Amount           = chequeObj.Amount;
                 Obj.BankName         = BankHelper.getBankName(chequeObj.BankNames.ToString());
                 Obj.BankNames        = chequeObj.BankNames;
                 Obj.ChequeNo         = chequeObj.ChequeNo;
                 Obj.InvoiceId        = inv;
                 Obj.IPChequeDetailId = cheid;
                 Obj.Remarks          = chequeObj.Remarks;
                 Obj.SortCode         = chequeObj.SortCode;
                 return(View(Obj));
             }
             else
             {
                 return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
             }
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Ejemplo n.º 2
0
        public ActionResult ChequeRealize(ChequeRealizeViewModel model)
        {
            if (ModelState.IsValid)
            {
                int           GeneralLedgerHeadId = (int)db.BankAccountLedgerHeads.Find(1).GeneralLedgerHeadId;
                GeneralLedger glObj = new GeneralLedger {
                    Amount = model.Amount, ApplicationUserId = User.Identity.GetUserId(), GeneralLedgerHeadId = GeneralLedgerHeadId, Notes = model.RealizationRemarks + " - " + model.Remarks + " - " + "Cheque Realization", PaymentMethods = PaymentMethod.Cheque, StatementTypes = TransactionType.Income, SysDateTime = DateTime.Now, GeneralLedgerType = LedgerType.Credit
                };
                db.GeneralLedgers.Add(glObj);
                db.SaveChanges();

                Agent agent = db.Agents.Find(model.Agents.Id);
                agent.Balance         = (agent.Balance - model.Amount);
                db.Entry(agent).State = EntityState.Modified;
                db.SaveChanges();

                AgentLedger alObj = new AgentLedger {
                    AgentId = model.Agents.Id, AgentLedgerHeadId = 3, Amount = model.Amount, ApplicationUserId = glObj.ApplicationUserId, Balance = agent.Balance, Remarks = glObj.Notes, SystemDate = glObj.SysDateTime
                };
                db.AgentLedgers.Add(alObj);
                db.SaveChanges();

                BankAccount baObj = db.BankAccounts.Find(model.BankAccountId);
                baObj.Balance         = (baObj.Balance + model.Amount);
                db.Entry(baObj).State = EntityState.Modified;
                db.SaveChanges();

                BankAccountLedger bclObj = new BankAccountLedger {
                    Amount = model.Amount, ApplicationUserId = glObj.ApplicationUserId, Balance = baObj.Balance, BankAccountId = model.BankAccountId, BankAccountLedgerHeadId = 1, LedgerTypes = LedgerType.Credit, Notes = glObj.Notes, PaymentMethods = PaymentMethod.Cheque, RelationId = null, SysDateTime = glObj.SysDateTime
                };
                db.BankAccountLedgers.Add(bclObj);
                db.SaveChanges();

                InvoicePayment ipObj = new InvoicePayment {
                    Amount = model.Amount, ApplicationUserId = glObj.ApplicationUserId, GeneralLedgerId = glObj.Id, InvoiceId = model.InvoiceId, PaymentMethods = PaymentMethod.Cheque, Remarks = model.RealizationRemarks + " - " + model.Remarks + " - " + "Cheque Realization", SysDateTime = glObj.SysDateTime, AgentLedgerId = alObj.Id, BankAccountLedgerId = bclObj.Id
                };
                db.InvoicePayments.Add(ipObj);
                db.SaveChanges();

                InvoiceLog ilObj = new InvoiceLog {
                    ApplicationUserId = glObj.ApplicationUserId, InvoiceId = model.InvoiceId, Remarks = "Payment Received by Cheque Transaction - Realization", SysDateTime = glObj.SysDateTime
                };
                db.InvoiceLogs.Add(ilObj);
                db.SaveChanges();

                IPChequeDetail ipchObj = db.IPChequeDetails.Find(model.IPChequeDetailId);
                ipchObj.GeneralLedgerId  = glObj.Id;
                ipchObj.InvoicePaymentId = ipObj.Id;
                ipchObj.BulkPayment      = false;
                ipchObj.Status           = ChequeStatus.Passed;
                db.Entry(ipchObj).State  = EntityState.Modified;
                db.SaveChanges();

                bclObj.RelationId       = ipchObj.Id;
                db.Entry(ipchObj).State = EntityState.Modified;
                db.SaveChanges();
                FlashMessage.Confirmation("Floating Cheque Realized");
                return(RedirectToAction("FloatingCheque", "Accounting"));
            }
            else
            {
                return(RedirectToAction("FloatingCheque", "Accounting"));
            }
        }