Пример #1
0
        protected virtual async Task Create(CreateOrEditSalesOrderDto input)
        {
            var salesOrder = new SalesOrder
            {
                //Id = 0,
                Number = CreateSalesOrderNumber(input.Date, input.CustomerId),
                ProcessedBySurabaya = input.ProcessedBySurabaya,
                CustomerId          = input.CustomerId,
                Date               = input.Date,
                Deadline           = input.Deadline,
                Amount             = decimal.Parse(input.Amount.Replace(".", "")),
                ProductionStatusId = 10, // 10 - New
                MarkForDelete      = false
            };

            //Iterate Sales Order Lines
            var           salesOrderLineList  = new List <SalesOrderLine>();
            List <string> salesOrderLineNames = new List <string>();

            foreach (var item in input.SalesOrderLines.ToList())
            {
                //Create Sales Order Line
                var markForDelete = item.MarkForDelete;
                var name          = item.Name;

                if (markForDelete)
                {
                    //Remove from collection
                    input.SalesOrderLines.Remove(item);
                }
                else
                {
                    var salesOrderLine = new SalesOrderLine
                    {
                        Id          = 0,
                        Name        = item.Name,
                        Description = item.Description,
                        Quantity    = decimal.Parse(item.Quantity.Replace(".", "")),
                        Price       = decimal.Parse(item.UnitPrice.Replace(".", "")),
                        Amount      = decimal.Parse(item.LineAmount.Replace(".", ""))
                    };

                    //Add item to collection
                    salesOrderLineList.Add(salesOrderLine);
                    salesOrderLineNames.Add(item.Name);
                }
            }

            //Add collection to parent
            salesOrder.SalesOrderLineNames = string.Join(", ", salesOrderLineNames);
            salesOrder.SalesOrderLines     = salesOrderLineList;

            //Create Sales Order
            int newSalesOrderId = _salesOrderRepository.InsertAndGetId(salesOrder);

            //Create Sales Invoice
            var salesInvoice = new SalesInvoice
            {
                Number                = salesOrder.Number.Substring(1),
                Date                  = salesOrder.Date,
                DueDate               = salesOrder.Deadline,
                SalesOrderId          = newSalesOrderId,
                Amount                = salesOrder.Amount,
                Paid                  = 0,
                Outstanding           = salesOrder.Amount,
                SalesInvoiceLineNames = salesOrder.SalesOrderLineNames,
                MarkForDelete         = false
            };

            int newSalesInvoiceId = await _salesInvoiceRepository.InsertAndGetIdAsync(salesInvoice);
        }
Пример #2
0
        public async Task <SalesOrderOutput> GetSalesOrderForEdit(NullableIdDto input)
        {
            SalesOrder salesOrder        = null;
            var        salesOrderLine    = new SalesOrderLine();
            var        salesOrderLineDto = new SalesOrderLineDto();
            var        salesOrderOutput  = new SalesOrderOutput();
            List <SalesOrderLineDto> salesOrderLineDtoList = new List <SalesOrderLineDto>();


            //Sales Order
            if (input.Id.HasValue)
            {
                salesOrder = await _salesOrderRepository
                             .GetAllIncluding(
                    s => s.SalesOrderLines
                    ).FirstOrDefaultAsync(s => s.Id.Equals(input.Id));

                foreach (var line in salesOrder.SalesOrderLines.ToList())
                {
                    salesOrderLineDto = new SalesOrderLineDto
                    {
                        Id          = line.Id,
                        Name        = line.Name,
                        Description = line.Description,
                        Quantity    = line.Quantity,
                        Price       = line.Price,
                        Amount      = line.Amount
                    };

                    salesOrderLineDtoList.Add(salesOrderLineDto);
                }
                salesOrderOutput.SalesOrder      = ObjectMapper.Map <SalesOrderDto>(salesOrder);
                salesOrderOutput.SalesOrderLines = salesOrderLineDtoList;
            }
            else
            {
                salesOrderLineDto = new SalesOrderLineDto
                {
                    Id          = 0,
                    Name        = "",
                    Description = "",
                    Quantity    = 0,
                    Price       = 0,
                    Amount      = 0
                };

                salesOrderLineDtoList.Add(salesOrderLineDto);
                salesOrderOutput.SalesOrderLines = salesOrderLineDtoList;
            }


            //Sales Order
            salesOrderOutput.SalesOrder = salesOrder != null
                        ? ObjectMapper.Map <SalesOrderDto>(salesOrder)
                        : new SalesOrderDto();



            //salesOrderOutput.Customers

            var customers = _lookup_customerRepository
                            .GetAll()
                            .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name + " (" + c.Company + ")")
            {
                IsSelected = salesOrderOutput.SalesOrder.CustomerId == c.Id
            })
                            .ToList();

            if (!input.Id.HasValue)
            {
                var def = new ComboboxItemDto("", "Please select ...")
                {
                    IsSelected = true
                };

                customers.Add(def);
            }

            salesOrderOutput.Customers = customers;

            //ProductionStatus
            salesOrderOutput.ProductionStatuses = _lookup_productionStatusRepository
                                                  .GetAll()
                                                  .Select(c => new ComboboxItemDto(c.Id.ToString(), c.Name)
            {
                IsSelected = salesOrderOutput.SalesOrder.ProductionStatusId == c.Id
            })
                                                  .ToList();



            return(salesOrderOutput);
        }