LP1904036 add billings
authorBill Erickson <berickxx@gmail.com>
Mon, 1 Mar 2021 22:28:18 +0000 (17:28 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 28 Oct 2022 00:13:25 +0000 (20:13 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/share/circ/billing-dialog.component.html
Open-ILS/src/eg2/src/app/staff/share/circ/billing-dialog.component.ts

index c957ed6..04dd4c0 100644 (file)
@@ -1,6 +1,12 @@
 <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>
index 6b20e19..60e6d7f 100644 (file)
@@ -1,7 +1,7 @@
 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';
@@ -16,6 +16,8 @@ import {CircService} from './circ.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'
@@ -41,6 +43,7 @@ export class AddBillingDialogComponent
         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,
@@ -61,7 +64,7 @@ export class AddBillingDialogComponent
         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(); }
         });
@@ -102,7 +105,28 @@ export class AddBillingDialogComponent
     }
 
     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);
+            }
+        })
     }
 }