· 6 years ago · Dec 13, 2019, 10:00 AM
1<?php
2/**
3*
4* @file name inv_rpt_ar_bil_bill_dt1.php
5* @version 1.00
6* @author : unknown
7* @remark This file will show the bill information-customer bill and also will show the list of products and information
8* @modified
9*
10* charleo had change the
11* if(($tbl_name1.dt_qty>0 && $tbl_name1.dt_price='0') || ('$chkFOC'='1' && $tbl_name1.dt_foc>0), 'F.O.C', $tbl_name1.dt_price) as dt_price,
12* to
13* if($tbl_name1.dt_qty>0 && $tbl_name1.dt_price='0' && '$chkFOC'='1', 'F.O.C', $tbl_name1.dt_price) as dt_price,
14*
15* 20080714 -Eric add option to consolidate each bill by prdt code, price in query page
16* 20080731 - Eric resolve bill listing query error, print bill with product repacking information quantity and amount not correct and fix bill priting show no record
17* 20080804 - Eric implemented coding standard
18* 20080811 - add WHERE dt_Transeqno>0
19* 20080903 - Eric dt_userdefine1 for dimension format AxBxC
20* 20080911 - stleong use hd_reference number, the original refno as grouping
21* 20080919 - shariza Purple Cane - Receipt, need to hide the sub component
22* 20080922 - William added generateConsolidatedNotesTable to generate notes value table
23* 20080925 - William added user_login_name
24* 20080930 - William added IF statement to avoid query error when no record
25* 20081009 - William off generateConsolidatedNotesTable function because of Max_Join_Size error and include notes_key in final sql to use getNotesValue function
26* 20080816 - options to select dt_userdefine1 or product weight from productmst for printout for Tohopak
27* 20081111 - shariza change the globalsetting no from '3026' to '3028' AND the setting only works in POS bill
28* 20081129 - Chris Added new field for reprint header function into CB and INV document type in Customer Bill
29* 200812023 - justin replace(dbtr_ref_no, '\n', '<br>') as dbtr_ref_no
30* 2008120204 - justin add if(flag=1 and dt_ini_amount!=0,concat(@counter-1,'.'),'') as rec_no1
31* 2008120204 - justin remove rec_no1 add temp_count
32* 20083012 Eric add debtor selection
33* 20090203 - #5514 justin remove 1 st_name2 filed check out duplicate
34* 20090203 - #revert back st_name2
35* 20090204 - ieja Firefox standardization
3620090204 bk
37 - justin fixing correctly, has duplicate st_name2, so remove 1 of it
3820090403 bk
39 - Add in driver name from tms_drivermst
4020090416 bk #6049
41 - Add Body SJT
42* 20090601 henri #6044
43* - Add in store address and phone_fax
44 20090605 - justin add temp_count2,
45* 20090630 - justin add prdt_inventory,dbtr_business,
46* 20090701 Yinru #6628
47* - Add in new counter variable for Assembly item which is service item @as_counter, and column name as as_recno
48* 20090804 bk #6474
49* - show assembly child
50* 20090820 eric #7087
51* - add template selection
52* 20090827 Azie #6750
53* - add in sql to show SO info at t_detail_line2 inside function nllEvents_PageBeforePrintFooter()
54* 20090904 PheiLing #6749
55* - add in condition and sql to select single copy
56* 20090929 Azie #6750
57* - change $sqlCaption
58* 200900928 Jack Son
59* - Add in hd_round for additional calculation for the report to print out with rounding amount
60* the class definition MUST be loaded BEFORE session_start() command
61*
62* 20091015 PheiLing #7248
63* - Add in condition to print cash bill auto 3 copy
64* 20091104 PheiLing #7478
65* - Add in new variable name full_card_no to show full card no
66* 20091105 Yinru #7688
67* - Add in userdefine2 information
68* 20091105 Yinru #7693
69* - Add in extra information.shipment inforat
70* 20091106 wai choong #7451
71* - Add idocstat_print_status as condition in sql
72* 20091109 Yinru #7694
73* - Add group header for Lii Hen Oversea DO templates and some fields.
74*
75* 20091229 yip
76* #7921 - separate shipment activation into header and Body
77* 20091231 bk #7688
78* - add new field price before tax and amount before tax
79*
80* 20091231 yip
81* #8114 - need to cater only lii hen template run the customized grouping
82*
83* 20100108 yip
84* #8091 - add customized DNote (outgoing) template to the customized sql part
85* - specific for TOKOPAK
86*
87* justin add field hd_shp_close_date,
88*
89* 20100208 yip
90* #7885 - print 3 copy - change to use bill_control setting to decide print 3 copy or notes_key
91* - the single copy option in qr will have higher priority than bill_control setting
92*
93* 20100206 Yinru #8389
94* FD format customization
95* 20100402 bk #8768
96* - select out Sales Order Quantity
97* 20100609 Yinru #8776
98* - for LH-CT to show > 1 import from refno
99* 20100730 Nurul #8778
100* - add rounding column
101* 20100830 Yinru #9044
102* to check original template from reportformat, so that it can go into the serial number sql instead hardcode the template name
103* 20100921 Yinru #10037
104* Add the where condition of type1 and type2 to prevent it have duplicate reference no.
105* 20101101 bk #10253
106* fix on hide/show of discount,tax,rounding row
107* 20101101 bk #10270
108* fix on hide/show of discount,tax,rounding row
109* 20101110 Choon Ming #10306
110* - added db_clean for company name
111* 20101125 bk #10420
112* - Fix for unable print for Promotion FOC. dt_assembly: 1=Assembly Parent, 2=Assembly Child, 3=Promotion FOC Parent, 4=Assembly FOC, 5=Promotion FOC
113* 20101228 Kenny add lii hen EF templates for good_total
114* 20101228 Yinru #10546
115* - Add Deposit Details from SO and account ledger detail
116*
117*20110420 Lew #10418
118*- added prdt_price column
119*20110510 karwei #10856
120*- add in param if from acc then use only where bill_from and to
121*
122*20110526 Alvin #11370
123* - Add the column srce_address1, srce_address2, srce_address3, srce_address4 and srce_contact.
124*20110627 Alvin #11435
125* - Add in the column dt_repack_text and dt_repack_remark.
126*20110628 bk #11328
127* - Add support for serial number template
128*20110919 Justin
129* - add truck_code
130*20120316 Jey #8778
131* - Add variable for credit note
132*20120319 Jeff
133* - add code for get deposit (#12610)
134*20120517 KY
135* - One Stop p3.3.3 Warehouse AR DO printout(local DO) (#13507)
136*20120705 Jey #14002
137* - OKN - Add in quantity Column
138*20120712 ida
139* take out hash # in comment
140* 20120921 yip
141* #14650 - add tpbp customize template (prefix start with tkpbp_)
142* 20130418 Chin #15719
143* Pigeon - AR /AP bill to show multiple discount amount in templates
144* 20130509 Jey #16333
145* Fiamma - Invoice + DO Template
146* 20130527 William 16291
147* Add filter by print status
148* 20130612 Yinru #16752 - Fiamma - Inventory AR Print DO from Invoice Count
149* 20130719 CK 15298
150* Bahagia - Membership; Member Card Number show out at Customer Bill / Order Template
151* 20130719 sook mun #16546- Pigeon - Add in "Issued by:-last modified user"
152* 20130730 -KY- 17203-Fiamma - INV Report - Pre-printed Invoice/DO with FOC
153* 20130923 sook mun -#15795-KMM - Inventory SN able to add hd_userdefine1, hd_userdefine2,hd_userdefine3
154* 20131016 william - 17746 - Fiamma - filter own document when print bill
155* 20131111 yip #16779 - modify to cope deposit+serial
156* 20131128 yip #18010 - modify count rec_no - fix scenario when 2 different invoice having same product - search "countB" for the fixes
157* 20131210 sook mun #18059 - Malaysia GST - Customer Bill DT modifications
158* 20131221 bk #18119
159* - Add Original Code and Name from Product Master (orig_prdt_code,orig_prdt_name1)
160* 20140110 megat 18176 Malaysia GST - Tax Invoice Format
161* 20140206 yinru #17080, 16176 - remove groupbreaks in the events
162* 20140214 rina 18421 - change title report
163* 20140305 megat 18598 Orientage - New customer bill print out format
164* 20140306 - David #18660 Add in count D and count E field to handle showing of child and pareant item
165* 20140307 megat 18597 Malaysia GST - Revise Bill Printing to Mixed GST
166* 20140313 ky #15394 - Export to PDF Separate by Debtor Code
167* 20140407- UNIC yinru #18991 add dt_rec_price as referer price
168* 20140418 - stephen #18690 add membership point
169* 20140702 stephen #13163 - Xeersoft- Xeer Search - Fill in All Reports
170* 20140716 ida #18402 - to show final approve user from workflow
171* 20140721 yinru #19601 - tpl issue with groupbreaks
172* 20141009 Hamizan 20441 - GST Malaysia - Inventory bill printing title based on condition.
173* 20141031 sook mun #20758 - Tohopak - Customer Bill Invoice print as DO product no show
174* 20150113 yip #21929 - webixs - show company bank info from Company Account - only to standard template
175* 20150213 sook mun #22626-GST Summary not show when print product with serial no
176* 20150311 guangzhen #22750
177* - Add the column srce_ref for let user enter email.
178* 20150312 ky #22927-Malaysia GST - inventory bill if mix only show * and **
179* 20150414 Lucas #23680 -GST - DT file need to get store GST no for AR and AP Order
180* 20150421 vernhui #23669 - Malaysia GST - Currency invoice printing, the product row amount column in rm shall get the value from dt, instead of by formula
181* 20150514 vernhui #24293 - Malaysia GST - Margin scheme Part 2
182* 20150516 Yinru - #24454 Malaysia GST - Bill Printing Summary table for Exemption issue
183* 20150722 sook mun - #24066 - Tokopak - Inventory Customer Bill, S Invoice and DO need 4 copies
184* 20150925 sook mun #25176 - Tokopak - Inventory Customer Bill, CN import Invoice, the Your ref and Our ref field info from Invoice take in to CN dt
185* 20150928 Hamizan 25627 - LYC - Option to hide cancelled item in template if print using inventory customer bill template format
186* 20161031 Azwan 29742 - Hup Lee - Fix for standard template as_recno does not reset when print in batch for both product map setting on/off
187* 20170126 sook mun 30545 - webixs - GST for purely Zero rated Invoice, cannot print as Tax Invoice wording
188* 20170301 beeha 30786 Lii Hen - Inventory Supplier Order, add document status in dt
189* 20170611 yinru#31730 - repacking based on master formula
190* 20170825 May #32070 Mr Eng - show total payment received and balance amount in Inventory Cash Bill tpl
191* 20170908 beeha #32524 Webixs - create INV tpl for link hub asia
192* 20170921 May #31882 - Mr Eng - Allow user set document title by bill control and report format
193* 20180611 beeha #35085 - Mr Eng - S.O.S Mobile Services Centre (M) Sdn Bhd- Customize php to cater printing in full page
194* 20181018 May #35447 - SST -Debtor Master/Creditor Master add Exemption information
195* 20190228 May #36812 - Hup Sheng - Inventory Purchase Order printout show quantity is double the value in entry
196* 20190528 leewah 37296 Xeersoft - E-Billing with CC and BCC recipients email
197* 20190821 Amirul #38426 zakir - tpl enhancment add delivery date inside tpl
198* 20190830 Ben #37869 Bahagia - Inventory print Customer Order want to have option to Hide Assembly Child
199*/
200
201if (!defined(RelativePath)){
202 define("RelativePath", "..");
203 $isIncluded="1";
204 require_once(RelativePath . "/common/nll_global_include_classes.php");
205 include_once(RelativePath . "/Common.php");
206 include_once(RelativePath . "/Template.php");
207 include_once(RelativePath . "/Sorter.php");
208 include_once(RelativePath . "/Navigator.php");
209}
210global $nlldb;
211session_start();
212//include the report generator class
213require_once(RelativePath."/report/engine/nll_classes_report_factory.php");
214require_once(RelativePath."/myfunction.php");
215require_once(RelativePath."/common/nll_constants.php");
216require_once(RelativePath."/common/inventory_entry_module.php");
217require_once(RelativePath."/common/num2words.inc");
218
219//access the db via class
220if (!$isIncluded)
221require_once(RelativePath."/common/nll_classes_common_db.php");
222$nllDb = new nllDbAccessExecution();
223
224if($nlldb_redir_name){
225 $nllDb->_dbConnection->setDb($nlldb_redir_name);
226 $nllDb->_dbConnection->openConnection(NLLDBHOST,NLLDBUSER,NLLDBPASS);
227 $nllDb->setFilterFlag(false);
228 $nlldb->_dbConnection->setDb($nlldb_redir_name);
229 $nlldb->_dbConnection->openConnection(NLLDBHOST,NLLDBUSER,NLLDBPASS);
230 $nlldb->setFilterFlag(false);
231 $_SESSION['nlldbname_redirect'] = $nlldb_redir_name;
232
233 $sql_session = "SELECT comp_id, comp_name, comp_name2, comp_regno, comp_address, comp_tel, comp_fax, comp_email, comp_url FROM companymst WHERE comp_id = '".$_SESSION['NLL_COMPANY_ID']."';";
234 $result_session = $nlldb->executeQuery($sql_session);
235 $session = $nlldb->fetchArray($result_session);
236
237 $_SESSION['NLL_COMPANY_NAME'] = $session['comp_name'];
238 $_SESSION['NLL_COMPANY_NAME2'] = $session['comp_name2'];
239 $_SESSION['NLL_COMPANY_REGNO'] = $session['comp_regno'];
240 $_SESSION["NLL_COMPANY_ADDRESS"] = $session['comp_address'];
241 $_SESSION["NLL_COMPANY_TEL"] = $session['comp_tel'];
242 $_SESSION['NLL_COMPANY_FAX'] = $session['comp_fax'];
243 $_SESSION['NLL_COMPANY_EMAIL'] = $session['comp_email'];
244 $_SESSION['NLL_COMPANY_URL'] = $session['comp_url'];
245 $_SESSION["NLL_COMPANY_TELFAX"] = 'Tel : '.$session['comp_tel'].' Fax : '.$session['comp_fax'];
246 $_SESSION['NLL_CURR'] = getHiddenGlobalSettingValue(100,47,90000000);
247 $_SESSION['OFF_SESSION_START'] = '1';
248}
249
250if (!$currselection)
251 $currselection="Original";
252//multi-currency
253require_once(RelativePath."/report/class/cls_multicurr.php");
254$MultiCurr=new MultiCurrencySQL($_SESSION["Customer_MultiCurrency"], "INV");
255$MultiCurr->SetCurrencyType($currselection); // list box value
256$MultiCurr->SetForceCurrency($allcurr); // force currency value
257
258//function to select notes value - william 22/09/2008
259include(RelativePath."/class/cls_notes_object.php"); // should use cls_notes_object instead of cls_notes cause cls_notes will populate javascript which not supported by pdf - bk (20110310) #10967
260
261//multi-currency
262
263$tbl_name1 = uniqid("tmp_tbl1_ar_bil_");
264$tbl_name2 = uniqid("tmp_tbl2_ar_bil_");
265$tbl_name3 = uniqid("tmp_maptbl_");
266//20140716 ida #18402 - temp table to show final approve user from workflow
267$tbl_name10 = uniqid("tmp_tbl10_ar_bil_");
268
269// #13163 - Xeersoft- Xeer Search - Fill in All Reports - set default values if parameter not exists
270if($xsch_flag){
271 include('../modules/xeersearch/default_parameter/inv_rpt_ar_bil_bill_dt1_parameter.php');
272}
273
274//mysql_connect(NLLDBHOST, NLLDBUSER, NLLDBPASS) or die("Could not connect: " . mysql_error());
275//mysql_select_db (NLLDBNAME);
276
277//20191206 leewah 39466 Hatch - Inventory Customer Order, deposit info should exclude cancelled in printing
278global $doc_status_join;
279global $doc_status_where;
280$doc_status_join="";
281$doc_status_where="";
282
283xs_include_event('deposit_filter_status');
284//end 39466
285
286
287$continue_text = "Continue to next page...";
288$continue_page = 0;
289$NLL_BILL_MDISC = $_SESSION["act365"];
290$NLL_PRD_REPACK = $_SESSION["act399"];
291$NLL_USER_SESSION = $_SESSION["UserID"];
292//for bill tax
293$NLL_BILL_MTAX = $_SESSION["act480"];
294if($NLL_BILL_MTAX=='')
295 $NLL_BILL_MTAX='N';
296else
297 $NLL_BILL_MTAX='Y';
298//end
299
300$default_paper = $_SESSION["NLL_DEFAULT_PAPER"];
301//$NLL_SHIPMENT = $_SESSION["act19"];
302$NLL_SHIPMENT = $_SESSION["act563"]; //#7921
303//$chkFOC = $_SESSION["act371"];
304
305//print both invoice and DO format together - yinru @ 20110620 #11429
306//20170921 May #31882
307if($print_type=='IDO'){
308
309 $tSql = "select * from (select rpt_class_name, if(rpt_format is not null and rpt_format <> '', rpt_format, rpt_org_format) as template, if(rpt_file is not null and rpt_file <>'', rpt_file, rpt_origin_ref) as file, rpt_title from reportformat where rpt_system='INV' and rpt_class_name in ('ARB-I', 'ARB-IO') and rpt_flag='1' order by rpt_report) as a group by rpt_class_name";
310 $tResult = $nllDb->executeQuery($tSql);
311
312 echo "<script>";
313
314 while($row = $nllDb->fetchArray($tResult)){
315 $filename = $row['file'];
316 $s_template = $row['template'];
317 $type = $row['rpt_class_name'];
318 $rpt_title = $row['rpt_title'];
319 if($filename=='')
320 $filename = $_SERVER['REQUEST_URI'];
321 else
322 $plink = "?".$_SERVER['QUERY_STRING'];
323
324 if($type=='ARB-I')
325 $print_type = 'INV';
326 else
327 $print_type = 'DO';
328
329 echo "window.open('".$filename.$plink."&print_type=".$print_type."&s_template=".$s_template."&rpt_title=".$rpt_title."');";
330 }
331
332 echo "</script>Reports Generated<BR><BR><A href='inv_rpt_ar_bil_bill_qr1.php?s_module=AR-BIL'>BACK</A>";
333 die();
334}
335
336// handle if 2 templates is posted together.
337$pos2 = stripos($s_template, ";");
338if ($pos2 !== false) {
339 echo "<script>";
340 $s_templateArr = explode(";",$s_template);
341 $filename=$_SERVER['REQUEST_URI'];
342 foreach($s_templateArr as $s_template){
343 echo "window.open('".$filename."&s_template=".$s_template."');";
344 }
345 echo "</script>Reports Generated";
346 die();
347}
348
349$template = $s_template;
350global $show_order_info;
351global $crcy_name1; // 20170908 beeha #32524 Webixs - create INV tpl for link hub asia
352
353//assign currency
354$curr = $_SESSION['NLL_CURR'];
355if($curr != '')
356{
357 $sql = "SELECT crcy_code,crcy_name1 FROM currencymst WHERE crcy_no=$curr;";
358 $result = $nllDb->executeQuery($sql);
359 $row = $nllDb->fetchArray($result);
360 $curr = $row[0];
361 $crcy_name1 = $row[1]; // 20170908 beeha #32524 Webixs - create INV tpl for link hub asia
362}
363else
364{
365 $sql = "SELECT crcy_code ,crcy_name1 FROM currencymst WHERE crcy_code='RM';";
366 $result = $nllDb->executeQuery($sql);
367 $row = $nllDb->fetchArray($result);
368 $curr = $row[0];
369 $crcy_name1 = $row[1]; // 20170908 beeha #32524 Webixs - create INV tpl for link hub asia
370}
371
372if($NLL_BILL_MDISC=='')
373 $NLL_BILL_MDISC='N';
374else
375 $NLL_BILL_MDISC='Y';
376
377$NLL_PRODUCT_MDISC = $_SESSION["act359"];
378if($NLL_PRODUCT_MDISC=='')
379 $NLL_PRODUCT_MDISC='N';
380else
381 $NLL_PRODUCT_MDISC='Y';
382
383$NLL_PRODUCT_MAP = $_SESSION["act397"];
384
385if (!$from_date){
386 $from_date=date("01/01/1980");
387}
388if (!$to_date){
389 $to_date=date("01/01/2020");
390}
391//20140305 megat 18598
392global $from_date2;
393$from_date2 = $from_date;
394global $to_date2;
395$to_date2 = $to_date;
396
397
398//format date to Y-m-d
399$from_date = str_replace("-", "/", "$from_date");
400$to_date = str_replace("-", "/", "$to_date");
401$from_date = xs_DisplayDate_to_dbDate($from_date);
402$to_date = xs_DisplayDate_to_dbDate($to_date);
403
404//format date to Y-m-d
405if ($from_dateExp){
406 $from_dateExp = str_replace("-", "/", "$from_dateExp");
407 $to_dateExp = str_replace("-", "/", "$to_dateExp");
408 $from_dateExp = xs_DisplayDate_to_dbDate($from_dateExp);
409 $to_dateExp = xs_DisplayDate_to_dbDate($to_dateExp);
410}
411
412
413
414//refer to doc_type, retrieve correspond doc name
415$type = Get_Doc_Type('AR-BIL', $doc_type);
416
417
418//20130612 Yinru #16752 - Fiamma - Inventory AR Print DO from Invoice Count
419$IDO_COUNT = getHiddenGlobalSettingValue(5000,278,90000200);
420$vat_prescribed = getHiddenGlobalSettingValue(1500,70,90000200);
421
422//20131212 sook mun -tax nature setting
423global $vat_nature_type;
424$vat_nature_type = getHiddenGlobalSettingValue(1500,2,90000200);
425$is_plain_invoice = false;
426
427switch ($type)
428{
429case 'I':
430 if($print_type=="DO")
431 {
432 $report_title = "DELIVERY ORDER";
433 $report_type = "DO No.";
434 $document_type = "DO";
435 }
436 else if($print_type=="INV" && $doc_type=="SR" )
437 {
438 $report_title = "SALES RETURN";
439 $report_type = "INV No.";
440 $document_type = $doc_type;
441 }
442 else
443 {
444 if($vat_nature_type==3){
445 $report_title = "TAX INVOICE";
446 }else{
447 $report_title = "I N V O I C E";
448 }
449 $report_type = "INV No.";
450 $document_type = $doc_type;
451 $is_plain_invoice = true; //20141009 Hamizan 20441 - To mark that this is a plain invoice. For title change at nllEvents_PageBeforePrintHeader().
452 }
453 break;
454case 'O':
455 $report_title = "DELIVERY ORDER";
456 $report_type = "D/O No.";
457 $document_type = $doc_type;
458 break;
459case 'D':
460 $report_title = "DEBIT NOTE";
461 $report_type = "D/N No.";
462 $name = "Customer's";
463 $document_type = $doc_type;
464 break;
465case 'C':
466 $report_title = "CREDIT NOTE";
467 $report_type = "C/N No.";
468 $name = "Customer's";
469 $document_type = $doc_type;
470 break;
471case 'K':
472 //20140214 rina 18421 - change title report
473 //20150406 yip - revert - report title change to tax invoice, but report type should not
474 if($vat_nature_type==3 && $doc_type !="POR"){
475 $report_title = "TAX INVOICE";
476 //$report_type = "INV No.";
477 $report_type = "CB No.";
478 }//29939 xy,if POR show sales return instead of tax invoice
479 else if ($doc_type == "POR"){
480 $report_title = "SALES RETURN";
481 $report_type = "CB No.";
482 }
483 else{
484 $report_title = "CASH BILL";
485 $report_type = "CB No.";
486 }
487 $document_type = $doc_type;
488 break;
489case 'P':
490 $report_title = "CASH BILL";
491 $report_type = "CB No.";
492 $document_type = $doc_type;
493 break;
494}
495
496global $bilctrl_margin_scheme;
497
498//#7885 - get the control setting from bill_control
499// 20150514 vernhui #24293 - Malaysia GST - Margin scheme Part 2
500// get the bill margin scheme setting from bill control
501$bilctrl_sql = "SELECT bilctrl_print_3copy , bilctrl_margin_scheme FROM bill_control WHERE bilctrl_doc='AR-BIL' AND bilctrl_name='$doc_type' LIMIT 1;";
502$bilctrl_res = $nlldb->executeQuery($bilctrl_sql);
503$bilctrl_row = $nlldb->fetchArray($bilctrl_res);
504$bil_print_3copy = $bilctrl_row[0];
505if ($bil_print_3copy=="" || $bil_print_3copy=="0" || $bil_print_3copy=="1")
506 $bil_print_3copy =0;
507$bilctrl_margin_scheme = $bilctrl_row[1];
508
509//
510
511function getHideZero($paras)
512{
513 $amount = $paras['arg1'];
514 if($amount==0)
515 return '';
516 else
517 return $amount;
518}
519//ida - to divide company address into two
520$sql = "SELECT comp_address,comp_regno,comp_taxid FROM companymst;";
521$result = $nllDb->executeQuery($sql);
522global $com_address;
523if($result<>"")
524 {while ($row = $nllDb->fetchArray($result, MYSQL_BOTH))
525 {
526 $com_address = $row['comp_address'];
527 $com_regno = $row['comp_regno'];
528 $com_taxID= $row['comp_taxid'];
529 }
530 }
531 $nllDb->freeResult($result);
532
533$space_separated= explode(" ", $com_address);
534$count_words = count($space_separated);
535$i = 0 ;
536while($i < $count_words){
537 //echo $space_separated[$i];
538 if($i<5)
539 $f_row.=$space_separated[$i]." ";
540 else
541 $s_row.=$space_separated[$i]." ";
542 $i++;
543}
544
545
546
547if($s_template=='inv_rpt_ar_bil_receipt_wisdom.tpl')//to show branch (store mapping to which user)
548{
549 $storeSQL=" SELECT st_name1 FROM mapping_value
550 inner join storemst on st_no = mv_target_key1
551 WHERE mv_source_key1 = $NLL_USER_SESSION and mv_link=4;";
552
553$result_tmp = $nllDb->executeQuery($storeSQL);
554list($st_mapped) = $nllDb->fetchRow($result_tmp);
555//echo $st_mapped;
556//echo $storeSQL;
557
558}
559
560//20081111 - shariza change the globalsetting no from '3026' to '3028'
561 global $nlldb;
562 $sql = "SELECT glob_var_value FROM globalsetting WHERE glob_no='3028'AND glob_grp_id ='3000' LIMIT 1;";
563 $result=$nlldb->executeQuery($sql);
564 $row=$nlldb->fetchArray($result);
565 $global_value=$row['glob_var_value'];
566
567$chkp = $chkReprint;
568//echo $chkp;
569if($chkp ==1)//for print original or copy receipt
570{
571 $print = " SELECT st_text FROM shorttext WHERE st_id = 'rptCopyT';";
572}
573else
574{
575 $print = " SELECT st_text FROM shorttext WHERE st_id = 'rptOriginalT';";
576}
577$result_print = $nllDb->executeQuery($print);
578list($reprint) = $nllDb->fetchRow($result_print);
579//ida - end
580
581if ($bill_from){
582 $strBillWhere=" BETWEEN '$bill_from' AND '$bill_to' ";
583}else{
584 $strBillWhere=" IS NOT NULL ";
585}
586
587//20150721 May #25100
588if ($tax_group){
589 $taxgroupWhere = " AND hd_vat_group IN ($tax_group) ";
590}
591
592// 20160224 May #19927
593if ($saleman){
594 $salesmanWhere = " AND hd_salesman IN ($saleman) ";
595}
596
597//20161013 XingKang #29672
598 if($Term_list)
599 {
600 $termWhere = " AND hd_terms IN ($Term_list) ";
601 }
602
603//20190228 Nurul 36391
604 if ($tms_drivermst)
605{
606 $tmsdrivermstWhere = "AND hd_tms_driver IN ($tms_drivermst)";
607}
608
609
610//20150205 may #22159
611$NLL_RECORDNO=$chkRecordNo;
612if($NLL_RECORDNO){
613 if($recordno_from)
614 $strRecordNoWhere=" AND hd_transno >= '$recordno_from' ";
615 if($recordno_to)
616 $strRecordNoWhere.=" AND hd_transno <= '$recordno_to' ";
617}
618//end #22159
619
620//20131016 william - 17746
621if($chk_own_doc)
622{
623 $strOwnDocument = " AND hd_sys_add_user = '$NLL_USER_SESSION' ";
624}
625else
626{
627 $strOwnDocument = "";
628}
629//END - 20131016 william - 17746
630
631if ($s_hd_customer && $s_hd_customers){
632 $strdebtor = " AND (debtormst.dbtr_code BETWEEN '$s_hd_customer' AND '$s_hd_customers') ";
633}
634
635//20150928 Hamizan 25627 - to hide cancelled items from bill
636if ($hide_cancelled_bill_items == 1) {
637 $where_hide_cancelled = 'AND dt_active != 0';
638}
639
640//20101228 Yinru #10546 - Add Deposit Details from ledger detail
641require_once("../class/authorization.php");
642$authorization = new Authorization();
643$deposit_auth = $authorization->setAuthorization("{nllauthCOLLIST_Deposit}");
644
645if ($billrefno_list){
646 $billrefno_list = "'".str_ireplace(",","','",$billrefno_list)."'";
647 $whereBillRefnoList_bh = " AND bill_header.hd_refno IN ($billrefno_list)";
648 $whereBillRefnoList= " AND hd_refno IN ($billrefno_list)";
649 $whereBillRefnoList_bill = " AND pse_bill_refno IN ($billrefno_list)";
650}
651
652//20170531 SoonGuan #31128 Bahagia - Inventory at print bill qr page want to filter by product
653 if($billprdt_list){
654 global $nlldb;
655 $billprdt_list = "'".str_ireplace(",","','",$billprdt_list)."'";
656 $nlldb->executeQuery("SET SESSION group_concat_max_len = 1000000;");
657 $billprdt_list_sql = "SELECT GROUP_CONCAT(distinct concat ('''',hd_refno,'''') SEPARATOR',') as billPrdt FROM bill_detail INNER JOIN bill_header ON bill_header.hd_transno=bill_detail.dt_transno AND bill_header.hd_type1=bill_detail.dt_type1 AND bill_header.hd_type2=bill_detail.dt_type2 WHERE dt_prdcode IN($billprdt_list) AND (hd_refno $strBillWhere $whereBillRefnoList) $taxgroupWhere $salesmanWhere $termWhere $strRecordNoWhere $tmsdrivermstWhere;";
658 $billprdt_list_sql_result=$nlldb->executeQuery($billprdt_list_sql);
659 list($billPrdt)=$nlldb->fetchRow($billprdt_list_sql_result);
660 if($billPrdt != ""){
661 $whereBillPrdt_List =" AND hd_refno IN ($billPrdt) ";
662 }
663 else{
664 $whereBillPrdt_List ="";
665 }
666 }
667
668if($deposit_auth == "{nllauthCOLLIST_Deposit}" && (strstr(strtolower($template), 'deposit'))){
669
670 require_once("../common/nll_classes_common_account_util.php");
671 require_once("../common/nll_classes_common_sql_util.php");
672
673 $bankGroup = nllAccountUtil::getBankGroupAccountNo();
674 $cashGroup = nllAccountUtil::getCashGroupAccountNo();
675 $accountNoArray = array_merge($bankGroup, $cashGroup);
676 $condition = nllSqlUtil::generateInCondition("acct_no",$accountNoArray);
677 $tbl_name_deposit = uniqid("tmp_tbl_deposit_");
678 $tbl_name_deposit2 = uniqid("tmp_tbl_deposit2_");
679 $tbl_name_deposit_final = uniqid("tmp_tbl_deposit_final_");
680
681 $sql = "DROP TABLE IF EXISTS $tbl_name_deposit,$tbl_name_deposit2,$tbl_name_deposit_final ;";
682 $nllDb->executeQuery($sql);
683
684 $depositSQL2 = "CREATE TEMPORARY TABLE $tbl_name_deposit2 (INDEX(dt_import_type1),INDEX(dt_import_type2), INDEX(dt_import_transno))
685 SELECT hd_type1, hd_type2, hd_transno, hd_refno,hd_salesman, dt_import_type1, dt_import_type2,dt_import_date, dt_import_transno
686 FROM bill_header
687 INNER JOIN bill_detail ON bill_header.hd_type1=bill_detail.dt_type1 and bill_header.hd_type2=bill_detail.dt_type2 and bill_header.hd_transno=bill_detail.dt_transno
688 INNER JOIN debtormst ON hd_customer = dbtr_no
689 WHERE bill_header.hd_doc = 'AR-BIL' AND bill_header.hd_type2 = '$doc_type' and (bill_header.hd_active is null or bill_header.hd_active = 1)
690 AND (bill_header.hd_date BETWEEN '$from_date' AND '$to_date')
691 AND (bill_header.hd_refno $strBillWhere $whereBillRefnoList_bh)
692 $strRecordNoWhere
693 $strOwnDocument
694 $strdebtor
695 $taxgroupWhere
696 $salesmanWhere
697 $termWhere
698 $tmsdrivermstWhere
699 GROUP BY dt_import_type1, dt_import_type2, dt_import_transno ;
700 ";
701
702 $depositSQL = "
703 CREATE TEMPORARY TABLE $tbl_name_deposit
704 SELECT bill_header.hd_type1, bill_header.hd_type2, bill_header.hd_transno,bill_header.hd_refno,ord_header.hd_refno as order_refno, apar_refno1 as deposit_refno,
705 date_format(lg_transdate,'%d/%m/%Y') as transdate, acct_code, acct_name1, lg_desc1, lg_desc2, if(lg_debit > 0, lg_debit, lg_credit) as deposit_amount
706 FROM bill_header
707 INNER JOIN bill_detail ON bill_header.hd_type1=bill_detail.dt_type1 and bill_header.hd_type2=bill_detail.dt_type2 and bill_header.hd_transno=bill_detail.dt_transno
708 INNER JOIN debtormst ON hd_customer = dbtr_no
709 INNER JOIN ord_header ON bill_detail.dt_import_type1=ord_header.hd_type1 AND bill_detail.dt_import_type2=ord_header.hd_type2 AND bill_detail.dt_import_transno=ord_header.hd_transno
710 INNER JOIN debtor_detail ON apar_deposit_link=concat(ord_header.hd_type1,'-',ord_header.hd_type2,'-',ord_header.hd_transno)
711 INNER JOIN ledger_detail ON apar_type1=lg_type1 and apar_type2=lg_type2 and apar_transno=lg_transno
712 INNER JOIN accountmst on lg_acno = acct_no
713 INNER JOIN chartacc_lv5 on acct_group = chartacc_lv5.chrt_no
714 INNER JOIN chartacc_lv4 on chartacc_lv5.chrt_link = chartacc_lv4.chrt_no
715 INNER JOIN chartacc_lv3 on chartacc_lv4.chrt_link = chartacc_lv3.chrt_no
716 $doc_status_join
717 WHERE bill_header.hd_doc = 'AR-BIL' AND bill_header.hd_type2 = '$doc_type' and (bill_header.hd_active is null or bill_header.hd_active = 1)
718 AND (bill_header.hd_date BETWEEN '$from_date' AND '$to_date')
719 AND (bill_header.hd_refno $strBillWhere $whereBillRefnoList_bh)
720 $strRecordNoWhere
721 $strOwnDocument
722 $strdebtor
723 $taxgroupWhere
724 $salesmanWhere
725 $termWhere
726 $tmsdrivermstWhere
727 $doc_status_where
728 AND $condition
729 GROUP BY bill_header.hd_refno,order_refno, deposit_refno";
730
731 $depositSQL_union = " INSERT INTO $tbl_name_deposit
732 SELECT $tbl_name_deposit2.hd_type1, $tbl_name_deposit2.hd_type2, $tbl_name_deposit2.hd_transno,$tbl_name_deposit2.hd_refno,ord_header.hd_refno as order_refno, apar_refno1 as deposit_refno,
733 date_format(lg_transdate,'%d/%m/%Y') as transdate, acct_code, acct_name1, lg_desc1, lg_desc2, if(lg_debit > 0, lg_debit, lg_credit) as deposit_amount
734 FROM $tbl_name_deposit2 INNER JOIN bill_header ON $tbl_name_deposit2.dt_import_type1=bill_header.hd_type1 AND $tbl_name_deposit2.dt_import_type2=bill_header.hd_type2 AND $tbl_name_deposit2.dt_import_transno=bill_header.hd_transno
735 INNER JOIN bill_detail ON bill_header.hd_type1=bill_detail.dt_type1 and bill_header.hd_type2=bill_detail.dt_type2 and bill_header.hd_transno=bill_detail.dt_transno
736 INNER JOIN ord_header ON bill_detail.dt_import_type1=ord_header.hd_type1 AND bill_detail.dt_import_type2=ord_header.hd_type2 AND bill_detail.dt_import_transno=ord_header.hd_transno
737 INNER JOIN debtor_detail ON apar_deposit_link=concat(ord_header.hd_type1,'-',ord_header.hd_type2,'-',ord_header.hd_transno)
738 INNER JOIN ledger_detail ON apar_type1=lg_type1 and apar_type2=lg_type2 and apar_transno=lg_transno
739 INNER JOIN accountmst on lg_acno = acct_no
740 INNER JOIN chartacc_lv5 on acct_group = chartacc_lv5.chrt_no
741 INNER JOIN chartacc_lv4 on chartacc_lv5.chrt_link = chartacc_lv4.chrt_no
742 INNER JOIN chartacc_lv3 on chartacc_lv4.chrt_link = chartacc_lv3.chrt_no
743 WHERE bill_header.hd_doc = 'AR-BIL'
744 AND $condition
745 GROUP BY $tbl_name_deposit2.hd_refno,order_refno, deposit_refno;
746 ";
747
748 $nllDb->executeQuery($depositSQL2);
749 $result = $nllDb->executeQuery($depositSQL);
750 $nllDb->executeQuery($depositSQL_union);
751
752 $depositSQLFinal = "CREATE TEMPORARY TABLE $tbl_name_deposit_final (INDEX(deposit_transno, deposit_type1, deposit_type2))
753 SELECT hd_type1 as deposit_type1,hd_type2 as deposit_type2, hd_transno as deposit_transno, sum(deposit_amount) as deposit_amount
754 FROM $tbl_name_deposit
755 GROUP BY hd_type1, hd_type2, hd_transno";
756 $nllDb->executeQuery($depositSQLFinal);
757 $deposit_join = " LEFT JOIN $tbl_name_deposit_final ON deposit_transno=$tbl_name1.hd_transno and deposit_type1=$tbl_name1.hd_type1 and deposit_type2=$tbl_name1.hd_type2 ";
758 $deposit_field = " ,deposit_amount " ;
759 }
760//end deposit
761
762//yinru @ 20170611 #31730 - repacking based on master formula
763$master_repack=0;
764xs_include_event("inventory_ar_bil_condition");
765
766
767$sql = "DROP TABLE IF EXISTS $tbl_name1 ;";
768$nllDb->executeQuery($sql);
769
770$sql = "DROP TABLE IF EXISTS $tbl_name2 ;";
771$nllDb->executeQuery($sql);
772
773
774$sql = "set @delim := '~';";
775$nllDb->executeQuery($sql);
776
777// Filter Source, Job, Task (bk) - start
778$NLL_SOURCE=$chkSource;
779$NLL_JOB=$chkJob;
780$NLL_TASK=$chkTask;
781
782if ($from_dateExp && $from_acc==""){//$from_acc param is pass from accounting debtor statement template-10856 karwei
783 $sql_FromToExp = " and (hd_promise_date BETWEEN '$from_dateExp' AND '$to_dateExp') ";
784}
785if($NLL_SOURCE || $NLL_JOB || $NLL_TASK)
786{
787 $tableSource1=uniqid("temp_source1_");
788 $tableSource=uniqid("temp_source_");
789
790 $strWhere="";
791 if($NLL_SOURCE && $from_acc=="")
792 {
793 $joinSource=" LEFT JOIN sourcemst on sourcemst.srce_no=$tableSource1.dt_source ";
794 if($source_from && $source_to)
795 $strWhere.= " WHERE (sourcemst.srce_code between '$source_from' and '$source_to') ";
796 }
797 else
798 {
799 $joinSource="";
800 }
801 if($NLL_JOB && $from_acc=="")
802 {
803 $joinJob=" LEFT JOIN jobmst on jobmst.jb_no=$tableSource1.dt_job ";
804
805 if($job_from && $job_to){
806 if($strWhere!="")
807 $strWhere.=" and (jobmst.jb_code between '$job_from' and '$job_to') ";
808 else
809 $strWhere.=" WHERE (jobmst.jb_code between '$job_from' and '$job_to') ";
810 }
811 }
812 else
813 {
814 $joinJob="";
815 }
816 if($NLL_TASK && $from_acc=="")
817 {
818 $joinTask=" LEFT JOIN taskmst on taskmst.task_no=$tableSource1.dt_task ";
819 if ($task_from && $task_to){
820 if($strWhere!="")
821 $strWhere.=" and (taskmst.task_code between '$task_from' and '$task_to') ";
822 else
823 $strWhere.=" where (taskmst.task_code between '$task_from' and '$task_to') ";
824 }
825 }
826 else
827 {
828 $joinTask="";
829 }
830
831 if($from_acc!=''){
832
833 $whereCondition = "WHERE (hd_refno $strBillWhere $whereBillRefnoList) $whereBillPrdt_List $taxgroupWhere $salesmanWhere $termWhere $strRecordNoWhere $strOwnDocument $tmsdrivermstWhere";
834 }else{
835 $whereCondition = "WHERE (hd_date BETWEEN '$from_date' AND '$to_date') $sql_FromToExp
836 AND (hd_refno $strBillWhere $whereBillRefnoList) $whereBillPrdt_List $taxgroupWhere $salesmanWhere $termWhere $strRecordNoWhere $strOwnDocument $tmsdrivermstWhere";
837 }
838 $sqlTempSourceDrop1="drop table if exists $tableSource1;";
839 $sqlTempSource1="create temporary table if not exists $tableSource1 (index(dt_transno), index(dt_type1), index(dt_type2), index(dt_transeqno))
840 SELECT dt_transno, dt_type1, dt_type2,dt_transeqno,
841 if(bill_detail.dt_source=0 or bill_detail.dt_source is null, bill_header.hd_source, bill_detail.dt_source) as dt_source,
842 if(bill_detail.dt_job=0 or bill_detail.dt_job is null, bill_header.hd_job, bill_detail.dt_job) as dt_job,
843 if(bill_detail.dt_task=0 or bill_detail.dt_task is null, bill_header.hd_task, bill_detail.dt_task) as dt_task
844 FROM bill_detail
845 INNER JOIN bill_header ON hd_transno = bill_detail.dt_transno and hd_type1 = bill_detail.dt_type1 and hd_type2 = bill_detail.dt_type2
846 $whereCondition;";
847 $nllDb->executeQuery($sqlTempSourceDrop1);
848 $nllDb->executeQuery($sqlTempSource1);
849
850 $sqlTempSourceDrop="drop table if exists $tableSource;";
851 $sqlTempSource="create temporary table if not exists $tableSource (index(temp_transno), index(temp_type1), index(temp_type2))
852 SELECT dt_transno as temp_transno, dt_type1 as temp_type1, dt_type2 as temp_type2
853 FROM $tableSource1
854 $joinSource
855 $joinJob
856 $joinTask
857 $strWhere
858 group by dt_transno, dt_type1, dt_type2;";
859 $nllDb->executeQuery($sqlTempSourceDrop);
860 $nllDb->executeQuery($sqlTempSource);
861
862
863 $joinTableSource="INNER JOIN $tableSource as c ON bill_detail.dt_transno=c.temp_transno and bill_detail.dt_type1=c.temp_type1 and dt_type2=c.temp_type2";
864}
865else
866{
867 $joinTableSource="";
868}
869// Filter Source (bk) - end
870
871if($vat_nature_type==3){
872 //yinru #28524 fix gst
873 $serial_gst = " gst_regno, ";
874 $serial_gst_update = " gst_regno='$serial_gst_regno', ";
875 $vat_tblname1_select="IF(hd_vat_type='include',0,hd_vat_amt + IF(bilctrl_mode='-',hd_vat_round*(-1),hd_vat_round)) AS hd_vat_amount,
876 (hd_vat_amt + IF(bilctrl_mode='-',hd_vat_round*(-1),hd_vat_round)) AS hd_vat_amount_ori,
877 if(hd_vat_type='include' OR hd_vat_type='exclude',1,0) AS hd_vat_type_flag,
878 body_vat.vat_code,body_vat.vat_type,body_vat.vat_rate,
879 hd_vat_type,header_vat.vat_code AS header_vat_code,
880 body_vat.vat_nature as body_vat_nature,
881 debtormst.dbtr_gst_no AS gst_regno,
882 ";
883 $vat_tblname1_join="LEFT JOIN vatmst header_vat ON hd_vat_group=header_vat.vat_no
884 LEFT JOIN vatmst AS body_vat ON dt_vat_no=body_vat.vat_no";
885 $vat_final_select="$tbl_name1.hd_vat_percent,
886 $tbl_name1.hd_vat_amount,
887 $tbl_name1.hd_vat_amount_ori,
888 IF(IFNULL($tbl_name1.dt_prdcode,0)=0 AND IFNULL($tbl_name1.dt_qty,0)=0 AND IFNULL($tbl_name1.dt_foc,0)=0,'',$tbl_name1.vat_code) AS vat_code,
889 $tbl_name1.hd_vat_type,
890 $tbl_name1.hd_vat_type2,
891 $tbl_name1.hd_vat_type_flag,
892 $tbl_name1.gst_regno,
893 $tbl_name1.header_vat_code,
894 $tbl_name1.body_vat_nature,
895 ";
896
897 //20150421 vernhui #23669 - Malaysia GST - Currency invoice printing, the product row amount column in rm shall get the value from dt, instead of by formula
898 $hd_ori_vat_amt_sql = "IF(hd_vat_type = 'include', 0, hd_vat_amt + IF(bilctrl_mode='-',hd_vat_round*(-1),hd_vat_round)) AS hd_ori_vat_amount, "; //yinru 20171120 #33034
899}
900else{
901 $vat_tblname1_select="(hd_vat_amt + hd_vat_round) AS hd_vat_amount,
902 0 AS hd_vat_type_flag,";
903 $vat_tblname1_join="";
904 $vat_final_select="$tbl_name1.hd_vat_percent,
905 $tbl_name1.hd_vat_amount,
906 $tbl_name1.hd_vat_amount AS hd_vat_amount_ori,
907 $tbl_name1.hd_vat_type2,
908 $tbl_name1.hd_vat_type_flag,
909 ";
910
911 //20150421 vernhui #23669 - Malaysia GST - Currency invoice printing, the product row amount column in rm shall get the value from dt, instead of by formula
912 $hd_ori_vat_amt_sql = "(hd_vat_amt + hd_vat_round) AS hd_ori_vat_amount, ";
913}
914
915//20160309 penghing #27049 - Hup Sheng - Inventory template dimension field want to take from product master notes
916xs_include_event("inventory_ar_bil_ord_custom_dimension");
917
918//multi-currency
919//for bill tax in the below sql SELECT hd_percent_tax,hd_mpercent_tax,hd_tax out FROM bill header
920//for notes value added sql below "concat(hd_transno, '-', hd_type1,'-',hd_type2) as notes_key," -william 22/09/2008
921//20130923 sook mun -#15795-KMM - Inventory SN able to add hd_userdefine1, hd_userdefine2,hd_userdefine3
922//20150421 vernhui #23669 - Malaysia GST - Currency invoice printing, the product row amount column in rm shall get the value from dt, instead of by formula
923//20160331 Azwan 27746 - add new column for order by condition
924//20160413 Azwan 27746 - change join productmst condition, only trigger when sort by product code
925//20160726 Azwan 29215 - cater for group child dt_assembly together when tick FOC
926if($sort_by=="dt_sorting"){
927 $prd_select="prdt_code as prd_code, IF(dt_assembly!='' AND dt_assembly=1,@dt_desc_assembly_b:=prdt_code,IF(dt_assembly!='' AND dt_assembly>1,@dt_desc_assembly_b:=@dt_desc_assembly_b,@dt_desc_assembly_b:='z')) as dt_assembly_code,";
928 $prd_join="LEFT JOIN productmst ON dt_prdcode = productmst.prdt_no";
929 $desc_assembly_select="";
930}
931else if($sort_by=="dt_desc"){
932 $prd_select="";
933 $prd_join="";
934 $desc_assembly_select="IF(dt_assembly!='' AND dt_assembly=1,@dt_desc_assembly_a:=dt_desc,IF(dt_assembly!='' AND dt_assembly>1,@dt_desc_assembly_a:=@dt_desc_assembly_a,@dt_desc_assembly_a:='z')) as dt_assembly_desc,";
935}
936else{
937 $prd_select="";
938 $prd_join="";
939 $desc_assembly_select="";
940}
941/*29777 Kella*/
942 $loc_check=getHiddenGlobalSettingValue(5000,186,90000200);
943 if ($loc_check == 1) {
944 $ptree_code= " producttree.ptree_code AS ptree_code, ";
945 $tbl_ptree_code = " $tbl_name1.ptree_code, ";
946 $ptree_code_join = " LEFT JOIN producttree ON bill_detail.dt_shelf=producttree.ptree_id ";
947 }
948/*29777 */
949$SQL = "SET @dt_desc_assembly_a:='';";
950$nllDb->executeQuery($SQL);
951$SQL = "SET @dt_desc_assembly_b:='';";
952$nllDb->executeQuery($SQL);
953
954$SQL="create TEMPORARY TABLE $tbl_name1
955 (index(dt_import_transno,
956 dt_import_type1,
957 dt_import_type2,
958 dt_import_transeqno,
959 dt_import_date,
960 dt_import_refno), index(dt_type1),index(dt_type2), index(dt_transno), index(dt_transeqno),index(dt_desc2(500)),index(dt_userdefine1(500)), index(dt_serial_number),INDEX(dt_transno,dt_transeqno,dt_type1,dt_type2))
961 SELECT
962 /*curr*/
963 /*hd_ori_amount*/
964 IF(hd_vat_type='','1','0') AS is_same_vat,
965 hd_type1,
966 hd_type2,
967 hd_transno, dt_prd_disc, concat(hd_transno, '-', hd_type1,'-',hd_type2) as notes_key,
968 hd_doc,
969 hd_no_print,
970 hd_print_no,
971 hd_invdo_print_no,
972 hd_date,
973 hd_refno,
974 hd_refno2,
975 hd_refno3,
976 hd_rate,
977 hd_amount,
978 hd_yourno,
979 hd_ourno,
980 hd_transport,
981 hd_remark,
982 hd_round,
983 hd_xround,
984 if(length(hd_remark)>110, substring(hd_remark,1,120), hd_remark) as hd_remark1,
985 if(length(hd_remark)>110, substring(hd_remark,121,130), '') as hd_remark2,
986 if(length(hd_remark)>110, substring(hd_remark,251,130), '') as hd_remark3,
987 if(length(hd_remark)>110, substring(hd_remark,381,130), '') as hd_remark4,
988 if(length(hd_remark)>110, substring(hd_remark,511,130), '') as hd_remark5,
989 hd_gross,
990 hd_customer, hd_deldate, hd_deltime, hd_deltime_to,
991 hd_add1,
992 hd_add2,
993 hd_add3,
994 hd_add4,
995 hd_o_tel,
996 hd_o_fax,
997 hd_dono,
998 hd_trandate,
999 hd_terms,
1000 hd_term_due_date,
1001 hd_name1,
1002 hd_name2,
1003 hd_discount,
1004 hd_percent,
1005 hd_mpercent,
1006 hd_percent_tax,
1007 hd_mpercent_tax,
1008 hd_tax,
1009 hd_reason_no,
1010 hd_vat_percent,
1011 $vat_tblname1_select
1012 if(hd_vat_type='include',1, 0) as hd_vat_type2,
1013 hd_attention,
1014 hd_salesman,
1015 hd_area,
1016 hd_promise_date, hd_revision_number,
1017 hd_source, hd_job,hd_task, hd_store,
1018 hd_sys_add_user ,hd_sys_last_mod_user,
1019 hd_tms_driver,
1020 hd_truck,
1021 hd_userdefine1,
1022 hd_userdefine2,
1023 hd_userdefine3,
1024 hd_pos_change_amount,
1025 SUBSTRING_INDEX(hd_prescribed_vat, '|||', -1) AS prescribed_vat,
1026 moduser.user_email as mod_usermail,
1027 adduser.user_email as add_usermail,
1028 adduser.user_login as add_username,
1029 adduser.user_login_name as add_userloginname,
1030 acct_code,
1031 acct_name1,
1032 customer_address1,
1033 customer_address2,
1034 customer_address3,
1035 customer_address4,
1036 customer_code,
1037 /*customer_first_name*/
1038 /*customer_last_name*/
1039 /*customer_password*/
1040 /*customer_classlevel_no*/
1041 /*level_no*/
1042 /*level_name1*/
1043 concat_ws('',customer_first_name, if(customer_middle_name is null, '', customer_middle_name), ' ', if(customer_last_name is null, '', customer_last_name)) as full_name,
1044 $prd_select
1045 $desc_assembly_select
1046 /*azwan*/
1047 storemst.st_gst_no as st_gst_no,
1048 /*customer_code_ord*/
1049 $ptree_code
1050 ";
1051 xs_include_event('InvBilBill');
1052
1053 if($NLL_SHIPMENT)
1054 $SQL.="
1055 hd_shp_company,
1056 hd_shp_refno1,
1057 hd_shp_refno2, hd_shp_lc_no,hd_shp_bals_order_no, hd_shp_mc_contract_no, hd_shp_container_out_date,hd_shp_close_date,
1058 hd_shp_container_in_date, hd_shp_sail_time, hd_shp_est_arrival_date, hd_shp_sail_date, hd_shp_name1, hd_shp_product_name,
1059 (select cnty_name1 from portmst inner join countrymst on port_country_no = cnty_no where port_no = hd_shp_port_to)as country_name_to,
1060 (select cnty_name1 from portmst inner join countrymst on port_country_no = cnty_no where port_no = hd_shp_port_from) as country_name_from,
1061 (select port_name1 from portmst where port_no = hd_shp_port_to)as port_name_to,
1062 (select port_name1 from portmst where port_no = hd_shp_port_from) as port_name_from,
1063 ";
1064 $SQL.="
1065 /*currINV*/
1066 dt_transno,
1067 dt_type1,
1068 dt_type2,
1069 dt_transeqno,
1070 dt_sorting,
1071 dt_prdcode,
1072 dt_desc,
1073 dt_mapcode,
1074 dt_unit,
1075 dt_qty,
1076 dt_foc,
1077 dt_foc_type,
1078 dt_rec_price as referer_price,
1079 dt_price,
1080 dt_rec_price AS dt_rec_price2,
1081 dt_percent,
1082 dt_desc2,
1083 dt_disc_item, dt_final_amount, dt_final_amount_bvat, dt_final_amount_btax,
1084 cast(0 as decimal(12,6)) as dt_disc ,cast(0 as decimal(12,6)) as dt_tax , cast(0 as decimal(12,6)) as dt_prddisc,
1085 dt_amount,
1086 dt_xprice,
1087 dt_store,
1088 dt_import_transno,
1089 dt_import_type1,
1090 dt_import_type2,
1091 dt_import_transeqno,
1092 dt_import_refno,
1093 dt_import_date,
1094 dt_deldate,
1095 dt_userdefine1 ,
1096 dt_userdefine2,
1097 dt_userdefine3,
1098 dt_userdefine4 ,
1099 dt_userdefine5 ,
1100 dt_userdefine6 ,
1101 dt_userdefine7 ,
1102 dt_userdefine8 ,
1103 dt_userdefine9 ,
1104 dt_userdefine10 ,
1105 dt_source,
1106 dt_job,
1107 dt_task,
1108 dt_assembly,
1109 dt_serial_number,
1110 dt_price_net,
1111 dt_prdt_expiry_date,
1112 dt_sst_crdt_taxexempt,
1113 '1' AS dt_assembly_level,
1114 $notes_dimension_concat
1115 bilctrl_desc,
1116 bilctrl_mode,
1117 bilctrl_flag_prefix,
1118 bilctrl_userdefine1,
1119 ROUND((dt_xamount*hd_rate),4) AS amount,
1120 /*prdt_barcode,*/
1121 '$NLL_BILL_MDISC' as mdisc,
1122 '$NLL_PRODUCT_MDISC' as mprd_disc,
1123 '$NLL_BILL_MTAX' as mtax,dt_taxable,
1124 dlto_code ,dlto_name1, dlto_name2, dlto_del1, dlto_del2, dlto_del3, dlto_del4, dlto_attention, dlto_contact_person, dlto_off_tel, dlto_fax, dlto_email,
1125 idocstat_desc, idocstat_code, hd_invdocstat
1126 ";
1127
1128//the setting only works in POS bill- ieja 20081111
1129// dt_assembly already select at above - bk (20101104) #10279
1130//if($document_type== 'POS' || $document_type == 'POR' )
1131//if($global_value=='1')
1132// {
1133// $SQL.= " , dt_assembly ";
1134// }
1135
1136
1137if($report_format == '1' && $NLL_PRD_REPACK)
1138{
1139 $SQL .= "
1140 , (case
1141 when running_no=1 then
1142 substring_index( substring_index( dt_repk_text ,@delim, 1) ,@delim,-1)
1143 when running_no=2 then
1144 substring_index( substring_index( dt_repk_text ,@delim, 2) ,@delim,-1)
1145 when running_no=3 then
1146 substring_index( substring_index( dt_repk_text ,@delim, 3) ,@delim,-1)
1147 when running_no=4 then
1148 substring_index( substring_index( dt_repk_text ,@delim, 4) ,@delim,-1)
1149 when running_no=5 then
1150 substring_index( substring_index( dt_repk_text ,@delim, 5) ,@delim,-1)
1151 when running_no=6 then
1152 substring_index( substring_index( dt_repk_text ,@delim, 6) ,@delim,-1)
1153 when running_no=7 then
1154 substring_index( substring_index( dt_repk_text ,@delim, 7) ,@delim,-1)
1155 when running_no=8 then
1156 substring_index( substring_index( dt_repk_text ,@delim, 8) ,@delim,-1)
1157 when running_no=9 then
1158 substring_index( substring_index( dt_repk_text ,@delim, 9) ,@delim,-1)
1159 else
1160 substring_index( substring_index( dt_repk_text ,@delim, 10) ,@delim,-1)
1161 end
1162 ) as repk_row,
1163 if(dt_repk_text<>'', 1, 0) as repack
1164 ";
1165}
1166
1167 //izzat #29243 - CSM - Full tax invoice need to retrieve member company name and address
1168 $auto_reg_cust_as_dbtr = getHiddenGlobalSettingValue(6000, 8000, 999999999);
1169 if ($auto_reg_cust_as_dbtr > 0) {
1170 $cust_comp_name_col = 'dbtr_cust.dbtr_name1';
1171 $cust_comp_addr1_col = 'dbtr_cust.dbtr_address1';
1172 $cust_comp_addr2_col = 'dbtr_cust.dbtr_address2';
1173 $cust_comp_addr3_col = 'dbtr_cust.dbtr_address3';
1174 $cust_comp_addr4_col = 'dbtr_cust.dbtr_address4';
1175 } else {
1176 $cust_comp_name_col = 'customer_company_name';
1177 $cust_comp_addr1_col = 'customer_company_address1';
1178 $cust_comp_addr2_col = 'customer_company_address2';
1179 $cust_comp_addr3_col = 'customer_company_address3';
1180 $cust_comp_addr4_col = 'customer_company_address4';
1181 }
1182 $SQL .= ", IF(hd_pos_member != 0, $cust_comp_name_col, '') AS member_company_name,
1183 IF(hd_pos_member != 0, $cust_comp_addr1_col, '') AS member_company_address1,
1184 IF(hd_pos_member != 0, $cust_comp_addr2_col, '') AS member_company_address2,
1185 IF(hd_pos_member != 0, $cust_comp_addr3_col, '') AS member_company_address3,
1186 IF(hd_pos_member != 0, $cust_comp_addr4_col, '') AS member_company_address4 ";
1187
1188//multi-currency // bk
1189//20083012 Eric add debtor selection
1190$SQL .= "FROM (bill_header
1191 INNER JOIN bill_detail ON hd_transno = bill_detail.dt_transno and hd_type1 = bill_detail.dt_type1 and hd_type2 = bill_detail.dt_type2
1192 INNER JOIN invdoc_status ON idocstat_id=hd_invdocstat)
1193 inner JOIN storemst ON bill_header.hd_store=storemst.st_no
1194 LEFT JOIN debtormst ON bill_header.hd_customer = debtormst.dbtr_no
1195 LEFT JOIN bill_control ON bill_header.hd_doc = bill_control.bilctrl_doc AND bill_header.hd_type2 = bill_control.bilctrl_name
1196 LEFT JOIN accountmst on accountmst.acct_no = bill_header.hd_acc_no
1197 $vat_tblname1_join
1198 $joinTableSource
1199 $notes_dimension_bil_join
1200 LEFT join usermst moduser on bill_header.hd_sys_last_mod_user = moduser.user_no
1201 LEFT join usermst adduser on bill_header.hd_sys_add_user = adduser.user_no
1202 LEFT join deltoadressmst on hd_delto=dlto_no
1203 LEFT JOIN resrve_customer ON hd_pos_member = customer_no
1204 LEFT JOIN debtormst dbtr_cust ON resrve_customer.customer_dbtr_link = dbtr_cust.dbtr_no
1205 /*resrve_classlevel_JOIN*/
1206 $prd_join
1207 $ptree_code_join
1208 /*INNER JOIN $tableSource as c ON bill_detail.dt_transno=c.temp_transno and bill_detail.dt_type1=c.temp_type1 and dt_type2=c.temp_type2*/
1209 /*AND bill_header.hd_type2 = bill_control.bilctrl_name */
1210 /*customer_code_JOIN*/
1211 /*currmst*/";
1212 xs_include_event('InvBilBill');
1213
1214if($report_format == '1' && $NLL_PRD_REPACK)
1215{
1216 $SQL .= ", (SELECT * FROM running_no order by running_no limit 10) as a ";
1217}
1218
1219
1220if (!$store_from){
1221 $result_initstore= $nllDb->executeQuery("SELECT st_code FROM storemst ORDER BY st_code ASC");
1222 list($store_from) = $nllDb->fetchRow($result_initstore);
1223}
1224if (!$store_to){
1225 $result_initstore= $nllDb->executeQuery("SELECT st_code FROM storemst ORDER BY st_code DESC");
1226 list($store_to) = $nllDb->fetchRow($result_initstore);
1227}
1228
1229// bk
1230$NLL_STORE=$_SESSION['act308'];
1231if(($store_from!=$source_to) || !$NLL_STORE)
1232 $store_null=" OR storemst.st_code is null";
1233
1234
1235if($from_acc!=''){
1236 $whereCondition = "WHERE hd_doc = 'AR-BIL' AND hd_type2 = '$doc_type'
1237 AND (hd_refno $strBillWhere $whereBillRefnoList) $whereBillPrdt_List $taxgroupWhere $salesmanWhere $termWhere $strRecordNoWhere $tmsdrivermstWhere and dt_transeqno > 0 $strOwnDocument";
1238
1239}else{
1240 //#13163 - set xeersearch default values if parameter not exists
1241 if($store_from != "" && $store_to != ""){
1242 $wherestore = "AND ((storemst.st_code BETWEEN '$store_from' AND '$store_to')".$store_null.")";
1243 }
1244 $whereCondition = "WHERE hd_doc = 'AR-BIL' AND hd_type2 = '$doc_type' /*and (hd_active is null or hd_active = 1)*/
1245and if(idocstat_print_status = 1 , 1 , 0)
1246AND (hd_date BETWEEN '$from_date' AND '$to_date') $sql_FromToExp
1247AND (hd_refno $strBillWhere $whereBillRefnoList) $whereBillPrdt_List and dt_transeqno > 0
1248$strRecordNoWhere
1249$strOwnDocument
1250$strdebtor
1251$taxgroupWhere
1252$salesmanWhere
1253$termWhere
1254$tmsdrivermstWhere
1255$wherestore
1256$where_hide_cancelled";
1257}
1258
1259 //20130612 Yinru #16752 - Fiamma - Inventory AR Print DO from Invoice Count
1260 if($type=='I' && $IDO_COUNT=='1'){
1261 if($print_type=='INV')
1262 $print_date_field = "hd_sys_last_print_date";
1263 else if($print_type=='DO')
1264 $print_date_field = "hd_invdo_sys_last_print_date";
1265 }
1266 else{
1267 $print_date_field = "hd_invdo_sys_last_print_date";
1268 }
1269
1270 //20130527 william 16291
1271 // check for printed parameter
1272 $s_printedSearch = $_GET["s_printedSearch"];
1273 switch($s_printedSearch) {
1274 case 1:
1275 $whereCondition .= " AND $print_date_field = '0000-00-00 00:00:00'";
1276 break;
1277 case 2:
1278 $whereCondition .= " AND $print_date_field != '0000-00-00 00:00:00'";
1279 break;
1280 default:
1281 break;
1282 }
1283 //END - check for printed parameter
1284
1285$SQL .= "$whereCondition";
1286
1287//the setting only works in POS bill - ieja 20081111
1288if($document_type== 'POS' || $document_type == 'POR' )
1289if($global_value=='1')
1290 {
1291 $SQL.= " AND (dt_assembly IN ('','1','3','5'))";
1292 }
1293
1294//20150625 jiteck - #24333
1295if($hide_child_item=="1"){
1296 // $SQL.= " AND (dt_assembly = '1' OR dt_assembly = '' OR dt_assembly is NULL)";
1297
1298 // 20190830 Ben #37869
1299 $unit_child_ignore_by_uom = trim($unit_child_ignore_by_uom);
1300 $SQL .= ($unit_child_ignore_by_uom === "") ? " AND (dt_assembly = '1' OR dt_assembly = '' OR dt_assembly is NULL) " : "";
1301 // end #37869
1302}
1303
1304if($report_format == '1' && $NLL_PRD_REPACK)
1305{
1306 $SQL .= " group by repk_row, dt_transno, dt_transeqno
1307 having (repk_row<>'' and repack=1) or repack=0
1308 ";
1309}
1310
1311if($_SESSION["act375"]) {
1312 $SQL .= " $notes_dimension_gp ORDER BY hd_refno, dt_sorting, dt_transeqno;";
1313 $sql_order=" ORDER BY hd_refno, dt_sorting, dt_transeqno;";
1314}
1315else{
1316 //$SQL .= " $notes_dimension_gp ORDER BY hd_refno, dt_transeqno;";
1317 //$sql_order=" ORDER BY hd_refno, dt_transeqno;";
1318
1319 //20160330 Azwan 27746 - change order by condition
1320 if($sort_by=="dt_desc"){
1321 $SQL .= " $notes_dimension_gp ORDER BY hd_refno, dt_assembly_desc, dt_assembly, dt_desc, dt_transeqno;";
1322 $sql_order=" ORDER BY hd_refno, dt_assembly_desc, dt_assembly, dt_desc, dt_transeqno;";
1323 }
1324 else if($sort_by=="dt_sorting"){
1325 $SQL .= " $notes_dimension_gp ORDER BY hd_refno, dt_assembly_code, dt_assembly, prd_code, dt_transeqno;";
1326 $sql_order=" ORDER BY hd_refno, dt_assembly_code, dt_assembly, prd_code, dt_transeqno;";
1327 }
1328 else{
1329 $SQL .= " $notes_dimension_gp ORDER BY hd_refno, dt_transeqno;";
1330 $sql_order=" ORDER BY hd_refno, dt_transeqno;";
1331 }
1332}
1333
1334$SQL = $MultiCurr->convertSQL($SQL,"hd_currency", ''); //multi-currency
1335
1336//20150421 vernhui #23669 - Malaysia GST - Currency invoice printing, the product row amount column in rm shall get the value from dt, instead of by formula
1337$hd_ori_amount_sql = " hd_amount AS hd_ori_amount, hd_gross AS hd_ori_gross, hd_discount AS hd_ori_discount, hd_tax AS hd_ori_tax,
1338 hd_vat_amt AS hd_ori_vat_amt, hd_vat_round AS hd_ori_vat_round,
1339 hd_round AS hd_ori_round, hd_xamount AS hd_xamount,
1340 $hd_ori_vat_amt_sql
1341 dt_amount AS dt_ori_amount, dt_price AS dt_ori_price, dt_final_amount_btax AS dt_ori_final_amount_btax, dt_final_bil_tax_amount, dt_final_bil_tax_rate,
1342 dt_price_net AS dt_ori_price_net, dt_final_amount AS dt_ori_final_amount,
1343 dt_final_vat_amount AS dt_ori_final_vat_amount, dt_xamount AS dt_xamount, ";
1344$SQL = str_replace ("/*hd_ori_amount*/", " $hd_ori_amount_sql ", $SQL);
1345
1346//echo $SQL;die();
1347$nllDb->query($SQL);
1348
1349// 20190830 Ben #37869
1350if ($hide_child_item == "1" && $unit_child_ignore_by_uom !== ""){
1351 $arr_unit_child = explode(",", $unit_child_ignore_by_uom);
1352 foreach ($arr_unit_child as $key => $val) {
1353 $arr_unit_child[$key] = trim($val);
1354 }
1355 $notInUnit = " '" . implode("', '", $arr_unit_child) . "' ";
1356 $sql_unit_count = "SELECT DISTINCT dt_unit, COUNT(1) FROM " . $tbl_name1 . "
1357 WHERE dt_unit IN (" . $notInUnit . ") AND
1358 (dt_assembly <> '1' AND dt_assembly <> '' AND dt_assembly IS NOT NULL) AND dt_unit <> ''
1359 GROUP BY dt_unit; ";
1360 $res_count = $nllDb->executeQuery($sql_unit_count);
1361 $num_row = $nllDb->num_rows($res_count);
1362 $nlldb->freeResult($res_count);
1363
1364 $filterSql = "DELETE FROM " . $tbl_name1 . " WHERE (dt_assembly <> '1' AND dt_assembly <> '' AND dt_assembly is NOT NULL) ";
1365 $createIdx = "ALTER TABLE `" . $tbl_name1 . "` ADD INDEX ";
1366
1367 if ($num_row !== 0){
1368 $filterSql .= " AND dt_unit IN (" . $notInUnit . ") ;";
1369 $nllDb->executeQuery($createIdx . " `dt_unit` (`dt_unit`) ");
1370 }
1371
1372 $nllDb->executeQuery($createIdx . " `dt_assembly` (`dt_assembly`) ");
1373 $nllDb->executeQuery($filterSql);
1374 unset($notInUnit, $sql_unit_count, $res_count, $num_row, $filterSql, $createIdx, $arr_unit_child);
1375}
1376// end #37869
1377
1378//20150925 sook mun #25176
1379xs_include_event('inv_ar_cn_join_inv_tkp');
1380
1381// Ecommerce Delivery Address - bk (20171005) 32698
1382$tpl_ecommerce=getHiddenGlobalSettingValue(5900,5909,90000200);
1383if($tpl_ecommerce==$template && $tpl_ecommerce!=''){
1384 $sql_ecom="UPDATE $tbl_name1 INNER JOIN xs_ecom_order_header ON ehd_transno=dt_transno AND ehd_type1=dt_type1 AND ehd_type2=dt_type2
1385 SET hd_attention=ehd_del_person, hd_o_tel=ehd_del_phone, hd_add1=ehd_del_address1, hd_add2=ehd_del_address2, hd_add3=CONCAT(ehd_del_postcode,' ',ehd_del_city,', ',ehd_del_state), hd_add4=''
1386 ";
1387 $nllDb->query($sql_ecom);
1388}
1389
1390//yinru @ 20170611 #31730 - repacking based on master formula
1391if($master_repack=='1'){
1392 list($master_repack_field ,$master_repack_join,$master_repack_group) = explode("||||",get_master_repacking($nlldb,$tbl_name1,$tbl_name1));
1393}
1394
1395$alter_zr_sql="ALTER TABLE $tbl_name1 ADD COLUMN zr_flag VARCHAR(1) DEFAULT 0;";
1396$nllDb->query($alter_zr_sql);
1397$select_bill_sql="SELECT hd_type1,hd_type2,hd_transno FROM $tbl_name1 GROUP BY hd_type1,hd_type2,hd_transno;";
1398$bill_res=$nllDb->executeQuery($select_bill_sql);
1399
1400while($row_bill=$nllDb->fetchArray($bill_res)){
1401 $t1=$row_bill['hd_type1'];
1402 $t2=$row_bill['hd_type2'];
1403 $trans_no=$row_bill['hd_transno'];
1404
1405 $tbl_summary = uniqid("tmp_tbl_summary_");
1406 $nllDb->executeQuery("DROP TABLE IF EXISTS $tbl_summary");
1407
1408 $create_summary_sql="CREATE TEMPORARY TABLE $tbl_summary SELECT vat_nature FROM bill_detail INNER JOIN vatmst ON dt_vat_no=vat_no WHERE dt_type1='$t1' AND dt_type2='$t2' AND dt_transno='$trans_no' GROUP BY vat_nature;";
1409 $nllDb->executeQuery($create_summary_sql);
1410
1411 $c_row_sql="SELECT COUNT(1) as c_row FROM $tbl_summary ;";
1412
1413 $res_count=$nllDb->executeQuery($c_row_sql);
1414 list($c_row)=$nllDb->fetchRow($res_count);
1415
1416 if($c_row==1){
1417 $zr_row_sql="SELECT COUNT(1) AS zr_row FROM $tbl_summary WHERE vat_nature IN('ZR','IM');";
1418
1419 $res_zr_count=$nllDb->executeQuery($zr_row_sql);
1420 list($zr_row)=$nllDb->fetchRow($res_zr_count);
1421 if ($zr_row>0){
1422 $update_zr_flag="UPDATE $tbl_name1 SET zr_flag=1 WHERE dt_type1='$t1' AND dt_type2='$t2' AND dt_transno='$trans_no'; ";
1423 $nllDb->executeQuery($update_zr_flag);
1424 }
1425 }
1426}
1427
1428$act_astrick_display = getHiddenGlobalSettingValue(1500,43,90000200); //20150410 May #23431
1429 if ($vat_nature_type==3 && $act_astrick_display == '0'){
1430 //20150312-ky-22927
1431/*$sql_vat="SELECT vat_type,vat_rate FROM $tbl_name1 WHERE dt_prdcode!=0;";
1432 $result_vat=$nllDb->executeQuery($sql_vat);
1433 unset($vat_type,$vat_rate,$is_same_vat);
1434 while($row_dbtr=$nllDb->fetchArray($result_vat)){
1435 $vat_type[]=$row_dbtr['vat_type'];
1436 $vat_rate[]=$row_dbtr['vat_rate'];
1437 }
1438 if (count(array_unique($vat_type)) == 1 && end($vat_type) == 'Exemption' || count(array_unique($vat_type)) ==1 && count(array_unique($vat_rate)) == 1 && end($vat_rate) == 0)
1439 {
1440 $is_same_vat=1;
1441 }*/
1442
1443 //20150514 May #24188
1444 $tmpIsSameVat = uniqid("tmp_IsSameVat");
1445 $sqlTempIsSameVatDrop1="DROP TABLE IF EXISTS $tmpIsSameVat;";
1446 $sqlTempIsSameVat1="CREATE TEMPORARY TABLE $tmpIsSameVat (index(hd_transno), index(hd_type1), index(hd_type2))
1447 SELECT COUNT(DISTINCT(IF(vat_type IN('include', 'exclude'), 1, 2))) AS type, COUNT(DISTINCT(vat_rate)) AS rate, hd_transno, hd_type1, hd_type2
1448 FROM $tbl_name1 WHERE vat_type IS NOT NULL AND vat_type <> ''
1449 GROUP BY hd_transno, hd_type1, hd_type2;";
1450 $nllDb->executeQuery($sqlTempIsSameVatDrop1);
1451 $nllDb->executeQuery($sqlTempIsSameVat1);
1452
1453 $same_vat_sql2="UPDATE $tbl_name1 INNER JOIN $tmpIsSameVat a ON a.hd_transno=dt_transno AND a.hd_type1=dt_type1 AND a.hd_type2=dt_type2 SET is_same_vat=1 WHERE type=1 AND rate=1;";
1454 $nllDb->query($same_vat_sql2);
1455
1456 }
1457
1458xs_include_event("custom_inv_rpt_ar_bil_bill_dt1"); //lengwee - custom php in GP Motor
1459
1460 // ky-15394
1461 if($separate_by_debtor==1){
1462 $dbAccess = new nllDbAccessExecution();
1463 $from_date = $_SESSION['nllGlobalDate']->toDisplay($from_date);
1464 $to_date = $_SESSION['nllGlobalDate']->toDisplay($to_date);
1465 //get selected debtor
1466 $sql_dbtr="SELECT dbtr_no, dbtr_code, dbtr_name1 FROM $tbl_name1
1467 INNER JOIN debtormst ON debtormst.dbtr_no = $tbl_name1.hd_customer
1468 GROUP BY dbtr_no;";
1469 $result_dbtr=$dbAccess->executeQuery($sql_dbtr);
1470 unset($debtor_no);
1471 $i=0;
1472 while($row_dbtr=$dbAccess->fetchArray($result_dbtr)){
1473 $debtor_no=$row_dbtr['dbtr_no'];
1474 $debtor_code=$row_dbtr['dbtr_code'];
1475 $debtor_name=$row_dbtr['dbtr_name1'];
1476 $i+=1;
1477 $debtor_link.= '<a class="BlueNoteDataLink" onclick="window.open(this.href,\'_blank\',\'WIDTH=1000,HEIGHT=650,LEFT=200,scrollbars=yes,resizable=yes\');return false;" href="inv_rpt_ar_bil_bill_dt1.php?doc_type='.$doc_type.'&bill_from='.$bill_from.'&bill_to='.$bill_to.'&recordno_from='.$recordno_from.'&recordno_to='.$recordno_to.'&billrefno_list='.$billrefno_list.'&from_date='.$from_date.'&to_date='.$to_date.'&chkFOC='.$chkFOC.'&chkReprint='.$chkReprint.'&report_format='.$report_format.'&print_type='.$print_type.'&currselection='.$currselection.'&allcurr='.$allcurr.'&chkSource='.$chkSource.'&chkJob='.$chkJob.'&chkTask='.$chkTask.'&chkRecordNo='.$chkRecordNo.'&show_assembly_child='.$show_assembly_child.'&filter_assembly_main_product='.$filter_assembly_main_product.'&with_outstanding='.$with_outstanding.'&show_order_info='.$show_order_info.'&chk_ageing='.$chk_ageing.'&source_from='.$source_from.'&source_to='.$source_to.'&store_from='.$store_from.'&store_to='.$store_to.'&job_from='.$job_from.'&job_to='.$job_to.'&task_from='.$task_from.'&task_to='.$task_to.'&s_printedSearch='.$s_printedSearch.'&EDIExport='.$EDIExport.'&EDIPdf='.$EDIPdf.'&store1_from='.$store1_from.'&store1_to'.$store1_to.'=&consolidate='.$consolidate.'&template='.$template.'&barcode='.$barcode.'&currselection='.$currselection.'&allcurr='.$allcurr.'&s_template='.$s_template.'&payment_type='.$payment_type.'&s_hd_customer='.$debtor_code.'&s_hd_customers='.$debtor_code.'&printToExcel='.$printToExcel.'&printToExcelRaw='.$printToExcelRaw.'&printToPDF='.$printToPDF.'&printToPDFType='.$printToPDFType.'&emailReport='.$emailReport.'&emailAddress='.$emailAddress.'&removeFixedTable='.$removeFixedTable.'&portrait='.$portrait.'&emailReportAddress='.$emailReportAddress.'&consolidate='.$consolidate.'&st_no='.$st_no.'">'.$i.') '.$debtor_code.' : '.$debtor_name.'</a><br/>';
1478 }
1479 if($debtor_link!=''){
1480 echo '<h3><u>Seperate By Debtor</u></h3>';
1481 echo $debtor_link;
1482 }
1483 else
1484 {
1485 echo 'no records';
1486 }
1487 }
1488
1489$SQL = "UPDATE $tbl_name1 SET dt_price_net = ABS(dt_price_net);";
1490$nllDb->query($SQL);
1491
1492//#8778 - Extract value from existing table
1493$tbl_name_credit1 = uniqid("tmp_tbl_credit_");
1494$cn_sql = "SELECT hd_gross,hd_discount,hd_percent_tax FROM $tbl_name1";
1495$cn_result = $nlldb->executeQuery($cn_sql);
1496$cn_row = $nlldb->fetchArray($cn_result);
1497
1498$cn_gross = $cn_row['hd_gross'];
1499$cn_discount = $cn_row['hd_discount'];
1500$cn_tax_percent = $cn_row['hd_percent_tax'];
1501
1502$cn_tax = (((-1)*$cn_gross)-$cn_discount)*($cn_tax_percent/100);
1503
1504
1505// show assembly child - bk (20090804) #6474
1506if($show_assembly_child=="1"){
1507 $tbl_select_final=uniqid("tmp_select_final_");
1508
1509 $sql_create_final="
1510 CREATE TEMPORARY TABLE $tbl_select_final (index(dt_import_transno, dt_import_type1, dt_import_type2, dt_import_transeqno, dt_import_refno))
1511 SELECT * FROM $tbl_name1
1512 ";
1513 $nllDb->executeQuery($sql_create_final);
1514
1515
1516 $sql_select_temp="SELECT * FROM $tbl_select_final LIMIT 1";
1517 $result_select_temp=$nllDb->executeQuery($sql_select_temp);
1518 $fieldname=$nllDb->getFieldsName1($result_select_temp);
1519
1520 $fieldname=str_replace("dt_prdcode,","prdt_no,",$fieldname);
1521 $fieldname=str_replace("dt_desc,","prdt_name1,",$fieldname);
1522 $fieldname=str_replace("dt_qty,","(dt_qty*asbly_qty*(-1)),",$fieldname);
1523 $fieldname=str_replace("dt_amount,","'' AS dt_amount,",$fieldname);
1524 $fieldname=str_replace("dt_price,","'' AS dt_price,",$fieldname);
1525 $fieldname=str_replace("dt_unit,","prdt_unit,",$fieldname);
1526 $tbl_select=uniqid("tmp_select_");
1527 $assembly_child="0";
1528 $assembly_level=1;
1529 do{
1530 $fieldname1=str_replace("dt_assembly_level,","'".($assembly_level+1)."' AS dt_assembly_level,",$fieldname);
1531
1532 $sql_select_drop="DROP TABLE IF EXISTS $tbl_select";
1533 $nllDb->executeQuery($sql_select_drop);
1534 $sql_select="
1535 CREATE TEMPORARY TABLE $tbl_select (index(dt_import_transno, dt_import_type1, dt_import_type2, dt_import_transeqno, dt_import_refno))
1536 SELECT $fieldname1 FROM $tbl_select_final
1537 INNER JOIN assemblymst ON dt_prdcode=asbly_product_no
1538 INNER JOIN productmst ON asbly_component_no=prdt_no
1539 WHERE dt_assembly_level='$assembly_level' AND ((dt_assembly!='1' AND dt_assembly!='2') OR (dt_assembly='2' AND asbly_before_sales='1'))";
1540 $nllDb->executeQuery($sql_select);
1541
1542 $sql_count="SELECT COUNT(1) FROM $tbl_select";
1543 $result_count=$nllDb->executeQuery($sql_count);
1544 list($assembly_child)=$nllDb->fetchRow($result_count);
1545
1546 if($assembly_child>"0"){
1547 $sql_insert="INSERT INTO $tbl_select_final SELECT * FROM $tbl_select";
1548 $result_insert=$nllDb->executeQuery($sql_insert);
1549 }
1550
1551 $assembly_level++;
1552 }while($assembly_child!="0" && $assembly_level<50);
1553
1554 $nllDb->executeQuery("TRUNCATE TABLE $tbl_name1");
1555 $nllDb->executeQuery("INSERT INTO $tbl_name1 SELECT * FROM $tbl_select_final $sql_order");
1556}
1557
1558//azie-20070911-start- to convert dt_desc2 to format a+b+c
1559//eric - 20080903 - dt_userdefine1 for dimension format AxBxC
1560 $SQL = "SELECT dt_transno, dt_transeqno, dt_type1, dt_type2, dt_desc2, dt_userdefine1, dt_qty ";
1561
1562//the setting only works in POS bill - ieja 20081111
1563if($document_type== 'POS' || $document_type == 'POR' )
1564if($global_value=='1')
1565 {
1566 $SQL.= " , dt_assembly ";
1567 }
1568
1569if($from_acc!=''){
1570 $whereCondition="AND (hd_refno $strBillWhere $whereBillRefnoList) $whereBillPrdt_List $taxgroupWhere $salesmanWhere $termWhere $strRecordNoWhere $strOwnDocument $tmsdrivermstWhere";
1571}else{
1572//#13163 - set xeersearch default values if parameter not exists
1573 if($store_from != "" && $store_to != ""){
1574 $wherestore = "AND ((storemst.st_code BETWEEN '$store_from' AND '$store_to')".$store_null.") ";
1575 }
1576 $whereCondition="AND (hd_refno $strBillWhere $whereBillRefnoList) $whereBillPrdt_List $taxgroupWhere $salesmanWhere $termWhere $strRecordNoWhere $tmsdrivermstWhere
1577 AND (hd_date BETWEEN '$from_date' AND '$to_date') $sql_FromToExp
1578 $strOwnDocument";
1579}
1580$SQL.= " FROM bill_detail
1581 INNER JOIN bill_header on dt_transno=hd_transno and dt_type1=hd_type1 and dt_type2=hd_type2
1582 LEFT JOIN storemst on st_no=hd_store
1583 WHERE hd_doc='AR-BIL' and dt_type2='$doc_type'
1584 $wherestore $whereCondition ";
1585
1586if($global_value=='1')
1587 {
1588 $SQL.= " AND dt_assembly = '1'";
1589 }
1590
1591 $result = $nllDb->executeQuery($SQL);
1592 while ($row = $nllDb->fetchArray($result, MYSQL_BOTH))
1593 {
1594 $dt_desc2 = $row['dt_desc2'];
1595 $transno= $row['dt_transno'];
1596 $transeqno = $row['dt_transeqno'];
1597 $type1 = $row['dt_type1'];
1598 $type2 = $row['dt_type2'];
1599 $userdefine1 = $row['dt_userdefine1'];
1600
1601 $num=substr_count($dt_desc2, "+");
1602 $sign=substr_count($userdefine1, "x");
1603
1604
1605
1606
1607 if($sign != 0 && $s_template=='thp_inv_rpt_ar_bil_inv.tpl')
1608 {
1609 $SQL ="UPDATE $tbl_name1 SET dt_userdefine1 = '' WHERE dt_userdefine1 is null or dt_userdefine1 = '';";
1610 //$nllDb->query($SQL);
1611
1612
1613 $SQL ="UPDATE $tbl_name1 SET dt_userdefine3 = SUBSTRING_INDEX(SUBSTRING_INDEX('$userdefine1', 'x', 2), 'x',1)*
1614 SUBSTRING_INDEX(SUBSTRING_INDEX('$userdefine1', 'x', 2), 'x',-1) *
1615 SUBSTRING_INDEX('$userdefine1', 'x', -1)*0.000000016*dt_qty
1616 WHERE dt_userdefine1 like '%x%';";
1617 $nllDb->query($SQL);
1618
1619
1620 }
1621
1622
1623
1624 if($num==0)
1625 {
1626 $SQL = "UPDATE $tbl_name1 SET dt_desc2=concat(dt_desc2, '+0+0') WHERE dt_type1='$type1' and dt_type2='$type2' and dt_transno=$transno and dt_transeqno=$transeqno and dt_desc2 not like '%+%'
1627 and dt_desc2 is not null and dt_desc2<>'' and dt_desc2 not like '%+%+%';";
1628 $nllDb->query($SQL);
1629 }
1630 if($num==1)
1631 {
1632 $SQL = "UPDATE $tbl_name1 SET dt_desc2=concat(dt_desc2, '+0') WHERE dt_type1='$type1' and dt_type2='$type2' and dt_transno=$transno and dt_transeqno=$transeqno and dt_desc2 is not null
1633 and dt_desc2<>'' and dt_desc2 not like '%+%+%';";
1634 $nllDb->query($SQL);
1635 }
1636 }
1637//azie-20070911-end- convert dt_desc2 to format a+b+c
1638
1639
1640
1641
1642$SQL = "ALTER TABLE $tbl_name1 ADD rec_no1 integer not null first; ";
1643$nllDb->executeQuery($SQL);
1644
1645$SQL = "ALTER TABLE $tbl_name1 ADD rec_no integer not null auto_increment first, add primary key (rec_no) ; ";
1646$nllDb->executeQuery($SQL);
1647
1648$SQL = "ALTER TABLE $tbl_name1 ADD INDEX product (dt_prdcode), ADD INDEX debtor (hd_customer), ADD INDEX term (hd_terms), ADD INDEX Salesman (hd_salesman), Add Index(hd_refno2); ";
1649$nllDb->executeQuery($SQL);
1650
1651//#8778 - insert value
1652$SQL = "ALTER TABLE $tbl_name1 ADD cn_tax float not null first; ";
1653$nllDb->executeQuery($SQL);
1654$SQL = "UPDATE $tbl_name1 SET cn_tax = '$cn_tax'";
1655$nllDb->executeQuery($SQL);
1656
1657
1658//reset rec_no to null for row no > 1
1659$sql = "SELECT * FROM $tbl_name1;";
1660$result_temp = $nllDb->executeQuery($sql);
1661
1662//20140716 ida #18402 - to show final approve user from workflow
1663$SQL="SELECT dt_transno, dt_type1, dt_type2 FROM $tbl_name1 LIMIT 1";
1664$RESULT_BILL_DETAIL=$nllDb->executeQuery($SQL);
1665while ($row = mysql_fetch_array($RESULT_BILL_DETAIL, MYSQL_BOTH)){
1666 $transo=$row[0];
1667 $type1=$row[1];
1668 $type2=$row[2];
1669}
1670
1671if($result_temp<>"")
1672{
1673 $SQL = "UPDATE $tbl_name1 SET hd_amount = 0 WHERE dt_transeqno > 1; ";
1674 $nllDb->executeQuery($SQL);
1675
1676}
1677$nllDb->freeResult($result_temp);
1678
1679if($_SESSION['Audit']==1)
1680{
1681 $sql = "SELECT distinct hd_transno,hd_type1,hd_type2,hd_no_print,hd_print_no FROM $tbl_name1;";
1682 $result = $nllDb->executeQuery($sql);
1683 if($result<>"")
1684 {
1685 while ($row = $nllDb->fetchArray($result, MYSQL_BOTH))
1686 {
1687 $audit_transno = $row['hd_transno'];
1688 $audit_type1 = $row['hd_type1'];
1689 $audit_type2 = $row['hd_type2'];
1690 $audit_no_print = $row['hd_print_no'];
1691 AuditList($nllDb,$audit_transno,$audit_type1,$audit_type2,$audit_no_print);
1692
1693 }
1694 }
1695$nllDb->freeResult($result);
1696}
1697
1698//20140716 ida #18402 - to show final approve user from workflow
1699$sql = "DROP TABLE IF EXISTS $tbl_name10 ;";
1700$nllDb->executeQuery($sql);
1701
1702$sql_workflow="CREATE temporary TABLE $tbl_name10
1703 SELECT wf_logic_login,wf_linked_documents FROM workflow_process
1704 INNER JOIN workflow_definition ON workflow_process.wf_workflow_id=workflow_definition.wf_workflow_id AND workflow_process.wf_workflow_state=workflow_definition.wf_workflow_state AND
1705 IF(workflow_process.wf_workflow_state2=1,workflow_definition.wf_next_state1=9999,
1706 IF(workflow_process.wf_workflow_state=2,workflow_definition.wf_next_state2=9999,
1707 IF(workflow_process.wf_workflow_state2=3,workflow_definition.wf_next_state3=9999,
1708 IF(workflow_process.wf_workflow_state2=4,workflow_definition.wf_next_state4=9999,workflow_definition.wf_next_state5=9999)
1709 )
1710 )
1711 ) WHERE wf_linked_documents LIKE '%hd_transno=$transo&hd_type1=$type1&hd_type2=$type2%' ORDER BY wf_id DESC LIMIT 1;";
1712
1713$nllDb->executeQuery($sql_workflow);
1714xs_include_event("inv_workflow_approve_user");
1715
1716
1717
1718
1719$SQL = "set @delim2 := '|';";
1720$nllDb->executeQuery($SQL);
1721$SQL="set @counter :=1;";
1722$nllDb->executeQuery($SQL);
1723$SQL="set @flag:='';";
1724$nllDb->executeQuery($SQL);
1725$SQL="set @current:=(SELECT concat(dt_transno, '-',dt_type1, '-', dt_type2) FROM $tbl_name1 limit 1);";
1726$nllDb->executeQuery($SQL);
1727$SQL="set @as_current:=@current;";
1728$nllDb->executeQuery($SQL);
1729$SQL="set @as_counter :=0;";
1730$nllDb->executeQuery($SQL);
1731$SQL="set @as_counter1 :=1;";
1732$nllDb->executeQuery($SQL);
1733//20170704 May #31937
1734$SQL="set @counter2 :=1;";
1735$nllDb->executeQuery($SQL);
1736$SQL="set @flag2:='';";
1737$nllDb->executeQuery($SQL);
1738//saha credit note and debit note to take Original INV info FROM refno2
1739
1740//added by Yinru 20091105 #7688
1741$SQL="set @dt_userdefine2 :='';";
1742$nllDb->executeQuery($SQL);
1743
1744if(strstr($s_template,'saha_credit_note') || strstr($s_template,'saha_debit_note')){
1745 $TaxInvJoin = " left join bill_header on $tbl_name1.hd_refno2 = bill_header.hd_refno and bill_header.hd_customer = $tbl_name1.hd_customer ";
1746 $TaxInvFields = ",DATE_FORMAT(bill_header.hd_date, '%d/%m/%Y') as taxInv_date, (bill_header.hd_gross - bill_header.hd_discount) as taxInv_amount ";
1747}
1748
1749//20100206 Yinru #8389 - FD format customization
1750if($s_template=="inv_rpt_ar_bil_bill_inv_preprinted_fd.tpl" || $s_template == 'inv_rpt_ar_bil_inv_LiiHen_usd_only.tpl' || $s_template == 'inv_rpt_ar_bil_bill_inv_fd_non_tax.tpl' || $s_template == 'inv_rpt_ar_bil_bill_inv_fd_non_gst_table.tpl'){
1751 $DOJoin = " left join bill_detail on bill_detail.dt_type1 = $tbl_name1.dt_import_type1 and bill_detail.dt_type2=$tbl_name1.dt_import_type2 and bill_detail.dt_transno=$tbl_name1.dt_import_transno and bill_detail.dt_transeqno = $tbl_name1.dt_import_transeqno
1752 left join bill_header on bill_header.hd_type1 = bill_detail.dt_type1 and bill_header.hd_type2=bill_detail.dt_type2 and bill_header.hd_transno=bill_detail.dt_transno ";
1753 $do_container = " ,concat(bill_header.hd_shp_lc_no,' / ',bill_header.hd_shp_bals_order_no) as do_container, concat(bill_header.hd_refno2,' / ', bill_header.hd_refno3,' / ', bill_header.hd_refno) as do_popi ";
1754}
1755
1756if($s_template=="inv_rpt_ar_bil_pack_list_fd.tpl"){
1757$DOJoin = " left join bill_detail on $tbl_name1.dt_type1=bill_detail.dt_import_type1 and $tbl_name1.dt_type2=bill_detail.dt_import_type2 and $tbl_name1.dt_transno=bill_detail.dt_import_transno and $tbl_name1.dt_transeqno=bill_detail.dt_import_transeqno
1758 left join bill_header on bill_header.hd_type1 = bill_detail.dt_type1 and bill_header.hd_type2=bill_detail.dt_type2 and bill_header.hd_transno=bill_detail.dt_transno ";
1759 $do_container = " ,bill_header.hd_refno as invoice_no ";
1760}
1761//end 20100206 Yinru #8389
1762
1763//serial no. - yip
1764$field = "";
1765$join_tbl = "";
1766//yinru@20100830#9044
1767$t_sql= "select rpt_org_format from reportformat where rpt_format='$s_template' order by rpt_report limit 1";
1768$t_result = $nllDb->executeQuery($t_sql);
1769list($orig_template) = $nllDb->fetchRow($t_result);
1770
1771if(strpos($s_template,"_with_serial")!==false || strpos($orig_template,"_with_serial")!==false){
1772 $tbl_name8 = uniqid("tmp_tbl8_ar_bil_");
1773 $tbl_name9 = uniqid("tmp_tbl9_ar_bil_");
1774
1775 $SQL="set @serialno :='';";
1776 $nllDb->executeQuery($SQL);
1777 $SQL="set @serialprdt :='';";
1778 $nllDb->executeQuery($SQL);
1779 $SQL="set @serialprdtseq :='';";
1780 $nllDb->executeQuery($SQL);
1781
1782 $d_temp1 = "drop table if exists $tbl_name8;";
1783 $nllDb->executeQuery($d_temp1);
1784 $temp1 = "create temporary table $tbl_name8
1785 SELECT * FROM product_serial_bill
1786 WHERE pse_bill_refno $strBillWhere $whereBillRefnoList_bill and pse_bill_type1='AR' and pse_bill_type2='$doc_type'
1787 order by pse_bill_prdt_no;";
1788 $nllDb->executeQuery($temp1);
1789
1790 $d_temp2 = "drop table if exists $tbl_name9;";
1791 $nllDb->executeQuery($d_temp2);
1792 $temp2 = "create temporary table $tbl_name9
1793 SELECT max(if(@serialprdt=pse_bill_prdt_no, if(@serialprdtseq=pse_bill_prdt_seq_no, @serialno := concat(@serialno,',',pse_bill_serial_no), @serialno:=pse_bill_serial_no), @serialno:=pse_bill_serial_no)) as serial_no,
1794 pse_bill_prdt_no, pse_bill_prdt_seq_no, @serialprdt:=pse_bill_prdt_no, @serialprdtseq:=pse_bill_prdt_seq_no FROM $tbl_name8 group by concat(pse_bill_prdt_no,'-',pse_bill_prdt_seq_no);
1795 ";
1796 $nllDb->executeQuery($temp2);
1797 $nllDb->executeQuery("alter table $tbl_name9 add index(pse_bill_prdt_no);");
1798
1799 $field = ", serial_no ";
1800 $join_tbl = " left join $tbl_name9 on productmst.prdt_no=pse_bill_prdt_no and dt_transeqno=pse_bill_prdt_seq_no ";
1801
1802}
1803
1804
1805//for elk - discount amount put at row of each product (use row based discount, product type discount) - ida
1806if($s_template=="elk_invoice2.tpl" || $s_template== "elk_invoice_disc2.tpl" || $s_template== "elk_delivery_order.tpl" )
1807{
1808$tbl_name8 = uniqid("tmp1_tbl_");
1809$SQL="set @point:=0;";
1810$nllDb->executeQuery($SQL);
1811$SQL="drop table if exists $tbl_name8;";
1812$nllDb->executeQuery($SQL);
1813// take out comment on order by dt_transeqno (bk)
1814$SQL=" create temporary table $tbl_name8 (index(type1), index(type2), index(transno))
1815 SELECT
1816 hd_type1 as type1, hd_type2 as type2, hd_transno as transno, dt_transeqno,
1817 dt_disc_item as type, dt_prd_disc as product, @point,
1818 if( dt_disc_item=1 or dt_disc_item=2, @point,@point:=dt_transeqno) as a,
1819 @point as target,
1820 /*if(dt_disc_item =1 or dt_disc_item =0, @disc:=concat(if(@disc ='', '', concat(@disc, '+')), format(dt_percent, 0)), @disc:='') as disc, */
1821 dt_prd_disc, dt_percent,
1822 dt_amount,dt_final_amount, dt_final_amount_bvat
1823 FROM $tbl_name1 WHERE dt_prdcode !=0 order by type1,type2,transno,dt_transeqno;";
1824$nllDb->executeQuery($SQL);
1825
1826$SQL="set @disc:='';";
1827$nllDb->executeQuery($SQL);
1828$SQL="set @target:='';";
1829$nllDb->executeQuery($SQL);
1830$tbl_name7 = uniqid("tmp2_tbl_");
1831$SQL="drop table if exists $tbl_name7;";
1832$nllDb->executeQuery($SQL);
1833$SQL=" create temporary table $tbl_name7 (index(type1), index(type2), index(transno))
1834 SELECT *,@target,
1835 if( @target= target , if(type =1 or type =0, @disc:=concat(if(@disc ='', '', concat(@disc, '+')), format(dt_percent, 0)), @disc:='') ,@disc:=format(dt_percent, 0)) as disc,
1836 @target:= target
1837 FROM $tbl_name8;";
1838$nllDb->executeQuery($SQL);
1839
1840$tbl_name5 = uniqid("tmp3_tbl_");
1841$SQL="drop table if exists $tbl_name5;";
1842$nllDb->executeQuery($SQL);
1843$SQL=" create temporary table $tbl_name5 (primary key(transno, type1, type2, target),index(disclink))
1844 SELECT type1, type2, transno, target, max(dt_transeqno) as disclink
1845 FROM $tbl_name7
1846 WHERE type=0 or type=1
1847 group by type1, type2, transno, target
1848 ;";
1849$nllDb->executeQuery($SQL);
1850
1851$tbl_name6 = uniqid("tmp4_tbl_");
1852$SQL="drop table if exists $tbl_name6;";
1853$nllDb->executeQuery($SQL);
1854$SQL=" create temporary table $tbl_name6 (primary key(transno, type1, type2, target))
1855 SELECT a.transno, a.type1, a.type2, a.target, substring(replace(concat('+',disc), '+0', ''), 2) as disc,
1856 '' as disc_amount
1857 FROM $tbl_name7 a
1858 inner join $tbl_name5 b on a.transno = b.transno and a.type1=b.type1 and a.type2=b.type2 and a.dt_transeqno = b.disclink;";
1859$nllDb->executeQuery($SQL);
1860
1861
1862
1863$SQL="update $tbl_name1
1864inner join $tbl_name6 on hd_transno = transno and hd_type1=type1 and hd_type2=type2 and dt_transeqno = target
1865set dt_userdefine1= disc;";
1866$nllDb->executeQuery($SQL);
1867
1868$tbl_name9 = uniqid("tmp5_tbl_");
1869$SQL="drop table if exists $tbl_name9;";
1870$nllDb->executeQuery($SQL);
1871$SQL=" create temporary table $tbl_name9 (index(type1), index(type2), index(transno), index(target), index(type))
1872 SELECT
1873 transno, type1, type2, dt_transeqno as transeqno,dt_transeqno, target,
1874 if(type=1, sum(dt_amount), 0) as dt_disc_amount,
1875 if(type=2, sum(dt_amount), 0) as dt_tax_amount,
1876 product, type
1877 FROM $tbl_name8
1878 WHERE type <>'' and type <> 0
1879 group by type1, type2, transno, target , type, dt_prd_disc;";
1880$nllDb->executeQuery($SQL);
1881
1882
1883$SQL="update $tbl_name1
1884inner join $tbl_name9 on hd_transno= transno and hd_type1=type1 and hd_type2=type2 and $tbl_name1.dt_transeqno=target and dt_prdcode = product and type=1
1885set dt_disc = dt_disc_amount;";
1886$nllDb->executeQuery($SQL);
1887
1888$SQL="update $tbl_name1
1889inner join $tbl_name9 on hd_transno= transno and hd_type1=type1 and hd_type2=type2 and $tbl_name1.dt_transeqno=target and dt_prdcode = product and type=2
1890set dt_tax = dt_tax_amount;";
1891$nllDb->executeQuery($SQL);
1892
1893$SQL="update $tbl_name1
1894inner join $tbl_name9 on hd_transno= transno and hd_type1=type1 and hd_type2=type2 and $tbl_name1.dt_transeqno=target and dt_prdcode = product
1895set dt_prddisc = cast(dt_qty*dt_price*dt_percent/100 as decimal(12,6));";
1896$nllDb->executeQuery($SQL);
1897
1898$SQL="delete FROM $tbl_name1
1899WHERE dt_disc_item <>'' and dt_disc_item <> 0 and dt_disc_item is not null;";
1900$nllDb->executeQuery($SQL);
1901
1902$disc_amount = " dt_disc,";
1903}
1904
1905// select out Sales Order Quantity - bk (20100402) #8768
1906if($template=="multiwash-do.tpl"){
1907 $select_so_qty=" ord_detail.dt_qty AS so_qty, ";
1908 $join_ord_detail=" LEFT JOIN ord_detail ON $tbl_name1.dt_import_transno=ord_detail.dt_transno AND $tbl_name1.dt_import_type1=ord_detail.dt_type1 AND $tbl_name1.dt_import_type2=ord_detail.dt_type2 AND $tbl_name1.dt_import_transeqno=ord_detail.dt_transeqno ";
1909}
1910
1911//20190309 May #36812
1912if($_SESSION["act375"]){
1913 $sortby_select = " $tbl_name1.dt_sorting, ";
1914}else{
1915 if($sort_by=="dt_desc"){
1916 $sortby_select = " $tbl_name1.dt_assembly_desc, ";
1917 }
1918 else if($sort_by=="dt_sorting"){
1919 $sortby_select = " $tbl_name1.dt_assembly_code, $tbl_name1.prd_code, ";
1920 }
1921 else{
1922 $sortby_select = "";
1923 }
1924}
1925
1926//20150421 vernhui #23669 - Malaysia GST - Currency invoice printing, the product row amount column in rm shall get the value from dt, instead of by formula
1927$tbl_name11=uniqid("tmp_tbl_11_ar_bil_");
1928$nllDb->executeQuery("DROP TEMPORARY TABLE IF EXISTS $tbl_name11");
1929$insert_recno="0";
1930if($report_format == '1' && $NLL_PRD_REPACK){
1931 if($NLL_PRODUCT_MAP){
1932
1933 $drop_sql = "DROP TABLE IF EXISTS $tbl_name3;";
1934 $nllDb->executeQuery($drop_sql);
1935
1936 //prodcut mapping + repacking special record no definition
1937 $sSQL = "
1938 CREATE TEMPORARY TABLE $tbl_name3
1939 (index(dt_import_transno,
1940 dt_import_type1,
1941 dt_import_type2,
1942 dt_import_transeqno,
1943 dt_import_refno))
1944 SELECT /*currency_code*/
1945 /*ori_amount*/
1946 @f:=if((pdgptp_is_disc=0 or pdgptp_is_disc is null) and (pdgptp_is_tax =0 or pdgptp_is_tax is null) and (pdgptp_is_charges=0 or pdgptp_is_charges is null) and $tbl_name1.dt_prdcode <> 0, 1,0) as b,
1947 if(pdgptp_is_item=1,1,@f) as flag , /*$tbl_name1.dt_assembly,*/
1948 concat($tbl_name1.dt_transno, '-',$tbl_name1.dt_type1, '-', $tbl_name1.dt_type2) as keyfield,
1949 @flag,@flag:=IF(pdgptp_is_item=1,1,@f) AS temp1,
1950 if( $tbl_name1.dt_transeqno=1,@as_counter1:=0,@as_counter1) AS temp5,
1951 if( $tbl_name1.dt_transeqno=1,@as_counter2:=0,@as_counter2) AS temp6,
1952 if($tbl_name1.dt_assembly = 2, @as_counter1:=@as_counter1+1, if(@flag=1 and $tbl_name1.dt_assembly <> 1, @as_counter1:=@as_counter1+1, '')) as countD,
1953 if($tbl_name1.dt_assembly = 1, @as_counter2:=@as_counter2+1, if(@flag=1 and $tbl_name1.dt_assembly <> 2, @as_counter2:=@as_counter2+1, '')) as countE,
1954
1955 ";
1956 }
1957 else{
1958
1959 $sSQL = "
1960 CREATE TEMPORARY TABLE $tbl_name11 (INDEX(hd_customer),INDEX(prdt_tariff),INDEX(grpinv_tariff))
1961 SELECT /*currency_code*/
1962 /*ori_amount*/
1963 /*if($tbl_name1.rec_no1=0, '', concat($tbl_name1.rec_no1, '.')) as rec_no,*/ $discount_amount
1964 /*@f:=if((pdgptp_is_disc=0 or pdgptp_is_disc is null) and (pdgptp_is_tax =0 or pdgptp_is_tax is null) and (pdgptp_is_charges=0 or pdgptp_is_charges is null) and $tbl_name1.dt_prdcode <> 0, 1,0) as b,*/
1965 /*@flag:=if(pdgptp_is_item=1,1,@f) AS temp1,*/
1966 /*@reset:= if(@current<>concat($tbl_name1.dt_transno, '-',$tbl_name1.dt_type1, '-', $tbl_name1.dt_type2),@counter:=1,@counter) AS temp2,*/
1967 /*if(@flag =1,concat(@counter,'.'), '') as rec_no, */
1968 /*@counter := if(@flag =1,@counter +1,@counter) AS temp3, */
1969 /*@current:=concat($tbl_name1.dt_transno, '-',$tbl_name1.dt_type1, '-', $tbl_name1.dt_type2) AS temp4,*/
1970 /*if($tbl_name1.dt_assembly = 1, @as_counter:=@as_counter+1, if(@flag=1 and $tbl_name1.dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,*/
1971 /*if( $tbl_name1.dt_transeqno=1,@as_counter1:=0,@as_counter1) AS temp5,*/
1972 /*if( $tbl_name1.dt_transeqno=1,@as_counter2:=0,@as_counter2) AS temp6,*/
1973 /*if($tbl_name1.dt_assembly = 2, @as_counter1:=@as_counter1+1, if(@flag=1 and $tbl_name1.dt_assembly <> 1, @as_counter1:=@as_counter1+1, '')) as countD, */
1974 /*if($tbl_name1.dt_assembly = 1, @as_counter2:=@as_counter2+1, if(@flag=1 and $tbl_name1.dt_assembly <> 2, @as_counter2:=@as_counter2+1, '')) as countE, */
1975 /*if($tbl_name1.dt_assembly = 1, concat(@as_counter,'.'), if(@flag=1 and $tbl_name1.dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,*/
1976 ";
1977
1978 $insert_recno="1";
1979 }
1980}
1981else{
1982 $sSQL = "
1983 CREATE TEMPORARY TABLE $tbl_name11 (INDEX(hd_customer),INDEX(prdt_tariff),INDEX(grpinv_tariff))
1984 SELECT /*currency_code*/
1985 /*ori_amount*/
1986 /*if($tbl_name1.rec_no1=0, '', concat($tbl_name1.rec_no1, '.')) as rec_no,*/ $discount_amount
1987 /*@f:=if((pdgptp_is_disc=0 or pdgptp_is_disc is null) and (pdgptp_is_tax =0 or pdgptp_is_tax is null) and (pdgptp_is_charges=0 or pdgptp_is_charges is null) and $tbl_name1.dt_prdcode <> 0, 1,0) as b,*/
1988 /*@flag:=if(pdgptp_is_item=1,1,@f) AS temp1,*/
1989 /*@reset:= if(@current<>concat($tbl_name1.dt_transno, '-',$tbl_name1.dt_type1, '-', $tbl_name1.dt_type2),@counter:=1,@counter) AS temp2,*/
1990 /*if(@flag =1,concat(@counter,'.'), '') as rec_no, */
1991 /*@counter := if(@flag =1,@counter +1,@counter) AS temp3, */
1992 /*@current:=concat($tbl_name1.dt_transno, '-',$tbl_name1.dt_type1, '-', $tbl_name1.dt_type2) AS temp4,*/
1993 /*if($tbl_name1.dt_assembly = 1, @as_counter:=@as_counter+1, if(@flag=1 and $tbl_name1.dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC, */
1994 /*if( $tbl_name1.dt_transeqno=1,@as_counter1:=0,@as_counter1) AS temp5,*/
1995 /*if( $tbl_name1.dt_transeqno=1,@as_counter2:=0,@as_counter2) AS temp6,*/
1996 /*if($tbl_name1.dt_assembly = 2, @as_counter1:=@as_counter1+1, if(@flag=1 and $tbl_name1.dt_assembly <> 1, @as_counter1:=@as_counter1+1, '')) as countD, */
1997 /*if($tbl_name1.dt_assembly = 1, @as_counter2:=@as_counter2+1, if(@flag=1 and $tbl_name1.dt_assembly <> 2, @as_counter2:=@as_counter2+1, '')) as countE, */
1998 /*if($tbl_name1.dt_assembly = 1, concat(@as_counter,'.'), if(@flag=1 and $tbl_name1.dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,*/
1999 ";
2000 $insert_recno="1";
2001}
2002
2003/* 20180321 Inda #33447 - Lii Hen - Inventory Entry, add new field in dt*/
2004 xs_include_event("inventory_rpt_ar_cust_pro_map_LiiHen");
2005
2006//for bill tax in the below sql hd_tax and hd_percent_tax
2007//20130923 sook mun -#15795-KMM - Inventory SN able to add hd_userdefine1, hd_userdefine2,hd_userdefine3
2008$sSQL .="
2009 $tbl_name1.dt_transno,
2010 $tbl_name1.dt_transeqno,
2011 $tbl_name1.dt_import_transno,
2012 $tbl_name1.dt_import_type1,
2013 $tbl_name1.dt_import_type2,
2014 $tbl_name1.dt_import_transeqno,
2015 $tbl_name1.dt_import_refno,
2016 $tbl_name1.dt_import_date,
2017 DATE_FORMAT($tbl_name1.dt_deldate, '%d/%m/%Y') AS dt_delivery_date,
2018 $tbl_name1.dt_mapcode,
2019 $tbl_name1.dt_price_net,
2020 $tbl_name1.dt_prdt_expiry_date,
2021 $tbl_name1.dt_price as dt_prdt_unit_price,
2022 if($tbl_name1.bilctrl_flag_prefix='1',$tbl_name1.hd_refno, substr( $tbl_name1.hd_refno , least(
2023 case when instr( $tbl_name1.hd_refno, '0' ) = 0 then 99999 else instr( $tbl_name1.hd_refno, '0' ) end ,
2024 case when instr( $tbl_name1.hd_refno, '1' ) = 0 then 99999 else instr( $tbl_name1.hd_refno, '1' ) end ,
2025 case when instr( $tbl_name1.hd_refno, '2' ) = 0 then 99999 else instr( $tbl_name1.hd_refno, '2' ) end ,
2026 case when instr( $tbl_name1.hd_refno, '3' ) = 0 then 99999 else instr( $tbl_name1.hd_refno, '3' ) end ,
2027 case when instr( $tbl_name1.hd_refno, '4' ) = 0 then 99999 else instr( $tbl_name1.hd_refno, '4' ) end ,
2028 case when instr( $tbl_name1.hd_refno, '5' ) = 0 then 99999 else instr( $tbl_name1.hd_refno, '5' ) end ,
2029 case when instr( $tbl_name1.hd_refno, '6' ) = 0 then 99999 else instr( $tbl_name1.hd_refno, '6' ) end ,
2030 case when instr( $tbl_name1.hd_refno, '7' ) = 0 then 99999 else instr( $tbl_name1.hd_refno, '7' ) end ,
2031 case when instr( $tbl_name1.hd_refno, '8' ) = 0 then 99999 else instr( $tbl_name1.hd_refno, '8' ) end ,
2032 case when instr( $tbl_name1.hd_refno, '9' ) = 0 then 99999 else instr( $tbl_name1.hd_refno, '9' ) end
2033 ) , 999999 )) as hd_refno,
2034 $tbl_name1.hd_refno as hd_reference,
2035 $tbl_name1.hd_refno2,
2036 $tbl_name1.hd_refno3,
2037 DATE_FORMAT($tbl_name1.hd_date, '%d/%m/%Y') AS hd_date,
2038 if(concat_ws(',',storemst.st_address1,storemst.st_address2,storemst.st_address3,storemst.st_address4)<>'', concat_ws(',',storemst.st_address1,storemst.st_address2,storemst.st_address3,storemst.st_address4), '".db_clean($_SESSION["NLL_COMPANY_ADDRESS"])."') as st_addressfull,storemst.st_address1, storemst.st_address2, storemst.st_address3, storemst.st_address4,
2039 if(concat(if(storemst.st_tel<>'', concat('Tel : ', storemst.st_tel), ''), if(storemst.st_fax<>'', concat(' Fax : ', storemst.st_fax), ''))<>'', concat('Tel : ', if(storemst.st_tel<>'', storemst.st_tel, '-'), ' Fax : ', if(storemst.st_fax<>'', storemst.st_fax, '-')), '".db_clean($_SESSION["NLL_COMPANY_TELFAX"])."') as st_telfax,
2040 concat($tbl_name1.hd_transno,'-',$tbl_name1.hd_type1,'-',$tbl_name1.hd_type2) as linknotes,
2041 $tbl_name1.hd_yourno,
2042 $tbl_name1.hd_type2,
2043 $tbl_name1.hd_no_print,
2044 $tbl_name1.hd_print_no,
2045 $tbl_name1.hd_invdo_print_no,
2046 $tbl_name1.hd_ourno,
2047 $tbl_name1.hd_transport,
2048 $tbl_name1.hd_remark,
2049 $tbl_name1.hd_remark1,
2050 $tbl_name1.hd_remark2,
2051 $tbl_name1.hd_remark3,
2052 $tbl_name1.hd_remark4,
2053 $tbl_name1.hd_remark5,
2054 $tbl_name1.hd_round,
2055 $tbl_name1.hd_xround,
2056 $tbl_name1.hd_xamount,
2057 if($tbl_name1.bilctrl_mode='-', $tbl_name1.hd_gross * -1, $tbl_name1.hd_gross) as hd_gross,
2058 $tbl_name1.hd_add1, $tbl_name1.hd_deldate, $tbl_name1.hd_deltime, $tbl_name1.hd_deltime_to,
2059 $tbl_name1.hd_add2,
2060 $tbl_name1.hd_add3,
2061 $tbl_name1.hd_add4,
2062 $tbl_name1.hd_o_tel,
2063 $tbl_name1.hd_o_fax,
2064 $tbl_name1.hd_dono,
2065 $tbl_name1.hd_attention,
2066 $tbl_name1.hd_userdefine1,
2067 $tbl_name1.hd_userdefine2,
2068 $tbl_name1.hd_userdefine3,
2069 $tbl_name1.hd_pos_change_amount,
2070 $tbl_name1.prescribed_vat,
2071 $tbl_name1.dt_xamount,
2072 $tbl_name1.amount,
2073 $tbl_name1.dt_xprice,
2074 if($tbl_name1.hd_attention is not null and $tbl_name1.hd_attention != '', $tbl_name1.hd_attention, debtormst.dbtr_contact_person) as contact_person,
2075 DATE_FORMAT($tbl_name1.hd_promise_date, '%d/%m/%Y') AS hd_promise_date,
2076 DATE_FORMAT($tbl_name1.hd_trandate, '%d/%m/%Y') AS hd_trandate,/*duedate ida add*/ date_format(date_add($tbl_name1.hd_trandate,INTERVAL term_days DAY), '%d/%m/%Y') as due_date,
2077 $tbl_name1.hd_job, $tbl_name1.idocstat_desc, $tbl_name1.idocstat_code, $tbl_name1.hd_invdocstat,
2078 $tbl_name1.bilctrl_userdefine1,
2079 UPPER($tbl_name1.bilctrl_desc) as bilctrl_desc,
2080 debtormst.dbtr_no,
2081 debtormst.dbtr_code,
2082 debtormst.dbtr_userdefine1,
2083 debtormst.dbtr_userdefine2,
2084 debtormst.dbtr_userdefine3,
2085 debtormst.dbtr_userdefine4,
2086 debtormst.dbtr_remark,
2087 /*azwan*/
2088 storemst.st_gst_no,
2089 termmst.term_code,
2090 termmst.term_name1,
2091 termmst.term_userdefine3,
2092 $tbl_name1.acct_code as acct_code,
2093 $tbl_name1.acct_name1 as acct_name1,
2094 $tbl_name1.hd_name1,
2095 $tbl_name1.hd_name2,
2096 $tbl_name1.hd_discount,
2097 $tbl_name1.hd_revision_number,
2098 $tbl_name1.customer_address1,
2099 $tbl_name1.customer_address2,
2100 $tbl_name1.customer_address3,
2101 $tbl_name1.customer_address4,
2102 $tbl_name1.customer_code,
2103 /*customer_first_name_tbl*/
2104 /*customer_last_name_tbl*/
2105 /*customer_password_tbl*/
2106 /*customer_classlevel_no_tbl*/
2107 /*level_no_tbl*/
2108 /*level_name1_tbl*/
2109 $tbl_name1.full_name,
2110 DATE_FORMAT($tbl_name1.hd_term_due_date, '%d/%m/%Y') AS hd_term_due_date,
2111 prdt_barcode,
2112 prdt_alternative_barcode1, prdt_alternative_barcode2, prdt_alternative_barcode3, prdt_alternative_barcode4, prdt_alternative_barcode5,
2113 cast($tbl_name1.dt_qty*prdt_inventory as decimal(16,4))as total_M3,
2114 prdt_inventory,
2115 prdt_gross_weight,
2116 prdt_remark,
2117 prdt_cumulative, /*20130730 -KY- 17203*/
2118 /* faizah*/
2119 moduser.user_email as mod_usermail,
2120 moduser.user_login as last_mod_user,
2121 adduser.user_email as add_usermail,
2122 adduser.user_login as add_username,
2123 adduser.user_login_name as add_userloginname,
2124 if($tbl_name1.mdisc='Y', $tbl_name1.hd_mpercent, $tbl_name1.hd_percent) as hd_percent,
2125 $tbl_name1.hd_tax,$tbl_name1.dt_taxable,
2126 if($tbl_name1.mtax='Y', $tbl_name1.hd_mpercent_tax, ROUND($tbl_name1.hd_percent_tax,2)) as hd_percent_tax,
2127 if($tbl_name1.hd_tax is not null and $tbl_name1.hd_tax <> 0.00, 7.00, 0.00) as hd_vat,
2128 $vat_final_select
2129 $tbl_name1.dlto_code,
2130 $tbl_name1.dlto_name1,
2131 $tbl_name1.dlto_del1,
2132 $tbl_name1.dlto_del2,
2133 $tbl_name1.dlto_del3,
2134 $tbl_name1.dlto_del4,
2135 tms_drivermst.dvr_code AS driver_code,
2136 tms_drivermst.dvr_name AS driver_name,
2137 tms_truckmst.trk_code AS truck_code,
2138 /*customer_code_tbl*/
2139 productmst.prdt_code AS orig_prdt_code,
2140 productmst.prdt_name1 AS orig_prdt_name1,
2141 reasonmst.reason_name1 AS reason_code,
2142 $tbl_ptree_code
2143 $notes_dimension
2144 $promap
2145 $select_so_qty "; //added by Yinru 20091112
2146 xs_include_event('InvBilBill');
2147
2148 if($NLL_SHIPMENT)
2149 $sSQL .= "
2150 shpco_code,
2151 $tbl_name1.hd_shp_refno1,
2152 $tbl_name1.hd_shp_refno2,
2153 $tbl_name1.hd_shp_lc_no, $tbl_name1.hd_shp_bals_order_no, $tbl_name1.hd_shp_mc_contract_no,
2154 DATE_FORMAT($tbl_name1.hd_shp_container_out_date, '%d/%m/%Y') as hd_shp_container_out_date,
2155 DATE_FORMAT($tbl_name1.hd_shp_container_in_date, '%d/%m/%Y') as hd_shp_container_in_date,
2156 DATE_FORMAT($tbl_name1.hd_shp_close_date, '%d/%m/%Y') as hd_close_date,
2157 DATE_FORMAT($tbl_name1.hd_shp_close_date, '%a') as hd_close_day,
2158 $tbl_name1.hd_shp_sail_time,
2159 DATE_FORMAT($tbl_name1.hd_shp_est_arrival_date, '%d/%m/%Y') as hd_shp_est_arrival_date,
2160 DATE_FORMAT($tbl_name1.hd_shp_sail_date, '%d/%m/%Y') as hd_shp_sail_date,
2161 $tbl_name1.hd_shp_name1, $tbl_name1.hd_shp_product_name,
2162 concat($tbl_name1.port_name_from, ',', $tbl_name1.country_name_from) as dt_port_from,
2163 concat($tbl_name1.port_name_to, ',', $tbl_name1.country_name_to) as dt_port_to,
2164 ";
2165
2166$sSQL = $MultiCurr->addCurrency($sSQL);
2167//20150421 vernhui #23669 - Malaysia GST - Currency invoice printing, the product row amount column in rm shall get the value from dt, instead of by formula
2168$ori_amount_sql = " SUM(IF($tbl_name1.bilctrl_mode='-', $tbl_name1.hd_ori_amount * -1, $tbl_name1.hd_ori_amount)) AS ori_hd_amount,
2169 IF($tbl_name1.bilctrl_mode='-', $tbl_name1.hd_ori_gross * -1, $tbl_name1.hd_ori_gross) AS ori_hd_gross,
2170 hd_ori_discount AS ori_hd_discount, hd_ori_tax AS ori_hd_tax,
2171 hd_ori_vat_amt AS ori_hd_vat_amt, hd_ori_vat_round AS ori_hd_vat_round,
2172 hd_ori_round AS ori_hd_round,
2173 hd_ori_vat_amount AS ori_hd_vat_amount,
2174 SUM(IF($tbl_name1.dt_qty<>0 && $tbl_name1.dt_ori_price<>0, $tbl_name1.dt_ori_amount, if($tbl_name1.dt_qty=0 && $tbl_name1.dt_foc=0 && $tbl_name1.dt_ori_amount = 0, '', if('$chkFOC'='1', 'F.O.C',$tbl_name1.dt_ori_amount)))) AS ori_dt_amount,
2175 IF($tbl_name1.dt_qty<>0 && $tbl_name1.dt_ori_price<>0, $tbl_name1.dt_ori_price, if($tbl_name1.dt_qty=0 && $tbl_name1.dt_foc=0 && $tbl_name1.dt_ori_price = 0, '', if('$chkFOC'='1', 'F.O.C',$tbl_name1.dt_ori_price))) AS ori_dt_price,
2176 dt_ori_final_amount_btax AS ori_dt_final_amount_btax, $tbl_name1.dt_final_bil_tax_amount, $tbl_name1.dt_final_bil_tax_rate,
2177 dt_ori_price_net AS ori_dt_price_net, dt_ori_final_amount AS ori_dt_final_amount, dt_ori_final_vat_amount AS ori_dt_final_vat_amount, ";
2178$sSQL = str_replace ("/*ori_amount*/", " $ori_amount_sql ", $sSQL);
2179
2180//$act_astrick_display = getHiddenGlobalSettingValue(1500,43,90000200); //20150410 May #23431
2181if($NLL_PRODUCT_MAP)
2182{
2183 if ($vat_nature_type==3){
2184 //20150312-ky-22927
2185/* if($is_same_vat==0 || $act_astrick_display == 1){
2186 $sSQL .= "if(prdmap_mapcode is not null, if(pdgptp_is_disc=1 ||pdgptp_is_charges=1 ,'',prdmap_mapcode), if(pdgptp_is_disc=1 || pdgptp_is_charges,'',productmst.prdt_code)) as prdt_code,
2187 CONCAT_WS('',(CASE WHEN body_vat_nature='EX' THEN '** ' WHEN vat_rate='0' THEN '* ' ELSE '' END),IF(prdmap_mapname1 IS NOT NULL,prdmap_mapname1,$tbl_name1.dt_desc)) AS dt_desc,
2188 IF(prdmap_mapcode IS NULL, prdt_code, prdmap_mapcode) AS prdt_mapcode,";
2189 }
2190 else if($is_same_vat==1)
2191 {
2192 $sSQL .= "if(prdmap_mapcode is not null, if(pdgptp_is_disc=1 ||pdgptp_is_charges=1 ,'',prdmap_mapcode), if(pdgptp_is_disc=1 || pdgptp_is_charges,'',productmst.prdt_code)) as prdt_code,
2193 IF(prdmap_mapname1 IS NOT NULL,prdmap_mapname1,$tbl_name1.dt_desc) AS dt_desc,
2194 IF(prdmap_mapcode IS NULL, prdt_code, prdmap_mapcode) AS prdt_mapcode,";
2195 }*/
2196
2197 //20150518 May #24188
2198 $sSQL .= "IF(prdmap_mapcode is not null, IF(pdgptp_is_disc=1 ||pdgptp_is_charges=1 ,'',prdmap_mapcode),
2199 IF(pdgptp_is_disc=1 || pdgptp_is_charges,'',productmst.prdt_code)) AS prdt_code,
2200 IF(is_same_vat=1, IF(prdmap_mapname1 IS NOT NULL,prdmap_mapname1,$tbl_name1.dt_desc), CONCAT_WS('',(CASE WHEN body_vat_nature='EX' THEN '** ' WHEN vat_rate='0' THEN '* ' ELSE '' END),IF(prdmap_mapname1 IS NOT NULL,prdmap_mapname1,$tbl_name1.dt_desc))) AS dt_desc,
2201 IF(prdmap_mapcode IS NULL, prdt_code, prdmap_mapcode) AS prdt_mapcode,";
2202 }
2203 else{
2204 $sSQL .= "if(prdmap_mapcode is not null, if(pdgptp_is_disc=1 ||pdgptp_is_charges=1 ,'',prdmap_mapcode), if(pdgptp_is_disc=1 || pdgptp_is_charges,'',productmst.prdt_code)) as prdt_code,
2205 /*if(prdmap_mapcode is not null, if(pdgptp_is_item=1,prdmap_mapcode,''), if(pdgptp_is_item=1,productmst.prdt_code,'')) as prdt_code,*/
2206 if(prdmap_mapname1 is not null, prdmap_mapname1,$tbl_name1.dt_desc) as dt_desc,
2207 if(prdmap_mapcode is null, prdt_code, prdmap_mapcode) as prdt_mapcode,
2208 ";
2209 }
2210}
2211
2212else
2213{
2214 if($vat_nature_type ==3){
2215 //20150312-ky-22927
2216/* if($is_same_vat==0 || $act_astrick_display == 1){
2217 $sSQL .= "if(pdgptp_is_item=1,productmst.prdt_code,'')as prdt_code,
2218 CONCAT_WS('',(CASE WHEN body_vat_nature='EX' THEN '** ' WHEN vat_rate='0' THEN '* ' ELSE '' END),$tbl_name1.dt_desc) AS dt_desc,";
2219 }
2220 else if($is_same_vat==1)
2221 {
2222 $sSQL .= "if(pdgptp_is_item=1,productmst.prdt_code,'')as prdt_code, $tbl_name1.dt_desc AS dt_desc,";
2223 }*/
2224
2225 //20150518 May #24188
2226 $sSQL .= "IF(pdgptp_is_item=1,productmst.prdt_code,'')AS prdt_code,
2227 IF(is_same_vat=1, $tbl_name1.dt_desc, CONCAT_WS('',(CASE WHEN body_vat_nature='EX' THEN '** ' WHEN vat_rate='0' THEN '* ' ELSE '' END),$tbl_name1.dt_desc)) AS dt_desc,";
2228 }
2229 else{
2230 $sSQL .= "if(pdgptp_is_item=1,productmst.prdt_code,'')as prdt_code, $tbl_name1.dt_desc, ";
2231 }
2232}
2233//20180307 leewah 30418 get email pdf password
2234$default_pw = getHiddenGlobalSettingValue(12000, 25006, 999999999);
2235
2236//11/06/2008 chris added dbtr_acno,dbtr_co_reg_no,dbtr_ref_no,dbtr_vendor_since,dbtr_userdefine10,prdt_unit,prdt_weight,
2237$sSQL .= "
2238 dbtr_name1,
2239 dbtr_name2,
2240 dbtr_address1,
2241 dbtr_address2,
2242 dbtr_address3,
2243 dbtr_address4,
2244 dbtr_acno,
2245 dbtr_co_reg_no,
2246 IF(dbtr_co_reg_no='' OR dbtr_co_reg_no IS NULL,'".$default_pw."',dbtr_co_reg_no) AS default_pw,
2247 replace(dbtr_ref_no, '\n', '<br>') as dbtr_ref_no,
2248 dbtr_vendor_since,
2249 dbtr_userdefine10,
2250 prdt_unit,
2251 prdt_weight,
2252 if($tbl_name1.dt_userdefine3 !=0,$tbl_name1.dt_userdefine3, (prdt_weight * $tbl_name1.dt_qty)) AS prdt_weight2,
2253 dbtr_off_tel,
2254 dbtr_fax,
2255 dbtr_email,
2256 dbtr_email_cc, dbtr_email_bcc,
2257 dbtr_website,
2258 dbtr_attention, dbtr_tax_ref,
2259 dbtr_contact_person,
2260 dbtr_attention as master_attention, dbtr_contact_person as master_contact_person,
2261 $tbl_name1.dt_foc,$tbl_name1.referer_price,
2262 pdgptp_is_disc,pdgptp_is_tax,pdgptp_is_item, $tbl_name1.dt_prdcode, IF($tbl_name1.dt_prdcode=0,SUBSTRING_INDEX(dt_desc, ':', -1),CONCAT(prdt_code,' : ', prdt_name1)) AS newton_dt_desc ,$tbl_name1.dt_type1,$tbl_name1.dt_type2,$tbl_name1.dt_assembly,";
2263
2264//22/09/2008 - william added function to select notes value
2265//09/10/2008 - William off generateConsolidatedNotesTable function because of Max_Join_Size error
2266#$master_name = "bill_headerAR";
2267#$tmp_notes = generateConsolidatedNotesTable($master_name,$nllDb);
2268#$sSQL .= "$tmp_notes.*,";
2269#$join_notes = "LEFT JOIN $tmp_notes ON $tmp_notes.notes_link_no = $tbl_name1.notes_key";
2270
2271//25/09/2008 - william added user_login_name
2272$nameSQL = "SELECT hd_sys_add_user FROM $tbl_name1";
2273$result = $nllDb->executeQuery($nameSQL);
2274$row = $nllDb->fetchArray($result);
2275$user_login = $row[0];
2276
2277//30/09/2008 - william fix query error when no record- added IF statement
2278if($user_login!=null)
2279{
2280$tbl_user = uniqid("tmp_tbl_user_");
2281$nameSQL = "CREATE TEMPORARY TABLE $tbl_user SELECT user_login_name as attendant_name,user_no FROM usermst WHERE user_no = $user_login;";
2282$nllDb->executeQuery($nameSQL);
2283$sSQL .="$tbl_user.*,";
2284$join_user = "LEFT JOIN $tbl_user on $tbl_user.user_no = $tbl_name1.hd_sys_add_user";
2285}
2286
2287//Checking whether FOC Type is active & there is FOC quantity
2288if($_SESSION["act371"])
2289{
2290 $sSQL .= "if($tbl_name1.dt_qty>0 && $tbl_name1.dt_price='0', foc_typemst.type_code, '')as type_code,";
2291}
2292//--end checking
2293
2294$sSQL .= "
2295 $tbl_name1.dt_desc2,
2296 if($tbl_name1.mprd_disc='Y',substring(replace(concat('+',$tbl_name1.dt_desc2),'+0',''),2), $tbl_name1.dt_percent) as dt_percent,
2297 ";
2298
2299//multi-currency
2300//Added by Alvin 20110627 #11435 - Add in the column dt_repack_text and dt_repack_remark.
2301//Jey 2012070 #14002 - Add 'dt_prdt_unit_qty' column for capture product quantity
2302if($report_format == '1' && $NLL_PRD_REPACK)
2303{
2304 if($NLL_PRODUCT_MAP){
2305
2306 $sSQL .= "
2307 IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 3) ,@delim2,-1), $tbl_name1.dt_unit) AS dt_unit,
2308 SUM(IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 5) ,@delim2,-1), $tbl_name1.dt_qty)) AS dt_qty,
2309 IF($tbl_name1.dt_prdcode=0, '' , dt_qty) AS newton_dt_qty,
2310 IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 1) ,@delim2,-1), '') AS dt_repack_text,
2311 IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 8) ,@delim2,-1), '') AS dt_repack_remark,
2312 IF(repk_row<>'', (SUBSTRING_INDEX( SUBSTRING_INDEX( repk_row ,@delim2, 5) ,@delim2,-1)) * (IF (SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(repk_row ,@delim2, 1), ' = ', -1), ' ',1) <> '', SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(repk_row ,@delim2, 1), ' = ', -1), ' ',1),1)), $tbl_name1.dt_qty) AS dt_prdt_unit_qty,
2313 /*repacking*/
2314 ";
2315 //detect the repacking formula in smalles unit
2316 $sSQL .= "if(trim(substring_index(substring_index(substring_index( repk_row ,@delim2, 1), ' = ', -1), ' ',1))<>'', trim(substring_index(substring_index(substring_index( repk_row ,@delim2, 1), ' = ', -1), ' ',1)) ,if(prdmap_mapcode is null, 1, '')) as repk_qty_unit,";
2317
2318 $sSQL = $MultiCurr->convertBillRepackSQL2($sSQL,$tbl_name1,$chkFOC,$NLL_PRODUCT_MAP);
2319 }
2320 else
2321 {
2322 //echo "test1";
2323 $sSQL .= "
2324 IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 3) ,@delim2,-1), $tbl_name1.dt_unit) AS dt_unit,
2325 SUM( IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 5) ,@delim2,-1), $tbl_name1.dt_qty)) AS dt_qty,
2326 IF($tbl_name1.dt_prdcode=0, '' , dt_qty) AS newton_dt_qty,
2327 IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 1) ,@delim2,-1), '') AS dt_repack_text,
2328 IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 8) ,@delim2,-1), '') AS dt_repack_remark,
2329 IF(repk_row<>'', (SUBSTRING_INDEX( SUBSTRING_INDEX( repk_row ,@delim2, 5) ,@delim2,-1)) * (IF (SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(repk_row ,@delim2, 1), ' = ', -1), ' ',1) <> '', SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(repk_row ,@delim2, 1), ' = ', -1), ' ',1),1)), $tbl_name1.dt_qty) AS dt_prdt_unit_qty,
2330 /*repacking*/
2331 ";
2332 $sSQL .= "if(trim(substring_index(substring_index(substring_index( repk_row ,@delim2, 1), ' = ', -1), ' ',1))<>'', trim(substring_index(substring_index(substring_index( repk_row ,@delim2, 1), ' = ', -1), ' ',1)) ,'1') as repk_qty_unit,";
2333
2334 $sSQL = $MultiCurr->convertBillRepackSQL($sSQL,$tbl_name1,$chkFOC,$NLL_PRODUCT_MAP);
2335 }
2336 //$sSQL = $MultiCurr->convertBillRepackSQL2($sSQL,$tbl_name1,$chkFOC,$NLL_PRODUCT_MAP);
2337}
2338else
2339{
2340 //echo "test";
2341 if($NLL_PRODUCT_MAP){
2342 $sSQL .= "
2343 SUM($tbl_name1.dt_qty) AS dt_qty,
2344 $tbl_name1.dt_unit,
2345 /*if($tbl_name1.dt_qty>0 && $tbl_name1.dt_price='0' && '$chkFOC'='1', 'F.O.C', $tbl_name1.dt_price) as dt_price, */
2346 IF($tbl_name1.dt_qty<>0 && $tbl_name1.dt_price<>0, $tbl_name1.dt_price, if($tbl_name1.dt_qty=0 && $tbl_name1.dt_foc=0 && $tbl_name1.dt_price = 0, '', if('$chkFOC'='1', 'F.O.C',$tbl_name1.dt_price))) as dt_price,
2347 /*sum(if($tbl_name1.dt_qty>0 && $tbl_name1.dt_price='0' && '$chkFOC'='1', 'F.O.C', $tbl_name1.dt_amount)) as dt_amount,*/
2348 SUM(IF($tbl_name1.dt_qty<>0 && $tbl_name1.dt_price<>0, $tbl_name1.dt_amount, if($tbl_name1.dt_qty=0 && $tbl_name1.dt_foc=0 && $tbl_name1.dt_amount = 0, '', if('$chkFOC'='1', 'F.O.C',$tbl_name1.dt_amount)))) AS dt_amount,
2349 SUM(IF($tbl_name1.bilctrl_mode='-', $tbl_name1.hd_amount * -1, $tbl_name1.hd_amount)) AS hd_amount,
2350 IF((prdt_code is null && prdmap_mapcode is null) && $tbl_name1.dt_desc is not null, $tbl_name1.dt_transeqno, '0') AS pname2,
2351 ";
2352 }
2353 else{
2354
2355 $sSQL .= "
2356 SUM($tbl_name1.dt_qty) AS dt_qty,
2357 $tbl_name1.dt_unit,
2358 /*if($tbl_name1.dt_qty>0 && $tbl_name1.dt_price='0' && '$chkFOC'='1', 'F.O.C', $tbl_name1.dt_price) as dt_price, */
2359 IF($tbl_name1.dt_qty<>0 && $tbl_name1.dt_price<>0, $tbl_name1.dt_price, if($tbl_name1.dt_qty=0 && $tbl_name1.dt_foc=0 && $tbl_name1.dt_price = 0, '', if('$chkFOC'='1', 'F.O.C',$tbl_name1.dt_price))) AS dt_price,
2360 /*if($tbl_name1.dt_qty>0 && $tbl_name1.dt_price='0' && '$chkFOC'='1', 'F.O.C', $tbl_name1.dt_amount) as dt_amount, */
2361 SUM(IF($tbl_name1.dt_qty<>0 && $tbl_name1.dt_price<>0, $tbl_name1.dt_amount, if($tbl_name1.dt_qty=0 && $tbl_name1.dt_foc=0 && $tbl_name1.dt_amount = 0 , '', if('$chkFOC'='1', 'F.O.C',$tbl_name1.dt_amount)))) AS dt_amount,
2362 SUM(IF($tbl_name1.bilctrl_mode='-', $tbl_name1.hd_amount * -1, $tbl_name1.hd_amount)) AS hd_amount,
2363 ";
2364 }
2365}
2366
2367if($_SESSION["act905"])
2368{
2369 //$sSQL.=" concat(hd_sys_add_user,'-',b.user_login) as cuser, concat(hd_sys_last_mod_user,'-',a.user_login) as muser,";
2370 $sSQL.=" $tbl_name1.hd_sys_add_user as auserid, $tbl_name1.hd_sys_last_mod_user as muserid, b.user_login as auserloginname, a.user_login as muserloginname, a.user_login_name as musername, b.user_login_name as ausername,";
2371 $join="left join usermst a on $tbl_name1.hd_sys_last_mod_user = a.user_no
2372 left join usermst b on $tbl_name1.hd_sys_add_user = b.user_no ";
2373}
2374
2375 if($template=="inv_rpt_ar_bil_inv_keatraco.tpl") {//for keatraco - want show truck code in their template -ida 20071217
2376 $sSQL .= " tms_truckmst.trk_code as truck_number, ";
2377 $join_tms = " left join tms_entry on tms_cust =debtormst.dbtr_no and trim(substring_index(tms_link, '-',-1) ) = hd_transno and trim(substring_index(tms_link, '-',1)) = hd_type1 and trim(substring_index(substring_index(tms_link, '-',2), '-', -1) ) = hd_type2 and $tbl_name1.dt_userdefine1 = date_format(tms_dlv_date, '%d/%m/%Y') and $tbl_name1.dt_userdefine2=tms_do_no left join tms_truckmst on tms_truck=trk_no ";
2378 }
2379
2380 //20191210 Elaine 39364 Newton - Print Receipt for Newton Course Sales
2381 if($template=='res_rpt_call_center_newton.tpl'){
2382
2383 //get payment code and payment name
2384 $sql = "
2385 SELECT CONCAT(tpop_code,' : ',tpop_name1) as payment_method FROM typeofpaymentmst
2386 LEFT JOIN resrve_detail ON resrve_detail.rdt_pay_method = typeofpaymentmst.tpop_no
2387 WHERE rdt_no = $rdt_no;";
2388
2389 $result = $nllDb->executeQuery($sql);
2390 $payment_method = $nllDb->fetchArray($result);
2391
2392 $sql = "
2393 SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(rdt_ref, '|', 2), '|', -1) AS transno FROM resrve_detail WHERE rdt_no = $rdt_no;";
2394 $result = $nllDb->executeQuery($sql);
2395 $res_transno = $nllDb->fetchArray($result);
2396
2397 $sSQL .= "
2398 IF($tbl_name1.dt_prdcode=0, '', CONCAT(DATE_FORMAT(rdt_crs_start_date, '%d/%m/%Y'), ' - ', DATE_FORMAT(rdt_crs_end_date, '%d/%m/%Y'))) AS course_duration, ";
2399
2400 $join_res = " LEFT JOIN resrve_detail ON $tbl_name1.dt_transno = '".$res_transno['transno']."' ";
2401
2402 }
2403
2404
2405 // Added by Alvin 20110526 #11370 - Add the column srce_address1, srce_address2, srce_address3, srce_address4 and srce_contact.
2406 // change recommendate price to dt_rec_price - bk (20150410)
2407 // Added by Huang 20150930 #24697 - left join sizemst on productmst.prdt_size=sizemst.size_no
2408 // Added by Peng Hing 20160302 #27043 - Add formula qty*prdt_gross_weight As total_gross_weight
2409 // Added by Faris #27710 - Add slmn_tel from salemanmst
2410 // Added by KahJun #31815 - Tokopak - Inventory - Add Column In Customer Invoice Printout
2411 // 20181018 May #35447 - SST -Debtor Master/Creditor Master add Exemption information
2412 // 20181112 Afiqah #35492 - Lii Hen - Inventory Entry, add m3 and m3_lii_hen in dt
2413 //20190621 Puteri #37893 - Milleon Extruder - add product userdefine4 to unprocessed at Customer Bill Invoice
2414 $sSQL .= " $tbl_name1.hd_rate, $tbl_name1.notes_key, dt_rec_price2,productmst.prdt_userdefine3,productmst.prdt_userdefine4,
2415 prdt_recommended_price as dt_rec_price,prdt_category,cate_code,cate_name1,cate_name2,prdt_cost,prdt_price,
2416 if($tbl_name1.dt_qty+$tbl_name1.dt_foc>0 and $tbl_name1.dt_price>0 and $tbl_name1.dt_price<>$tbl_name1.referer_price, '*', '') as chk_mark,
2417 $tbl_name1.dt_userdefine1 as dt_pkgs,
2418 $tbl_name1.dt_userdefine1,
2419 $tbl_name1.dt_userdefine2,
2420 $tbl_name1.dt_userdefine3,
2421 $tbl_name1.dt_userdefine4,
2422 $tbl_name1.dt_userdefine5,
2423 $tbl_name1.dt_userdefine6,
2424 $tbl_name1.dt_userdefine7,
2425 $tbl_name1.dt_userdefine8,
2426 $tbl_name1.dt_userdefine9,
2427 $tbl_name1.dt_userdefine10,
2428 $tbl_name1.cn_tax,
2429 $tbl_name1.dt_serial_number,
2430 storemst_b.st_code as dt_storecode,
2431 storemst_b.st_name1 as dt_storename,
2432 bussnaturemst.bn_code as bussnature,
2433 storemst.st_name2 as st_name2,
2434 storemst.st_address1 as st_add1,
2435 storemst.st_address2 as st_add2,
2436 storemst.st_address3 as st_add3,
2437 storemst.st_address4 as st_add4,
2438 storemst.st_tel as st_tel,
2439 storemst.st_fax as st_fax,
2440 storemst.st_email as st_email,
2441 storemst.st_contact as st_contact,
2442 storemst.st_userdefine1 as st_user1,
2443 storemst.st_pos_msg1 as msg1,
2444 storemst.st_pos_msg2 as msg2,
2445 storemst.st_pos_msg3 as msg3,
2446 storemst.st_pos_msg4 as msg4,
2447 salemanmst.slmn_code,
2448 salemanmst.slmn_name1,
2449 salemanmst.slmn_tel,
2450 sizemst.size_name1 as size_name1,
2451 areamst.area_code,
2452 areamst.area_name1,$disc_amount
2453 productmst.prdt_no, productmst.prdt_picture, brnd_no, brnd_code, brnd_name1, bn_name1, modl_no, modl_code, modl_name1,
2454 /*shelfmst_COL_tbl*/
2455 sourcemst.srce_code AS srce_code, sourcemst.srce_name1 AS srce_name1,sourcemst.srce_name1 as source_name, sourcemst.srce_address1 AS srce_address1,sourcemst.srce_address2 AS srce_address2,sourcemst.srce_address3 AS srce_address3,sourcemst.srce_address4 AS srce_address4, sourcemst.srce_contact AS srce_contact, sourcemst.srce_ref as srce_ref, jobmst.jb_code AS jb_code, jobmst.jb_name1 AS jb_name1, taskmst.task_code AS task_code, taskmst.task_name1 AS task_name1 ,storemst.st_code,storemst.st_name1,jobmst.jb_address1 AS jb_address1,jobmst.jb_address2 AS jb_address2,jobmst.jb_address3 AS jb_address3,jobmst.jb_address4 AS jb_address4,jobmst.jb_contact AS jb_contact,
2456 sourcemst_b.srce_code AS detail_source_code, sourcemst_b.srce_name1 AS detail_source_name, jobmst_b.jb_code AS detail_job_code, jobmst_b.jb_name1 AS detail_job_name,jobmst_b.jb_address1 AS detail_jb_address1,jobmst_b.jb_address2 AS detail_jb_address2,jobmst_b.jb_address3 AS detail_jb_address3,jobmst_b.jb_address4 AS detail_jb_address4,jobmst_b.jb_contact AS detail_jb_contact, taskmst_b.task_code AS detail_task_code, taskmst_b.task_name1 AS detail_task_name,
2457 prdt_measurement2,
2458 ROUND(($tbl_name1.dt_qty DIV prdt_measurement2),6) AS no_of_pack,
2459 ROUND(MOD($tbl_name1.dt_qty ,prdt_measurement2),6) AS loose_qty,
2460 zr_flag,
2461 if($tbl_name1.dt_userdefine2!='','1','') as temp_count2,
2462 if($tbl_name1.dt_qty>0 && $tbl_name1.dt_price='0' && '$chkFOC'='1', '1', '0') as foc_flag /* for grouping purpose, avoid row base foc group togather*/
2463 $field $TaxInvFields,
2464 if($tbl_name1.dt_qty=0.00,'',$tbl_name1.dt_desc ) as temp_desc, if($tbl_name1.dt_qty=0.00,'','(FOC)') as temp_foc, prdt_name1, prdt_name2,pdgptp_is_charges, if($tbl_name1.dt_price=0,'',1) as temp_count1,
2465 if(pdgptp_is_charges=1, $tbl_name1.dt_amount ,0.00 ) as extra_charges,
2466 if($tbl_name1.dt_userdefine2 <> @dt_userdefine2 and $tbl_name1.dt_userdefine2<> '', if(@dt_userdefine2='', @dt_userdefine2:=$tbl_name1.dt_userdefine2, @dt_userdefine2:=concat(@dt_userdefine2,',',$tbl_name1.dt_userdefine2)), @dt_userdefine2) as CPO,
2467 if($tbl_name1.dt_userdefine3 <> '',SUBSTRING_INDEX($tbl_name1.dt_userdefine3,'|',1), round($tbl_name1.dt_qty * prdt_measurement2, 2) )as ctn,
2468 if(prdt_measurement2 <> 0.00 and prdt_measurement2 is not null, concat_ws('',round(1.0 /prdt_measurement2,2), prdt_unit), '') as pack,
2469 if($tbl_name1.dt_userdefine3 <> '', SUBSTRING_INDEX(SUBSTRING_INDEX($tbl_name1.dt_userdefine3,'|',2),'|',-1), round($tbl_name1.dt_qty * prdt_gross_weight, 2)) as gw,
2470 if($tbl_name1.dt_userdefine3 <> '', SUBSTRING_INDEX(SUBSTRING_INDEX($tbl_name1.dt_userdefine3,'|',3),'|',-1), round($tbl_name1.dt_qty * prdt_weight, 2)) as nw,
2471 if($tbl_name1.dt_userdefine3 <> '', SUBSTRING_INDEX($tbl_name1.dt_userdefine3,'|',-1), round($tbl_name1.dt_qty * prdt_cumulative, 2)) as m,
2472 if($tbl_name1.dt_userdefine3 <> '', SUBSTRING_INDEX($tbl_name1.dt_userdefine3,'|',-1), round($tbl_name1.dt_qty * prdt_cumulative, 3)) as m_2,
2473 if($tbl_name1.dt_userdefine3 <> '', SUBSTRING_INDEX($tbl_name1.dt_userdefine3,'|',-1), round(IF ($tbl_name1.dt_foc > 0, $tbl_name1.dt_foc * prdt_cumulative, $tbl_name1.dt_qty * prdt_cumulative), 4)) as m3,
2474 round($tbl_name1.dt_qty * prdt_cumulative, 3) as m3_lii_hen,
2475 if(prdt_measurement2 <> 0.00 and prdt_measurement2 is not null, concat_ws('',round(1.0 /prdt_measurement2,2), '/', prdt_unit), '') as pack_2,
2476 color_code, color_name1,sizemst.size_code as size_code,
2477 ($tbl_name1.dt_final_amount_btax/$tbl_name1.dt_qty) AS dt_price_btax,wf_user.user_login_name as Approve_user, $approve_user1
2478 $tbl_name1.dt_final_amount_btax, IF($tbl_name1.dt_taxable=1, $tbl_name1.dt_final_amount_btax, 0) AS dt_final_amount_include_tax ,$tbl_name1.dt_final_amount_bvat
2479 $deposit_field
2480 $do_container
2481 $inv_field
2482 $serial_field
2483 $last_serial_store
2484 /*get the current system date time*/
2485 ,DATE_FORMAT(CURRENT_TIMESTAMP,'%d/%m/%Y %T') AS current_datetime,
2486 productmst.prdt_packing_case ,
2487 grpinv_code, grpinv_name1,
2488 $tbl_name1.hd_customer,prdt_tariff,grpinv_tariff, $tbl_name1.hd_date AS bill_date, $sortby_select
2489 ($tbl_name1.dt_qty+IFNULL($tbl_name1.dt_foc, 0))*IFNULL(prdt_weight, 0) AS total_weight,
2490 ($tbl_name1.dt_qty+IFNULL($tbl_name1.dt_foc, 0))*IFNULL(prdt_gross_weight, 0) AS total_gross_weight,
2491 /*prdt_tariff_fields*/
2492 /*taxexempt_certno_fields*/
2493 $tbl_name1.member_company_name,
2494 $tbl_name1.member_company_address1,
2495 $tbl_name1.member_company_address2,
2496 $tbl_name1.member_company_address3,
2497 $tbl_name1.member_company_address4
2498 $master_repack_field
2499 FROM ($tbl_name1
2500 INNER JOIN debtormst ON $tbl_name1.hd_customer = debtormst.dbtr_no)
2501 $join_ord_detail
2502 LEFT JOIN salemanmst ON $tbl_name1.hd_salesman = salemanmst.slmn_no
2503 LEFT JOIN areamst ON $tbl_name1.hd_area = areamst.area_no
2504 LEFT JOIN termmst ON $tbl_name1.hd_terms = termmst.term_no
2505 LEFT JOIN productmst ON $tbl_name1.dt_prdcode = productmst.prdt_no
2506 LEFT JOIN sizemst ON productmst.prdt_size=sizemst.size_no
2507 LEFT JOIN categorymst on productmst.prdt_category = categorymst.cate_no
2508 LEFT JOIN brandmst ON productmst.prdt_brand = brandmst.brnd_no
2509 LEFT JOIN modelmst ON productmst.prdt_model = modelmst.modl_no
2510 /*shelfmst_JOIN_tbl*/
2511 LEFT JOIN sourcemst ON $tbl_name1.hd_source = sourcemst.srce_no
2512 LEFT JOIN jobmst ON $tbl_name1.hd_job = jobmst.jb_no
2513 LEFT JOIN taskmst ON $tbl_name1.hd_task = taskmst.task_no
2514 LEFT JOIN sourcemst AS sourcemst_b ON $tbl_name1.dt_source = sourcemst_b.srce_no
2515 LEFT JOIN jobmst AS jobmst_b ON $tbl_name1.dt_job = jobmst_b.jb_no
2516 LEFT JOIN taskmst AS taskmst_b ON $tbl_name1.dt_task = taskmst_b.task_no
2517 LEFT JOIN storemst ON $tbl_name1.hd_store = storemst.st_no
2518 LEFT JOIN storemst as storemst_b ON $tbl_name1.dt_store = storemst_b.st_no
2519 LEFT JOIN groupinvmst on prdt_group = grpinv_no
2520 LEFT JOIN productgrptypemst on grpinv_type = pdgptp_no
2521 LEFT JOIN tms_drivermst ON $tbl_name1.hd_tms_driver=tms_drivermst.dvr_no
2522 LEFT JOIN tms_truckmst ON $tbl_name1.hd_truck=tms_truckmst.trk_no
2523 LEFT JOIN reasonmst ON $tbl_name1.hd_reason_no = reasonmst.reason_no
2524 $deposit_join
2525 /*bill_header_JOIN_dt*/
2526 /*customer_code_JOIN_tbl*/
2527 $join_tms
2528 LEFT JOIN bussnaturemst ON bussnaturemst.bn_no = debtormst.dbtr_business
2529 /*faizah*/
2530 LEFT join usermst moduser on $tbl_name1.hd_sys_last_mod_user = moduser.user_no
2531 LEFT join usermst adduser on $tbl_name1.hd_sys_add_user = adduser.user_no
2532 $join $join_tbl $TaxInvJoin
2533 /*william for notes value*/
2534 $join_notes
2535 /*william for user_login_name*/
2536 $join_user
2537 LEFT JOIN colormst on prdt_color = color_no
2538 LEFT JOIN $tbl_name10 ON wf_linked_documents LIKE '%hd_transno=$transo&hd_type1=$type1&hd_type2=$type2%'
2539 $joinDoc
2540 LEFT JOIN usermst wf_user ON $tbl_name10.wf_logic_login = wf_user.user_no
2541 $joinUser
2542 $DOJoin
2543 $serial_join
2544 $last_serial_join
2545 $master_repack_join
2546 /*tariffmst_join*/
2547 $join_res
2548 ";
2549 xs_include_event('InvBilBill');
2550
2551 /* 20191209 Amirul 39214 CSM - Inventory Bill Printing - Product Shelf need to take info from Store Item detail before take from product master */
2552 xs_include_event('UpdateProductShelf_StoreItemDetail');
2553
2554 // Check if the Custom Setting didn't replace the string, then replace it with default COLUMN and LEFT JOIN
2555 if (strpos($sSQL, '/*shelfmst_COL_tbl*/') == true || strpos($sSQL, '/*shelfmst_JOIN_tbl*/') == true) {
2556 // Replace COLUMN
2557 $select_col = " shelf_no, shelf_code, shelf_name1, ";
2558 $sSQL = str_replace("/*shelfmst_COL_tbl*/", $select_col, $sSQL);
2559
2560 // Replace LEFT JOIN
2561 $join_table = " LEFT JOIN shelfmst ON productmst.prdt_shelf = shelfmst.shelf_no ";
2562 $sSQL = str_replace("/*shelfmst_JOIN_tbl*/", $join_table, $sSQL);
2563 }
2564 /* END 39214 */
2565
2566//Checking whether FOC Type is active & there is FOC quantity
2567if($_SESSION["act371"])
2568{
2569 $sSQL .= " LEFT JOIN foc_typemst ON $tbl_name1.dt_foc_type = foc_typemst.type_no ";
2570}
2571//--end checking
2572
2573
2574
2575if($NLL_PRODUCT_MAP)
2576{
2577 $sSQL .= " LEFT JOIN cust_productmapmst ON prdmap_customer=$tbl_name1.hd_customer AND prdmap_product_no=$tbl_name1.dt_prdcode AND prdmap_mapcode=$tbl_name1.dt_mapcode ";
2578}
2579if($NLL_SHIPMENT)
2580{
2581 $sSQL .= " LEFT JOIN shipment_compmst on $tbl_name1.hd_shp_company = shpco_no ";
2582}
2583
2584//for Thailand Tax
2585if($_SESSION['PRINT_WT'] == 0){
2586 if($_SESSION['WT_PRODUCT'] != 0){
2587 $wt_item = $_SESSION['WT_PRODUCT'];
2588 $ww = " WHERE $tbl_name1.dt_prdcode <> $wt_item ";
2589 //$sSQL .= " $tbl_name1.dt_prdcode <> $wt_item ";
2590 $wt_sql = "SELECT abs(sum($tbl_name1.dt_amount)) FROM $tbl_name1 WHERE $tbl_name1.dt_prdcode = $wt_item; ";
2591
2592 }
2593
2594 if($_SESSION['VAT_PRODUCT'] != 0){
2595 $vat_item = $_SESSION['VAT_PRODUCT'];
2596 if($ww == '')
2597 {
2598 $ww = " WHERE $tbl_name1.dt_prdcode <> $vat_item ";
2599 }
2600 else
2601 {
2602 $ww .= " and $tbl_name1.dt_prdcode <> $vat_item ";
2603 }
2604 //$sSQL .= " and $tbl_name1.dt_prdcode <> $vat_item ";
2605 $vat_sql = "SELECT sum($tbl_name1.dt_amount) FROM $tbl_name1 WHERE $tbl_name1.dt_prdcode = $vat_item; ";
2606
2607 }
2608 if($ww != '')
2609 $sSQL .= $ww;
2610}
2611//Thai Tax End
2612
2613if($do_dsg_where !=''){ //for gp tme do dsg 30418 lengwee
2614 if($ww == '')
2615 $sSQL .= " WHERE $do_dsg_where ";
2616 else
2617 $sSQL .= " AND $do_dsg_where ";
2618}
2619
2620xs_include_event('InvBilWhere'); // 20180611 beeha #35085 - Mr Eng - S.O.S Mobile Services Centre (M) Sdn Bhd- Customize php to cater printing in full page
2621
2622//$consolidate=1;
2623// product consolidation by same product and price - Eric
2624if($report_format == '1' && $NLL_PRD_REPACK){
2625 //echo "Eric";
2626
2627
2628 if($NLL_PRODUCT_MAP)
2629 {
2630 if($consolidate)//product mapping and repacking is on with consolidation
2631 {
2632 // echo "a";
2633 $sSQL .= " GROUP BY $tbl_name1.hd_refno, IF(prdmap_mapcode is null, $tbl_name1.dt_prdcode, prdmap_mapcode), (IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 3) ,@delim2,-1), $tbl_name1.dt_unit)), $tbl_name1.dt_price, $tbl_name1.dt_unit ";
2634 }
2635 else //no consolidation
2636 {
2637 // echo "aaa";
2638 $sSQL .= " GROUP BY $tbl_name1.hd_refno, IF(prdmap_mapcode is null, $tbl_name1.dt_prdcode, prdmap_mapcode), (IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 3) ,@delim2,-1), $tbl_name1.dt_unit)),$tbl_name1.dt_transno, $tbl_name1.dt_transeqno, $tbl_name1.dt_price, $tbl_name1.dt_unit ";
2639 }
2640 }
2641 else
2642 {
2643 if($consolidate) //product repacking on with consolidations
2644 {
2645 $sSQL .= " GROUP BY $tbl_name1.hd_refno,(IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 3) ,@delim2,-1), $tbl_name1.dt_unit)), $tbl_name1.dt_prdcode, $tbl_name1.dt_price, $tbl_name1.dt_unit ";
2646 //echo "1";
2647 }
2648 else //no consolidation
2649 {
2650 //
2651 $sSQL .= " GROUP BY $tbl_name1.hd_refno,(IF(repk_row<>'', substring_index( substring_index( repk_row ,@delim2, 3) ,@delim2,-1), $tbl_name1.dt_unit)),$tbl_name1.dt_prdcode, $tbl_name1.dt_transno, $tbl_name1.dt_transeqno, $tbl_name1.dt_price, $tbl_name1.dt_unit ";
2652 //echo "111";
2653 }
2654 }
2655
2656}
2657
2658
2659else{ //if no mapcode, use product code to group
2660//echo "2";
2661
2662 if($NLL_PRODUCT_MAP)
2663 {
2664 if($consolidate)
2665 {
2666 $sSQL .= " GROUP BY $tbl_name1.hd_refno, $tbl_name1.dt_prdcode, $tbl_name1.dt_price, $tbl_name1.dt_unit ";
2667 //echo "2";
2668 }
2669 else
2670 {
2671 $sSQL .= " GROUP BY $tbl_name1.hd_refno,$tbl_name1.dt_transno, $tbl_name1.dt_transeqno, $tbl_name1.dt_prdcode, $tbl_name1.dt_price, $tbl_name1.dt_unit ";
2672 //echo "2.1";
2673 }
2674 }
2675 else
2676 {
2677 if($consolidate)
2678 {
2679 $sSQL .= " GROUP BY $tbl_name1.hd_refno, $tbl_name1.dt_prdcode, $tbl_name1.dt_price, $tbl_name1.dt_unit ";
2680 //echo "3";
2681 }
2682 else
2683 {
2684 $sSQL .= " GROUP BY $tbl_name1.hd_refno,$tbl_name1.dt_transno, $tbl_name1.dt_transeqno, $tbl_name1.dt_prdcode, $tbl_name1.dt_price, $tbl_name1.dt_unit ";
2685 //echo "4";
2686 }
2687 }
2688}
2689
2690//yinru @ 20170611 #31730 - repacking based on master formula
2691if($master_repack=='1')
2692 $sSQL .= $master_repack_group;
2693
2694if($_GET['chkSecurePDF']=='1') //20180228 leewah 33418 email secured PDF
2695{
2696 $orderDbtrCode = "debtormst.dbtr_name1, "; //to ensure only 1 pdf for each debtor, prevent pdf override
2697 $orderByDebtor = "dbtr_name1, "; //20190305 May #36812
2698}
2699
2700if($_SESSION["act375"]){
2701 $sSQL .= " ORDER BY $orderDbtrCode $tbl_name1.hd_refno, $tbl_name1.dt_sorting, $tbl_name1.dt_transeqno, $tbl_name1.dt_userdefine1, $tbl_name1.dt_userdefine2;";
2702}
2703else{
2704 //$sSQL .= " ORDER BY $tbl_name1.hd_refno, $tbl_name1.dt_transeqno, $tbl_name1.dt_userdefine1, $tbl_name1.dt_userdefine2;";
2705
2706 //20160330 Azwan 27746 - change order by condition
2707 if($sort_by=="dt_desc"){
2708 $sSQL.=" ORDER BY $orderDbtrCode $tbl_name1.hd_refno, $tbl_name1.dt_assembly_desc, $tbl_name1.dt_assembly, $tbl_name1.dt_desc, $tbl_name1.dt_transeqno, $tbl_name1.dt_userdefine1, $tbl_name1.dt_userdefine2;";
2709 }
2710 else if($sort_by=="dt_sorting"){
2711 $sSQL.=" ORDER BY $orderDbtrCode $tbl_name1.hd_refno, $tbl_name1.dt_assembly_code, $tbl_name1.dt_assembly, $tbl_name1.prd_code, $tbl_name1.dt_transeqno, $tbl_name1.dt_userdefine1, $tbl_name1.dt_userdefine2;";
2712 }
2713 else{
2714 $sSQL.=" ORDER BY $orderDbtrCode $tbl_name1.hd_refno, $tbl_name1.dt_transeqno, $tbl_name1.dt_userdefine1, $tbl_name1.dt_userdefine2;";
2715 }
2716}
2717
2718xs_include_event('show_tariff_and_tax_exemption'); //20190823 May #38145
2719//20160920 Azwan 29742 - Fix as_recno does not reset when print in batch
2720//20170704 May #31937
2721if($insert_recno=="1"){
2722 $nllDb->executeQuery($sSQL);
2723
2724 //20190228 May #36812 Hup Sheng - Inventory Purchase Order printout show quantity is double the value in entry
2725 //20191022 May #39060 Hup sheng - Inventory PO Printing out item will display few times causing total amount wrong
2726 $tbl_taxexempt = uniqid("tmp_tbl_taxexempt");
2727 $tbl_final = uniqid("tmp_tbl_final");
2728 $sql_drop_taxexempt = "DROP TABLE IF EXISTS $tbl_taxexempt,$tbl_final;";
2729 $nllDb->executeQuery($sql_drop_taxexempt);
2730 $taxexempt_sql = "CREATE TEMPORARY TABLE $tbl_taxexempt (INDEX(type1),INDEX(type2),INDEX(transno),INDEX(transeqno))
2731 SELECT dt_type1 AS type1, dt_type2 AS type2, dt_transno AS transno, dt_transeqno AS transeqno, taxexempt_dbtr_no, GROUP_CONCAT(taxexempt_cert_no) AS taxexempt_cert_no, GROUP_CONCAT(taxexempt_reference) AS taxexempt_reference, GROUP_CONCAT(ROUND(taxexempt_limit, 2)) AS taxexempt_limit, GROUP_CONCAT(taxexempt_info1) AS taxexempt_info1, GROUP_CONCAT(taxexempt_info2) AS taxexempt_info2, GROUP_CONCAT(taxexempt_tariff) AS taxexempt_tariff, tariff_code, GROUP_CONCAT(DATE_FORMAT(taxexempt_duration_from, '%d/%m/%Y')) AS taxexempt_duration_from, GROUP_CONCAT(DATE_FORMAT(taxexempt_duration_to, '%d/%m/%Y')) AS taxexempt_duration_to, GROUP_CONCAT(hd_customer) AS taxexempt_hd_customer, GROUP_CONCAT(prdt_tariff) AS taxexempt_prdt_tariff, GROUP_CONCAT(grpinv_tariff) AS taxexempt_grpinv_tariff
2732 FROM $tbl_name11
2733 LEFT JOIN dbtr_tax_exemptionmst ON $tbl_name11.hd_customer=taxexempt_dbtr_no AND IFNULL($tbl_name11.prdt_tariff, $tbl_name11.grpinv_tariff)=taxexempt_tariff
2734 LEFT JOIN tariffmst ON taxexempt_tariff=tariff_no
2735 WHERE bill_date BETWEEN taxexempt_duration_from AND taxexempt_duration_to
2736 GROUP by dt_type1, dt_type2, dt_transno, dt_transeqno;";
2737 $nlldb->executeQuery($taxexempt_sql);
2738 $final_tbl_sql = "CREATE TEMPORARY TABLE $tbl_final
2739 SELECT * FROM $tbl_name11
2740 LEFT JOIN $tbl_taxexempt ON $tbl_name11.dt_type1=$tbl_taxexempt.type1 AND $tbl_name11.dt_type2=$tbl_taxexempt.type2 AND $tbl_name11.dt_transno=$tbl_taxexempt.transno AND $tbl_name11.dt_transeqno=$tbl_taxexempt.transeqno ";
2741
2742 if($_SESSION["act375"]){
2743 $final_tbl_sql .= " ORDER BY $orderByDebtor hd_refno, dt_sorting, dt_transeqno, dt_userdefine1, dt_userdefine2;";
2744 }
2745 else{
2746 //20160330 Azwan 27746 - change order by condition
2747 if($sort_by=="dt_desc"){
2748 $final_tbl_sql.=" ORDER BY $orderByDebtor hd_refno, dt_assembly_desc, dt_assembly, dt_desc, dt_transeqno, dt_userdefine1, dt_userdefine2;";
2749 }
2750 else if($sort_by=="dt_sorting"){
2751 $final_tbl_sql.=" ORDER BY $orderByDebtor hd_refno, dt_assembly_code, dt_assembly, prd_code, dt_transeqno, dt_userdefine1, dt_userdefine2;";
2752 }
2753 else{
2754 $final_tbl_sql.=" ORDER BY $orderByDebtor hd_refno, dt_transeqno, dt_userdefine1, dt_userdefine2;";
2755 }
2756 }
2757
2758 $nlldb->executeQuery($final_tbl_sql);
2759 //20190228 #36812
2760
2761 $sSQL2="SELECT *,
2762 @f:=if((pdgptp_is_disc=0 or pdgptp_is_disc is null) and (pdgptp_is_tax =0 or pdgptp_is_tax is null) and (pdgptp_is_charges=0 or pdgptp_is_charges is null) and dt_prdcode <> 0, 1,0) as b,
2763 @flag:=if(pdgptp_is_item=1,1,@f) AS temp1,
2764 @reset:= if(@current<>concat(dt_transno, '-',dt_type1, '-', dt_type2),@counter:=1,@counter) AS temp2,
2765 if(@flag =1,concat(@counter,'.'), '') as rec_no,
2766 @counter := if(@flag =1,@counter +1,@counter) AS temp3,
2767 @flag2:=IF(dt_price <> 0,1,0) AS temp7,
2768 @reset3:= if(@current<>concat(dt_transno, '-',dt_type1, '-', dt_type2),@counter2:=1,@counter2) AS temp_counter2,
2769 IF(@flag2 =1,CONCAT(@counter2,'.'), '') AS rec_no2,
2770 @counter2 := IF(@flag2 =1,@counter2 +1,@counter2) AS temp8,
2771 @current:=concat(dt_transno, '-',dt_type1, '-', dt_type2) AS temp4,
2772 @reset2:= IF(@as_current<>CONCAT(dt_transno, '-',dt_type1, '-', dt_type2),@as_counter:=0,@as_counter) AS temp_reset,
2773 if(dt_assembly = 1, @as_counter:=@as_counter+1, if(@flag=1 and dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,
2774 if( dt_transeqno=1,@as_counter1:=0,@as_counter1) AS temp5,
2775 if( dt_transeqno=1,@as_counter2:=0,@as_counter2) AS temp6,
2776 if(dt_assembly = 2, @as_counter1:=@as_counter1+1, if(@flag=1 and dt_assembly <> 1, @as_counter1:=@as_counter1+1, '')) as countD,
2777 if(dt_assembly = 1, @as_counter2:=@as_counter2+1, if(@flag=1 and dt_assembly <> 2, @as_counter2:=@as_counter2+1, '')) as countE,
2778 if(dt_assembly = 1, concat(@as_counter,'.'), if(@flag=1 and dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,
2779 @as_current:=CONCAT(dt_transno, '-',dt_type1, '-', dt_type2) AS temp_as_current
2780 FROM $tbl_final
2781 ";
2782 $sSQL=$sSQL2;
2783}
2784
2785if($report_format == '1' && $NLL_PRD_REPACK){
2786 if($NLL_PRODUCT_MAP){
2787 $nllDb->executeQuery($sSQL);
2788 $sql = "set @counter :=0;";
2789 $nllDb->executeQuery($sql);
2790 $sql = "set @current:=(SELECT concat(dt_transno, '-',dt_type1, '-', dt_type2) FROM $tbl_name1 limit 1);";
2791 $nllDb->executeQuery($sql);
2792 $sql = "set @prdcode:='';";
2793 $nllDb->executeQuery($sql);
2794 $sql = "set @runningTokoVal:=0;";
2795 $nllDb->executeQuery($sql);
2796 $sql = "set @as_counter:=0;";
2797 $nllDb->executeQuery($sql);
2798 //20160418 cheefai #27943
2799 $sql = "set @previousTranseqno:='';";
2800 $nllDb->executeQuery($sql);
2801
2802 if($s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl" ||$s_template=="tkpbp_inv_rpt_ar_bil_inv1.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_sony.tpl")
2803 {
2804 $tbl_name4=uniqid("temp4_ar_bil_");
2805 $sql="drop table if exists $tbl_name4;";
2806 $nllDb->executeQuery($sql);
2807 $sql="create temporary table $tbl_name4
2808 SELECT b.*, sum(b.dt_qty) as total_qty, sum(b.dt_ini_amount) as total_amount,
2809 a.dt_import_transno as SO_import_transno, a.dt_import_transeqno as SO_import_transeqno,
2810 a.dt_import_type1 as SO_import_type1, a.dt_import_type2 as SO_import_type2,
2811 a.dt_import_refno as SO_import_refno,
2812 if(b.dbtr_no=14, NULL, dbtr_userdefine1) as dbtr_ud1,
2813 a.dt_sorting AS dt_sorting
2814 FROM $tbl_name3 b
2815 left join bill_detail a on
2816 a.dt_transno = b.dt_import_transno and
2817 a.dt_type1=b.dt_import_type1 and
2818 a.dt_type2= b.dt_import_type2 and
2819 a.dt_transeqno = b.dt_import_transeqno
2820 group by if( concat(a.dt_import_transno, a.dt_import_transeqno, a.dt_import_type1, a.dt_import_type2, b.keyfield) is null || concat(a.dt_import_transno, a.dt_import_transeqno, a.dt_import_type1, a.dt_import_type2, b.keyfield) =concat('00',b.keyfield), concat(b.keyfield, b.dt_transeqno),concat(a.dt_import_transno, a.dt_import_transeqno, a.dt_import_type1, a.dt_import_type2, b.keyfield));";
2821 $nllDb->executeQuery($sql);
2822
2823 //Phei Ling @20090904
2824 //#7885
2825 if ($single_copy=="1" || $bil_print_3copy==0){
2826 $tmpA = "temp_tableA";
2827 $dropSQL = "drop table if exists $tmpA;";
2828 $nllDb->executeQuery($dropSQL);
2829 if($_SESSION["act375"]){
2830 $sort = " , dt_sorting";
2831 }
2832 $sql1 = "create temporary table $tmpA
2833 SELECT * ,
2834 substring_index(dt_userdefine1, '-', 1) as PONO ,
2835 if(total_amount=0 && prdt_code is not null, 'F.O.C', total_amount) as dt_amount,
2836 @current:=keyfield
2837 FROM $tbl_name4 order by hd_refno $sort,dt_transeqno;";
2838
2839 $nllDb->executeQuery($sql1);
2840 $sSQL ="SELECT *,
2841 concat(hd_refno,'-1') as dummy_refno FROM $tmpA ";
2842 }
2843 else {
2844 //***
2845 //tokopak need to print 3 copies at once for each invoice
2846 $tmpA = "temp_tableA";
2847 $tmpB = "temp_tableB";
2848 $tmpC = "temp_tableC";
2849 $dropSQL = "drop table if exists $tmpA, $tmpB, $tmpC;";
2850 $nllDb->executeQuery($dropSQL);
2851
2852 $sql1 = "create temporary table $tmpA
2853 SELECT * ,
2854 substring_index(dt_userdefine1, '-', 1) as PONO ,
2855 if(total_amount=0 && prdt_code is not null, 'F.O.C', total_amount) as dt_amount,
2856 @current:=keyfield
2857 FROM $tbl_name4 order by hd_refno, dt_transeqno;";
2858
2859 $sql2 = "create temporary table $tmpB
2860 SELECT * FROM $tmpA; ";
2861 $sql3 = "create temporary table $tmpC
2862 SELECT * FROM $tmpA WHERE dbtr_userdefine4=1 ;";
2863
2864 $nllDb->executeQuery($sql1);
2865 $nllDb->executeQuery($sql2);
2866 $nllDb->executeQuery($sql3);
2867
2868 if($s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_sony.tpl"){
2869 $tmpD = "temp_tableD";
2870 $drop_tmpD_SQL = "drop table if exists $tmpD;";
2871 $nllDb->executeQuery($drop_tmpD_SQL);
2872 $sql4="create temporary table $tmpD
2873 SELECT * FROM $tmpA WHERE dbtr_userdefine4=1 ;";
2874 $nllDb->executeQuery($sql4);
2875 $tmpD_sql=" union all
2876 SELECT *, 'Customer Copy' as footer_title,
2877 concat(hd_refno,'-4') as dummy_refno FROM $tmpD ";
2878 }
2879
2880 if ($bil_print_3copy==3)
2881 $sSQL ="SELECT *, 'Master Copy' as footer_title,
2882 concat(hd_refno,'-1') as dummy_refno FROM $tmpA
2883 union all ";
2884 else
2885 $sSQL ="";
2886 $sSQL .=" SELECT *, 'Accounts Copy' as footer_title,
2887 concat(hd_refno,'-2') as dummy_refno FROM $tmpB
2888 union all
2889 SELECT *, 'Customer Copy' as footer_title,
2890 concat(hd_refno,'-3') as dummy_refno FROM $tmpC
2891 $tmpD_sql
2892 order by dummy_refno ";
2893 }
2894 //end
2895 }
2896 else
2897 {
2898 //#8091
2899 if($s_template=="tokopak_do.tpl" || $s_template=="tokopak_do_smmdo.tpl" || $s_template=="tokopak_do_with_lesenno.tpl"||$s_template=="tokopak1_do.tpl" ||$s_template=="tokopak_pl.tpl" ||$s_template=="tkp_tpbp_inv_rpt_ar_bill_do.tpl" ||$s_template=="tkp_tps_tppg_inv_rpt_ar_bill_do.tpl" ||$s_template=="tkpbp_inv_rpt_ar_bill_DO.tpl" || $s_template=="do_deliver_to_tokopak.tpl")
2900 {
2901 //***
2902 //tokopak need to print the loose packet in the other row
2903 //COMMENT: dt_userdefine2 is for dynamic packing measurement for CUT-SHEET product
2904
2905 $tmpA = "temp_tableA";
2906 $tmpB = "temp_tableB";
2907 $tmpC = "temp_tableC";
2908 $tmpD = "temp_tableD";
2909 $dropSQL = "drop table if exists $tmpA, $tmpB, $tmpC, $tmpD;";
2910 $nllDb->executeQuery($dropSQL);
2911
2912 $sql1 = "create temporary table $tmpA
2913 SELECT * ,
2914 if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount,
2915 round(mod(dt_qty ,if(dt_userdefine2!='' and dt_userdefine2 is not null, dt_userdefine2, prdt_measurement2)),6) as loose,
2916 ceil(dt_qty/if(dt_userdefine2!='' and dt_userdefine2 is not null, dt_userdefine2, prdt_measurement2)) as temp_qty_pkt,
2917 @current:=keyfield
2918 FROM $tbl_name3;
2919 ";
2920
2921 //full packing product first
2922 //COMMENT: the WHERE condition is to INCLUDE name2 as well
2923 $sql2 = "create temporary table $tmpB
2924 SELECT *,
2925 prdt_code as pcode,
2926 temp_qty_pkt as qty_pkt,
2927 if(dt_userdefine2!='' and dt_userdefine2 is not null, dt_userdefine2, prdt_measurement2) as prdt_msm,
2928 if(loose is not null, (dt_qty - loose), dt_qty) as final_dt_qty
2929 FROM $tmpA
2930 /*WHERE dt_qty >= prdt_measurement2*/
2931 WHERE ((prdt_code is not null && dt_qty >= if(dt_userdefine2!='' and dt_userdefine2 is not null, dt_userdefine2, prdt_measurement2)) or (prdt_code is null or prdt_code=''))
2932 ;";
2933
2934 //loose packing product
2935 $sql3 = "create temporary table $tmpC
2936 SELECT *,
2937 if(dt_qty > if(dt_userdefine2!='' and dt_userdefine2 is not null, dt_userdefine2, prdt_measurement2),'', prdt_code) as pcode,
2938 1 as qty_pkt,
2939 loose as prdt_msm,
2940 loose as final_dt_qty
2941 FROM $tmpA WHERE loose is not null and loose<>0;";
2942
2943 $sql4 = "create temporary table $tmpD
2944 SELECT * FROM $tmpB union all SELECT * FROM $tmpC
2945 order by hd_refno, dt_transeqno, dt_userdefine1, dt_userdefine2;";
2946
2947 $nllDb->executeQuery($sql1);
2948 $nllDb->executeQuery($sql2);
2949 $nllDb->executeQuery($sql3);
2950 $nllDb->executeQuery($sql4);
2951
2952 $sSQL ="
2953 SELECT * ,
2954 if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount,
2955 if(@current<>keyfield, @counter:=0, @counter) as countA,
2956 IF(@current<>keyfield, @as_counter:=0, @as_counter) AS countA_1,
2957 if(flag=1 and @prdcode<>prdt_code, @counter:=@counter+1, IF(@current<>keyfield,@counter:=@counter+1, @counter)) as countB,
2958 if(flag=1 and @prdcode<>prdt_code,concat(@counter,'.'),IF(@current<>keyfield,concat(@counter,'.'), '')) as rec_no,
2959 if(dt_assembly = 1, @as_counter:=@as_counter+1, if(flag=1 and dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,
2960 if(dt_assembly = 1, concat(@as_counter,'.'), if(flag=1 and dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,
2961 if(prdt_code is not null, @prdcode:=prdt_code, @prdcode:='') as prdA,
2962 if(@current=keyfield,1,@runningTokoVal:=0) as runno,
2963 if((dt_ini_amount=0 && prdt_code is null) or (dt_ini_amount=0 && prdt_code is not null),'',@runningTokoVal:=@runningTokoVal) as fromToko,
2964 if((dt_ini_amount=0 && prdt_code is null) or (dt_ini_amount=0 && prdt_code is not null),'',concat(@runningTokoVal:=@runningTokoVal+1,'-',@runningTokoVal:=@runningTokoVal -if(final_dt_qty>0,1,0) + ceil(final_dt_qty/ifnull(prdt_msm,1) )) ) as toToko,
2965 ceil(final_dt_qty/prdt_msm) as qty_pkt,
2966 @current:=keyfield
2967 FROM $tmpD;
2968 ";
2969
2970 //print 3 copies at once for each DO when template is tokopak1_do.tpl
2971 //if ($s_template=="tokopak1_do.tpl")
2972 //#7885
2973 if ($single_copy=="1" || $bil_print_3copy==0){
2974 $sSQL = "SELECT * ,
2975 if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount_temp,
2976 if(@current<>keyfield, @counter:=0, @counter) as countA,
2977 IF(@current<>keyfield, @as_counter:=0, @as_counter) AS countA_1,
2978 if(flag=1 and @prdcode<>prdt_code, @counter:=@counter+1, IF(@current<>keyfield,@counter:=@counter+1, @counter)) as countB,
2979 if(flag=1 and @prdcode<>prdt_code,concat(@counter,'.'),IF(@current<>keyfield,concat(@counter,'.'), '')) as rec_no,
2980 if(dt_assembly = 1, @as_counter:=@as_counter+1, if(flag=1 and dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,
2981 if(dt_assembly = 1, concat(@as_counter,'.'), if(flag=1 and dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,
2982 if(prdt_code is not null, @prdcode:=prdt_code, @prdcode:='') as prdA,
2983 if(@current=keyfield,1,@runningTokoVal:=0) as runno,
2984 if((dt_ini_amount=0 && prdt_code is null) or (dt_ini_amount=0 && prdt_code is not null),'',@runningTokoVal:=@runningTokoVal) as fromToko,
2985 if((dt_ini_amount=0 && prdt_code is null) or (dt_ini_amount=0 && prdt_code is not null),'',concat(@runningTokoVal:=@runningTokoVal+1,'-',@runningTokoVal:=@runningTokoVal -if(final_dt_qty>0,1,0) + ceil(final_dt_qty/ifnull(prdt_msm,1) )) ) as toToko,
2986 ceil(final_dt_qty/prdt_msm) as qty_pkt_temp,
2987 @current:=keyfield as keyfield_temp
2988 FROM $tmpD;";
2989 }
2990 else{
2991 $tmpA = "temp_tableA";
2992 $tmpB = "temp_tableB";
2993 $tmpC = "temp_tableC";
2994 $dropSQL = "drop table if exists $tmpA, $tmpB, $tmpC;";
2995 $nllDb->executeQuery($dropSQL);
2996
2997 $sql1 = "create temporary table $tmpA
2998 SELECT * ,
2999 if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount_temp,
3000 if(@current<>keyfield, @counter:=0, @counter) as countA,
3001 IF(@current<>keyfield, @as_counter:=0, @as_counter) AS countA_1,
3002 if(flag=1 and @prdcode<>prdt_code, @counter:=@counter+1, IF(@current<>keyfield,@counter:=@counter+1, @counter)) as countB,
3003 if(flag=1 and @prdcode<>prdt_code,concat(@counter,'.'),IF(@current<>keyfield,concat(@counter,'.'), '')) as rec_no,
3004 if(dt_assembly = 1, @as_counter:=@as_counter+1, if(flag=1 and dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,
3005 if(dt_assembly = 1, concat(@as_counter,'.'), if(flag=1 and dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,
3006 if(prdt_code is not null, @prdcode:=prdt_code, @prdcode:='') as prdA,
3007 if(@current=keyfield,1,@runningTokoVal:=0) as runno,
3008 if((dt_ini_amount=0 && prdt_code is null) or (dt_ini_amount=0 && prdt_code is not null),'',@runningTokoVal:=@runningTokoVal) as fromToko,
3009 if((dt_ini_amount=0 && prdt_code is null) or (dt_ini_amount=0 && prdt_code is not null),'',concat(@runningTokoVal:=@runningTokoVal+1,'-',@runningTokoVal:=@runningTokoVal -if(final_dt_qty>0,1,0) + ceil(final_dt_qty/ifnull(prdt_msm,1) )) ) as toToko,
3010 ceil(final_dt_qty/prdt_msm) as qty_pkt_temp,
3011 @current:=keyfield as keyfield_temp
3012 FROM $tmpD;";
3013 $sql2 = "create temporary table $tmpB
3014 SELECT * FROM $tmpA; ";
3015 $sql3 = "create temporary table $tmpC
3016 SELECT * FROM $tmpA ;";
3017
3018 $nllDb->executeQuery($sql1);
3019 $nllDb->executeQuery($sql2);
3020 $nllDb->executeQuery($sql3);
3021
3022 if($s_template=="tokopak_do.tpl"){
3023 $tmpE = "temp_tableE";
3024 $drop_tmpE_SQL = "drop table if exists $tmpE;";
3025 $nllDb->executeQuery($drop_tmpE_SQL);
3026 $sql4="create temporary table $tmpE
3027 SELECT * FROM $tmpA ;";
3028 $nllDb->executeQuery($sql4);
3029 $tmpE_sql=" union all
3030 SELECT *, 'Customer Copy' as footer_title,
3031 concat(hd_refno,'-4') as dummy_refno FROM $tmpE ";
3032 }
3033
3034 $sSQL ="SELECT *, 'Customer Copy' as footer_detail,
3035 concat(hd_refno,'-1') as dummy_refno FROM $tmpA
3036 union all
3037 SELECT *, 'A/C Copy' as footer_detail,
3038 concat(hd_refno,'-2') as dummy_refno FROM $tmpB $tmpE_sql";
3039 if ($bil_print_3copy==3)
3040 $sSQL .=" union all
3041 SELECT *, 'Master Copy' as footer_detail,
3042 concat(hd_refno,'-3') as dummy_refno FROM $tmpC ";
3043
3044 $sSQL.="order by dummy_refno ";
3045 }
3046
3047 //***
3048 }
3049 //Phei Ling @20091015
3050 //print 3 copies at once for each cash bill
3051 else if($s_template=="inv_rpt_ar_bil_cb_tokopak4.tpl")
3052{
3053
3054 $tbl_name7=uniqid("temp7_ar_bil_");
3055 $sql="drop table if exists $tbl_name7;";
3056 $nllDb->executeQuery($sql);
3057 $sql="create temporary table $tbl_name7
3058 SELECT * ,
3059 if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount_temp,
3060 if(@current<>keyfield, @counter:=0, @counter) as countA,
3061 IF(@current<>keyfield, @as_counter:=0, @as_counter) AS countA_1,
3062 if(flag=1 and @prdcode<>prdt_code, @counter:=@counter+1, IF(@current<>keyfield,@counter:=@counter+1, @counter)) as countB,
3063 if(flag=1 and @prdcode<>prdt_code,concat(@counter,'.'),IF(@current<>keyfield,concat(@counter,'.'), '')) as rec_no,
3064 if(dt_assembly = 1, @as_counter:=@as_counter+1, if(flag=1 and dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,
3065 if(dt_assembly = 1, concat(@as_counter,'.'), if(flag=1 and dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,
3066 if(prdt_code is not null, @prdcode:=prdt_code, @prdcode:='') as prdA,
3067 if(@current=keyfield,1,@runningTokoVal:=0) as runno,
3068 if(dt_ini_amount=0 && prdt_code is not null,'',@runningTokoVal:=@runningTokoVal) as fromToko,
3069 if(dt_ini_amount=0 && prdt_code is not null,'',concat(@runningTokoVal:=@runningTokoVal+1,'-',@runningTokoVal:=@runningTokoVal -if(dt_Qty>0,1,0) + ceil(dt_qty/ifnull(prdt_measurement2,1) )) ) as toToko,
3070 round(mod(dt_qty ,prdt_measurement2),6) as loose,
3071 ceil(dt_qty/prdt_measurement2) as qty_pkt_temp,
3072 prdt_measurement2 as prdt_msm, prdt_code as pcode,
3073 @current:=keyfield as keyfield_temp
3074 FROM $tbl_name3;
3075 ";
3076 $nllDb->executeQuery($sql);
3077
3078 //print single copy when single copy is tick
3079 //if ($single_copy=="1")
3080 //#7885
3081 if ($single_copy=="1" || $bil_print_3copy==0){
3082 $tmpA = "temp_tableA";
3083 $dropSQL = "drop table if exists $tmpA;";
3084 $nllDb->executeQuery($dropSQL);
3085 $sql1 = "create temporary table $tmpA
3086 SELECT * ,
3087 if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount,
3088 @current:=keyfield
3089 FROM $tbl_name7;";
3090
3091 $nllDb->executeQuery($sql1);
3092 $sSQL ="SELECT *,
3093 concat(hd_refno,'-1') as dummy_refno FROM $tmpA ";
3094 }
3095 else {
3096 //print 3 copies at once
3097 $tmpA = "temp_tableA";
3098 $tmpB = "temp_tableB";
3099 $tmpC = "temp_tableC";
3100 $dropSQL = "drop table if exists $tmpA, $tmpB, $tmpC;";
3101 $nllDb->executeQuery($dropSQL);
3102
3103 $sql1 = "create temporary table $tmpA
3104 SELECT * ,
3105 if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount,
3106 @current:=keyfield
3107 FROM $tbl_name7;";
3108
3109 $sql2 = "create temporary table $tmpB
3110 SELECT * FROM $tmpA; ";
3111
3112 $sql3 = "create temporary table $tmpC
3113 SELECT * FROM $tmpA ;";
3114
3115 $nllDb->executeQuery($sql1);
3116 $nllDb->executeQuery($sql2);
3117 $nllDb->executeQuery($sql3);
3118
3119
3120 $sSQL="SELECT *,'Customer Copy' as footer_detail,concat(hd_refno,'-1') as dummy_refno FROM $tmpA
3121 union all
3122 SELECT *, 'A/C Copy' as footer_detail,concat(hd_refno,'-2') as dummy_refno FROM $tmpB ";
3123 if ($bil_print_3copy==3)
3124 $sSQL .=" union all SELECT *,'Master Copy' as footer_detail,concat(hd_refno,'-3') as dummy_refno FROM $tmpC ";
3125 $sSQL .=" order by dummy_refno ;";
3126 }
3127 }
3128 //end
3129
3130 else if($s_template=="eisentech_inv_rpt_ar_bil_inv_preprint.tpl" || $s_template=="eisentech_inv_rpt_ar_bil_inv_proforma.tpl" || $s_template=="ja_inv_rpt_ar_bil_inv_preprint.tpl" || $s_template=="eisentech_inv_rpt_bil_dncn.tpl" || $s_template=="ja_inv_rpt_bil_dncn.tpl")
3131
3132 { /** For eisentech tpl - 1st row for qty , 2nd row for foc qty in details */
3133 $tbl_name_Eis1=uniqid("temp_eisentech1_");
3134 $tbl_name_Eis2=uniqid("temp_eisentech2_");
3135 $tbl_name_Eis3=uniqid("temp_eisentech3_");
3136 $sqldrop="drop table if exists $tbl_name_Eis1;";
3137 $nllDb->executeQuery($sqldrop);
3138 $sqlA="create temporary table $tbl_name_Eis1
3139 SELECT * ,
3140 if(pdgptp_is_charges =1,0.00, dt_ini_amount) as dt_amount,if(pdgptp_is_charges =1,0.00, dt_ini_amount) as dt_amountA, dt_ini_amount as dt_amount2,if(pdgptp_is_charges =1, '', dt_price) as dt_price2,if(pdgptp_is_charges =1, '', dt_qty) as qtyA,prdt_code as codeE,
3141 if(pdgptp_is_charges =1, '', dt_desc) as dt_descE, if(prdt_code is not null, @prdcode:=prdt_code, @prdcode:='') as prdA
3142 FROM $tbl_name3 WHERE (dt_qty <>0.00 or prdt_code is null)
3143 ";
3144
3145 $nllDb->executeQuery($sqlA);
3146
3147
3148 $sqldrop="drop table if exists $tbl_name_Eis2;";
3149 $nllDb->executeQuery($sqldrop);
3150 $sqlB="create temporary table $tbl_name_Eis2
3151 SELECT * ,
3152 '(FOC)' as dt_amount,0.00 as dt_amountA, dt_ini_amount as dt_amount2,'(FOC)' as dt_price2, dt_foc as qtyA,'' as codeE,
3153 dt_desc as dt_descE, if(prdt_code is not null, @prdcode:=prdt_code, @prdcode:='') as prdA
3154 FROM $tbl_name3 WHERE dt_foc <>0.00;
3155 ";
3156
3157 $nllDb->executeQuery($sqlB);
3158
3159 $sqldrop="drop table if exists $tbl_name_Eis3;";
3160 $nllDb->executeQuery($sqldrop);
3161 $sqlC="create temporary table $tbl_name_Eis3
3162 SELECT *
3163 FROM $tbl_name_Eis1 union SELECT * FROM $tbl_name_Eis2 order by hd_refno,dt_transeqno;";
3164 $nllDb->executeQuery($sqlC);
3165 $sql = "set @counter :=0;";
3166 $nllDb->executeQuery($sql);
3167 $sql = "set @current:=(SELECT concat(dt_transno, '-',dt_type1, '-', dt_type2) FROM $tbl_name1 limit 1);";
3168 $nllDb->executeQuery($sql);
3169 $sql = "set @prdcode:='';";
3170 $nllDb->executeQuery($sql);
3171 $sql = "set @runningTokoVal:=0;";
3172 $nllDb->executeQuery($sql);
3173 $sql = "set @as_counter:=0;";
3174 $nllDb->executeQuery($sql);
3175 $sql = "set @previousTranseqno:='';";
3176 $nllDb->executeQuery($sql);
3177
3178 $sSQL="SELECT *,
3179 if(@current<>keyfield, @counter:=0, @counter) as countA,
3180 IF(@current<>keyfield, @as_counter:=0, @as_counter) AS countA_1,
3181 if(flag=1 and @prdcode<>prdt_code, @counter:=@counter+1, IF(@current<>keyfield,@counter:=@counter+1, @counter)) as countB,
3182 if(flag=1 and @prdcode<>prdt_code,concat(@counter,'.'),IF(@current<>keyfield,concat(@counter,'.'), '')) as rec_no,
3183 if(dt_assembly = 1, @as_counter:=@as_counter+1, if(flag=1 and dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,
3184 if(dt_assembly = 1, concat(@as_counter,'.'), if(flag=1 and dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,
3185 current:=keyfield
3186 FROM $tbl_name_Eis3;";
3187 }// end eisentech
3188
3189
3190 else
3191 {
3192 //#7885
3193 if ($single_copy=="1" || $bil_print_3copy==0){
3194
3195// if(strpos($s_template,"_with_serial")!==false || strpos($orig_template,"_with_serial")!==false){
3196// // formulate number of serial per row - bk (20110624) #11328 Start
3197// $tbl_serial=uniqid("tmp_serial_");
3198// $nllDb->executeQuery("DROP TEMPORARY TABLE IF EXISTS $tbl_serial;");
3199// $sql_serial="CREATE TEMPORARY TABLE $tbl_serial
3200// SELECT * ,
3201// if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount,
3202// if(@current<>keyfield, @counter:=0, @counter) as countA,
3203// if(flag=1 and @prdcode<>prdt_code, @counter:=@counter+1, @counter) as countB,
3204// if(flag=1 and @prdcode<>prdt_code,concat(@counter,'.'),'') as rec_no,
3205// if(dt_assembly = 1, @as_counter:=@as_counter+1, if(flag=1 and dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,
3206// if(dt_assembly = 1, concat(@as_counter,'.'), if(flag=1 and dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,
3207// if(prdt_code is not null, @prdcode:=prdt_code, @prdcode:='') as prdA,
3208// if(@current=keyfield,1,@runningTokoVal:=0) as runno,
3209// if(dt_ini_amount=0 && prdt_code is not null,'',@runningTokoVal:=@runningTokoVal) as fromToko,
3210// if(dt_ini_amount=0 && prdt_code is not null,'',concat(@runningTokoVal:=@runningTokoVal+1,'-',@runningTokoVal:=@runningTokoVal -if(dt_Qty>0,1,0) + ceil(dt_qty/ifnull(prdt_measurement2,1) )) ) as toToko,
3211// mod(dt_qty ,prdt_measurement2) as loose,
3212// ceil(dt_qty/prdt_measurement2) as qty_pkt,
3213// prdt_measurement2 as prdt_msm, prdt_code as pcode,
3214// @current:=keyfield
3215// FROM $tbl_name3;
3216// ";
3217// $nllDb->executeQuery($sql_serial);
3218//
3219// $result_serial=$nllDb->executeQuery("SELECT hd_type2,serial_no,hd_refno,dt_transno,dt_transeqno,dt_userdefine1,dt_userdefine2 FROM $tbl_serial WHERE serial_no!='' AND serial_no IS NOT NULL");
3220// while($row_serial=$nllDb->fetchArray($result_serial)){
3221// // get and loop all transaction that with serial number to formulate
3222// $serial_type2=$row_serial['hd_type2'];
3223// $serial_no_batch=$row_serial['serial_no'];
3224// $serial_refno=$row_serial['hd_refno'];
3225// $serial_transno=$row_serial['dt_transno'];
3226// $serial_transeqno=$row_serial['dt_transeqno'];
3227// $serial_userdefine1=$row_serial['dt_userdefine1'];
3228// $serial_userdefine2=$row_serial['dt_userdefine2'];
3229//
3230// if($serial_no_batch!=""){
3231// $sql_serial_row="SELECT bilctrl_print_serial_per_row FROM bill_control WHERE bilctrl_doc='AR-BIL' AND bilctrl_name='$serial_type2' LIMIT 1";
3232// $result_serial_row=$nllDb->executeQuery($sql_serial_row);
3233// list($serial_per_row)=$nllDb->fetchRow($result_serial_row);
3234//
3235// if($serial_per_row!=''){
3236// // when got set number of serial per row
3237// $serial_no="";
3238// $array_serial=array();
3239// $array_serial_batch=explode(",",$serial_no_batch);
3240// $count_serial=count($array_serial_batch);
3241// for($i_serial=1;$i_serial<=$count_serial;$i_serial++){
3242// $array_serial[]=$array_serial_batch[$i_serial-1];
3243// if($i_serial%$serial_per_row==0 || $i_serial==$count_serial){
3244// $serial_no=implode(",",$array_serial);
3245// $sql_insert_serial="INSERT INTO $tbl_serial SET hd_refno='$serial_refno', dt_desc='$serial_no', dt_transno='$serial_transno', dt_transeqno='$serial_transeqno', dt_userdefine1='$serial_userdefine1', dt_userdefine2='$serial_userdefine2'";
3246// $nllDb->executeQuery($sql_insert_serial);
3247// $array_serial=array();
3248// }
3249// }
3250// }
3251// else{
3252// $sql_insert_serial="INSERT INTO $tbl_serial SET hd_refno='$serial_refno', dt_desc='$serial_no_batch', dt_transno='$serial_transno', dt_transeqno='$serial_transeqno', dt_userdefine1='$serial_userdefine1', dt_userdefine2='$serial_userdefine2'";
3253// $nllDb->executeQuery($sql_insert_serial);
3254// }
3255// }
3256// }
3257//
3258// $sSQL="SELECT * FROM $tbl_serial ORDER BY hd_refno, dt_transeqno, dt_userdefine1, dt_userdefine2 ";
3259//
3260// // formulate number of serial per row - bk (20110624) #11328 End
3261// }
3262// else{
3263// $sSQL ="
3264// SELECT /*xxx*/ * ,
3265// if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount,
3266// if(@current<>keyfield, @counter:=0, @counter) as countA,
3267// if(flag=1 and @prdcode<>prdt_code, @counter:=@counter+1, @counter) as countB,
3268// if(flag=1 and @prdcode<>prdt_code,concat(@counter,'.'),'') as rec_no,
3269// if(dt_assembly = 1, @as_counter:=@as_counter+1, if(flag=1 and dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,
3270// if(dt_assembly = 1, concat(@as_counter,'.'), if(flag=1 and dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,
3271// if(prdt_code is not null, @prdcode:=prdt_code, @prdcode:='') as prdA,
3272// if(@current=keyfield,1,@runningTokoVal:=0) as runno,
3273// if(dt_ini_amount=0 && prdt_code is not null,'',@runningTokoVal:=@runningTokoVal) as fromToko,
3274// if(dt_ini_amount=0 && prdt_code is not null,'',concat(@runningTokoVal:=@runningTokoVal+1,'-',@runningTokoVal:=@runningTokoVal -if(dt_Qty>0,1,0) + ceil(dt_qty/ifnull(prdt_measurement2,1) )) ) as toToko,
3275// mod(dt_qty ,prdt_measurement2) as loose,
3276// ceil(dt_qty/prdt_measurement2) as qty_pkt,
3277// prdt_measurement2 as prdt_msm, prdt_code as pcode,
3278// @current:=keyfield
3279// FROM $tbl_name3;
3280// ";
3281// }
3282
3283 $sSQL ="
3284 SELECT /*xxx*/ * ,
3285 if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount,
3286 if(@current<>keyfield, @counter:=0, @counter) as countA,
3287 IF(@current<>keyfield, @as_counter:=0, @as_counter) AS countA_1,
3288 if(flag=1 AND @previousTranseqno<>dt_transeqno, @counter:=@counter+1, IF(@current<>keyfield,@counter:=@counter+1, @counter)) as countB,
3289 if(flag=1 AND @previousTranseqno<>dt_transeqno,concat(@counter,'.'),IF(@current<>keyfield,concat(@counter,'.'), '')) as rec_no,
3290 if(dt_assembly = 1, @as_counter:=@as_counter+1, if(flag=1 and dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,
3291 if(dt_assembly = 1, concat(@as_counter,'.'), if(flag=1 and dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,
3292 if(prdt_code is not null, @prdcode:=prdt_code, @prdcode:='') as prdA,
3293 if(@current=keyfield,1,@runningTokoVal:=0) as runno,
3294 if(dt_ini_amount=0 && prdt_code is not null,'',@runningTokoVal:=@runningTokoVal) as fromToko,
3295 if(dt_ini_amount=0 && prdt_code is not null,'',concat(@runningTokoVal:=@runningTokoVal+1,'-',@runningTokoVal:=@runningTokoVal -if(dt_Qty>0,1,0) + ceil(dt_qty/ifnull(prdt_measurement2,1) )) ) as toToko,
3296 round(mod(dt_qty ,prdt_measurement2),6) as loose,
3297 ceil(dt_qty/prdt_measurement2) as qty_pkt,
3298 prdt_measurement2 as prdt_msm, prdt_code as pcode,
3299 @current:=keyfield,
3300 @previousTranseqno:=dt_transeqno
3301 FROM $tbl_name3;
3302 ";
3303 }
3304 else{
3305 $tmpA = "temp_tableA";
3306 $tmpB = "temp_tableB";
3307 $tmpC = "temp_tableC";
3308 $dropSQL = "drop table if exists $tmpA, $tmpB, $tmpC;";
3309 $nllDb->executeQuery($dropSQL);
3310
3311 $sql1 = "create temporary table $tmpA
3312 SELECT * ,
3313 if(dt_ini_amount=0 && prdt_code is not null, 'F.O.C', dt_ini_amount) as dt_amount,
3314 if(@current<>keyfield, @counter:=0, @counter) as countA,
3315 IF(@current<>keyfield, @as_counter:=0, @as_counter) AS countA_1,
3316 if(flag=1 and @previousTranseqno<>dt_transeqno, @counter:=@counter+1, IF(@current<>keyfield,@counter:=@counter+1, @counter)) as countB,
3317 if(flag=1 and @previousTranseqno<>dt_transeqno,concat(@counter,'.'),IF(@current<>keyfield,concat(@counter,'.'), '')) as rec_no,
3318 if(dt_assembly = 1, @as_counter:=@as_counter+1, if(flag=1 and dt_assembly <> 2, @as_counter:=@as_counter+1, '')) as countC,
3319 if(dt_assembly = 1, concat(@as_counter,'.'), if(flag=1 and dt_assembly <> 2,concat(@as_counter,'.'),'') ) as as_recno,
3320 if(prdt_code is not null, @prdcode:=prdt_code, @prdcode:='') as prdA,
3321 if(@current=keyfield,1,@runningTokoVal:=0) as runno,
3322 if(dt_ini_amount=0 && prdt_code is not null,'',@runningTokoVal:=@runningTokoVal) as fromToko,
3323 if(dt_ini_amount=0 && prdt_code is not null,'',concat(@runningTokoVal:=@runningTokoVal+1,'-',@runningTokoVal:=@runningTokoVal -if(dt_Qty>0,1,0) + ceil(dt_qty/ifnull(prdt_measurement2,1) )) ) as toToko,
3324 round(mod(dt_qty ,prdt_measurement2),6) as loose,
3325 ceil(dt_qty/prdt_measurement2) as qty_pkt,
3326 prdt_measurement2 as prdt_msm, prdt_code as pcode,
3327 @current:=keyfield,
3328 @previousTranseqno:=dt_transeqno
3329 FROM $tbl_name3;";
3330
3331 $sql2 = "create temporary table $tmpB
3332 SELECT * FROM $tmpA; ";
3333
3334 $sql3 = "create temporary table $tmpC
3335 SELECT * FROM $tmpA ;";
3336
3337 $nllDb->executeQuery($sql1);
3338 $nllDb->executeQuery($sql2);
3339 $nllDb->executeQuery($sql3);
3340
3341
3342 $sSQL="SELECT *,'Customer Copy' as footer_detail,concat(hd_refno,'-1') as dummy_refno FROM $tmpA
3343 union all
3344 SELECT *, 'A/C Copy' as footer_detail,concat(hd_refno,'-2') as dummy_refno FROM $tmpB ";
3345 if ($bil_print_3copy==3)
3346 $sSQL.=" union all
3347 SELECT *,'Master Copy' as footer_detail,concat(hd_refno,'-3') as dummy_refno FROM $tmpC ";
3348 $sSQL.=" order by dummy_refno ;";
3349 }
3350 }
3351
3352 }
3353
3354
3355
3356 }
3357}
3358
3359if(strpos($s_template,"_with_serial")!==false || strpos($orig_template,"_with_serial")!==false){
3360 // formulate number of serial per row - bk (20110624) #11328 Start
3361 $tbl_serial=uniqid("tmp_serial_");
3362 $nllDb->executeQuery("DROP TEMPORARY TABLE IF EXISTS $tbl_serial;");
3363 $sql_serial="CREATE TEMPORARY TABLE $tbl_serial
3364 $sSQL
3365 ";
3366 $nllDb->executeQuery($sql_serial);
3367
3368 if($s_template=='ikon_inv_rpt_ar_bil_inv_with_serial_deposit.tpl'){
3369 $serial_font="font-size:8.5px;";
3370 }
3371 else{
3372 // convert the shorttext
3373 global $multilanguage;
3374 $serial_font = "{stxtStyleFontSerialNo}";
3375 if(!$multilanguage){
3376 require_once(RelativePath."/class/multi_language.php");
3377 $multilanguage=new MultiLanguage();
3378 }
3379 $serial_font = $multilanguage->convertField($serial_font);
3380 if($serial_font == "{stxtStyleFontSerialNo}")
3381 $serial_font="font-size:9px;"; // if shorttext not set, set 9px as default
3382 }
3383
3384 //20150525 cheefai #24624
3385 if($vat_nature_type==3){
3386 $hd_vat_type = ",hd_vat_type,";
3387 $header_vat_code = ",header_vat_code";
3388 }
3389 else{
3390 $hd_vat_type = ",";
3391 $header_vat_code = "";
3392 }
3393
3394 $result_serial=$nllDb->executeQuery("SELECT hd_dono,hd_yourno,term_code,hd_date,hd_remark,hd_o_tel,hd_name1,hd_attention,dbtr_code,hd_add1,hd_add2,hd_add3,hd_add4,hd_type2,dt_serial_number as serial_internal_no,hd_refno,dt_transno,dt_transeqno,dt_userdefine1,dt_userdefine2, currency, add_username, hd_reference, hd_vat_amount $hd_vat_type hd_vat_percent,currency,linknotes,
3395 hd_gross,hd_round,hd_percent,hd_discount,hd_percent_tax,hd_tax,hd_vat_amount_ori $header_vat_code,
3396 st_name2, st_add1, st_add2, st_add3, st_add4, st_tel, st_fax, st_email, st_contact,st_user1, st_addressfull, st_telfax, st_gst_no, $serial_gst hd_o_fax, slmn_name1,
3397 taxexempt_cert_no, taxexempt_reference, taxexempt_duration_from, taxexempt_duration_to, taxexempt_limit, taxexempt_info1, taxexempt_info2, tariff_code,dbtr_userdefine1,dbtr_userdefine2,dbtr_userdefine3
3398 FROM $tbl_serial WHERE dt_serial_number!='' AND dt_serial_number IS NOT NULL");
3399 while($row_serial=$nllDb->fetchArray($result_serial)){
3400 // get and loop all transaction that with serial number to formulate
3401 //20140618 #19681 yip - addslashes to avoid sql error
3402 $serial_dono=addslashes($row_serial['hd_dono']);
3403 $serial_yourno=addslashes($row_serial['hd_yourno']);
3404 $serial_term=$row_serial['term_code'];
3405 $serial_date=$row_serial['hd_date'];
3406 $serial_remark=addslashes($row_serial['hd_remark']);
3407 $serial_tel=$row_serial['hd_o_tel'];
3408 $serial_name=addslashes($row_serial['hd_name1']);
3409 $serial_attention=addslashes($row_serial['hd_attention']);
3410 $serial_dbtr=addslashes($row_serial['dbtr_code']);
3411 $serial_add1=addslashes($row_serial['hd_add1']);
3412 $serial_add2=addslashes($row_serial['hd_add2']);
3413 $serial_add3=addslashes($row_serial['hd_add3']);
3414 $serial_add4=addslashes($row_serial['hd_add4']);
3415 $serial_type2=$row_serial['hd_type2'];
3416 $serial_internal_no=$row_serial['serial_internal_no'];
3417 $serial_refno=addslashes($row_serial['hd_refno']);
3418 $serial_transno=$row_serial['dt_transno'];
3419 $serial_transeqno=$row_serial['dt_transeqno'];
3420 $serial_userdefine1=addslashes($row_serial['dt_userdefine1']);
3421 $serial_userdefine2=addslashes($row_serial['dt_userdefine2']);
3422 //20130516 kahing 16397 - template missed out these 2 whenever the product got serial no
3423 $serial_currency=$row_serial['currency'];
3424 $serial_add_username=$row_serial['add_username'];
3425 $serial_hd_reference=addslashes($row_serial['hd_reference']); //#16779-need hd_reference field
3426 $serial_vat_amount=addslashes($row_serial['hd_vat_amount']);
3427 $serial_vat_type=addslashes($row_serial['hd_vat_type']);
3428 $serial_vat_percent=addslashes($row_serial['hd_vat_percent']);
3429 $serial_currency=addslashes($row_serial['currency']);
3430 $serial_linknotes=addslashes($row_serial['linknotes']);
3431 $serial_gross=addslashes($row_serial['hd_gross']);
3432 $serial_round=addslashes($row_serial['hd_round']);
3433 $serial_percent=addslashes($row_serial['hd_percent']);
3434 $serial_discount=addslashes($row_serial['hd_discount']);
3435 $serial_percent_tax=addslashes($row_serial['hd_percent_tax']);
3436 $serial_tax=addslashes($row_serial['hd_tax']);
3437 $serial_header_vat_code=addslashes($row_serial['header_vat_code']);
3438 $serial_vat_amount_ori=addslashes($row_serial['hd_vat_amount_ori']);
3439 //20160601 May #28564
3440 $serial_st_name2=addslashes($row_serial['st_name2']);
3441 $serial_st_add1=addslashes($row_serial['st_add1']);
3442 $serial_st_add2=addslashes($row_serial['st_add2']);
3443 $serial_st_add3=addslashes($row_serial['st_add3']);
3444 $serial_st_add4=addslashes($row_serial['st_add4']);
3445 $serial_st_tel=addslashes($row_serial['st_tel']);
3446 $serial_st_fax=addslashes($row_serial['st_fax']);
3447 $serial_st_email=addslashes($row_serial['st_email']);
3448 $serial_st_contact=addslashes($row_serial['st_contact']);
3449 $serial_st_user1=addslashes($row_serial['st_user1']);
3450 $serial_st_addressfull=addslashes($row_serial['st_addressfull']);
3451 $serial_st_telfax=addslashes($row_serial['st_telfax']);
3452 $serial_st_gst_no=addslashes($row_serial['st_gst_no']);
3453 $serial_gst_regno=addslashes($row_serial['gst_regno']);
3454 $serial_hd_o_fax=addslashes($row_serial['hd_o_fax']);
3455 $serial_slmn_name1=addslashes($row_serial['slmn_name1']);
3456 //end #28564
3457 //20181018 May #35447
3458 $serial_taxexempt_cert_no=addslashes($row_serial['taxexempt_cert_no']);
3459 $serial_taxexempt_reference=addslashes($row_serial['taxexempt_reference']);
3460 $serial_taxexempt_duration_from=addslashes($row_serial['taxexempt_duration_from']);
3461 $serial_taxexempt_duration_to=addslashes($row_serial['taxexempt_duration_to']);
3462 $serial_taxexempt_limit=addslashes($row_serial['taxexempt_limit']);
3463 $serial_taxexempt_info1=addslashes($row_serial['taxexempt_info1']);
3464 $serial_taxexempt_info2=addslashes($row_serial['taxexempt_info2']);
3465 $serial_tariff_code=addslashes($row_serial['tariff_code']);
3466 //end #35447
3467
3468 $dbtr_userdefine1=addslashes($row_serial['dbtr_userdefine1']);
3469 $dbtr_userdefine2=addslashes($row_serial['dbtr_userdefine2']);
3470 $dbtr_userdefine3=addslashes($row_serial['dbtr_userdefine3']);
3471
3472 if($vat_nature_type==3){
3473 $sql_update_vat="hd_vat_type='$serial_vat_type',header_vat_code='$serial_header_vat_code',";
3474 }
3475
3476 if($serial_internal_no!=""){
3477 $set_sql = "SET SESSION group_concat_max_len = 1000000;";
3478 $nlldb->executeQuery($set_sql);
3479
3480 $sql_serial_internal="SELECT GROUP_CONCAT(psi_serial) AS serial_no
3481 FROM product_serial_in
3482 WHERE psi_no='$serial_internal_no'
3483 UNION ALL
3484 SELECT GROUP_CONCAT(pso_serial) AS serial_no
3485 FROM product_serial_out
3486 WHERE pso_no='$serial_internal_no' ORDER BY serial_no DESC
3487 ";
3488
3489 //customize php-32084-serial number show like entry
3490 xs_include_event("custom_inv_rpt_ar_bil_serial_number");
3491
3492 $result_serial_internal=$nllDb->executeQuery($sql_serial_internal);
3493 list($serial_no_batch)=$nllDb->fetchRow($result_serial_internal);
3494
3495 $sql_serial_row="SELECT bilctrl_print_serial_per_row FROM bill_control WHERE bilctrl_doc='AR-BIL' AND bilctrl_name='$serial_type2' LIMIT 1";
3496 $result_serial_row=$nllDb->executeQuery($sql_serial_row);
3497 list($serial_per_row)=$nllDb->fetchRow($result_serial_row);
3498
3499 if($serial_per_row!=''){
3500 // when got set number of serial per row
3501 $serial_no="";
3502 $array_serial=array();
3503 $array_serial_batch=explode(",",$serial_no_batch);
3504 $count_serial=count($array_serial_batch);
3505 for($i_serial=1;$i_serial<=$count_serial;$i_serial++){
3506 $array_serial[]=$array_serial_batch[$i_serial-1];
3507 if($i_serial%$serial_per_row==0 || $i_serial==$count_serial){
3508 $serial_no=implode(",",$array_serial);
3509 $serial_no='<font style="'.$serial_font.'">'.$serial_no.'</font>';
3510 // serial font size
3511 $sql_insert_serial="INSERT INTO $tbl_serial SET hd_dono = '$serial_dono', hd_yourno = '$serial_yourno', term_code='$serial_term', hd_date='$serial_date', hd_remark='$serial_remark', hd_o_tel='$serial_tel' ,hd_name1 = '$serial_name',hd_attention = '$serial_attention',dbtr_code ='$serial_dbtr',hd_add1 = '$serial_add1',hd_add2 = '$serial_add2', hd_add3='$serial_add3',hd_add4='$serial_add4', hd_refno='$serial_refno', dt_desc='$serial_no', dt_transno='$serial_transno', dt_transeqno='$serial_transeqno', dt_userdefine1='$serial_userdefine1', dt_userdefine2='$serial_userdefine2', currency='$serial_currency', add_username='$serial_add_username', hd_type2='$serial_type2', hd_reference='$serial_hd_reference', hd_vat_amount='$serial_vat_amount', $sql_update_vat hd_vat_percent='$serial_vat_percent',linknotes='$serial_linknotes',hd_gross='$serial_gross',hd_round='$serial_round',hd_percent='$serial_percent',hd_discount='$serial_discount',hd_percent_tax='$serial_percent_tax',hd_tax='$serial_tax',
3512 hd_vat_amount_ori='$serial_vat_amount_ori', st_name2='$serial_st_name2', st_add1='$serial_st_add1',st_add2='$serial_st_add2', st_add3='$serial_st_add3', st_add4='$serial_st_add4', st_tel='$serial_st_tel', st_fax='$serial_st_fax', st_email='$serial_st_email', st_contact='$serial_st_contact', st_user1='$serial_st_user1', st_addressfull='$serial_st_addressfull', st_telfax='$serial_st_telfax', st_gst_no='$serial_st_gst_no', $serial_gst_update hd_o_fax='$serial_hd_o_fax', slmn_name1='$serial_slmn_name1',
3513 taxexempt_cert_no='$serial_taxexempt_cert_no', taxexempt_reference='$serial_taxexempt_reference', taxexempt_duration_from='$serial_taxexempt_duration_from', taxexempt_duration_to='$serial_taxexempt_duration_to', taxexempt_limit='$serial_taxexempt_limit', taxexempt_info1='$serial_taxexempt_info1', taxexempt_info2='$serial_taxexempt_info2', tariff_code='$serial_tariff_code', dbtr_userdefine1='$dbtr_userdefine1', dbtr_userdefine2='$dbtr_userdefine2', dbtr_userdefine3='$dbtr_userdefine3'"; //20181018 May #35447
3514 $nllDb->executeQuery($sql_insert_serial);
3515 $array_serial=array();
3516 }
3517 }
3518 }
3519 else{
3520 $sql_insert_serial="INSERT INTO $tbl_serial SET hd_dono = '$serial_dono', hd_yourno = '$serial_yourno', term_code='$serial_term', hd_date='$serial_date', hd_remark='$serial_remark', hd_o_tel='$serial_tel' ,hd_name1 = '$serial_name',hd_attention = '$serial_attention',dbtr_code ='$serial_dbtr',hd_add1 = '$serial_add1',hd_add2 = '$serial_add2', hd_add3='$serial_add3',hd_add4='$serial_add4', hd_refno='$serial_refno', dt_desc='$serial_no_batch', dt_transno='$serial_transno', dt_transeqno='$serial_transeqno', dt_userdefine1='$serial_userdefine1', dt_userdefine2='$serial_userdefine2', hd_reference='$serial_hd_reference', hd_vat_amount='$serial_vat_amount', $sql_update_vat hd_vat_percent='$serial_vat_percent', currency='$serial_currency',linknotes='$serial_linknotes',hd_gross='$serial_gross',hd_round='$serial_round',hd_percent='$serial_percent',hd_discount='$serial_discount',hd_percent_tax='$serial_percent_tax',hd_tax='$serial_tax',hd_vat_amount_ori='$serial_vat_amount_ori',st_name2='$serial_st_name2', st_add1='$serial_st_add1',st_add2='$serial_st_add2', st_add3='$serial_st_add3', st_add4='$serial_st_add4', st_tel='$serial_st_tel', st_fax='$serial_st_fax', st_email='$serial_st_email', st_contact='$serial_st_contact', st_user1='$serial_st_user1',st_addressfull='$serial_st_addressfull',st_telfax='$serial_st_telfax',st_gst_no='$serial_st_gst_no', $serial_gst_update hd_o_fax='$serial_hd_o_fax', slmn_name1='$serial_slmn_name1',
3521 taxexempt_cert_no='$serial_taxexempt_cert_no', taxexempt_reference='$serial_taxexempt_reference', taxexempt_duration_from='$serial_taxexempt_duration_from', taxexempt_duration_to='$serial_taxexempt_duration_to', taxexempt_limit='$serial_taxexempt_limit', taxexempt_info1='$serial_taxexempt_info1', taxexempt_info2='$serial_taxexempt_info2', tariff_code='$serial_tariff_code', dbtr_userdefine1='$dbtr_userdefine1', dbtr_userdefine2='$dbtr_userdefine2', dbtr_userdefine3='$dbtr_userdefine3'"; //20181018 May #35447
3522 $nllDb->executeQuery($sql_insert_serial);
3523 }
3524 }
3525 }
3526
3527 //20171206 #33164 - with serial format cannot show workflow approval name
3528 $sql_update_serial="UPDATE $tbl_serial
3529 LEFT JOIN $tbl_name10 ON wf_linked_documents LIKE '%hd_transno=$transo&hd_type1=$type1&hd_type2=$type2%'
3530 LEFT JOIN usermst wf_user ON $tbl_name10.wf_logic_login = wf_user.user_no
3531 SET Approve_user=wf_user.user_login_name ";
3532 $nllDb->executeQuery($sql_update_serial);
3533
3534 $sSQL="SELECT * FROM $tbl_serial ORDER BY hd_refno, dt_transeqno, dt_userdefine1, dt_userdefine2 ";
3535
3536 // formulate number of serial per row - bk (20110624) #11328 End
3537
3538}
3539
3540
3541
3542 if($deposit_auth == "{nllauthCOLLIST_Deposit}" && (strstr(strtolower($template), 'deposit'))){
3543 //#12610-fixing on wrong deposit amount showing - bk (20090401)
3544 //20131111 yip #16779 - fix sql error when doing this task
3545 $sSQL1= "SELECT $tbl_name_deposit.*,sum(apar_amount*-1) AS deposit_amount FROM $tbl_name_deposit
3546 LEFT JOIN debtor_detail ON CONCAT_WS('-','AR',hd_type2,hd_transno)=apar_deposit_link
3547 GROUP BY hd_refno
3548 ";
3549 $nllDb->executeQuery($sSQL1);
3550 }
3551 global $comp_gst_no;
3552 global $comp_sst_no;
3553 global $gst_text_disply;
3554 global $sst_text_disply;
3555 $comp_id = $_SESSION['NLL_COMPANY_ID'];
3556 $comp_taxid_sql = "select comp_gst_no, comp_sst_no from companymst where comp_id = '$comp_id'";
3557 $comp_taxid_res = $nlldb->executeQuery($comp_taxid_sql);
3558 list($comp_gst_no, $comp_sst_no) = $nlldb->fetchArray($comp_taxid_res);
3559
3560 $gst_text = "{stxtrptGSTRegNo} : $comp_gst_no";
3561 $sst_text = "{stxtSSTNumber} : $comp_sst_no";
3562 global $multilanguage;
3563
3564 if(!$multilanguage){
3565 require_once(RelativePath."/class/multi_language.php");
3566 $multilanguage=new MultiLanguage();
3567 }
3568 $gst_text_disply = $multilanguage->convertField($gst_text);
3569 $sst_text_disply = $multilanguage->convertField($sst_text);
3570
3571global $rpt;
3572$rpt = nllReportFactory::getWrapperClass("detail");
3573$template = $s_template;
3574$rpt->loadTemplate(RelativePath."/report/templates/" . $template);
3575$rpt->assign('com_taxID', $com_taxID);
3576$rpt->assign('currency', $curr);
3577$rpt->assign('currencyName', $crcy_name1); // 20170908 beeha #32524 Webixs - create INV tpl for link hub asia
3578$rpt->assign('c_regno',$com_regno);
3579$rpt->assign('c_add1',$f_row);
3580$rpt->assign('c_add2',$s_row);
3581$rpt->assign('branch',$st_mapped);
3582$rpt->assign('reprint',$reprint);
3583if($_SESSION["act905"])
3584 $rpt->assign('user', '');
3585else
3586 $rpt->assign('user', 'DISPLAY:none');
3587
3588$list_by = $sorting == "code" ? " code " : " name ";
3589//20170921 May #31882
3590if($rpt_title!='')
3591 $reportTitle = $rpt_title;
3592else
3593 $reportTitle = $report_title;
3594$rpt->assign('bill_type', 'AR');
3595$rpt->assign('report_title',$reportTitle);
3596$rpt->assign('report_type',$report_type);
3597$rpt->assign('name',$name);
3598$rpt->assign('company_address',$_SESSION["NLL_COMPANY_ADDRESS"]);
3599$rpt->assign('company_email',$_SESSION["NLL_COMPANY_EMAIL"]);
3600$rpt->assign('company_tel',$_SESSION["NLL_COMPANY_TEL"]);
3601$rpt->assign('company_telfax',$_SESSION["NLL_COMPANY_TELFAX"]);
3602$rpt->assign('company_telfaxSpace',str_replace(" "," ",$_SESSION["NLL_COMPANY_TELFAX"]));
3603
3604//20150928 Hamizan 25627 - to hide cancelled items from bill
3605if ($hide_cancelled_bill_items == 1) {
3606 $rpt->hide_cancelled_bill_items = 1;
3607}
3608
3609// 20150514 vernhui #24293 - Malaysia GST - Margin scheme Part 2
3610if($bilctrl_margin_scheme) {
3611 // get the margin scheme number from companymst
3612 $sql_comp_detail = "SELECT comp_margin_scheme_no FROM companymst WHERE comp_id = '".$_SESSION['NLL_COMPANY_ID']."' ; ";
3613 $res_comp_detail = $nlldb->executeQuery($sql_comp_detail);
3614 list($comp_margin_scheme_no) = $nlldb->fetchRow($res_comp_detail);
3615
3616 // convert the shorttext
3617 global $multilanguage;
3618 $margin_scheme_text = "{stxtrptMarginSchemeNo} : $comp_margin_scheme_no";
3619
3620 if(!$multilanguage){
3621 require_once(RelativePath."/class/multi_language.php");
3622 $multilanguage=new MultiLanguage();
3623 }
3624 $margin_scheme_text = $multilanguage->convertField($margin_scheme_text);
3625 $rpt->assign('company_margin_scheme_no', "$margin_scheme_text");
3626}
3627$rpt->setContinueTrue($continue_text);
3628
3629//20140305 megat 18598
3630global $from_date2;
3631global $to_date2;
3632$rpt->assign('from_date',$from_date2);
3633$rpt->assign('to_date',$to_date2);
3634
3635//20140506 megat 18597 Malaysia GST - Revise Bill Printing to Mixed GST
3636global $com_address;
3637$comp_add= explode(",", $com_address);
3638$comp_address1 = "$comp_add[0] , $comp_add[1] , $comp_add[2] ";
3639$comp_address2 = "$comp_add[3] , $comp_add[4] ";
3640$rpt->assign('company_address1', $comp_address1);
3641$rpt->assign('company_address2', $comp_address2);
3642//Get the deposit amount(tpl)
3643$rpt->assign('deposit_amount',$deposit_amount);
3644
3645//20141204 lengwee - assign num_Print #21169
3646$rpt->assign('num_Print', $num_Print);
3647
3648//20150511 May - assign globalsetting(bill with company currency) #24171
3649$inv_bil_comp_curr = getHiddenGlobalSettingValue(100,518,999999999);
3650$rpt->assign('inv_bil_comp_curr', $inv_bil_comp_curr);
3651
3652if($_SESSION['PRINT_WT'] == 0){
3653 if($wt_sql !=''){
3654 $result = $nllDb->query($wt_sql);
3655 list($wt) = $nllDb->fetchRow($result);
3656 $rpt->assign('WT',$wt);
3657 if($wt != '' && $wt != 0.00)
3658 $rpt->assign('icon',"✔");
3659 }
3660
3661 if($vat_sql != ''){
3662 $result = $nllDb->query($vat_sql);
3663 list($vat) = $nllDb->fetchRow($result);
3664 $rpt->assign('VAT',$vat);
3665
3666 }
3667}
3668
3669$rpt->assign('vat_prescribed',$vat_prescribed);
3670
3671function AuditList($dbAccess,$audit_transno,$audit_type1,$audit_type2)
3672{
3673 require_once(RelativePath."/class/cls_audit_list.php");
3674
3675 $audit=new audit_listing($dbAccess, $audit_transno, $audit_type1,$audit_type2);
3676 $audit->SetRemark("Activation");
3677
3678 $audit->setMode("Report Generation/Printing");
3679 $audit->setFrom("inv");
3680 $audit->InsertHeader("");
3681 $audit->Insertbody("");
3682
3683}
3684
3685 $lsql = "SELECT comp_logo FROM companymst;";
3686 $lres = $nllDb->executeQuery($lsql);
3687 $lrow = $nllDb->fetchArray($lres);
3688 $src = "../".$lrow[0];
3689
3690 $rpt->assign('logosrc',$src);
3691
3692
3693//for LH-CT to show > 1 import from refno #8776 - Yinru 20100609
3694function nllEvents_PageBeforePrintHeader(){
3695 global $rpt;
3696 global $template;
3697 global $sSQL;
3698 global $nllDb;
3699 global $t_page_header;
3700 global $headerpreviousContent;
3701 global $vat_nature_type;
3702 global $t_page_footer;
3703 global $is_plain_invoice;
3704 global $curr;
3705 global $print_type;
3706 global $bilctrl_margin_scheme;
3707 global $rpt_title;
3708 global $s_template;
3709 global $comp_gst_no;
3710 global $comp_sst_no;
3711 global $gst_text_disply;
3712 global $sst_text_disply;
3713 global $doc_type;
3714
3715 $rpt->setAlwaysCompile(true);
3716 $headerpreviousContent = $t_page_header;
3717
3718 if(strtolower($template)=='inv_rpt_ar_bil_bill_inv_ct.tpl' || strtolower($template) =='inv_rpt_ar_bil_bill_do_ct.tpl'){
3719
3720 $sql = str_replace(';','',$sSQL);
3721 $import_sql = "select distinct(dt_import_refno) from ($sql) as a WHERE hd_refno = '".$rpt->data['hd_refno']."' and dt_import_refno <> '';";
3722
3723 $import_result = $nllDb->executeQuery($import_sql);
3724 while($import_row = $nllDb->fetchArray($import_result)){
3725 $import_array[] =$import_row[0];
3726 }
3727 $import_refno = implode(', ', $import_array);
3728 $rpt->assign('import_refno',$import_refno);
3729 }
3730
3731 $hd_vat_amount =(isset($rpt->data['hd_vat_amount_ori']) ? $rpt->data['hd_vat_amount_ori'] : $rpt->oldData['hd_vat_amount_ori']);
3732 //20150409 yip - $gstrow show or not should depend on vat_code, not vat amount, because for inclusive, vat amount is set 0 in the sql
3733 $header_vat_code =(isset($rpt->data['header_vat_code']) ? $rpt->data['header_vat_code'] : $rpt->oldData['header_vat_code']);
3734
3735 $zr_flag =(isset($rpt->data['zr_flag']) ? $rpt->data['zr_flag'] : $rpt->oldData['zr_flag']);
3736
3737 //yinru @ 20150411 #23635
3738 $isHeaderGST = strpos($t_page_header, '$GSTRow');
3739 $gst_display_header =getHiddenGlobalSettingValue('1500','44','90000200');
3740 $zr_rate_display =getHiddenGlobalSettingValue('1500','61','90000200');
3741
3742 if($isHeaderGST &&((($gst_display_header=="0" && $hd_vat_amount==0.00) || $header_vat_code==''))){
3743 $t_page_header = str_replace('{$GSTRow}','DISPLAY:none;',$t_page_header);
3744 //$rpt->assign('GSTRow','DISPLAY:none;');
3745 }
3746 else
3747 $t_page_header = str_replace('{$GSTRow}','',$t_page_header);
3748
3749 $GSTCalcTable='';
3750 //yinru @ 20150307 change to use function and modify inclusive
3751 /* move to nllEvents_PageBeforePrintFooter
3752 list($GSTCalcTable,$available_line) =explode("|||||", gst_summary_footer('BILL',$nllDb,$t_page_footer,$rpt,$vat_nature_type,$curr));
3753
3754 if($GSTCalcTable!=''){
3755 $rpt->tpl->mod_avail_page_line=$available_line;
3756 $rpt->assign("GSTCalcTable",$GSTCalcTable);
3757 }
3758 else
3759 $rpt->assign("GSTCalcTable",'');
3760*/
3761
3762 //20141003 Hamizan 20441 - When VAT nature is set to 'MIXED', if header tax code is empty or
3763 // header tax code is of 'Exemption' type, set title to 'I N V O I C E';
3764 if ($vat_nature_type == '3' // IF VAT nature 'MIXED'.
3765 && ((($rpt->data['bilctrl_userdefine1'] == 'I') // AND only on invoice.
3766 && ($is_plain_invoice)) || $rpt->data['bilctrl_userdefine1'] == 'K' ) //35285 yinru 20180901
3767 )
3768 {
3769 //yinru @ 20141226 - fix error
3770 // AND bill has no tax code, OR tax code is of 'Exemption' type
3771 if(($print_type=='INV' || $rpt->data['bilctrl_userdefine1'] == 'K') && $doc_type!='POR'){
3772 //20170921 May #31882
3773 if($rpt_title)
3774 $rpt->tpl->_tpl_vars['report_title'] = $rpt_title;
3775 else if(($rpt->data['header_vat_code'] == '') || ($rpt->data['hd_vat_type'] == 'Exemption')||($zr_flag=='1' && $zr_rate_display==1)){
3776 if($print_type=='INV')
3777 $rpt->tpl->_tpl_vars['report_title'] = 'I N V O I C E';
3778
3779 //35285 yinru 20180901
3780 if($rpt->data['bilctrl_userdefine1'] == 'K')
3781 $rpt->tpl->_tpl_vars['report_title'] = 'CASH BILL';
3782 }else{
3783 $rpt->tpl->_tpl_vars['report_title'] = 'TAX INVOICE';
3784 }
3785 //xueyun- for inv to print QR code
3786 xs_include_event("inv_rpt_ar_bil_bill_dt1_QRCODE");
3787 //END xueyun
3788 }
3789 }
3790 //20150514 vernhui #24293 - Malaysia GST - Margin Scheme part2
3791 // if document bill allow for margin scheme, append the footer message
3792 if($bilctrl_margin_scheme){
3793 $inv_margin_scheme_msg = getHiddenGlobalSettingValue(1500, 45, 90000200);
3794 if($inv_margin_scheme_msg != '') {
3795 $rpt->tpl->mod_avail_page_line -= 1;
3796 }
3797 }
3798
3799 xs_include_event("inv_rpt_ar_bil_bill_dt1_QRCODE");
3800
3801 if($s_template == 'tokopak_do.tpl')
3802 {
3803 xs_include_event("inv_rpt_ar_bil_bill_dt1_QRCODE");
3804 }
3805
3806 if($rpt->data['header_vat_code'] == ''){
3807 if($comp_sst_no!=''){
3808 $rpt->tpl->_tpl_vars['company_gst'] = $sst_text_disply;
3809 }else{
3810 $rpt->tpl->_tpl_vars['company_gst'] = "";
3811 }
3812 }else{
3813 if($comp_gst_no!=''){
3814 $rpt->tpl->_tpl_vars['company_gst'] = $gst_text_disply;
3815 }else{
3816 $rpt->tpl->_tpl_vars['company_gst'] = "";
3817 }
3818 }
3819}
3820
3821function nllEvents_PageAfterPrintHeader(){
3822 global $rpt;
3823 global $t_page_header;
3824 global $headerpreviousContent;
3825 global $template;
3826 $t_page_header = $headerpreviousContent;
3827
3828 $rpt->setAlwaysCompile(true);
3829}
3830
3831//for Lii Hen templates, standard template do not have the group #7694
3832function nllEvents_GroupBeforePrintHeader()
3833{
3834 global $rpt;
3835 global $s_template;
3836 global $t_group_header;
3837 global $previousPageContent;
3838 global $nllDb;
3839 global $where_hide_cancelled; //20150928 Hamizan 25627
3840
3841 $str_key=$rpt->data['linknotes'];
3842 $str = explode("-",$str_key);
3843 $transno = $str[0];
3844 $type1 = $str[1];
3845 $type2 = $str[2];
3846
3847 if($rpt->oldData['hd_refno']!=$rpt->data['hd_refno']){
3848 $dt_sql = "select count(1) from bill_detail where dt_transno='$transno' and dt_type1='$type1' and dt_type2='$type2' $where_hide_cancelled;";
3849 $dt_res = $nllDb->executeQuery($dt_sql);
3850 list($dt_row) = $nllDb->fetchRow($dt_res);
3851 $rpt->tpl->recordNumber = $dt_row;
3852 }
3853
3854
3855 if($s_template == 'inv_rpt_ar_bil_pack_list_LH.tpl') //#8114
3856 {
3857 $groupBreaks[] = array("column" => "dt_userdefine2"
3858 , "page_break" => false
3859 , "h_rows" => 1
3860 , "h_index" => 2
3861 , "f_rows" => 0
3862 , "f_index" => 0
3863 );
3864 $rpt->setGroupBreaks($groupBreaks);
3865 $rpt->setPageReset(false);
3866 }
3867
3868 //20100206 Yinru #8389 - FD format customization
3869 /* $do_container = $rpt->data['do_container'];
3870 if($do_container != ' / ' && $do_container !='' && $s_template == 'inv_rpt_ar_bil_bill_inv_preprinted_fd.tpl')
3871 {
3872 $groupBreaks[] = array("column" => "do_container"
3873 , "page_break" => false
3874 , "h_rows" => 2
3875 , "h_index" => 2
3876 , "f_rows" => 0
3877 , "f_index" => 0
3878 );
3879 $rpt->setGroupBreaks($groupBreaks);
3880
3881 }*/
3882}
3883
3884function nllEvents_BeforePrintDetail()
3885{
3886 global $rpt;
3887 global $nllDb;
3888 global $s_template;
3889 global $show_order_info;
3890 global $vat_nature_type;
3891 global $printToExcel;
3892 global $printToExcelEngine;
3893 //One Stop p3.3.3 Warehouse AR DO printout(local DO) (#13507)
3894 global $total_amount;
3895 $img = '';
3896
3897 //Amin 35418 - print bill tpl/excel with image
3898 if($rpt->data['prdt_picture'] <> ''){
3899 if($printToExcel == 1 && $printToExcelEngine == 0){
3900 $img = base64_encode($rpt->data['prdt_picture']);
3901 }else if($printToExcelEngine != 1){
3902 $img = '<img src="data:image/jpeg;base64,'.base64_encode($rpt->data['prdt_picture']) .' " height=100 width=90 />';
3903 }
3904 }
3905
3906 $rpt->assign('img', $img);
3907
3908 $transno= $rpt->data['dt_import_transno'];
3909 $type1=$rpt->data['dt_import_type1'];
3910 $type2=$rpt->data['dt_import_type2'];
3911 $transeqno=$rpt->data['dt_import_transeqno'];
3912 $refno=$rpt->data['dt_import_refno'];
3913
3914 if($s_template=="tokopak1_do.tpl"||$s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"||$s_template=="inv_rpt_ar_bil_tkp_list2.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_sony.tpl")
3915 {
3916 if($transno!="" && $transeqno!="" && $transno!=0)
3917 {
3918 if($type2=="SO")
3919 $sql="SELECT ord_header.hd_yourno,
3920 if(ord_header.hd_ourno='' || ord_header.hd_ourno is null, ord_header.hd_refno, ord_header.hd_ourno) as hd_ourno, $transeqno AS transeqno
3921 FROM ord_header
3922 WHERE hd_transno=$transno and hd_type1='$type1' and hd_type2='$type2'";
3923 else
3924 $sql="SELECT ord_header.hd_yourno,
3925 if(ord_header.hd_ourno='' || ord_header.hd_ourno is null, ord_header.hd_refno, ord_header.hd_ourno) as hd_ourno, bill_detail.dt_import_transeqno FROM bill_detail
3926 inner join ord_header on hd_transno = dt_import_transno and hd_type1=dt_import_type1 and hd_type2=dt_import_type2
3927 WHERE dt_transno=$transno and dt_type1='$type1' and dt_type2='$type2' and dt_transeqno=$transeqno";
3928 //echo $sql;
3929 $result = $nllDb->executeQuery($sql);
3930 $row = $nllDb->fetchArray($result);
3931 $len=strlen($row[2]);
3932 if($len==1)
3933 $transeqno="00".$row[2];
3934 else if($len==2)
3935 $transeqno="0".$row[2];
3936 else
3937 $transeqno=$row[2];
3938
3939 if($row[1]=="")
3940 {
3941 $orderkey=explode("-", $rpt->data['dt_userdefine1']);
3942 $orderno=$orderkey[0];
3943 if($orderkey[2]!="")
3944 $orderkey[1].= "-".$orderkey[2];
3945 //$rpt->assign('orderno', $orderno);
3946 $assign_orderno = $orderno;
3947 if($controlno=="")
3948 //$rpt->assign('controlno', "-".$orderkey[1]);
3949 $assign_controlno = $orderkey[1];
3950 else
3951 //$rpt->assign('orderno', $orderno);
3952 $assign_orderno = $orderno;
3953 }else
3954 {
3955 if($row[0]=="")
3956 $controlno = $rpt->data['dt_userdefine1'];
3957 else
3958 $controlno=$row[0]."-".$transeqno;
3959 $orderno=$row[1];
3960 //$rpt->assign('controlno', $controlno);
3961 //$rpt->assign('orderno', $orderno);
3962 $assign_controlno = $controlno;
3963 $assign_orderno = $orderno;
3964 }
3965 }
3966 else
3967 {
3968 if($orderkey=="")
3969 {
3970 $orderkey=explode("-", $rpt->data['dt_userdefine1']);
3971 $orderno=$orderkey[0];
3972 if($orderkey[2]!="")
3973 $orderkey[1].= "-".$orderkey[2];
3974 //$rpt->assign('orderno', $orderno);
3975 $assign_orderno = $orderno;
3976 if($controlno=="")
3977 //$rpt->assign('controlno', "-".$orderkey[1]);
3978 $assign_controlno = $orderkey[1];
3979 }
3980 }
3981
3982 if($assign_controlno=="" || $assign_controlno=="undefined" || $assign_controlno=="NULL")
3983 $rpt->assign('controlno', "-".$refno);
3984 else
3985 $rpt->assign('controlno', "-".$assign_controlno);
3986
3987 $rpt->assign('orderno', $assign_orderno);
3988
3989
3990 }
3991 //One Stop p3.3.3 Warehouse AR DO printout(local DO) (#13507)
3992 if($s_template == 'inv_rpt_bil_dncn_one_stop.tpl'){
3993 $prod_no=$rpt->data['prdt_no'];
3994 $job_no=$rpt->data['hd_job'];
3995 $dt_userdefine1=$rpt->data['dt_userdefine1'];
3996 $dt_price=$rpt->data['dt_price'];
3997 $dt_qty=$rpt->data['dt_qty'];
3998 if( $dt_userdefine1 !='' && $dt_userdefine1 !=0 && $dt_userdefine1 !=NULL){
3999 $total_amount+=$dt_userdefine1 * $dt_qty;
4000 $rpt->assign('total_SP', $total_SP);
4001 $rpt->assign('selling_price', $dt_userdefine1);
4002 }
4003 else if ($job_no!='' && $prod_no!=''){
4004 // to get selling price from concept product master for onestop - KY (20120523) #13507
4005 $sql_consolidate_db="SELECT dbc_database FROM mapping_database_consolidate WHERE dbc_job='$job_no' LIMIT 1";
4006 $result_consolidate_db=$nllDb->executeQuery($sql_consolidate_db);
4007 list($concept_db)=$nllDb->fetchRow($result_consolidate_db);
4008 if($concept_db!=''){
4009 $sql_concept_price="SELECT prdt_price FROM $concept_db.productmst WHERE prdt_no='$prod_no'";
4010 $result_concept_price=$nllDb->executeQuery($sql_concept_price);
4011 list($concept_price)=$nllDb->fetchRow($result_concept_price);
4012 }
4013 if ($concept_price!=''&& $concept_price !=0 && $concept_price !=NULL){
4014 $total_amount+=$concept_price * $dt_qty;
4015 $rpt->assign('total_SP', $total_SP);
4016 $rpt->assign('selling_price', $concept_price);
4017 }
4018 else{
4019 $total_amount+=$dt_price * $dt_qty;
4020 $rpt->assign('total_SP', $total_SP);
4021 $rpt->assign('selling_price', $dt_price);
4022 }
4023 }
4024 else{
4025 $total_amount+=$dt_price * $dt_qty;
4026 $rpt->assign('total_SP', $total_SP);
4027 $rpt->assign('selling_price', $dt_price);
4028 }
4029 }
4030
4031 if( $s_template=="ja_inv_rpt_ar_bil_inv_preprint.tpl" || $s_template=="eisentech_inv_rpt_bil_dncn.tpl" || $s_template=="ja_inv_rpt_bil_dncn.tpl")
4032 {
4033 $amount=$rpt->data['dt_ini_amount'];
4034 $qty=$rpt->data['qtyA'];
4035 $code= $rpt->data['prdt_code'];
4036
4037 if ($code=='' && $qty==0.00 && $amount==0.00 )
4038 $rpt->assign('hide', 'DISPLAY:none');
4039 else
4040 $rpt->assign('hide', " ");
4041 }
4042
4043
4044 //20140307 megat 18597 Malaysia GST - Revise Bill Printing to Mixed GST
4045 if($vat_nature_type=='3'){
4046 $isTaxInclusive = 0;
4047 $hd_vat_group = $rpt->data['header_vat_code'];
4048 $hd_vat_type = $rpt->data['hd_vat_type'];
4049
4050 if($hd_vat_group==''){
4051 $rpt->assign('GSTHideRowIfNoGSTCode','display:none;');
4052 }
4053 if($hd_vat_type == "Include")
4054 {
4055 $rpt->data['hd_vat_amount'] = 0; //force vat amount to 0 if detect tax inclusive
4056 $isTaxInclusive = 1;
4057 }
4058 }
4059 return true;
4060}
4061
4062//20101228 Yinru #10546 - Add Deposit Details from ledger detail
4063function nllEvents_GroupRightAfterPrintFooter(){
4064 global $rpt;
4065 global $nllDb;
4066 global $tbl_name_deposit;
4067 global $deposit_auth;
4068 global $template;
4069
4070 if($deposit_auth == "{nllauthCOLLIST_Deposit}" && (strstr(strtolower($template), 'deposit'))){
4071 $refno = (isset($rpt->oldData['hd_reference']) ? $rpt->oldData['hd_reference'] : $rpt->data['hd_reference']);
4072
4073 $sql = "SELECT * FROM $tbl_name_deposit WHERE hd_refno='$refno';";
4074 $res = $nllDb->executeQuery($sql);
4075
4076 while($row = $nllDb->fetchArray($res)){
4077 $rpt->tpl->assign('data2',$row);
4078 //20091105 ming ee If choose print to excel, will not run, so that excel can display properly
4079 if($rpt->_printInExcel!=1 && ($rpt->_detailRowNo + 1 > $rpt->tpl->avail_page_line)){
4080 //assign page break variable;
4081 $rpt->tpl->assign( 'page_break',$rpt->tpl->page_break);
4082
4083 //show page footer
4084 $rpt->tpl->show_tpl_output($rpt->_tplPageFooter);
4085
4086 //assign page no variable
4087 $rpt->tpl->assign_by_ref('page_no',++$rpt->pageNo);
4088
4089 //reset detail row no
4090 $rpt->_detailRowNo = 0;
4091 //show page header
4092 $rpt->tpl->show_tpl_output($rpt->_tplPageHeader);
4093
4094
4095 }
4096 $rpt->tpl->show_tpl_output("t_detail_line2");
4097 $rpt->_detailRowNo++;
4098 }
4099 }
4100}
4101//end deposit
4102
4103
4104function nllEvents_GroupBeforePrintFooter(){
4105 //add the code here
4106 global $rpt;
4107 global $t_group_footer1;
4108 global $previousContent;
4109 global $s_template;
4110 global $single_copy; //#7885
4111 global $bil_print_3copy;
4112 global $vat_nature_type;
4113
4114 $rpt->setAlwaysCompile(true);
4115 $previousContent = $t_group_footer1;
4116 if(!strstr($s_template,'saha')){
4117 //if($rpt->oldData['hd_discount'] == 0){
4118 $disc = (isset($rpt->oldData['hd_discount']) ? $rpt->oldData['hd_discount'] : $rpt->data['hd_discount']);
4119
4120 //for discount amount
4121 $disc_amount = (isset($rpt->oldData['dt_price_net']) ? $rpt->oldData['dt_price_net'] : $rpt->data['dt_price_net']);
4122
4123 //for bill tax
4124 $tax = (isset($rpt->oldData['hd_tax']) ? $rpt->oldData['hd_tax'] : $rpt->data['hd_tax']);
4125
4126 // 20100730 Nurul #8778 - add rounding column
4127 $hd_round = (isset($rpt->oldData['hd_round']) ? $rpt->oldData['hd_round'] : $rpt->data['hd_round']);
4128
4129 //gst
4130 $hd_vat_type=(isset($rpt->oldData['hd_vat_type']) ? $rpt->oldData['hd_vat_type'] : $rpt->data['hd_vat_type']);
4131 //check if the template has tax variable, if not use the original coding
4132 $isTax = strpos($t_group_footer1, '$taxRow');
4133 $isDisc = strpos($t_group_footer1, '$discRow');
4134 $isRound = strpos($t_group_footer1, '$hd_round');
4135 //yinru @ 20140721 - fix gst tpl and customize tpl issue #19601
4136 if($s_template == 'inv_rpt_ar_bil_bill_inv_preprinted_fd.tpl'){
4137 $rrow = $rpt->_t_group_footer_rows;
4138 }
4139 else{
4140 if($rpt->_t_group_footer_rows==='' || $rpt->_t_group_footer_rows===NULL)
4141 $rrow = 3;
4142 else
4143 $rrow = $rpt->_t_group_footer_rows;
4144 }
4145
4146 if($rrow > 0){
4147 $hd_vat_amount =(isset($rpt->oldData['hd_vat_amount']) ? $rpt->oldData['hd_vat_amount'] : $rpt->data['hd_vat_amount']);
4148
4149 //34534 yinru 20180531 - gst dynamic show footer
4150 $hd_vat_type =(isset($rpt->oldData['hd_vat_type']) ? $rpt->oldData['hd_vat_type'] : $rpt->data['hd_vat_type']);
4151 $vat_nature =(isset($rpt->oldData['body_vat_nature']) ? $rpt->oldData['body_vat_nature'] : $rpt->data['body_vat_nature']);
4152 $show_gst = getHiddenGlobalSettingValue('1500','73','90000200');
4153
4154 $isGST = strpos($t_group_footer1, '$GSTRow');
4155 if($disc==0.00 && $tax==0.00 && $hd_round==0.00 && (($hd_vat_amount==0.00 && $show_gst=='0') || !$isGST || $hd_vat_type=='Exemption' || $vat_nature=='IM')){
4156 $rpt->hideParts("t_group_footer1","part1");
4157 if($rpt->_t_group_footer_part1_rows==='' || $rpt->_t_group_footer_part1_rows===NULL)
4158 $minus = 3;
4159 else
4160 $minus = $rpt->_t_group_footer_part1_rows;
4161 $rpt->_tr_group_footer_rows=$rrow - $minus; //20150121-ky-22074 should not set to 0 if there still have <tr> under the t_group_footer1 outside <part1> unable to print eventhought tpl $t_group_footer_rows = 1.
4162 }
4163 else{
4164 $rpt->_tr_group_footer_rows=$rrow;
4165 if($disc==0.00){
4166 $rpt->assign('discRow','DISPLAY:none');
4167 if($isDisc){
4168 $rpt->_tr_group_footer_rows-=3;
4169 }
4170 }
4171
4172
4173 if($tax==0.00){
4174 $rpt->assign('taxRow','DISPLAY:none');
4175 }
4176 else {
4177 if($isTax)
4178 $rpt->_tr_group_footer_rows+=3;
4179 }
4180
4181 if($hd_round==0.00){
4182 $rpt->assign('hd_round','DISPLAY:none');
4183 }
4184 else{
4185 if($isRound)
4186 $rpt->_tr_group_footer_rows+=3;
4187 }
4188
4189 if($vat_nature_type=='3' && $hd_vat_type!='Exemption' && $vat_nature!='IM' && $hd_vat_type!=''){
4190 if($hd_vat_amount==0.00 && $show_gst=='0'){
4191 $rpt->assign('GSTRow','DISPLAY:none;');
4192 $rpt->assign('GSTExcludeRow','display:none;');
4193 }
4194 else{
4195 $rpt->assign('GSTRow','');
4196 if($isGST){
4197 $rpt->_tr_group_footer_rows+=2;
4198 if($hd_vat_type=='Exclude'){
4199 $rpt->assign('GSTExcludeRow','');
4200 $rpt->_tr_group_footer_rows+=1;
4201 }
4202 else
4203 $rpt->assign('GSTExcludeRow','display:none;');
4204 }
4205 }
4206 }
4207 else{
4208 $rpt->assign('GSTRow','DISPLAY:none;');
4209 $rpt->assign('GSTExcludeRow','display:none;');
4210 }
4211 }
4212 }
4213 // $rpt->tpl->mod_avail_page_line=$available_line;
4214 //#19601 END
4215 /*
4216 // 20100730 Nurul #8778 - add rounding column
4217 if($isTax){
4218 if($disc == 0.00 && $tax == 0.00){ //first
4219 if($hd_round==0.00){
4220
4221 $rpt->assign('hd_round', 'DISPLAY:none');
4222 $rpt->hideParts("t_group_footer1","part1");
4223 // assign attributes
4224 //if($s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4225 //#7885
4226 if (($single_copy=="0" || $single_copy=="") && $bil_print_3copy>1){
4227 // assign attributes
4228 $groupBreaks[] = array("column" => "dummy_refno"
4229 , "page_break" => true
4230 , "h_rows" => 0
4231 , "h_index" => 0
4232 , "f_rows" => 0
4233 , "f_index" => 1
4234 );
4235
4236 $rpt->setGroupBreaks($groupBreaks);
4237 $rpt->setPageReset(true);
4238 }
4239 else{
4240 $groupBreaks[] = array("column" => "hd_refno"
4241 , "page_break" => true
4242 , "h_rows" => 0
4243 , "h_index" => 0
4244 , "f_rows" => 0
4245 , "f_index" => 1
4246 );
4247 $rpt->setGroupBreaks($groupBreaks);
4248 }
4249 }
4250 elseif($disc == 0.00 && $tax == 0.00){
4251 if($hd_round!=0.00){
4252 $rpt->assign('discRow','DISPLAY:none');
4253 $rpt->assign('taxRow', 'DISPLAY:none');
4254 // assign attributes
4255 $groupBreaks[] = array("column" => "hd_reference"
4256 , "page_break" => true
4257 , "h_rows" => 0
4258 , "h_index" => 0
4259 , "f_rows" => 3
4260 , "f_index" => 1
4261 );
4262 $rpt->setGroupBreaks($groupBreaks);
4263 }
4264
4265 // assign attributes
4266 $groupBreaks[] = array("column" => "hd_reference"
4267 , "page_break" => true
4268 , "h_rows" => 0
4269 , "h_index" => 0
4270 , "f_rows" => 3
4271 , "f_index" => 1
4272 );
4273 $rpt->setGroupBreaks($groupBreaks);
4274 }
4275
4276 else{
4277 $rpt->hideParts("t_group_footer1","part1");
4278 // assign attributes
4279 //if($s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4280 //#7885
4281 if (($single_copy=="0" || $single_copy=="") && $bil_print_3copy>1){
4282 // assign attributes
4283 $groupBreaks[] = array("column" => "dummy_refno"
4284 , "page_break" => true
4285 , "h_rows" => 0
4286 , "h_index" => 0
4287 , "f_rows" => 0
4288 , "f_index" => 1
4289 );
4290
4291 $rpt->setGroupBreaks($groupBreaks);
4292 $rpt->setPageReset(true);
4293 }
4294 else{
4295 $groupBreaks[] = array("column" => "hd_refno"
4296 , "page_break" => true
4297 , "h_rows" => 0
4298 , "h_index" => 0
4299 , "f_rows" => 0
4300 , "f_index" => 1
4301 );
4302 $rpt->setGroupBreaks($groupBreaks);
4303 }
4304 }
4305 }//ending first
4306 elseif($disc != 0.00 && $tax == 0.00){
4307 if($hd_round==0.00){
4308 $rpt->assign('hd_round', 'DISPLAY:none');
4309 $rpt->assign('taxRow', 'DISPLAY:none');
4310 // assign attributes
4311 //if($s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl"||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4312 //#7885
4313 if (($single_copy=="0" || $single_copy=="") && $bil_print_3copy>1){
4314 // assign attributes
4315 $groupBreaks[] = array("column" => "dummy_refno"
4316 , "page_break" => true
4317 , "h_rows" => 0
4318 , "h_index" => 0
4319 , "f_rows" => 3
4320 , "f_index" => 1
4321 );
4322
4323 $rpt->setGroupBreaks($groupBreaks);
4324 $rpt->setPageReset(true);
4325 }
4326 else{
4327 $groupBreaks[] = array("column" => "hd_refno"
4328 , "page_break" => true
4329 , "h_rows" => 0
4330 , "h_index" => 0
4331 , "f_rows" => 3
4332 , "f_index" => 1
4333 );
4334 $rpt->setGroupBreaks($groupBreaks);
4335 }
4336 }
4337 else{
4338
4339 $rpt->assign('taxRow', 'DISPLAY:none');
4340 // assign attributes
4341 //if($s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl"||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4342 //#7885
4343 if (($single_copy=="0" || $single_copy=="") && $bil_print_3copy>1){
4344 // assign attributes
4345 $groupBreaks[] = array("column" => "dummy_refno"
4346 , "page_break" => true
4347 , "h_rows" => 0
4348 , "h_index" => 0
4349 , "f_rows" => 3
4350 , "f_index" => 1
4351 );
4352
4353 $rpt->setGroupBreaks($groupBreaks);
4354 $rpt->setPageReset(true);
4355 }
4356 else{
4357 $groupBreaks[] = array("column" => "hd_refno"
4358 , "page_break" => true
4359 , "h_rows" => 0
4360 , "h_index" => 0
4361 , "f_rows" => 3
4362 , "f_index" => 1
4363 );
4364 $rpt->setGroupBreaks($groupBreaks);
4365 }
4366 }
4367
4368 }
4369 elseif($disc == 0.00 && $tax != 0.00){ //echo $disc;
4370 $rpt->assign('discRow', 'DISPLAY:none');
4371 // assign attributes
4372 //if($s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4373 //#7885
4374 if (($single_copy=="0" || $single_copy=="") && $bil_print_3copy>1){
4375 // assign attributes
4376 $groupBreaks[] = array("column" => "dummy_refno"
4377 , "page_break" => true
4378 , "h_rows" => 0
4379 , "h_index" => 0
4380 , "f_rows" => 3
4381 , "f_index" => 1
4382 );
4383
4384 $rpt->setGroupBreaks($groupBreaks);
4385 $rpt->setPageReset(true);
4386 }
4387 else{
4388 $groupBreaks[] = array("column" => "hd_refno"
4389 , "page_break" => true
4390 , "h_rows" => 0
4391 , "h_index" => 0
4392 , "f_rows" => 3
4393 , "f_index" => 1
4394 );
4395 $rpt->setGroupBreaks($groupBreaks);
4396 }
4397
4398 }
4399 elseif($disc != 0.00 && $tax != 0.00){
4400 if($hd_round==0.00){//if tax!=0 and disc!=0
4401 $rpt->assign('hd_round', 'DISPLAY:none');
4402 // assign attributes
4403 $groupBreaks[] = array("column" => "hd_reference"
4404 , "page_break" => true
4405 , "h_rows" => 0
4406 , "h_index" => 0
4407 , "f_rows" => 3
4408 , "f_index" => 1
4409 );
4410 $rpt->setGroupBreaks($groupBreaks);
4411 }
4412
4413 // assign attributes
4414 $groupBreaks[] = array("column" => "hd_reference"
4415 , "page_break" => true
4416 , "h_rows" => 0
4417 , "h_index" => 0
4418 , "f_rows" => 3
4419 , "f_index" => 1
4420 );
4421 $rpt->setGroupBreaks($groupBreaks);
4422 }
4423 }
4424 else{
4425
4426 //original coding
4427 if($disc == 0.00 && $tax == 0.00){//first Ori
4428 if($hd_round==0.00){//hd_round ori1
4429 $rpt->assign('hd_round', 'DISPLAY:none');
4430 $rpt->hideParts("t_group_footer1","part1");
4431
4432 // assign attributes
4433 //if($s_template=="inv_rpt_ar_bil_cb_tokopak4.tpl"||$s_template=="tokopak1_do.tpl"||$s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4434 //#7885
4435 if (($single_copy=="0" || $single_copy=="") && $bil_print_3copy>1){
4436 // assign attributes
4437 $groupBreaks[] = array("column" => "dummy_refno"
4438 , "page_break" => true
4439 , "h_rows" => 0
4440 , "h_index" => 0
4441 , "f_rows" => 0
4442 , "f_index" => 1
4443 );
4444
4445 $rpt->setGroupBreaks($groupBreaks);
4446 $rpt->setPageReset(true);
4447 }
4448 else{
4449 $groupBreaks[] = array("column" => "hd_refno"
4450 , "page_break" => true
4451 , "h_rows" => 0
4452 , "h_index" => 0
4453 , "f_rows" => 0
4454 , "f_index" => 1
4455 );
4456 $rpt->setGroupBreaks($groupBreaks);
4457 }
4458 } //endhd_round ori1
4459 $rpt->hideParts("t_group_footer1","part1");
4460 // assign attributes
4461 //if($s_template=="inv_rpt_ar_bil_cb_tokopak4.tpl"||$s_template=="tokopak1_do.tpl"||$s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4462 //#7885
4463 if (($single_copy=="0" || $single_copy=="") && $bil_print_3copy>1){
4464 // assign attributes
4465 $groupBreaks[] = array("column" => "dummy_refno"
4466 , "page_break" => true
4467 , "h_rows" => 0
4468 , "h_index" => 0
4469 , "f_rows" => 0
4470 , "f_index" => 1
4471 );
4472
4473 $rpt->setGroupBreaks($groupBreaks);
4474 $rpt->setPageReset(true);
4475 }
4476 else{
4477 $groupBreaks[] = array("column" => "hd_refno"
4478 , "page_break" => true
4479 , "h_rows" => 0
4480 , "h_index" => 0
4481 , "f_rows" => 0
4482 , "f_index" => 1
4483 );
4484 $rpt->setGroupBreaks($groupBreaks);
4485 }
4486 if($s_template == 'inv_rpt_ar_bil_bill_inv_preprinted_fd.tpl')
4487 {
4488 $groupBreaks[] = array("column" => "do_container"
4489 , "page_break" => false
4490 , "h_rows" => 2
4491 , "h_index" => 2
4492 , "f_rows" => 0
4493 , "f_index" => 0
4494 );
4495 $rpt->setGroupBreaks($groupBreaks);
4496
4497 }
4498 }//End first Ori
4499 else{//second Ori
4500
4501
4502
4503// if($disc == 0.00 && $tax != 0.00 && $hd_round != 0.00)
4504//
4505// $rpt->assign('discRow','DISPLAY:none');
4506// else
4507// $rpt->assign('taxRow', 'DISPLAY:none');
4508// $rpt->assign('hd_round', 'DISPLAY:none');
4509 // fix on hide/show of discount,tax,rounding row - bk (20101101) #10253
4510 if($disc==0.00){
4511 $rpt->assign('discRow','DISPLAY:none');
4512 }
4513 if($tax==0.00){
4514 $rpt->assign('taxRow','DISPLAY:none');
4515 }
4516 if($hd_round==0.00){
4517 $rpt->assign('hd_round','DISPLAY:none');
4518 }
4519
4520 // assign attributes
4521 //if($s_template=="inv_rpt_ar_bil_cb_tokopak4.tpl"||$s_template=="tokopak1_do.tpl"||$s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4522 //#7885
4523 if (($single_copy=="0" || $single_copy=="") && $bil_print_3copy>1){
4524 // assign attributes
4525 $groupBreaks[] = array("column" => "dummy_refno"
4526 , "page_break" => true
4527 , "h_rows" => 0
4528 , "h_index" => 0
4529 , "f_rows" => 3
4530 , "f_index" => 1
4531 );
4532
4533 $rpt->setGroupBreaks($groupBreaks);
4534 $rpt->setPageReset(true);
4535 }
4536 else{
4537 $groupBreaks[] = array("column" => "hd_refno"
4538 , "page_break" => true
4539 , "h_rows" => 0
4540 , "h_index" => 0
4541 , "f_rows" => 3
4542 , "f_index" => 1
4543 );
4544 $rpt->setGroupBreaks($groupBreaks);
4545 }
4546 if($s_template == 'inv_rpt_ar_bil_bill_inv_preprinted_fd.tpl')
4547 {
4548 $groupBreaks[] = array("column" => "do_container"
4549 , "page_break" => false
4550 , "h_rows" => 2
4551 , "h_index" => 2
4552 , "f_rows" => 0
4553 , "f_index" => 0
4554 );
4555 $rpt->setGroupBreaks($groupBreaks);
4556
4557 }
4558
4559 }//end second ori
4560 }*/
4561
4562 //#16779 - if does not have deposit data, don't show the caption
4563 global $tbl_name_deposit;
4564 global $deposit_auth;
4565 global $nllDb;
4566 global $template;
4567
4568 if($deposit_auth == "{nllauthCOLLIST_Deposit}" && (strstr(strtolower($template), 'deposit'))){
4569 $refno = (isset($rpt->oldData['hd_reference']) ? $rpt->oldData['hd_reference'] : $rpt->data['hd_reference']);
4570
4571 $sql = "SELECT COUNT(1) FROM $tbl_name_deposit WHERE hd_refno='$refno';";
4572 $res = $nllDb->executeQuery($sql);
4573 $row = $nllDb->fetchArray($res);
4574
4575 if($row[0]=='' || $row[0]==0)
4576 $rpt->assign("deposit_caption_style","style='display:none'");
4577 else
4578 $rpt->assign("deposit_caption_style","style='height:12.75pt'");
4579 }
4580 //
4581}
4582return true;
4583
4584}
4585
4586function nllEvents_GroupAfterPrintFooter(){
4587 //add the code here
4588 global $rpt;
4589 global $t_group_footer1;
4590 global $previousContent;
4591 global $s_template;
4592 global $single_copy; //#7885
4593 global $bil_print_3copy;
4594 global $vat_nature_type;
4595
4596 $t_group_footer1 = $previousContent ;
4597 //20150427 cheefai #23866 - solve last page appear gst code even is ZRE
4598 $isGST = strpos($t_group_footer1, '$GSTRow');
4599 $hd_vat_type = $rpt->data["hd_vat_type"];
4600 $hd_vat_amount = $rpt->data["hd_vat_amount"];
4601 if(!strstr($s_template,'saha')){
4602 //for bill tax
4603 $rpt->assign('discRow', "");
4604 $rpt->assign('taxRow', "");
4605 $rpt->assign('GSTRow', "");
4606 $rpt->assign('GSTExcludeRow', "");
4607 if($vat_nature_type=='3'){
4608 if($hd_vat_amount==0.00){
4609 $rpt->assign('GSTRow','DISPLAY:none;');
4610 $rpt->assign('GSTExcludeRow','display:none;');
4611 }
4612 else{
4613 if($isGST){
4614 $rpt->_tr_group_footer_rows+=2;
4615 if($hd_vat_type=='Exclude'){
4616 $rpt->assign('GSTExcludeRow','');
4617 $rpt->_tr_group_footer_rows+=1;
4618 }
4619 else
4620 $rpt->assign('GSTExcludeRow','display:none;');
4621 }
4622 }
4623 }
4624 else{
4625 $rpt->assign('GSTRow','DISPLAY:none;');
4626 $rpt->assign('GSTExcludeRow','DISPLAY:none;');
4627 }
4628 // 20100730 Nurul #8778 - add rounding column
4629 $rpt->assign('hd_round', "");
4630 //end
4631
4632 //for bill tax change the f_rows FROM 3 to 6
4633 // assign attributes
4634// if($s_template=="inv_rpt_ar_bil_cb_tokopak4.tpl"||$s_template=="tokopak1_do.tpl"||$s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4635//#7885
4636/* 20140206 yinru #17080, 16176 - remove groupbreaks in the events
4637if (($single_copy=="0" || $single_copy=="") && $bil_print_3copy>1){
4638// assign attributes
4639$groupBreaks[] = array("column" => "dummy_refno"
4640 , "page_break" => true
4641 , "h_rows" => 0
4642 , "h_index" => 0
4643 , "f_rows" => 6
4644 , "f_index" => 1
4645 );
4646
4647$rpt->setGroupBreaks($groupBreaks);
4648}
4649else{
4650 $groupBreaks[] = array("column" => "hd_refno"
4651 , "page_break" => true
4652 , "h_rows" => 0
4653 , "h_index" => 0
4654 , "f_rows" => 10
4655 , "f_index" => 1
4656 );
4657
4658 $rpt->setGroupBreaks($groupBreaks);
4659}
4660
4661if($s_template == 'inv_rpt_ar_bil_bill_inv_preprinted_fd.tpl')
4662 {
4663 $groupBreaks[] = array("column" => "do_container"
4664 , "page_break" => false
4665 , "h_rows" => 2
4666 , "h_index" => 2
4667 , "f_rows" => 0
4668 , "f_index" => 0
4669 );
4670 $rpt->setGroupBreaks($groupBreaks);
4671
4672 }
4673 */
4674 $rpt->setAlwaysCompile(true);
4675}
4676
4677 return true;
4678}
4679
4680function nllEvents_PageBeforePrintFooter(){
4681 //add the code here
4682 global $rpt;
4683 global $t_page_footer;
4684 global $previousPageContent;
4685 global $s_template;
4686 global $deposit_auth;
4687 global $tbl_name_deposit;
4688 //One Stop p3.3.3 Warehouse AR DO printout(local DO) (#13507)
4689 global $total_amount;
4690 global $vat_nature_type;
4691 global $curr;
4692 global $GSTCalcTable;
4693 //Print Payment information Yinru @ 20090506
4694 global $type;
4695 global $nllDb;
4696 global $bilctrl_margin_scheme;
4697 $doc_type=$_GET['doc_type'];
4698
4699 list($GSTCalcTable,$available_line) =explode("|||||", gst_summary_footer('BILL',$nllDb,$t_page_footer,$rpt,$vat_nature_type,$curr));
4700
4701 if($GSTCalcTable!=''){
4702 $rpt->tpl->mod_avail_page_line=$available_line;
4703 $rpt->assign("GSTCalcTable",$GSTCalcTable);
4704 }
4705 else
4706 {
4707 $rpt->assign("GSTCalcTable",'');
4708 }
4709
4710 //20150514 vernhui #24293 - Malaysia GST - Margin Scheme part2
4711 // if document bill allow for margin scheme, append the footer message
4712 if($bilctrl_margin_scheme){
4713 $inv_margin_scheme_msg = getHiddenGlobalSettingValue(1500, 45, 90000200);
4714 if($inv_margin_scheme_msg != '') {
4715 // append the margin scheme footer message in front of gst calculation table
4716 if($rpt->dbTemplate_isODT)
4717 {
4718 $rpt->assign("GSTCalcTable","# $inv_margin_scheme_msg\n".$GSTCalcTable);
4719 }
4720 else
4721 {
4722 $GSTCalcTable = "
4723 <tr height=17 style='height:12pt'>
4724 <td colspan=100 height=12 class=xl2422397 style=\'height:12pt;text-align:left;\'># $inv_margin_scheme_msg</td>
4725 </tr>".$GSTCalcTable;
4726 $rpt->assign("GSTCalcTable",$GSTCalcTable);
4727 }
4728 }
4729 }
4730
4731 //Condition to get the deposit amount and printed to tpl
4732 if($deposit_auth == "{nllauthCOLLIST_Deposit}" && (strstr(strtolower($s_template), 'deposit'))){
4733 $refno = (isset($rpt->oldData['hd_reference']) ? $rpt->oldData['hd_reference'] : $rpt->data['hd_reference']);
4734 $sql = "SELECT sum(deposit_amount) AS Total_deposit from $tbl_name_deposit
4735 GROUP BY hd_refno='$refno';
4736 ";
4737 $res = $nllDb->executeQuery($sql);
4738 $row = $nllDb->fetchArray($res);
4739 $rpt->assign('deposit_amount',$row[0]);
4740 }
4741 //20140418 - stephen #18690 add membership point
4742 xs_include_event("inv_rpt_ar_bil_bill_dt1_PageBeforePrintFooter");
4743
4744 //#9695 - need to get RM values direct from DB - yinru 20100729
4745 if($s_template=='inv_rpt_ar_bil_bill_INV_LiiHen.tpl' || $s_template == "inv_rpt_ar_bil_bill_INV_LiiHen_preprinted.tpl" || $s_template=='inv_rpt_ar_bil_bill_inv_preprinted_ef.tpl' || $s_template=='inv_rpt_ar_bil_bill_INV_LiiHen_preprinted3.tpl' || $s_template=='inv_rpt_ar_bil_bill_INV_LiiHen_preprinted5.tpl' || $s_template=='inv_rpt_ar_bil_bill_INV_LiiHen_preprinted1.tpl' || $s_template=='inv_rpt_ar_bil_bill_INV_LiiHen_preprinted2.tpl' || $s_template=='inv_rpt_ar_bil_bill_INV_LiiHen_preprinted4.tpl' ){
4746 $refno = (isset($rpt->oldData['hd_reference']) ? $rpt->oldData['hd_reference'] : $rpt->data['hd_reference']);
4747 $sql = "select round(hd_amount - hd_vat_amt + hd_vat_round, 2) as good_total, (hd_vat_amt + hd_vat_round) as sales_tax, hd_amount as total from bill_header where hd_doc = 'AR-BIL' AND hd_type2 = '$doc_type' AND hd_refno='$refno';";
4748 $result = $nllDb->executeQuery($sql);
4749 list($good_total, $sales_tax,$total) = $nllDb->fetchRow($result);
4750
4751 $rpt->assign('good_total', "$good_total");
4752 $rpt->assign('sales_tax', "$sales_tax");
4753 $rpt->assign('total', "$total");
4754 }
4755 $pymt_activation = getHiddenGlobalSettingValue(5000,81,90000200);
4756 if($type == 'K' && $pymt_activation == '1'){
4757 $type1 = "AR";
4758 $type2 = $rpt->oldData['hd_type2'];
4759 $transno = $rpt->oldData['dt_transno'];
4760
4761 $sql3 = "
4762 select 'Payment Info:' as tpop_name1,'Payment Type:' as payment_name1,'Payment Method:' as tpop_name2,'' as card_no,'' as bank,'' as full_card_no,'' as voucher_no,'' as pay_amt, '' as info
4763 union all
4764 select if(tpop_nature=3,ccard_name1,tpop_code) as tpop_name1,
4765 if(tpop_nature=3,ccard_name1,tpop_name1) as payment_name1,
4766 if(tpop_nature=3,ccard_name1,tpop_code) as tpop_name2,
4767 if(tpop_nature=3, right(pymt_info2,4), '') as card_no,
4768 if(tpop_nature=2, concat(bb_code,':',bb_name), '') as bank,
4769 if(tpop_nature=3, right(pymt_info2,16), '') as full_card_no,
4770 if(tpop_nature=4 or tpop_nature=6, pymt_info1, '') as voucher_no,
4771 sum(pymt_received_amt) as pay_amt,
4772 if(tpop_nature=3, right(pymt_info2,4), pymt_info1) as info
4773 from pos_pymt_detail inner join typeofpaymentmst on pymt_type=tpop_no left join creditcardmst on ccard_no = pymt_info1
4774 left join bankbranchmst on bb_no=pymt_info1
4775 where pymt_type1 = '$type1' and pymt_type2='$type2' and pymt_transno='$transno'
4776 group by pymt_type,if(tpop_nature=3,right(pymt_info2,4),pymt_info1);
4777 ";
4778 $res3 = $nllDb->executeQuery($sql3);
4779 while($row3 = $nllDb->fetchArray($res3)){
4780 $rpt->tpl->assign('data2',$row3);
4781 $rpt->tpl->show_tpl_output("t_detail_line2");
4782 $rpt->_detailRowNo++;
4783 }
4784 }
4785 //ENd
4786
4787 global $show_order_info;
4788 global $tbl_name1;
4789
4790 $tbl_tempTotal = uniqid("tmp_temptotal_");
4791 $sqlDrop = "DROP TABLE IF EXISTS $tbl_tempTotal;";
4792 $nllDb->executeQuery($sqlDrop);
4793
4794 if($s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4795 if($show_order_info){
4796 $sqlCaption ="CREATE TEMPORARY TABLE $tbl_tempTotal SELECT '' AS ord_refno, '' AS ord_qty, '' AS deli_qty, '' AS bal_qty, '' AS dt_prdcode, '' AS prdt_code, '' AS prdt_name1 ";
4797
4798 $sql ="SELECT dt_import_transno, dt_import_type1, dt_import_type2, dt_import_transeqno, dt_import_refno FROM $tbl_name1 GROUP BY dt_import_transno ORDER BY $tbl_name1.dt_import_refno, dt_sorting, dt_transeqno, dt_userdefine1, dt_userdefine2; ";
4799 $res4 = $nllDb->executeQuery($sql);
4800
4801 while($row4 =$nllDb->fetchArray($res4)){
4802 $transno= $row4['dt_import_transno'];
4803 $type1=$row4['dt_import_type1'];
4804 $type2=$row4['dt_import_type2'];
4805 $transeqno=$row4['dt_import_transeqno'];
4806 $refno=$row4['dt_import_refno'];
4807
4808 if($transno!="" && $transeqno!="" && $transno!=0){
4809 if($type2=="SO"){
4810 $sqlCaption .=" UNION ALL SELECT ord_header.hd_refno AS ord_refno, ord_detail.dt_qty AS ord_qty, (ord_detail.dt_qty- ord_detail.dt_backorder) AS deli_qty,
4811 ord_detail.dt_backorder AS bal_qty, dt_prdcode, prdt_code, prdt_name1
4812 FROM ord_detail INNER JOIN ord_header ON hd_transno=dt_transno AND hd_type1=dt_type1 AND hd_type2=dt_type2
4813 LEFT JOIN productmst ON dt_prdcode=prdt_no
4814 WHERE dt_transno=$transno AND dt_type1='$type1' AND dt_type2='$type2'
4815 ";
4816 }
4817 else{
4818 $sqlDO= "SELECT ord_header.hd_yourno,
4819 if(ord_header.hd_ourno='' || ord_header.hd_ourno is null, ord_header.hd_refno, ord_header.hd_ourno) as hd_ourno,
4820 bill_detail.dt_import_transeqno AS transeqno, bill_detail.dt_import_transno AS transno, bill_detail.dt_import_type1 AS type1, bill_detail.dt_import_type2 AS type2
4821 FROM bill_detail
4822 INNER JOIN ord_header ON hd_transno = dt_import_transno AND hd_type1=dt_import_type1 AND hd_type2=dt_import_type2
4823 WHERE dt_transno=$transno and dt_type1='$type1' and dt_type2='$type2' and dt_transeqno=$transeqno;
4824 ";
4825 $results = $nllDb->executeQuery($sqlDO);
4826 while($rows = $nllDb->fetchArray($results)){
4827 $s_refno = $rows['hd_ourno'];
4828 $s_transeqno = $rows['transeqno'];
4829 $s_transno = $rows['transno'];
4830 $s_type1 = $rows['type1'];
4831 $s_type2 = $rows['type2'];
4832 }
4833 //azie@20090929
4834 $sqlCaption.=" UNION ALL SELECT ord_header.hd_refno AS ord_refno, ord_detail.dt_qty AS ord_qty, (ord_detail.dt_qty- ord_detail.dt_backorder) AS deli_qty,
4835 ord_detail.dt_backorder AS bal_qty, dt_prdcode, prdt_code, prdt_name1
4836 FROM ord_detail INNER JOIN ord_header ON hd_transno=dt_transno AND hd_type1=dt_type1 AND hd_type2=dt_type2
4837 LEFT JOIN productmst ON dt_prdcode=prdt_no
4838 WHERE dt_transno=$s_transno AND dt_type1='$s_type1' AND dt_type2='$s_type2'
4839 ";
4840 }
4841 }
4842 }
4843
4844 //$sqlTotal = "CREATE TEMPORARY TABLE $tbl_tempTotal $sqlCaption $sqlOrder";
4845 $nllDb->executeQuery($sqlCaption);
4846 $sqlOrdDetail = "SELECT * FROM $tbl_tempTotal ";
4847 $ress = $nllDb->executeQuery($sqlOrdDetail);
4848 while($rows = $nllDb->fetchArray($ress)){
4849 $rpt->tpl->assign('data2',$rows);
4850 $rpt->tpl->show_tpl_output("t_detail_line2");
4851 $rpt->_detailRowNo++;
4852 }
4853
4854 $sqlGetTotal = "SELECT CAST(SUM(ord_qty)AS decimal (16,6)) AS ttl_ord, CAST(SUM(deli_qty) AS decimal(16,6)) AS ttl_deli, CAST(SUM(bal_qty) AS decimal(16,6)) AS ttl_bal FROM $tbl_tempTotal WHERE ord_qty>0;";
4855 $resTtl = $nllDb->executeQuery($sqlGetTotal);
4856
4857 while($rowTtl = $nllDb->fetchArray($resTtl)){
4858 $ttl_ord = $rowTtl['ttl_ord'];
4859 $ttl_deli = $rowTtl['ttl_deli'];
4860 $ttl_bal = $rowTtl['ttl_bal'];
4861 }
4862 $rpt->assign('ttl_ord',$ttl_ord);
4863 $rpt->assign('ttl_deli',$ttl_deli);
4864 $rpt->assign('ttl_bal',$ttl_bal);
4865 }
4866 }
4867 if(!$show_order_info)
4868 $rpt->assign('ShowOrderInfo', 'display:none');
4869
4870 $rpt->setAlwaysCompile(true);
4871 $previousPageContent = $t_page_footer;
4872
4873 global $template;
4874 $rpt->assign('isContinue', $rpt->_isContinue);//yinru @ 20141217
4875 if($rpt->_isContinue){
4876 $rpt->hideParts("t_page_footer","pgfooter_part2");
4877 }
4878 else{
4879 $rpt->hideParts("t_page_footer","pgfooter_part1");
4880 //One Stop p3.3.3 Warehouse AR DO printout(local DO) (#13507)
4881 if($s_template == 'inv_rpt_bil_dncn_one_stop.tpl'){
4882 $rpt->tpl->assign('total_amount',$total_amount);
4883 $total_amount=0;
4884 }
4885 }
4886
4887 return true;
4888}
4889
4890function nllEvents_PageAfterPrintFooter(){
4891 //add the code here
4892 global $rpt;
4893 global $t_page_footer;
4894 global $previousPageContent;
4895 global $s_template;
4896 global $single_copy;
4897 global $bil_print_3copy;
4898
4899
4900
4901 $t_page_footer = $previousPageContent ;
4902 $rpt->setAlwaysCompile(true);
4903}
4904
4905
4906
4907
4908if(strstr($s_template,'saha'))
4909 $row = 0;
4910else{
4911 if($rpt->_t_group_footer_rows==='' ||$rpt->_t_group_footer_rows===NULL)
4912 $row = 3;
4913 else
4914 $row = $rpt->_t_group_footer_rows;
4915}
4916
4917//if($s_template=="inv_rpt_ar_bil_cb_tokopak4.tpl"||$s_template=="tokopak1_do.tpl"||$s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl"){
4918//#7885
4919
4920if (($single_copy=="0" || $single_copy=="") && $bil_print_3copy>1){
4921// assign attributes
4922$groupBreaks[] = array("column" => "dummy_refno"
4923 , "page_break" => true
4924 , "h_rows" => 0
4925 , "h_index" => 0
4926 , "f_rows" => $row
4927 , "f_index" => 1
4928 );
4929
4930$rpt->setGroupBreaks($groupBreaks);
4931$rpt->setPageReset(true);
4932}
4933else{
4934// assign attributes
4935$groupBreaks[] = array("column" => "hd_refno"
4936 , "page_break" => true
4937 , "h_rows" => 0
4938 , "h_index" => 0
4939 , "f_rows" => $row
4940 , "f_index" => 1
4941 );
4942
4943$rpt->setGroupBreaks($groupBreaks);
4944$rpt->setPageReset(true);
4945}
4946
4947if($s_template == 'inv_rpt_ar_bil_bill_inv_preprinted_fd.tpl' || $s_template == 'inv_rpt_ar_bil_inv_LiiHen_usd_only.tpl' || $s_template == 'inv_rpt_ar_bil_bill_inv_fd_non_tax.tpl' || $s_template == 'inv_rpt_ar_bil_bill_inv_fd_non_gst_table.tpl')
4948 {
4949 $groupBreaks[] = array("column" => "do_container"
4950 , "page_break" => false
4951 , "h_rows" => 2
4952 , "h_index" => 2
4953 , "f_rows" => 0
4954 , "f_index" => 0
4955 );
4956 $rpt->setGroupBreaks($groupBreaks);
4957
4958 }
4959
4960//serial no. -yip
4961//if($s_template=='inv_rpt_ar_bil_inv_with_serial.tpl'){
4962// $rpt->setNumberOfDetailRow(3);
4963//}
4964
4965//#21929
4966/* 20170417 beeha 31196 Inventory - Transaction Entry - Customer Bill Printing - add listbox option of company bank account to be printed in invoice */
4967$p_bankno=CCGetParam('bankno1');
4968if($p_bankno!="" ){
4969 $compacc_sql = "SELECT cmpnyacct_Name, bankacc_no, cmpnyacct_ID, acct_name1 AS cmpnyacct_name1 FROM companyaccountmst LEFT JOIN accountmst ON chartacc_no = acct_no WHERE bank_format_no = '$p_bankno' ;";
4970 $compacc_res = $nllDb->executeQuery($compacc_sql);
4971 $compacc_row = $nllDb->fetchArray($compacc_res);
4972}else{
4973 $compacc_sql = "SELECT cmpnyacct_Name, bankacc_no, cmpnyacct_ID, acct_name1 AS cmpnyacct_name1 FROM companyaccountmst LEFT JOIN accountmst ON chartacc_no = acct_no;";
4974 $compacc_res = $nllDb->executeQuery($compacc_sql);
4975 $compacc_row = $nllDb->fetchArray($compacc_res);
4976}
4977if($compacc_row[1]!='' && $compacc_row[1]!='0')
4978{
4979 //$bank_name = "<strong>*Bank Name : </strong>".$compacc_row[0];
4980 //$bank_accno = "<strong>*Bank Account No. : </strong>".$compacc_row[1];
4981 //$bank_accid = "<strong>*Bank Account ID : </strong>".$compacc_row[2];
4982
4983 $rpt->assign("hasaccount",1);
4984 //$rpt->assign("bank_account_name",$bank_name);
4985 //$rpt->assign("bank_account_no",$bank_accno);
4986
4987 // #27874 convert to shorttext for bank_account_name , bank_account_no, bank_account_id
4988 global $multilanguage;
4989 $bankaccname = "<strong>*{stxtrptBankAccountName} :</strong>".$compacc_row[0] ;
4990 $bankaccno = "<strong>*{stxtrptBankAccountNo} :</strong>".$compacc_row[1] ;
4991 $bankaccid = "<strong>*{stxtrptBankAccountID} :</strong>".$compacc_row[2] ;
4992
4993 if(!$multilanguage){
4994 require_once(RelativePath."/class/multi_language.php");
4995 $multilanguage=new MultiLanguage();
4996 }
4997 $bankaccname = $multilanguage->convertField($bankaccname);
4998 $bankaccno = $multilanguage->convertField($bankaccno);
4999 $bankaccid = $multilanguage->convertField($bankaccid);
5000
5001 $rpt->assign("bank_account_name",$bankaccname);
5002 $rpt->assign("bank_account_no",$bankaccno);
5003 $rpt->assign("bank_account_id",$bankaccid);
5004 //
5005
5006 //for ODT report
5007 $rpt->assign("bank_acc_name",$compacc_row[0]);
5008 $rpt->assign("bank_acc_no",$compacc_row[1]);
5009
5010 if($compacc_row[2]!='' && $compacc_row[2]!=NULL)
5011 {
5012 //$rpt->assign("bank_account_id",$bank_accid);
5013 $rpt->assign("bank_acc_id",$compacc_row[2]);
5014 }
5015}
5016//
5017xs_include_event('inv_bill_webixs_brisk_disb');
5018//register funtion to use in template
5019$rpt->tpl->register_function("customHideZero", "getHideZero");
5020
5021$sql = array(
5022 "detail" => $sSQL
5023 );
5024$rpt->setSql($sql);
5025
5026//update the printed time & print count duplicate
5027//20130612 Yinru #16752 - Fiamma - Inventory AR Print DO from Invoice Count
5028if($type=='I' && $IDO_COUNT=='1'){
5029 $print_date=date("Y-m-d H:i:s");
5030 if($print_type=='INV'){
5031 $update_fields = "hd_print_no = (hd_print_no+1), hd_sys_last_print_date='$print_date', hd_sys_last_print_user='$NLL_USER_SESSION' ";
5032 }
5033 else if($print_type=='DO'){
5034 $update_fields = "hd_invdo_print_no = (hd_invdo_print_no+1), hd_invdo_sys_last_print_date='$print_date', hd_invdo_sys_last_print_user='$NLL_USER_SESSION' ";
5035 }
5036
5037 $fieldsArray=array($update_fields);
5038 $rpt->updatedate("SELECT distinct hd_transno, hd_print_no, hd_type1,hd_type2, 'inv_update' as module FROM $tbl_name1", $fieldsArray, "bill_header", 0);
5039
5040}
5041else{
5042 $fieldsArray=array("hd_sys_last_print_date", "hd_sys_last_print_user", "hd_print_no");
5043 $rpt->updatedate("SELECT distinct hd_transno, hd_print_no, hd_type1,hd_type2, 'INV' as module FROM $tbl_name1", $fieldsArray, "bill_header", 0);
5044}
5045//echo $fieldsArray;
5046
5047//$rpt->setAlwaysCompile(true);
5048
5049if($template=='inv_rpt_ar_bil_inv_KFM.tpl')
5050{
5051 $rpt->setPaperSize(LT);
5052}
5053else if($s_template=="inv_rpt_ar_bil_inv_tkp.tpl" || $s_template=="tokopak_do_with_lesenno.tpl" || $s_template=="tokopak_do.tpl" || $s_template=="tokopak_do_smmdo.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_delto.tpl" ||$s_template=="inv_rpt_ar_bil_inv_tkp1.tpl" ||$s_template=="tokopak1_do.tpl"||$s_template=="inv_rpt_ar_bil_cb_tokopak4.tpl" || $s_template=="do_deliver_to_tokopak.tpl" || $s_template=="inv_rpt_ar_bil_inv_tkp_sony.tpl")
5054{
5055 $rpt->setPaperSize(LT);
5056 $rpt->printingPortrait="false";
5057}
5058else if($s_template=="inv_rpt_ar_bil_cb_tokopak.tpl" || $s_template=="saha_receipt_tax_invoice.tpl" || $s_template=="saha_receipt_tax_invoice_vat.tpl")
5059{
5060 $rpt->setPaperSize(LT);
5061 $rpt->printingPortrait="true";
5062}
5063
5064$rpt->setEmailSubject($report_title);
5065
5066// do the looping execution
5067$rpt->setEmailColumn('dbtr_email');
5068$rpt->setReceipientColumn('dbtr_name1');
5069
5070//20190528 leewah 37296 Xeersoft - E-Billing with CC and BCC recipients email
5071$rpt->setEmailCcColumn('dbtr_email_cc');
5072$rpt->setEmailBccColumn('dbtr_email_bcc');
5073//end 37296
5074
5075//20180227 leewah 33418 email secured pdf
5076if($chkSecurePDF=='1' && $printToPDF=='1' && $printToPDFType=='emailto')
5077{
5078 $from_mth = str_replace("-", "", "$from_date"); //cut '-'
5079 $from_mth = substr($from_mth, 0, -2 ); //cut dd
5080 $to_mth = str_replace("-", "", "$to_date");
5081 $to_mth = substr($to_mth, 0, -2 );
5082
5083 $mth_range = $from_mth;
5084 if($from_mth != $to_mth) //if to_mth on different mth, show the month range
5085 {
5086 $mth_range .= "_to_".$to_mth;
5087 }
5088 // $mth_range = $to_date;
5089 $suffix_securedPDFName = "-Monthly_".$report_title."-".$mth_range;
5090 $suffix_securedPDFName = str_replace(" ", "_", "$suffix_securedPDFName");
5091 //echo $suffix_securedPDFName."<br><br>";
5092
5093 $rpt->setPDFNameRaw('dbtr_name1','',$suffix_securedPDFName); //setPDFNameRaw(data column, prefix, suffix)
5094 $rpt->setPDFpw('default_pw');
5095
5096}
5097
5098//Elaine
5099$rpt->assign('payment_method', $payment_method['payment_method']);
5100
5101if($separate_by_debtor!=1){
5102$rpt->generate();
5103}
5104
5105if($nlldb_redir_name){
5106 $nllDb->_dbConnection->setDb($original_company);
5107 $nllDb->_dbConnection->openConnection(NLLDBHOST,NLLDBUSER,NLLDBPASS);
5108 $nlldb->_dbConnection->setDb($original_company);
5109 $nlldb->_dbConnection->openConnection(NLLDBHOST,NLLDBUSER,NLLDBPASS);
5110 $_SESSION['nlldbname_redirect'] = $comp_session[0];
5111 $_SESSION['NLL_COMPANY_NAME'] = $comp_session[1];
5112 $_SESSION['NLL_COMPANY_NAME2'] = $comp_session[2];
5113 $_SESSION['NLL_COMPANY_REGNO'] = $comp_session[3];
5114 $_SESSION["NLL_COMPANY_ADDRESS"] = $comp_session[4];
5115 $_SESSION["NLL_COMPANY_TEL"] = $comp_session[5];
5116 $_SESSION['NLL_COMPANY_FAX'] = $comp_session[6];
5117 $_SESSION['NLL_COMPANY_EMAIL'] = $comp_session[7];
5118 $_SESSION['NLL_COMPANY_URL'] = $comp_session[8];
5119 $_SESSION["NLL_COMPANY_TELFAX"] = $comp_session[9];
5120 $_SESSION["NLL_CURR"] = $comp_session[10];
5121 $_SESSION['OFF_SESSION_START'] = '';
5122}
5123//ends
5124return;
5125
5126///////////////////////////////////////////////////////////////////////
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138//////////////////////////////////////////////////////////////////////
5139
5140
5141
5142?>
5143<?php
5144die;
5145
5146//Include Common Files @1-B385E435
5147define("RelativePath", "..");
5148define("PathToCurrentPage", "/report/");
5149define("FileName", "inv_rpt_ar_bil_bill_dt1.php");
5150include(RelativePath . "/Common.php");
5151include(RelativePath . "/Template.php");
5152include(RelativePath . "/Sorter.php");
5153include(RelativePath . "/Navigator.php");
5154//End Include Common Files
5155
5156//Initialize Page @1-823111ED
5157// Variables
5158$FileName = "";
5159$Redirect = "";
5160$Tpl = "";
5161$TemplateFileName = "";
5162$BlockToParse = "";
5163$ComponentName = "";
5164
5165// Events;
5166$CCSEvents = "";
5167$CCSEventResult = "";
5168
5169$FileName = FileName;
5170$Redirect = "";
5171$TemplateFileName = "inv_rpt_ar_bil_bill_dt1.html";
5172$BlockToParse = "main";
5173$TemplateEncoding = "ISO-8859-1";
5174$PathToRoot = "../";
5175//End Initialize Page
5176
5177//Initialize Objects @1-E10C591F
5178
5179$CCSEventResult = CCGetEvent($CCSEvents, "AfterInitialize", $MainPage);
5180
5181$Charset = $Charset ? $Charset : "iso-8859-1";
5182if ($Charset)
5183 header("Content-Type: text/html; charset=" . $Charset);
5184//End Initialize Objects
5185
5186//Initialize HTML Template @1-6CC97037
5187$CCSEventResult = CCGetEvent($CCSEvents, "OnInitializeView", $MainPage);
5188$Tpl = new clsTemplate();
5189$Tpl->LoadTemplate(PathToCurrentPage . $TemplateFileName, $BlockToParse, "ISO-8859-1");
5190$Tpl->block_path = "/$BlockToParse";
5191$CCSEventResult = CCGetEvent($CCSEvents, "BeforeShow", $MainPage);
5192//End Initialize HTML Template
5193
5194//Go to destination page @1-FBA93089
5195if($Redirect)
5196{
5197 $CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload", $MainPage);
5198 header("Location: " . $Redirect);
5199 unset($Tpl);
5200 exit;
5201}
5202//End Go to destination page
5203
5204//Show Page @1-0ED5DF31
5205$Tpl->block_path = "";
5206$Tpl->Parse($BlockToParse, false);
5207$main_block = $Tpl->GetVar($BlockToParse);
5208$PKQQHIM2E10O5H9C = array("<center><font fac","e=\"Arial\"><smal","l>Gen&#","101;rat",";ed <!-- CCS -","->wi","16;h <!-- SC","C -->CodeC
","4;arge ","<!-- CCS -->S","tudio.</","small></font></ce","nter>");
5209if(preg_match("/<\/body>/i", $main_block)) {
5210 $main_block = preg_replace("/<\/body>/i", join($PKQQHIM2E10O5H9C,"") . "</body>", $main_block);
5211} else if(preg_match("/<\/html>/i", $main_block) && !preg_match("/<\/frameset>/i", $main_block)) {
5212 $main_block = preg_replace("/<\/html>/i", join($PKQQHIM2E10O5H9C,"") . "</html>", $main_block);
5213} else if(!preg_match("/<\/frameset>/i", $main_block)) {
5214 $main_block .= join($PKQQHIM2E10O5H9C,"");
5215}
5216$CCSEventResult = CCGetEvent($CCSEvents, "BeforeOutput", $MainPage);
5217if ($CCSEventResult) echo $main_block;
5218//End Show Page
5219
5220//Unload Page @1-74A7C1E7
5221$CCSEventResult = CCGetEvent($CCSEvents, "BeforeUnload", $MainPage);
5222unset($Tpl);
5223//End Unload Page
5224?>