From 26c50e21568c7933f0555efdfe9ffbcdf90c12fa Mon Sep 17 00:00:00 2001 From: "dennes.schaeffler" Date: Tue, 23 Sep 2025 08:48:13 +0200 Subject: [PATCH] Dateien nach "/" hochladen --- index.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 index.ts diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..984288c --- /dev/null +++ b/index.ts @@ -0,0 +1,60 @@ +import { Inject, Injectable, OnApplicationBootstrap } from '@nestjs/common'; +import { DocumentLineItem, DocumentLineItemStatusChangedEvent, DocumentStatusType, EventBus, Logger, PhoenixPlugin, PluginCommonModule } from '@phoenix/core'; + +// Example service for the plugin +@Injectable() +export class AmplidService { + + getPluginInfo() { + return { + name: 'AmplidPlugin', + version: '1.0.0', + description: '' + }; + } +} + +// The main plugin class using the PhoenixPlugin decorator +@PhoenixPlugin({ + imports: [PluginCommonModule], + controllers: [], + providers: [AmplidService], + exports: [AmplidService] +}) +export class AmplidPlugin implements OnApplicationBootstrap { + + private customFieldForBestellteMenge = 'bestellteMenge'; //bestellteMenge + + @Inject(EventBus) + private readonly eventBus!: EventBus; + + // Required static init method for Phoenix plugins + static init(): typeof AmplidPlugin { + console.log('AmplidPlugin initialized'); + return AmplidPlugin; + } + + async onApplicationBootstrap() { + this.setupEvents(); + } + + setupEvents() { + this.eventBus.ofType(DocumentLineItemStatusChangedEvent).subscribe(async (event) => { + if (event.newStatus == DocumentStatusType.COMPLETED) { + + let bestellteMenge = +event.dli.customFields?.[this.customFieldForBestellteMenge]; + + if (bestellteMenge && bestellteMenge > 0) { + if (bestellteMenge == event.dli.quantity && event.dli.openQuantity == 0) { + //we are good, we can keep it being completed + } else { + //we need to change the status to inwork + Logger.info(`Changing status to inwork for DocumentLineItem ${event.dli.id} because bestellteMenge ${bestellteMenge} is not equal to quantity ${event.dli.quantity} and openQuantity ${event.dli.openQuantity}`); + event.dli.status = DocumentStatusType.INWORK; + await DocumentLineItem.update(event.dli.id, { status: DocumentStatusType.INWORK }); + } + } + } + }); + } +} \ No newline at end of file