1 import {Component, OnInit, Input} from '@angular/core';
2 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
3 import {IdlService, IdlObject} from '@eg/core/idl.service';
4 import {PcrudService} from '@eg/core/pcrud.service';
5 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
6 import {PoService} from './po.service';
9 templateUrl: 'charges.component.html',
10 selector: 'eg-acq-po-charges'
12 export class PoChargesComponent implements OnInit {
18 private idl: IdlService,
19 private pcrud: PcrudService,
20 public poService: PoService
24 this.poService.poRetrieved.subscribe(() => {
25 if (this.po().po_items().length > 0) {
32 return this.poService.currentPo;
37 const chg = this.idl.create('acqpoi');
39 chg.purchase_order(this.po().id());
40 chg.id(this.autoId--);
41 this.po().po_items().push(chg);
44 saveCharge(charge: IdlObject) {
45 if (!charge.inv_item_type()) { return; }
48 this.pcrud.create(charge).toPromise()
53 .then(_ => this.poService.refreshOrderSummary());
56 removeCharge(charge: IdlObject) {
57 this.po().po_items( // remove local copy
58 this.po().po_items().filter(item => item.id() !== charge.id())
61 if (!charge.isnew()) {
62 this.pcrud.remove(charge).toPromise()
63 .then(_ => this.poService.refreshOrderSummary());