private async Task <string> ConstructProductionTicketFilePathAsync(int orderId)
        {
            var query = new QuerySet();

            query.Include.Fields = new string[] { "customer" };
            var order = await _orderDataProvider.GetByIdAsync(orderId, query);

            var year      = order.OrderDate != null ? ((DateTime)order.OrderDate).Year : 0;
            var directory = $"{_productionTicketStorageLocation}{year}{Path.DirectorySeparatorChar}";

            Directory.CreateDirectory(directory);

            var filename = _onlyAlphaNumeric.Replace($"{order.OfferNumber}", "") + $"_{order.Customer.Name}";

            return($"{directory}{filename}.pdf");
        }
Exemplo n.º 2
0
        // Embed relations in deposit resource: reuse old relation if there is one and it hasn't changed
        private async Task EmbedRelations(Deposit deposit, Deposit oldDeposit = null)
        {
            try {
                if (deposit.Invoice != null)
                {
                    if (oldDeposit != null && oldDeposit.Invoice != null && oldDeposit.Invoice.Id == deposit.Invoice.Id)
                    {
                        deposit.Invoice = oldDeposit.Invoice;
                    }
                    else
                    {
                        deposit.Invoice = await _invoiceDataProvider.GetByIdAsync(deposit.Invoice.Id);
                    }
                }

                if (deposit.Payment != null)
                {
                    if (oldDeposit != null && oldDeposit.Payment != null && oldDeposit.Payment.Id == deposit.Payment.Id)
                    {
                        deposit.Payment = oldDeposit.Payment;
                    }
                    else
                    {
                        deposit.Payment = await _paymentDataProvider.GetByIdAsync(deposit.Payment.Id);
                    }
                }

                // Customer cannot be updated. Take customer of oldDeposit on update.
                if (oldDeposit != null)
                {
                    deposit.Customer = oldDeposit.Customer;
                }
                else
                {
                    deposit.Customer = await _customerDataProvider.GetByNumberAsync(deposit.Customer.Id);
                }

                // Order cannot be updated. Take order of oldDeposit on update.
                var includeCustomer = new QuerySet();
                includeCustomer.Include.Fields = new string[] { "customer" };
                if (oldDeposit != null)
                {
                    deposit.Order = oldDeposit.Order;
                }
                else
                {
                    deposit.Order = await _orderDataProvider.GetByIdAsync(deposit.Order.Id, includeCustomer);
                }

                // Invoice cannot be updated. Take invoice of oldDeposit on update.
                // On create the invoice is set by the dataprovider
                if (oldDeposit != null)
                {
                    deposit.Invoice = oldDeposit.Invoice;
                }
            }
            catch (EntityNotFoundException)
            {
                _logger.LogDebug($"Failed to find a related entity");
                throw new IllegalArgumentException("IllegalAttribute", "Not all related entities exist.");
            }
        }
Exemplo n.º 3
0
        // Embed relations in intervention resource: reuse old relation if there is one and it hasn't changed
        private async Task EmbedRelations(Intervention intervention, Intervention oldIntervention = null)
        {
            try {
                if (intervention.WayOfEntry != null)
                {
                    if (oldIntervention != null && oldIntervention.WayOfEntry != null && oldIntervention.WayOfEntry.Id == intervention.WayOfEntry.Id)
                    {
                        intervention.WayOfEntry = oldIntervention.WayOfEntry;
                    }
                    else
                    {
                        intervention.WayOfEntry = await _wayOfEntryDataProvider.GetByIdAsync(int.Parse(intervention.WayOfEntry.Id));
                    }
                }

                if (intervention.Employee != null)
                {
                    if (oldIntervention != null && oldIntervention.Employee != null && oldIntervention.Employee.Id == intervention.Employee.Id)
                    {
                        intervention.Employee = oldIntervention.Employee;
                    }
                    else
                    {
                        intervention.Employee = await _employeeDataProvider.GetByIdAsync(intervention.Employee.Id);
                    }
                }

                if (intervention.Origin != null)
                {
                    if (oldIntervention != null && oldIntervention.Origin != null && oldIntervention.Origin.Id == intervention.Origin.Id)
                    {
                        intervention.Origin = oldIntervention.Origin;
                    }
                    else
                    {
                        intervention.Origin = await _orderDataProvider.GetByIdAsync(intervention.Origin.Id);
                    }
                }

                var technicians = new List <Employee>();
                foreach (var technicianRelation in intervention.Technicians)
                {
                    var technician = await _employeeDataProvider.GetByIdAsync(technicianRelation.Id);

                    technicians.Add(technician);
                }
                intervention.Technicians = technicians;

                // Invoice cannot be updated. Take invoice of oldRequest on update.
                if (oldIntervention != null)
                {
                    intervention.Invoice = oldIntervention.Invoice;
                }
                else
                {
                    intervention.Invoice = null;
                }

                if (intervention.Invoice != null && intervention.Customer == null)
                {
                    intervention.Customer = oldIntervention.Customer;  // Intervention already has an invoice, so it must have a customer
                }
                else
                {
                    if (intervention.Customer != null)
                    {
                        if (oldIntervention != null && oldIntervention.Customer != null && oldIntervention.Customer.Id == intervention.Customer.Id)
                        {
                            intervention.Customer = oldIntervention.Customer;
                        }
                        else
                        {
                            intervention.Customer = await _customerDataProvider.GetByNumberAsync(intervention.Customer.Id);
                        }
                    }
                }

                var includeCustomer = new QuerySet();
                includeCustomer.Include.Fields = new string[] { "customer" };

                // Contact can only be updated through CaseManager. Take contact of oldRequest on update.
                if (oldIntervention != null)
                {
                    intervention.Contact = oldIntervention.Contact;
                }
                else if (intervention.Contact != null)
                {
                    intervention.Contact = await _contactDataProvider.GetByIdAsync(intervention.Contact.Id, includeCustomer);
                }

                // Building can only be updated through CaseManager. Take building of oldRequest on update.
                if (oldIntervention != null)
                {
                    intervention.Building = oldIntervention.Building;
                }
                else if (intervention.Building != null)
                {
                    intervention.Building = await _buildingDataProvider.GetByIdAsync(intervention.Building.Id, includeCustomer);
                }
            }
            catch (EntityNotFoundException)
            {
                _logger.LogDebug($"Failed to find a related entity");
                throw new IllegalArgumentException("IllegalAttribute", "Not all related entities exist.");
            }
        }
Exemplo n.º 4
0
        // Embed relations in deposit invoice resource: reuse old relation if there is one and it hasn't changed
        private async Task EmbedRelationsAsync(DepositInvoice depositInvoice, DepositInvoice oldDepositInvoice = null)
        {
            try {
                if (depositInvoice.VatRate != null)
                {
                    if (oldDepositInvoice != null && oldDepositInvoice.VatRate != null && oldDepositInvoice.VatRate.Id == depositInvoice.VatRate.Id)
                    {
                        depositInvoice.VatRate = oldDepositInvoice.VatRate;
                    }
                    else
                    {
                        depositInvoice.VatRate = await _vatRateDataProvider.GetByIdAsync(int.Parse(depositInvoice.VatRate.Id));
                    }
                }

                // Customer cannot be updated. Take customer of oldDepositInvoice on update.
                if (oldDepositInvoice != null)
                {
                    depositInvoice.Customer = oldDepositInvoice.Customer;
                }
                else
                {
                    depositInvoice.Customer = await _customerDataProvider.GetByNumberAsync(depositInvoice.Customer.Id);
                }

                // Order cannot be updated. Take order of oldDepositInvoice on update.
                if (oldDepositInvoice != null)
                {
                    depositInvoice.Order = oldDepositInvoice.Order;
                }
                else if (depositInvoice.Order != null) // isolated invoice doesn't have an order attached
                {
                    depositInvoice.Order = await _orderDataProvider.GetByIdAsync(depositInvoice.Order.Id);
                }

                var includeCustomer = new QuerySet();
                includeCustomer.Include.Fields = new string[] { "customer" };

                // Contact can only be updated through CaseManager. Take contact of oldDepositInvoice on update.
                if (oldDepositInvoice != null)
                {
                    depositInvoice.Contact = oldDepositInvoice.Contact;
                }
                else if (depositInvoice.Contact != null)
                {
                    depositInvoice.Contact = await _contactDataProvider.GetByIdAsync(depositInvoice.Contact.Id, includeCustomer);
                }

                // Building can only be updated through CaseManager. Take building of oldDepositInvoice on update.
                if (oldDepositInvoice != null)
                {
                    depositInvoice.Building = oldDepositInvoice.Building;
                }
                else if (depositInvoice.Building != null)
                {
                    depositInvoice.Building = await _buildingDataProvider.GetByIdAsync(depositInvoice.Building.Id, includeCustomer);
                }
            }
            catch (EntityNotFoundException)
            {
                _logger.LogDebug($"Failed to find a related entity");
                throw new IllegalArgumentException("IllegalAttribute", "Not all related entities exist.");
            }
        }
Exemplo n.º 5
0
 public async Task <Order> GetByIdAsync(int id, QuerySet query)
 {
     return(await _orderDataProvider.GetByIdAsync(id, query));
 }