コード例 #1
0
ファイル: SalesController.cs プロジェクト: jontacky/accountgo
        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));
            }
        }
コード例 #2
0
ファイル: SalesController.cs プロジェクト: jontacky/accountgo
        public IActionResult SalesOrders()
        {
            var salesOrders = _salesService.GetSalesOrders();
            IList <Dto.Sales.SalesOrder> salesOrdersDto = new List <Dto.Sales.SalesOrder>();


            try
            {
                foreach (var salesOrder in salesOrders)
                {
                    var salesOrderDto = new Dto.Sales.SalesOrder()
                    {
                        Id            = salesOrder.Id,
                        PaymentTermId = salesOrder.PaymentTermId,
                        CustomerId    = salesOrder.CustomerId.Value,
                        CustomerNo    = salesOrder.Customer.No,
                        CustomerName  = salesOrder.Customer.Party.Name,
                        OrderDate     = salesOrder.Date,
                        ReferenceNo   = salesOrder.ReferenceNo,
                        Status        = (int)salesOrder.Status.GetValueOrDefault(),
                        No            = salesOrder.No
                    };

                    foreach (var line in salesOrder.SalesOrderLines)
                    {
                        var lineDto = new Dto.Sales.SalesOrderLine()
                        {
                            ItemId                = line.ItemId,
                            MeasurementId         = line.MeasurementId,
                            Quantity              = line.Quantity,
                            Amount                = line.Amount,
                            Discount              = line.Discount,
                            RemainingQtyToInvoice = line.GetRemainingQtyToInvoice()
                        };
                        salesOrderDto.SalesOrderLines.Add(lineDto);
                    }

                    salesOrdersDto.Add(salesOrderDto);
                }

                return(new ObjectResult(salesOrdersDto));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(ex));
            }
        }
コード例 #3
0
ファイル: SalesController.cs プロジェクト: jontacky/accountgo
        public IActionResult SalesOrder(int id)
        {
            try
            {
                var salesOrder = _salesService.GetSalesOrderById(id);

                var salesOrderDto = new Dto.Sales.SalesOrder()
                {
                    Id              = salesOrder.Id,
                    CustomerId      = salesOrder.CustomerId.Value,
                    CustomerNo      = salesOrder.Customer.No,
                    CustomerName    = _salesService.GetCustomerById(salesOrder.CustomerId.Value).Party.Name,
                    OrderDate       = salesOrder.Date,
                    PaymentTermId   = salesOrder.PaymentTermId,
                    ReferenceNo     = salesOrder.ReferenceNo,
                    SalesOrderLines = new List <Dto.Sales.SalesOrderLine>()
                };

                foreach (var line in salesOrder.SalesOrderLines)
                {
                    var lineDto = new Dto.Sales.SalesOrderLine();
                    lineDto.Id                     = line.Id;
                    lineDto.Amount                 = line.Amount;
                    lineDto.Discount               = line.Discount;
                    lineDto.Quantity               = line.Quantity;
                    lineDto.ItemId                 = line.ItemId;
                    lineDto.ItemDescription        = line.Item.Description;
                    lineDto.MeasurementId          = line.MeasurementId;
                    lineDto.MeasurementDescription = line.Measurement.Description;
                    lineDto.RemainingQtyToInvoice  = line.GetRemainingQtyToInvoice();

                    salesOrderDto.SalesOrderLines.Add(lineDto);
                }

                return(new ObjectResult(salesOrderDto));
            }
            catch (Exception ex)
            {
                return(new ObjectResult(ex));
            }
        }
コード例 #4
0
ファイル: SalesController.cs プロジェクト: jontacky/accountgo
        public IActionResult SaveSalesOrder([FromBody] Dto.Sales.SalesOrder salesOrderDto)
        {
            string[] errors = null;
            try
            {
                if (!ModelState.IsValid)
                {
                    errors = new string[ModelState.ErrorCount];
                    foreach (var val in ModelState.Values)
                    {
                        for (int i = 0; i < ModelState.ErrorCount; i++)
                        {
                            errors[i] = val.Errors[i].ErrorMessage;
                        }
                    }

                    return(new BadRequestObjectResult(errors));
                }

                bool isNew = salesOrderDto.Id == 0;
                Core.Domain.Sales.SalesOrderHeader salesOrder = null;

                if (isNew)
                {
                    salesOrder        = new Core.Domain.Sales.SalesOrderHeader();
                    salesOrder.Status = SalesOrderStatus.Open;
                }
                else
                {
                    salesOrder = _salesService.GetSalesOrderById(salesOrderDto.Id);
                }

                salesOrder.CustomerId    = salesOrderDto.CustomerId;
                salesOrder.Date          = salesOrderDto.OrderDate;
                salesOrder.PaymentTermId = salesOrderDto.PaymentTermId;
                salesOrder.ReferenceNo   = salesOrderDto.ReferenceNo;

                foreach (var line in salesOrderDto.SalesOrderLines)
                {
                    if (!isNew)
                    {
                        var existingLine = salesOrder.SalesOrderLines.Where(id => id.Id == line.Id).FirstOrDefault();
                        if (salesOrder.SalesOrderLines.Where(id => id.Id == line.Id).FirstOrDefault() != null)
                        {
                            existingLine.Amount        = line.Amount.GetValueOrDefault();
                            existingLine.Discount      = line.Discount.GetValueOrDefault();
                            existingLine.Quantity      = line.Quantity.GetValueOrDefault();
                            existingLine.ItemId        = line.ItemId.GetValueOrDefault();
                            existingLine.MeasurementId = line.MeasurementId.GetValueOrDefault();
                        }
                        else
                        {
                            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);
                        }
                    }
                    else
                    {
                        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);
                    }
                }

                if (isNew)
                {
                    _salesService.AddSalesOrder(salesOrder, true);
                }
                else
                {
                    var deleted = (from line in salesOrder.SalesOrderLines
                                   where !salesOrderDto.SalesOrderLines.Any(x => x.Id == line.Id)
                                   select line).ToList();

                    foreach (var line in deleted)
                    {
                        if (line.SalesInvoiceLines.Count() > 0)
                        {
                            throw new Exception("The line cannot be deleted. An invoice line is created from the item.");
                        }
                    }

                    foreach (var line in deleted)
                    {
                        salesOrder.SalesOrderLines.Remove(line);
                    }

                    _salesService.UpdateSalesOrder(salesOrder);
                }


                return(new OkObjectResult(Ok()));
            }
            catch (Exception ex)
            {
                errors = new string[1] {
                    ex.Message
                };
                return(new BadRequestObjectResult(errors));
            }
        }