amplid stuff and fixes
This commit is contained in:
40
index.ts
40
index.ts
@@ -23,11 +23,13 @@ export class AmplidService {
|
||||
})
|
||||
export class AmplidPlugin implements OnApplicationBootstrap {
|
||||
|
||||
private customFieldForBestellteMenge = 'bestellteMenge'; //bestellteMenge
|
||||
private customFieldForBestellteMenge = 'bestelltemenge'; //bestellteMenge
|
||||
|
||||
@Inject(EventBus)
|
||||
private readonly eventBus!: EventBus;
|
||||
|
||||
private readonly logger = Logger.forContext(this);
|
||||
|
||||
// Required static init method for Phoenix plugins
|
||||
static init(): typeof AmplidPlugin {
|
||||
console.log('AmplidPlugin initialized');
|
||||
@@ -39,22 +41,34 @@ export class AmplidPlugin implements OnApplicationBootstrap {
|
||||
}
|
||||
|
||||
setupEvents() {
|
||||
this.eventBus.ofType(DocumentLineItemStatusChangedEvent).subscribe(async (event) => {
|
||||
if (event.newStatus == DocumentStatusType.COMPLETED) {
|
||||
this.eventBus.registerBlockingEventHandler(DocumentLineItemStatusChangedEvent, {
|
||||
id: 'amplid-plugin-document-line-item-status-changed',
|
||||
handler: async (event) => {
|
||||
if (event.newStatus == DocumentStatusType.COMPLETED) {
|
||||
|
||||
let bestellteMenge = +event.dli.customFields?.[this.customFieldForBestellteMenge];
|
||||
if (!event.dli) {
|
||||
this.logger.error(`DocumentLineItem not found in event`, "AMPLID PLUGIN");
|
||||
return;
|
||||
}
|
||||
|
||||
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 });
|
||||
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
|
||||
this.logger.info(`Keeping status as completed for DocumentLineItem ${event.dli.id} because bestellteMenge ${bestellteMenge} is equal to quantity ${event.dli.quantity} and openQuantity ${event.dli.openQuantity}`);
|
||||
} else {
|
||||
//we need to change the status to inwork
|
||||
this.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 });
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.logger.info(`Keeping status as completed for DocumentLineItem ${event.dli.id} because bestelltemenge ${bestellteMenge} is not set`);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user