Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 35.65 KB | None | 0 0
  1. import { AddCasePage } from './../../cases/add-case/add-case';
  2. import { AcceptSalePage } from './../../sales-opportunities/sales-details/accept-sale/accept-sale';
  3. import { CasesProvider } from './../../../providers/cases/cases';
  4. import { LoadingService } from './../../../providers/api/LoadingService';
  5. import { ErrorProvider } from '../../../providers/error/error';
  6. import { ICustomer, CrmPersonContactDto, CrmRestRelationDto, CrmCommentDto } from '../../../models/customer.model';
  7. import { TranslateService } from '@ngx-translate/core';
  8. import { ClientsProvider } from '../../../providers/clients/clients';
  9. import { ClientCRMPage } from '../client-crm-page/client-crm-page';
  10. import { Component } from '@angular/core';
  11. import { ModalController, Keyboard } from 'ionic-angular';
  12. import { AddRelationModalPage } from '../add-client/add-relation-modal/add-relation-modal';
  13. import { ToastController, IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
  14. import { FormGroup, FormBuilder, Validators } from '@angular/forms';
  15. import { DictionaryDao } from '../../../providers/db/dictionary-dao';
  16. import { IDictionaryEntity } from '../../../providers/db/dictionary-entity';
  17. import { IRelationDictionary } from '../../../models/dictionaries.model';
  18. import { IContact } from '../../../models/contact.model';
  19. import * as moment from 'moment';
  20. import { UtilProvider } from '../../../providers/util';
  21. import { NormalizerProvider } from '../../../providers/normalizer/normalizer';
  22. import { IPostCode, IStreet, IVoivodeship, ICounty, ICommune } from '../../../models/normalizer.model';
  23. import { NormalizerModalPage } from '../../normalizer-modal/normalizer-modal';
  24.  
  25.  
  26. @IonicPage()
  27. @Component({
  28. selector: 'add-client',
  29. templateUrl: 'add-client.html',
  30. })
  31.  
  32.  
  33.  
  34. export class AddClientPage {
  35.  
  36. hdl: any;
  37. gender: string;
  38. // eca: any;
  39. // ecaID: number;
  40. commentDiff: string = '';
  41. businessClient: boolean;
  42. privateComment: boolean;
  43. isNewClient: boolean;
  44. customerType: number = 0;
  45. required: boolean = true;
  46. timeout: any = undefined;
  47.  
  48. moreAddressData: boolean = false;
  49.  
  50. clientData: ICustomer;
  51. relationsData: CrmRestRelationDto[] = [];
  52. commentsData: CrmCommentDto[] = [];
  53.  
  54. provinceList: Array<IVoivodeship> = [];
  55. countyList: Array<ICounty> = [];
  56. tempCommuneList: Array<ICommune> = [];
  57. communeList: Array<ICommune> = [];
  58. districtList: Array<ICommune> = [];
  59.  
  60. mailContacts: CrmPersonContactDto[] = [];
  61. phoneContacts: CrmPersonContactDto[] = [];
  62.  
  63.  
  64. commentsScrollHeight: any = '0px';
  65. casesScrollHeight: any = '0px';
  66. vehiclesScrollHeight: any = '0px';
  67. relationsScrollHeight: any = '0px';
  68.  
  69. relationsDict: Array<IRelationDictionary>;
  70. //ecaDict: Array<CrmEcaDto>;
  71. //slownik: Array<CrmEcaDto>;
  72. businessTypesDict: any;
  73. countriesDict: any;
  74. streetTypesDict: any;
  75. normalizerMode: boolean;
  76.  
  77. serviceRequestClientForm: FormGroup;
  78. serviceRequestRelationsForm: FormGroup;
  79.  
  80. clicked: Array<boolean>;
  81.  
  82. translateValue: string;
  83. loadingMessage: any;
  84. loadingState: boolean;
  85. typedNote: string;
  86. saveContactErrorMsg: string;
  87.  
  88. requiredMsg: string;
  89. requiredFirstName: string;
  90. requiredLastName: string;
  91. requiredName: string;
  92. requiredSex: string;
  93. requiredContact: string;
  94. requiredBusinessType: string;
  95. requiredGender: string;
  96. casesModel: any;
  97.  
  98.  
  99.  
  100. constructor(
  101. public keyboard: Keyboard,
  102. public dictionaryDao: DictionaryDao,
  103. public navCtrl: NavController,
  104. public navParams: NavParams,
  105. public modalCtrl: ModalController,
  106. public clientService: ClientsProvider,
  107. public loadingCtrl: LoadingService,
  108. public alertCtrl: AlertController,
  109. private _fb: FormBuilder,
  110. public translate: TranslateService,
  111. public toastCtrl: ToastController,
  112. public errorProvider: ErrorProvider,
  113. public casesProvider: CasesProvider,
  114. public normalizerProvider: NormalizerProvider)
  115.  
  116. {
  117. this.getProvinceList();
  118.  
  119. this.hdl = this.navParams.get("hdl");
  120. this.clientData = this.navParams.get("clientData");
  121. console.warn("this.cliendata", this.clientData)
  122. this.businessClient = false;
  123. this.privateComment = false;
  124. this.isNewClient = true;
  125. this.normalizerMode = false;
  126. this.clicked = [false, true, false, false, false, false];
  127. //this.getECADictionary();
  128. this.keyboard.hasFocusedTextInput()
  129.  
  130. this.getBusinessTypesDictionary();
  131. this.getCountriesDictionary();
  132. this.getStreetTypesDictionary();
  133. this.getTranslations();
  134. this.getRelationsDictionary();
  135.  
  136. this.serviceRequestClientForm = this._fb.group({
  137. gender: [''],
  138. name1: ['', Validators.compose([Validators.required, Validators.minLength(2)])],
  139. name2: [''],
  140. vatin: ['', Validators.pattern('^[0-9]{10}$')],
  141. regon: ['', Validators.pattern('^[0-9]{9}$')],
  142. businessEntity: [''],
  143. pesel: ['', Validators.pattern('^[0-9]{11}$')],
  144. shortDesc: [''],
  145. moreCardNo: [''],
  146. streetName: [''],
  147. streetHdl: [''],
  148. houseNo: [''],
  149. cityName: [''],
  150. cityHdl: [''],
  151. postCode: ['', Validators.pattern('[0-9]{2}-[0-9]{3}')],
  152.  
  153. province: [''],
  154. county: [''],
  155. commune: [''],
  156. communeType: [''],
  157. district: [''],
  158. country: [''],
  159. streetType: [''],
  160.  
  161. phoneNumber: ['', Validators.pattern('^[0-9]{9}$')],
  162. mobilePhoneNumber: ['', Validators.pattern('^[0-9]{9}$')],
  163. mail: ['', Validators.pattern('^$|^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(?:[a-zA-Z]{2})$')],
  164. });
  165.  
  166.  
  167. if (typeof this.clientData != 'undefined') {
  168. this.isNewClient = false;
  169. this.fillClientForm();
  170.  
  171. }
  172.  
  173. this.serviceRequestClientForm.get('moreCardNo').disable();
  174. }
  175.  
  176. // ionViewDidLoad() {
  177. // this.getCaseList();
  178. // }
  179.  
  180. ionViewDidEnter() {
  181. this.getCaseList();
  182. }
  183.  
  184. getCaseList() {
  185. this.casesProvider.getCaseList("", "ALL", 20, 0, "", "", this.hdl)
  186. .subscribe(data => {
  187. this.casesModel = data;
  188. console.log("------------------TASKS: ", data);
  189. this.resizeIonScroll();
  190. // console.log("CASES LIST: ", this.casesModel);
  191. }, (err) => {
  192. // this.showErrorDataOnPage(err);
  193. })
  194. }
  195.  
  196. addCase() {
  197. this.navCtrl.push(AcceptSalePage, { customer: this.clientData });
  198. }
  199.  
  200. getCasePage(elem){
  201. this.navCtrl.push(AddCasePage, { hdl: elem.hdl, 'customer-hdl': elem.customerHdl })
  202. }
  203.  
  204. searchByPostCode(){
  205. let searchByPostCodeModal = this.modalCtrl.create(NormalizerModalPage);
  206. searchByPostCodeModal.onDidDismiss(async(data: IPostCode) => {
  207. if(!data) return null;
  208. if(data.custom) {
  209. this.serviceRequestClientForm.controls['cityName'].setValue(data.city.name);
  210. this.serviceRequestClientForm.controls['postCode'].setValue(data.name);
  211. }
  212. else {
  213. this.normalizerMode = true;
  214. this.serviceRequestClientForm.controls['cityName'].setValue(data.city.name);
  215. this.serviceRequestClientForm.controls['cityHdl'].setValue(data.city.hdl);
  216. this.serviceRequestClientForm.controls['postCode'].setValue(data.name);
  217. if(data.communeType)
  218. this.serviceRequestClientForm.controls['communeType'].setValue(data.communeType.hdl);
  219. if(data.voivodeship && data.voivodeship.name){
  220. await this.normalizerProvider.getCountyList(data.voivodeship.name).then(resp => this.countyList = resp.items);
  221. this.serviceRequestClientForm.controls['province'].setValue(data.voivodeship.hdl);
  222. }
  223. if(data.county && data.county.name){
  224. await this.normalizerProvider.getCommuneList(data.county.name).then(resp => {
  225. this.districtList = [];
  226. this.communeList = [];
  227. resp.items.forEach(commune => {
  228. if(commune.communeType.hdl === 8 || commune.communeType.hdl === 9)
  229. this.districtList.push(commune);
  230. else
  231. this.communeList.push(commune);
  232. });
  233. });
  234. this.serviceRequestClientForm.controls['county'].setValue(data.county.hdl);
  235. }
  236.  
  237. if(data.commune && data.commune.name)
  238. this.serviceRequestClientForm.controls['commune'].setValue(data.commune.hdl);
  239. }
  240. })
  241. searchByPostCodeModal.present();
  242. }
  243.  
  244. searchByStreet(){
  245. if(this.serviceRequestClientForm.get('cityName').value && this.serviceRequestClientForm.get('postCode').value){
  246. let searchByStreetModal = this.modalCtrl.create(NormalizerModalPage, { cityName: this.serviceRequestClientForm.get('cityName').value, postCode: this.serviceRequestClientForm.get('postCode').value });
  247. searchByStreetModal.onDidDismiss((data: IStreet) => {
  248. if(!data) return null;
  249. this.normalizerMode = true;
  250. this.serviceRequestClientForm.controls['streetHdl'].setValue(data.hdl);
  251. if(data.namePrefix)
  252. this.serviceRequestClientForm.controls['streetName'].setValue(data.namePrefix + " " + data.name);
  253. else
  254. this.serviceRequestClientForm.controls['streetName'].setValue(data.name);
  255. if(data.streetType)
  256. this.serviceRequestClientForm.controls['streetType'].setValue(data.streetType);
  257. })
  258. searchByStreetModal.present();
  259. }
  260. }
  261.  
  262.  
  263. saveClient() {
  264. if (this.generalValidation()) {
  265. let loading = this.loadingCtrl.create({
  266. content: "Trwa zapis kontaktu."
  267. });
  268. loading.present();
  269. let clientForm = this.getClientForm();
  270. if (this.isNewClient) {
  271. this.createClient(clientForm);
  272. }
  273. else {
  274. this.editClient(clientForm);
  275. }
  276. console.log("TO WYSYLAM:", this.clientData)
  277. this.clientService.saveClient(this.clientData).subscribe(response => {
  278. console.log("TO ODBIERAM:", response)
  279. loading.dismiss();
  280. this.navCtrl.push(ClientCRMPage, { hdl: response.hdl }).then(() => {
  281. if (this.isNewClient) {
  282. const startIndex = this.navCtrl.getActive().index - 1;
  283. this.navCtrl.remove(startIndex, 1);
  284. }
  285. else {
  286. const startIndex = this.navCtrl.getActive().index - 2;
  287. this.navCtrl.remove(startIndex, 2);
  288. }
  289. });
  290. }, error => {
  291. loading.dismiss();
  292. this.showErrorToast(this.saveContactErrorMsg + ': ' + error);
  293. });
  294. }
  295. }
  296.  
  297. getClientForm(){
  298. let clientForm = {
  299. name1: this.serviceRequestClientForm.get('name1').value,
  300. name2: this.serviceRequestClientForm.get('name2').value,
  301. gender: this.serviceRequestClientForm.get('gender').value,
  302. street: this.serviceRequestClientForm.get('streetName').value,
  303. streetHdl: this.serviceRequestClientForm.get('streetHdl').value,
  304. streetType: this.serviceRequestClientForm.get('streetType').value,
  305. houseNo: this.serviceRequestClientForm.get('houseNo').value,
  306. cityName: this.serviceRequestClientForm.get('cityName').value,
  307. cityHdl: this.serviceRequestClientForm.get('cityHdl').value,
  308. postCode: this.serviceRequestClientForm.get('postCode').value,
  309. moreCardNo: this.serviceRequestClientForm.get('moreCardNo').value,
  310.  
  311. voivodeshipHdl: this.serviceRequestClientForm.get('province').value,
  312. communeHdl: this.serviceRequestClientForm.get('commune').value,
  313. communeTypeHdl: this.serviceRequestClientForm.get('communeType').value,
  314. countyHdl: this.serviceRequestClientForm.get('county').value,
  315. district: this.serviceRequestClientForm.get('district').value,
  316. country: this.serviceRequestClientForm.get('country').value,
  317.  
  318. regon: this.serviceRequestClientForm.get('regon').value,
  319. vatin: this.serviceRequestClientForm.get('vatin').value,
  320. pesel: this.serviceRequestClientForm.get('pesel').value,
  321. shortDesc: this.serviceRequestClientForm.get('shortDesc').value,
  322. businessEntity: this.serviceRequestClientForm.get('businessEntity').value,
  323. };
  324. return clientForm;
  325. }
  326.  
  327. generalValidation() {
  328. let required = [];
  329.  
  330. if (this.businessClient) {
  331. if (this.serviceRequestClientForm.get('name1').value === null || this.serviceRequestClientForm.get('name1').value === '') required.push(this.requiredName)
  332. if (this.serviceRequestClientForm.get('businessEntity').value === null || this.serviceRequestClientForm.get('businessEntity').value === '') required.push(this.requiredBusinessType)
  333. }
  334. else {
  335. if (this.serviceRequestClientForm.get('name1').value === null || this.serviceRequestClientForm.get('name1').value === '') required.push(this.requiredLastName)
  336. if (this.serviceRequestClientForm.get('name2').value === null || this.serviceRequestClientForm.get('name2').value === '') required.push(this.requiredFirstName)
  337. if ((this.gender === null && this.gender === '' || typeof this.gender === 'undefined')) required.push(this.requiredGender)
  338. }
  339.  
  340. if (this.phoneContacts.concat(this.mailContacts).length === 0) required.push(this.requiredContact);
  341.  
  342. if (required.length === 0)
  343. return true;
  344. else{
  345. this.showErrorToast(this.requiredMsg + required.join(', '))
  346. return false;
  347. }
  348.  
  349. }
  350.  
  351.  
  352.  
  353. createClient(clientForm) {
  354. if (this.businessClient) {
  355. this.clientData = {
  356. name1: clientForm.name1,
  357. shortDesc: clientForm.shortDesc,
  358. street: clientForm.street,
  359. streetHdl: clientForm.streetHdl,
  360. streetType: clientForm.streetType,
  361. houseNo: clientForm.houseNo,
  362. cityName: clientForm.cityName,
  363. cityHdl: clientForm.cityHdl,
  364. communeHdl: clientForm.communeHdl,
  365. communeTypeHdl: clientForm.communeTypeHdl,
  366. country: clientForm.country,
  367. countyHdl: clientForm.countyHdl,
  368. voivodeshipHdl: clientForm.voivodeshipHdl,
  369. postCode: clientForm.postCode,
  370. regon: clientForm.regon,
  371. vatin: clientForm.vatin,
  372. businessEntity: clientForm.businessEntity,
  373. legalFormCode: this.getLegalFormCode(),
  374. contacts: this.phoneContacts.concat(this.mailContacts),
  375. relations: this.relationsData,
  376. comments: this.commentsData,
  377. customerType: CustomerTypes.Types[this.customerType]
  378. }
  379. }
  380. else {
  381. this.clientData = {
  382. name1: clientForm.name1,
  383. name2: clientForm.name2,
  384. shortDesc: clientForm.shortDesc,
  385. pesel: clientForm.pesel,
  386. gender: clientForm.gender,
  387. vatin: clientForm.vatin,
  388. moreCard: clientForm.moreCardNo,
  389. street: clientForm.street,
  390. streetHdl: clientForm.streetHdl,
  391. streetType: clientForm.streetType,
  392. houseNo: clientForm.houseNo,
  393. cityName: clientForm.cityName,
  394. cityHdl: clientForm.cityHdl,
  395. communeHdl: clientForm.communeHdl,
  396. communeTypeHdl: clientForm.communeTypeHdl,
  397. country: clientForm.country,
  398. countyHdl: clientForm.countyHdl,
  399. voivodeshipHdl: clientForm.voivodeshipHdl,
  400. postCode: clientForm.postCode,
  401. province: clientForm.province,
  402. commune: clientForm.commune,
  403. county: clientForm.county,
  404. district: clientForm.district,
  405. legalFormCode: this.getLegalFormCode(),
  406. contacts: this.phoneContacts.concat(this.mailContacts),
  407. relations: this.relationsData,
  408. comments: this.commentsData,
  409. customerType: CustomerTypes.Types[this.customerType]
  410. }
  411. }
  412. console.log("Create: ", this.clientData);
  413. }
  414.  
  415. createRelation(data: any) {
  416. let relationContact: IContact = data[0]
  417. let relationData: IRelationDictionary = data[1]
  418.  
  419. let newRelation: CrmRestRelationDto = {
  420. name1: relationContact.name.split(" ")[0],
  421. name2: relationContact.name.split(" ")[1],
  422. name3: relationContact.name.split(" ")[2],
  423. relatedCustomerHdl: relationContact.hdl,
  424. relationTypeHdl: relationData.hdl,
  425. typeValue: this.relationsDict.find(elem => elem.hdl === relationData.hdl).displayName,
  426. shortDesc: relationContact.name + relationData.displayName,
  427. };
  428. this.relationsData.push(newRelation)
  429. this.resizeIonScroll();
  430. }
  431.  
  432. createComment(note: string) {
  433. if (note != null && note != '') {
  434. let comment: CrmCommentDto = {
  435. active: true,
  436. content: note,
  437. privateComment: this.privateComment,
  438. differential: this.commentDiff
  439. }
  440. this.commentsData.push(comment);
  441. this.typedNote = '';
  442. this.commentDiff = '';
  443. this.privateComment = false;
  444. this.resizeIonScroll();
  445. }
  446. }
  447.  
  448. deleteComment(comment: CrmCommentDto) {
  449. this.commentsData = this.commentsData.filter(item => {
  450. return item !== comment;
  451. });
  452. this.resizeIonScroll();
  453. }
  454.  
  455. addPhoneNumberContact() {
  456. if (this.serviceRequestClientForm.get('phoneNumber').value != "" && this.serviceRequestClientForm.get('phoneNumber').value != null) {
  457. let phoneNumber: CrmPersonContactDto = {
  458. contactAddress: this.serviceRequestClientForm.get('phoneNumber').value,
  459. name: "Numer telefonu stacjonarnego",
  460. type: 3
  461. };
  462. this.phoneContacts.push(phoneNumber);
  463. this.serviceRequestClientForm.controls['phoneNumber'].setValue('');
  464. }
  465. }
  466.  
  467. addMobilePhoneNumberContact() {
  468. if (this.serviceRequestClientForm.get('mobilePhoneNumber').value != "" && this.serviceRequestClientForm.get('mobilePhoneNumber').value != null) {
  469. let mobilePhoneNumber: CrmPersonContactDto = {
  470. contactAddress: this.serviceRequestClientForm.get('mobilePhoneNumber').value,
  471. name: "Numer telefonu komórkowego",
  472. type: 1
  473. };
  474. this.phoneContacts.push(mobilePhoneNumber);
  475. this.serviceRequestClientForm.controls['mobilePhoneNumber'].setValue('');
  476. }
  477. }
  478.  
  479. addMailContact() {
  480. if (this.serviceRequestClientForm.get('mail').value != "" && this.serviceRequestClientForm.get('mail').value != null) {
  481. let mail: CrmPersonContactDto = {
  482. contactAddress: this.serviceRequestClientForm.get('mail').value,
  483. name: "E-Mail",
  484. type: 6
  485. };
  486. this.mailContacts.push(mail);
  487. this.serviceRequestClientForm.controls['mail'].setValue('');
  488. }
  489. }
  490.  
  491. openModalAddRelation() {
  492. let relationModal = this.modalCtrl.create(AddRelationModalPage);
  493. relationModal.onDidDismiss(data => {
  494. if (!data) return null;
  495. this.createRelation(data);
  496. })
  497. relationModal.present();
  498. }
  499.  
  500.  
  501. getContact(contactHdl: number) {
  502. let relationContactData: ICustomer;
  503. let contactName;
  504. this.clientService.getContact(contactHdl).subscribe(res => {
  505. relationContactData = res.json();
  506. contactName = relationContactData.name1 + relationContactData.name2
  507. })
  508. return contactName
  509. }
  510.  
  511. getRelationsDictionary() {
  512. this.loadingState = true;
  513. this.dictionaryDao.select('24').then(data => {
  514. var dictionary: IDictionaryEntity;
  515. dictionary = data;
  516. this.relationsDict = JSON.parse(dictionary.json);
  517. this.loadingState = false;
  518. this.showRelation();
  519. });
  520. }
  521.  
  522. // openEcaModal(){
  523. // let ecaModal = this.modalCtrl.create(EcaModalPage, {"eca": this.eca, "ecaIndex": this.ecaID });
  524. // ecaModal.onDidDismiss((data:any) => {
  525. // if(data){
  526. // this.eca = data[0];
  527. // this.ecaID = data[1];
  528. // this.serviceRequestClientForm.controls['eca'].setValue(this.eca.description);
  529. // }
  530. // });
  531. // ecaModal.present();
  532. // }
  533.  
  534. // getECADictionary() {
  535. // return new Promise((resolve, reject) => {
  536. // this.loadingState = true;
  537. // this.dictionaryDao.select('37').then(async(data) => {
  538. // var dictionary: IDictionaryEntity;
  539. // dictionary = data;
  540. // this.ecaDict = await JSON.parse(dictionary.json);
  541. // this.loadingState = false;
  542. // resolve();
  543. // }, err => {
  544. // reject(err);
  545. // })
  546. // }).catch(err => { console.log('getECADictionary() err ', err) });
  547. // }
  548.  
  549. async getProvinceList(){
  550. await this.normalizerProvider.getProvinceList().then(resp => this.provinceList = resp.items);
  551. console.warn("PROVINCE LIST", this.provinceList)
  552. }
  553.  
  554. async getCountyList(hdl){
  555. this.clearAfterChangingProvince();
  556. if(this.provinceList.length === 0) await this.getProvinceList();
  557. await this.normalizerProvider.getCountyList(this.provinceList.find(x => x.hdl === Number(hdl)).name).then(resp => this.countyList = resp.items);
  558. console.warn("PROVINCE LIST", this.countyList)
  559. }
  560.  
  561. async getCommuneList(hdl){
  562. this.clearAfterChangingCounty();
  563. if(this.countyList.length > 0) //this.countyList.find(x => x.hdl === Number(hdl)).name
  564. await this.normalizerProvider.getCommuneList(hdl).then(resp => {
  565. this.districtList = [];
  566. this.communeList = [];
  567. resp.items.forEach(commune => {
  568. if(commune.communeType.hdl === 8 || commune.communeType.hdl === 9)
  569. this.districtList.push(commune);
  570. else
  571. this.communeList.push(commune);
  572. });
  573. });
  574. console.warn("PROVINCE LIST", this.districtList, this.communeList)
  575. }
  576.  
  577. clearAfterChangingProvince(){
  578. this.countyList = [];
  579. this.serviceRequestClientForm.controls['county'].setValue("");
  580. this.clearAfterChangingCounty();
  581. }
  582.  
  583. clearAfterChangingCounty(){
  584. this.communeList = [];
  585. this.districtList = [];
  586. this.serviceRequestClientForm.controls['commune'].setValue("");
  587. this.serviceRequestClientForm.controls['district'].setValue("");
  588. }
  589.  
  590. getBusinessTypesDictionary() {
  591. return new Promise((resolve, reject) => {
  592. this.dictionaryDao.select('21').then(async (data) => {
  593. console.log("SLOWNIK business S ", data)
  594. var dictionary: IDictionaryEntity;
  595. dictionary = data;
  596. this.businessTypesDict = await JSON.parse(dictionary.json);
  597. console.log("SLOWNIK business S", this.businessTypesDict)
  598. resolve();
  599. }, err => {
  600. reject(err);
  601. })
  602. }).catch(err => { console.log('getBusinessTypesDictionary() err ', err) });
  603. }
  604.  
  605. getCountriesDictionary() {
  606. return new Promise((resolve, reject) => {
  607. this.loadingState = true;
  608. this.dictionaryDao.select('3').then(async (data) => {
  609. console.log("SLOWNIK DICT COUNTRIES ", data)
  610. var dictionary: IDictionaryEntity;
  611. dictionary = data;
  612. this.countriesDict = await JSON.parse(dictionary.json);
  613. this.loadingState = false;
  614. resolve();
  615. }, err => {
  616. reject(err);
  617. })
  618. }).catch(err => { console.log('getCountriesDictionary() err ', err) });
  619. }
  620.  
  621. getStreetTypesDictionary() {
  622. return new Promise((resolve, reject) => {
  623. this.loadingState = true;
  624. this.dictionaryDao.select('41').then(async (data) => {
  625. console.log("SLOWNIK ulic S ", data)
  626. var dictionary: IDictionaryEntity;
  627. dictionary = data;
  628. this.streetTypesDict = await JSON.parse(dictionary.json);
  629. this.loadingState = false;
  630. resolve();
  631. }, err => {
  632. reject(err);
  633. })
  634. }).catch(err => { console.log('getStreetTypesDictionary() err ', err) });
  635. }
  636.  
  637. showRelation() {
  638. this.relationsData.forEach(element => {
  639. element.typeValue = this.relationsDict.find(elem => elem.hdl === element.relationTypeHdl).displayName;
  640. });
  641. this.loadingState = false;
  642. }
  643.  
  644. showMoreAddressData(){
  645. if(this.moreAddressData)
  646. this.moreAddressData = false;
  647. else
  648. this.moreAddressData = true;
  649. }
  650.  
  651.  
  652.  
  653. editClient(clientForm) {
  654. if (clientForm.name1 != this.clientData.name1) this.clientData.name1 = clientForm.name1;
  655. if (clientForm.name2 != this.clientData.name2) this.clientData.name2 = clientForm.name2;
  656. if (clientForm.street != this.clientData.street) this.clientData.street = clientForm.street;
  657. if (clientForm.houseNo != this.clientData.houseNo) this.clientData.houseNo = clientForm.houseNo;
  658. if (clientForm.cityName != this.clientData.cityName) this.clientData.cityName = clientForm.cityName;
  659. if (clientForm.postCode != this.clientData.postCode) this.clientData.postCode = clientForm.postCode;
  660. if (clientForm.province != this.clientData.province) this.clientData.province = clientForm.province;
  661. if (clientForm.commune != this.clientData.commune) this.clientData.commune = clientForm.commune;
  662. if (clientForm.county != this.clientData.county) this.clientData.county = clientForm.county;
  663. if (clientForm.district != this.clientData.district) this.clientData.district = clientForm.district;
  664. if (clientForm.regon != this.clientData.regon) this.clientData.regon = clientForm.regon;
  665. if (clientForm.vatin != this.clientData.vatin) this.clientData.vatin = clientForm.vatin;
  666. if (clientForm.pesel != this.clientData.pesel) this.clientData.pesel = clientForm.pesel;
  667. if (clientForm.moreCardNo != this.clientData.moreCard) this.clientData.moreCard = clientForm.moreCardNo;
  668. if (clientForm.shortDesc != this.clientData.shortDesc) this.clientData.shortDesc = clientForm.shortDesc;
  669. if (this.gender != this.clientData.gender) this.clientData.gender = this.gender;
  670. if (this.customerType != CustomerTypes.Types[this.clientData.customerType]) this.clientData.customerType = CustomerTypes.Types[this.customerType];
  671.  
  672. this.clientData.contacts = this.phoneContacts.concat(this.mailContacts);
  673. this.clientData.legalFormCode = this.getLegalFormCode();
  674. this.clientData.relations = this.relationsData;
  675. this.clientData.comments = this.commentsData;
  676.  
  677. if (clientForm.businessEntity != this.clientData.businessEntity) this.clientData.businessEntity = clientForm.businessEntity;
  678.  
  679. }
  680.  
  681. async fillClientForm(){
  682. if(this.clientData.legalFormCode === 247){
  683. this.businessClient = true;
  684. if(this.clientData.businessEntity) this.serviceRequestClientForm.controls['businessEntity'].setValue(this.clientData.businessEntity);
  685. }else {
  686. this.businessClient = false;
  687. }
  688.  
  689. this.serviceRequestClientForm.controls['name1'].setValue(this.clientData.name1);
  690. this.serviceRequestClientForm.controls['name2'].setValue(this.clientData.name2);
  691. this.serviceRequestClientForm.controls['regon'].setValue(this.clientData.regon);
  692. this.serviceRequestClientForm.controls['vatin'].setValue(this.clientData.vatin);
  693. this.serviceRequestClientForm.controls['streetName'].setValue(this.clientData.street);
  694. this.serviceRequestClientForm.controls['houseNo'].setValue(this.clientData.houseNo);
  695. this.serviceRequestClientForm.controls['cityName'].setValue(this.clientData.cityName);
  696. this.serviceRequestClientForm.controls['postCode'].setValue(this.clientData.postCode);
  697.  
  698. this.serviceRequestClientForm.controls['province'].setValue(this.clientData.voivodeshipHdl);
  699. this.serviceRequestClientForm.controls['country'].setValue(this.clientData.country);
  700. if(this.clientData.voivodeshipHdl){
  701. await this.getCountyList(this.clientData.voivodeshipHdl);
  702. this.serviceRequestClientForm.controls['county'].setValue(this.clientData.countyHdl);
  703. }
  704. if(this.clientData.countyHdl){
  705. await this.getCommuneList(this.clientData.countyHdl);
  706. this.serviceRequestClientForm.controls['commune'].setValue(this.clientData.communeHdl);
  707. this.serviceRequestClientForm.controls['district'].setValue(this.clientData.district);
  708. }
  709. this.serviceRequestClientForm.controls['pesel'].setValue(this.clientData.pesel);
  710. this.serviceRequestClientForm.controls['moreCardNo'].setValue(this.clientData.moreCard);
  711. this.serviceRequestClientForm.controls['shortDesc'].setValue(this.clientData.shortDesc);
  712. this.serviceRequestClientForm.controls['gender'].setValue(this.clientData.gender);
  713. this.gender = this.serviceRequestClientForm.get('gender').value;
  714. this.customerType = CustomerTypes.Types[this.clientData.customerType];
  715. this.clientData.contacts.forEach(element => {
  716. if (element.type === 6) this.mailContacts.push(element);
  717. if (element.type === 3) this.phoneContacts.push(element);
  718. if (element.type === 1) this.phoneContacts.push(element);
  719. });
  720. console.warn("WYPLUWAN CONTACTY", this.mailContacts, this.phoneContacts)
  721. this.relationsData = this.clientData.relations;
  722. this.commentsData = this.clientData.comments;
  723. this.resizeIonScroll();
  724. }
  725.  
  726. // async setECA(){
  727. // if(this.clientData.eca) {
  728. // await this.getECADictionary();
  729. // this.eca = this.ecaDict.find( elem => elem.hdl === this.clientData.eca);
  730. // this.serviceRequestClientForm.controls['eca'].setValue(this.eca.description);
  731. // console.log("poka mi eca", this.eca, this.ecaID)
  732. // }
  733. // }
  734.  
  735. removeRelation(relation: CrmRestRelationDto, index: any) {
  736. this.relationsData.splice(index, 1);
  737. this.resizeIonScroll();
  738. }
  739.  
  740. removeContact(conatct, index: any) {
  741. this.phoneContacts.splice(index, 1);
  742. this.resizeIonScroll();
  743. }
  744.  
  745. removeMail(conatct, index: any) {
  746. this.mailContacts.splice(index, 1);
  747. this.resizeIonScroll();
  748. }
  749.  
  750. parseDate(dateValue: number, withTime: boolean) {
  751. if (withTime == true) {
  752. return moment(dateValue).lang("pl").format('DD/MM/YYYY HH:mm').toString();
  753. } else return moment(dateValue).lang("pl").format('DD/MM/YYYY').toString();
  754. }
  755.  
  756. getLegalFormCode() {
  757. let legalFormCode;
  758. if (this.businessClient) {
  759. legalFormCode = 247; //firma
  760. }
  761. else {
  762. legalFormCode = 246; //osoba fizyczna
  763. }
  764. return legalFormCode
  765. }
  766.  
  767. checkIfEmpty(toCheck: string) {
  768. if (toCheck != '') {
  769. return false;
  770. } else return true;
  771. }
  772.  
  773. checked_businessClient(val) {
  774. this.businessClient = val;
  775. }
  776.  
  777. checked_privateComment(val) {
  778. this.privateComment = val;
  779. }
  780.  
  781. onChangeGender(val) {
  782. this.gender = val;
  783. }
  784.  
  785. onChangeCommentDiff(val) {
  786. this.commentDiff = val;
  787. }
  788.  
  789. click(num: number) {
  790. for (let i = 0; i < this.clicked.length; i++) {
  791. if (i == num) {
  792. this.clicked[i] = true;
  793. }
  794. else {
  795. this.clicked[i] = false;
  796. }
  797. }
  798. }
  799.  
  800. resizeIonScroll(){
  801. if(this.commentsData){
  802. console.warn("COMENTSDATA : ",this.commentsData)
  803. if(this.commentsData.length == 1){
  804. this.commentsScrollHeight = "115px"
  805. }else if(this.commentsData.length == 2){
  806. this.commentsScrollHeight = "225px"
  807. }else{
  808. this.commentsScrollHeight = "335px"
  809. }
  810. }
  811.  
  812. if(this.casesModel){
  813. console.warn("casesModel : ",this.casesModel)
  814. if(this.casesModel.length == 1){
  815. this.casesScrollHeight = "80px"
  816. }else if(this.casesModel.length == 2){
  817. this.casesScrollHeight = "155px"
  818. }else if(this.casesModel.length == 3){
  819. this.casesScrollHeight = "230px"
  820. }else{
  821. this.casesScrollHeight = "305px"
  822. }
  823. }
  824.  
  825. if(this.relationsData){
  826. console.warn("relationsData : ",this.relationsData)
  827. if(this.relationsData.length == 1){
  828. this.relationsScrollHeight = "80px"
  829. }else if(this.relationsData.length == 2){
  830. this.relationsScrollHeight = "155px"
  831. }else if(this.relationsData.length == 3){
  832. this.relationsScrollHeight = "230px"
  833. }else{
  834. this.relationsScrollHeight = "305px"
  835. }
  836. }
  837. }
  838.  
  839. showErrorToast(message_: any) {
  840. UtilProvider.generateToast(this.toastCtrl, message_, 1).present();
  841. }
  842.  
  843. getTranslations() {
  844.  
  845. this.translate.get('CUSTOMER-DETAILS.DATA-REQUIRED').subscribe(
  846. value => {
  847. this.requiredMsg = value;
  848. });
  849.  
  850. this.translate.get('CUSTOMER-DETAILS.PHONE-NUMBER-OR-EMAIL').subscribe(
  851. value => {
  852. this.requiredContact = value;
  853. });
  854.  
  855. this.translate.get('CUSTOMER-DETAILS.GENDER').subscribe(
  856. value => {
  857. this.requiredGender = value;
  858. });
  859.  
  860. this.translate.get('CUSTOMER-DETAILS.BUSINESS-TYPE').subscribe(
  861. value => {
  862. this.requiredBusinessType = value;
  863. });
  864.  
  865. this.translate.get('CUSTOMER-DETAILS.FIRST-NAME').subscribe(
  866. value => {
  867. this.requiredFirstName = value;
  868. });
  869.  
  870. this.translate.get('CUSTOMER-DETAILS.LAST-NAME').subscribe(
  871. value => {
  872. this.requiredLastName = value;
  873. });
  874.  
  875. this.translate.get('CUSTOMER-DETAILS.CUSTOMER-NAME').subscribe(
  876. value => {
  877. this.requiredName = value;
  878. });
  879.  
  880. this.translate.get('NOTIFICATIONS-LIST.PLEASE-WAIT').subscribe(
  881. value => {
  882. this.loadingMessage = value;
  883. })
  884. this.translate.get('CASES.ERROR.CONTACT_SAVING').subscribe(
  885. value => {
  886. this.saveContactErrorMsg = value;
  887. })
  888. this.translate.get('CUSTOMER-DETAILS.NO-RELATIONS').subscribe(
  889. value => {
  890. this.loadingMessage = value;
  891. })
  892. this.translate.get('CUSTOMER-DETAILS.CUSTOMER-DETAILS-TITLE').subscribe(
  893. value => {
  894. this.translateValue = value;
  895. })
  896. this.translate.get('CUSTOMER-DETAILS.BUSINESS-CUSTOMER').subscribe(
  897. value => {
  898. this.translateValue = value;
  899. })
  900. this.translate.get('CUSTOMER-DETAILS.ADD-CUSTOMER-TITLE').subscribe(
  901. value => {
  902. this.translateValue = value;
  903. })
  904. this.translate.get('CUSTOMER-DETAILS.CUSTOMER-STATUS').subscribe(
  905. value => {
  906. this.translateValue = value;
  907. })
  908. this.translate.get('CUSTOMER-DETAILS.GENDER').subscribe(
  909. value => {
  910. this.translateValue = value;
  911. })
  912. this.translate.get('CUSTOMER-DETAILS.MALE').subscribe(
  913. value => {
  914. this.translateValue = value;
  915. })
  916. this.translate.get('CUSTOMER-DETAILS.FAMALE').subscribe(
  917. value => {
  918. this.translateValue = value;
  919. })
  920. this.translate.get('CUSTOMER-DETAILS.CUSTOMER-NAME').subscribe(
  921. value => {
  922. this.translateValue = value;
  923. })
  924. this.translate.get('CUSTOMER-DETAILS.FIRST-NAME').subscribe(
  925. value => {
  926. this.translateValue = value;
  927. })
  928. this.translate.get('CUSTOMER-DETAILS.LAST-NAME').subscribe(
  929. value => {
  930. this.translateValue = value;
  931. })
  932. this.translate.get('CUSTOMER-DETAILS.PESEL').subscribe(
  933. value => {
  934. this.translateValue = value;
  935. })
  936. this.translate.get('CUSTOMER-DETAILS.REGON').subscribe(
  937. value => {
  938. this.translateValue = value;
  939. })
  940. this.translate.get('CUSTOMER-DETAILS.VATIN').subscribe(
  941. value => {
  942. this.translateValue = value;
  943. })
  944. this.translate.get('CUSTOMER-DETAILS.CONTACT-DETAILS').subscribe(
  945. value => {
  946. this.translateValue = value;
  947. })
  948. this.translate.get('CUSTOMER-DETAILS.STREET').subscribe(
  949. value => {
  950. this.translateValue = value;
  951. })
  952. this.translate.get('CUSTOMER-DETAILS.HOUSE-NUMBER').subscribe(
  953. value => {
  954. this.translateValue = value;
  955. })
  956. this.translate.get('CUSTOMER-DETAILS.CITY').subscribe(
  957. value => {
  958. this.translateValue = value;
  959. })
  960. this.translate.get('CUSTOMER-DETAILS.POST-CODE').subscribe(
  961. value => {
  962. this.translateValue = value;
  963. })
  964. this.translate.get('CUSTOMER-DETAILS.TELEPHONE1').subscribe(
  965. value => {
  966. this.translateValue = value;
  967. })
  968. this.translate.get('CUSTOMER-DETAILS.TELEPHONE2').subscribe(
  969. value => {
  970. this.translateValue = value;
  971. })
  972. this.translate.get('CUSTOMER-DETAILS.EMAIL').subscribe(
  973. value => {
  974. this.translateValue = value;
  975. })
  976. this.translate.get('CUSTOMER-DETAILS.RELATIONS').subscribe(
  977. value => {
  978. this.translateValue = value;
  979. })
  980. }
  981.  
  982. }
  983.  
  984. module CustomerTypes {
  985. export enum Types {
  986. COLD,
  987. TEPID,
  988. HOT
  989. }
  990. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement