public ActionResult SaveSalesDeliveryInternal(SlsSalesOrderViewModel objS) { int soId = objS.Id; decimal discount = objS.Discount; decimal total = objS.Total; SlsDeliveryViewModel objT = new SlsDeliveryViewModel(); int userId = Convert.ToInt32(Session["userId"]); int companyId = Convert.ToInt32(Session["companyId"]); int employeeId = Convert.ToInt32(Session["employeeId"]); SecCompany objCmnCompany = _SecCompanyService.GetById(companyId); SlsOffice office = _officeService.GetById((int)_hrmEmployeeService.GetById(employeeId).SlsOfficeId); string challanNo = _DeliveryService.GetChallanNo(objCmnCompany.Prefix, office.Code); string invoiceNo = _DeliveryService.GetInvoiceNo(objCmnCompany.Prefix, office.Code); Operation objOperation = new Operation { Success = false }; if (ModelState.IsValid) { if (objT.Id == 0) { if ((bool)Session["Add"]) { objT.SlsSalesOrderId = soId; objT.DeliveryDate = DateTime.Now; objT.ChallanNo = challanNo; objT.InvoiceNo = invoiceNo; objT.VehicleNo = ""; objT.Remarks = ""; objT.Discount = discount; objT.Total = total; objT.ReceivedStatus = 1; objT.ReceivedDate = DateTime.Now; objT.ReceivedRemarks = ""; objT.CreatedBy = userId; objT.CreatedDate = DateTime.Now.Date; //map details of sales items to delivery items. IList<SlsDeliverDetailViewModel> details = new List<SlsDeliverDetailViewModel>(); foreach(var det in objS.SalesOrderDetails) { SlsDeliverDetailViewModel dObj = new SlsDeliverDetailViewModel(); dObj.SlsProductId = det.SlsProductId; dObj.Quantity = det.SalesOrderQuantity; dObj.SlsUnitId = det.SlsUnitId; dObj.Rate = det.Rate; dObj.Price = det.Price; dObj.Discount = det.Discount; dObj.Total = det.Total; dObj.SalesOrderQuantity = det.SalesOrderQuantity; dObj.SlsProductName = det.SlsProductName; dObj.SlsUnitName = det.SlsUnitName; details.Add(dObj); } objT.SlsDeliverDetails = details; objOperation = _DeliveryService.Save(objT); } else { objOperation.OperationId = -1; } } else { if ((bool)Session["Edit"]) { //Normally not required till now - as this will perform once upon a time objT.ModifiedBy = userId; objT.ModifiedDate = DateTime.Now.Date; objOperation = _DeliveryService.Update(objT); } else { objOperation.OperationId = -2; } } } return Json(objOperation, JsonRequestBehavior.DenyGet); }
public static SlsDeliverDetail MapToSlsSalesDeliveryDetail(SlsDeliverDetailViewModel obj) { SlsDeliverDetail model = new SlsDeliverDetail(); model.Id = obj.Id; model.SlsDeliveryId = obj.SlsDeliveryId; model.SlsProductId = obj.SlsProductId; model.Quantity = obj.Quantity; model.SlsUnitId = obj.SlsUnitId; model.Rate = obj.Rate; model.Price = obj.Price; model.Discount = obj.Discount; model.Total = obj.Total; return model; }