dialogTitle="Confirm Alert" [dialogBodyTemplate]="confirmAlertsMsg">
</eg-confirm-dialog>
<ng-template #confirmAlertsMsg>
+ <div *ngIf="numAlerts > 0" class="alert alert-warning" i18n>
+ Alert {{alertIndex}} out of {{numAlerts}}
+ </div>
<div i18n>An alert has been placed on line item {{liId}} ({{title}})</div>
<div class="mt-2">{{alertText.code()}}</div>
<div>{{alertText.description()}}</div>
<div>{{alertComment}}</div>
- <div class="mt-2" i18n>Choose "Confirm" to acknowledge this alert and continue with receiving. Otherwise, choose "Cancel".</div>
+ <div class="mt-2" i18n>Choose "Confirm" to acknowledge this alert and continue with receiving.
+ Otherwise, choose "Cancel" to not receive the line item(s). If there is more than one alert,
+ all of them must be confirmed in order to complete the receiving.
+ </div>
</ng-template>
toCache?: boolean;
}
+interface LineitemAlertData {
+ liId: number;
+ title: string;
+ alertText: IdlObject;
+ alertComment: string;
+}
+
@Injectable()
export class LineitemService {
);
}
- checkLiAlerts(li: IdlObject, dialog: LineitemAlertDialogComponent): Promise<boolean> {
+ checkLiAlerts(lis: IdlObject[], dialog: LineitemAlertDialogComponent): Promise<boolean> {
let promise = Promise.resolve(true);
- const notes = li.lineitem_notes().filter(note =>
- note.alert_text() && !this.alertAcks[note.id()]);
+ const alerts: LineitemAlertData[] = [];
+ lis.forEach(li => {
+ li.lineitem_notes().filter(
+ note => note.alert_text() && !this.alertAcks[note.id()]
+ ).forEach(alert =>
+ alerts.push({
+ liId: li.id(),
+ title: this.getFirstAttributeValue(li, 'title'),
+ alertText: alert.alert_text(),
+ alertComment: alert.value()
+ })
+ );
+ });
- if (notes.length === 0) { return promise; }
+ if (alerts.length === 0) { return promise; }
- dialog.liId = li.id();
- dialog.title = this.getFirstAttributeValue(li, 'title');
+ dialog.numAlerts = alerts.length;
- notes.forEach(n => {
+ alerts.forEach((alert, i) => {
promise = promise.then(_ => {
- dialog.alertText = n.alert_text();
- dialog.alertComment = n.value();
+ dialog.liId = alert.liId;
+ dialog.title = alert.title;
+ dialog.alertText = alert.alertText;
+ dialog.alertComment = alert.alertComment;
+ dialog.alertIndex = i + 1;
return dialog.open().toPromise().then(ok => {
if (!ok) { return Promise.reject(); }
- this.alertAcks[n.id()] = true;
+ this.alertAcks[alert.alertText.id()] = true;
return true;
});
});