· 6 years ago · Mar 18, 2020, 05:38 AM
1import { Component,OnInit } from '@angular/core';
2import { UserService } from '../user.service';
3import { AlertController, ModalController, ActionSheetController, Events } from '@ionic/angular';
4import { ActivatedRoute, Router } from '@angular/router';
5import { TextremarkPage } from '../textremark/textremark.page';
6import { Geolocation } from '@ionic-native/geolocation/ngx';
7import { ViewcartPage } from '../viewcart/viewcart.page';
8import 'rxjs/add/operator/filter';
9
10@Component({
11 selector: 'app-items',
12 templateUrl: './items.page.html',
13 styleUrls: ['./items.page.scss'],
14 providers: [ViewcartPage]
15})
16export class ItemsPage implements OnInit{
17 remark;allItemsctgList=[];toggled=false;amt=0;srch='';allItemsctgList2=[];viewcart='NO';
18 category=[];srchlength=1;
19 myinfo=false;alert;
20 id1: string;id2: string;id3: string;id4: string;id5: string;id6: string;id7: string;
21 complogin;hideshowmenu=true;showgroup=false;
22 location:any;distancekm;distancem;time;longitude='';latitude='';showsteward='';
23 userid='';iminelse=true;neg_value=[];rate_stk=[];grouplist=[];ctg=[];grp='';
24 ctglen;calledurl='';
25 constructor(public user:UserService , public alertctrl:AlertController, public router: ActivatedRoute, public navrouter: Router, public modalCtrl:ModalController,public geolocation: Geolocation, public viewcartpg:ViewcartPage,
26 public actionSheetController:ActionSheetController, public events:Events) {
27 if(localStorage.getItem("pgtype") == 'DINEIN')
28 {
29 this.router.params.subscribe(params=>{
30 this.id1 = params.id1; //key
31 this.id2 = params.id2; //resttype
32 this.id3 = params.id3; //tableno
33 this.id4 = params.id4; //steward (GUEST ORDER)
34 this.id5 = params.id5; //remarks
35 if(params.hasOwnProperty("id8"))
36 {
37 this.user.fgroup =params.id8; //group (back from view cart screen)
38 }
39 else{
40 this.user.fgroup =params.id6; //group
41 }
42
43 });
44 }
45 else if(localStorage.getItem("pgtype") == 'TAKEOUT')
46 {
47 this.router.params.subscribe(params=>{
48 this.user.compkey = params.id1; //key
49 this.user.RESTTYPE = params.id2; //REST
50 this.user.city = params.id3; //city
51 this.user.type = params.id4; //type
52 this.user.qrremark = params.id5; //remark
53 });
54 }
55
56
57 if(this.user.authkeymode == 'Y')
58 {
59 console.log(localStorage.getItem("authkey"));
60 if(localStorage.getItem("authkey") == null)
61 {
62 this.random();
63 }
64 }
65
66 console.log(localStorage.getItem("complogin"));
67 if((localStorage.getItem("complogin") !=undefined && localStorage.getItem("complogin") == 'NO' && localStorage.getItem("complogin") != null) || localStorage.getItem("pgtype") == 'DINEIN')
68 {
69 localStorage.setItem("complogin", "NO");
70 this.complogin = 'NO';
71 }
72 else
73 {
74 localStorage.setItem("complogin", "YES");
75 this.complogin = 'YES';
76 }
77 }
78
79 random() {
80 var no = new Date().getTime();
81 no = Math.floor(no/16);
82 //var vno = 'QORDER'+no+'@#@';
83 var vno = no.toString();
84 localStorage.setItem("authkey", vno);
85 localStorage.setItem("authstatus", 'Y');
86 }
87
88 ngOnInit()
89 {
90 if(localStorage.getItem("Changepwd") == 'YES')
91 {
92 this.setpassword();
93 }
94 setTimeout(()=>{
95 this.calledurl =='once';
96 this.url();
97 }, 100);
98 }
99
100 ionViewDidEnter()
101 {
102 this.iminelse = true;
103 console.log("called ionViewDidEnter");
104
105 this.viewcart = 'NO'; //not open mutiple times
106 console.log(this.user.allItemsctgList2, "++", this.user.clearaftersave, this.iminelse);
107 if(this.user.clearaftersave == 'YES')
108 {
109 console.log(" inside if++++++++++++++");
110 this.iminelse= false;
111 this.srch ='';
112 this.allItemsctgList2 = JSON.parse(JSON.stringify(this.user.allItemsctgList));
113 this.user.clearaftersave ='NO';
114 for(let j = 0;j <this.allItemsctgList2.length;j++)
115 {
116 for(let k = 0;k <this.allItemsctgList2[j]["ITEMS"].length;k++)
117 {
118 if(this.allItemsctgList2[j]["ITEMS"][k].hasOwnProperty("countr"))
119 {
120 this.allItemsctgList2[j]["ITEMS"][k]["countr"] = 0;
121 }
122 if(this.allItemsctgList2[j]["ITEMS"][k].hasOwnProperty("QNTY"))
123 {
124 this.allItemsctgList2[j]["ITEMS"][k]["QNTY"] = 0;
125 }
126 if(this.allItemsctgList2[j]["ITEMS"][k].hasOwnProperty("shwcnt"))
127 {
128 this.allItemsctgList2[j]["ITEMS"][k]["shwcnt"] = false;
129 }
130 }
131 if(this.allItemsctgList2.length-1 == j)
132 {
133 this.allItemsctgList = JSON.parse(JSON.stringify(this.allItemsctgList2));
134 }
135 }
136 }
137 else
138 {
139 this.srch ='';
140
141 //this.changear();
142 }
143 console.log(this.user.arrlen);
144 if(this.user.arrlen == 0)
145 {
146 this.user.amt = 0;
147 }
148
149 if(this.user.comingfrom == 'company' && this.calledurl != 'once')
150 {
151 setTimeout(()=>{
152 this.url();
153 }, 100);
154 this.user.comingfrom = '';
155 this.calledurl ='';
156 }
157
158 }
159
160 changear()
161 {
162
163 // for(let i=0; i<this.allItemsctgList.length;i++)
164 // {
165 // for(let j = 0;j <this.user.show_product.length;j++)
166 // {
167 // if(this.allItemsctgList[i].CODE == this.user.show_product[j].CODE)
168 // {
169 // this.allItemsctgList[i].countr = this.user.show_product[j].countr;
170 // }
171 // }
172 // if(this.allItemsctgList.length-1 == i)
173 // {
174 // return this.allItemsctgList;
175 // }
176 // }
177
178 // console.log(this.iminelse);
179 // this.iminelse = true;
180
181 //this.allItemsctgList = JSON.parse(JSON.stringify(this.user.allItemsctgList2));
182
183
184 //console.log(this.allItemsctgList);
185 //return this.allItemsctgList;
186 }
187 url()
188 {
189
190 this.user.allItemsctgList = [];
191 this.allItemsctgList2 = [];
192 this.allItemsctgList = [];
193 this.ctg = [];
194 //if(this.id1 != '**')
195 if(localStorage.getItem("pgtype") == 'DINEIN')
196 {
197 this.complogin = 'NO';
198 this.user.g_key = this.id1;
199 this.user.RESTTYPE = this.id2;
200 if(this.user.RESTTYPE == 'REST')
201 {
202 this.user.tableno = this.id3;
203 this.user.steward = this.id4;
204 }
205 this.remark = this.id5;
206
207 this.user.p_compdata(this.user.g_key).subscribe(data=>{
208 this.user.compdata = data;
209 if(data[0].hasOwnProperty("CONNSTR")){
210 this.user.connstr = btoa(data[0].CONNSTR);
211 this.user.connstrlen = data[0].CONNSTR.length;
212 }
213 if(data[0].hasOwnProperty("CONNUSR")){
214 this.user.connusr = btoa(data[0].CONNUSR);
215 this.user.connusrlen = data[0].CONNUSR.length;
216 }
217 if(data[0].hasOwnProperty("TIMEZONE")){
218 this.user.timezone = data[0]["TIMEZONE"] === undefined ? '' : (data[0]["TIMEZONE"] === null ? '' : data[0]["TIMEZONE"]);
219 this.productlist();
220 //this.callotherservices();
221 }
222 if(data[0].hasOwnProperty("'GUESTORDER'") && this.user.RESTTYPE == 'REST')
223 {
224 this.user.steward = data[0]["'GUESTORDER'"];
225 }
226 if(data[0].hasOwnProperty("COMPANY"))
227 {
228 this.user.company = data[0]["COMPANY"];
229 }
230 if(data[0].hasOwnProperty("COMPIMG"))
231 {
232 this.user.compimg = 'https://qorder.in/pwaqorder/api/'+data[0]["COMPIMG"];
233 }
234 if(data[0].hasOwnProperty("ONLINE_SEQ"))
235 {
236 this.user.online_seq = data[0]["ONLINE_SEQ"];
237 }
238 if(data[0].hasOwnProperty("SHORTCOMPNM"))
239 {
240 this.user._shortcomp = data[0]["SHORTCOMPNM"];
241 }
242 if(data[0].hasOwnProperty("QRREMARK"))
243 {
244 this.user.qrremark = data[0]["QRREMARK"];
245
246 if(this.remark == null)
247 {
248 this.remark = data[0]["QRREMARK"];
249 this.remark = 'MYREMARK';
250 }
251 }
252 if(data[0].hasOwnProperty("DINEKOTPWD"))
253 {
254 this.user.dinekotpwd = data[0]['DINEKOTPWD'];
255 }
256 if(data[0].hasOwnProperty("COMPLAT"))
257 {
258 this.user.complat = data[0]["COMPLAT"];
259 }
260 if(data[0].hasOwnProperty("COMPLONG"))
261 {
262 this.user.complong = data[0]["COMPLONG"];
263 }
264 if(data[0].hasOwnProperty("ALLOWEDMETERS"))
265 {
266 this.user.allowedmeters = data[0]["ALLOWEDMETERS"];
267 }
268 if(data[0].hasOwnProperty("LATLONGMODE"))
269 {
270 this.user.latlongmode = data[0]["LATLONGMODE"];
271 }
272 if(data[0].hasOwnProperty("AUTHKEYMODE"))
273 {
274 this.user.authkeymode = data[0]["AUTHKEYMODE"];
275 }
276 if(data[0].hasOwnProperty("MENULARSMALL"))
277 {
278 this.user.menularsmall = data[0]["MENULARSMALL"];
279 }
280 if(data[0].hasOwnProperty("MENUHIDESHOW"))
281 {
282 this.user.menuhideshow = data[0]["MENUHIDESHOW"];
283 }
284 if(data[0].hasOwnProperty("RPAYKEY"))
285 {
286 this.user.razorpaykey = data[0]["RPAYKEY"];
287 }else
288 {
289 this.user.razorpaykey = "";
290 }
291 if(this.user.menuhideshow == 'Y')
292 {
293 this.hideshowmenu = true;
294 }
295 else{
296 this.hideshowmenu = false;
297 }
298 this.user._user='QORDER';
299 let api = 'foxp.php';
300 let param = '';
301 this.user.p_serv(api,param).subscribe(data=>{
302 // console.log(data);
303
304 this.user._foxp = data[0];
305 });
306
307 if(this.user.RESTTYPE == 'REST')
308 {
309 let param = '&TABLENO='+this.user.tableno;
310 this.user.p_typegentbl(param).subscribe(data=>{
311 if(data.hasOwnProperty("STATUS"))
312 {
313 if(data.STATUS == 'error')
314 {
315 this.user.showToast(data.MESSAGE);
316 }
317 }
318 });
319 }
320
321
322 //VALID -CHECK (1)
323 //LOGIN - SAVE (2)
324 console.log(this.remark.substr(0, 2));
325 if(this.remark.substr(0, 2) == '*1')
326 {
327 this.popup('*1'); //save(login)
328 }
329 else if(this.remark.substr(0, 2) == '*2')
330 {
331 this.popup('*2'); //check(valid)
332 }
333 else if(this.remark.substr(0, 1) == '~')
334 {
335 this.popup('~'); //save(login)
336 }
337 else{
338 this.checkpwd('Vaild');
339 }
340
341 });
342 }
343 else if(localStorage.getItem("pgtype") == 'TAKEOUT')
344 {
345
346 this.user.g_key = localStorage.getItem("ckey");
347 if(this.user.connstrlen == 0)
348 {
349 console.log("get company data key wise");
350 this.user.p_compdata(this.user.g_key).subscribe(data=>{
351 //this.user.compdata = data[0];
352
353 localStorage.setItem('company',data[0]["COMPANY"]);
354 if(data[0].hasOwnProperty("TIMEZONE")){
355 this.user.timezone = data[0]["TIMEZONE"] === undefined ? '' : (data[0]["TIMEZONE"] === null ? '' : data[0]["TIMEZONE"]);
356 }
357 if(data[0].hasOwnProperty("CONNSTR")){
358 this.user.connstr = btoa(data[0].CONNSTR);
359 this.user.connstrlen = data[0].CONNSTR.length;
360 }
361 if(data[0].hasOwnProperty("CONNUSR")){
362 this.user.connusr = btoa(data[0].CONNUSR);
363 this.user.connusrlen = data[0].CONNUSR.length;
364 }
365 if(data[0].hasOwnProperty("SYNCSTR")){
366 this.user.syncstr = data[0]["SYNCSTR"];
367 }
368 if(data[0].hasOwnProperty("SYNCUSR"))
369 {
370 this.user.syncusr = data[0]["SYNCUSR"];
371 }
372 if(data[0].hasOwnProperty("PRINTTO"))
373 {
374 this.user.printto = data[0]["PRINTTO"];
375 }
376 if(data[0].hasOwnProperty("TOTLALLENC"))
377 {
378 this.user.connstrlen = data[0]["TOTALLENC"];
379 }
380 if(data[0].hasOwnProperty("TOTALLENU"))
381 {
382 this.user.connusrlen = data[0]["TOTALLENU"];
383 }
384 if(data[0].hasOwnProperty("COMPANY"))
385 {
386 this.user.company = data[0]["COMPANY"];
387 }
388 if(data[0].hasOwnProperty("COMPIMG"))
389 {
390 this.user.compimg = 'https://qorder.in/pwaqorder/api/'+data[0]["COMPIMG"];
391 }
392 if(data[0].hasOwnProperty("SHOWBILLS"))
393 {
394 this.user.showbills = data[0]["SHOWBILLS"];
395 }
396 if(data[0].hasOwnProperty("PRINT_SERVICE"))
397 {
398 this.user.print_service = data[0]["PRINT_SERVICE"];
399 }
400 if(data[0].hasOwnProperty("PRINT_HSN"))
401 {
402 this.user.print_hsn = data[0]["PRINT_HSN"];
403 }
404 if(data[0].hasOwnProperty("KOT_GRP_CTG"))
405 {
406 this.user.kot_grp_ctg = data[0]["KOT_GRP_CTG"];
407 }
408 if(data[0].hasOwnProperty("PRINT_GST"))
409 {
410 this.user.print_gst = data[0]["PRINT_GST"];
411 }
412 if(data[0].hasOwnProperty("MRPCHK"))
413 {
414 this.user.mrpchk = data[0]["MRPCHK"];
415 }
416 if(data[0].hasOwnProperty("PRINT_ALOWED"))
417 {
418 this.user.print_allowed = data[0]["PRINT_ALLOWED"];
419 }
420 if(data[0].hasOwnProperty("PRINT_KOT_OFFCOPY"))
421 {
422 this.user.print_kot_offcopy = data[0]["PRINT_KOT_OFFCOPY"];
423 }
424 if(data[0].hasOwnProperty("ONLINE_SEQ"))
425 {
426 this.user.online_seq = data[0]["ONLINE_SEQ"];
427 }
428 if(data[0].hasOwnProperty("COMPLAT"))
429 {
430 this.user.complat = data[0]["COMPLAT"];
431 }
432 if(data[0].hasOwnProperty("COMPLONG"))
433 {
434 this.user.complong = data[0]["COMPLONG"];
435 }
436 if(data[0].hasOwnProperty("ALLOWEDMETERS"))
437 {
438 this.user.allowedmeters = data[0]["ALLOWEDMETERS"];
439 }
440 if(data[0].hasOwnProperty("LATLONGMODE"))
441 {
442 this.user.latlongmode = data[0]["LATLONGMODE"];
443 }
444 if(data[0].hasOwnProperty("AUTHKEYMODE"))
445 {
446 this.user.authkeymode = data[0]["AUTHKEYMODE"];
447 }
448 if(data[0].hasOwnProperty("MENULARSMALL"))
449 {
450 this.user.menularsmall = data[0]["MENULARSMALL"];
451 }
452 if(data[0].hasOwnProperty("MENUHIDESHOW"))
453 {
454 this.user.menuhideshow = data[0]["MENUHIDESHOW"];
455 }
456 if(data[0].hasOwnProperty("RPAYKEY"))
457 {
458 this.user.razorpaykey = data[0]["RPAYKEY"];
459 }else
460 {
461 this.user.razorpaykey = "";
462 }
463
464 if(this.user.menuhideshow == 'Y')
465 {
466 this.hideshowmenu = true;
467 }
468 else{
469 this.hideshowmenu = false;
470 }
471 setTimeout(()=>{
472 //foxp
473 let api = 'foxp.php';
474 let param = '';
475 this.user.p_serv(api,param).subscribe(data=>{//console.log(data);
476
477 this.user._foxp = data[0];
478 });
479 //history
480 var srchTerm=this.user._custname+'#'+this.user._user;
481 this.user.usernm = srchTerm;
482 if(this.user.adminuser == true)
483 {
484 var aduser='Y';
485 }
486 else
487 {
488 var aduser='';
489 }
490 this.user.k_view_s(this.user.online_seq,'N','2',srchTerm,aduser,'YES').subscribe(viewdata => {
491 var viewinv = viewdata.BILLS;
492 this.user.viewhistory=viewinv;
493 });
494 this.productlist();
495 this.user.RESTTYPE ='REST';
496 },100);
497 });
498 }
499 else{
500 this.productlist();
501 this. user.RESTTYPE = 'REST';
502 }
503 }
504 }
505
506 productlist()
507 {
508 this.user.showLoading1('Fetching Menu Items..');
509 this.user.k_item_ctg('','0','G').subscribe(srchdata => {
510 if(srchdata.hasOwnProperty("STATUS")) {
511 this.user._loading1.dismiss();
512 if(srchdata.STATUS.toLowerCase() == "error" || srchdata.STATUS.toLowerCase() == "notice"){
513 if(srchdata.hasOwnProperty("MESSAGE"))
514 this.user.showToast(srchdata.MESSAGE);
515 else
516 this.user.showToast("Some error occurred in service.");
517 }
518 }else{
519 this.user.allItemsctgList = JSON.parse(JSON.stringify(srchdata));
520 this.allItemsctgList2 = JSON.parse(JSON.stringify(srchdata));
521 this.allItemsctgList = JSON.parse(JSON.stringify(srchdata));
522 this.ctg = JSON.parse(JSON.stringify(srchdata));
523 this.ctglen = this.ctg.length-1;
524 this.user.arrlen='';
525 this.user.amt =0;
526 this.user.show_product=[];
527 // console.log(this.allItemsctgList);
528 this.user._loading1.dismiss();
529
530 }},
531 err => {
532 this.user._loading1.dismiss();
533 var msg = 'Some error occurred in service';
534 this.user.showToast(msg);
535 });
536
537 this.user.getgroup().subscribe(data=>{
538 console.log(data);
539 this.grouplist = data[0]["GRP"];
540 });
541 }
542 home()
543 {
544 //this.navCtrl.push('CompanyPage');
545 this.navrouter.navigate(["/company"]);
546 }
547 countitem(list,i)
548 {
549 console.log(list.countr, 'countr line 131');
550 if(list.countr == undefined)
551 {
552 list.countr = 1;
553 list.QNTY = 1;
554 console.log(list.NAME, list.RATE,this.user.amt);
555 }
556 else
557 {
558 list.countr=Number(list.countr)+1;
559 list.QNTY = list.countr;
560 if(list.SHOWDEAL == 'Y')
561 {
562 if(list.CF1 != null && (list.countr >= list.CF1 && list.countr < list.CF2 && list.countr < list.CF3))
563 {
564 list.RATE = list.RATE1;
565 }
566 else if(list.CF2 != null && (list.countr >= list.CF2 && list.countr > list.CF1 && list.countr < list.CF3))
567 {
568 list.RATE = list.RATE2;
569 }
570 else if(list.CF3 != null && (list.countr >= list.CF3 && list.countr > list.CF1 && list.countr > list.CF2))
571 {
572 list.RATE = list.RATE3;
573 }
574 }
575 else{
576 list.RATE = list.MYRATE;
577 console.log(list.RATE, 'line159');
578 }
579 }
580 list.shwcnt=true;
581
582 /** calstock work starts here */
583 this.check_stock(list);
584 /** calstock work ends here */
585
586 if(list.countr > 0)
587 {
588 if(this.user.show_product.length == 0)
589 {
590 this.user.show_product.push(list);
591 }
592 else
593 {
594 let kindex = this.user.show_product.indexOf(list);
595 if(kindex===-1)
596 this.user.show_product.push(list);
597 }
598 }
599 else if(list.countr <= 0)
600 {
601 this.delcount(list,i);
602 }
603 console.log(this.user.show_product.length, '+++');
604 for(let j = 0;j <this.user.show_product.length;j++)
605 {
606 if(j==0)
607 {
608 this.user.amt = 0;
609 }
610 this.user.show_product[j].AMT = Number(this.user.show_product[j].RATE) * Number(this.user.show_product[j].QNTY);
611 this.user.amt=this.user.amt+(Number(this.user.show_product[j].RATE) * Number(this.user.show_product[j].QNTY));
612
613 this.user.amt = Number(parseFloat(this.user.amt.toString()).toFixed(2));
614 }
615
616 this.user.arrlen=this.user.show_product.length;
617 //console.log(this.user.show_product, this.allItemsctgList);
618 }
619 delcount(list,i)
620 {
621 if(list.countr>0)
622 {
623 list.countr=Number(list.countr-1);
624 list.QNTY = list.countr;
625
626 for(let j = 0;j <this.user.show_product.length;j++)
627 {
628 if(this.user.show_product[j].QNTY == 0)
629 {
630 this.user.show_product.splice(j, 1);
631 }
632 }
633 }
634 if(list.SHOWDEAL == 'Y')
635 {
636 if(list.CF1 != null && (list.countr >= list.CF1 && list.countr < list.CF2 && list.countr < list.CF3))
637 {
638 list.RATE = list.RATE1;
639 }
640 else if(list.CF2 != null && (list.countr >= list.CF2 && list.countr > list.CF1 && list.countr < list.CF3))
641 {
642 list.RATE = list.RATE2;
643 }
644 else if(list.CF3 != null && (list.countr >= list.CF3 && list.countr > list.CF1 && list.countr > list.CF2))
645 {
646 list.RATE = list.RATE3;
647 }
648 }
649 else{
650 list.RATE = list.MYRATE;
651 }
652 // this.user.amt=this.user.amt-list.RATE;
653 // this.user.amt = Number(parseFloat(this.user.amt.toString()).toFixed(2));
654 // list.AMT = Number(list.RATE) * Number(list.QNTY);
655
656 if(this.user.show_product.length == 0)
657 {
658 this.user.amt =0;
659 }
660 for(let j = 0;j <this.user.show_product.length;j++)
661 {
662 if(j==0)
663 {
664 this.user.amt = 0;
665 }
666 this.user.show_product[j].AMT = Number(this.user.show_product[j].RATE) * Number(this.user.show_product[j].QNTY);
667 this.user.amt=this.user.amt+(Number(this.user.show_product[j].RATE) * Number(this.user.show_product[j].QNTY));
668
669 this.user.amt = Number(parseFloat(this.user.amt.toString()).toFixed(2));
670 }
671
672 if(list.countr==0)
673 {
674 list.shwcnt=false;
675 for(let j = 0;j <this.user.show_product.length;j++)
676 {
677 if(this.user.show_product[j].QNTY == 0)
678 {
679 this.user.show_product.splice(j, 1);
680 }
681 }
682 list.REMARK = '';
683 }
684 this.user.arrlen=this.user.show_product.length;
685
686 }
687
688 togglesearch()
689 {
690 this.toggled = this.toggled ? false: true;
691
692 }
693 cancelsearch()
694 {
695 this.srch = '';
696 this.allItemsctgList = JSON.parse(JSON.stringify(this.allItemsctgList2));
697 }
698 search(srch)
699 {
700 for(let i = 0; i<this.allItemsctgList2.length; i++)
701 {
702 if(this.allItemsctgList[i] != undefined)
703 {
704 //console.log(this.allItemsctgList2, srch);
705 this.allItemsctgList[i]["ITEMS"] = this.allItemsctgList2[i]["ITEMS"].filter(item=>{
706 if(item != null)
707 {
708 return item.NAME.toLowerCase().indexOf(this.srch.toLowerCase()) > -1;
709 }
710 });
711 }
712 else{
713 if(this.srch != null && this.srch != undefined && this.srch.length == 0)
714 {
715 this.allItemsctgList = JSON.parse(JSON.stringify(this.allItemsctgList2));
716 }
717 return;
718 }
719 }
720 }
721 showcart()
722 {
723 // this.user.allItemsctgList2 = JSON.parse(JSON.stringify(this.allItemsctgList));
724 // alert("inside showcart");
725 console.log(this.user.show_product, "before viewcart");
726 if(this.viewcart == 'NO')
727 {
728 if(localStorage.getItem("pgtype") == 'DINEIN')
729 this.navrouter.navigate(["/viewcart", {id1:this.id1, id2:this.id2, id3:this.id3,id4:this.id4,id5:this.id5, id6:this.distancem, id7:this.distancekm, id8:this.user.fgroup}]);
730 else if(localStorage.getItem("pgtype") == 'TAKEOUT')
731 this.navrouter.navigate(["/viewcart", {id1:this.user.compkey, id2:'REST', id3:this.user.city, id4:this.user.type,id5:this.user.qrremark, id6:this.distancem, id7:this.distancekm }]);
732 }
733 this.viewcart = 'YES';
734 }
735
736 gotocat(id)
737 {
738 const itemToScrollTo = document.getElementById(id);
739 // null check to ensure that the element actually exists
740 if (itemToScrollTo) {
741 itemToScrollTo.scrollIntoView(true);
742 }
743 }
744
745 popup(val)
746 {
747 //VALID -CHECK
748 //LOGIN - SAVE
749
750 var text;
751 var placeholder;
752 var title;
753
754 if(val == '*1' || val == '~')
755 {
756 text = 'Valid';
757 title = '';
758 }
759 if(val == '*2')
760 {
761 text = 'Login';
762 title = 'Login ';
763 }
764
765
766 if(val == '*1')
767 {
768 this.alert = this.alertctrl.create({
769 message: 'Enter '+this.remark.substr(2),
770 inputs: [
771 {
772 name: 'username',
773 placeholder: this.remark.substr(2)
774 }
775 // ,
776 // {
777 // name: 'address',
778 // placeholder: 'Address'
779 // }
780 ],
781 buttons: [
782 {
783 text: text,
784 role: 'ok',
785 handler: (data:any) => {
786 console.log(data);
787 if(data.username == '')
788 {
789 this.alert.setMessage('<span class="alert_msg">Enter '+this.remark.substr(2)+'</span>');
790 return false;
791 }
792 else if(data.address == '')
793 {
794 this.alert.setMessage('<span class="alert_msg">Enter Address</span>');
795 return false;
796 }
797 else{
798
799 let param = '&cardno='+data.username+'&shortcomp='+this.user._shortcomp;
800 this.user.p_validuser(param).subscribe(datac=>{
801 if(datac.hasOwnProperty('status'))
802 {
803 if(datac.status == 'Success')
804 {
805 this.user._custname = datac.CUSTNAME;
806 this.user._user = datac.EXTVAR;
807 this.user.cusaddress = data.address;
808 this.user.showToast('Validate successfully.');
809 this.alert.dismiss();
810 }
811 else{
812 this.alert.setMessage('<span class="alert_msg">'+datac.message+'</span>');
813 }
814 }
815 else
816 {
817 this.alert.setMessage('<span class="alert_msg">'+datac.message+'</span>');
818 }
819 });
820 return false;
821 }
822
823 }
824 }
825 ]
826 //,enableBackdropDismiss: false
827 });
828
829 this.alert.present();
830 this.alert.onDidDismiss(()=>{
831 console.log('dismiss', this.user.dinekotpwd);
832 this.checkpwd(text);
833 })
834 }
835
836 if(val == '*2')
837 {
838 this.alert = this.alertctrl.create({
839 message: 'Enter '+this.remark.substr(2)+' & password',
840 inputs: [
841 {
842 name: 'username',
843 placeholder: this.remark.substr(2)
844 },
845 {
846 name: 'password',
847 placeholder: 'PASSWORD',
848 type: 'password'
849 }
850 ],
851 buttons: [
852 {
853 text: text,
854 handler: (data) => {
855 if(data.username == '')
856 {
857 this.alert.setMessage('<span class="alert_msg">Enter '+this.remark.substr(2)+'</span>');
858 return false;
859 }
860 else if(data.password == '')
861 {
862 this.alert.setMessage('<span class="alert_msg">Enter Password</span>');
863 return false;
864 }
865 else{
866
867 let param = '&cardno='+data.username+'&pwd='+data.password+'&shortcomp='+this.user._shortcomp;
868 this.user.p_validuserpwd(param).subscribe(datac=>{
869 if(datac.hasOwnProperty('status'))
870 {
871 if(datac.status == 'Success')
872 {
873 this.user._custname = datac.CUSTNAME;
874 this.user._user = datac.EXTVAR;
875 this.user.showToast('Validate successfully.');
876 this.alert.dismiss();
877 }
878 else{
879 this.alert.setMessage('<span class="alert_msg">'+datac.message+'</span>');
880 return false;
881 }
882
883 }
884 });
885 return false;
886 }
887 }
888 }
889 ]
890 //,enableBackdropDismiss: false
891 });
892
893 this.alert.present();
894 this.alert.onDidDismiss(()=>{
895 console.log('dismiss', this.user.dinekotpwd);
896 this.checkpwd(text);
897 })
898 }
899
900 if(val == '~')
901 {
902 this.alert = this.alertctrl.create({
903 message:'Enter '+this.remark.substr(1),
904 inputs: [
905 {
906 name: 'password',
907 placeholder: this.remark.substr(1)
908 }
909 ],
910 buttons: [
911 {
912 text: text,
913 handler: (data) => {
914 if(data.username == '')
915 {
916 this.alert.setMessage('<span class="alert_msg">Enter Password</span>');
917 return false;
918 }
919 else{
920 this.user._user = data.username;
921 this.user._custname = 'QORDER';
922 this.alert.dismiss();
923 }
924 return false;
925 }
926 }
927 ]
928 //,enableBackdropDismiss: false
929 });
930
931 this.alert.present();
932 this.alert.onDidDismiss(()=>{
933 console.log('dismiss', this.user.dinekotpwd);
934 this.checkpwd(text);
935 })
936 }
937
938 }
939 checkpwd(text)
940 {
941 if(this.user.dinekotpwd != null)
942 {
943 this.alert = this.alertctrl.create({
944 message:'Enter Password',
945 inputs: [
946 {
947 name: 'password',
948 type: 'password',
949 placeholder: 'password'
950 }
951 ],
952 buttons: [
953 {
954 text: text,
955 handler: (data) => {
956 if(data.password == '')
957 {
958 this.alert.setMessage('<span class="alert_msg">Enter Password</span>');
959 return false;
960 }
961 else if(data.password.toUpperCase() == this.user.dinekotpwd.toUpperCase())
962 {
963 return true;
964 }
965 else if(data.password.toUpperCase() != this.user.dinekotpwd.toUpperCase()){
966 this.alert.setMessage('<span class="alert_msg">Invalid Password</span>');
967 return false;
968 }
969
970 return false;
971 }
972 }
973 ]
974 //,enableBackdropDismiss: false
975 });
976
977 this.alert.present();
978 }
979 }
980 showinfo()
981 {
982 this.myinfo = this.myinfo ? false : true;
983 }
984
985 async servpop(data)
986 {
987 let param = '&cardno='+data.username+'&shortcomp='+this.user._shortcomp;
988 await this.user.p_validuser(param).subscribe(datac=>{
989 if(datac.hasOwnProperty('status'))
990 {
991 if(datac.status == 'Success')
992 {
993 this.user._custname = datac.CUSTNAME;
994 this.user._user = datac.EXTVAR;
995 this.user.showToast('Validate successfully.');
996 }
997 else{
998 console.log("++");
999 this.alert.setMessage('<span class="alert_msg">Enter Mobile No.</span>');
1000
1001 return false;
1002
1003 }
1004
1005 }
1006 else
1007 {
1008 return false;
1009
1010
1011 }
1012 });
1013 }
1014
1015 getcount(list, index)
1016 {
1017 console.log(this.iminelse,list.countr);
1018 if(this.iminelse == false)
1019 {
1020 list.countr = Number(list.countr);
1021 list.QNTY = list.countr;
1022 console.log(list.countr, list.CF1, list.CF2, list.CF3);
1023 if(list.SHOWDEAL == 'Y')
1024 {
1025 if(list.CF1 != null && (list.countr >= list.CF1 && list.countr < list.CF2 && list.countr < list.CF3))
1026 {
1027 list.RATE = list.RATE1;
1028 console.log(list.RATE);
1029 }
1030 else if(list.CF2 != null && (list.countr >= list.CF2 && list.countr > list.CF1 && list.countr < list.CF3))
1031 {
1032 list.RATE = list.RATE2;
1033 console.log(list.RATE);
1034 }
1035 else if(list.CF3 != null && (list.countr >= list.CF3 && list.countr > list.CF1 && list.countr > list.CF2))
1036 {
1037 list.RATE = list.RATE3;
1038 console.log(list.RATE);
1039 }
1040 }
1041 else{
1042 list.RATE = list.MYRATE;
1043 }
1044 list.shwcnt=true;
1045
1046
1047 /** calstock work starts here */
1048 this.check_stock(list);
1049 /** calstock work ends here */
1050
1051
1052 // this.user.amt=Number(this.user.amt)+Number(list.RATE);
1053 // list.AMT = Number(list.RATE) * Number(list.QNTY);
1054 // console.log(list.RATE,"rate");
1055
1056 if(list.countr > 0)
1057 {
1058 if(this.user.show_product.length == 0)
1059 {
1060 this.user.show_product.push(list);
1061 }
1062 else
1063 {
1064 let kindex = this.user.show_product.indexOf(list);
1065 if(kindex===-1)
1066 this.user.show_product.push(list);
1067 }
1068
1069 console.log(this.user.show_product);
1070 setTimeout(()=>{
1071 for(let j = 0;j <this.user.show_product.length;j++)
1072 {
1073 if(j==0)
1074 {
1075 this.user.amt = 0;
1076 }
1077
1078 // if(list.CODE == this.user.show_product[j].CODE)
1079 // {
1080 // this.user.show_product[j]['countr'] = list.countr;
1081 // this.user.show_product[j]['QNTY'] = list.QNTY;
1082 // }
1083 // else
1084 // {
1085 // this.user.show_product.push(list);
1086 // }
1087
1088 this.user.show_product[j].AMT = Number(this.user.show_product[j].RATE) * Number(this.user.show_product[j].QNTY);
1089 this.user.amt=this.user.amt+(Number(this.user.show_product[j].RATE) * Number(this.user.show_product[j].QNTY));
1090
1091 this.user.amt = Number(parseFloat(this.user.amt.toString()).toFixed(2));
1092 if(this.user.show_product.length-1 == j)
1093 {
1094 this.user.arrlen=this.user.show_product.length;
1095 }
1096 }
1097 });
1098 }
1099 else if(list.countr <= 0)
1100 {
1101 this.delcount(list,index);
1102 }
1103
1104 }
1105
1106 }
1107 checkcount(list,index)
1108 {
1109 console.log(this.user.show_product);
1110 if(list.countr == 0)
1111 {
1112 this.delcount(list,index);
1113 }
1114 }
1115 setpassword()
1116 {
1117 let param = '&extvar='+localStorage.getItem("loyaltycardno")+'&password='+localStorage.getItem("password")+'&type=login';
1118 this.user.changepassword(param).subscribe(data=>{
1119 if(data.hasOwnProperty("STATUS"))
1120 {
1121 if(data.STATUS == 'success')
1122 {
1123 console.log(data.MESSAGE);
1124 localStorage.setItem("Changepwd", "NO");
1125 }
1126 else
1127 {
1128 this.user.showToast(data.MESSAGE);
1129 }
1130 }
1131 });
1132 }
1133
1134 checkfoucs(list)
1135 {
1136 console.log(list.REMARK);
1137 this.modalCtrl.create({
1138 component: TextremarkPage,
1139 componentProps: {
1140 itemname: list.NAME,
1141 remark: list.REMARK
1142 }}).then(
1143 modal=>{
1144 modal.present();
1145 modal.onDidDismiss().then(data=>{
1146 console.log(data.data);
1147 if(data.data!=undefined)
1148 {
1149 list.REMARK = data.data;
1150 }
1151 })
1152 });
1153 }
1154 orderstatus()
1155 {
1156 this.navrouter.navigate(['/orderstatus']);
1157 }
1158 getLocation() {
1159 console.log("called geolocation");
1160 if(this.user.latlongmode == 'Y')
1161 {
1162 // alert("inside if latlongmode");
1163 this.geolocation.getCurrentPosition({
1164 enableHighAccuracy: true }).then((resp) => {
1165 console.log('Response => ', resp);
1166 // alert(JSON.stringify(resp));
1167 this.location = resp.coords;
1168 this.latitude = this.location.latitude;
1169 this.longitude = this.location.longitude;
1170 this.user.mylat = this.latitude;
1171 this.user.mylong = this.longitude;
1172 // alert("inside geolocation");
1173 this.diffkm(this.location);
1174 }).catch((error) => {
1175 // alert(JSON.stringify(error.message));
1176 // alert(error.message);
1177 // return;
1178 console.log('Error getting location', error);
1179 console.log(error.code);
1180 if(error.code == 1)
1181 {
1182 this.user.callingwaiter=false;
1183 // let alert = this.alertctrl.create({
1184 // message: 'Please enable location services',
1185
1186 // });
1187 }
1188 });
1189
1190 //For Live location update
1191 // this.geolocation.watchPosition().subscribe((data: any) => {
1192
1193 // this.location = data.coords;
1194 // console.log("CALLING");
1195
1196 // this.diffkm(this.location);
1197 // });
1198 }
1199 else if(this.user.authkeymode == 'Y')
1200 {
1201
1202 //this.showcart();
1203 }
1204 else
1205 {
1206 this.viewcart = 'NO';
1207 if(this.user.callingwaiter == true)
1208 {
1209 this.viewcartpg.waitercalling();
1210 }
1211 else{
1212 this.showcart();
1213 }
1214
1215 }
1216
1217 }
1218
1219 diffkm(location)
1220 {
1221 // alert("inside DIFFkm");
1222 console.log(Math.PI, this.user.complat, this.user.complong);
1223 if ((this.user.complat == location.latitude) && (this.user.complong == location.longitude)) {
1224 // alert("inside if 0");
1225 return 0;
1226 }
1227 else {
1228 var radlat1 = Math.PI * this.user.complat/180;
1229 var radlat2 = Math.PI * location.latitude/180;
1230 var theta = this.user.complong - location.longitude;
1231 var radtheta = Math.PI * theta/180;
1232 var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
1233 if (dist > 1) {
1234 dist = 1;
1235 }
1236 dist = Math.acos(dist);
1237 dist = dist * 180/Math.PI;
1238 dist = dist * 60 * 1.1515;
1239 dist = dist * 1.609344;
1240 this.distancekm = dist.toFixed(2);
1241 this.distancem = Number(dist.toFixed(2)) * 1000;
1242 console.log(dist, "++++");
1243
1244 if(this.distancem != NaN)
1245 {
1246 // alert("distance in meter :: "+this.distancem +"!=NAN");
1247 console.log("distance in meter(if) :: "+this.distancem,this.user.allowedmeters );
1248 if(Number(this.distancem) <= Number(this.user.allowedmeters))
1249 {
1250 this.time = new Date();
1251 //this.tbl_bill();
1252 if(this.user.callingwaiter == true)
1253 {
1254 this.viewcartpg.waitercalling();
1255 }
1256 else
1257 {
1258 this.viewcart = 'NO';
1259 this.showcart();
1260 }
1261 }
1262 else{
1263 if(this.user.callingwaiter == true)
1264 {
1265 this.viewcartpg.waitercalling();
1266 }
1267 else{
1268 this.viewcart = 'NO';
1269 this.showcart();
1270 }
1271 //this.user.showToast("Order can not be placed at the moment");
1272 }
1273 return;
1274 }
1275 else{
1276 // alert("inside else ");
1277 console.log("distance in meter(if) :: "+this.distancem);
1278 return;
1279 }
1280 }
1281 }
1282 callsteward()
1283 {
1284 console.log("call steward");
1285 this.user.callingwaiter = true;
1286 this.user.createwaiterreq().subscribe(data=>{
1287 //console.log(data);
1288 if(data.hasOwnProperty("STATUS"))
1289 {
1290 if(data.STATUS == 'success')
1291 {
1292 this.getLocation();
1293 }
1294 else{
1295 this.user.showToast(data.MESSAGE);
1296 this.user.callingwaiter = false;
1297 }
1298 }
1299 });
1300
1301 // this.viewcartpg.waitercalling();
1302 }
1303 shwImgDiv(list)
1304 {
1305 console.log("called 1098");
1306 list.imgDiv = list.imgDiv ? false : true;
1307 // this.imgsource = list.NAR;
1308 // this.divCtg = list.CTG;
1309 // this.divItem = list.NAME.charAt(0).toUpperCase() + list.NAME.substr(1).toLowerCase();
1310 }
1311
1312 check_stock(list)
1313 {
1314 console.log(list.CALSTOCK);
1315 if(list.CALSTOCK === undefined)
1316 list.CALSTOCK = '';
1317 if(list.CALSTOCK == 'Y')
1318 {
1319 this.neg_value = []; var ng='';
1320
1321 if(Number(list.CODE) < 0)
1322 ng = list.CODE;
1323 else
1324 ng = '-'+list.CODE;
1325 for(let i=0; i<this.allItemsctgList.length;i++)
1326 {
1327 this.neg_value = JSON.parse(JSON.stringify(this.allItemsctgList[i]["ITEMS"].filter( item =>{
1328 console.log(item.CODE);
1329 if(Number(item.CODE) == Number(ng))
1330 {
1331 // console.log(item.CODE, ng);
1332 i=this.allItemsctgList.length-1;
1333 return true;
1334 }
1335
1336 })));
1337 // console.log(this.neg_value, i);
1338 if(this.allItemsctgList.length-1 == i)
1339 {
1340 // console.log(this.neg_value, ng);
1341 if(this.neg_value.length > 0)
1342 {
1343 list.IS_NEGATIVE = 'Y';
1344 list.CS = Number(list.QNTY) * Number(list.PGSHIFT);
1345 }
1346 else
1347 {
1348 list.IS_NEGATIVE = 'N';
1349 list.CS = Number(list.QNTY) * Number(list.PGSHIFT);
1350 }
1351 }
1352 }
1353
1354
1355 // console.log(list.CODE,ng,list.IS_NEGATIVE,this.neg_value, "+++");
1356 }
1357
1358 if(list.VATCREDIT != 'Y' || (list.org_rate == null || list.org_rate == ''))
1359 {
1360
1361 if(list.RATE === undefined)
1362 {list.RATE=0;}
1363 if(list.QNTY===undefined)
1364 {list.QNTY=0;}
1365
1366 /** calculate stock */
1367
1368 list.CS = Number(list.QNTY) * Number(list.PGSHIFT);
1369 if(list.IS_NEGATIVE == 'Y' && Number(list.QNTY) > 0)
1370 {
1371 //this.chk_neg(index);
1372 console.log(this.neg_value);
1373 if(this.neg_value.length > 0 && list.QNTY != "")
1374 {
1375 if(this.neg_value[0].FDESC != undefined && this.neg_value[0].FDESC != null)
1376 {
1377 // this.disabled_kot = true;
1378 this.user.k_stk_upd(this.neg_value[0].FDESC).subscribe(data=>{
1379 if(data.hasOwnProperty("PHYSICAL_STOCK"))
1380 {
1381 // setTimeout(()=>{
1382 // this.disabled_kot = false;
1383 if(data.PHYSICAL_STOCK.length > 0)
1384 {
1385 this.rate_stk = data.PHYSICAL_STOCK;
1386 if(this.rate_stk[0].CURSTK === undefined || this.rate_stk[0].CURSTK == null)
1387 { this.rate_stk[0].CURSTK = 0; }
1388 if(this.rate_stk[0].CURSL === undefined || this.rate_stk[0].CURSL == null)
1389 { this.rate_stk[0].CURSL = 0; }
1390 console.log(this.rate_stk[0].CURSTK,"curstk",Number(this.rate_stk[0].CURSL),"CURSL",list.CS,"cs");
1391
1392 if(((Number(this.rate_stk[0].CURSTK) - Number(this.rate_stk[0].CURSL)) >= Number(list.CS)))
1393 { // cs = qnty * ml
1394 list.NAME = this.neg_value[0].NAME;
1395 list.CODE = this.neg_value[0].CODE;
1396 list.FDESC = this.neg_value[0].FDESC;
1397 }
1398 else
1399 {
1400 if(list.FDESC === undefined || list.FDESC == null)
1401 { list.FDESC = ''; }
1402 list.NAME = list.NAME.replace(/#/i, '');
1403 list.CODE = list.CODE.replace(/-/i, '');
1404 list.FDESC = list.FDESC.replace(/-/i, '');
1405 }
1406 }
1407
1408
1409 // },20000);
1410 }
1411 },err=>{
1412 console.log(err);
1413 });
1414 }
1415 }
1416 }
1417 }
1418 console.log(list, "++++++++");
1419 }
1420
1421
1422 async presentActionSheet() {
1423 const actionSheet = await this.actionSheetController.create({
1424 header: 'Albums',
1425 buttons: [{
1426 text: 'Delete',
1427 role: 'destructive',
1428 icon: 'trash',
1429 handler: () => {
1430 console.log('Delete clicked');
1431 }
1432 }, {
1433 text: 'Share',
1434 icon: 'share',
1435 handler: () => {
1436 console.log('Share clicked');
1437 }
1438 }, {
1439 text: 'Play (open modal)',
1440 icon: 'arrow-dropright-circle',
1441 handler: () => {
1442 console.log('Play clicked');
1443 }
1444 }, {
1445 text: 'Favorite',
1446 icon: 'heart',
1447 handler: () => {
1448 console.log('Favorite clicked');
1449 }
1450 }, {
1451 text: 'Cancel',
1452 icon: 'close',
1453 role: 'cancel',
1454 handler: () => {
1455 console.log('Cancel clicked');
1456 }
1457 }]
1458 });
1459 await actionSheet.present();
1460 }
1461
1462 gotogrp(grp)
1463 {
1464 this.grp = grp;
1465 console.log(grp);
1466 if(this.grp == '')
1467 {
1468 this.ctg = JSON.parse(JSON.stringify(this.user.allItemsctgList));
1469 this.ctglen = this.ctg.length-1;
1470 }
1471 else
1472 {
1473 this.ctg = this.allItemsctgList.filter(item=>{
1474 if(item != null)
1475 {
1476 console.log(item.GRP);
1477 if(item.GRP.toUpperCase() == grp.toUpperCase())
1478 {
1479 return item;
1480 }
1481 }
1482 });
1483 console.log(this.ctg, this.hideshowmenu);
1484 this.ctglen = this.ctg.length;
1485 }
1486
1487
1488 }
1489 logout()
1490 {
1491 this.events.publish("logout");
1492 }
1493}