Ejemplo n.º 1
0
        public IActionResult AddSalesOrder([FromBody] Dto.Sales.SalesOrder salesorderDto)
        {
            try
            {
                var salesOrder = new Core.Domain.Sales.SalesOrderHeader()
                {
                    CustomerId = salesorderDto.CustomerId,
                    Date       = salesorderDto.OrderDate,
                };

                foreach (var line in salesorderDto.SalesOrderLines)
                {
                    var salesOrderLine = new Core.Domain.Sales.SalesOrderLine();
                    salesOrderLine.Amount        = line.Amount.GetValueOrDefault();
                    salesOrderLine.Discount      = line.Discount.GetValueOrDefault();
                    salesOrderLine.Quantity      = line.Quantity.GetValueOrDefault();
                    salesOrderLine.ItemId        = line.ItemId.GetValueOrDefault();
                    salesOrderLine.MeasurementId = line.MeasurementId.GetValueOrDefault();

                    salesOrder.SalesOrderLines.Add(salesOrderLine);
                }

                _salesService.AddSalesOrder(salesOrder, true);

                salesorderDto.Id = salesOrder.Id;

                return(new ObjectResult(salesorderDto));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(ex));
            }
        }
Ejemplo n.º 2
0
        public IActionResult CreateSalesOrder([FromBody] Model.Sales.SalesOrder model)
        {
            try
            {
                var salesOrder = new Core.Domain.Sales.SalesOrderHeader()
                {
                    CustomerId = model.CustomerId,
                    Date       = model.OrderDate,
                };

                foreach (var line in model.SalesOrderLines)
                {
                    var salesOrderLine = new Core.Domain.Sales.SalesOrderLine();
                    salesOrderLine.Amount        = line.Amount;
                    salesOrderLine.Discount      = line.Discount;
                    salesOrderLine.Quantity      = line.Quantity;
                    salesOrderLine.ItemId        = line.ItemId;
                    salesOrderLine.MeasurementId = line.MeasurementId;

                    salesOrder.SalesOrderLines.Add(salesOrderLine);
                }

                _salesService.AddSalesOrder(salesOrder, true);

                model.Id = salesOrder.Id;

                return(new ObjectResult(model));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(ex));
            }
        }
Ejemplo n.º 3
0
        public ActionResult SaveOrder(Models.ViewModels.Sales.SalesHeaderViewModel model)
        {
            SalesOrderHeader order = null;

            if (model.Id == 0)
            {
                order           = new SalesOrderHeader();
                order.CreatedBy = User.Identity.Name;
                order.CreatedOn = DateTime.Now;
            }
            else
            {
                order = _salesService.GetSalesOrderById(model.Id);
            }

            order.ModifiedBy    = User.Identity.Name;
            order.ModifiedOn    = DateTime.Now;
            order.CustomerId    = model.CustomerId.Value;
            order.PaymentTermId = model.PaymentTermId;
            order.Date          = model.Date;

            foreach (var line in model.SalesLine.SalesLineItems)
            {
                SalesOrderLine lineItem = null;
                var            item     = _inventoryService.GetItemByNo(line.ItemNo);
                if (!line.Id.HasValue)
                {
                    lineItem           = new SalesOrderLine();
                    lineItem.CreatedBy = User.Identity.Name;
                    lineItem.CreatedOn = DateTime.Now;
                    order.SalesOrderLines.Add(lineItem);
                }
                else
                {
                    lineItem = order.SalesOrderLines.Where(i => i.Id == line.Id).FirstOrDefault();
                }

                lineItem.ModifiedBy    = User.Identity.Name;
                lineItem.ModifiedOn    = DateTime.Now;
                lineItem.ItemId        = line.ItemId;
                lineItem.MeasurementId = item.SellMeasurementId.Value;
                lineItem.Quantity      = line.Quantity;
                lineItem.Discount      = line.Discount;
                lineItem.Amount        = line.Price;
            }

            if (model.Id == 0)
            {
                _salesService.AddSalesOrder(order, true);
            }
            else
            {
                _salesService.UpdateSalesOrder(order);
            }

            return(RedirectToAction("SalesOrders"));
        }