Beispiel #1
0
        public async Task HandleDequeuedMessage(FortnoxQueueMessage message)
        {
            switch (message.Action)
            {
            case FortnoxQueueAction.UpsertFortnoxDelivery:
            {
                var payload       = JsonConvert.DeserializeObject <FortnoxUpsertWebcrmDeliveryPayload>(message.Payload);
                var configuration = FortnoxConfigService.LoadFortnoxConfiguration(payload.WebcrmSystemId);
                var dataCopier    = await FortnoxDataCopier.Create(Logger, WebcrmClientFactory, configuration);

                await dataCopier.CopyDeliveryToFortnox(payload.FortnoxCustomerNumber, payload.FortnoxCustomerNumber, configuration.OrganisationIdFieldName);
            }
            break;

            case FortnoxQueueAction.UpsertWebcrmOrganisation:
            {
                var payload = JsonConvert.DeserializeObject <FortnoxUpsertWebcrmOrganisationPayload>(message.Payload);

                var configuration = FortnoxConfigService.LoadFortnoxConfiguration(payload.WebcrmSystemId);
                var dataCopier    = await FortnoxDataCopier.Create(Logger, WebcrmClientFactory, configuration);

                await dataCopier.CopyOrganisationFromFortnox(payload.FortnoxCustomerNumber, configuration.OrganisationIdFieldName);
            }
            break;

            case FortnoxQueueAction.UpsertFortnoxOrganisation:
            {
                var payload = JsonConvert.DeserializeObject <WebcrmUpsertFortnoxOrganisationPayload>(message.Payload);

                // TODO 1358: Only update Fortnox if a custom checkbox list contains a checked item that says something like "Fortnox Customer". Otherwise we should not sync the organisation.

                var configuration = FortnoxConfigService.LoadFortnoxConfiguration(payload.WebcrmSystemId);
                var dataCopier    = await FortnoxDataCopier.Create(Logger, WebcrmClientFactory, configuration);

                await dataCopier.CopyOrganisationToFortnox(payload.Organisation, configuration.OrganisationIdFieldName);
            }
            break;

            case FortnoxQueueAction.Unknown:
            default:
                throw new ApplicationException($"The action '{message.Action}' is not supported.");
            }
        }
Beispiel #2
0
        public async Task EnqueueUpsertedInvoices()
        {
            var configurations = FortnoxConfigService.LoadEnabledFortnoxConfigurations();

            foreach (var configuration in configurations)
            {
                // Store time we are using to detect changes
                var dateTimeBeforeSync = DateTime.UtcNow;

                var dataCopier = await FortnoxDataCopier.Create(
                    Logger,
                    WebcrmClientFactory,
                    configuration);

                await dataCopier.EnqueueRecentlyUpsertedInvoices(
                    StorageAccountConnectionString,
                    configuration.WebcrmSystemId,
                    configuration.LastSuccessfulCopyFromErpHeartbeat);

                configuration.LastSuccessfulCopyFromErpHeartbeat = dateTimeBeforeSync;
                await FortnoxConfigService.SaveFortnoxConfiguration(configuration);
            }
        }