示例#1
0
        public static List <RevenueUpdateMasterVM> GetRevenueUpdateList(string ConsignmentNote, DateTime FromDate, DateTime ToDate)
        {
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = new SqlConnection(CommanFunctions.GetConnectionString);
            cmd.CommandText = "SP_GetRevenueUpdateList";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@FromDate", SqlDbType.VarChar);
            cmd.Parameters["@FromDate"].Value = FromDate.ToString("MM/dd/yyyy");
            cmd.Parameters.Add("@ToDate", SqlDbType.VarChar);
            cmd.Parameters["@ToDate"].Value = ToDate.ToString("MM/dd/yyyy");
            cmd.Parameters.Add("@ConsignmentNo", SqlDbType.VarChar);
            if (ConsignmentNote == null)
            {
                ConsignmentNote = "";
            }
            cmd.Parameters["@ConsignmentNo"].Value = ConsignmentNote;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet        ds = new DataSet();

            da.Fill(ds);

            List <RevenueUpdateMasterVM> objList = new List <RevenueUpdateMasterVM>();

            if (ds != null && ds.Tables.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    RevenueUpdateMasterVM obj = new RevenueUpdateMasterVM();
                    obj.ID                = CommanFunctions.ParseInt(ds.Tables[0].Rows[i]["ID"].ToString());
                    obj.ConsignmentNo     = ds.Tables[0].Rows[i]["ConsignmentNo"].ToString();
                    obj.ConsignmentDate   = Convert.ToDateTime(ds.Tables[0].Rows[i]["ConsignmentDate"].ToString()); // CommanFunctions.ParseDate(ds.Tables[0].Rows[i]["RecPayDate"].ToString());
                    obj.Currency          = ds.Tables[0].Rows[i]["CurrencyName"].ToString();
                    obj.PaymentType       = ds.Tables[0].Rows[i]["PaymentType"].ToString();
                    obj.InvoiceTo         = ds.Tables[0].Rows[i]["InvoiceTo"].ToString();
                    obj.DebitAccountName  = ds.Tables[0].Rows[i]["DebitAccountHead"].ToString();
                    obj.CreditAccountName = ds.Tables[0].Rows[i]["CreditAccountHead"].ToString();
                    obj.CustomerName      = ds.Tables[0].Rows[i]["CustomerName"].ToString();
                    if (ds.Tables[0].Rows[i]["Amount"] == DBNull.Value)
                    {
                        obj.Amount = 0;
                    }
                    else
                    {
                        obj.Amount = CommanFunctions.ParseDecimal(ds.Tables[0].Rows[i]["Amount"].ToString());
                    }
                    objList.Add(obj);
                }
            }
            return(objList);
        }
        public JsonResult GetConsignmentDetail(int id)
        {
            RevenueUpdateMasterVM vm = (RevenueUpdateMasterVM)Session["CreateRevenueUpdate"];

            var    inscan        = db.InScanMasters.Find(id);
            int    paymentModeid = Convert.ToInt32(inscan.PaymentModeId);
            string InvoiceTo     = inscan.InvoiceTo;

            var    cust          = (from c in db.CustomerMasters where c.CustomerName == inscan.Consignor select c).FirstOrDefault();
            var    receiver      = (from c in db.CustomerMasters where c.CustomerName == inscan.Consignee select c).FirstOrDefault();
            var    customer      = (from c in db.CustomerMasters where c.CustomerType == "PKP" select c).FirstOrDefault();
            int    consignorid   = 0;
            string consignorname = "";
            int    consigneeid   = 0;
            string consigneename = "";
            string errormessage  = "";
            bool   status        = true;

            if (cust != null)
            {
                consignorid   = cust.CustomerID;
                consignorname = cust.CustomerName;
                if (paymentModeid == 3 && InvoiceTo == "Shipper" && cust.CustomerType != "CR")
                {
                    status       = false;
                    errormessage = "Invoiced Customer is not a Credit Customer";
                }
            }
            if (receiver != null)
            {
                consigneeid   = receiver.CustomerID;
                consigneename = receiver.CustomerName;
                if (paymentModeid == 3 && InvoiceTo == "Consignee" && receiver.CustomerType != "CR")
                {
                    status       = false;
                    errormessage = "Invoiced Customer is not a Credit Customer";
                }
            }
            if (paymentModeid == 1 && customer != null)
            {
                consignorid   = customer.CustomerID;
                consigneeid   = customer.CustomerID;
                consignorname = customer.CustomerName;
                consigneename = customer.CustomerName;
            }
            List <RevenueUpdateDetailVM> list = new List <RevenueUpdateDetailVM>();

            if (vm != null)
            {
                list = vm.DetailVM;
                for (int i = 0; i < list.Count; i++)
                {
                    list[i].Currency = db.CurrencyMasters.Find(list[i].CurrencyId).CurrencyName;
                    if (list[i].AcHeadDebitId != null)
                    {
                        list[i].DebitAccountName = db.AcHeads.Find(list[i].AcHeadDebitId).AcHead1;
                    }
                    if (list[i].AcHeadCreditId != null)
                    {
                        list[i].CreditAccountName = db.AcHeads.Find(list[i].AcHeadCreditId).AcHead1;
                    }

                    var customer1 = db.CustomerMasters.Find(list[i].CustomerId);

                    if (customer1 != null)
                    {
                        list[i].CustomerName = customer1.CustomerName + "(" + customer.CustomerType + ")";
                    }


                    if (list[i].RevenueCost != null)
                    {
                        list[i].RevenueCost = db.RevenueCostMasters.Find(list[i].RevenueCostMasterID).RevenueComponent;
                    }
                }
            }
            else
            {
                list = RevenueDAO.GetMandatoryRevenueUpdateDetail(id);
            }

            Session["CreateRevenueUpdate"] = null;
            return(Json(new { Remarks = inscan.Remarks, PaymentModeId = paymentModeid, InvoiceTo = InvoiceTo, ConsignorId = consignorid, ConsignorName = consignorname, ConsigneeId = consigneeid, ConsigneeName = consigneename, Status = status, Errormessage = errormessage, revenuedetail = list }, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Create(int id = 0)
        {
            int userId = Convert.ToInt32(Session["UserID"].ToString());

            ViewBag.Title    = "Revenue Update - Create";
            ViewBag.employee = db.EmployeeMasters.ToList();

            ViewBag.PaymentType = db.tblPaymentModes.ToList();
            ViewBag.Currency    = db.CurrencyMasters.ToList();
            ViewBag.Consignment = db.InScanMasters.ToList();
            List <VoucherTypeVM> lsttype = new List <VoucherTypeVM>();

            //lsttype.Add(new VoucherTypeVM { TypeName = "All" });
            lsttype.Add(new VoucherTypeVM {
                TypeName = "Shipper"
            });
            lsttype.Add(new VoucherTypeVM {
                TypeName = "Consignee"
            });

            ViewBag.InvoiceTo = lsttype;
            RevenueUpdateMasterVM vm = new RevenueUpdateMasterVM();

            if (id == 0)
            {
                vm.ID        = 0;
                vm.DetailVM  = new List <RevenueUpdateDetailVM>();
                vm.EntryDate = DateTime.Now;
                var acc = db.AcHeads.Where(cc => cc.AcHead1 == "Un-invoiced Consignment Note").FirstOrDefault();


                if (acc != null)
                {
                    vm.DebitAccountName = acc.AcHead1;
                    vm.DebitAccountId   = acc.AcHeadID;
                }

                var pacc = db.AcHeads.Where(cc => cc.AcHead1 == "Pickup Cash Control Account").FirstOrDefault();
                if (pacc != null)
                {
                    vm.DebitCashAccountName = pacc.AcHead1;
                    vm.DebitCashAccountId   = pacc.AcHeadID;
                }
                var customer = db.CustomerMasters.Where(cc => cc.CustomerType == "COD").FirstOrDefault();
                if (customer != null)
                {
                    vm.DebitCODCustomerId = customer.CustomerID;
                    vm.DebitCODCustomer   = customer.CustomerName;
                }
                var codacc = db.AcHeads.Where(cc => cc.AcHead1 == "Cod Control A/c.").FirstOrDefault();
                if (codacc != null)
                {
                    vm.DebitCODAccountName = codacc.AcHead1;
                    vm.DebitCODAccountId   = codacc.AcHeadID;
                }
                vm.CurrencyId = Convert.ToInt32(Session["CurrencyId"].ToString());
                var emp = db.EmployeeMasters.Where(cc => cc.UserID == userId).FirstOrDefault();
                if (emp != null)
                {
                    vm.EmployeeID = emp.EmployeeID;
                }
                ViewBag.EditMode = "false";
            }
            else
            {
                ViewBag.Title = "Revenue Update - Modify";
                RevenueUpdateMaster v = db.RevenueUpdateMasters.Find(id);
                vm.ID                = v.ID;
                vm.EntryDate         = v.EntryDate;
                vm.EmployeeID        = v.EmployeeID;
                vm.InScanID          = v.InScanID;
                vm.BranchID          = v.BranchID;
                vm.CurrencyId        = Convert.ToInt32(Session["CurrencyId"].ToString());
                vm.AcFinancialYearID = v.AcFinancialYearID;
                var acc = db.AcHeads.Where(cc => cc.AcHead1 == "Un-invoiced Consignment Note").FirstOrDefault();
                if (acc != null)
                {
                    vm.DebitAccountName = acc.AcHead1;
                    vm.DebitAccountId   = acc.AcHeadID;
                }
                var pacc = db.AcHeads.Where(cc => cc.AcHead1 == "Pickup Cash Control Account").FirstOrDefault();
                if (pacc != null)
                {
                    vm.DebitCashAccountName = pacc.AcHead1;
                    vm.DebitCashAccountId   = pacc.AcHeadID;
                }
                var codacc = db.AcHeads.Where(cc => cc.AcHead1 == "Cod Control A/c.").FirstOrDefault();
                if (codacc != null)
                {
                    vm.DebitCODAccountName = codacc.AcHead1;
                    vm.DebitCODAccountId   = codacc.AcHeadID;
                }

                vm.ConsignmentNo = db.InScanMasters.Find(v.InScanID).ConsignmentNo;
                ViewBag.EditMode = "true";
            }
            //vm.PickupCashHeadId = db.AcHeads.Where(cc => cc.AcHead1 == "Main Cash Account").FirstOrDefault().AcHead1;

            return(View(vm));
        }
        public ActionResult Create(RevenueUpdateMasterVM vm)
        {
            ViewBag.Title = "Revenue Update - Create";
            int userId = Convert.ToInt32(Session["UserID"].ToString());

            ViewBag.employee = db.EmployeeMasters.ToList();

            ViewBag.PaymentType = db.tblPaymentModes.ToList();
            ViewBag.Currency    = db.CurrencyMasters.ToList();
            ViewBag.Consignment = db.InScanMasters.ToList();
            List <VoucherTypeVM> lsttype = new List <VoucherTypeVM>();

            //lsttype.Add(new VoucherTypeVM { TypeName = "All" });
            lsttype.Add(new VoucherTypeVM {
                TypeName = "Shipper"
            });
            lsttype.Add(new VoucherTypeVM {
                TypeName = "Consignee"
            });

            ViewBag.InvoiceTo = lsttype;
            int branchid          = Convert.ToInt32(Session["CurrentBranchID"].ToString());
            int fyearid           = Convert.ToInt32(Session["fyearid"].ToString());
            RevenueUpdateMaster v = new RevenueUpdateMaster();
            bool duplicatecost    = false;

            for (int i = 0; i < vm.DetailVM.Count; i++)
            {
                if (vm.DetailVM[i].IsDeleted != true)
                {
                    for (int j = i + 1; j < vm.DetailVM.Count; j++)
                    {
                        if (vm.DetailVM[i].RevenueCostMasterID == vm.DetailVM[j].RevenueCostMasterID && vm.DetailVM[j].IsDeleted != true)
                        {
                            duplicatecost = true;

                            TempData["ErrorMsg"]           = "Revenue Component should not be Duplicated!";
                            Session["CreateRevenueUpdate"] = vm;
                            ViewBag.Title = "Revenue Update - Modify";

                            return(View(vm));
                        }
                    }
                }
            }
            if (vm.ID == 0)
            {
                ViewBag.Title = "Revenue Update - Create";

                v.EntryDate         = vm.EntryDate;
                v.EmployeeID        = vm.EmployeeID;
                v.InScanID          = vm.InScanID;
                v.BranchID          = branchid;
                v.AcFinancialYearID = fyearid;
                v.CreatedBy         = userId;
                v.CreatedDate       = CommanFunctions.GetCurrentDateTime();
                v.ModifiedBy        = userId;
                v.ModifiedDate      = CommanFunctions.GetCurrentDateTime();
                db.RevenueUpdateMasters.Add(v);
                db.SaveChanges();
            }
            else
            {
                ViewBag.Title       = "Revenue Update - Modify";
                v                   = db.RevenueUpdateMasters.Find(vm.ID);
                v.EntryDate         = vm.EntryDate;
                v.EmployeeID        = vm.EmployeeID;
                v.InScanID          = vm.InScanID;
                v.BranchID          = branchid;
                v.AcFinancialYearID = fyearid;
                v.ModifiedBy        = userId;
                v.ModifiedDate      = CommanFunctions.GetCurrentDateTime();
                db.Entry(v).State   = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            for (int i = 0; i < vm.DetailVM.Count; i++)
            {
                if (vm.DetailVM[i].IsDeleted != true)
                {
                    if (vm.DetailVM[i].ID == 0)
                    {
                        RevenueUpdateDetail detail = new RevenueUpdateDetail();
                        detail.MasterID            = v.ID;
                        detail.RevenueCostMasterID = vm.DetailVM[i].RevenueCostMasterID;
                        detail.AcHeadCreditId      = vm.DetailVM[i].AcHeadCreditId;
                        detail.AcHeadDebitId       = vm.DetailVM[i].AcHeadDebitId;
                        detail.Amount        = vm.DetailVM[i].Amount;
                        detail.CurrencyId    = vm.DetailVM[i].CurrencyId;
                        detail.CustomerId    = vm.DetailVM[i].CustomerId;
                        detail.ExchangeRate  = vm.DetailVM[i].ExchangeRate;
                        detail.TaxPercent    = vm.DetailVM[i].TaxPercent;
                        detail.TaxAmount     = vm.DetailVM[i].TaxAmount;
                        detail.TotalCharge   = vm.DetailVM[i].TotalCharge;
                        detail.PaymentModeId = vm.DetailVM[i].PaymentModeId;
                        detail.InvoiceTo     = vm.DetailVM[i].InvoiceTo;

                        db.RevenueUpdateDetails.Add(detail);
                        db.SaveChanges();
                    }
                    else
                    {
                        RevenueUpdateDetail detail = db.RevenueUpdateDetails.Find(vm.DetailVM[i].ID);
                        if (detail != null)
                        {
                            detail.MasterID            = v.ID;
                            detail.RevenueCostMasterID = vm.DetailVM[i].RevenueCostMasterID;
                            detail.AcHeadCreditId      = vm.DetailVM[i].AcHeadCreditId;
                            detail.AcHeadDebitId       = vm.DetailVM[i].AcHeadDebitId;
                            detail.Amount        = vm.DetailVM[i].Amount;
                            detail.CurrencyId    = vm.DetailVM[i].CurrencyId;
                            detail.CustomerId    = vm.DetailVM[i].CustomerId;
                            detail.ExchangeRate  = vm.DetailVM[i].ExchangeRate;
                            detail.PaymentModeId = vm.DetailVM[i].PaymentModeId;
                            detail.InvoiceTo     = vm.DetailVM[i].InvoiceTo;

                            db.Entry(detail).State = System.Data.Entity.EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }
                else
                {
                    if (vm.DetailVM[i].ID > 0)
                    {
                        RevenueUpdateDetail detail = db.RevenueUpdateDetails.Find(vm.DetailVM[i].ID);
                        db.RevenueUpdateDetails.Remove(detail);
                        db.SaveChanges();
                    }
                }
            }


            //update inscan revenue update status
            var inscan = db.InScanMasters.Find(vm.InScanID);

            inscan.Remarks         = vm.Remarks;
            inscan.RevenueUpdate   = true;
            db.Entry(inscan).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            PickupRequestDAO _dao = new PickupRequestDAO();

            _dao.GenerateRevenueUpdatePosting(v.ID);
            Session["CreateRevenueUpdate"] = null;
            TempData["SuccessMsg"]         = "Revenue of Consignment Updated Successfully!";
            return(RedirectToAction("Index"));
            //ViewBag.Title = "Revenue Update - Create";
            //ViewBag.employee = db.EmployeeMasters.ToList();
            //List<VoucherTypeVM> lsttype = new List<VoucherTypeVM>();
            //lsttype.Add(new VoucherTypeVM { TypeName = "Pickup Cash" });
            //lsttype.Add(new VoucherTypeVM { TypeName = "Customer" });
            //lsttype.Add(new VoucherTypeVM { TypeName = "Shipper" });

            //ViewBag.PaymentType = lsttype;
            //ViewBag.Currency = db.CurrencyMasters.ToList();
            //return View();
        }