/var/www/enzatesting.onesolution.hk/pdf_ord_planreport.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<?php
$formid 
"Order";
require_once 
"inc/configure.php";
require_once 
"inc/ord_dtl_func.php";
require_once 
"inc/pdf/tcpdf.php";
/*
if(havePermission("DCr")==false
|| havePermission("DPr")==false
//|| havePermission("MDr")==false
//|| havePermission("TDr")==false
){
    
    myerror("Invalid Permission");    
}
*/

//$_REQUEST['status'] = setDefaultReqVar("status", 'PIP');

/*
search_orderField($_REQUEST['act'], $_REQUEST['customer'], $_REQUEST['launchdate_start'], $_REQUEST['launchdate_end'], $_REQUEST['deliverydate_start'], $_REQUEST['deliverydate_end'], $_REQUEST['finished'], $_REQUEST['status'], $_REQUEST['vendor'], $_REQUEST['showRemaining']  );    
*/
//vdump($_SESSION['search']['order']);

$row_height 18;
$height_2row $row_height 2;
$showBorder 0;
$tableBorder 1;
//vdump($req);
//var_dump($row);

function ord_header(){
    global 
$pdf$tableBorder$row_height;
    
$pdf->SetFont('data_fonts_droidsansfallback'''6);
    
$pdf->MultiCell(44$row_height*2
    
ORDER.WS.NUMBER,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(48$row_height*2
    
LAUNCH_DATE,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(48$row_height*2
    
DELIVERY.WS.DATE,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height*2
    
ORDER.WS.QTY,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(31$row_height*2
    
NOT_STARTED,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height*2
    
WAXD,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height*2
    
CASO,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height*2
    
CASD,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height*2
    
FILD,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height*2
    
SETD,
    
$tableBorder'C'10''''true0falsetrue0'M');

    
// 20240711 update by OSL_yee
    
$pdf->MultiCell(28$row_height*2
    
LAPID_CODE,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height*2
    
POLD,
    
$tableBorder'C'10''''true0falsetrue0'M');

    
// 20240711 update by OSL_yee
    
$pdf->MultiCell(28$row_height*2
    
ENAMEL_CODE,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height*2
    
MQCD,
    
$tableBorder'C'10''''true0falsetrue0'M');

    
// 20240711 update by OSL_yee
    
$pdf->MultiCell(26$row_height*2
    
WCFM_CODE,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height*2
    
PAKD,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height*2
    
SENT_TO_HK,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(36$row_height*2
    
SENT_TO_CUSTOMER,
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(38$row_height*2
    
CUSTOMER.WS.ORDER.WS.REFERENCE,
    
$tableBorder'C'11''''true0falsetrue0'M');    
    
$pdf->SetFont('data_fonts_droidsansfallback'''7);
}

function 
ord_footer($ttl){
    global 
$pdf$tableBorder$row_height;
    
$pdf->SetFont('data_fonts_droidsansfallback'''7);
    
$pdf->MultiCell(140$row_height
    
TOTAL,
    
$tableBorder'L'10''''true0falsetrue0'L');
    
/*    $pdf->MultiCell(50, $row_height, 
        datef($row['launch_date']),
        $tableBorder, 'C', 1, 0, '', '', true, 0, false, true, 0, 'M');
        $pdf->MultiCell(50, $row_height, 
        datef($row['del_date']),
        $tableBorder, 'C', 1, 0, '', '', true, 0, false, true, 0, 'M');
    */
    
$pdf->MultiCell(26$row_height
    
numf($ttl['QTY']+$ttl['NOT_STARTED']),//2022-02-18
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(31$row_height
    
$ttl['NOT_STARTED'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height
    
$ttl['WAXD'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height
    
$ttl['CASO'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height
    
$ttl['CASD'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height
    
$ttl['FILD'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height
    
$ttl['SETD'],
    
$tableBorder'R'10''''true0falsetrue0'M');

    
// 20240711 update by OSL_yee
    
$pdf->MultiCell(28$row_height
    
$ttl['LAPID'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height
    
$ttl['POLD'],
    
$tableBorder'R'10''''true0falsetrue0'M');

    
// 20240711 update by OSL_yee
    
$pdf->MultiCell(28$row_height
    
$ttl['ENAMEL'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height
    
$ttl['MQCD'],
    
$tableBorder'R'10''''true0falsetrue0'M');

    
// 20240711 update by OSL_yee
    
$pdf->MultiCell(26$row_height
    
$ttl['WCFM'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height
    
$ttl['PAKD'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(26$row_height
    
$ttl['IVC_FTY'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(36$row_height
    
$ttl['IVC_CUS'],
    
$tableBorder'R'10''''true0falsetrue0'M');
    
$pdf->MultiCell(38$row_height
    
'',
    
$tableBorder'C'11''''true0falsetrue0'M');    
    
$pdf->SetFont('data_fonts_droidsansfallback'''7);
}

function 
reqnewpage_check($fn$margin=0){
    global 
$pdf$pagebreakpt;
    if(
$pdf->getY() + $margin $pagebreakpt){
        
//page break
        
$pdf->addPage();
        
//print user defined header function
        
call_user_func($fn);
    }
}

class 
doc extends TCPDF{
    
//Page header
    
public function Header(){
        global 
$row
        
$image_file 'image/ENZA-Logo.jpg';
        
$this->Image($image_file1010150'''''''''');
        
//$this->Image($image_file, 125, 20, 350, '', '', '', '', '');
        //$this->Image($image_file, 50, 20, 500, '', '', '', '', '');

// define barcode style
$style = array(
    
'position' => '',
    
'align' => 'C',
    
'stretch' => false,
    
'fitwidth' => true,
    
'cellfitalign' => '',
    
'border' => true,
    
'hpadding' => 'auto',
    
'vpadding' => 'auto',
    
'fgcolor' => array(0,0,0),
    
'bgcolor' => false//array(255,255,255),
    
'text' => true,
    
'font' => 'helvetica',
    
'fontsize' => 8,
    
'stretchtext' => 4
);

        
//$this->write1DBarcode($row['delnote_nbr'], 'C128', '460', '40', '200', 40, 0.8, $style, 'N');
        
        
$this->SetFont('data_fonts_droidsansfallback''B'10);    // bold
        
$this->SetY(30);
        
        if(
$_SESSION['search']['order']['customer'] && $customer=getCustomerByCode($_SESSION['search']['order']['customer']) ){
            
$pdf_title "Production Planning Report (".$customer['custname_en'].")";    
        }else{
            
$pdf_title "Production Planning Report (General)";
        }
        
$this->MultiCell(5600
        
$pdf_title,
        
0'C'01);

        
$this->ln(30);
        
        
//$this->ln(5);
        
$GLOBALS['x_main']= $this->GetX();
        
$GLOBALS['y_main']= $this->GetY();
    }

}

// create new PDF document
$pdf = new doc('P''pt''A4'true'UTF-8'false);
// size reference 'A4' : {$pf = array(  595.276,  841.890); break;}

// set document information
$pdf->SetCreator('ENZA');
$pdf->SetAuthor('ENZA');
$pdf->SetTitle('ENZA');
$pdf->SetSubject('ENZA');
$pdf->SetKeywords('ENZA');
// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 008', PDF_HEADER_STRING);
// set header and footer fonts
//$pdf->setHeaderFont(Array(data_fonts_droidsansfallback, '', PDF_FONT_SIZE_MAIN));
//$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT-1075PDF_MARGIN_RIGHT);    // left, top, right
$pdf->SetHeaderMargin(10);

$pdf->SetCellPadding(5);
//set auto page breaks
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE90);
//set image scale factor
$pdf->setImageScale(1.3333);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// set font
//$pdf->SetFont('data_fonts_droidsansfallback', '', 12);    // bold
$pdf->SetFont('data_fonts_droidsansfallback'''8);
// set color for background
$pdf->SetFillColor(222222222);
$pagebreakpt =720;

// add a page
$pdf->AddPage();

$pdf->SetTopMargin($y_main);    
$x_main$pdf->GetX();

ord_header();

    
$sql_clause='';
    
$sql_param= array();

    if( !empty(
$_SESSION['search']['order']['finished']) ){
        
$sql_clause .= 'dbo.ord_main.finished = :finished ';
        
$sql_param[':finished'] = '1';    
    }    else {
        
$sql_clause .= '( dbo.ord_main.finished <> :finished OR dbo.ord_main.finished IS NULL )';
        
$sql_param[':finished'] = '1';            
    }
        
    if( !empty(
$_SESSION['search']['order']['customer']) ){
        
$sql_clause .= 'AND (custname_en LIKE :custname_en OR custname_sc LIKE :custname_sc OR master_customer.custcode LIKE :custcode) ';
        
$sql_param[':custname_en'] = "%".$_SESSION['search']['order']['customer']."%";
        
$sql_param[':custname_sc'] = "%".$_SESSION['search']['order']['customer']."%";
        
$sql_param[':custcode'] = "%".$_SESSION['search']['order']['customer']."%";            
    }
    
    if( !empty(
$_SESSION['search']['order']['launchdate_start']) ){
        
$sql_clause .= 'AND launch_date>=:launchdate_start ';
        
$sql_param[':launchdate_start'] = $_SESSION['search']['order']['launchdate_start'];
    }
    
    if( !empty(
$_SESSION['search']['order']['launchdate_end']) ){
        
$sql_clause .= 'AND launch_date<=:launchdate_end ';
        
$sql_param[':launchdate_end'] = $_SESSION['search']['order']['launchdate_end'];
    }    

    if( !empty(
$_SESSION['search']['order']['deliverydate_start']) ){
        
$sql_clause .= 'AND del_date>=:deliverydate_start ';
        
$sql_param[':deliverydate_start'] = $_SESSION['search']['order']['deliverydate_start'];
    }
    
    if( !empty(
$_SESSION['search']['order']['deliverydate_end']) ){
        
$sql_clause .= 'AND del_date<=:deliverydate_end ';
        
$sql_param[':deliverydate_end'] = $_SESSION['search']['order']['deliverydate_end'];
    }
    
    if( !empty(
$_SESSION['search']['order']['status']) ){
        
$sql_clause .= 'AND status=:status ';
        
$sql_param[':status'] = $_SESSION['search']['order']['status'];
    }
    
    if( !empty(
$_SESSION['search']['misc']['1']) ){
        
$sql_clause .= 'AND projectmanager=:projectmanager ';
        
$sql_param[':projectmanager'] = $_SESSION['search']['misc']['1'];
    }
    
    if( !empty(
$_SESSION['search']['misc']['2']) ){
        
$sql_clause .= 'AND sales=:sales ';
        
$sql_param[':sales'] = $_SESSION['search']['misc']['2'];
    }        

    if(
$_SESSION['search']['misc']['4']=='ALL'){
        
//no filter
    
}elseif($_SESSION['search']['misc']['4']=='0'){
        
//normal order
        
$sql_clause .= 'AND isrepairorder=:isrepairorder ';
        
$sql_param[':isrepairorder'] = '0';
    }else{
        
//repair order
        
$sql_clause .= 'AND isrepairorder=:isrepairorder ';
        
$sql_param[':isrepairorder'] = '1';
    }

    
$sql "SELECT
    dbo.ord_main.refid,
    dbo.ord_main.order_nbr,
    dbo.ord_main.custorder_ref,
    dbo.ord_main.launch_date,
    dbo.ord_main.del_date,
    dbo.ord_main.confirm_date,    
    dbo.ord_main.remark,
    dbo.master_customer.custname_en,
    dbo.master_customer.custname_sc,
    dbo.ord_main.ttl_qty AS QTY,
    dbo.ord_main.ttl_ordercost,
    dbo.ord_main.ttl_factcost,
    dbo.ord_main.ttl_orderprice,
    dbo.ord_main.ttl_goldwt,
    dbo.ord_main.ttl_silverwt,
    dbo.ord_main.uom_cy,
    dbo.ord_main.status
    FROM
    dbo.ord_main
    INNER JOIN dbo.master_customer ON dbo.ord_main.custcode = dbo.master_customer.custcode
    WHERE 
    
$sql_clause
    ORDER BY launch_date ASC"
;
    
    
$sth $dbh->prepare($sql);
    
$q $sth->execute$sql_param );
//echo $sth->getSQL( $sql_param ) . HTML_EOL;
    
pdo_showerror($sth$q);
                    
while(
$row $sth->fetch()) {    
    
    
$pdf->SetFont('data_fonts_droidsansfallback'''7);
    
$wipstatus ord_WIPStatus($row['refid']);
    
$wipstatus['NOT_STARTED'] = $row['QTY'] - $wipstatus['QTY'];
    
calc_total($ttl$wipstatus);

    
reqnewpage_check('ord_header'$row_height);
    
    
$tmp_h =  $pdf->getStringHeight(80$row['custorder_ref']) * 2;
    
$pdf->MultiCell(44$tmp_h
    
$row['order_nbr'],
    
$tableBorder'C'00''''true0falsetrue0'M');
    
$pdf->MultiCell(48$tmp_h
    
datef($row['launch_date']),
    
$tableBorder'C'00''''true0falsetrue0'M');
    
$pdf->MultiCell(48$tmp_h
    
datef($row['del_date']),
    
$tableBorder'C'00''''true0falsetrue0'M');
    
$pdf->MultiCell(26$tmp_h
    
numf($row['QTY']),
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(31$tmp_h
    
emptyIfZero($wipstatus['NOT_STARTED']),
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(26$tmp_h
    
$wipstatus['WAXD'],
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(26$tmp_h
    
$wipstatus['CASO'],
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(26$tmp_h
    
$wipstatus['CASD'],
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(26$tmp_h
    
$wipstatus['FILD'],
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(26$tmp_h
    
$wipstatus['SETD'],
    
$tableBorder'R'00''''true0falsetrue0'M');

    
// 20240711 update by OSL_yee
    
$pdf->MultiCell(28$tmp_h
    
$wipstatus['LAPID'],
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(26$tmp_h
    
$wipstatus['POLD'],
    
$tableBorder'R'00''''true0falsetrue0'M');

    
// 20240711 update by OSL_yee
    
$pdf->MultiCell(28$tmp_h
    
$wipstatus['ENAMEL'],
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(26$tmp_h
    
$wipstatus['MQCD'],
    
$tableBorder'R'00''''true0falsetrue0'M');

    
// 20240711 update by OSL_yee
    
$pdf->MultiCell(26$tmp_h
    
$wipstatus['WCFM'],
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(26$tmp_h
    
$wipstatus['PAKD'],
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(26$tmp_h
    
$wipstatus['IVC_FTY'],
    
$tableBorder'R'00''''true0falsetrue0'M');
    
$pdf->MultiCell(36$tmp_h
    
$wipstatus['IVC_CUS'],
    
$tableBorder'R'00''''true0falsetrue0'M');

    
$pdf->SetFont('data_fonts_droidsansfallback'''6);
    
$pdf->MultiCell(38$tmp_h
    
txtf($row['custorder_ref']),
    
$tableBorder'L'01''''true0falsetrue0'M');    
}

ord_footer($ttl);
 

//Close and output PDF document
$custcode = empty($customer['custcode']) ? '' $customer['custcode'].'_';
$filename "PlanningReport_".$custcode.date("YmdHis").".pdf";

$pdf->Output($filename'I');
//$pdf->Output($filename, 'D');
?>