|
|
@@ -4,6 +4,7 @@ import { CommonFunctionService } from '../services/commonfunctions.service';
|
|
|
import { DatePipe } from '@angular/common';
|
|
|
import { Router } from '@angular/router';
|
|
|
import { Subject } from 'rxjs';
|
|
|
+import { NgModule } from '@angular/core';
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
@@ -26,7 +27,8 @@ export class CustomerComponent implements OnInit {
|
|
|
|
|
|
datalist: any = [];
|
|
|
salePersonlist: any = [];
|
|
|
-
|
|
|
+ cust_add: any;
|
|
|
+ sp_add: any;
|
|
|
|
|
|
checkfirstnm_flag: boolean = false;
|
|
|
checklastnm_flag: boolean = false;
|
|
|
@@ -90,7 +92,8 @@ export class CustomerComponent implements OnInit {
|
|
|
this.contactList = [];
|
|
|
this.customerForm = new FormGroup({
|
|
|
customer_name: new FormControl('', Validators.required),
|
|
|
- sales_person: new FormControl('', Validators.required)
|
|
|
+ sales_person: new FormControl('', Validators.required),
|
|
|
+ status: new FormControl('', Validators.required)
|
|
|
})
|
|
|
|
|
|
|
|
|
@@ -101,23 +104,18 @@ export class CustomerComponent implements OnInit {
|
|
|
this.login_id = this.loginData[0]["user_id"];
|
|
|
this.role = this.loginData[0]["role"];
|
|
|
|
|
|
-
|
|
|
-
|
|
|
this.commonservice.getAllData(this.commonservice.projectpath + "/getselectionData").subscribe(response => {
|
|
|
if (response.status == 'falsetoken') {
|
|
|
this.router.navigate(['/login'])
|
|
|
} else {
|
|
|
this.cust_data = response.data[0].customerData;
|
|
|
+ // console.log(this.cust_data);
|
|
|
this.dtTrigger.next(this.dtOptions);
|
|
|
console.log("yyyyyyyyyyyyyy");
|
|
|
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
this.commonservice.getAllData(this.commonservice.projectpath + "/getsalepersonlist").subscribe(response => {
|
|
|
if (response.status == 'falsetoken') {
|
|
|
this.router.navigate(['/login'])
|
|
|
@@ -146,6 +144,7 @@ export class CustomerComponent implements OnInit {
|
|
|
customer_id: "",
|
|
|
customer_name: form.value.customer_name,
|
|
|
sale_person: form.value.sales_person,
|
|
|
+ status: form.value.status,
|
|
|
created_by: this.login_id,
|
|
|
action: 'insert'
|
|
|
}
|
|
|
@@ -176,7 +175,8 @@ export class CustomerComponent implements OnInit {
|
|
|
this.checkfirstnm_flag = true;
|
|
|
this.customerForm = new FormGroup({
|
|
|
customer_name: new FormControl('', Validators.required),
|
|
|
- sales_person: new FormControl('', Validators.required)
|
|
|
+ sales_person: new FormControl('', Validators.required),
|
|
|
+ status: new FormControl('', Validators.required)
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
@@ -273,6 +273,157 @@ export class CustomerComponent implements OnInit {
|
|
|
};
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ onEditButtonClick() {
|
|
|
+ if (this.isEditMode) {
|
|
|
+ this.editCustomerLogic();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ onAddButtonClick() {
|
|
|
+ if (this.isAddMode) {
|
|
|
+ console.log("Adding");
|
|
|
+ this.showAddBox = true;
|
|
|
+
|
|
|
+ // this.addCustomerMappingLogic();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+closeAddPanel() {
|
|
|
+ this.showAddBox = false;
|
|
|
+}
|
|
|
+
|
|
|
+addTask(customerId: string, userId: string) {
|
|
|
+
|
|
|
+ if (!customerId || !userId) {
|
|
|
+ alert('Please select both Customer and User');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const payload = {
|
|
|
+ customer_id: customerId,
|
|
|
+ user_id: userId,
|
|
|
+ created_by: this.login_id
|
|
|
+ };
|
|
|
+
|
|
|
+ console.log('Mapping Payload:', payload);
|
|
|
+ this.commonservice.getData(this.commonservice.projectpath + "/addCustomerUserMapping", payload).subscribe(response => {
|
|
|
+
|
|
|
+ console.log("response", response);
|
|
|
+
|
|
|
+ if (response.status == 'falsetoken') {
|
|
|
+ this.router.navigate(['/login'])
|
|
|
+ } else {
|
|
|
+ console.log("response", response);
|
|
|
+ // this.msg = response["message"];
|
|
|
+ if (response.status == false) {
|
|
|
+ //error occured
|
|
|
+ this.status_msg = "Warning";
|
|
|
+ this.error_msg = response.data[0].message;
|
|
|
+ this.openPopup();
|
|
|
+ } else {
|
|
|
+ //succeessful response
|
|
|
+ if (response.data?.[0]?.addCustomerMappingStatus === '0') {
|
|
|
+ this.sucess_flag = true;
|
|
|
+ this.status_msg = "Success";
|
|
|
+ this.error_msg = response.data[0].message;
|
|
|
+ this.openPopup();
|
|
|
+ this.checkfirstnm_flag = true;
|
|
|
+ this.closeAddPanel();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ this.status_msg = "Warning";
|
|
|
+ this.error_msg = response.data[0].message;
|
|
|
+ this.openPopup();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+ editCustomerLogic() {
|
|
|
+ console.log("Editing");
|
|
|
+ console.log(this.customerForm.value);
|
|
|
+ console.log(this.old_sales_person_id);
|
|
|
+ const customerData = {
|
|
|
+ customer_id: this.selectedCustomerId,
|
|
|
+ customer_name: this.customerForm.value.customer_name,
|
|
|
+ sale_person: this.customerForm.value.sales_person,
|
|
|
+ status: this.customerForm.value.status,
|
|
|
+ updated_by: this.login_id,
|
|
|
+ old_sale_person: this.old_sales_person_id
|
|
|
+ }
|
|
|
+ console.log(customerData);
|
|
|
+ this.commonservice.updateData(this.commonservice.projectpath + "/updateCustomerDetails", customerData).subscribe(response => {
|
|
|
+
|
|
|
+ console.log("response", response);
|
|
|
+
|
|
|
+ if (response.status == 'falsetoken') {
|
|
|
+ this.router.navigate(['/login'])
|
|
|
+ } else {
|
|
|
+ console.log("response", response);
|
|
|
+ // this.msg = response["message"];
|
|
|
+ if (response.status == false) {
|
|
|
+ //error occured
|
|
|
+ this.openPopup();
|
|
|
+ this.status_msg = "Warning";
|
|
|
+ this.error_msg = response.errors || response.mesasge;
|
|
|
+ } else {
|
|
|
+ //succeessful response
|
|
|
+ if (response.updateCustomerStatus == 0) {
|
|
|
+ this.openPopup();
|
|
|
+ this.sucess_flag = true;
|
|
|
+ this.status_msg = "Success";
|
|
|
+ this.error_msg = response.mesasge;
|
|
|
+ this.checkfirstnm_flag = true;
|
|
|
+ this.customerForm = new FormGroup({
|
|
|
+ customer_name: new FormControl('', Validators.required),
|
|
|
+ sales_person: new FormControl('', Validators.required),
|
|
|
+ status: new FormControl('', Validators.required)
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+ this.openPopup();
|
|
|
+ this.status_msg = "Warning";
|
|
|
+ this.error_msg = response.mesasge;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ selectedCustomerId: any;
|
|
|
+ isEditMode: boolean = false;
|
|
|
+ isAddMode: boolean = true;
|
|
|
+ showAddBox: boolean = false;
|
|
|
+ old_sales_person_id: any;
|
|
|
+
|
|
|
+ editCustomer(current: any) {
|
|
|
+ console.log(current);
|
|
|
+ this.isEditMode = true;
|
|
|
+ this.selectedCustomerId = current.customer_id;
|
|
|
+ console.log(this.selectedCustomerId);
|
|
|
+
|
|
|
+ this.customerForm.patchValue({
|
|
|
+ customer_id: current.customer_id,
|
|
|
+ customer_name: current.customer_name,
|
|
|
+ status: current.customer_status,
|
|
|
+ sales_person: current.first_name + " " + current.last_name || current.first_name
|
|
|
+ });
|
|
|
+
|
|
|
+ this.old_sales_person_id = current.user_id;
|
|
|
+
|
|
|
+ window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
|
+
|
|
|
+ // NEED TO ADD EDIT BUTTON ON UI BESIDES SAVE, DROPDOWN FOR STATUS,
|
|
|
+ // QUERY TO FETCH USER AS WELL SO CAN UPDATE THAT, ETC
|
|
|
+ }
|
|
|
+
|
|
|
+ deleteCustomer(i: any) {
|
|
|
+ console.log("Deleting" + i)
|
|
|
+ }
|
|
|
+
|
|
|
openPopup() {
|
|
|
this.displayStyle = "block";
|
|
|
}
|
|
|
@@ -359,10 +510,9 @@ export class CustomerComponent implements OnInit {
|
|
|
|
|
|
reset(){
|
|
|
this.resetflag=true;
|
|
|
- this.customerForm = new FormGroup({
|
|
|
- customer_name: new FormControl('', Validators.required),
|
|
|
- sales_person: new FormControl('', Validators.required)
|
|
|
- })
|
|
|
+ this.isEditMode = false;
|
|
|
+ this.isAddMode = false;
|
|
|
+ this.customerForm.reset();
|
|
|
}
|
|
|
}
|
|
|
|