public QuotationLineDto(
            OutgoingInvoiceLine powerofficeLine,
            Product powerofficeProduct,
            int webcrmDeliveryId,
            int webcrmOrganisationId,
            double vatPercentage,
            PowerofficeConfiguration configuration)
        {
            QuotationLineDiscount       = Convert.ToDouble(powerofficeLine.DiscountPercent);
            QuotationLineMemo           = powerofficeLine.Description;
            QuotationLineOpportunityId  = webcrmDeliveryId;
            QuotationLineOrganisationId = webcrmOrganisationId;
            QuotationLinePrice          = GetPrice(powerofficeLine, powerofficeProduct);
            QuotationLineQuantity       = Convert.ToDouble(powerofficeLine.Quantity);
            QuotationLineSortOrder      = powerofficeLine.SortOrder;
            QuotationLineVatPercentage  = vatPercentage;

            SetPropertyValueUsingLinkedDataItemFieldName(configuration.ProductCodeFieldName, powerofficeLine.ProductCode);
            SetPropertyValueUsingLinkedDataItemFieldName(configuration.ProductNameFieldName, powerofficeProduct.Name);
            SetPropertyValueUsingLinkedDataItemFieldName(configuration.ProductIdFieldName, powerofficeProduct.Id.ToString());

            if (!string.IsNullOrWhiteSpace(configuration.ProductUnitFieldName))
            {
                string unit = string.IsNullOrWhiteSpace(powerofficeProduct.Unit)
                    ? QuotationLineLinkedDataItemDto.DataItemDefault
                    : powerofficeProduct.Unit;

                SetPropertyValueUsingLinkedDataItemFieldName(configuration.ProductUnitFieldName, unit);
            }
        }
        private static double GetPrice(OutgoingInvoiceLine powerofficeLine, Product powerofficeProduct)
        {
            if (powerofficeLine.UnitPrice.HasValue)
            {
                return(Convert.ToDouble(powerofficeLine.UnitPrice.Value));
            }

            return(Convert.ToDouble(powerofficeProduct.SalesPrice));
        }
Example #3
0
        public async Task <InvoiceResult> CreateInvoiceAsync(InvoiceInfo info)
        {
            var api = await GetApiAsync();

            if (api.Client == null)
            {
                throw new InvoicingException("Did not find PowerOffice Client");
            }

            var result   = new InvoiceResult();
            var customer = await CreateCustomerIfNotExistsAsync(info, result);

            _logger.LogInformation("* Bruker kunde med epost: {CustomerEmailAddress}, id {CustomerId}",
                                   customer.EmailAddress, customer.Id);

            await CreateProductsIfNotExistsAsync(info);

            var invoice = new OutgoingInvoice
            {
                Status            = OutgoingInvoiceStatus.Draft,
                OrderDate         = info.OrderDate?.ToDateTimeUnspecified(),
                ContractNo        = info.OrderId,
                CustomerReference = info.CustomerInvoiceReference,
                CustomerCode      = customer.Code
            };

            if (!string.IsNullOrWhiteSpace(info.ProjectCode))
            {
                invoice.ProjectCode = info.ProjectCode;
            }

            foreach (var line in info.Lines)
            {
                if (line.Type == InvoiceLineType.Text)
                {
                    invoice.OutgoingInvoiceLines.Add(
                        new OutgoingInvoiceLine
                    {
                        LineType    = VoucherLineType.Text,
                        Description = line.Description
                    });
                }
                else
                {
                    var invoiceLine = new OutgoingInvoiceLine
                    {
                        LineType    = VoucherLineType.Normal,
                        ProductCode = line.ProductCode,
                        Quantity    = line.Quantity,
                        Description = line.Description,
                        UnitPrice   = line.Price
                    };
                    invoice.OutgoingInvoiceLines.Add(invoiceLine);
                }
            }

            var outgoingInvoice = await api.OutgoingInvoice.SaveAsync(invoice);

            result.InvoiceId = outgoingInvoice.Id.ToString();
            return(result);
        }
Example #4
0
        public async Task <bool> CreateInvoiceAsync(Order order)
        {
            if (api.Client == null)
            {
                throw new InvalidOperationException("Did not find PowerOffice Client");
            }

            var customer = await createCustomerIfNotExists(order);

            _logger.LogInformation($"* Bruker kunde med epost: {customer.EmailAddress}, id {customer.Id}");

            await createProductsIfNotExists(order);

            var invoice = new OutgoingInvoice {
                Status            = OutgoingInvoiceStatus.Draft,
                OrderDate         = order.OrderTime,
                ContractNo        = order.OrderId.ToString(),
                CustomerReference = order.Registration.CustomerInvoiceReference,
                CustomerCode      = customer.Code
            };

            if (!string.IsNullOrWhiteSpace(order.Registration.EventInfo.ProjectCode))
            {
                invoice.ProjectCode = order.Registration.EventInfo.ProjectCode;
            }

            foreach (var orderline in order.OrderLines)
            {
                var invoiceLine = new OutgoingInvoiceLine {
                    LineType    = VoucherLineType.Normal,
                    ProductCode = orderline.ItemCode,
                    Quantity    = orderline.Quantity,

                    Description = orderline.ProductVariantId.HasValue? $"{orderline.ProductName} ({orderline.ProductVariantName})": orderline.ProductName,
                    UnitPrice   = orderline.Price
                };
                invoice.OutgoingInvoiceLines.Add(invoiceLine);
            }

            var invoiceDescription = $"Deltakelse for {order.Registration.ParticipantName} på {order.Registration.EventInfo.Title} ";

            if (order.Registration.EventInfo.DateStart != null)
            {
                invoiceDescription += String.Format("{0:d}", order.Registration.EventInfo.DateStart);
            }
            if (order.Registration.EventInfo.DateEnd != null)
            {
                invoiceDescription += "-" + String.Format("{0:d}", order.Registration.EventInfo.DateEnd);
            }

            invoice.OutgoingInvoiceLines.Add(
                new OutgoingInvoiceLine {
                LineType    = VoucherLineType.Text,
                Description = invoiceDescription
            });

            var result = api.OutgoingInvoice.Save(invoice);

            order.ExternalInvoiceId = invoice.Id.ToString();
            order.AddLog("Sendte fakturautkast til PowerOffice");
            _db.Orders.Update(order);
            await _db.SaveChangesAsync();

            return(true);
        }