Пример #1
0
        public ActionResult Create(int id = 0)
        {
            int FyearId           = Convert.ToInt32(Session["fyearid"]);
            CustomerRcieptVM cust = new CustomerRcieptVM();

            cust.CustomerRcieptChildVM = new List <CustomerRcieptChildVM>();
            List <CurrencyMaster> Currencys = new List <CurrencyMaster>();

            Currencys        = MM.GetCurrency();
            ViewBag.Currency = new SelectList(Currencys, "CurrencyID", "CurrencyName");
            if (Session["UserID"] != null)
            {
                var branchid = Convert.ToInt32(Session["CurrentBranchID"]);

                if (id > 0)
                {
                    ViewBag.Title = "COD Receipt - Modify";
                    cust          = RP.GetRecPayByRecpayID(id);

                    var acheadforcash = (from c in db.AcHeads join g in db.AcGroups on c.AcGroupID equals g.AcGroupID where g.AcGroup1 == "Cash" select new { AcHeadID = c.AcHeadID, AcHead = c.AcHead1 }).ToList();
                    var acheadforbank = (from c in db.AcHeads join g in db.AcGroups on c.AcGroupID equals g.AcGroupID where g.AcGroup1 == "Bank" select new { AcHeadID = c.AcHeadID, AcHead = c.AcHead1 }).ToList();
                    ViewBag.achead     = acheadforcash;
                    ViewBag.acheadbank = acheadforbank;
                    cust.recPayDetail  = db.RecPayDetails.Where(item => item.RecPayID == id).ToList();
                    int fyearid      = Convert.ToInt32(Session["fyearid"].ToString());
                    var salesinvoice = new List <CustomerTradeReceiptVM>();
                    salesinvoice               = ReceiptDAO.GetCODPending(fyearid, id);
                    Session["CODAWBList"]      = salesinvoice;
                    cust.CustomerRcieptChildVM = new List <CustomerRcieptChildVM>();
                    foreach (var item in cust.recPayDetail)
                    {
                        if (item.InScanID > 0)
                        {
                            if (salesinvoice.Count > 0)
                            {
                                CustomerTradeReceiptVM sales = salesinvoice.Where(cc => cc.InScanID == Convert.ToInt32(item.InScanID)).FirstOrDefault();
                                decimal invoicetotal         = Convert.ToDecimal(sales.InvoiceAmount);
                                decimal received             = Convert.ToDecimal(sales.AmountReceived);
                                var     allrecpay            = (from d in db.RecPayDetails where d.InScanID == item.InScanID select d).ToList();
                                var     totamtpaid           = allrecpay.Sum(d => d.Amount) * -1;
                                var     totadjust            = allrecpay.Sum(d => d.AdjustmentAmount);

                                var customerinvoice = new CustomerRcieptChildVM();

                                customerinvoice.InvoiceType = "D";
                                var inscan = db.InScanMasters.Find(item.InScanID);

                                if (inscan != null)
                                {
                                    customerinvoice.InScanID      = inscan.InScanID;
                                    customerinvoice.ConsignmentNo = inscan.ConsignmentNo;
                                    customerinvoice.strDate       = Convert.ToDateTime(inscan.TransactionDate).ToString("dd/MM/yyyy");
                                }

                                customerinvoice.AmountToBeRecieved = invoicetotal;
                                customerinvoice.AmountToBePaid     = received;
                                customerinvoice.Amount             = Convert.ToDecimal(item.Amount) * -1;
                                customerinvoice.Balance            = invoicetotal - received;
                                customerinvoice.RecPayDetailID     = item.RecPayDetailID;

                                customerinvoice.RecPayID         = Convert.ToInt32(item.RecPayID);
                                customerinvoice.AdjustmentAmount = 0;
                                cust.CustomerRcieptChildVM.Add(customerinvoice);
                            }
                        }
                    }
                    Session["AWBAllocation"] = cust.AWBAllocation;
                }
                else
                {
                    ViewBag.Title = "COD Receipt - Create";
                    var codcust = db.CustomerMasters.Where(cc => cc.CustomerName == "Cod Customer").FirstOrDefault();

                    var acheadforcash = (from c in db.AcHeads join g in db.AcGroups on c.AcGroupID equals g.AcGroupID where g.AcGroup1 == "Cash" select new { AcHeadID = c.AcHeadID, AcHead = c.AcHead1 }).ToList();
                    var acheadforbank = (from c in db.AcHeads join g in db.AcGroups on c.AcGroupID equals g.AcGroupID where g.AcGroup1 == "Bank" select new { AcHeadID = c.AcHeadID, AcHead = c.AcHead1 }).ToList();

                    ViewBag.achead     = acheadforcash;
                    ViewBag.acheadbank = acheadforbank;

                    DateTime pFromDate = AccountsDAO.CheckParamDate(DateTime.Now, FyearId).Date;
                    cust.RecPayDate = pFromDate;
                    cust.RecPayID   = 0;
                    cust.CustomerID = codcust.CustomerID;
                    cust.DocumentNo = ReceiptDAO.SP_GetMaxCODID();
                    cust.CurrencyId = Convert.ToInt32(Session["CurrencyId"].ToString());

                    var salesinvoice = new List <CustomerTradeReceiptVM>();
                    if (codcust != null)
                    {
                        int fyearid = Convert.ToInt32(Session["fyearid"].ToString());
                        salesinvoice          = ReceiptDAO.GetCODPending(fyearid, 0);
                        Session["CODAWBList"] = salesinvoice;
                    }
                }
            }
            else
            {
                return(RedirectToAction("Login", "Login"));
            }
            var StaffNotes = (from d in db.StaffNotes where d.PageTypeId == 2 orderby d.NotesId descending select d).ToList();
            var users      = (from d in db.UserRegistrations select d).ToList();

            var staffnotemodel = new List <StaffNoteModel>();

            foreach (var item in StaffNotes)
            {
                var model = new StaffNoteModel();
                model.id         = item.NotesId;
                model.employeeid = item.EmployeeId;
                //model.jobid = item.JobId;
                model.TaskDetails = item.Notes;
                model.Datetime    = item.EntryDate;
                model.EmpName     = users.Where(d => d.UserID == item.EmployeeId).FirstOrDefault().UserName;
                staffnotemodel.Add(model);
            }
            ViewBag.StaffNoteModel = staffnotemodel;
            var customerdetails = (from d in db.CustomerMasters where d.CustomerID == cust.CustomerID && d.CustomerType == "CS" select d).FirstOrDefault();

            if (customerdetails == null)
            {
                customerdetails = new CustomerMaster();
            }
            ViewBag.CustomerDetail = customerdetails;
            var CustomerNotification = (from d in db.CustomerNotifications where d.RecPayID == id && d.PageTypeId == 2 orderby d.NotificationId descending select d).ToList();

            var customernotification = new List <CustomerNotificationModel>();

            foreach (var item in CustomerNotification)
            {
                var model = new CustomerNotificationModel();
                model.id         = item.NotificationId;
                model.employeeid = item.UserId;
                model.jobid      = item.RecPayID;
                model.Message    = item.MessageText;
                model.Datetime   = item.EntryDate;
                model.IsEmail    = item.NotifyByEmail;
                model.IsSms      = item.NotifyBySMS;
                model.IsWhatsapp = item.NotifyByWhatsApp;
                model.EmpName    = users.Where(d => d.UserID == item.UserId).FirstOrDefault().UserName;
                customernotification.Add(model);
            }
            cust.AWBAllocation           = new List <ReceiptAllocationDetailVM>();
            ViewBag.CustomerNotification = customernotification;
            return(View(cust));
        }