Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="orderView"></param>
        /// <param name="orderItemList"></param>
        /// <returns></returns>
        public virtual string GetTemplateContent(SaleOrderViewModel orderView,
                                                 List <SaleOrderItemViewModel> orderItemList)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(
                "<style>body{margin:0; padding:0;font-family: 'microsoft yahei',Helvetica;font-size:12px;color: #333;}.table-hd{ margin:0;line-height:30px; float:left; background: #f5f5f5;padding:0 10px;  margin-top:30px;}.table-hd strong{font-size:14px;font-weight:normal; float:left}.table-hd span{ font-weight:normal; font-size:12px;float:right}table{border: 1px solid #ddd;width:100%;border-collapse: collapse;border-spacing: 0; font-size:12px; float:left}table th,table td{border:1px solid #ddd;padding: 8px; text-align:center}table th{border-top:0;}</style>");
            stringBuilder.Append("<body>");
            stringBuilder.AppendFormat("<h3 class=\"table-hd\"><strong>{0}发货单</strong><span>订单号:{1}({2})</span></h3>",
                                       "", orderView.OrderNo, orderView.OrderDate.HasValue ? orderView.OrderDate.Value.ToString("") : "");
            stringBuilder.Append(
                "<table class=\"table table-bordered\"><thead><tr><th>商品名称</th><th>规格</th><th>数量</th><th>单价</th><th>总价</th></tr></thead><tbody>");
            foreach (SaleOrderItemViewModel orderItemInfo in orderItemList)
            {
                stringBuilder.Append("<tr>");
                stringBuilder.AppendFormat("<td style=\"text-align:left\">{0}</td>", orderItemInfo.ProductId);
                stringBuilder.AppendFormat("<td>{0} {1} {2}</td>", orderItemInfo.ProductId, orderItemInfo.ProductId,
                                           orderItemInfo.ProductId);
                stringBuilder.AppendFormat("<td>{0}</td>", orderItemInfo.Qty);
                stringBuilder.AppendFormat("<td>¥{0}</td>", "");
                stringBuilder.AppendFormat("<td>¥{0}</td>", "");
                stringBuilder.Append("</tr>");
            }
            stringBuilder.AppendFormat(
                "<tr><td style=\"text-align:right\" colspan=\"6\"><span>商品总价:¥{0} &nbsp; 运费:¥{1}</span> &nbsp; <b>实付金额:¥{2}</b></td></tr>",
                "", "", "");
            stringBuilder.AppendLine("</tbody></table>");
            stringBuilder.Append("</body>");
            return(stringBuilder.ToString());
        }
Exemple #2
0
        public ActionResult CreateSaleOrderOfAnVehicle(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            //lock xe khi co sale order
            var existSaleOrder = _db.SaleOrders.Where(s => s.VehicleId == (int)id && s.Status != SaleOrder.SaleOrderStatus.Cancel).FirstOrDefault();

            if (existSaleOrder != null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Conflict));
            }
            var saleOrderViewModel = new SaleOrderViewModel();

            var vehicle = _db.Vehicles.Find((int)id);

            if (vehicle.Status == Vehicle.VehicleStatus.Pending || vehicle.Status == Vehicle.VehicleStatus.Assigned || vehicle.Status == Vehicle.VehicleStatus.Ready || vehicle.Status == Vehicle.VehicleStatus.Sold)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            saleOrderViewModel.Vehicle = vehicle;


            return(View("CreateSaleOrderModelView", saleOrderViewModel));
        }
Exemple #3
0
        public SaleOrderViewModel FindByIDWithAllProducts(int ID)
        {
            using (dbUltraCoralEntities db = new dbUltraCoralEntities())
            {
                var SO = db.tblSaleOrders.Find(ID);
                if (SO == null)
                {
                    return(null);
                }
                else
                {
                    SaleOrderViewModel ViewModel = new SaleOrderViewModel()
                    {
                        SaleOrderID     = SO.SaleOrderID,
                        SODate          = SO.SODate,
                        SONo            = SO.SONo,
                        CustomerID      = SO.CustomerID,
                        BusinessName    = SO.BusinessName,
                        ContactName     = SO.ContactName,
                        Address         = SO.Address,
                        City            = SO.City,
                        Postcode        = SO.Postcode,
                        Country         = SO.Country,
                        AirportDestCity = SO.AirportDestCity,
                        IntPhoneNo      = SO.IntPhoneNo,
                        EstDelDate      = SO.EstDelDate,
                    };

                    ViewModel.Products = (from r in db.tblProducts
                                          join sn in db.tblProductScientificNames on r.ScientificNameID equals sn.ProductScientificNameID into joinsn
                                          from rsn in joinsn.DefaultIfEmpty()
                                          join cn in db.tblProductCommonNames on r.CommonNameID equals cn.ProductCommonNameID into joincn
                                          from rcn in joincn.DefaultIfEmpty()
                                          join size in db.tblProductSizes on r.SizeID equals size.ProductSizeID into joinsize
                                          from rsize in joinsize.DefaultIfEmpty()
                                          join ct in db.tblProductCultivationTypes on r.CultivationTypeID equals ct.ProductCultivationTypeID into joinct
                                          from rct in joinct.DefaultIfEmpty()
                                          join sopd in
                                          (from saleordprod in db.tblSaleOrderProductDetails where saleordprod.SaleOrderID == ID select saleordprod)
                                          on r.ProductID equals sopd.ProductID into joinsopd
                                          from rsopd in joinsopd.DefaultIfEmpty()

                                          select new SaleOrderProducDetailViewModel()
                    {
                        ProductID = r.ProductID,
                        ScientificName = (rct != null ? rsn.ProductScientificName : ""),
                        CommonName = (rcn != null ? rcn.ProductCommonName : ""),
                        Descr = r.Descr,
                        SizeName = (rsize != null ? rsize.ProductSizeName : ""),
                        CultivationTypeName = (rct != null ? rct.ProductCultivationTypeName : ""),
                        CurrentStock = (rsopd != null ? r.CurrentStock : 0),
                        Rate = (rsopd != null ? rsopd.Rate : 0),
                        OrderQty = (rsopd != null ? rsopd.Quan : 0)
                    }).ToList();
                    return(ViewModel);
                }
            }
        }
Exemple #4
0
        public ActionResult Create(int id = 0)
        {
            var viewModel = new SaleOrderViewModel
            {
                PersonId = id
            };

            return(View(viewModel));
        }
Exemple #5
0
        public ActionResult Edit(int id)
        {
            var saleOrder = db.SalesOrders.Find(id);

            var viewModel = new SaleOrderViewModel
            {
                SaleOrderId = saleOrder.SalesOrderId,
                OrderDate   = saleOrder.OrderDate,
                PersonId    = saleOrder.PersonId,
                OrderNumber = saleOrder.OrderNumber.Trim()
            };

            return(View(viewModel));
        }
Exemple #6
0
        public ActionResult Create(SaleOrderViewModel viewModel)
        {
            var saleorder = new SalesOrder
            {
                OrderDate   = DateTime.Now,
                PersonId    = viewModel.PersonId,
                OrderNumber = viewModel.OrderNumber
            };

            db.SalesOrders
            .Add(saleorder);
            db.SaveChanges();

            return(RedirectToAction("Index", "SaleOrder"));
        }
        public IActionResult PostSaleOrderEntity([FromBody] SaleOrderViewModel saleOrderEntity)
        {
            if (!ModelState.IsValid || !_saleOrderService.VerifyStock(Mapper.Map <SaleOrder>(saleOrderEntity)))
            {
                return(BadRequest(ModelState));
            }

            _saleOrderService.CreateEntity(Mapper.Map <SaleOrder>(saleOrderEntity));

            foreach (var s in saleOrderEntity.SoldItems)
            {
                _saleOrderService.SubtractFromItemInventory(s.ItemEntityId, s.SoldQuantity);
            }

            return(CreatedAtAction("GetSaleOrderEntity", new { id = saleOrderEntity.Id }, saleOrderEntity));
        }
Exemple #8
0
        public ActionResult Create()
        {
            if (Common.Props.LoginUser == null)
            {
                return(RedirectToAction("Login", "Users", new { ReturnUrl = "/SaleOrder/Create" }));
            }
            else if (Common.Props.LoginUser != null && !(Common.Props.LoginUser.Role == Models.Users.eUserRoleID.Admin ||
                                                         Common.Props.LoginUser.Role == Models.Users.eUserRoleID.Customer))
            {
                return(RedirectToAction("PermissionDenied", "Home"));
            }

            SaleOrderViewModel ViewModel         = new SaleOrderViewModel();
            CustomerDAL        CustomerDALObj    = new CustomerDAL();
            CustomerViewModel  CustomerViewModel = CustomerDALObj.FindByID(Common.Props.LoginUser.UserID);

            DAL.Product.ProductMasterDAL ProductDAL = new DAL.Product.ProductMasterDAL();
            ViewModel.SODate = DateTime.Now.Date;

            if (Common.Props.LoginUser.Role != Models.Users.eUserRoleID.Admin)
            {
                ViewModel.CustomerID = CustomerViewModel.UserID;
            }
            ViewModel.BusinessName    = CustomerViewModel.BusinessName;
            ViewModel.ContactName     = CustomerViewModel.ContactName;
            ViewModel.Address         = CustomerViewModel.Address ?? "";
            ViewModel.City            = CustomerViewModel.City;
            ViewModel.Postcode        = CustomerViewModel.Postcode ?? "";
            ViewModel.Country         = CustomerViewModel.Country;
            ViewModel.IntPhoneNo      = CustomerViewModel.IntPhoneNo;
            ViewModel.EMailContact    = CustomerViewModel.EMailID;
            ViewModel.AirportDestCity = CustomerViewModel.AirportDestCity;
            ViewModel.Products        = ProductDAL.GetList().Select <ProductMasterListViewModel, SaleOrderProducDetailViewModel>(r => new SaleOrderProducDetailViewModel()
            {
                ProductID           = r.ProductID,
                ScientificName      = r.ScientificName,
                CommonName          = r.CommonName,
                Descr               = r.Descr,
                SizeName            = r.SizeName,
                CultivationTypeName = r.CultivationTypeName,
                Rate         = r.Rate,
                CurrentStock = r.CurrentStock
            }).ToList();

            ViewBag.NewSaleOrderCode = 0;
            return(View(ViewModel));
        }
        // GET: SOes/Create

        public ActionResult Create()
        {
            //ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name");
            //ViewBag.Products = db.Products;

            //int maxId = db.Customers.Max(p => p.Id);
            decimal maxId = db.Customers.DefaultIfEmpty().Max(p => p == null ? 0 : p.Id);

            maxId += 1;
            ViewBag.SuggestedNewCustId = maxId;


            SaleOrderViewModel saleOrderViewModel = new SaleOrderViewModel();

            saleOrderViewModel.Customers = db.Customers;
            saleOrderViewModel.Products  = db.Products.Where(x => x.Saleable == true);
            return(View(saleOrderViewModel));
        }
        public IActionResult PutSaleOrderEntity([FromRoute] int id, [FromBody] SaleOrderViewModel saleOrderEntity)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != saleOrderEntity.Id)
            {
                return(BadRequest());
            }

            if (_saleOrderService.SaveModifiedEntity(Mapper.Map <SaleOrderEntity>(saleOrderEntity)))
            {
                return(NoContent());
            }

            return(NotFound());
        }
Exemple #11
0
        public ActionResult CreateSaleOrderOfAnVehicle(SaleOrderViewModel saleOrderViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("CreateSaleOrderModelView", saleOrderViewModel));
            }
            ////create customer
            var customer = new Customer();

            customer.Name      = saleOrderViewModel.Customer.Name;
            customer.Phone     = saleOrderViewModel.Customer.Phone;
            customer.Address   = saleOrderViewModel.Customer.Address;
            customer.Email     = saleOrderViewModel.Customer.Email;
            customer.Status    = Customer.CustomerStatus.Active;
            customer.CreatedAt = DateTime.Now;
            customer.UpdatedAt = DateTime.Now;
            var createdCustomer = _db.Customers.Add(customer);

            _db.SaveChanges();

            ////create sale order
            var saleOrder = new SaleOrder();

            saleOrder.CustomerId = createdCustomer.Id;
            saleOrder.VehicleId  = saleOrderViewModel.Vehicle.Id;
            saleOrder.TotalPrice = saleOrderViewModel.Vehicle.SalePrice;
            saleOrder.Status     = SaleOrder.SaleOrderStatus.Pending;
            saleOrder.CreateAt   = DateTime.Now;
            saleOrder.UpdateAt   = DateTime.Now;

            var createdSaleOrder = _db.SaleOrders.Add(saleOrder);

            _db.SaveChanges();
            //change vehicle status
            var currentVehicle = _db.Vehicles.Find(saleOrderViewModel.Vehicle.Id);

            currentVehicle.Status = Vehicle.VehicleStatus.InOrder;
            _db.SaveChanges();

            return(RedirectToAction("ListPendingSaleOrder"));
        }
        //public ActionResult Edit([Bind(Prefix = "SaleOrder", Include = "BillAmount,Balance,BillPaid,Discount")] SO sO, [Bind(Prefix = "SaleOrderDetail", Include = "ProductId,Quantity")] List<SOD> sOD)
        public ActionResult Edit(SaleOrderViewModel saleOrderViewModel1)
        {
            SO         newSO   = saleOrderViewModel1.SaleOrder;
            List <SOD> newSODs = saleOrderViewModel1.SaleOrderDetail;

            if (ModelState.IsValid)
            {
                newSO.Id = Encryption.Decrypt(saleOrderViewModel1.SaleOrder.Id);                                                                 //
                SO sO = db.SOes.Where(x => x.Id == newSO.Id).FirstOrDefault();
                sO.Date       = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, TimeZoneInfo.FindSystemTimeZoneById("Pakistan Standard Time")); //
                sO.SaleReturn = false;                                                                                                           //
                sO.BillAmount = newSO.BillAmount;                                                                                                //
                sO.Discount   = newSO.Discount;                                                                                                  //
                sO.Remarks    = newSO.Remarks;                                                                                                   //
                sO.BillPaid   = newSO.BillPaid;                                                                                                  //
                sO.Balance    = newSO.Balance;                                                                                                   //

                //sO.SOSerial = newSO.SOSerial;//should be unchanged

                ///////////////////////////////////////////

                //Customer cust = db.Customers.FirstOrDefault(x => x.Id == newSO.CustomerId);
                Customer customer = db.Customers.Where(x => x.Id == newSO.CustomerId).FirstOrDefault();
                if (customer == null)
                {//its means new customer(not in db)
                 //sO.CustomerId = 10;
                 //int maxId = db.Customers.Max(p => p.Id);
                    customer = saleOrderViewModel1.Customer;
                    decimal maxId = db.Customers.DefaultIfEmpty().Max(p => p == null ? 0 : p.Id);
                    maxId += 1;

                    customer.Id = maxId;
                    //customer.Balance = newSO.Balance;
                    db.Customers.Add(customer);
                }
                else
                {
                    db.Entry(customer).State = EntityState.Modified;
                }

                if (sO.CustomerId != newSO.CustomerId)
                {//some other db customer
                 //first revert the previous customer balance
                    Customer oldCustomer = db.Customers.Where(x => x.Id == sO.CustomerId).FirstOrDefault();
                    oldCustomer.Balance         = db.SOes.Where(x => x.Id == sO.Id).FirstOrDefault().PrevBalance;
                    db.Entry(oldCustomer).State = EntityState.Modified;
                }

                sO.PrevBalance = newSO.PrevBalance;//
                // assign balance of this customer
                //Customer customer = db.Customers.Where(x => x.Id == newSO.CustomerId).FirstOrDefault();
                customer.Balance = newSO.Balance;
                //assign customer and customerId in SO
                sO.CustomerId = newSO.CustomerId;
                sO.Customer   = customer;

                /////////////////////////////////////////////////////////////////////////////



                List <SOD> oldSODs = db.SODs.Where(x => x.SOId == newSO.Id).ToList();

                //handling old prodcts quantity. add old quantites back to the stock, then in next loop product quantity will be minus. this is simple and stateforward.
                foreach (SOD sod in oldSODs)
                {
                    Product product = db.Products.FirstOrDefault(x => x.Id == sod.ProductId);
                    if (sod.SaleType == false)//sale
                    {
                        product.Stock += sod.Quantity;
                    }
                    else//return
                    {
                        product.Stock -= sod.Quantity;
                    }
                    db.Entry(product).State = EntityState.Modified;
                }

                db.SODs.RemoveRange(oldSODs);
                //////////////////////////////////////////////////////////////////////////////

                sO.SaleOrderAmount  = 0;
                sO.SaleReturnAmount = 0;
                sO.SaleOrderQty     = 0;
                sO.SaleReturnQty    = 0;
                sO.Profit           = 0;
                int sno = 0;

                if (newSODs != null)
                {
                    foreach (SOD sod in newSODs)
                    {
                        sno      += 1;
                        sod.SODId = sno;
                        sod.SO    = sO;
                        sod.SOId  = sO.Id;

                        Product product = db.Products.FirstOrDefault(x => x.Id == sod.ProductId);
                        //sod.salePrice is now from view
                        //sod.SalePrice = product.SalePrice;
                        sod.PurchasePrice = product.PurchasePrice;
                        if (sod.Quantity == null)
                        {
                            sod.Quantity = 0;
                        }
                        if (sod.SaleType == true)//return
                        {
                            product.Stock       += sod.Quantity;
                            sO.SaleReturnAmount += (decimal)(sod.Quantity * sod.SalePrice);
                            sO.SaleReturnQty    += (int)sod.Quantity;

                            sO.Profit -= (sod.Quantity * sod.SalePrice) - (decimal)(sod.Quantity * product.PurchasePrice); //- (decimal)(sO.Discount);
                        }
                        else//sale
                        {
                            product.Stock      -= sod.Quantity;
                            sO.SaleOrderAmount += (decimal)(sod.Quantity * sod.SalePrice);
                            sO.SaleOrderQty    += (int)sod.Quantity;

                            sO.Profit += (sod.Quantity * sod.SalePrice) - (decimal)(sod.Quantity * product.PurchasePrice); //- (decimal)(sO.Discount);
                        }
                    }
                    sO.Profit         -= (decimal)sO.Discount;
                    db.Entry(sO).State = EntityState.Modified;
                    db.Entry(sO).Property(x => x.SOSerial).IsModified = false;
                    db.SODs.AddRange(newSODs);
                }
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            //ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", sO.CustomerId);
            //return View(sO);
            SaleOrderViewModel saleOrderViewModel = new SaleOrderViewModel();

            saleOrderViewModel.Products = db.Products;
            return(View(saleOrderViewModel));
            //return View();
        }
        // GET: SOes/Edit/5
        public ActionResult Edit(string id, bool update)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            //byte[] BytesArr = id.Split('-').Select(byte.Parse).ToArray();
            //id = new string( Encoding.UTF8.GetString(BytesArr).ToCharArray());
            //id = Encryption.Decrypt(id,"BZNS");

            decimal maxId = db.Customers.DefaultIfEmpty().Max(p => p == null ? 0 : p.Id);

            maxId += 1;
            ViewBag.SuggestedNewCustId = maxId;

            List <MySaleType> myOptionLst = new List <MySaleType> {
                new MySaleType {
                    Text  = "Order",
                    Value = "false"
                },
                new MySaleType {
                    Text  = "Return",
                    Value = "true"
                }
            };

            ViewBag.OptionLst = myOptionLst;

            ////////////////
            List <MyPaymentMethod> myPaymentOptionLst = new List <MyPaymentMethod> {
                new MyPaymentMethod {
                    Text  = "Cash",
                    Value = "Cash"
                },
                new MyPaymentMethod {
                    Text  = "Cheque",
                    Value = "Cheque"
                },
                new MyPaymentMethod {
                    Text  = "Other",
                    Value = "Other"
                }
            };

            ViewBag.PaymentMethodOptionLst = myPaymentOptionLst;
            string  iid  = Decode(id);
            Payment pmnt = db.Payments.Where(x => x.SOId == iid).FirstOrDefault();

            if (pmnt != null)
            {
                ViewBag.paymentMethod  = pmnt.PaymentMethod;
                ViewBag.paymentRemarks = pmnt.Remarks;
            }
            ///////////////////

            id = Decode(id);

            SO sO = db.SOes.Find(id);

            if (sO == null)
            {
                return(HttpNotFound());
            }
            SaleOrderViewModel saleOrderViewModel = new SaleOrderViewModel();
            List <SOD>         sod = db.SODs.Where(x => x.SOId == id).ToList();

            saleOrderViewModel.Products        = db.Products;
            saleOrderViewModel.Customers       = db.Customers;
            saleOrderViewModel.SaleOrderDetail = sod;
            sO.Id = Encryption.Encrypt(sO.Id);
            saleOrderViewModel.SaleOrder = sO;


            //ViewBag.CustomerId = new SelectList(db.Customers, "Id", "Name", sO.CustomerId);
            ViewBag.CustomerName    = sO.Customer.Name;
            ViewBag.CustomerAddress = sO.Customer.Address;
            decimal subTotal = (decimal)(sO.SaleOrderAmount - sO.SaleReturnAmount - sO.Discount);

            ViewBag.SubTotal = subTotal;
            ViewBag.Total    = subTotal + (decimal)sO.PrevBalance;
            ViewBag.IsUpdate = update;
            return(View(saleOrderViewModel));
        }
Exemple #14
0
        public SavingResult SaveRecord(SaleOrderViewModel ViewModel)
        {
            SavingResult res = new SavingResult();

            //if (String.IsNullOrWhiteSpace(ViewModel.SaleOrderName))
            //{
            //    res.ExecutionResult = eExecutionResult.ValidationError;
            //    res.ValidationError = "Please enter Cultivation Type name";
            //    return res;
            //}

            using (dbUltraCoralEntities db = new dbUltraCoralEntities())
            {
                if (ViewModel.SaleOrderID != 0 && CheckDuplicate(ViewModel.SaleOrderID, ViewModel.SONo))
                {
                    res.ExecutionResult = eExecutionResult.ValidationError;
                    res.ValidationError = "Can not accept duplicate values. The Cultivation Type name is already exists.";
                    return(res);
                }

                tblSaleOrder SaveModel = null;
                if (ViewModel.SaleOrderID == 0)
                {
                    SaveModel = new tblSaleOrder()
                    {
                        SONo  = GenerateNextSONo(db),
                        rcdt  = DateTime.Now,
                        rcuid = Common.Props.LoginUser.UserID
                    };
                    db.tblSaleOrders.Add(SaveModel);
                }
                else
                {
                    SaveModel = db.tblSaleOrders.FirstOrDefault(r => r.SaleOrderID == ViewModel.SaleOrderID);
                    if (SaveModel == null)
                    {
                        res.ExecutionResult = eExecutionResult.ValidationError;
                        res.ValidationError = "Selected user has been deleted over network. Can not find user's details. Please retry.";
                        return(res);
                    }

                    SaveModel.redt  = DateTime.Now;
                    SaveModel.reuid = Common.Props.LoginUser.UserID;

                    db.tblSaleOrders.Attach(SaveModel);
                    db.Entry(SaveModel).State = System.Data.Entity.EntityState.Modified;

                    db.tblSaleOrderProductDetails.RemoveRange(db.tblSaleOrderProductDetails.Where(r => r.SaleOrderID == ViewModel.SaleOrderID));
                }

                SaveModel.SODate          = ViewModel.SODate;
                SaveModel.CustomerID      = ViewModel.CustomerID;
                SaveModel.BusinessName    = ViewModel.BusinessName;
                SaveModel.ContactName     = ViewModel.ContactName;
                SaveModel.Address         = ViewModel.Address;
                SaveModel.City            = ViewModel.City;
                SaveModel.Postcode        = ViewModel.Postcode;
                SaveModel.Country         = ViewModel.Country;
                SaveModel.IntPhoneNo      = ViewModel.IntPhoneNo;
                SaveModel.AirportDestCity = ViewModel.AirportDestCity;
                SaveModel.EstDelDate      = ViewModel.EstDelDate;
                SaveModel.TotalQuan       = (ViewModel.Products.Sum(r => (decimal?)r.OrderQty) ?? 0);
                SaveModel.TotalAmt        = (ViewModel.Products.Sum(r => (decimal?)(r.OrderQty * r.Rate)) ?? 0);

                foreach (SaleOrderProducDetailViewModel rp in ViewModel.Products.Where(r => r.OrderQty != 0))
                {
                    SaveModel.tblSaleOrderProductDetails.Add(new tblSaleOrderProductDetail()
                    {
                        tblSaleOrder = SaveModel,
                        ProductID    = rp.ProductID,
                        Rate         = rp.Rate,
                        Quan         = rp.OrderQty,
                        Amt          = rp.Rate * rp.OrderQty
                    });
                }

                //--
                try
                {
                    db.SaveChanges();
                    res.PrimeKeyValue   = SaveModel.SaleOrderID;
                    res.ExecutionResult = eExecutionResult.CommitedSucessfuly;
                }
                catch (Exception ex)
                {
                    ex = Common.Functions.FindFinalError(ex);

                    res.ExecutionResult = eExecutionResult.ErrorWhileExecuting;
                    res.Exception       = ex;
                }
            }
            return(res);
        }
Exemple #15
0
        public ActionResult DeliveryChallanForm(Guid id, Guid?saleOrderID, Guid?prodOrderID)
        {
            DeliveryChallanViewModel deliveryChallanVM = null;

            try
            {
                if (id != Guid.Empty)
                {
                    deliveryChallanVM          = Mapper.Map <DeliveryChallan, DeliveryChallanViewModel>(_deliveryChallanBusiness.GetDeliveryChallan(id));
                    deliveryChallanVM.IsUpdate = true;
                    AppUA appUA = Session["AppUA"] as AppUA;
                    deliveryChallanVM.IsDocLocked = deliveryChallanVM.DocumentOwners.Contains(appUA.UserName);
                    if (deliveryChallanVM.SaleOrderID != null)
                    {
                        deliveryChallanVM.DocumentType        = "SaleOrder";
                        deliveryChallanVM.SaleOrderSelectList = _saleOrderBusiness.GetSaleOrderForSelectList(saleOrderID);
                    }
                    if (deliveryChallanVM.ProdOrderID != null)
                    {
                        deliveryChallanVM.DocumentType = "ProductionOrder";
                        deliveryChallanVM.ProductionOrderSelectList = _productionOrderBusiness.GetProductionOrderForSelectList(prodOrderID);
                    }
                }
                else if (id == Guid.Empty && saleOrderID != null)
                {
                    SaleOrderViewModel saleOrderVM = Mapper.Map <SaleOrder, SaleOrderViewModel>(_saleOrderBusiness.GetSaleOrder((Guid)saleOrderID));
                    deliveryChallanVM                           = new DeliveryChallanViewModel();
                    deliveryChallanVM.IsUpdate                  = false;
                    deliveryChallanVM.ID                        = Guid.Empty;
                    deliveryChallanVM.SaleOrderSelectList       = _saleOrderBusiness.GetSaleOrderForSelectList(saleOrderID);
                    deliveryChallanVM.SaleOrderID               = saleOrderID;
                    deliveryChallanVM.CustomerID                = saleOrderVM.CustomerID;
                    deliveryChallanVM.ProdOrderID               = null;
                    deliveryChallanVM.DocumentType              = "SaleOrder";
                    deliveryChallanVM.ProductionOrderSelectList = new List <SelectListItem>();
                    deliveryChallanVM.Customer                  = saleOrderVM.Customer;
                    deliveryChallanVM.IsDocLocked               = false;
                }
                else if (id == Guid.Empty && prodOrderID != null)
                {
                    ProductionOrderViewModel productionOrderVM = Mapper.Map <ProductionOrder, ProductionOrderViewModel>(_productionOrderBusiness.GetProductionOrder((Guid)prodOrderID));
                    deliveryChallanVM          = new DeliveryChallanViewModel();
                    deliveryChallanVM.IsUpdate = false;
                    deliveryChallanVM.ID       = Guid.Empty;
                    deliveryChallanVM.ProductionOrderSelectList = _productionOrderBusiness.GetProductionOrderForSelectList(prodOrderID);
                    deliveryChallanVM.ProdOrderID         = prodOrderID;
                    deliveryChallanVM.CustomerID          = productionOrderVM.CustomerID;
                    deliveryChallanVM.SaleOrderID         = null;
                    deliveryChallanVM.DocumentType        = "ProductionOrder";
                    deliveryChallanVM.SaleOrderSelectList = new List <SelectListItem>();
                    deliveryChallanVM.Customer            = productionOrderVM.Customer;
                    deliveryChallanVM.IsDocLocked         = false;
                }
                else
                {
                    deliveryChallanVM = new DeliveryChallanViewModel();
                    deliveryChallanVM.SaleOrderSelectList       = new List <SelectListItem>();
                    deliveryChallanVM.ProductionOrderSelectList = new List <SelectListItem>();
                    deliveryChallanVM.SaleOrderID          = null;
                    deliveryChallanVM.ProdOrderID          = null;
                    deliveryChallanVM.DocumentType         = "SaleOrder";
                    deliveryChallanVM.IsDocLocked          = false;
                    deliveryChallanVM.IsUpdate             = false;
                    deliveryChallanVM.ID                   = Guid.Empty;
                    deliveryChallanVM.Customer             = new CustomerViewModel();
                    deliveryChallanVM.Customer.CompanyName = "-";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(PartialView("_DeliveryChallanForm", deliveryChallanVM));
        }