diff --git a/AstuteClient2/src/app/app-routing.module.ts b/AstuteClient2/src/app/app-routing.module.ts index f545174..6fdbbe7 100644 --- a/AstuteClient2/src/app/app-routing.module.ts +++ b/AstuteClient2/src/app/app-routing.module.ts @@ -7,8 +7,8 @@ import {InvoiceComponent} from './invoice/invoice.component'; import {HomepageComponent} from './homepage/homepage.component'; import {InvoiceGenComponent} from './invoice-gen/invoice-gen.component'; import {InvoicePaymentComponent} from './invoice-payment/invoice-payment.component'; -import {ServiceTypeComponent} from './service-type/service-type.component'; import {LoginComponent} from './login/login.component'; +import {SettingsComponent} from './settings/settings.component'; const routes: Routes = [ { path: '', redirectTo: 'login', pathMatch: 'full'}, @@ -19,8 +19,9 @@ const routes: Routes = [ { path: 'invoice', component: InvoiceComponent }, { path: 'invoice-gen', component: InvoiceGenComponent }, { path: 'invoice-payment', component: InvoicePaymentComponent }, - { path: 'service-type', component: ServiceTypeComponent}, - { path: 'login', component: LoginComponent } + // { path: 'service-type', component: ServiceTypeComponent}, + { path: 'login', component: LoginComponent }, + { path: 'settings', component: SettingsComponent } ]; @NgModule({ diff --git a/AstuteClient2/src/app/app.module.ts b/AstuteClient2/src/app/app.module.ts index bbd60a2..71252d0 100644 --- a/AstuteClient2/src/app/app.module.ts +++ b/AstuteClient2/src/app/app.module.ts @@ -19,9 +19,10 @@ import { TextMaskModule } from 'angular2-text-mask'; import { LoginComponent } from './login/login.component'; import { InvoicePaymentComponent } from './invoice-payment/invoice-payment.component'; import { CommonModule } from '@angular/common'; -import { FormsModule } from '@angular/forms'; +import { FormsModule } from '@angular/forms'; import { ReactiveFormsModule } from '@angular/forms'; -import { ServiceTypeComponent } from './service-type/service-type.component'; +import { SettingsComponent } from './settings/settings.component'; +// import { ServiceTypeComponent } from './service-type/service-type.component'; @NgModule({ declarations: [ @@ -36,7 +37,8 @@ import { ServiceTypeComponent } from './service-type/service-type.component'; InvoiceGenComponent, LoginComponent, InvoicePaymentComponent, - ServiceTypeComponent + SettingsComponent// , + // ServiceTypeComponent ], imports: [ BrowserModule, diff --git a/AstuteClient2/src/app/customer/customer.component.html b/AstuteClient2/src/app/customer/customer.component.html index d500c70..bc32c09 100644 --- a/AstuteClient2/src/app/customer/customer.component.html +++ b/AstuteClient2/src/app/customer/customer.component.html @@ -5,27 +5,34 @@
-
+
-
- +
+
-
- +
+ +
+
+
@@ -244,16 +251,13 @@ Phone* - + - - - Ext* - + @@ -292,3 +296,58 @@
+ + + +
+
+
+
+ +
+
+
+ + + +
+
+ + +
+
\ No newline at end of file diff --git a/AstuteClient2/src/app/customer/customer.component.ts b/AstuteClient2/src/app/customer/customer.component.ts index d28ef46..9300dac 100644 --- a/AstuteClient2/src/app/customer/customer.component.ts +++ b/AstuteClient2/src/app/customer/customer.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit, ViewChild} from '@angular/core'; +import {Component, OnInit} from '@angular/core'; import {AstuteClientService} from '../services/astute-client-service'; @Component({ @@ -7,23 +7,27 @@ import {AstuteClientService} from '../services/astute-client-service'; styleUrls: ['./customer.component.css'] }) export class CustomerComponent implements OnInit { - @ViewChild('agGrid') agGrid; + // @ViewChild('agGrid') agGrid; + gridApi; + gridColumnApi; + contactGridApi; + contactColumnApi; selected = null; customers; columnDefs = [ - {headerName: 'Customer ID', field: 'customerId', checkboxSelection: true}, - {headerName: 'Customer Name', field: 'customerName'}, - {headerName: 'Bill To Department', field: 'billToDept'}, - {headerName: 'Address 1', field: 'add1'}, - {headerName: 'Address 2', field: 'add2'}, - {headerName: 'City', field: 'city'}, - {headerName: 'Email', field: 'email'}, - {headerName: 'Fax', field: 'fax'}, - {headerName: 'Phone', field: 'phone'}, - {headerName: 'phExt', field: 'phExt'}, - {headerName: 'State', field: 'state'}, - {headerName: 'ZIP', field: 'zip'}, - {headerName: 'ZIP-4', field: 'ziplast4'} + {headerName: 'ID', field: 'customerId'}, + {headerName: 'Name', field: 'customerName', editable: true}, + {headerName: 'Bill To', field: 'billToDept', editable: true}, + {headerName: 'Address 1', field: 'add1', editable: true}, + {headerName: 'Address 2', field: 'add2', editable: true}, + {headerName: 'City', field: 'city', editable: true}, + {headerName: 'Email', field: 'email', editable: true}, + {headerName: 'Fax', field: 'fax', editable: true}, + {headerName: 'Phone', field: 'phone', editable: true}, + {headerName: 'Ext.', field: 'phExt', editable: true}, + {headerName: 'State', field: 'state', editable: true}, + {headerName: 'ZIP', field: 'zip', editable: true}, + {headerName: 'ZIP-4', field: 'ziplast4', editable: true} ]; rowData: any; states = [ @@ -81,6 +85,30 @@ export class CustomerComponent implements OnInit { ]; usPhoneMask = ['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]; + contactsData: any; + contactsColDef = [ + {headerName: 'ID', field: 'contactId', checkboxSelection: true}, + {headerName: 'Name', field: 'name', editable: true}, + {headerName: 'Title', field: 'title', editable: true}, + {headerName: 'Email', field: 'email', editable: true}, + {headerName: 'Work', field: 'workPhone', editable: true}, + {headerName: 'Phone', field: 'mobile', editable: true}, + {headerName: 'Ext.', field: 'phExt', editable: true}, + {headerName: 'Fax', field: 'fax', editable: true}, + {headerName: 'Address', field: 'address', editable: true} + ]; + + // address: "123 Test Drive" + // contactId: 1 + // customerId: "MDOT" + // email: "Test@Test.com" + // fax: 234123344 + // mobile: 1232343455 + // name: "John Shaw" + // phExt: 1233 + // title: "Manager" + // workPhone: 1231231233 + constructor(protected astuteClientService: AstuteClientService) { } @@ -88,104 +116,204 @@ export class CustomerComponent implements OnInit { this.refreshData(); } - getSelectedRows() { - const selectedNodes = this.agGrid.api.getSelectedNodes(); - if (selectedNodes.length) { - this.selected = selectedNodes.map(node => node.data)[0]; - } else { - this.selected = null; - } + // callback for grid selection + setSelectedRow(event) { + this.selected = event.data; } - // inName.value, inBillToDept.value, inAdd1.value, inAdd2.value, inCity.value, inState.value, inZIP.value, inZIP4.value, inEmail.value, inPhone.value, inFax.value + // wrappers for customer service methods addCustomer(customerId, name, billTo, add1, add2, city, state, zip, zip4, email, phone, phExt, fax, ref) { - if (fax.length > 0 && fax.length < 14) { + if (fax.length > 0 && fax.length < 14) { alert('Invalid fax.'); } else if (phone.length > 0 && phone.length < 14) { alert('Invalid phone.'); - } else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) == false) { - alert("You have entered an invalid email address!") + } else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) === false) { + alert('You have entered an invalid email address!'); } else { - let customerData = { - "customerId": customerId, - "customerName": name, - "billToDept": billTo, - "add1": add1, - "add2": add2, - "city": city, - "state": state, - "zip": zip, - "ziplast4": zip4, - "email": email, - "phone": phone, - "phExt": phExt, - "fax": fax - }; - this.astuteClientService.createCustomer(customerData).then((data) => { - if (data) { - this.refreshData(); - ref.close(); - } else { - alert("Customer Creation Failed, Check Input Fields") - } - }, (reason) => { - alert("add customer failed for " + reason); - }); - }} - - - editCustomer(id, name, billTo, add1, add2, city, state, zip, zip4, email, phone, phExt, fax, ref) { - if (fax.length > 0 && fax.length < 14) { - alert('Invalid fax.'); - } else if (phone.length > 0 && phone.length < 14) { - alert('Invalid phone.'); - } else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) == false) { - alert("You have entered an invalid email address!") - } else { - const customerData = { - "customerId": id, - "customerName": name, - "billToDept": billTo, - "add1": add1, - "add2": add2, - "city": city, - "state": state, - "zip": zip, - "ziplast4": zip4, - "email": email, - "phone": phone, - "phExt": phExt, - "fax": fax - }; - - this.astuteClientService.updateCustomer(id, customerData).then((data) => { - if (data) { - this.refreshData(); - ref.close(); - } else { - alert("Customer Updating Failed, Check Input Fields") - } - }, (reason) => { - alert("update customer failed for " + reason); - }); - }} - - deleteCustomer (customerId) { - if (confirm('Are you sure you want to delete customer, ' + customerId)) { - this.astuteClientService.deleteCustomer(customerId).then((data) => { + const customerData = { + 'customerId': customerId, + 'customerName': name, + 'billToDept': billTo, + 'add1': add1, + 'add2': add2, + 'city': city, + 'state': state, + 'zip': zip, + 'ziplast4': zip4, + 'email': email, + 'phone': phone, + 'phExt': phExt, + 'fax': fax + }; + this.astuteClientService.createCustomer(customerData).then((data) => { if (data) { - console.log('Customer, ' + customerId + ' successfully deleted'); this.refreshData(); + ref.close(); } else { - alert ('Error in deleting; Customer, ' + customerId + ' has not been deleted'); + alert('Customer Creation Failed, Check Input Fields'); } + }, (reason) => { + alert('Add customer failed: ' + reason); }); } } + editCustomer(id, name, billTo, add1, add2, city, state, zip, zip4, email, phone, phExt, fax, ref) { + if (fax.length > 0 && fax.length < 14) { + alert('Invalid fax.'); + } else if (phone.length > 0 && phone.length < 14) { + alert('Invalid phone.'); + } else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) === false) { + alert('You have entered an invalid email address!'); + } else { + const customerData = { + 'customerId': id, + 'customerName': name, + 'billToDept': billTo, + 'add1': add1, + 'add2': add2, + 'city': city, + 'state': state, + 'zip': zip, + 'ziplast4': zip4, + 'email': email, + 'phone': phone, + 'phExt': phExt, + 'fax': fax + }; + this.astuteClientService.updateCustomer(id, customerData).then((data) => { + if (data) { + this.refreshData(); + ref.close(); + } else { + alert('Customer Updating Failed, Check Input Fields'); + } + }, (reason) => { + alert('Update customer failed: ' + reason); + }); + } + } + + deleteCustomer(customerId) { + if (customerId) { + if (confirm('Are you sure you want to delete customer, ' + customerId)) { + this.astuteClientService.deleteCustomer(customerId).then((data) => { + if (data) { + console.log('Customer, ' + customerId + ' successfully deleted'); + this.refreshData(); + } else { + alert('Error in deleting; Customer, ' + customerId + ' has not been deleted'); + } + }); + } + } else { + alert('Choose a customer first!'); + } + } + + // wrappers for contact service methods (only inline editing) + createEmptyContact() { + const newContactData = { + address: '', + customerId: this.selected.customerId, + email: 'example@email.com', + fax: null, + mobile: null, + name: '', + phExt: null, + title: '', + workPhone: null + }; + console.log(newContactData); + this.astuteClientService.createCustomerContact(newContactData).then ((data) => { + if (!data) { + alert('Contact Creation Failed, Check Input Fields'); + } else { + this.refreshContactData(this.selected.customerId); + } + }, (reason) => { + alert('Create customer failed: ' + reason); + }); + } + + deleteContact() { + const selectedNodes = this.contactGridApi.getSelectedNodes(); + if (selectedNodes.length > 0) { + if (confirm('Are you sure?')) { + const selec = selectedNodes.map(node => node.data)[0]; + this.astuteClientService.deleteCustomerContact(selec.customerId, selec.contactId).then((data) => { + if (data) { + this.refreshContactData(selec.customerId); + } else { + alert('Contact Deletion Failed, Check Input Fields'); + } + }, (reason) => { + alert('Delete customer failed: ' + reason); + }); + } + } else { + alert('Choose a contact first!'); + } + } + + // for inline updating + updateRow(event) { + const eventData = event.data; + console.log(eventData); + if (eventData.fax.length > 0 && eventData.fax.length < 14) { + alert('Invalid fax.'); + } else if (eventData.phone.length > 0 && eventData.phone.length < 14) { + alert('Invalid phone.'); + } else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(eventData.email) === false) { + alert('You have entered an invalid email address!'); + } else { + this.astuteClientService.updateCustomer(eventData.customerId, eventData).then((data) => { + if (data) { + this.refreshData(); + } else { + alert('Customer Updating Failed, Check Input Fields'); + } + }, (reason) => { + alert('Update customer failed: ' + reason); + }); + } + this.refreshData(); + } + + updateContactRow(event) { + console.log(event); + + const eventData = event.data; + // if (eventData.fax % 10 < 14) { + // alert('Invalid fax.'); + // } else if (eventData.mobile % 10 < 14) { + // alert('Invalid phone.'); + // } else if (eventData.workPhone % 10 < 14) { + // alert('Invalid work phone.'); + // } else + if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(eventData.email) === false) { + alert('You have entered an invalid email address!'); + } else { + this.astuteClientService.updateCustomerContact(eventData.customerId, eventData).then((data) => { + if (!data) { + alert('Customer Updating Failed, Check Input Fields'); + } else { + this.contactsData = this.astuteClientService.getCustomerContacts(eventData.customerId); + } + }, (reason) => { + alert('Update customer failed: ' + reason); + }); + } + this.contactsData = this.astuteClientService.getCustomerContacts(eventData.customerId); + } + + // opening and closing modal-form components open(ref) { - this.getSelectedRows(); + // this.getSelectedRows(); + if (this.selected) { + this.contactsData = this.astuteClientService.getCustomerContacts(this.selected.customerId); + } ref.open(); } @@ -193,10 +321,32 @@ export class CustomerComponent implements OnInit { ref.close(); } + // refreshes corresponding data refreshData() { this.rowData = this.astuteClientService.getCustomers(); + this.selected = null; this.astuteClientService.getCustomers().then((data) => { this.customers = data; }); } -} \ No newline at end of file + + refreshContactData(customerId) { + this.contactsData = this.astuteClientService.getCustomerContacts(customerId); + } + + + // on each grid ready: sets api's and enable auto-resizing + onGridReady(evt) { + this.gridApi = evt.api; + this.gridColumnApi = evt.columnApi; + } + + onContactGridReady(evt) { + this.contactGridApi = evt.api; + this.contactColumnApi = evt.columnApi; + } + + resizeColumns(evt) { + evt.columnApi.autoSizeAllColumns(); + } +} diff --git a/AstuteClient2/src/app/homepage/homepage.component.html b/AstuteClient2/src/app/homepage/homepage.component.html index c726dcb..6c85773 100644 --- a/AstuteClient2/src/app/homepage/homepage.component.html +++ b/AstuteClient2/src/app/homepage/homepage.component.html @@ -21,19 +21,23 @@
-
Go here to add or edit customers
+
Add or edit customers!
-
Go here to add sales orders or make change orders
+
Add sales orders or make change orders!
- -
Go here to interact with invoices
+ +
Interact with invoices!
- -
Go here to enter payments received
+ +
Enter payments received!
+ +
+ +
Change your settings!
diff --git a/AstuteClient2/src/app/invoice/invoice.component.html b/AstuteClient2/src/app/invoice/invoice.component.html index 57f8a46..a2266c5 100644 --- a/AstuteClient2/src/app/invoice/invoice.component.html +++ b/AstuteClient2/src/app/invoice/invoice.component.html @@ -70,11 +70,11 @@ - - - - - + + + + + @@ -84,9 +84,9 @@ - - - + + + @@ -131,36 +131,36 @@ - - + + - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - + + + + + + + @@ -187,7 +187,7 @@ - + @@ -217,72 +217,72 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -343,14 +343,14 @@ - - - - - - - - + + + + + + + + @@ -380,14 +380,14 @@ @@ -395,268 +395,268 @@ - - - - + + + diff --git a/AstuteClient2/src/app/nav-bar/nav-bar.component.ts b/AstuteClient2/src/app/nav-bar/nav-bar.component.ts index 209d0c7..7b4c9f8 100644 --- a/AstuteClient2/src/app/nav-bar/nav-bar.component.ts +++ b/AstuteClient2/src/app/nav-bar/nav-bar.component.ts @@ -1,4 +1,5 @@ import {Component, Input, OnInit} from '@angular/core'; +import {AstuteClientService} from '../services/astute-client-service'; @Component({ selector: 'app-nav-bar', @@ -6,17 +7,29 @@ import {Component, Input, OnInit} from '@angular/core'; styleUrls: ['./nav-bar.component.css'] }) export class NavBarComponent implements OnInit { - @Input() customerActive: boolean; - @Input() salesOrderActive: boolean; - @Input() invoiceActive: boolean; - @Input() invoicePaymentActive: boolean; - @Input() serviceTypeActive: boolean; - @Input() logoffActive: boolean; + @Input() customerActive: boolean; + @Input() salesOrderActive: boolean; + @Input() invoiceActive: boolean; + @Input() invoicePaymentActive: boolean; + // @Input() serviceTypeActive: boolean; + // @Input() logoffActive: boolean; + @Input() settingsActive: boolean; - constructor() { } + constructor(private astuteClientService: AstuteClientService) { + } - ngOnInit() { - } + ngOnInit() { + } + // logout() { + // this.astuteClientService.logout().then((data) => { + // if (data) { + // alert('Logout successful'); + // } else { + // alert('Logout unsuccessful'); + // } + // }); + // } } + diff --git a/AstuteClient2/src/app/sales-order/sales-order.component.html b/AstuteClient2/src/app/sales-order/sales-order.component.html index 88627da..92de56c 100644 --- a/AstuteClient2/src/app/sales-order/sales-order.component.html +++ b/AstuteClient2/src/app/sales-order/sales-order.component.html @@ -4,28 +4,36 @@
-
+
-
+
-
- +
+
-
+
+ +
+
@@ -38,127 +46,127 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Astute Proj. No.
Customer - -
SO Title
SO NumberSO Date
Contract NumberContract Amount
Notes
Astute Proj. No.
Customer + +
SO Title
SO NumberSO Date
Contract NumberContract Amount
Notes
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -276,89 +284,90 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/AstuteClient2/src/app/sales-order/sales-order.component.ts b/AstuteClient2/src/app/sales-order/sales-order.component.ts index 9e225de..c97da4e 100644 --- a/AstuteClient2/src/app/sales-order/sales-order.component.ts +++ b/AstuteClient2/src/app/sales-order/sales-order.component.ts @@ -1,6 +1,6 @@ import {Component, OnInit, ViewChild} from '@angular/core'; import {AstuteClientService} from '../services/astute-client-service'; -import {formatCurrency} from "@angular/common"; +import {formatCurrency} from '@angular/common'; @Component({ selector: 'app-sales-order', @@ -8,225 +8,335 @@ import {formatCurrency} from "@angular/common"; styleUrls: ['./sales-order.component.css'] }) export class SalesOrderComponent implements OnInit { - @ViewChild('agGrid') agGrid; - selected = null; - selectedPODetail = []; - newPODetail = []; - newContractAmount = 0; - editContractAmount = 0; + // both of the grid api's + gridApi; + gridColumnApi; + detailGridApi; + detailColumnApi; + + // one time fetch meta-data customers; - pos; serviceTypes; + serviceNames = []; + rateTypes = []; + rateNames = []; + + // data for SO grid + rowData: any; columnDefs = [ - {headerName: 'Project Number', field: 'astuteProjectNumber'}, + {headerName: 'Project Number', field: 'astuteProjectNumber', editable: true}, {headerName: 'SO Number', field: 'ponum'}, // {headerName: 'Customer ID', field: 'customerId'}, {headerName: 'Customer Name', field: 'customerName'}, - {headerName: 'Contract Number', field: 'contractNum'}, - {headerName: 'SO Title', field: 'title'}, - {headerName: 'Contract Amount', field: 'contractAmt'}, - {headerName: 'SO Date', field: 'podate'}, + {headerName: 'Contract Number', field: 'contractNum', editable: true}, + {headerName: 'SO Title', field: 'title', editable: true}, + {headerName: 'Contract Amount', field: 'contractAmtString'}, + // {headerName: 'Contract Amount', field: 'contractAmt'}, + {headerName: 'SO Date', field: 'podate', editable: true}, {headerName: '# of Invoice', field: 'invoiceSequence'}, - {headerName: 'notes', field: 'notes'} + {headerName: 'notes', field: 'notes', editable: true, cellEditor: 'agLargeTextCellEditor'} // {headerName: 'oneInvInDraft', field: 'oneInvInDraft'} ]; - rowData: any; + selected = null; // the selected SO row + + // data for SO detail grid + selectedPODetail; + detailColumnDefs = [ + {headerName: '#', field: 'lineItemNo'}, + {headerName: 'Description', field: 'serviceDesc', editable: true}, + {headerName: 'Rate Type', field: 'rateTypeName', editable: true, + cellEditor: 'agSelectCellEditor', cellEditorParams: {values: this.rateNames}}, + {headerName: 'Service Type', field: 'serviceTypeName', editable: true, + cellEditor: 'agSelectCellEditor', cellEditorParams: {values: this.serviceNames}}, + {headerName: 'Qty or Hours', field: 'qty', editable: true}, + {headerName: 'Rate ($)', field: 'fee', editable: true} + ]; + contractAmount = 0; // used to show total amount constructor(private astuteClientService: AstuteClientService) { } ngOnInit() { - this.refreshData(); this.astuteClientService.getServiceTypes().then((d) => { if (d) { this.serviceTypes = d; + this.serviceTypes.forEach((type) => { + this.serviceNames.push(type.serviceTypeDesc); + }); + // console.log(this.serviceNames); } else { - alert ('get service types failed'); + alert ('Get service types failed'); } + }, reason => { + alert('Get service type failed: ' + reason); + }); + this.astuteClientService.getRateTypes().then((d) => { + if (d) { + this.rateTypes = d; + this.rateTypes.forEach((type) => { + this.rateNames.push(type.feeTypeDesc); + }); + } else { + alert ('Get rate types failed'); + } + }, reason => { + alert('Get rate type failed: ' + reason); + }); + this.astuteClientService.getCustomers().then((customers) => { + if (customers) { + this.customers = customers; + this.refreshData(); + } else { + alert('Get Customers Failed!'); + } + }, (reason) => { + alert('Get Customers Failed: ' + reason); }); } - printValue(val) { - console.log(val); + + // callback for grid selection + setSelectedRow(event) { + if (event) { + this.selected = event.data; + } + + this.selectedPODetail = this.astuteClientService.getPODetail(this.selected.ponum).then((data) => { + if (data) { + data.forEach((row) => { + row.poNum = row.ponum; + row.serviceTypeName = this.serviceNames[row.serviceTypeId - 1]; + row.rateTypeName = this.rateNames[row.feeTypeId - 1]; + }); + // console.log(this.selectedPODetail); + this.updateContractAmt(); + if (this.gridColumnApi) { + this.gridColumnApi.autoSizeAllColumns(); + } + if (this.detailColumnApi) { + this.detailColumnApi.autoSizeAllColumns(); + } + return data; + } else { + alert('Get SO detail failed!'); + } + }, (reason) => { + alert('Get SO detail failed: ' + reason); + }); } - gridOptions = { - onRowClicked: (event) => { - this.getSelectedRows(); + // for inline updating + updateRow(event) { + const eventData = event.data; + // console.log(eventData); + + this.astuteClientService.updatePO(eventData.poNum, eventData).then((data) => { + if (!data) { + alert('SO updating failed, check input fields'); + } + this.refreshData(); + }, (reason) => { + alert('Update SO failed: ' + reason); + }); + // this.refreshData(); + } + updateDetailRow(event) { + const eventData = event.data; + // console.log(eventData); + event.data.serviceTypeId = this.getServiceIdFromName(event.data.serviceTypeName); + event.data.feeTypeId = this.getFeeIdFromName(event.data.rateTypeName); + if (event.data.feeTypeId === 1 && event.data.qty > 1) { // fixed fee and qty > 1 + alert('Cannot have a quantity greater than 1 for fixed fee rate type.'); + this.refreshDetailsOfSelected(); + } else { + // console.log(event.data.serviceTypeId); + this.astuteClientService.updatePODetail(eventData.poNum, eventData.lineItemNo, eventData).then((data) => { + if (!data) { + alert('SO Detail updating failed, check input fields'); + } + this.refreshDetailsOfSelected(); + }, (reason) => { + alert('Update SO Detail failed: ' + reason); + }); + // this.refreshData(); } } + // wrappers for PO service methods addPo(projNum, ponum, podate, customerid, contractnum, contractamt, title, notes, ref) { const poData = { - "astuteProjectNumber": projNum, - "poNum": ponum, - "podate": podate, - "customerId": customerid, - "contractNum": contractnum, - "contractAmt": contractamt, - "title": title, - "notes": notes, - } - console.log(poData); + 'astuteProjectNumber': projNum, + 'poNum': ponum, + 'podate': podate, + 'customerId': customerid, + 'contractNum': contractnum, + 'contractAmt': contractamt, + 'title': title, + 'notes': notes + }; + // console.log(poData); this.astuteClientService.createPO(poData).then((data) => { if (data) { this.refreshData(); - this.addPODetail(this.newPODetail); + // this.addPODetail(this.newPODetail); ref.close(); } else { - alert("PO Creation failed, check input fields"); + alert('SO Creation failed, check input fields'); } }, (reason) => { - alert("add po failed for " + reason); + alert('Add SO failed for ' + reason); }); } - - addPODetail(details) { - if (details.length) { - console.log(details[0]); - this.astuteClientService.createPODetail(details[0]).then((data) => { - if (data) { - details.splice(0, 1); - this.addPODetail(details); - } else { - alert("add detail failed"); - } - }); - } else { - this.newPODetail = []; - } - } - editPo(projNum, ponum, podate, contractnum, contractamt, title, notes, ref) { const poData = { - "astuteProjectNumber": projNum, - "poNum": ponum, - "podate": podate, - "contractNum": contractnum, - "contractAmt": contractamt, - "title": title, - "notes": notes, - } - console.log(poData); + 'astuteProjectNumber': projNum, + 'poNum': ponum, + 'podate': podate, + 'contractNum': contractnum, + 'contractAmt': contractamt, + 'title': title, + 'notes': notes, + }; + // console.log(poData); this.astuteClientService.updatePO(ponum, poData).then((data) => { if (data) { this.refreshData(); - this.editPODetail(this.selectedPODetail); + // this.editPODetail(this.selectedPODetail); ref.close(); } else { - alert("PO updating failed, check input fields"); + alert('SO updating failed, check input fields'); } }, (reason) => { - alert("update po failed for " + reason); + alert('Update SO failed for ' + reason); }); } - - editPODetail(details) { - if (details.length) { - console.log(details[0]); - this.astuteClientService.updatePODetail(details[0].ponum, details[0].lineItemNo, details[0]).then((data) => { - if (data) { - details.splice(0, 1); - this.editPODetail(details); - } else { - alert('add detail failed'); - } - }); - } else { - this.newPODetail = []; - } - } - - finalizePO(ponum) { this.astuteClientService.finalizePO(ponum).then((data) => { if (data) { this.refreshData(); - alert("PO is now final and ready to be used, you can't delete it anymore!"); + alert('SO is now final and ready to be used, you can\'t delete it anymore!'); } else { - alert("Finalizing PO failed, check input fields"); + alert('Finalizing SO failed, check input fields'); } + }, reason => { + alert('Finalizing SO failed: ' + reason); }); } - deletePO(ponum) { - this.astuteClientService.deletePO(ponum).then((data) => { - if (data) { - this.refreshData(); - } else { - alert("deleting PO failed, check input fields"); + if (confirm('Are you sure?')) { + this.astuteClientService.deletePO(ponum).then((data) => { + if (data) { + this.refreshData(); + } else { + alert('Deleting SO failed, check input fields'); + } + }, (reason) => { + alert('Deleting SO failed: ' + reason); + + }); + } + } + + // wrappers for SO detail service methods + addEmptyDetail() { + const emptyData = { + fee: 0, + feeTypeId: 1, + // lineItemNo: 7, + poNum: this.selected.poNum, + qty: 1, + remainingQty: 1, + serviceDesc: '', + serviceTypeId: 1 + }; + + // String poNum; + // int lineItemNo; + // String serviceDesc; + // int feeTypeId; + // Double qty; + // Double fee; + // int serviceTypeId; + // Double remainingQuantity; + this.astuteClientService.createPODetail(emptyData).then((data) => { + if (!data) { + alert('Creating SO detailed failed!'); } + this.refreshDetailsOfSelected(); + }, (reason) => { + alert('Creating SO detailed failed: ' + reason); }); } - pushOntoSelectedDetail(lineItemNo: number, ponum, serviceDesc, feeTypeId, serviceTypeId, qty, fee, remainingQty) { - this.selectedPODetail.push({ - 'lineItemNo': lineItemNo, - 'ponum': ponum, - 'serviceDesc': serviceDesc, - 'feeTypeId': feeTypeId, - 'serviceTypeId': serviceTypeId, - 'qty': qty, - 'fee': fee, - 'remainingQty': remainingQty - }); - } - - pushOntoNewDetail(lineItemNo: number, ponum, serviceDesc, feeTypeId, serviceTypeId, qty, fee, remainingQty) { - this.newPODetail.push({ - 'lineItemNo': lineItemNo, - 'poNum': ponum, - 'serviceDesc': serviceDesc, - 'feeTypeId': feeTypeId, - 'serviceTypeId': serviceTypeId, - 'qty': qty, - 'fee': fee, - 'remainingQty': remainingQty - }); - } - - updateNewContractAmt() { - let tot = 0; - this.newPODetail.forEach((d) => { - tot += +d.qty * +d.fee; - }); - this.newContractAmount = tot; - } - - updateEditContractAmt() { - let tot = 0; - this.selectedPODetail.forEach((d) => { - tot += +d.qty * +d.fee; - }); - this.editContractAmount = tot; - } - + // open and closing modal-form components open(ref) { - this.getSelectedRows(); + // this.getSelectedRows(); + this.gridColumnApi.autoSizeAllColumns(); + this.detailColumnApi.autoSizeAllColumns(); ref.open(); } - close(ref) { - this.newPODetail = []; - this.selectedPODetail = []; - + // this.newPODetail = []; + // this.selectedPODetail = []; ref.close(); } - onSelectedCellChange(row: number, col: string, value) { - this.selectedPODetail[row][col] = value; - console.log(this.selectedPODetail); - } - - onNewCellChange(row: number, col: string, value) { - this.newPODetail[row][col] = value; - console.log(this.newPODetail); + // refreshing data methods + refreshData() { + // this.astuteClientService.getPOs().then((data) => { + // if (data) { + // // this.pos = data; + // this.rowData = data; + // this.rowData.forEach((row) => { + // row.customerName = this.getCustomerNameFromId(row.customerId); + // row.contractAmtString = formatCurrency(row.contractAmt, 'en-US', '$', 'USD'); + // row.poNum = row.ponum; + // }); + // this.selected = null; + // this.updateNewContractAmt(); + // this.updateEditContractAmt(); + // } else { + // alert('Get SO\'s Failed!'); + // } + // }, (reason) => { + // alert('Get SO\'s Failed: ' + reason); + // }); + this.rowData = this.astuteClientService.getPOs().then((data) => { + if (data) { + // this.pos = data; + data.forEach((row) => { + row.customerName = this.getCustomerNameFromId(row.customerId); + row.contractAmtString = formatCurrency(row.contractAmt, 'en-US', '$', 'USD'); + row.poNum = row.ponum; + }); + this.selected = null; + this.contractAmount = 0; + return data; + } else { + alert('Get SO\'s Failed!'); + } + }, (reason) => { + alert('Get SO\'s Failed: ' + reason); + }); + } + refreshDetailsOfSelected() { + this.setSelectedRow(null); + } + updateContractAmt() { + this.contractAmount = 0; + if (this.selectedPODetail) { + this.selectedPODetail.then((detail) => { + detail.forEach((d) => { + this.contractAmount += +d.qty * +d.fee; + }); + }); + } } + // helper methods getCurrDate() { const d = new Date(); return this.formatDate(d); } - formatDate(d: Date) { let month = '' + (d.getMonth() + 1), day = '' + d.getDate(), @@ -240,50 +350,7 @@ export class SalesOrderComponent implements OnInit { } return [year, month, day].join('-'); } - - getSelectedRows() { - const selectedNodes = this.agGrid.api.getSelectedNodes(); - if (selectedNodes.length) { - this.selected = selectedNodes.map(node => node.data)[0]; - // this.editContractAmount = +this.selected.contractAmt; - console.log(this.selected.contractNum); - this.astuteClientService.getPODetail(this.selected.ponum).then((data) => { - if (data) { - this.selectedPODetail = data; - // console.log(this.selectedPODetail); - this.updateEditContractAmt(); - } else { - alert('get PO detail failed!'); - } - }); - } else { - this.selected = null; - this.selectedPODetail = []; - } - } - - refreshData() { - this.astuteClientService.getCustomers().then((customers) => { - if (customers) { - this.customers = customers; - this.astuteClientService.getPOs().then((data) => { - if (data) { - this.pos = data; - this.rowData = data; - this.rowData.forEach((row) => { - row.customerName = this.getCustomerName(row.customerId); - row.contractAmt = formatCurrency(row.contractAmt, 'en-US', '$', 'USD'); - }); - } - }); - } else { - alert('get Customers Failed!'); - } - }); - // this.rowData = this.astuteClientService.getPOs(); - } - - getCustomerName(customerId) { + getCustomerNameFromId(customerId) { let name = ''; this.customers.forEach((customer) => { if (customer.customerId === customerId) { @@ -292,4 +359,36 @@ export class SalesOrderComponent implements OnInit { }); return name; } + getServiceIdFromName(name) { + let id = -1; + this.serviceTypes.forEach((type) => { + console.log(type.serviceTypeDesc + ' ' + name); + if (type.serviceTypeDesc === name) { + id = type.serviceTypeId; + } + }); + return id; + } + getFeeIdFromName(name: any) { + let id = -1; + this.rateTypes.forEach((type) => { + if (type.feeTypeDesc === name) { + id = type.feeTypeId; + } + }); + return id; + } + + // ag grid callbacks + onGridReady(evt) { + this.gridApi = evt.api; + this.gridColumnApi = evt.columnApi; + } + onDetailGridReady(evt) { + this.detailGridApi = evt.api; + this.detailColumnApi = evt.columnApi; + } + resizeColumns(evt) { + evt.columnApi.autoSizeAllColumns(); + } } diff --git a/AstuteClient2/src/app/services/astute-client-service.ts b/AstuteClient2/src/app/services/astute-client-service.ts index a7a3c02..4618fc2 100644 --- a/AstuteClient2/src/app/services/astute-client-service.ts +++ b/AstuteClient2/src/app/services/astute-client-service.ts @@ -3,101 +3,100 @@ import {Injectable} from '@angular/core'; @Injectable() export class AstuteClientService { - headers = { - headers: new HttpHeaders().set('Content-Type', 'application/json'), - }; - private authUrl = 'http://localhost:8080/astutesystem/auth'; - private customerUrl = 'http://localhost:8080/astutesystem/customer'; - private POUrl = 'http://localhost:8080/astutesystem/po'; - private POServiceTypesUrl = 'http://localhost:8080/astutesystem/po/serviceTypes'; - private PODetailUrl = 'http://localhost:8080/astutesystem/po/detail'; - private invoiceUrl = 'http://localhost:8080/astutesystem/invoice'; - private invoiceDetailUrl = 'http://localhost:8080/astutesystem/invoice/detail'; - private invoiceGenUrl = 'http://localhost:8080/astutesystem/invoice/generatedInvoice'; - private invoicePaymentUrl = 'http://localhost:8080/astutesystem/invoicePayment'; - private serviceTypeUrl = 'http://localhost:8080/astutesystem/serviceType'; - private sessionId = localStorage.getItem(''); - private sessionString = `?sessionId=${this.sessionId}`; - - constructor(private http: HttpClient) { } - - // **************************************** AUTH Service methods - - public login(username: string, password: string): Promise { - const data = { - 'username': username, - 'password': password + headers = { + headers: new HttpHeaders().set('Content-Type', 'application/json'), }; + private authUrl = 'http://localhost:8080/astutesystem/auth'; + private customerUrl = 'http://localhost:8080/astutesystem/customer'; + private customerContactUrl = 'http://localhost:8080/astutesystem/customer/contact'; + private POUrl = 'http://localhost:8080/astutesystem/po'; + private POServiceTypesUrl = 'http://localhost:8080/astutesystem/po/serviceTypes'; + private PODetailUrl = 'http://localhost:8080/astutesystem/po/detail'; + private invoiceUrl = 'http://localhost:8080/astutesystem/invoice'; + private invoiceDetailUrl = 'http://localhost:8080/astutesystem/invoice/detail'; + private invoiceGenUrl = 'http://localhost:8080/astutesystem/invoice/generatedInvoice'; + private invoicePaymentUrl = 'http://localhost:8080/astutesystem/invoicePayment'; + private serviceTypeUrl = 'http://localhost:8080/astutesystem/serviceType'; + private sessionString = `?sessionId=${localStorage.getItem('SESSION_ID')}`; - return this.http - .post(this.authUrl, data) - .toPromise() - .then(response => { - console.log(response['entity']); - const name = response['entity'].name; - const sessionId = response['entity'].sessionId; - if (sessionId != null) { - localStorage.setItem('SESSION_ID', sessionId); - localStorage.setItem('SESSION_USER', name); - return sessionId; - } else { - return null; - } - }); - } - public logout() { - localStorage.removeItem('SESSION_ID'); - localStorage.removeItem('SESSION_USER'); - console.log(localStorage.getItem('SESSION_ID')); + constructor(private http: HttpClient) { } + + // **************************************** AUTH Service methods + public login(username: string, password: string): Promise { + const data = { + 'username': username, + 'password': password + }; + return this.http + .post(this.authUrl, data) + .toPromise() + .then(response => { + console.log(response['entity']); + const name = response['entity'].name; + const sessionId = response['entity'].sessionId; + if (sessionId != null) { + localStorage.setItem('SESSION_ID', sessionId); + this.sessionString = `?sessionId=${localStorage.getItem('SESSION_ID')}`; + console.log(sessionId); + localStorage.setItem('SESSION_USER', name); + return sessionId; + } else { + return null; + } + }); + } + public logout() { + return this.http + .post(`${this.authUrl}/logout${this.sessionString}`, {}) + .toPromise() + .then(response => { + localStorage.removeItem('SESSION_ID'); + localStorage.removeItem('SESSION_USER'); + return response['entity']; + }); } - public getSessionId(): string { console.log(localStorage.getItem('SESSION_ID')); return localStorage.getItem('SESSION_ID'); } - public getSessionUser(): string { console.log(localStorage.getItem('SESSION_USER')); return localStorage.getItem('SESSION_USER'); } - - // **************************************** Customer Service methods - - public getCustomers(): Promise { - console.log("*** In getCustomers()"); - const url = `${this.customerUrl}${this.sessionString}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }) - .catch( error => { - alert(error); - }); - } - - public updateCustomer(customerId: number, data: any): Promise { - console.log("*** In updateCustomer()"); - const url = `${this.customerUrl}/${customerId}`; //TODO send sessionId - return this.http.put(url, data) - .toPromise() - .then(response => response['entity']); - } - - public createCustomer(data: any): Promise { - console.log("*** In createCustomer()"); - const url = `${this.customerUrl}`; //TODO send sessionId - return this.http.post(url, data) - .toPromise() - .then(response => response['entity']); - } - + // **************************************** Customer Service methods + public getCustomers(): Promise { + console.log('*** In getCustomers()'); + const url = `${this.customerUrl}${this.sessionString}`; + console.log(url); + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }) + .catch( error => { + alert(error); + }); + } + public updateCustomer(customerId: number, data: any): Promise { + console.log('*** In updateCustomer()'); + const url = `${this.customerUrl}/${customerId}${this.sessionString}`; + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + public createCustomer(data: any): Promise { + console.log('*** In createCustomer()'); + const url = `${this.customerUrl}${this.sessionString}`; + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } public deleteCustomer(customerId) { - console.log("*** In deleteCustomer()"); - const url = `${this.customerUrl}/${customerId}/delete`; + console.log('*** In deleteCustomer()'); + const url = `${this.customerUrl}/${customerId}/delete${this.sessionString}`; return this.http.put(url, {}) .toPromise() .then(response => { @@ -106,200 +105,11 @@ export class AstuteClientService { }); } - // **************************************** PO Service methods - - - public getPOs(): Promise { - console.log("*** In getPOs()"); - const url = `${this.POUrl}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public getPODetail(ponum): Promise { - console.log("*** In getPODetails()"); - const url = `${this.PODetailUrl}?PONum=${ponum}`; - console.log(url); - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public updatePO(ponum: string, data: any): Promise { - console.log("*** In updatePO()"); - const url = `${this.POUrl}/${ponum}`; //TODO send sessionId - return this.http.put(url, data) - .toPromise() - .then(response => response['entity']); - } - - public createPO(data: any): Promise { - console.log("*** In createPO()"); - const url = `${this.POUrl}`; //TODO send sessionId - return this.http.post(url, data) - .toPromise() - .then(response => response['entity']); - } - - public updatePODetail(ponum, lineItemNo, data) { - console.log("*** In updatePODetail()"); - const sessionId = localStorage.getItem('sessionId'); - const url = `${this.POUrl}/detail/${ponum}/${lineItemNo}`; //TODO send sessionId - return this.http.put(url, data) - .toPromise() - .then(response => response['entity']); - } - - public createPODetail(data) { - console.log("*** In createPODetail()"); - const url = `${this.POUrl}/detail`; //TODO send sessionId - return this.http.post(url, data) - .toPromise() - .then(response => response['entity']); - } - - public finalizePO(ponum: string){ - console.log("*** In finalizePO()"); - const url = `${this.POUrl}/${ponum}/finalize`; //TODO send sessionId - return this.http.put(url, {}) - .toPromise() - .then(response => response['entity']); - } - - - public deletePO(ponum: string) { - console.log("*** In deletePO()"); - const url = `${this.POUrl}/${ponum}/delete`; //TODO send sessionId - return this.http.put(url, {}) - .toPromise() - .then(response => response['entity']); - } - - // **************************************** Invoice Service methods - - // /{InvoiceNumber}/void - public submitInvoice (invoiceNumber) { - console.log("*** In submitInvoice(), invoiceNumber" + invoiceNumber); - const url = `${this.invoiceUrl}/${invoiceNumber}/submit`; - return this.http.put(url, {}) - .toPromise() - .then(response => { - console.log (response['entity']); - return response['entity']; - }); - } - - public voidInvoice (invoiceNumber) { - console.log("*** In voidInvoice(), invoiceNumber" + invoiceNumber); - const url = `${this.invoiceUrl}/${invoiceNumber}/void`; - return this.http.put(url, {}) - .toPromise() - .then(response => { - console.log (response['entity']); - return response['entity']; - }); - } - - public deleteInvoice (invoiceNumber) { - console.log("*** In deleteInvoice(), invoiceNumber" + invoiceNumber); - const url = `${this.invoiceUrl}/${invoiceNumber}/delete`; - return this.http.put(url, {}) - .toPromise() - .then(response => { - console.log (response['entity']); - return response['entity']; - }); - } - - public generateInvoiceNumber (ponum) { - console.log("*** In generateInvoiceNumber()"); - const url = `${this.invoiceUrl}/generateInvoiceNumber/${ponum}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log (response['entity']) - return response['entity']; - }); - } - - public getInvoices(): Promise { - console.log("*** In getInvoices()"); - const url = `${this.invoiceUrl}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public getInvoiceDetail(invoiceId: string): Promise { - console.log("*** In getInvoiceDetail()"); - const url = `${this.invoiceDetailUrl}?invoiceNumber=${invoiceId}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public getInvoiceGen (invoiceId: string): Promise { - console.log("*** In getInvoiceGen()"); - const url = `${this.invoiceGenUrl}/${invoiceId}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public updateInvoice(invoiceNumber: string, data: any): Promise { - console.log("*** In updateInvoice()"); - const url = `${this.invoiceUrl}/${invoiceNumber}`; //TODO send sessionId - return this.http.put(url, data) - .toPromise() - .then(response => response['entity']); - } - - public createInvoice(data: any): Promise { - console.log("*** In createInvoice()"); - const url = `${this.invoiceUrl}`; //TODO send sessionId - return this.http.post(url, data) - .toPromise() - .then(response => response['entity']); - } - - public updateInvoiceDetail(invNum, lineItemNo, data) { - console.log("*** In updateInvoiceDetail()"); - const url = `${this.invoiceUrl}/detail/${invNum}/${lineItemNo}`; //TODO send sessionId - return this.http.put(url, data) - .toPromise() - .then(response => response['entity']); - } - - public createInvoiceDetail(data) { - console.log("*** In createInvoiceDetail()"); - const url = `${this.invoiceUrl}/detail`; //TODO send sessionId - return this.http.post(url, data) - .toPromise() - .then(response => response['entity']); - } - - - // **************************************** Invoice Payment Service methods - - public getSumittedInvoices(): Promise { - console.log("*** In getSumittedInvoices()"); - const url = `${this.invoiceUrl}/submitted`; + // **************************************** Customer Contact Service methods + public getCustomerContacts(customerId): Promise { + console.log('*** In getCustomerContacts()'); + const url = `${this.customerContactUrl}?customerId=${customerId}&sessionId=${localStorage.getItem('SESSION_ID')}`; + console.log(url); return this.http.get(url) .toPromise() .then(response => { @@ -307,51 +117,257 @@ export class AstuteClientService { return response['entity']; }); } - - public getInvoiceTypes(): Promise { - const url = `${this.invoicePaymentUrl}/paymentTypes`; - console.log("*** In getInvoiceTypes() ... calling " + url); - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public getInvoicePayments(): Promise { - console.log("*** In getInvoicePayments()"); - const url = `${this.invoicePaymentUrl}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public updateInvoicePayment(invoiceNumber: string, invoicePaymentId: string, data: any): Promise { - console.log("*** In updateInvoicePayment()"); - const url = `${this.invoicePaymentUrl}/${invoiceNumber}/${invoicePaymentId}`; //TODO send sessionId - console.log("*** invoicePaymentUrl is " + url); + public updateCustomerContact(customerId: string, data: any): Promise { + console.log('*** In updateCustomerContact()'); + const url = `${this.customerContactUrl}/${customerId}${this.sessionString}`; return this.http.put(url, data) .toPromise() .then(response => response['entity']); } + public deleteCustomerContact(customerId: string, contactId: number): Promise { + console.log('*** In deleteCustomerContact()'); + const url = `${this.customerContactUrl}/${customerId}/${contactId}/delete${this.sessionString}`; + return this.http.put(url, {}) + .toPromise() + .then(response => response['entity']); + } + public createCustomerContact(data: any): Promise { + console.log('*** In createCustomerContact()'); + const url = `${this.customerContactUrl}/${this.sessionString}`; + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + // **************************************** PO Service methods + public getPOs(): Promise { + console.log('*** In getPOs()'); + const url = `${this.POUrl}${this.sessionString}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + public getPODetail(ponum): Promise { + console.log('*** In getPODetails()'); + const url = `${this.PODetailUrl}?PONum=${ponum}&sessionId=${localStorage.getItem('SESSION_ID')}`; + console.log(url); + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + public updatePO(ponum: string, data: any): Promise { + console.log('*** In updatePO()'); + const url = `${this.POUrl}/${ponum}${this.sessionString}`; + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + public createPO(data: any): Promise { + console.log('*** In createPO()'); + const url = `${this.POUrl}${this.sessionString}`; + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + public updatePODetail(ponum, lineItemNo, data) { + console.log('*** In updatePODetail()'); + const sessionId = localStorage.getItem('sessionId'); + const url = `${this.POUrl}/detail/${ponum}/${lineItemNo}${this.sessionString}`; + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + public createPODetail(data) { + console.log('*** In createPODetail()'); + const url = `${this.POUrl}/detail${this.sessionString}`; + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + public finalizePO(ponum: string) { + console.log('*** In finalizePO()'); + const url = `${this.POUrl}/${ponum}/finalize${this.sessionString}`; + return this.http.put(url, {}) + .toPromise() + .then(response => response['entity']); + } + public deletePO(ponum: string) { + console.log('*** In deletePO()'); + const url = `${this.POUrl}/${ponum}/delete${this.sessionString}`; + return this.http.put(url, {}) + .toPromise() + .then(response => response['entity']); + } + public getRateTypes(): Promise { + console.log('*** In getPOs()'); + const url = `${this.POUrl}/feeTypes${this.sessionString}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + // **************************************** Invoice Service methods + public submitInvoice (invoiceNumber) { + console.log('*** In submitInvoice(), invoiceNumber' + invoiceNumber); + const url = `${this.invoiceUrl}/${invoiceNumber}/submit${this.sessionString}`; + return this.http.put(url, {}) + .toPromise() + .then(response => { + console.log (response['entity']); + return response['entity']; + }); + } + public voidInvoice (invoiceNumber) { + console.log('*** In voidInvoice(), invoiceNumber' + invoiceNumber); + const url = `${this.invoiceUrl}/${invoiceNumber}/void${this.sessionString}`; + return this.http.put(url, {}) + .toPromise() + .then(response => { + console.log (response['entity']); + return response['entity']; + }); + } + public deleteInvoice (invoiceNumber) { + console.log('*** In deleteInvoice(), invoiceNumber' + invoiceNumber); + const url = `${this.invoiceUrl}/${invoiceNumber}/delete${this.sessionString}`; + return this.http.put(url, {}) + .toPromise() + .then(response => { + console.log (response['entity']); + return response['entity']; + }); + } + public generateInvoiceNumber (ponum) { + console.log('*** In generateInvoiceNumber()'); + const url = `${this.invoiceUrl}/generateInvoiceNumber/${ponum}${this.sessionString}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log (response['entity']); + return response['entity']; + }); + } + public getInvoices(): Promise { + console.log('*** In getInvoices()'); + const url = `${this.invoiceUrl}${this.sessionString}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + public getInvoiceDetail(invoiceId: string): Promise { + console.log('*** In getInvoiceDetail()'); + const url = `${this.invoiceDetailUrl}?invoiceNumber=${invoiceId}&sessionId=${localStorage.getItem('SESSION_ID')}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + public getInvoiceGen (invoiceId: string): Promise { + console.log('*** In getInvoiceGen()'); + const url = `${this.invoiceGenUrl}/${invoiceId}${this.sessionString}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + public updateInvoice(invoiceNumber: string, data: any): Promise { + console.log('*** In updateInvoice()'); + const url = `${this.invoiceUrl}/${invoiceNumber}${this.sessionString}`; + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + public createInvoice(data: any): Promise { + console.log('*** In createInvoice()'); + const url = `${this.invoiceUrl}${this.sessionString}`; + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + public updateInvoiceDetail(invNum, lineItemNo, data) { + console.log('*** In updateInvoiceDetail()'); + const url = `${this.invoiceUrl}/detail/${invNum}/${lineItemNo}${this.sessionString}`; + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + public createInvoiceDetail(data) { + console.log('*** In createInvoiceDetail()'); + const url = `${this.invoiceUrl}/detail${this.sessionString}`; + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + + + // **************************************** Invoice Payment Service methods + public getSumittedInvoices(): Promise { + console.log('*** In getSumittedInvoices()'); + const url = `${this.invoiceUrl}/submitted${this.sessionString}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + public getInvoiceTypes(): Promise { + const url = `${this.invoicePaymentUrl}/paymentTypes${this.sessionString}`; + console.log('*** In getInvoiceTypes() ... calling ' + url); + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + public getInvoicePayments(): Promise { + console.log('*** In getInvoicePayments()'); + const url = `${this.invoicePaymentUrl}${this.sessionString}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + public updateInvoicePayment(invoiceNumber: string, invoicePaymentId: string, data: any): Promise { + console.log('*** In updateInvoicePayment()'); + const url = `${this.invoicePaymentUrl}/${invoiceNumber}/${invoicePaymentId}${this.sessionString}`; + console.log('*** invoicePaymentUrl is ' + url); + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } public addInvoicePayment(data: any): Promise { - console.log("*** In addInvoicePayment()"); - const url = `${this.invoicePaymentUrl}`; //TODO send sessionId + console.log('*** In addInvoicePayment()'); + const url = `${this.invoicePaymentUrl}${this.sessionString}`; return this.http.post(url, data) .toPromise() .then(response => response['entity']); } // **************************************** Service Type methods - public getServiceTypes(): Promise { - console.log("*** In getPOServiceTypes()"); - const url = `${this.serviceTypeUrl}`; + console.log('*** In getPOServiceTypes()'); + const url = `${this.serviceTypeUrl}${this.sessionString}`; + // console.log(url); return this.http.get(url) .toPromise() .then(response => { @@ -359,19 +375,17 @@ export class AstuteClientService { return response['entity']; }); } - - public updateServiceType(serviceTypeId, serviceTypeDesc, data: any): Promise { - console.log("*** In updateServiceType()"); - const url = `${this.serviceTypeUrl}/${serviceTypeId}/?desc=${serviceTypeDesc}`; //TODO send sessionId - console.log("*** updateServiceType is " + url); + public updateServiceType(serviceTypeId, data: any): Promise { + console.log('*** In updateServiceType()'); + const url = `${this.serviceTypeUrl}/${serviceTypeId}${this.sessionString}`; + console.log('*** updateServiceType is ' + url); return this.http.put(url, data) .toPromise() .then(response => response['entity']); } - public createServiceType(data: any): Promise { - console.log("*** In createServiceType()"); - const url = `${this.serviceTypeUrl}`; //TODO send sessionId + console.log('*** In createServiceType()'); + const url = `${this.serviceTypeUrl}${this.sessionString}`; return this.http.post(url, data) .toPromise() .then(response => response['entity']); diff --git a/AstuteClient2/src/app/settings/settings.component.css b/AstuteClient2/src/app/settings/settings.component.css new file mode 100644 index 0000000..2454b91 --- /dev/null +++ b/AstuteClient2/src/app/settings/settings.component.css @@ -0,0 +1,3 @@ +.top-buffer { + margin-top:20px; +} \ No newline at end of file diff --git a/AstuteClient2/src/app/settings/settings.component.html b/AstuteClient2/src/app/settings/settings.component.html new file mode 100644 index 0000000..86b3392 --- /dev/null +++ b/AstuteClient2/src/app/settings/settings.component.html @@ -0,0 +1,75 @@ + +
+
+
+

Settings

+
+ +

Configuration

+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ +

Configuration

+
+
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/AstuteClient2/src/app/settings/settings.component.spec.ts b/AstuteClient2/src/app/settings/settings.component.spec.ts new file mode 100644 index 0000000..91588f3 --- /dev/null +++ b/AstuteClient2/src/app/settings/settings.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { SettingsComponent } from './settings.component'; + +describe('SettingsComponent', () => { + let component: SettingsComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ SettingsComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(SettingsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/AstuteClient2/src/app/settings/settings.component.ts b/AstuteClient2/src/app/settings/settings.component.ts new file mode 100644 index 0000000..f728cbf --- /dev/null +++ b/AstuteClient2/src/app/settings/settings.component.ts @@ -0,0 +1,84 @@ +import { Component, OnInit } from '@angular/core'; +import {AstuteClientService} from '../services/astute-client-service'; +import {Router} from '@angular/router'; + +@Component({ + selector: 'app-settings', + templateUrl: './settings.component.html', + styleUrls: ['./settings.component.css'] +}) +export class SettingsComponent implements OnInit { + serviceTypeData: Promise; + columnDefs = [ + {headerName: 'Service Type ID', field: 'serviceTypeId'}, + {headerName: 'Service Type Description', field: 'serviceTypeDesc', editable: true}, + ]; + gridApi; + gridColumnApi; + + constructor(private astuteClientService: AstuteClientService, + private router: Router) { + } + + ngOnInit() { + this.refreshServiceTypeData(); + } + + updateServiceTypeRow(evt) { + const data = evt.data; + console.log(data); + this.astuteClientService.updateServiceType(data.serviceTypeId, data).then((d) => { + if (!d) { + alert('Service Type updating failed, check input fields'); + } + this.refreshServiceTypeData(); + }, (reason) => { + alert('Update Service Type failed: ' + reason); + }); + } + + addEmptyServiceTypes() { + const data = {'serviceTypeName': ''}; + this.astuteClientService.createServiceType(data).then((d) => { + if (!d) { + alert('Create Service Type Failed!'); + } + this.refreshServiceTypeData(); + }, (reason) => { + alert('Create Service Type Failed: ' + reason); + }); + } + + open(ref) { + ref.open(); + } + close(ref) { + this.refreshServiceTypeData(); + ref.close(); + } + + refreshServiceTypeData() { + this.serviceTypeData = this.astuteClientService.getServiceTypes(); + } + + onGridReady(evt) { + this.gridApi = evt.api; + this.gridColumnApi = evt.columnApi; + } + resizeColumns(evt) { + evt.columnApi.autoSizeAllColumns(); + } + + logout() { + this.astuteClientService.logout().then((data) => { + if (data) { + this.router.navigate(['/login']); + alert('Logout successful'); + } else { + alert('Logout unsuccessful'); + } + }); + } + + +}