Esempio n. 1
0
        public async Task <IActionResult> Save([FromBody] Orders orders)
        {
            // stores all document responses
            var orderResponses = new List <OrderResponse> {
            };

            // Find the user responsible of this operation
            var username = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier)?.Value;

            // get the user owner of this operation
            var user = await userRepository.Find(username);

            /* === Instances of Configuration model that represent
             *      configurations of this specific emission point === */
            var serieConf = await configurationRepository.Get("SERIE", user.EmissionPoint.Id);

            var docTypeConf = await configurationRepository.Get("TIPO_DOC_EMISOR", user.EmissionPoint.Id);

            var correlaConf = await configurationRepository.Get("CORRELATIVO", user.EmissionPoint.Id);

            var docNumberConf = await configurationRepository.Get("NUMERO_DOC_EMISOR", user.EmissionPoint.Id);

            var issuerNameConf = await configurationRepository.Get("NOMBRE_EMISOR", user.EmissionPoint.Id);

            var taxRateConf = await configurationRepository.Get("IGV_TASA", user.EmissionPoint.Id);

            foreach (Order order in orders.Data)
            {
                var document = new Document
                {
                    Type           = docTypeConf.Value,
                    Serie          = serieConf.Value,
                    Correlative    = Int32.Parse(correlaConf.Value) + 1,
                    IssuerType     = docTypeConf.Value,
                    IssuerNumber   = docNumberConf.Value,
                    IssuerName     = issuerNameConf.Value,
                    User           = user,
                    EmissionPoint  = user.EmissionPoint,
                    Currency       = order.Currency,
                    TotalAmount    = order.Total,
                    NetAmount      = order.Total - (order.Total * Double.Parse(taxRateConf.Value)),
                    IgvTotalAmount = order.Total * Double.Parse(taxRateConf.Value),
                    CreationDate   = DateTime.Now,
                    EmissionDate   = DateTime.Now,
                    EmissionState  = "P",
                    Creator        = user.Username,
                    Plate          = order.Plate
                };

                var tax = new Tax
                {
                    DocumentType = docTypeConf.Value,
                    Serie        = serieConf.Value,
                    Correlative  = Int32.Parse(correlaConf.Value) + 1,
                    Code         = "",
                    Rate         = Double.Parse(taxRateConf.Value),
                    Amount       = order.Total * Double.Parse(taxRateConf.Value)
                };

                var service = await serviceRepository.Find(order.Service);

                var detail = new Detail
                {
                    DocumentType = docTypeConf.Value,
                    Serie        = serieConf.Value,
                    Correlative  = Int32.Parse(correlaConf.Value) + 1,
                    Service      = service,
                    Quantity     = order.Quantity,
                    Amount       = service.Cost * order.Quantity,
                    Discount     = 0.0,
                    TaxRate      = Double.Parse(taxRateConf.Value),
                    TaxAmount    = (service.Cost * order.Quantity) * Double.Parse(taxRateConf.Value),
                };

                var _document = await documentRepository.Create(document);

                var _tax = await taxRepository.Create(tax);

                var _detail = await detailRepository.Create(detail);

                orderResponses.Add(new OrderResponse
                {
                    Document = _document,
                    Tax      = _tax,
                    Detail   = _detail
                });

                correlaConf.Value = (Int32.Parse(correlaConf.Value) + 1).ToString();
                correlaConf       = await configurationRepository.Update(correlaConf, user.EmissionPoint.Id);
            }

            return(Json(new StandardResponse
            {
                Status = 200,
                // Data = await documentRepository.Get(docTypeConf.Value, serieConf.Value, Int32.Parse(correlaConf.Value))
                // Data = new OrderResponse
                // {
                //     Document = _document,
                //     Tax = _tax,
                //     Detail = _detail
                // }
                Data = orderResponses
            }));
        }
Esempio n. 2
0
        public void CreateTax(TaxDetails taxDetails)
        {
            var tax = Mapper.Map <Tax>(taxDetails);

            _taxRepository.Create(tax);
        }
Esempio n. 3
0
        public async Task <TaxReadModel> Create(TaxWriteModel model, CancellationToken cancellationToken)
        {
            ValidatePeriod(model.PeriodStartDate, model.PeriodLength());

            return(await _taxRepository.Create(model, cancellationToken));
        }