示例#1
0
        public async Task <PaymentReceiptDto> Save(PaymentReceiptEditDto itemToEdit)
        {
            PaymentReceipt res;

            if (itemToEdit.Id != Guid.Empty)
            {
                _logger.LogDebug($"Calling Update PaymentReceipt for id=[{itemToEdit.Id}]");
                //edit
                res = await this.GetInner(itemToEdit.Id);

                if (res == null)
                {
                    throw new NotFoundException($"PaymentReceipt with id={itemToEdit.Id} not exists!");
                }
                //res.CostAmount = itemToEdit.CostAmount;
                res.PaymentDate = itemToEdit.PaymentDate;
                res.Name        = itemToEdit.Name;
                res.Description = itemToEdit.Description;
                _dbCtx.PaymentReceipts.Update(res);
                _dbCtx.SaveChanges();
            }
            else
            {
                //insert
                res    = itemToEdit.ToEntity();
                res.Id = Guid.NewGuid();
                _logger.LogDebug($"Calling Insert PaymentReceipt for id=[{res.Id}] (temp id, not created yet!)");
                await _dbCtx.PaymentReceipts.AddAsync(res);

                _dbCtx.SaveChanges();
            }
            return(res.ToDto());
        }
示例#2
0
        public async Task <ActionResult <PaymentReceiptDto> > Put([FromBody] PaymentReceiptEditDto value)
        {
            if (value.Id == Guid.Empty)
            {
                throw new Exception("Unable to edit a PaymentReceipt without ID");
            }
            var res = await _service.Save(value);

            return(res);
        }
示例#3
0
        public static PaymentReceipt ToEntity(this PaymentReceiptEditDto e)
        {
            if (e == null)
            {
                return(null);
            }

            var res = new PaymentReceipt();

            res.Id          = e.Id;
            res.IdCustomer  = e.IdCustomer;
            res.PaymentDate = e.PaymentDate;
            res.IssueDate   = e.IssueDate;
            res.ReceiptPath = e.ReceiptPath;
            //res.CostAmount = e.CostAmount;
            res.Name        = e.Name;
            res.Description = e.Description;
            res.PaymentType = e.PaymentType;
            return(res);
        }
示例#4
0
        public async Task <ActionResult <PaymentReceiptDto> > Post([FromBody] PaymentReceiptEditDto value)
        {
            var res = await _service.Save(value);

            return(res);
        }
示例#5
0
        public async Task <PaymentReceiptDto> CreateFastInvoice(PaymentReceiptEditForFastInvoceDto data)
        {
            var editRecipt = new PaymentReceiptEditDto()
            {
                CostAmount  = data.CostAmount,
                Description = data.Description,
                IdCustomer  = data.IdCustomer,
                IssueDate   = data.IssueDate,
                PaymentType = data.PaymentType,
                Name        = data.Name
            };
            var savedReceipt = await Save(editRecipt);

            var detailList = new List <PaymentReceiptDetailDto>();

            foreach (var d in data.PaymentReceiptDetails)
            {
                var customerInstance = new CustomerProductInstanceDto();
                if (d.CustomerProductInstance != null)
                {
                    var editCustomerProduct = new CustomerProductInstanceEditDto()
                    {
                        CostAmount          = d.CustomerProductInstance.CostAmount,
                        Description         = d.CustomerProductInstance.Description,
                        Discount            = d.CustomerProductInstance.Discount,
                        DiscountDescription = d.CustomerProductInstance.DiscountDescription,
                        DiscountType        = d.CustomerProductInstance.DiscountType,
                        ExpirationDate      = d.CustomerProductInstance.ExpirationDate,
                        IdCustomer          = d.CustomerProductInstance.IdCustomer,
                        IdProductInstance   = d.CustomerProductInstance.IdProductInstance,
                        IdReceipt           = savedReceipt.Id,
                        Name           = d.CustomerProductInstance.Name,
                        Price          = d.CustomerProductInstance.Price,
                        ReversalCredit = d.CustomerProductInstance.ReversalCredit,
                        ReversalDate   = d.CustomerProductInstance.ReversalDate,
                        IdReversal     = d.CustomerProductInstance.IdReversal
                    };
                    customerInstance = await _customerInstanceProductService.Value.Save(editCustomerProduct);
                }

                var editReceiptDetail = new PaymentReceiptDetailEditDto()
                {
                    CostAmount        = d.CostAmount,
                    Description       = d.Description,
                    IdReceipt         = savedReceipt.Id,
                    IdResource        = customerInstance.Id != null && customerInstance.Id != Guid.Empty ? customerInstance.Id : d.IdResource,
                    Name              = d.Name,
                    ProductAmount     = d.ProductAmount,
                    ReceiptDetailType = d.ReceiptDetailType
                };

                await _receiptDetailService.Value.Save(editReceiptDetail);
            }

            var invoiceData = new InvoiceRequestData()
            {
                CustomerAddress     = data.CustomerAddress,
                CustomerFiscalCode  = data.CustomerFiscalCode,
                CustomerName        = data.CustomerName,
                IdReceipt           = savedReceipt.Id,
                Description         = data.Description,
                Discount            = data.Discount,
                DiscountDescription = data.DiscountDescription,
                DiscountType        = data.DiscountType
            };

            return(await GenerateInvoice(invoiceData));
        }