Example #1
0
        public async Task <ActionResult <PaymentReceiptDetailDto> > Put([FromBody] PaymentReceiptDetailEditDto value)
        {
            if (value.Id == Guid.Empty)
            {
                throw new Exception("Unable to edit a PaymentReceiptDetail without ID");
            }
            var res = await _service.Save(value);

            return(res);
        }
Example #2
0
        public static PaymentReceiptDetail ToEntity(this PaymentReceiptDetailEditDto e)
        {
            if (e == null)
            {
                return(null);
            }

            var res = new PaymentReceiptDetail();

            res.Id                = e.Id;
            res.IdResource        = e.IdResource;
            res.IdReceipt         = e.IdReceipt;
            res.ReceiptDetailType = (dal.Entities.ReceiptDetailType)e.ReceiptDetailType;
            res.CostAmount        = e.CostAmount * e.ProductAmount;
            res.Name              = e.Name;
            res.Description       = e.Description;
            res.ProductAmount     = e.ProductAmount;
            return(res);
        }
        public async Task <PaymentReceiptDetailDto> Save(PaymentReceiptDetailEditDto itemToEdit)
        {
            PaymentReceiptDetail res;

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

                if (res == null)
                {
                    throw new NotFoundException($"PaymentReceiptDetail with id={itemToEdit.Id} not exists!");
                }
                await removePaymentResource(res.ReceiptDetailType, res.IdResource, false);

                res.CostAmount        = itemToEdit.CostAmount * itemToEdit.ProductAmount;
                res.Name              = itemToEdit.Name;
                res.Description       = itemToEdit.Description;
                res.IdResource        = itemToEdit.IdResource;
                res.ProductAmount     = itemToEdit.ProductAmount;
                res.ReceiptDetailType = (dal.Entities.ReceiptDetailType)itemToEdit.ReceiptDetailType;
                _dbCtx.PaymentReceiptDetails.Update(res);
            }
            else
            {
                //insert
                res    = itemToEdit.ToEntity();
                res.Id = Guid.NewGuid();
                _logger.LogDebug($"Calling Insert PaymentReceiptDetail for id=[{res.Id}] (temp id, not created yet!)");
                await _dbCtx.PaymentReceiptDetails.AddAsync(res);

                _dbCtx.SaveChanges();
            }
            // add receipt reference to destination table
            await addPaymentResource(itemToEdit.ReceiptDetailType, itemToEdit.IdResource, itemToEdit.IdReceipt, false);

            _dbCtx.SaveChanges();
            return(res.ToDto());
        }
Example #4
0
        public async Task <ActionResult <PaymentReceiptDetailDto> > Post([FromBody] PaymentReceiptDetailEditDto value)
        {
            var res = await _service.Save(value);

            return(res);
        }
Example #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));
        }