* Fixed Responses to catch error messages

* Fixed a function called delete_customer
This commit is contained in:
Gopi Katwala 2019-07-12 22:27:41 -04:00
parent 329b8b3fed
commit 78c21ee143
3 changed files with 571 additions and 58 deletions

View File

@ -127,7 +127,7 @@ export class CustomerComponent implements OnInit {
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) {
} else if (email.length > 0 && /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) === false) {
alert('You have entered an invalid email address!');
} else {
const customerData = {
@ -162,7 +162,7 @@ export class CustomerComponent implements OnInit {
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) {
} else if (email.length > 0 && /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) === false) {
alert('You have entered an invalid email address!');
} else {
const customerData = {
@ -264,7 +264,7 @@ export class CustomerComponent implements OnInit {
} else if (eventData.phone.length > 0 && eventData.phone.length < 14) {
this.refreshData();
alert('Invalid phone.');
} else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(eventData.email) === false) {
} else if (eventData.email.length > 0 && /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(eventData.email) === false) {
this.refreshData();
alert('You have entered an invalid email address!');
} else {
@ -289,14 +289,14 @@ export class CustomerComponent implements OnInit {
// } else if (eventData.workPhone % 10 < 14) {
// alert('Invalid work phone.');
// } else
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(eventData.email) === false) {
if (eventData.email.length > 0 && /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(eventData.email) === false) {
this.contactsData = this.astuteClientService.getCustomerContacts(eventData.customerId);
alert('You have entered an invalid email address!');
} else {
this.astuteClientService.updateCustomerContact(eventData.customerId, eventData).then((data) => {
if (!data) {
this.contactsData = this.astuteClientService.getCustomerContacts(eventData.customerId);
alert('Customer Updating Failed, Check Input Fields');
// alert('Customer Updating Failed, Check Input Fields');
}
}, (reason) => {
alert('Update customer failed: ' + reason);

View File

@ -76,8 +76,9 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
const code = response['code'];
const message = response['message'];
if (message === 'Success') {
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
@ -97,14 +98,46 @@ export class AstuteClientService {
const url = `${this.customerUrl}/${customerId}${this.sessionString}`;
return this.http.put(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Update Customer Failed: ' + message);
}
}, (reason) => {
alert('Update Customer Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public createCustomer(data: any): Promise<any> {
console.log('*** In createCustomer()');
const url = `${this.customerUrl}${this.sessionString}`;
return this.http.post(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Create Customer Failed: ' + message);
}
}, (reason) => {
alert('Create Customer Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public deleteCustomer(customerId) {
console.log('*** In deleteCustomer()');
@ -112,8 +145,21 @@ export class AstuteClientService {
return this.http.put(url, {})
.toPromise()
.then(response => {
console.log (response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Delete Customer Failed: ' + message);
}
}, (reason) => {
alert('Delete Customer Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
@ -124,8 +170,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customer Contacts Failed: ' + message);
}
}, (reason) => {
alert('Get Customer Contacts Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public updateCustomerContact(customerId: string, data: any): Promise<any> {
@ -133,21 +192,69 @@ export class AstuteClientService {
const url = `${this.customerContactUrl}/${customerId}${this.sessionString}`;
return this.http.put(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Update Customer Contacts Failed: ' + message);
}
}, (reason) => {
alert('Update Customer Contacts Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public deleteCustomerContact(customerId: string, contactId: number): Promise<any> {
console.log('*** In deleteCustomerContact()');
const url = `${this.customerContactUrl}/${customerId}/${contactId}/delete${this.sessionString}`;
return this.http.put(url, {})
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Delete Customer Contacts Failed: ' + message);
}
}, (reason) => {
alert('Delete Customer Contacts Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public createCustomerContact(data: any): Promise<any> {
console.log('*** In createCustomerContact()');
const url = `${this.customerContactUrl}/${this.sessionString}`;
return this.http.post(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Create Customer Contacts Failed: ' + message);
}
}, (reason) => {
alert('Create Customer Contacts Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
// **************************************** PO Service methods
@ -157,8 +264,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Get Sales Orders Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public getPODetail(ponum): Promise<any> {
@ -167,8 +287,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Get Sales Order Details Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public updatePO(ponum: string, data: any): Promise<any> {
@ -176,14 +309,46 @@ export class AstuteClientService {
const url = `${this.POUrl}/${ponum}${this.sessionString}`;
return this.http.put(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Update Sales Order Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public createPO(data: any): Promise<any> {
console.log('*** In createPO()');
const url = `${this.POUrl}${this.sessionString}`;
return this.http.post(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Create Sales Order Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public updatePODetail(ponum, lineItemNo, data) {
console.log('*** In updatePODetail()');
@ -191,28 +356,92 @@ export class AstuteClientService {
const url = `${this.POUrl}/detail/${ponum}/${lineItemNo}${this.sessionString}`;
return this.http.put(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Update Sales Order Details Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
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']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Create Sales Order Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
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']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Finalize Sales Order Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
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']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Delete Sales Order Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public getRateTypes(): Promise<any> {
console.log('*** In getRateTypes()');
@ -220,8 +449,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Get Rate Types Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
@ -232,8 +474,21 @@ export class AstuteClientService {
return this.http.put(url, {})
.toPromise()
.then(response => {
console.log (response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Submit Invoice Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public voidInvoice (invoiceNumber) {
@ -242,8 +497,21 @@ export class AstuteClientService {
return this.http.put(url, {})
.toPromise()
.then(response => {
console.log (response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Void Invoice Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public deleteInvoice (invoiceNumber) {
@ -252,8 +520,21 @@ export class AstuteClientService {
return this.http.put(url, {})
.toPromise()
.then(response => {
console.log (response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Delete Invoice Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public generateInvoiceNumber (ponum) {
@ -262,8 +543,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log (response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Generate Invoice Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public getInvoices(): Promise<any> {
@ -272,8 +566,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Get Invoices Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public getInvoiceDetail(invoiceId: string): Promise<any> {
@ -282,8 +589,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Get Invoice Details Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public getInvoiceGen (invoiceId: string): Promise<any> {
@ -292,8 +612,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Get Generated Invoice Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public updateInvoice(invoiceNumber: string, data: any): Promise<any> {
@ -301,28 +634,92 @@ export class AstuteClientService {
const url = `${this.invoiceUrl}/${invoiceNumber}${this.sessionString}`;
return this.http.put(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Update Invoice Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public createInvoice(data: any): Promise<any> {
console.log('*** In createInvoice()');
const url = `${this.invoiceUrl}${this.sessionString}`;
return this.http.post(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Create Invoice Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
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']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Update Invoice Detail Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
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']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Create Invoice Detail Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
@ -333,8 +730,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Get Submitted Invoices Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public getInvoicePaymentTypes(): Promise<any> {
@ -343,8 +753,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Get Invoice Payment Types Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public getInvoicePayments(): Promise<any> {
@ -353,8 +776,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Get Invoice Payments Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public updateInvoicePayment(invoiceNumber: string, invoicePaymentId: string, data: any): Promise<any> {
@ -363,14 +799,46 @@ export class AstuteClientService {
console.log('*** invoicePaymentUrl is ' + url);
return this.http.put(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Update Invoice Payment Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public addInvoicePayment(data: any): Promise<any> {
console.log('*** In addInvoicePayment()');
const url = `${this.invoicePaymentUrl}${this.sessionString}`;
return this.http.post(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Add Invoice Payment Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
// **************************************** Service Type methods
@ -380,8 +848,21 @@ export class AstuteClientService {
return this.http.get(url)
.toPromise()
.then(response => {
console.log(response['entity']);
return response['entity'];
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Get Service Types Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public updateServiceType(serviceTypeId, data: any): Promise<any> {
@ -390,13 +871,45 @@ export class AstuteClientService {
console.log('*** updateServiceType is ' + url);
return this.http.put(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Update Service Type Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
public createServiceType(data: any): Promise<any> {
console.log('*** In createServiceType()');
const url = `${this.serviceTypeUrl}${this.sessionString}`;
return this.http.post(url, data)
.toPromise()
.then(response => response['entity']);
.then(response => {
const code = response['code'];
const message = response['message'];
if (code === 9000) {
console.log(response['entity']);
return response['entity'];
} else if (message.includes('login')) {
alert('Please login again!');
} else {
alert('Get Customers Failed: ' + message);
}
}, (reason) => {
alert('Create Service Type Failed: ' + reason);
})
.catch( error => {
alert(error);
});
}
}

View File

@ -181,7 +181,7 @@ INSERT INTO `customer_contact` (`customer_id`, `contact_id`, `name`, `title`, `w
-- Dumping structure for function astute.delete_customer
DELIMITER //
CREATE DEFINER=`root`@`localhost` FUNCTION `delete_customer`(customer_id_in varchar(20)) RETURNS varchar(40) CHARSET utf8
CREATE DEFINER=`root`@`localhost` FUNCTION `delete_customer`(customer_id_in varchar(10)) RETURNS varchar(100) CHARSET utf8
BEGIN
DECLARE po_count int;