Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { AddCasePage } from './../../cases/add-case/add-case';
- import { AcceptSalePage } from './../../sales-opportunities/sales-details/accept-sale/accept-sale';
- import { CasesProvider } from './../../../providers/cases/cases';
- import { LoadingService } from './../../../providers/api/LoadingService';
- import { ErrorProvider } from '../../../providers/error/error';
- import { ICustomer, CrmPersonContactDto, CrmRestRelationDto, CrmCommentDto } from '../../../models/customer.model';
- import { TranslateService } from '@ngx-translate/core';
- import { ClientsProvider } from '../../../providers/clients/clients';
- import { ClientCRMPage } from '../client-crm-page/client-crm-page';
- import { Component } from '@angular/core';
- import { ModalController, Keyboard } from 'ionic-angular';
- import { AddRelationModalPage } from '../add-client/add-relation-modal/add-relation-modal';
- import { ToastController, IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
- import { FormGroup, FormBuilder, Validators } from '@angular/forms';
- import { DictionaryDao } from '../../../providers/db/dictionary-dao';
- import { IDictionaryEntity } from '../../../providers/db/dictionary-entity';
- import { IRelationDictionary } from '../../../models/dictionaries.model';
- import { IContact } from '../../../models/contact.model';
- import * as moment from 'moment';
- import { UtilProvider } from '../../../providers/util';
- import { NormalizerProvider } from '../../../providers/normalizer/normalizer';
- import { IPostCode, IStreet, IVoivodeship, ICounty, ICommune } from '../../../models/normalizer.model';
- import { NormalizerModalPage } from '../../normalizer-modal/normalizer-modal';
- @IonicPage()
- @Component({
- selector: 'add-client',
- templateUrl: 'add-client.html',
- })
- export class AddClientPage {
- hdl: any;
- gender: string;
- // eca: any;
- // ecaID: number;
- commentDiff: string = '';
- businessClient: boolean;
- privateComment: boolean;
- isNewClient: boolean;
- customerType: number = 0;
- required: boolean = true;
- timeout: any = undefined;
- moreAddressData: boolean = false;
- clientData: ICustomer;
- relationsData: CrmRestRelationDto[] = [];
- commentsData: CrmCommentDto[] = [];
- provinceList: Array<IVoivodeship> = [];
- countyList: Array<ICounty> = [];
- tempCommuneList: Array<ICommune> = [];
- communeList: Array<ICommune> = [];
- districtList: Array<ICommune> = [];
- mailContacts: CrmPersonContactDto[] = [];
- phoneContacts: CrmPersonContactDto[] = [];
- commentsScrollHeight: any = '0px';
- casesScrollHeight: any = '0px';
- vehiclesScrollHeight: any = '0px';
- relationsScrollHeight: any = '0px';
- relationsDict: Array<IRelationDictionary>;
- //ecaDict: Array<CrmEcaDto>;
- //slownik: Array<CrmEcaDto>;
- businessTypesDict: any;
- countriesDict: any;
- streetTypesDict: any;
- normalizerMode: boolean;
- serviceRequestClientForm: FormGroup;
- serviceRequestRelationsForm: FormGroup;
- clicked: Array<boolean>;
- translateValue: string;
- loadingMessage: any;
- loadingState: boolean;
- typedNote: string;
- saveContactErrorMsg: string;
- requiredMsg: string;
- requiredFirstName: string;
- requiredLastName: string;
- requiredName: string;
- requiredSex: string;
- requiredContact: string;
- requiredBusinessType: string;
- requiredGender: string;
- casesModel: any;
- constructor(
- public keyboard: Keyboard,
- public dictionaryDao: DictionaryDao,
- public navCtrl: NavController,
- public navParams: NavParams,
- public modalCtrl: ModalController,
- public clientService: ClientsProvider,
- public loadingCtrl: LoadingService,
- public alertCtrl: AlertController,
- private _fb: FormBuilder,
- public translate: TranslateService,
- public toastCtrl: ToastController,
- public errorProvider: ErrorProvider,
- public casesProvider: CasesProvider,
- public normalizerProvider: NormalizerProvider)
- {
- this.getProvinceList();
- this.hdl = this.navParams.get("hdl");
- this.clientData = this.navParams.get("clientData");
- console.warn("this.cliendata", this.clientData)
- this.businessClient = false;
- this.privateComment = false;
- this.isNewClient = true;
- this.normalizerMode = false;
- this.clicked = [false, true, false, false, false, false];
- //this.getECADictionary();
- this.keyboard.hasFocusedTextInput()
- this.getBusinessTypesDictionary();
- this.getCountriesDictionary();
- this.getStreetTypesDictionary();
- this.getTranslations();
- this.getRelationsDictionary();
- this.serviceRequestClientForm = this._fb.group({
- gender: [''],
- name1: ['', Validators.compose([Validators.required, Validators.minLength(2)])],
- name2: [''],
- vatin: ['', Validators.pattern('^[0-9]{10}$')],
- regon: ['', Validators.pattern('^[0-9]{9}$')],
- businessEntity: [''],
- pesel: ['', Validators.pattern('^[0-9]{11}$')],
- shortDesc: [''],
- moreCardNo: [''],
- streetName: [''],
- streetHdl: [''],
- houseNo: [''],
- cityName: [''],
- cityHdl: [''],
- postCode: ['', Validators.pattern('[0-9]{2}-[0-9]{3}')],
- province: [''],
- county: [''],
- commune: [''],
- communeType: [''],
- district: [''],
- country: [''],
- streetType: [''],
- phoneNumber: ['', Validators.pattern('^[0-9]{9}$')],
- mobilePhoneNumber: ['', Validators.pattern('^[0-9]{9}$')],
- mail: ['', Validators.pattern('^$|^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(?:[a-zA-Z]{2})$')],
- });
- if (typeof this.clientData != 'undefined') {
- this.isNewClient = false;
- this.fillClientForm();
- }
- this.serviceRequestClientForm.get('moreCardNo').disable();
- }
- // ionViewDidLoad() {
- // this.getCaseList();
- // }
- ionViewDidEnter() {
- this.getCaseList();
- }
- getCaseList() {
- this.casesProvider.getCaseList("", "ALL", 20, 0, "", "", this.hdl)
- .subscribe(data => {
- this.casesModel = data;
- console.log("------------------TASKS: ", data);
- this.resizeIonScroll();
- // console.log("CASES LIST: ", this.casesModel);
- }, (err) => {
- // this.showErrorDataOnPage(err);
- })
- }
- addCase() {
- this.navCtrl.push(AcceptSalePage, { customer: this.clientData });
- }
- getCasePage(elem){
- this.navCtrl.push(AddCasePage, { hdl: elem.hdl, 'customer-hdl': elem.customerHdl })
- }
- searchByPostCode(){
- let searchByPostCodeModal = this.modalCtrl.create(NormalizerModalPage);
- searchByPostCodeModal.onDidDismiss(async(data: IPostCode) => {
- if(!data) return null;
- if(data.custom) {
- this.serviceRequestClientForm.controls['cityName'].setValue(data.city.name);
- this.serviceRequestClientForm.controls['postCode'].setValue(data.name);
- }
- else {
- this.normalizerMode = true;
- this.serviceRequestClientForm.controls['cityName'].setValue(data.city.name);
- this.serviceRequestClientForm.controls['cityHdl'].setValue(data.city.hdl);
- this.serviceRequestClientForm.controls['postCode'].setValue(data.name);
- if(data.communeType)
- this.serviceRequestClientForm.controls['communeType'].setValue(data.communeType.hdl);
- if(data.voivodeship && data.voivodeship.name){
- await this.normalizerProvider.getCountyList(data.voivodeship.name).then(resp => this.countyList = resp.items);
- this.serviceRequestClientForm.controls['province'].setValue(data.voivodeship.hdl);
- }
- if(data.county && data.county.name){
- await this.normalizerProvider.getCommuneList(data.county.name).then(resp => {
- this.districtList = [];
- this.communeList = [];
- resp.items.forEach(commune => {
- if(commune.communeType.hdl === 8 || commune.communeType.hdl === 9)
- this.districtList.push(commune);
- else
- this.communeList.push(commune);
- });
- });
- this.serviceRequestClientForm.controls['county'].setValue(data.county.hdl);
- }
- if(data.commune && data.commune.name)
- this.serviceRequestClientForm.controls['commune'].setValue(data.commune.hdl);
- }
- })
- searchByPostCodeModal.present();
- }
- searchByStreet(){
- if(this.serviceRequestClientForm.get('cityName').value && this.serviceRequestClientForm.get('postCode').value){
- let searchByStreetModal = this.modalCtrl.create(NormalizerModalPage, { cityName: this.serviceRequestClientForm.get('cityName').value, postCode: this.serviceRequestClientForm.get('postCode').value });
- searchByStreetModal.onDidDismiss((data: IStreet) => {
- if(!data) return null;
- this.normalizerMode = true;
- this.serviceRequestClientForm.controls['streetHdl'].setValue(data.hdl);
- if(data.namePrefix)
- this.serviceRequestClientForm.controls['streetName'].setValue(data.namePrefix + " " + data.name);
- else
- this.serviceRequestClientForm.controls['streetName'].setValue(data.name);
- if(data.streetType)
- this.serviceRequestClientForm.controls['streetType'].setValue(data.streetType);
- })
- searchByStreetModal.present();
- }
- }
- saveClient() {
- if (this.generalValidation()) {
- let loading = this.loadingCtrl.create({
- content: "Trwa zapis kontaktu."
- });
- loading.present();
- let clientForm = this.getClientForm();
- if (this.isNewClient) {
- this.createClient(clientForm);
- }
- else {
- this.editClient(clientForm);
- }
- console.log("TO WYSYLAM:", this.clientData)
- this.clientService.saveClient(this.clientData).subscribe(response => {
- console.log("TO ODBIERAM:", response)
- loading.dismiss();
- this.navCtrl.push(ClientCRMPage, { hdl: response.hdl }).then(() => {
- if (this.isNewClient) {
- const startIndex = this.navCtrl.getActive().index - 1;
- this.navCtrl.remove(startIndex, 1);
- }
- else {
- const startIndex = this.navCtrl.getActive().index - 2;
- this.navCtrl.remove(startIndex, 2);
- }
- });
- }, error => {
- loading.dismiss();
- this.showErrorToast(this.saveContactErrorMsg + ': ' + error);
- });
- }
- }
- getClientForm(){
- let clientForm = {
- name1: this.serviceRequestClientForm.get('name1').value,
- name2: this.serviceRequestClientForm.get('name2').value,
- gender: this.serviceRequestClientForm.get('gender').value,
- street: this.serviceRequestClientForm.get('streetName').value,
- streetHdl: this.serviceRequestClientForm.get('streetHdl').value,
- streetType: this.serviceRequestClientForm.get('streetType').value,
- houseNo: this.serviceRequestClientForm.get('houseNo').value,
- cityName: this.serviceRequestClientForm.get('cityName').value,
- cityHdl: this.serviceRequestClientForm.get('cityHdl').value,
- postCode: this.serviceRequestClientForm.get('postCode').value,
- moreCardNo: this.serviceRequestClientForm.get('moreCardNo').value,
- voivodeshipHdl: this.serviceRequestClientForm.get('province').value,
- communeHdl: this.serviceRequestClientForm.get('commune').value,
- communeTypeHdl: this.serviceRequestClientForm.get('communeType').value,
- countyHdl: this.serviceRequestClientForm.get('county').value,
- district: this.serviceRequestClientForm.get('district').value,
- country: this.serviceRequestClientForm.get('country').value,
- regon: this.serviceRequestClientForm.get('regon').value,
- vatin: this.serviceRequestClientForm.get('vatin').value,
- pesel: this.serviceRequestClientForm.get('pesel').value,
- shortDesc: this.serviceRequestClientForm.get('shortDesc').value,
- businessEntity: this.serviceRequestClientForm.get('businessEntity').value,
- };
- return clientForm;
- }
- generalValidation() {
- let required = [];
- if (this.businessClient) {
- if (this.serviceRequestClientForm.get('name1').value === null || this.serviceRequestClientForm.get('name1').value === '') required.push(this.requiredName)
- if (this.serviceRequestClientForm.get('businessEntity').value === null || this.serviceRequestClientForm.get('businessEntity').value === '') required.push(this.requiredBusinessType)
- }
- else {
- if (this.serviceRequestClientForm.get('name1').value === null || this.serviceRequestClientForm.get('name1').value === '') required.push(this.requiredLastName)
- if (this.serviceRequestClientForm.get('name2').value === null || this.serviceRequestClientForm.get('name2').value === '') required.push(this.requiredFirstName)
- if ((this.gender === null && this.gender === '' || typeof this.gender === 'undefined')) required.push(this.requiredGender)
- }
- if (this.phoneContacts.concat(this.mailContacts).length === 0) required.push(this.requiredContact);
- if (required.length === 0)
- return true;
- else{
- this.showErrorToast(this.requiredMsg + required.join(', '))
- return false;
- }
- }
- createClient(clientForm) {
- if (this.businessClient) {
- this.clientData = {
- name1: clientForm.name1,
- shortDesc: clientForm.shortDesc,
- street: clientForm.street,
- streetHdl: clientForm.streetHdl,
- streetType: clientForm.streetType,
- houseNo: clientForm.houseNo,
- cityName: clientForm.cityName,
- cityHdl: clientForm.cityHdl,
- communeHdl: clientForm.communeHdl,
- communeTypeHdl: clientForm.communeTypeHdl,
- country: clientForm.country,
- countyHdl: clientForm.countyHdl,
- voivodeshipHdl: clientForm.voivodeshipHdl,
- postCode: clientForm.postCode,
- regon: clientForm.regon,
- vatin: clientForm.vatin,
- businessEntity: clientForm.businessEntity,
- legalFormCode: this.getLegalFormCode(),
- contacts: this.phoneContacts.concat(this.mailContacts),
- relations: this.relationsData,
- comments: this.commentsData,
- customerType: CustomerTypes.Types[this.customerType]
- }
- }
- else {
- this.clientData = {
- name1: clientForm.name1,
- name2: clientForm.name2,
- shortDesc: clientForm.shortDesc,
- pesel: clientForm.pesel,
- gender: clientForm.gender,
- vatin: clientForm.vatin,
- moreCard: clientForm.moreCardNo,
- street: clientForm.street,
- streetHdl: clientForm.streetHdl,
- streetType: clientForm.streetType,
- houseNo: clientForm.houseNo,
- cityName: clientForm.cityName,
- cityHdl: clientForm.cityHdl,
- communeHdl: clientForm.communeHdl,
- communeTypeHdl: clientForm.communeTypeHdl,
- country: clientForm.country,
- countyHdl: clientForm.countyHdl,
- voivodeshipHdl: clientForm.voivodeshipHdl,
- postCode: clientForm.postCode,
- province: clientForm.province,
- commune: clientForm.commune,
- county: clientForm.county,
- district: clientForm.district,
- legalFormCode: this.getLegalFormCode(),
- contacts: this.phoneContacts.concat(this.mailContacts),
- relations: this.relationsData,
- comments: this.commentsData,
- customerType: CustomerTypes.Types[this.customerType]
- }
- }
- console.log("Create: ", this.clientData);
- }
- createRelation(data: any) {
- let relationContact: IContact = data[0]
- let relationData: IRelationDictionary = data[1]
- let newRelation: CrmRestRelationDto = {
- name1: relationContact.name.split(" ")[0],
- name2: relationContact.name.split(" ")[1],
- name3: relationContact.name.split(" ")[2],
- relatedCustomerHdl: relationContact.hdl,
- relationTypeHdl: relationData.hdl,
- typeValue: this.relationsDict.find(elem => elem.hdl === relationData.hdl).displayName,
- shortDesc: relationContact.name + relationData.displayName,
- };
- this.relationsData.push(newRelation)
- this.resizeIonScroll();
- }
- createComment(note: string) {
- if (note != null && note != '') {
- let comment: CrmCommentDto = {
- active: true,
- content: note,
- privateComment: this.privateComment,
- differential: this.commentDiff
- }
- this.commentsData.push(comment);
- this.typedNote = '';
- this.commentDiff = '';
- this.privateComment = false;
- this.resizeIonScroll();
- }
- }
- deleteComment(comment: CrmCommentDto) {
- this.commentsData = this.commentsData.filter(item => {
- return item !== comment;
- });
- this.resizeIonScroll();
- }
- addPhoneNumberContact() {
- if (this.serviceRequestClientForm.get('phoneNumber').value != "" && this.serviceRequestClientForm.get('phoneNumber').value != null) {
- let phoneNumber: CrmPersonContactDto = {
- contactAddress: this.serviceRequestClientForm.get('phoneNumber').value,
- name: "Numer telefonu stacjonarnego",
- type: 3
- };
- this.phoneContacts.push(phoneNumber);
- this.serviceRequestClientForm.controls['phoneNumber'].setValue('');
- }
- }
- addMobilePhoneNumberContact() {
- if (this.serviceRequestClientForm.get('mobilePhoneNumber').value != "" && this.serviceRequestClientForm.get('mobilePhoneNumber').value != null) {
- let mobilePhoneNumber: CrmPersonContactDto = {
- contactAddress: this.serviceRequestClientForm.get('mobilePhoneNumber').value,
- name: "Numer telefonu komórkowego",
- type: 1
- };
- this.phoneContacts.push(mobilePhoneNumber);
- this.serviceRequestClientForm.controls['mobilePhoneNumber'].setValue('');
- }
- }
- addMailContact() {
- if (this.serviceRequestClientForm.get('mail').value != "" && this.serviceRequestClientForm.get('mail').value != null) {
- let mail: CrmPersonContactDto = {
- contactAddress: this.serviceRequestClientForm.get('mail').value,
- name: "E-Mail",
- type: 6
- };
- this.mailContacts.push(mail);
- this.serviceRequestClientForm.controls['mail'].setValue('');
- }
- }
- openModalAddRelation() {
- let relationModal = this.modalCtrl.create(AddRelationModalPage);
- relationModal.onDidDismiss(data => {
- if (!data) return null;
- this.createRelation(data);
- })
- relationModal.present();
- }
- getContact(contactHdl: number) {
- let relationContactData: ICustomer;
- let contactName;
- this.clientService.getContact(contactHdl).subscribe(res => {
- relationContactData = res.json();
- contactName = relationContactData.name1 + relationContactData.name2
- })
- return contactName
- }
- getRelationsDictionary() {
- this.loadingState = true;
- this.dictionaryDao.select('24').then(data => {
- var dictionary: IDictionaryEntity;
- dictionary = data;
- this.relationsDict = JSON.parse(dictionary.json);
- this.loadingState = false;
- this.showRelation();
- });
- }
- // openEcaModal(){
- // let ecaModal = this.modalCtrl.create(EcaModalPage, {"eca": this.eca, "ecaIndex": this.ecaID });
- // ecaModal.onDidDismiss((data:any) => {
- // if(data){
- // this.eca = data[0];
- // this.ecaID = data[1];
- // this.serviceRequestClientForm.controls['eca'].setValue(this.eca.description);
- // }
- // });
- // ecaModal.present();
- // }
- // getECADictionary() {
- // return new Promise((resolve, reject) => {
- // this.loadingState = true;
- // this.dictionaryDao.select('37').then(async(data) => {
- // var dictionary: IDictionaryEntity;
- // dictionary = data;
- // this.ecaDict = await JSON.parse(dictionary.json);
- // this.loadingState = false;
- // resolve();
- // }, err => {
- // reject(err);
- // })
- // }).catch(err => { console.log('getECADictionary() err ', err) });
- // }
- async getProvinceList(){
- await this.normalizerProvider.getProvinceList().then(resp => this.provinceList = resp.items);
- console.warn("PROVINCE LIST", this.provinceList)
- }
- async getCountyList(hdl){
- this.clearAfterChangingProvince();
- if(this.provinceList.length === 0) await this.getProvinceList();
- await this.normalizerProvider.getCountyList(this.provinceList.find(x => x.hdl === Number(hdl)).name).then(resp => this.countyList = resp.items);
- console.warn("PROVINCE LIST", this.countyList)
- }
- async getCommuneList(hdl){
- this.clearAfterChangingCounty();
- if(this.countyList.length > 0) //this.countyList.find(x => x.hdl === Number(hdl)).name
- await this.normalizerProvider.getCommuneList(hdl).then(resp => {
- this.districtList = [];
- this.communeList = [];
- resp.items.forEach(commune => {
- if(commune.communeType.hdl === 8 || commune.communeType.hdl === 9)
- this.districtList.push(commune);
- else
- this.communeList.push(commune);
- });
- });
- console.warn("PROVINCE LIST", this.districtList, this.communeList)
- }
- clearAfterChangingProvince(){
- this.countyList = [];
- this.serviceRequestClientForm.controls['county'].setValue("");
- this.clearAfterChangingCounty();
- }
- clearAfterChangingCounty(){
- this.communeList = [];
- this.districtList = [];
- this.serviceRequestClientForm.controls['commune'].setValue("");
- this.serviceRequestClientForm.controls['district'].setValue("");
- }
- getBusinessTypesDictionary() {
- return new Promise((resolve, reject) => {
- this.dictionaryDao.select('21').then(async (data) => {
- console.log("SLOWNIK business S ", data)
- var dictionary: IDictionaryEntity;
- dictionary = data;
- this.businessTypesDict = await JSON.parse(dictionary.json);
- console.log("SLOWNIK business S", this.businessTypesDict)
- resolve();
- }, err => {
- reject(err);
- })
- }).catch(err => { console.log('getBusinessTypesDictionary() err ', err) });
- }
- getCountriesDictionary() {
- return new Promise((resolve, reject) => {
- this.loadingState = true;
- this.dictionaryDao.select('3').then(async (data) => {
- console.log("SLOWNIK DICT COUNTRIES ", data)
- var dictionary: IDictionaryEntity;
- dictionary = data;
- this.countriesDict = await JSON.parse(dictionary.json);
- this.loadingState = false;
- resolve();
- }, err => {
- reject(err);
- })
- }).catch(err => { console.log('getCountriesDictionary() err ', err) });
- }
- getStreetTypesDictionary() {
- return new Promise((resolve, reject) => {
- this.loadingState = true;
- this.dictionaryDao.select('41').then(async (data) => {
- console.log("SLOWNIK ulic S ", data)
- var dictionary: IDictionaryEntity;
- dictionary = data;
- this.streetTypesDict = await JSON.parse(dictionary.json);
- this.loadingState = false;
- resolve();
- }, err => {
- reject(err);
- })
- }).catch(err => { console.log('getStreetTypesDictionary() err ', err) });
- }
- showRelation() {
- this.relationsData.forEach(element => {
- element.typeValue = this.relationsDict.find(elem => elem.hdl === element.relationTypeHdl).displayName;
- });
- this.loadingState = false;
- }
- showMoreAddressData(){
- if(this.moreAddressData)
- this.moreAddressData = false;
- else
- this.moreAddressData = true;
- }
- editClient(clientForm) {
- if (clientForm.name1 != this.clientData.name1) this.clientData.name1 = clientForm.name1;
- if (clientForm.name2 != this.clientData.name2) this.clientData.name2 = clientForm.name2;
- if (clientForm.street != this.clientData.street) this.clientData.street = clientForm.street;
- if (clientForm.houseNo != this.clientData.houseNo) this.clientData.houseNo = clientForm.houseNo;
- if (clientForm.cityName != this.clientData.cityName) this.clientData.cityName = clientForm.cityName;
- if (clientForm.postCode != this.clientData.postCode) this.clientData.postCode = clientForm.postCode;
- if (clientForm.province != this.clientData.province) this.clientData.province = clientForm.province;
- if (clientForm.commune != this.clientData.commune) this.clientData.commune = clientForm.commune;
- if (clientForm.county != this.clientData.county) this.clientData.county = clientForm.county;
- if (clientForm.district != this.clientData.district) this.clientData.district = clientForm.district;
- if (clientForm.regon != this.clientData.regon) this.clientData.regon = clientForm.regon;
- if (clientForm.vatin != this.clientData.vatin) this.clientData.vatin = clientForm.vatin;
- if (clientForm.pesel != this.clientData.pesel) this.clientData.pesel = clientForm.pesel;
- if (clientForm.moreCardNo != this.clientData.moreCard) this.clientData.moreCard = clientForm.moreCardNo;
- if (clientForm.shortDesc != this.clientData.shortDesc) this.clientData.shortDesc = clientForm.shortDesc;
- if (this.gender != this.clientData.gender) this.clientData.gender = this.gender;
- if (this.customerType != CustomerTypes.Types[this.clientData.customerType]) this.clientData.customerType = CustomerTypes.Types[this.customerType];
- this.clientData.contacts = this.phoneContacts.concat(this.mailContacts);
- this.clientData.legalFormCode = this.getLegalFormCode();
- this.clientData.relations = this.relationsData;
- this.clientData.comments = this.commentsData;
- if (clientForm.businessEntity != this.clientData.businessEntity) this.clientData.businessEntity = clientForm.businessEntity;
- }
- async fillClientForm(){
- if(this.clientData.legalFormCode === 247){
- this.businessClient = true;
- if(this.clientData.businessEntity) this.serviceRequestClientForm.controls['businessEntity'].setValue(this.clientData.businessEntity);
- }else {
- this.businessClient = false;
- }
- this.serviceRequestClientForm.controls['name1'].setValue(this.clientData.name1);
- this.serviceRequestClientForm.controls['name2'].setValue(this.clientData.name2);
- this.serviceRequestClientForm.controls['regon'].setValue(this.clientData.regon);
- this.serviceRequestClientForm.controls['vatin'].setValue(this.clientData.vatin);
- this.serviceRequestClientForm.controls['streetName'].setValue(this.clientData.street);
- this.serviceRequestClientForm.controls['houseNo'].setValue(this.clientData.houseNo);
- this.serviceRequestClientForm.controls['cityName'].setValue(this.clientData.cityName);
- this.serviceRequestClientForm.controls['postCode'].setValue(this.clientData.postCode);
- this.serviceRequestClientForm.controls['province'].setValue(this.clientData.voivodeshipHdl);
- this.serviceRequestClientForm.controls['country'].setValue(this.clientData.country);
- if(this.clientData.voivodeshipHdl){
- await this.getCountyList(this.clientData.voivodeshipHdl);
- this.serviceRequestClientForm.controls['county'].setValue(this.clientData.countyHdl);
- }
- if(this.clientData.countyHdl){
- await this.getCommuneList(this.clientData.countyHdl);
- this.serviceRequestClientForm.controls['commune'].setValue(this.clientData.communeHdl);
- this.serviceRequestClientForm.controls['district'].setValue(this.clientData.district);
- }
- this.serviceRequestClientForm.controls['pesel'].setValue(this.clientData.pesel);
- this.serviceRequestClientForm.controls['moreCardNo'].setValue(this.clientData.moreCard);
- this.serviceRequestClientForm.controls['shortDesc'].setValue(this.clientData.shortDesc);
- this.serviceRequestClientForm.controls['gender'].setValue(this.clientData.gender);
- this.gender = this.serviceRequestClientForm.get('gender').value;
- this.customerType = CustomerTypes.Types[this.clientData.customerType];
- this.clientData.contacts.forEach(element => {
- if (element.type === 6) this.mailContacts.push(element);
- if (element.type === 3) this.phoneContacts.push(element);
- if (element.type === 1) this.phoneContacts.push(element);
- });
- console.warn("WYPLUWAN CONTACTY", this.mailContacts, this.phoneContacts)
- this.relationsData = this.clientData.relations;
- this.commentsData = this.clientData.comments;
- this.resizeIonScroll();
- }
- // async setECA(){
- // if(this.clientData.eca) {
- // await this.getECADictionary();
- // this.eca = this.ecaDict.find( elem => elem.hdl === this.clientData.eca);
- // this.serviceRequestClientForm.controls['eca'].setValue(this.eca.description);
- // console.log("poka mi eca", this.eca, this.ecaID)
- // }
- // }
- removeRelation(relation: CrmRestRelationDto, index: any) {
- this.relationsData.splice(index, 1);
- this.resizeIonScroll();
- }
- removeContact(conatct, index: any) {
- this.phoneContacts.splice(index, 1);
- this.resizeIonScroll();
- }
- removeMail(conatct, index: any) {
- this.mailContacts.splice(index, 1);
- this.resizeIonScroll();
- }
- parseDate(dateValue: number, withTime: boolean) {
- if (withTime == true) {
- return moment(dateValue).lang("pl").format('DD/MM/YYYY HH:mm').toString();
- } else return moment(dateValue).lang("pl").format('DD/MM/YYYY').toString();
- }
- getLegalFormCode() {
- let legalFormCode;
- if (this.businessClient) {
- legalFormCode = 247; //firma
- }
- else {
- legalFormCode = 246; //osoba fizyczna
- }
- return legalFormCode
- }
- checkIfEmpty(toCheck: string) {
- if (toCheck != '') {
- return false;
- } else return true;
- }
- checked_businessClient(val) {
- this.businessClient = val;
- }
- checked_privateComment(val) {
- this.privateComment = val;
- }
- onChangeGender(val) {
- this.gender = val;
- }
- onChangeCommentDiff(val) {
- this.commentDiff = val;
- }
- click(num: number) {
- for (let i = 0; i < this.clicked.length; i++) {
- if (i == num) {
- this.clicked[i] = true;
- }
- else {
- this.clicked[i] = false;
- }
- }
- }
- resizeIonScroll(){
- if(this.commentsData){
- console.warn("COMENTSDATA : ",this.commentsData)
- if(this.commentsData.length == 1){
- this.commentsScrollHeight = "115px"
- }else if(this.commentsData.length == 2){
- this.commentsScrollHeight = "225px"
- }else{
- this.commentsScrollHeight = "335px"
- }
- }
- if(this.casesModel){
- console.warn("casesModel : ",this.casesModel)
- if(this.casesModel.length == 1){
- this.casesScrollHeight = "80px"
- }else if(this.casesModel.length == 2){
- this.casesScrollHeight = "155px"
- }else if(this.casesModel.length == 3){
- this.casesScrollHeight = "230px"
- }else{
- this.casesScrollHeight = "305px"
- }
- }
- if(this.relationsData){
- console.warn("relationsData : ",this.relationsData)
- if(this.relationsData.length == 1){
- this.relationsScrollHeight = "80px"
- }else if(this.relationsData.length == 2){
- this.relationsScrollHeight = "155px"
- }else if(this.relationsData.length == 3){
- this.relationsScrollHeight = "230px"
- }else{
- this.relationsScrollHeight = "305px"
- }
- }
- }
- showErrorToast(message_: any) {
- UtilProvider.generateToast(this.toastCtrl, message_, 1).present();
- }
- getTranslations() {
- this.translate.get('CUSTOMER-DETAILS.DATA-REQUIRED').subscribe(
- value => {
- this.requiredMsg = value;
- });
- this.translate.get('CUSTOMER-DETAILS.PHONE-NUMBER-OR-EMAIL').subscribe(
- value => {
- this.requiredContact = value;
- });
- this.translate.get('CUSTOMER-DETAILS.GENDER').subscribe(
- value => {
- this.requiredGender = value;
- });
- this.translate.get('CUSTOMER-DETAILS.BUSINESS-TYPE').subscribe(
- value => {
- this.requiredBusinessType = value;
- });
- this.translate.get('CUSTOMER-DETAILS.FIRST-NAME').subscribe(
- value => {
- this.requiredFirstName = value;
- });
- this.translate.get('CUSTOMER-DETAILS.LAST-NAME').subscribe(
- value => {
- this.requiredLastName = value;
- });
- this.translate.get('CUSTOMER-DETAILS.CUSTOMER-NAME').subscribe(
- value => {
- this.requiredName = value;
- });
- this.translate.get('NOTIFICATIONS-LIST.PLEASE-WAIT').subscribe(
- value => {
- this.loadingMessage = value;
- })
- this.translate.get('CASES.ERROR.CONTACT_SAVING').subscribe(
- value => {
- this.saveContactErrorMsg = value;
- })
- this.translate.get('CUSTOMER-DETAILS.NO-RELATIONS').subscribe(
- value => {
- this.loadingMessage = value;
- })
- this.translate.get('CUSTOMER-DETAILS.CUSTOMER-DETAILS-TITLE').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.BUSINESS-CUSTOMER').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.ADD-CUSTOMER-TITLE').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.CUSTOMER-STATUS').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.GENDER').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.MALE').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.FAMALE').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.CUSTOMER-NAME').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.FIRST-NAME').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.LAST-NAME').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.PESEL').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.REGON').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.VATIN').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.CONTACT-DETAILS').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.STREET').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.HOUSE-NUMBER').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.CITY').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.POST-CODE').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.TELEPHONE1').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.TELEPHONE2').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.EMAIL').subscribe(
- value => {
- this.translateValue = value;
- })
- this.translate.get('CUSTOMER-DETAILS.RELATIONS').subscribe(
- value => {
- this.translateValue = value;
- })
- }
- }
- module CustomerTypes {
- export enum Types {
- COLD,
- TEPID,
- HOT
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement