<eg-string #successMsg text="Successfully Added Billing" i18n-text></eg-string>
<eg-string #errorMsg text="Failed To Add Billing" i18n-text></eg-string>
+<!-- putting this here guarantees it's available to ViewChild before open -->
+<ng-template #bTypes>
+ <eg-combobox #bTypeCbox [entries]="billingTypes"
+ [required]="true" (onChange)="btChanged($event)"></eg-combobox>
+</ng-template>
+
<ng-template #dialogContent>
<div class="modal-header bg-info">
<h4 class="modal-title" i18n>
<div class="row mt-2">
<div class="col-lg-4" i18n>Billing Type</div>
<div class="col-lg-8">
- <eg-combobox #bTypeCbox [entries]="billingTypes"
- [required]="true" (onChange)="btChanged($event)"></eg-combobox>
+ <ng-container *ngTemplateOutlet="bTypes"></ng-container>
</div>
</div>
<div class="row mt-2">
<div class="col-lg-4" i18n>Amount</div>
<div class="col-lg-8" i18n>
- <input type="number" class="form-control"
+ <input type="number" class="form-control" id="amount-input"
required [(ngModel)]="amount" [min]="0"/>
</div>
</div>
import {Component, OnInit, Input, ViewChild} from '@angular/core';
import {Observable} from 'rxjs';
import {switchMap} from 'rxjs/operators';
-import {IdlObject} from '@eg/core/idl.service';
+import {IdlObject, IdlService} from '@eg/core/idl.service';
import {NetService} from '@eg/core/net.service';
import {EventService} from '@eg/core/event.service';
import {ToastService} from '@eg/share/toast/toast.service';
/* Add a billing to a transaction */
+const DEFAULT_BILLING_TYPE = 101; // Stock "Misc"
+
@Component({
selector: 'eg-add-billing-dialog',
templateUrl: 'billing-dialog.component.html'
private modal: NgbModal, // required for passing to parent
private toast: ToastService,
private net: NetService,
+ private idl: IdlService,
private evt: EventService,
private pcrud: PcrudService,
private circ: CircService,
this.onOpen$.subscribe(_ => {
this.amount = null;
this.note = '';
- //this.bTypeCbox.selectedId = 101; // Stock "Misc"
+ this.bTypeCbox.selectedId = DEFAULT_BILLING_TYPE;
const node = document.getElementById('amount-input');
if (node) { node.focus(); }
});
}
submit() {
- this.close();
+ const bill = this.idl.create('mb');
+ bill.xact(this.xactId);
+ bill.amount(this.amount);
+ bill.btype(this.billingType.id);
+ bill.billing_type(this.billingType.label);
+ bill.note(this.note);
+
+ this.net.request(
+ 'open-ils.circ',
+ 'open-ils.circ.money.billing.create',
+ this.auth.token(), bill
+ ).subscribe(billId => {
+
+ const evt = this.evt.parse(billId);
+ if (evt) {
+ console.error(evt);
+ alert(evt);
+ this.close(null);
+ } else {
+ this.close(billId);
+ }
+ })
}
}