dvrentry.component.ts 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. import { Component, OnDestroy, OnInit } from '@angular/core';
  2. import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';
  3. import { CommonFunctionService } from '../services/commonfunctions.service';
  4. import { RouterModule, Routes, Router } from '@angular/router';
  5. import { Subject } from 'rxjs';
  6. import { HttpClient, HttpHeaders } from '@angular/common/http';
  7. @Component({
  8. selector: 'dvr-entry',
  9. templateUrl: './dvrentry.component.html',
  10. styleUrls: ['./dvrentry.component.css']
  11. })
  12. export class DvrEntryComponent implements OnInit, OnDestroy {
  13. allowOnlyNumber(event: KeyboardEvent) {
  14. const charCode = event.charCode;
  15. if (charCode < 48 || charCode > 57) {
  16. event.preventDefault();
  17. }
  18. }
  19. public contactEntryForm !: FormGroup;
  20. public xmlItems: any;
  21. username: any;
  22. login_id: any;
  23. logindata: any = [];
  24. last_login_date: any;
  25. cust_data: any = [];
  26. contact_data: any = [];
  27. secondContact_Details: any = [];
  28. stage_data: any = [];
  29. currentDateData: any = [];
  30. currentDateData_flag: boolean = false;
  31. currentSecondContact: boolean = false;
  32. cust_name: any;
  33. messages: any;
  34. cust_id: any;
  35. formControlName: any;
  36. current_date: any;
  37. mincurrent_date: any;
  38. dtOptions: any = {};
  39. dtTrigger: Subject<any> = new Subject();
  40. displayStyle = "none";
  41. error_msg: any;
  42. success_msg: any;
  43. status_msg: any;
  44. cont_id: any;
  45. dvrupdate = [];
  46. visit_date: any;
  47. customer_name: any;
  48. contact_name: any;
  49. message: any;
  50. updation_msg: any;
  51. stage_des: any;
  52. stage_id: any;
  53. checkstage_id: any;
  54. dvr_id: any;
  55. role: any;
  56. check_date: any;
  57. est_Date: any;
  58. objective: any;
  59. deal: any;
  60. nextstep: any;
  61. postion: any;
  62. person: any;
  63. funcDetails: any = [];
  64. personDetails: any = [];
  65. checkupdatedelete: boolean;
  66. saveautoData = [];
  67. autofillData = [];
  68. checkoperationflag: boolean = false;
  69. checkdataflag: boolean;
  70. entry_successflag: boolean = false;
  71. second_contact: any;
  72. constructor(private commonservice: CommonFunctionService, private router: Router, private http: HttpClient) {
  73. console.log("in contact");
  74. console.log(this.router.url);
  75. var url = this.router.url;
  76. console.log("url------->", url);
  77. var myArray = url.split(":");
  78. //console.log("myArray", myArray);
  79. this.cont_id = myArray[2];
  80. var res = myArray[1];
  81. console.log("res========>", res);
  82. // getdvrDetailscheck
  83. if (res) {
  84. this.dvr_id = res;
  85. this.checkoperationflag = true;
  86. console.log("in updation");
  87. $(document).ready(function () {
  88. $(".textarea").css("height", "207px");
  89. });
  90. this.commonservice.getAllData(this.commonservice.projectpath + "/getdvrdetails?dvrid=" + res).subscribe(response => {
  91. // console.log("getdvrdetails response----------------> ", response.data);
  92. // console.log("getdvrdetails response----------------> ", response.data[0].contact_name);
  93. this.dvrupdate = response.data;
  94. console.log("this.dvrupdate", this.dvrupdate);
  95. this.visit_date = response.data[0].visit_date;
  96. this.customer_name = response.data[0].customer_name;
  97. this.contact_name = response.data[0].contact_name;
  98. this.updation_msg = response.data[0].mesasge;
  99. this.stage_des = response.data[0].stage_desc;
  100. this.stage_id = response.data[0].stage_id;
  101. this.check_date = response.data[0].created_on;
  102. this.nextstep = response.data[0].nextstep;
  103. this.second_contact = response.data[0].second_contact;
  104. this.est_Date = response.data[0].est_Date;
  105. this.objective = response.data[0].objective;
  106. this.deal = response.data[0].deal;
  107. this.postion = response.data[0].func;
  108. this.person = response.data[0].person;
  109. console.log("functinon::::::::::::::::::", this.contact_name)
  110. //this.visit_date = datePipetransform(this.visit_date.now(),'dd/MM/yyyy');
  111. this.visit_date = this.formatDate(this.visit_date);
  112. this.check_date = this.formatDate(this.check_date);
  113. this.est_Date = this.formatDate(this.est_Date);
  114. this.visit_date = String(this.visit_date)
  115. console.log(" this.visit_date", this.visit_date, this.customer_name, this.contact_name, this.stage_des);
  116. console.log("in updatation");
  117. this.est_Date = String(this.est_Date)
  118. this.contactEntryForm = new FormGroup({
  119. date: new FormControl(this.visit_date, Validators.required),
  120. message: new FormControl(this.updation_msg, Validators.required),
  121. contactName: new FormControl(this.contact_name, Validators.required),
  122. custName: new FormControl(this.customer_name, Validators.required),
  123. stageName: new FormControl(this.stage_des, Validators.required),
  124. ph_meet: new FormControl('yes', Validators.required),
  125. nextstep: new FormControl(this.nextstep, Validators.required),
  126. secondContact: new FormControl(this.second_contact, Validators.required),
  127. estDate: new FormControl(this.est_Date, Validators.required),
  128. objective: new FormControl(this.objective, Validators.required),
  129. deal: new FormControl(this.deal, Validators.required),
  130. postion: new FormControl(this.postion, Validators.required),
  131. personData: new FormControl(this.person, Validators.required),
  132. });
  133. console.log("this.check_date", this.check_date);
  134. var date1 = new Date(this.check_date);
  135. var date2 = new Date();
  136. // To calculate the time difference of two dates
  137. var Difference_In_Time = date2.getTime() - date1.getTime();
  138. // To calculate the no. of days between two dates
  139. var Difference_In_Days = Difference_In_Time / (1000 * 3600 * 24);
  140. console.log("Difference_In_Days---->", Math.round(Difference_In_Days));
  141. if (Math.round(Difference_In_Days) <= 1) {
  142. console.log("differnt in one days");
  143. this.checkupdatedelete = true;
  144. } else {
  145. console.log("difference is longer");
  146. this.checkupdatedelete = false;
  147. // this.FormControl['name'].disable();
  148. }
  149. });
  150. } else {
  151. this.checkoperationflag = false;
  152. console.log("in insert");
  153. }
  154. if (this.checkoperationflag == false) {
  155. console.log("in insert");
  156. this.contactEntryForm = new FormGroup({
  157. date: new FormControl(null, Validators.required),
  158. message: new FormControl(null, Validators.required),
  159. contactName: new FormControl(null, Validators.required),
  160. custName: new FormControl(null, Validators.required),
  161. stageName: new FormControl(null, Validators.required),
  162. ph_meet: new FormControl('yes', Validators.required),
  163. nextstep: new FormControl(null, Validators.required),
  164. secondContact: new FormControl(null, Validators.required),
  165. estDate: new FormControl(null, Validators.required),
  166. objective: new FormControl(null, Validators.required),
  167. deal: new FormControl(null, Validators.required),
  168. postion: new FormControl(null, Validators.required),
  169. personData: new FormControl(null, Validators.required),
  170. });
  171. }
  172. }
  173. ngOnInit() {
  174. this.dtOptions = {
  175. pagingType: 'full_numbers',
  176. pageLength: 15,
  177. processing: true,
  178. order: [],
  179. lengthMenu: [15, 25, 35],
  180. ordering: false,
  181. dom: 'Blfrtip',
  182. buttons: [
  183. 'csv', 'excel', 'print'
  184. ]
  185. }
  186. this.current_date = new Date();
  187. // console.log(this.current_date);
  188. // console.log(this.current_date - 7);
  189. var dd = this.current_date.getDate();
  190. // console.log(this.current_date.getDate())
  191. // console.log(dd);
  192. var mm = this.current_date.getMonth() + 1;
  193. // console.log(this.current_date.getMonth());
  194. // console.log(mm);
  195. var yyyy = this.current_date.getFullYear();
  196. // console.log(dd);
  197. // console.log(mm);
  198. if (dd < 10) {
  199. dd = '0' + dd
  200. }
  201. if (mm < 10) {
  202. mm = '0' + mm
  203. }
  204. this.current_date = yyyy + '-' + mm + '-' + dd;
  205. console.log("max date------>", this.current_date);
  206. document.getElementById("Date").setAttribute("max", this.current_date);
  207. //max date
  208. var dd1;
  209. //console.log("dddddddd------->", this.current_date.getDate() - 7);
  210. // var date = dd - 7;
  211. var date = dd;
  212. this.mincurrent_date = new Date();
  213. var min_mm = this.mincurrent_date.getMonth();
  214. // console.log(min_mm);
  215. if (min_mm < 10) {
  216. min_mm = '0' + min_mm;
  217. }
  218. console.log("date====>", date);
  219. // if (date < 10) {
  220. // dd1 = '0' + date;
  221. // } else {
  222. // dd1 = date;
  223. // }
  224. console.log(yyyy - 1);
  225. if (min_mm == "00") {
  226. min_mm = 11;
  227. yyyy = yyyy - 1;
  228. }
  229. // this.mincurrent_date = yyyy + '-' + mm + '-' + dd1;
  230. // this.mincurrent_date = yyyy + '-' + min_mm + '-' + dd1;
  231. this.mincurrent_date = yyyy + '-' + min_mm + '-' + date;
  232. console.log("min date------>", this.mincurrent_date);
  233. document.getElementById("Date").setAttribute("min", this.mincurrent_date);
  234. this.logindata.push(JSON.parse(localStorage.getItem("loginData")));
  235. this.username = this.logindata[0]["user_name"];
  236. this.last_login_date = this.logindata[0]["last_loginDate"];
  237. this.login_id = this.logindata[0]["user_id"];
  238. this.role = this.logindata[0]["role"];
  239. console.log(" this.logindata=========>", this.login_id, this.role);
  240. this.commonservice.getAllData(this.commonservice.projectpath + "/getselectionData").subscribe(response => {
  241. if (response.status == 'falsetoken') {
  242. this.router.navigate(['/login'])
  243. }
  244. else {
  245. this.cust_data = response.data[0].customerData;
  246. if(this.role === 'users') {
  247. this.cust_data = this.cust_data.filter(item => item.first_name + " " + item.last_name === this.username);
  248. }
  249. this.cust_data = Array.from(
  250. new Map(
  251. this.cust_data.map(item => [
  252. `${item.customer_id}-${item.customer_name}`,
  253. {
  254. customer_id: item.customer_id,
  255. customer_name: item.customer_name
  256. }
  257. ])
  258. ).values()
  259. );
  260. console.log(this.cust_data);
  261. this.contact_data = response.data[1].contactData;
  262. console.log(" this.contact_data ", this.contact_data);
  263. this.stage_data = response.data[2].stageData;
  264. this.personDetails = response.data[3].personData;
  265. this.funcDetails = response.data[4].funcDetails;
  266. }
  267. });
  268. this.commonservice.getAllData(this.commonservice.projectpath + "/getlastestdvr?role=" + this.role + "&login_id=" + this.login_id).subscribe(response => {
  269. if (response.status == 'falsetoken') {
  270. this.router.navigate(['/login'])
  271. } else {
  272. if (response.data[0].getdvrDataStatus == '1') {
  273. //data not found
  274. console.log("in dataa not found");
  275. this.checkdataflag = true
  276. } else {
  277. console.log("in data");
  278. // this.checkdataflag=false;
  279. console.log("response.data[0].dvrData;", response.data[0].getdvrDataStatus);
  280. // if(response.data[0].getdvrDataStatus == '1'){
  281. // console.log("in if condition");
  282. // }else{
  283. // console.log("in else condition");
  284. this.currentDateData = response.data[0].dvrData;
  285. // }
  286. }
  287. this.dtTrigger.next(this.dtOptions)
  288. }
  289. console.log("response-------->", response);
  290. });
  291. setTimeout(() => {
  292. $('#datatableexample').DataTable({
  293. pagingType: 'full_numbers',
  294. pageLength: 5,
  295. processing: true,
  296. lengthMenu: [5, 10, 25]
  297. });
  298. }, 1);
  299. if (localStorage.getItem("contactlastinsert")) {
  300. console.log("data is prsent for contact insert");
  301. this.contact_name = localStorage.getItem("contactlastinsert");
  302. this.contactEntryForm = new FormGroup({
  303. date: new FormControl(this.autofillData["date"], Validators.required),
  304. message: new FormControl(this.autofillData["message"], Validators.required),
  305. contactName: new FormControl(this.contact_name, Validators.required),
  306. custName: new FormControl(this.customer_name, Validators.required),
  307. stageName: new FormControl(this.stage_des, Validators.required),
  308. nextstep: new FormControl(this.autofillData["nextstep"], Validators.required),
  309. secondContact: new FormControl(this.second_contact, Validators.required),
  310. estDate: new FormControl(this.autofillData["estDate"], Validators.required),
  311. objective: new FormControl(this.autofillData["objective"], Validators.required),
  312. deal: new FormControl(this.autofillData["deal"], Validators.required),
  313. postion: new FormControl(this.postion, Validators.required),
  314. personData: new FormControl(this.person, Validators.required),
  315. });
  316. }
  317. if (localStorage.getItem("autofilldata")) {
  318. console.log("data is autofilldata");
  319. console.log("local storage item", localStorage.getItem("autofilldata"));
  320. console.log("local storage item---->", localStorage.getItem("contactlastinsert"));
  321. this.autofillData.push(JSON.parse(localStorage.getItem("autofilldata")));
  322. console.log("this.autofillData", this.autofillData[0]);
  323. this.autofillData = this.autofillData[0][0];
  324. console.log("date", this.autofillData["custName"].customer_name);
  325. this.customer_name = this.autofillData["custName"].customer_name;
  326. if (localStorage.getItem("contactlastinsert")) {
  327. this.contact_name = localStorage.getItem("contactlastinsert")
  328. }
  329. this.cust_id = this.autofillData["custName"].customer_id;
  330. if (this.autofillData["stageName"] == null) {
  331. //stage name null
  332. } else {
  333. this.stage_id = this.autofillData["stageName"].stage_id;
  334. this.stage_des = this.autofillData["stageName"].stage_desc;
  335. }
  336. // this.stage_des=
  337. this.contactEntryForm = new FormGroup({
  338. date: new FormControl(this.autofillData["date"], Validators.required),
  339. message: new FormControl(this.autofillData["message"], Validators.required),
  340. contactName: new FormControl(this.contact_name, Validators.required),
  341. custName: new FormControl(this.customer_name, Validators.required),
  342. stageName: new FormControl(this.stage_des, Validators.required),
  343. ph_meet: new FormControl(this.autofillData["ph_meet"], Validators.required),
  344. nextstep: new FormControl(this.autofillData["nextstep"], Validators.required),
  345. secondContact: new FormControl(this.second_contact, Validators.required),
  346. estDate: new FormControl(this.autofillData["estDate"], Validators.required),
  347. objective: new FormControl(this.autofillData["objective"], Validators.required),
  348. deal: new FormControl(this.autofillData["deal"], Validators.required),
  349. postion: new FormControl(this.autofillData["postion"], Validators.required),
  350. personData: new FormControl(this.person, Validators.required),
  351. });
  352. }
  353. }
  354. ngOnDestroy(): void {
  355. this.dtTrigger.unsubscribe();
  356. }
  357. ngOnchanges() {
  358. console.log("form.value.message", this.contactEntryForm);
  359. this.secondContactDetails(this.contactEntryForm)
  360. }
  361. ngDoCheck() {
  362. console.log("form.value.message", this.contactEntryForm);
  363. this.secondContactDetails(this.contactEntryForm)
  364. }
  365. openPopup() {
  366. this.displayStyle = "block";
  367. }
  368. closePopup() {
  369. this.displayStyle = "none";
  370. if (this.checkoperationflag == true) {
  371. this.router.navigate(['/home'])
  372. } else {
  373. if (this.entry_successflag == true) {
  374. window.location.reload();
  375. }
  376. }
  377. }
  378. dvrEntry(form: FormGroup) {
  379. console.log("this.login_id", this.login_id)
  380. if (this.checkoperationflag == true) {
  381. //in updation
  382. console.log("form.value.custName", form.value.custName.length);
  383. if (form.value.custName.length == undefined) {
  384. console.log("change custname");
  385. this.customer_name = form.value.custName.customer_name;
  386. //((form.value.custName ? form.value.custName.customer_name : '') ? '' : this.customer_name )
  387. } if (form.value.contactName.length == undefined) {
  388. console.log("change contactname", form.value.contactName);
  389. this.contact_name = form.value.contactName.first_name + ' ' + form.value.contactName.last_name;
  390. console.log("contact name", this.contact_name);
  391. } if (form.value.stageName.length == undefined) {
  392. console.log("change stage id");
  393. this.stage_id = form.value.stageName.stage_id;
  394. } if (form.value.secondContact.length == undefined) {
  395. console.log("change contactname", form.value.secondContact);
  396. this.second_contact = form.value.secondContact.first_name + ' ' + form.value.secondContact.last_name;
  397. console.log("contact name", this.second_contact);
  398. }
  399. const createdvr = {
  400. dvr_id: this.dvr_id,
  401. visit_date: form.value.date,
  402. customer_name: this.customer_name,
  403. contact_name: this.contact_name,
  404. message: form.value.message,
  405. physical_metting: form.value.ph_meet,
  406. stage_id: this.stage_id,
  407. updated_by: this.login_id,
  408. nextstep: form.value.nextstep,
  409. second_contact: this.second_contact != null ? this.second_contact : '',
  410. estDate: form.value.estDate,
  411. objective: form.value.objective,
  412. deal: form.value.deal,
  413. postion: form.value.postion,
  414. person: form.value.personData,
  415. }
  416. console.log("createdvr111", createdvr);
  417. this.commonservice.updateData(this.commonservice.projectpath + "/updateDvrEntry", createdvr).subscribe(response => {
  418. this.status_msg = "";
  419. this.error_msg = "";
  420. if (response.status == 'falsetoken') {
  421. this.router.navigate(['/login'])
  422. } else {
  423. console.log("response.error", response.errors);
  424. console.log("response.data", response.data[0]);
  425. if (response.data.length == 0) {
  426. //warning
  427. this.openPopup();
  428. this.status_msg = "Warning";
  429. this.error_msg = response.errors;
  430. } else if (response.data.length > 0) {
  431. console.log("inside if(response.message== '') ")
  432. this.openPopup();
  433. localStorage.removeItem("autofilldata")
  434. this.status_msg = "Success";
  435. this.error_msg = response.data[0].message;
  436. // console.log("response.data.message", response.data[0].exception.errorid);
  437. // if (response.data[0].exception.errorid != '') {
  438. // this.openPopup();
  439. // this.status_msg = "Warning";
  440. // this.error_msg = response.errors;
  441. // }
  442. }
  443. else {
  444. this.status_msg = "";
  445. this.error_msg = "";
  446. }
  447. }
  448. console.log("response-------->", response);
  449. });
  450. } else {
  451. //in insert
  452. var createdvr;
  453. console.log("this.stage_id", this.stage_id);
  454. console.log("this.second_contact", this.second_contact, form.value.secondContact);
  455. if (this.stage_id == undefined) {
  456. createdvr = {
  457. visit_date: form.value.date,
  458. customer_name: (this.customer_name == undefined ? form.value.custName.customer_name : this.customer_name),
  459. contact_name: (this.contact_name == undefined ? form.value.contactName.first_name + ' ' + form.value.contactName.last_name : this.contact_name),
  460. message: form.value.message,
  461. physical_metting: form.value.ph_meet,
  462. sale_person: this.username,
  463. stage_id: (form.value.stageName ? form.value.stageName.stage_id : ''),
  464. created_by: this.login_id,
  465. nextstep: form.value.nextstep,
  466. second_contact: (form.value.secondContact == null ? null : form.value.secondContact.first_name + form.value.secondContact.last_name),
  467. estDate: form.value.estDate,
  468. objective: form.value.objective,
  469. deal: form.value.deal,
  470. func: form.value.postion ? form.value.postion.func_name : null,
  471. person: form.value.personData ? form.value.personData.person_name : null,
  472. }
  473. } else {
  474. createdvr = {
  475. visit_date: form.value.date,
  476. customer_name: (this.customer_name == undefined ? form.value.custName.customer_name : this.customer_name),
  477. contact_name: (this.contact_name == undefined ? form.value.contactName.first_name + form.value.contactName.last_name : this.contact_name),
  478. message: form.value.message,
  479. physical_metting: form.value.ph_meet,
  480. sale_person: this.username,
  481. stage_id: this.stage_id,
  482. created_by: this.login_id,
  483. nextstep: form.value.nextstep,
  484. second_contact: (form.value.secondContact == null ? null : form.value.secondContact.first_name + form.value.secondContact.last_name),
  485. estDate: form.value.estDate,
  486. objective: form.value.objective,
  487. deal: form.value.deal,
  488. func: form.value.postion ? form.value.postion.func_name : null,
  489. person: form.value.personData ? form.value.personData.person_name : null,
  490. }
  491. }
  492. console.log("createdvr in insert", createdvr);
  493. console.log("estDate", form.value.estDate);
  494. console.log("yyyyyyyy", this.customer_name, form.value.custName, this.stage_id, form.value.stageName, this.username);
  495. this.commonservice.getData(this.commonservice.projectpath + "/createDvrEntry", createdvr).subscribe(response => {
  496. this.status_msg = "";
  497. this.error_msg = "";
  498. if (response.status == 'falsetoken') {
  499. this.router.navigate(['/login'])
  500. } else {
  501. console.log("response.error", response.errors);
  502. console.log("response.data", response.data.length);
  503. if (response.data.length == 0) {
  504. //warning
  505. this.openPopup();
  506. this.status_msg = "Warning";
  507. this.error_msg = response.errors;
  508. } else if (response.data.length > 0) {
  509. console.log("inside if(response.message== '') ");
  510. localStorage.removeItem("contactlastinsert")
  511. this.openPopup();
  512. this.status_msg = "Success";
  513. this.error_msg = response.data[0].message;
  514. this.entry_successflag = true;
  515. this.customer_name = "";
  516. this.contact_name = "";
  517. this.stage_id = "";
  518. this.stage_des = "";
  519. this.postion = "";
  520. this.person = "";
  521. this.second_contact = "";
  522. localStorage.removeItem("autofilldata")
  523. this.contactEntryForm = new FormGroup({
  524. date: new FormControl(null, Validators.required),
  525. message: new FormControl(null, Validators.required),
  526. contactName: new FormControl(null, Validators.required),
  527. custName: new FormControl(null, Validators.required),
  528. stageName: new FormControl(null, Validators.required),
  529. ph_meet: new FormControl('yes', Validators.required),
  530. nextstep: new FormControl(null, Validators.required),
  531. secondContact: new FormControl(null, Validators.required),
  532. estDate: new FormControl(null, Validators.required),
  533. objective: new FormControl(null, Validators.required),
  534. deal: new FormControl(null, Validators.required),
  535. postion: new FormControl(null, Validators.required),
  536. personData: new FormControl(null, Validators.required),
  537. });
  538. // console.log("response.data.message", response.data[0].exception.errorid);
  539. if (response.data[0].exception.errorid != '') {
  540. this.openPopup();
  541. this.status_msg = "Warning";
  542. this.error_msg = response.errors;
  543. }
  544. }
  545. else {
  546. this.status_msg = "";
  547. this.error_msg = "";
  548. }
  549. }
  550. console.log("response-------->", response);
  551. });
  552. }
  553. console.log(" this.logindata=========>", this.login_id, this.role);
  554. this.commonservice.getAllData(this.commonservice.projectpath + "/getlastestdvr?role=" + this.role + "&login_id=" + this.login_id).subscribe(response => {
  555. if (response.status == 'falsetoken') {
  556. this.router.navigate(['/login'])
  557. } else {
  558. // console.log("response-------->", response);
  559. this.currentDateData = response.data[0].dvrData;
  560. }
  561. });
  562. }
  563. addUser() {
  564. console.log("addUser button click");
  565. this.customer_name = "";
  566. this.contact_name = "";
  567. this.stage_id = "";
  568. this.stage_des = "";
  569. this.second_contact = "";
  570. this.postion = "";
  571. this.person = "";
  572. this.contactEntryForm = new FormGroup({
  573. date: new FormControl(null, Validators.required),
  574. message: new FormControl(null, Validators.required),
  575. contactName: new FormControl(null, Validators.required),
  576. custName: new FormControl(null, Validators.required),
  577. stageName: new FormControl(null, Validators.required),
  578. ph_meet: new FormControl('yes', Validators.required),
  579. nextstep: new FormControl(null, Validators.required),
  580. secondContact: new FormControl(null, Validators.required),
  581. estDate: new FormControl(null, Validators.required),
  582. objective: new FormControl(null, Validators.required),
  583. deal: new FormControl(null, Validators.required),
  584. postion: new FormControl(null, Validators.required),
  585. personData: new FormControl(null, Validators.required),
  586. });
  587. }
  588. contactDetails(form: FormGroup) {
  589. console.log("form value", form.value);
  590. if (form.value.contactName == "Add New Contact") {
  591. if (form.value.custName == null) {
  592. console.log("value not entered");
  593. //user not entered customer details
  594. this.router.navigate(['/contactDetails'])
  595. localStorage.removeItem('autofilldata');
  596. } else if (this.customer_name != null) {
  597. this.router.navigate(["/contactDetails/contact:" + this.customer_name + "/id:" + this.cust_id]);
  598. }
  599. else {
  600. console.log("value entered");
  601. this.cust_name = form.value.custName.customer_name;
  602. this.cust_id = form.value.custName.customer_id
  603. this.saveautoData.push(form.value);
  604. console.log("this.saveautoData", this.saveautoData)
  605. localStorage.setItem('autofilldata', JSON.stringify(this.saveautoData));
  606. //user entered customer details
  607. this.router.navigate(["/contactDetails/contact:" + this.cust_name + "/id:" + this.cust_id]);
  608. }
  609. } else {
  610. console.log('other options selected');
  611. }
  612. if (form.value.secondContact == "Add New Contact") {
  613. if (form.value.custName == null) {
  614. console.log("value not entered");
  615. //user not entered customer details
  616. this.router.navigate(['/contactDetails'])
  617. localStorage.removeItem('autofilldata');
  618. } else if (this.customer_name != null) {
  619. this.router.navigate(["/contactDetails/contact:" + this.customer_name + "/id:" + this.cust_id]);
  620. }
  621. else {
  622. console.log("value entered");
  623. this.cust_name = form.value.custName.customer_name;
  624. this.cust_id = form.value.custName.customer_id
  625. this.saveautoData.push(form.value);
  626. console.log("this.saveautoData", this.saveautoData)
  627. localStorage.setItem('autofilldata', JSON.stringify(this.saveautoData));
  628. //user entered customer details
  629. this.router.navigate(["/contactDetails/contact:" + this.cust_name + "/id:" + this.cust_id]);
  630. }
  631. } else {
  632. console.log('other options selected');
  633. }
  634. }
  635. customerDetails(form: FormGroup) {
  636. console.log("form value", form.value.custName.customer_name);
  637. if (form.value.custName) {
  638. this.commonservice.getAllData(this.commonservice.projectpath + "/getcustcontactdetails?customer_id=" + form.value.custName.customer_name).subscribe(response => {
  639. if (response.status == 'falsetoken') {
  640. this.router.navigate(['/login'])
  641. } else {
  642. this.contact_data = response.data[0].conrtactData;
  643. console.log("aaaaaaaaaaa------------>", this.contact_data);
  644. // this.dtTrigger.next(this.dtOptions)
  645. }
  646. });
  647. } else {
  648. console.log("customer not selected yet");
  649. }
  650. }
  651. get dateValidationCheck() {
  652. return this.formControlName.get('date');
  653. }
  654. isFieldValid(field: string) {
  655. // console.log("in field", field)
  656. return !this.contactEntryForm.get(field).valid && this.contactEntryForm.get(field).touched;
  657. }
  658. displayFieldCss(field: string) {
  659. return {
  660. 'has-error': this.isFieldValid(field),
  661. 'has-feedback': this.isFieldValid(field)
  662. };
  663. }
  664. formatDate(date) {
  665. var d = new Date(date),
  666. month = '' + (d.getMonth() + 1),
  667. day = '' + d.getDate(),
  668. year = d.getFullYear();
  669. if (month.length < 2)
  670. month = '0' + month;
  671. if (day.length < 2)
  672. day = '0' + day;
  673. return [year, month, day].join('-');
  674. }
  675. currformatDate() {
  676. var d = new Date(),
  677. month = '' + (d.getMonth() + 1),
  678. day = '' + d.getDate(),
  679. year = d.getFullYear();
  680. if (month.length < 2)
  681. month = '0' + month;
  682. if (day.length < 2)
  683. day = '0' + day;
  684. return [year, month, day].join('-');
  685. }
  686. deleteEntry() {
  687. console.log("delete entry");
  688. const dvrEntryData = {
  689. dvr_id: this.dvr_id,
  690. created_by: this.login_id
  691. }
  692. console.log("dvrEntryData ", dvrEntryData);
  693. this.commonservice.getData(this.commonservice.projectpath + "/deletedvrEntry", dvrEntryData).subscribe(response => {
  694. console.log("response", response);
  695. if (response.status == 'falsetoken') {
  696. this.router.navigate(['/login'])
  697. } else {
  698. console.log("response", response);
  699. if (response.data.length < 1) {
  700. //warning
  701. console.log("in warning")
  702. this.openPopup();
  703. this.status_msg = "Warning";
  704. this.error_msg = response.errors;
  705. } else if (response.data.length > 0) {
  706. console.log("inside if(response.message== '') ");
  707. console.log("message", response.data[0].message);
  708. this.openPopup();
  709. this.status_msg = "Success";
  710. this.error_msg = response.data[0].message;
  711. console.log("this.error_msg", this.error_msg);
  712. this.entry_successflag = true;
  713. this.customer_name = "";
  714. this.contact_name = "";
  715. this.stage_id = "";
  716. this.stage_des = "";
  717. this.postion = "";
  718. this.person = "";
  719. localStorage.removeItem("contactlastinsert")
  720. localStorage.removeItem("autofilldata")
  721. this.contactEntryForm = new FormGroup({
  722. date: new FormControl(null, Validators.required),
  723. message: new FormControl(null, Validators.required),
  724. contactName: new FormControl(null, Validators.required),
  725. custName: new FormControl(null, Validators.required),
  726. stageName: new FormControl(null, Validators.required),
  727. ph_meet: new FormControl('yes', Validators.required),
  728. nextstep: new FormControl(null, Validators.required),
  729. secondContact: new FormControl(null, Validators.required),
  730. estDate: new FormControl(null, Validators.required),
  731. objective: new FormControl(null, Validators.required),
  732. deal: new FormControl(null, Validators.required),
  733. postion: new FormControl(null, Validators.required),
  734. personData: new FormControl(null, Validators.required),
  735. });
  736. //this.router.navigate(['/home'])
  737. // console.log("response.data.message", response.data[0].exception.errorid);
  738. }
  739. else {
  740. this.status_msg = "";
  741. this.error_msg = "";
  742. }
  743. }
  744. });
  745. }
  746. secondContactDetails(form: FormGroup) {
  747. // console.log("form value", form.value);
  748. if (form.value.contactName != null) {
  749. console.log("first contact is present")
  750. console.log("email", form.value.contactName.email_id)
  751. if (form.value.contactName.email_id != null) {
  752. this.secondContact_Details = this.contact_data.filter((item: { email_id: any; }) => item.email_id != form.value.contactName.email_id)
  753. console.log("contact dataqqqqqqqqqqqqqqqqqqq", this.contact_data)
  754. this.currentSecondContact = true;
  755. } else {
  756. this.currentSecondContact = false;
  757. }
  758. } else {
  759. console.log("first contact is not present")
  760. }
  761. }
  762. funcPersonDetails(form: FormGroup) {
  763. console.log("form value", form.value);
  764. if (form.value.postion != null) {
  765. console.log("postion", form.value.postion)
  766. this.commonservice.getAllData(this.commonservice.projectpath + "/mappingFuncIDToPersonNames?func_id=" + form.value.postion.func_id).subscribe(response => {
  767. if (response.status == 'falsetoken') {
  768. this.router.navigate(['/login'])
  769. } else {
  770. console.log("response:::::::::::::::::::::::::::::::::::::::::::::::::", response.data)
  771. this.personDetails = response.data;
  772. console.log("personDetails------------>", this.personDetails);
  773. }
  774. });
  775. } else {
  776. console.log(" func_id is not present")
  777. }
  778. }
  779. }