1 import {Component, OnInit, Output, EventEmitter} from '@angular/core';
2 import {AuthService} from '@eg/core/auth.service';
3 import {AcqProviderSearchTerm, AcqProviderSearch} from './acq-provider-search.service';
4 import {StoreService} from '@eg/core/store.service';
5 import {OrgFamily} from '@eg/share/org-family-select/org-family-select.component';
8 selector: 'eg-acq-provider-search-form',
9 styleUrls: ['acq-provider-search-form.component.css'],
10 templateUrl: './acq-provider-search-form.component.html'
13 export class AcqProviderSearchFormComponent implements OnInit {
15 @Output() searchSubmitted = new EventEmitter<AcqProviderSearch>();
21 providerOwners: OrgFamily;
25 providerCurrencyType = '';
27 providerEDIDefault = null;
29 providerIsActive = 'active';
32 private localStore: StoreService,
33 private auth: AuthService,
38 this.providerOwners = {primaryOrgId: this.auth.user().ws_ou(), includeDescendants: true};
39 this.collapsed = this.localStore.getLocalItem('eg.acq.provider.search.collapse_form') || false;
43 this.providerName = '';
44 this.providerCode = '';
45 this.providerOwners = {primaryOrgId: this.auth.user().ws_ou(), includeDescendants: true};
46 this.contactName = '';
47 this.providerEmail = '';
48 this.providerPhone = '';
49 this.providerCurrencyType = '';
50 this.providerSAN = '';
51 this.providerEDIDefault = null;
52 this.providerURL = '';
53 this.providerIsActive = 'active';
58 const searchTerms: AcqProviderSearchTerm[] = [];
59 if (this.providerName) {
60 searchTerms.push({ classes: ['acqpro'], fields: ['name'], op: 'ilike', value: this.providerName });
62 if (this.providerCode) {
63 searchTerms.push({ classes: ['acqpro'], fields: ['code'], op: 'ilike', value: this.providerCode });
65 if (this.providerOwners) {
66 searchTerms.push({ classes: ['acqpro'], fields: ['owner'], op: 'in', value: this.providerOwners.orgIds });
68 if (this.contactName) {
69 searchTerms.push({ classes: ['acqpc'], fields: ['name'], op: 'ilike', value: this.contactName });
71 if (this.providerEmail) {
72 searchTerms.push({ classes: ['acqpro', 'acqpc'], fields: ['email', 'email'], op: 'ilike', value: this.providerEmail });
74 if (this.providerPhone) {
75 // this requires the flesh hash to contain: { ... join: { acqpc: { type: 'left' } } ... }
77 classes: ['acqpc', 'acqpro', 'acqpro'],
78 fields: ['phone', 'phone', 'fax_phone'],
80 value: this.providerPhone,
83 if (this.providerCurrencyType) {
84 searchTerms.push({ classes: ['acqpro'], fields: ['currency_type'], op: '=', value: this.providerCurrencyType });
86 if (this.providerSAN) {
87 searchTerms.push({ classes: ['acqpro'], fields: ['san'], op: 'ilike', value: this.providerSAN });
89 if (this.providerEDIDefault) {
90 searchTerms.push({ classes: ['acqpro'], fields: ['edi_default'], op: '=', value: this.providerEDIDefault });
92 if (this.providerURL) {
93 searchTerms.push({ classes: ['acqpro'], fields: ['url'], op: 'ilike', value: this.providerURL });
95 switch (this.providerIsActive) {
97 searchTerms.push({ classes: ['acqpro'], fields: ['active'], op: '=', value: 't' });
101 searchTerms.push({ classes: ['acqpro'], fields: ['active'], op: '=', value: 'f' });
106 // tossing setTimeout here to ensure that the
107 // grid data source is fully initialized
109 this.searchSubmitted.emit({
116 this.collapsed = ! this.collapsed;
117 this.localStore.setLocalItem('eg.acq.provider.search.collapse_form', this.collapsed);