Exemplo n.º 1
0
        public IActionResult Quotation(int id)
        {
            var quote = _salesService.GetSalesQuotationById(id);

            var quoteDto = new Dto.Sales.SalesQuotation()
            {
                Id            = quote.Id,
                CustomerId    = quote.CustomerId,
                CustomerName  = quote.Customer.Party.Name,
                QuotationDate = quote.Date,
                PaymentTermId = quote.PaymentTermId,
                ReferenceNo   = quote.ReferenceNo
            };


            foreach (var line in quote.SalesQuoteLines)
            {
                var lineDto = new Dto.Sales.SalesQuotationLine()
                {
                    Id            = line.Id,
                    ItemId        = line.ItemId,
                    MeasurementId = line.MeasurementId,
                    Quantity      = line.Quantity,
                    Amount        = line.Amount,
                    Discount      = line.Discount
                };
                quoteDto.SalesQuotationLines.Add(lineDto);
            }

            return(new ObjectResult(quoteDto));
        }
Exemplo n.º 2
0
        public IActionResult Quotations()
        {
            var quotes = _salesService.GetSalesQuotes();

            var quoteDtos = new List <Dto.Sales.SalesQuotation>();

            foreach (var quote in quotes)
            {
                var quoteDto = new Dto.Sales.SalesQuotation()
                {
                    Id            = quote.Id,
                    No            = quote.No,
                    CustomerId    = quote.CustomerId,
                    CustomerName  = quote.Customer.Party.Name,
                    PaymentTermId = quote.PaymentTermId,
                    QuotationDate = quote.Date,
                    ReferenceNo   = quote.ReferenceNo
                };

                foreach (var line in quote.SalesQuoteLines)
                {
                    var lineDto = new Dto.Sales.SalesQuotationLine()
                    {
                        ItemId        = line.ItemId,
                        MeasurementId = line.MeasurementId,
                        Quantity      = line.Quantity,
                        Amount        = line.Amount,
                        Discount      = line.Discount
                    };
                    quoteDto.SalesQuotationLines.Add(lineDto);
                }

                quoteDtos.Add(quoteDto);
            }

            return(new ObjectResult(quoteDtos.OrderBy(q => q.Id).Reverse()));
        }
Exemplo n.º 3
0
        public IActionResult SaveQuotation([FromBody] Dto.Sales.SalesQuotation quotationDto)
        {
            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 = quotationDto.Id == 0;
                Core.Domain.Sales.SalesQuoteHeader salesQuote = null;

                if (isNew)
                {
                    salesQuote = new Core.Domain.Sales.SalesQuoteHeader();
                }
                else
                {
                    salesQuote = _salesService.GetSalesQuotationById(quotationDto.Id);
                }

                salesQuote.CustomerId = quotationDto.CustomerId.GetValueOrDefault();
                salesQuote.Date       = quotationDto.QuotationDate;

                salesQuote.ReferenceNo   = quotationDto.ReferenceNo;
                salesQuote.PaymentTermId = quotationDto.PaymentTermId;

                foreach (var line in quotationDto.SalesQuotationLines)
                {
                    if (!isNew)
                    {
                        var existingLine = salesQuote.SalesQuoteLines.Where(id => id.Id == line.Id).FirstOrDefault();
                        if (salesQuote.SalesQuoteLines.Where(id => id.Id == line.Id).FirstOrDefault() != null)
                        {
                            existingLine.Amount        = line.Amount == null ? 0 : line.Amount.Value;
                            existingLine.Discount      = line.Discount == null ? 0 : line.Discount.Value;
                            existingLine.Quantity      = line.Quantity == null ? 0 : line.Quantity.Value;
                            existingLine.ItemId        = line.ItemId.GetValueOrDefault();
                            existingLine.MeasurementId = line.MeasurementId.GetValueOrDefault();
                        }
                        else
                        {
                            var salesQuoteLine = new Core.Domain.Sales.SalesQuoteLine();
                            salesQuoteLine.Amount        = line.Amount == null ? 0 : line.Amount.Value;
                            salesQuoteLine.Discount      = line.Discount == null ? 0 : line.Discount.Value;
                            salesQuoteLine.Quantity      = line.Quantity == null ? 0 : line.Quantity.Value;
                            salesQuoteLine.ItemId        = line.ItemId.GetValueOrDefault();
                            salesQuoteLine.MeasurementId = line.MeasurementId.GetValueOrDefault();

                            salesQuote.SalesQuoteLines.Add(salesQuoteLine);
                        }
                    }
                    else
                    {
                        var salesQuoteLine = new Core.Domain.Sales.SalesQuoteLine();
                        salesQuoteLine.Amount        = line.Amount == null ? 0 : line.Amount.Value;
                        salesQuoteLine.Discount      = line.Discount == null ? 0 : line.Discount.Value;
                        salesQuoteLine.Quantity      = line.Quantity == null ? 0 : line.Quantity.Value;
                        salesQuoteLine.ItemId        = line.ItemId.GetValueOrDefault();
                        salesQuoteLine.MeasurementId = line.MeasurementId.GetValueOrDefault();

                        salesQuote.SalesQuoteLines.Add(salesQuoteLine);
                    }
                }

                if (isNew)
                {
                    _salesService.AddSalesQuote(salesQuote);
                }
                else
                {
                    var deleted = (from line in salesQuote.SalesQuoteLines
                                   where !quotationDto.SalesQuotationLines.Any(x => x.Id == line.Id)
                                   select line).ToList();

                    foreach (var line in deleted)
                    {
                        salesQuote.SalesQuoteLines.Remove(line);
                    }

                    _salesService.UpdateSalesQuote(salesQuote);
                }


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