public IActionResult Post([FromBody] SalesOrderDetailDto salesOrderDetailDto) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var salesOrderDetail = Mapper.Map <SalesOrderDetail>(salesOrderDetailDto); if (_salesOrderDetailRepository.SalesOrderDetailExists(salesOrderDetail)) { return(StatusCode(500, "SalesOrderDetail already exists.")); } var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var profile = _accountRepository.GetUserProfile(userId); var createdSalesOrderDetail = _salesOrderDetailRepository.CreateSalesOrderDetail(salesOrderDetail, profile.UserProfileId); if (createdSalesOrderDetail == null) { return(StatusCode(500, "A problem happened while handling your request.")); } var createdSalesOrderDetailToReturn = Mapper.Map <SalesOrderDetailDto>(createdSalesOrderDetail); return(Created(createdSalesOrderDetailToReturn)); } catch (Exception ex) { _logger.LogError($"Failed in Post /SalesOrderDetails: {ex}"); return(StatusCode(500, "A problem happened while handling your request.")); } }
public bool SaveSalesOrderDetail(SalesOrderDetailDto newDetails) { this.salesOrderDetail = newDetails.DtoToEntity(); if (this._salesOrderDetail.Insert(this.salesOrderDetail).IsNull()) { return(false); } //_inventoryService.UpdateQuantityOrder(newDetails.ProductId, newDetails.Quantity, Enums.OrderType.SalesOrder); return(true); }
public virtual ActionResult AddSalesOrder(SalesOrderDetailDto dto) { string alertMessage = string.Empty, salesOrder = string.Empty; bool isSuccess = true; List <SalesOrderDetailDto> listOfOrders = new List <SalesOrderDetailDto>(); var inventoryList = _inventoryService.FindByProductId(dto.ProductID); var unitList = _unitService.FindUnitById((int)dto.UnitID); if (inventoryList.IsNull()) { isSuccess = false; Danger(Messages.NoProductFound); } else { if (!dto.IsNull()) { listOfOrders.Add(new SalesOrderDetailDto() { ProductID = dto.ProductID, ProductCode = inventoryList == null ? string.Empty : inventoryList.ProductCode, ProductName = inventoryList == null ? string.Empty : inventoryList.ProductName, ProductExt = inventoryList == null ? string.Empty : inventoryList.ProductExtension, UnitID = dto.UnitID, UnitDesc = unitList == null ? string.Empty : unitList.UnitDesc, UnitPrice = dto.UnitPrice, Quantity = dto.Quantity }); isSuccess = true; salesOrder = this.RenderRazorViewToString(IOBALANCEMVC.OrderManagement.SalesOrder.Views._ListOfOrderSales, listOfOrders); } } alertMessage = this.RenderRazorViewToString(IOBALANCEMVC.Shared.Views._Alerts, string.Empty); var jsonResult = new { isSuccess = isSuccess, alertMessage = alertMessage, salesOrder = salesOrder }; return(Json(jsonResult, JsonRequestBehavior.AllowGet)); }
public static IOBalanceDBV2Entity.SalesOrderDetail DtoToEntity(this SalesOrderDetailDto dto) { IOBalanceDBV2Entity.SalesOrderDetail entity = null; if (!dto.IsNull()) { entity = new IOBalanceDBV2Entity.SalesOrderDetail { SalesOrderID = dto.SalesOrderId, ProductID = dto.ProductId, SalesPrice = dto.SalesPrice, UnitPrice = dto.UnitPrice, Quantity = dto.Quantity, DateCreated = dto.DateCreated, CreatedBy = dto.CreatedBy }; } return(entity); }
public virtual ActionResult SaveSalesOrder(List <SalesOrderListDto> dto, string SalesNo, int CustomerId) { bool isSuccess = false; int createdBy = 1; DateTime dateNow = DateTime.Now; string alertMsg = string.Empty; long salesOrderId = 0; if (!dto.IsNull()) { SalesOrderDto orderDto = new SalesOrderDto() { CreatedBy = createdBy, DateCreated = dateNow, SalesNo = SalesNo, CustomerId = CustomerId, SalesOrderId = 0, IsPrinted = true, IsCorrected = false }; salesOrderId = _orderService.SaveSalesOrder(orderDto); if (salesOrderId == 0) { alertMsg = "Error in inserting Order Id"; } else { foreach (var oDetail in dto) { SalesOrderDetailDto orderDetailDto = new SalesOrderDetailDto() { SalesOrderId = salesOrderId, ProductId = oDetail.ProductId, SalesPrice = oDetail.SalesPrice, Quantity = oDetail.Quantity, UnitPrice = oDetail.UnitPrice, DateCreated = dateNow, CreatedBy = createdBy }; _orderService.SaveSalesOrderDetail(orderDetailDto); var productDetails = _inventoryService.GetAll().Where(p => p.ProductId == oDetail.ProductId).FirstOrDefault(); productDetails.Quantity = (productDetails.Quantity - oDetail.Quantity); _inventoryService.UpdateDetails(productDetails); CustomerPriceDto customerPriceDto = new CustomerPriceDto() { Price = oDetail.UnitPrice, ProductId = oDetail.ProductId, CustomerId = CustomerId, CreatedBy = createdBy, DateCreated = dateNow }; SaveCustomerPrice(customerPriceDto); } isSuccess = true; alertMsg = Messages.InsertSuccess; } } var jsonResult = new { isSuccess = isSuccess, alertMsg = alertMsg, salesOrderId = salesOrderId, customerId = CustomerId, salesNo = SalesNo }; return(Json(jsonResult, JsonRequestBehavior.AllowGet)); }
public virtual ActionResult UpdateQtyDetails(EditQtyProductDto dto, string qtyType) { bool isSuccess = false; string alertMessage = string.Empty; decimal?qtyBefore = dto.EditQuantity; int? createdBy = WebSecurity.GetUserId(User.Identity.Name); if (ModelState.IsValid) { if (!qtyType.IsNull()) { switch (qtyType.ToLower()) { case "add": dto.EditQuantity = dto.EditQuantity + dto.OldQuantity; break; case "minus": dto.EditQuantity = dto.OldQuantity - dto.EditQuantity; break; default: break; } ProductDto newDetails = new ProductDto() { ProductId = dto.ProductId, CategoryId = dto.CategoryId, QuantityUnitId = dto.QuantityUnitId, ProductCode = dto.ProductCode, ProductName = dto.ProductName, ProductDescription = dto.ProductDescription, ProductSize = dto.ProductSize, CurrentNum = dto.CurrentNum, DRNum = dto.DRNum, CartonNum = dto.CartonNum, Quantity = dto.EditQuantity }; if (qtyType.ToLower() == "minus") { SalesOrderDto orderDto = new SalesOrderDto() { CreatedBy = createdBy, DateCreated = DateTime.Now, SalesNo = "PL" + Constants.SalesTemplate, CustomerId = 0, SalesOrderId = 0, IsPrinted = false, IsCorrected = false }; var salesOrderId = _orderService.SaveSalesOrder(orderDto); if (salesOrderId == 0) { alertMessage = string.Format(Messages.ErrorOccuredDuringProcessingThis, "saving in sales order"); } else { SalesOrderDetailDto orderDetailDto = new SalesOrderDetailDto() { SalesOrderId = salesOrderId, ProductId = newDetails.ProductId, SalesPrice = 0, Quantity = (decimal)qtyBefore, UnitPrice = 0, DateCreated = DateTime.Now, CreatedBy = createdBy }; isSuccess = _orderService.SaveSalesOrderDetail(orderDetailDto); if (!isSuccess) { alertMessage = string.Format(Messages.ErrorOccuredDuringProcessingThis, "saving in sales order details"); } else { isSuccess = _inventoryService.UpdateDetails(newDetails); if (!isSuccess) { alertMessage = string.Format(Messages.ErrorOccuredDuringProcessingThis, "updating in product"); } else { alertMessage = Messages.UpdateSuccess; } } } } else { OrderDto orders = new OrderDto() { OrderId = 0, DateCreated = DateTime.Now, CreatedBy = createdBy }; var retPurchaseOrderId = _orderService.SaveOrder(orders); if (retPurchaseOrderId == 0) { alertMessage = string.Format(Messages.ErrorOccuredDuringProcessingThis, "saving in purchase order"); } else { OrderDetailDto orderDetails = new OrderDetailDto() { OrderDetailId = 0, OrderId = retPurchaseOrderId, ProductId = newDetails.ProductId, Quantity = Convert.ToDecimal(qtyBefore), SupplierId = dto.SupplierId }; if (!_orderService.SaveOrderDetail(orderDetails)) { alertMessage = (string.Format(Messages.ErrorOccuredDuringProcessingThis, "saving in purchase order details")); } else { isSuccess = _inventoryService.UpdateDetails(newDetails); if (!isSuccess) { alertMessage = string.Format(Messages.ErrorOccuredDuringProcessingThis, "updating in product"); } else { alertMessage = Messages.UpdateSuccess; } } } } } } var jsonResult = new { isSuccess = isSuccess, alertMessage = alertMessage }; return(Json(jsonResult, JsonRequestBehavior.AllowGet)); }
public virtual ActionResult QueueSalesOrder(List <SalesOrderListDto> dto, int CustomerId, long salesOrderId) { bool isSuccess = false; int createdBy = 1; DateTime dateNow = DateTime.Now; string alertMsg = string.Empty; if (!dto.IsNull()) { var oldSalesOrderDto = _orderService.GetAllSalesOrder().Where(so => so.OrderId == salesOrderId).FirstOrDefault(); if (oldSalesOrderDto.IsNull()) { alertMsg = "No queue order selected"; } else { SalesOrderDto orderDto = new SalesOrderDto() { CreatedBy = createdBy, DateCreated = dateNow, SalesNo = oldSalesOrderDto.SalesNo, CustomerId = oldSalesOrderDto.CustomerId, SalesOrderId = salesOrderId, IsPrinted = false, IsCorrected = false }; if (_orderService.UpdateSalesOrder(orderDto) <= 0) { alertMsg = "Error in updating queue order id"; } else { if (!_orderService.DeleteAllSalesOrderDetail(salesOrderId)) { alertMsg = "Error in deleting all queue order details"; } else { foreach (var oDetail in dto) { SalesOrderDetailDto orderDetailDto = new SalesOrderDetailDto() { SalesOrderId = salesOrderId, ProductId = oDetail.ProductId, SalesPrice = oDetail.SalesPrice, Quantity = oDetail.Quantity, UnitPrice = oDetail.UnitPrice, DateCreated = dateNow, CreatedBy = createdBy }; _orderService.SaveSalesOrderDetail(orderDetailDto); var productDetails = _inventoryService.GetAll().Where(p => p.ProductId == oDetail.ProductId).FirstOrDefault(); productDetails.Quantity = (productDetails.Quantity - oDetail.Quantity); _inventoryService.UpdateDetails(productDetails); CustomerPriceDto customerPriceDto = new CustomerPriceDto() { Price = oDetail.UnitPrice, ProductId = oDetail.ProductId, CustomerId = CustomerId, CreatedBy = createdBy, DateCreated = dateNow }; SaveCustomerPrice(customerPriceDto); } isSuccess = true; alertMsg = Messages.UpdateSuccess; } } } } var jsonResult = new { isSuccess = isSuccess, alertMsg = alertMsg }; return(Json(jsonResult, JsonRequestBehavior.AllowGet)); }