コード例 #1
0
        //
        // POST: /OutgoingInvoice/Delete/5
        public ActionResult Delete(int id)
        {
            OutgoingInvoice outgoingInvoice = ctx.OutgoingInvoices.Where(o => o.IdOutgoingInvoice == id).First();
            string          currUserId      = User.Identity.GetUserId();

            //redirects user to the 403 page if he is trying to change data that is not his own
            if (outgoingInvoice.ApplicationUserId != currUserId)
            {
                throw new HttpException(403, "Forbidden");
            }
            try
            {
                // TODO: Add delete logic here

                ctx.OutgoingInvoices.Remove(outgoingInvoice);


                ctx.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(RedirectToAction("Error", "Shared"));
            }
        }
コード例 #2
0
        public void Handle(OutgoingInvoiceIssuedEvent message)
        {
            var invoice = new OutgoingInvoice();

            invoice.Amount              = message.Amount;
            invoice.Date                = message.InvoiceDate;
            invoice.Description         = message.Description;
            invoice.Number              = message.InvoiceNumber;
            invoice.OriginalId          = message.InvoiceId;
            invoice.PurchaseOrderNumber = message.PurchaseOrderNumber;
            invoice.Taxes               = message.Taxes;
            invoice.TotalPrice          = message.TotalPrice;
            invoice.Customer            = new Invoice.PartyInfo()
            {
                City    = message.Customer.City,
                Country = message.Customer.Country,
                Name    = message.Customer.Name,
                NationalIdentificationNumber = message.Customer.NationalIdentificationNumber,
                OriginalId = message.Customer.Id,
                PostalCode = message.Customer.PostalCode,
                StreetName = message.Customer.StreetName,
                VatIndex   = message.Customer.VatIndex
            };
            using (var ctx = new AccountancyContext())
            {
                ctx.OutgoingInvoices.Add(invoice);
                ctx.SaveChanges();
            }
        }
コード例 #3
0
        public ActionResult Create(OutgoingInvoiceViewModel outgoingInvoiceView)
        {
            try
            {
                // TODO: Add insert logic here
                string currUserId = User.Identity.GetUserId();

                decimal  amount = Convert.ToDecimal(outgoingInvoiceView.Amount);
                DateTime date   = Convert.ToDateTime(outgoingInvoiceView.Date);

                OutgoingInvoice outgoingInvoice = new OutgoingInvoice()
                {
                    ApplicationUserId   = currUserId,
                    DateOutgoingInvoice = date,
                    InvoiceClassNumber  = outgoingInvoiceView.InvoiceClassNumber,
                    CustomerInfo        = outgoingInvoiceView.CustomerInfo,
                    Amount = amount
                };


                ctx.OutgoingInvoices.Add(outgoingInvoice);
                ctx.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(RedirectToAction("Error", "Shared"));
            }
        }
コード例 #4
0
        //
        // GET: /OutgoingInvoice/Edit/5
        public ActionResult Edit(int id)
        {
            OutgoingInvoice outgoingInvoice = ctx.OutgoingInvoices.Where(o => o.IdOutgoingInvoice == id).First();

            string currUserId = User.Identity.GetUserId();

            //redirects user to the 403 page if he is trying to change data that is not his own
            if (outgoingInvoice.ApplicationUserId != currUserId)
            {
                throw new HttpException(403, "Forbidden");
            }


            OutgoingInvoiceViewModel outgoingInvoiceView = new OutgoingInvoiceViewModel()
            {
                Id = outgoingInvoice.IdOutgoingInvoice,
                ApplicationUserId = outgoingInvoice.ApplicationUserId,
                Date = outgoingInvoice.DateOutgoingInvoice.ToShortDateString(),
                InvoiceClassNumber = outgoingInvoice.InvoiceClassNumber,
                CustomerInfo       = outgoingInvoice.CustomerInfo,
                Amount             = outgoingInvoice.Amount.ToString()
            };

            return(View(outgoingInvoiceView));
        }
コード例 #5
0
        public async Task <OutgoingInvoice> UpdateInvoice(OutgoingInvoice invoice)
        {
            var updateResponse = await AuthorizedPost("OutgoingInvoice", invoice);

            var updatedInvoice = await DeserializeScalarResponse <OutgoingInvoice>(updateResponse, "outgoing invoice");

            return(updatedInvoice);
        }
コード例 #6
0
        public void Update(
            OutgoingInvoice powerofficeDelivery,
            int webcrmOrganisationId,
            PowerofficeConfiguration configuration)
        {
            DeliveryErpSyncDateTime = DateTime.UtcNow;
            DeliveryOrderDate       = powerofficeDelivery.OrderDate;
            DeliveryOrganisationId  = webcrmOrganisationId;

            SetPowerofficeDeliveryId(configuration.DeliveryIdFieldName, powerofficeDelivery.Id);
        }
コード例 #7
0
        public DeliveryDto(
            OutgoingInvoice powerofficeDelivery,
            int webcrmOrganisationId,
            PowerofficeConfiguration configuration)
        {
            DeliveryAssignedTo  = 0;
            DeliveryAssignedTo2 = 0;
            DeliveryResponsible = 0;

            Update(powerofficeDelivery, webcrmOrganisationId, configuration);
        }
コード例 #8
0
        public async Task Handle(OutgoingInvoiceIssuedEvent message)
        {
            var invoice = new OutgoingInvoice();

            invoice.TaxableAmount       = message.TaxableAmount;
            invoice.Currency            = message.Currency;
            invoice.Date                = message.InvoiceDate;
            invoice.DueDate             = message.DueDate;
            invoice.Description         = message.Description;
            invoice.Number              = message.InvoiceNumber;
            invoice.OriginalId          = message.InvoiceId;
            invoice.PurchaseOrderNumber = message.PurchaseOrderNumber;
            invoice.Taxes               = message.Taxes;
            invoice.TotalPrice          = message.TotalPrice;
            invoice.IsOverdue           = false;
            invoice.IsPaid              = false;
            invoice.Customer            = new Invoice.PartyInfo()
            {
                City    = message.Customer.City,
                Country = message.Customer.Country,
                Name    = message.Customer.Name,
                NationalIdentificationNumber = message.Customer.NationalIdentificationNumber,
                OriginalId = message.Customer.Id,
                PostalCode = message.Customer.PostalCode,
                StreetName = message.Customer.StreetName,
                VatIndex   = message.Customer.VatIndex
            };
            invoice.Supplier = new Invoice.PartyInfo()
            {
                City    = message.Supplier.City,
                Country = message.Supplier.Country,
                Name    = message.Supplier.Name,
                NationalIdentificationNumber = message.Supplier.NationalIdentificationNumber,
                OriginalId = message.Supplier.Id,
                PostalCode = message.Supplier.PostalCode,
                StreetName = message.Supplier.StreetName,
                VatIndex   = message.Supplier.VatIndex
            };
            using (var ctx = new AccountancyDbContext(Options))
            {
                ctx.OutgoingInvoices.Add(invoice);
                await ctx.SaveChangesAsync();
            }
        }
コード例 #9
0
ファイル: PowerOfficeService.cs プロジェクト: losol/eventuras
        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);
        }
コード例 #10
0
        public async Task Handle(OutgoingInvoiceIssuedEvent message)
        {
            var invoice = new OutgoingInvoice();

            invoice.TaxableAmount       = message.TaxableAmount;
            invoice.Currency            = message.Currency;
            invoice.Date                = message.InvoiceDate;
            invoice.DueDate             = message.DueDate;
            invoice.Description         = message.Description;
            invoice.Number              = message.InvoiceNumber;
            invoice.OriginalId          = message.InvoiceId;
            invoice.PurchaseOrderNumber = message.PurchaseOrderNumber;
            invoice.Taxes               = message.Taxes;
            invoice.TotalPrice          = message.TotalPrice;
            invoice.IsOverdue           = false;
            invoice.IsPaid              = false;
            invoice.Customer            = new Invoice.PartyInfo()
            {
                City    = message.Customer.City,
                Country = message.Customer.Country,
                Name    = message.Customer.Name,
                NationalIdentificationNumber = message.Customer.NationalIdentificationNumber,
                OriginalId = message.Customer.Id,
                PostalCode = message.Customer.PostalCode,
                StreetName = message.Customer.StreetName,
                VatIndex   = message.Customer.VatIndex
            };
            invoice.Supplier = new Invoice.PartyInfo()
            {
                City    = message.Supplier.City,
                Country = message.Supplier.Country,
                Name    = message.Supplier.Name,
                NationalIdentificationNumber = message.Supplier.NationalIdentificationNumber,
                OriginalId = message.Supplier.Id,
                PostalCode = message.Supplier.PostalCode,
                StreetName = message.Supplier.StreetName,
                VatIndex   = message.Supplier.VatIndex
            };

            if (message.LineItems != null && message.LineItems.Count() > 0)
            {
                invoice.InvoiceLineItems = message.LineItems.Select(i => new InvoiceLineItem
                {
                    Code        = i.Code,
                    Description = i.Description,
                    Quantity    = i.Quantity,
                    TotalPrice  = i.TotalPrice,
                    UnitPrice   = i.UnitPrice,
                    Vat         = i.Vat
                }).ToList();
            }

            if (message.PricesByVat != null && message.PricesByVat.Count() > 0)
            {
                invoice.PricesByVat = message.PricesByVat.Select(p => new PriceByVat
                {
                    TaxableAmount = p.TaxableAmount,
                    TotalPrice    = p.TotalPrice,
                    VatAmount     = p.VatAmount,
                    VatRate       = p.VatRate
                }).ToList();
            }

            if (message.NonTaxableItems != null && message.NonTaxableItems.Count() > 0)
            {
                invoice.NonTaxableItems = message.NonTaxableItems.Select(t => new NonTaxableItem
                {
                    Description = t.Description,
                    Amount      = t.Amount
                }).ToList();
            }

            invoice.PricesAreVatIncluded = message.PricesAreVatIncluded;

            using (var ctx = new AccountancyDbContext(Options))
            {
                ctx.OutgoingInvoices.Add(invoice);
                await ctx.SaveChangesAsync();
            }
        }
コード例 #11
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);
        }
コード例 #12
0
        public async Task CopyDeliveryFromPoweroffice(OutgoingInvoice powerofficeDelivery)
        {
            var matchingWebcrmDelivery = await WebcrmClient.GetDeliveryByField(Configuration.DeliveryIdFieldName, powerofficeDelivery.Id.ToString());

            // Creating or updating a delivery in webCRM requires multiple calls to the API. If one of the call fails, the queue message will be retried, and this should make the incorrect state very temporary.
            int webcrmDeliveryId;
            int webcrmOrganisationId;

            if (matchingWebcrmDelivery == null)
            {
                if (!powerofficeDelivery.CustomerCode.HasValue)
                {
                    Logger.LogInformation("The PowerOffice delivery is not associated with a customer, so we cannot create it in webCRM.");
                    return;
                }

                // PowerOffice deliveries are associated with the Code of the organisation and not the Id.
                var webcrmOrganisation = await WebcrmClient.GetOrganisationByField(Configuration.OrganisationNumberFieldName, powerofficeDelivery.CustomerCode.ToString());

                if (webcrmOrganisation == null)
                {
                    throw new ApplicationException($"Not copying the delivery to webCRM because no organisation found with the PowerOffice code {powerofficeDelivery.CustomerCode}.");
                }

                Logger.LogTrace("Copying delivery from PowerOffice, creating a new one.");

                webcrmOrganisationId = webcrmOrganisation.OrganisationId;

                var newWebcrmDelivery = new DeliveryDto(powerofficeDelivery, webcrmOrganisation.OrganisationId, Configuration);
                webcrmDeliveryId = await WebcrmClient.CreateDelivery(newWebcrmDelivery);
            }
            else
            {
                if (!matchingWebcrmDelivery.DeliveryOrganisationId.HasValue)
                {
                    throw new ApplicationException("Not copying the delivery to webCRM because the matching webCRM delivery does not have a DeliveryOrganisationId.");
                }

                // Not comparing the two deliveries, since we're only synchronising deliveries one way.

                Logger.LogTrace("Copying delivery from PowerOffice, updating an existing one.");

                webcrmOrganisationId = matchingWebcrmDelivery.DeliveryOrganisationId.Value;

                // We cannot delete a delivery through the API, so we delete the associated delivery lines, but modify the delivery.
                var lines = await WebcrmClient.GetQuotationLines(matchingWebcrmDelivery.DeliveryId);

                Logger.LogTrace($"Deleting {lines.Count} associated quotation lines.");
                foreach (var line in lines)
                {
                    await WebcrmClient.DeleteQuotationLine(line.QuotationLineId);
                }

                matchingWebcrmDelivery.Update(powerofficeDelivery, matchingWebcrmDelivery.DeliveryOrganisationId.Value, Configuration);
                await WebcrmClient.UpdateDelivery(matchingWebcrmDelivery);

                webcrmDeliveryId = matchingWebcrmDelivery.DeliveryId;
            }

            Logger.LogTrace($"Copying {powerofficeDelivery.OutgoingInvoiceLines.Count} quotation lines from PowerOffice.");
            const int millisecondsDelayBetweenCalls = 20;

            foreach (var powerofficeLine in powerofficeDelivery.OutgoingInvoiceLines)
            {
                Logger.LogTrace("Copying quotation lines from PowerOffice.");
                var powerofficeProduct = await PowerofficeClient.GetProductByCode(powerofficeLine.ProductCode);

                var webcrmLine = new QuotationLineDto(
                    powerofficeLine,
                    powerofficeProduct,
                    webcrmDeliveryId,
                    webcrmOrganisationId,
                    Configuration);

                await WebcrmClient.CreateQuotationLine(webcrmLine);

                await Task.Delay(millisecondsDelayBetweenCalls);
            }
        }