/var/www/enzatesting.onesolution.hk/pdf_cn_fty.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
<?php
$formid 
"Order";
require_once 
"inc/configure.php";
require_once 
"inc/pdf/tcpdf.php";
require_once 
"inc/ord_cn_func.php";
if(
havePermission("DCr")==false
|| havePermission("DPr")==false
//|| havePermission("RTr")==false
//|| havePermission("MDr")==false
//|| havePermission("TDr")==false
){

    
myerror("Invalid Permission");
}



function 
ivc_summary(&$ttl_var$dtl){
    
$ttl_var['amount'] += numf($dtl['unitprice']*$dtl['qty'] ,2);
    
$ttl_var['qty'] += $dtl['qty'];
    
$ttl_var['wt'] += $dtl['wt'];
    
//vdump($ttl_var);
    
return $ttl_var;
}

function 
ord_header(){
    global 
$pdf$tableBorder$row_height;
    
$pdf->SetFont('data_fonts_droidsansfallback'''8);
    
$pdf->MultiCell(80$row_height*2,
    
'Product Number',
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(60$row_height*2,
    
'Invoice Number',
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(240$row_height*2,
    
'Description',
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(40$row_height*2,
    
'Weight',
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(40$row_height*2,
    
'Qty',
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(50$row_height*2,
    
'Unit'.PHP_EOL.'Price',
    
$tableBorder'C'10''''true0falsetrue0'M');
    
$pdf->MultiCell(50$row_height*2,
    
'Amount'.PHP_EOL.'USD',
    
$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);
    }
}

$refid = (int)setDefaultReqVar("refid"'');
//$editable = setDefaultReqVar("edit", 0);

if($refid && $row=getDB("cn_int_main"$refid) ){
    
//vdump($row);
} else {
    
myerror(INVALID.WS.REQUEST);
    exit;
}
$header $row;
$customer getDB_master_customer($row['cn_customer']);


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

class doc extends TCPDF{
    
//Page header
    
public function Header(){
        global 
$row;
        
$image_file 'image/ENZA-Logo.jpg';
        
$this->Image($image_file20020200'''''''''');
        
//$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(75);

//        $this->MultiCell(560, 0,
//        ''.PHP_EOL.
//        PHP_EOL.
//        "深圳恩佳珠宝有限公司".PHP_EOL.
//        "SHENZHEN ENZA JEWELLERY CO. LTD.",
//        0, 'C', 0, 1);
//        $this->ln(10);

        
$this->SetFont('helvetica''UB'16);    // bold
        
$this->MultiCell(5600,
        
''.PHP_EOL.
        
PHP_EOL.
        
"Credit Note",
        
0'C'01);
        
$this->ln(10);

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

    
// Page footer
    
public function Footer(){
        global 
$showBorder;
        
$this->SetY(-80);

        
// Set font
        //$this->SetFont('helvetica', 'I', 8);
        
$this->SetFont('data_fonts_droidsansfallback'''6);
        
//addresses
        
$this->MultiCell(180$row_height,
        
'ENZA JEWELLERY LTD.'.PHP_EOL.
// 'Heng Ngai Jewllery Centre,'.PHP_EOL.
// 'Room 14, 11/fl, 4 Hok Yuen street east'.PHP_EOL.
// 'Hung Hom, Hong Kong'.PHP_EOL.
'Unit D5, 9/F, Kaiser Estate, Phase 1, No.37-45 Man Yue'.PHP_EOL.
'Street, Hung Hom, Kowloon, Hong Kong'.PHP_EOL.
'Tel: +852 2180 7118 – Fax: +852 2180 7121'.PHP_EOL,
        
$showBorder'C'00);

        
$this->MultiCell(190$row_height,
        
'SHENZHEN ENZA JEWELLERY CO. LTD.'.PHP_EOL.
'Building B4, 10th/FL,'.PHP_EOL.
'Lilang International jewellery park, 31, Bulan road'.PHP_EOL.
'Shang Lilang, Shenzhen, Guangdong, China'.PHP_EOL.
'Tel: +86 755 89240329 – Fax: +86 755 89240323',
        
$showBorder'C'00);

        
$this->MultiCell(190$row_height,
        
'SHENZHEN ENZA JEWELLERY CO. LTD.'.PHP_EOL.
'Building 6, 4th/FL,Wan Shan Jewellery Park'.PHP_EOL.
'Tian Bei, 4th road Luohu district'.PHP_EOL.
'Shenzhen, Guangdong, China'.PHP_EOL.
'Tel: +86 755 2550 3529 - Fax: +86 755 2553 1507',
        
$showBorder'C'01);

        
$this->ln(10);

        
// Page number
        
$this->SetX(35);
        
$this->Cell(010''.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), $showBorderfalse'C'0''0false'T''M');
    }
}

// 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_LEFT75PDF_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();

$pdf->MultiCell(300$row_height,
'Invoicing address - 发票地址:'.PHP_EOL,
$showBorder'L'00);

$pdf->MultiCell(90$row_height,
'Date: ',
$showBorder'L'00);
$pdf->MultiCell(150$row_height,
date_format(date_create($row['launch_date']), 'l, F d, Y'),
//$row['launch_date'], //date("l, F d, Y")
$showBorder'R'01);

//$pdf->SetFont('data_fonts_droidsansfallback', 'B', 9);
$pdf->MultiCell(300$row_height,
html_entity_decode($customer['companyname_en'], ENT_QUOTES),
$showBorder'L'00);
//$pdf->SetFont('data_fonts_droidsansfallback', '', 8);
$pdf->MultiCell(90$row_height,
'Credit note number: ',
$showBorder'L'00);
$pdf->MultiCell(150$row_height,
$row['cn_nbr'],
$showBorder'R'01);

$pdf->MultiCell(300$row_height,
html_entity_decode(buildAddressFormat($customer['invaddr1'], $customer['invpostcode'], $customer['invcity'], $customer['invcountry'], $customer['invtelno'], $customer['invfaxno']), ENT_QUOTES).PHP_EOL,
$showBorder'L'01);
//
//$pdf->MultiCell(300, $row_height,
//'Shipping address - 送货地址:'.PHP_EOL,
//$showBorder, 'L', 0, 0);
//
//$pdf->MultiCell(90, $row_height,
//'',
//$showBorder, 'L', 0, 0);
//$pdf->MultiCell(150, $row_height,
//$row[''],
//$showBorder, 'R', 0, 1);
//
////$pdf->SetFont('data_fonts_droidsansfallback', 'B', 9);
//$pdf->MultiCell(300, $row_height,
//html_entity_decode($customer['companyname_en'], ENT_QUOTES),
//$showBorder, 'L', 0, 0);
////$pdf->SetFont('data_fonts_droidsansfallback', '', 8);
//
//
//$pdf->MultiCell(90, $row_height,
//'',
//$showBorder, 'L', 0, 0);
//$pdf->MultiCell(150, $row_height,
//$row[''],
//$showBorder, 'R', 0, 1);
//
//$pdf->MultiCell(300, $row_height,
//html_entity_decode(buildAddressFormat($customer['deladdr'], $customer['delpostcode'], $customer['delcity'], $customer['delcountry'], $customer['deltelno'], $customer['delfaxno']), ENT_QUOTES).PHP_EOL,
//$showBorder, 'L', 0, 1);

$pdf->Ln(10);


ord_header();

$sql "SELECT
        dbo.cn_intmain_dtl.*,
        dbo.inv_product.itemno
        FROM
        dbo.cn_intmain_dtl
        LEFT JOIN dbo.inv_product ON dbo.inv_product.refid = dbo.cn_intmain_dtl.product_refid
        WHERE
        dbo.cn_intmain_dtl.cnintmain_refid = :refid"
;
$sth $dbh->prepare($sql);
$q $sth->execute( array(':refid'=>$refid) );
//echo $sth->getSQL( array(':ivcfty_refid'=>$refid) ) . HTML_EOL;
pdo_showerror($sth$q);

$ttl_var = array();
while(
$dtl $sth->fetch()){
    
reqnewpage_check('ord_header');

    
$itemdesc $dtl['desc'].PHP_EOL.$dtl['remarks'];
    
$rowh max($pdf->getStringHeight(240$itemdesc), $row_height*2);

    
//vdump($dtl);
    
$pdf->MultiCell(80$rowh,
    
evl($dtl['itemno'], 'N/A'),//.PHP_EOL.'('.$dtl['serialno'].')',
    
$tableBorder'C'00''''true0falsetrue0'M'true);
    
$pdf->MultiCell(60$rowh,
    empty(
$dtl['ordtxpako_refid']) ? 'N/A' cn_fty_getSNivcftynbr$dtl['ordtxpako_refid'] ),
    
//zvl(cn_fty_getSNivcftynbr( $dtl['ordtxpako_refid'] ), ),
    
$tableBorder'C'00''''true0falsetrue0'M'true);
    
$pdf->MultiCell(240$rowh,
    
$itemdesc,
    
$tableBorder'L'00''''true0falsetrue0'M'true);
    
$pdf->MultiCell(40$rowh,
    
numfs($dtl['wt']).' '.$dtl['uom_wt'],
    
$tableBorder'C'00''''true0falsetrue0'M'true);
    
$pdf->MultiCell(40$rowh,
    
numf($dtl['qty']),
    
$tableBorder'C'00''''true0falsetrue0'M'true);
    
$pdf->MultiCell(50$rowh,
    
numfs($dtl['unitprice']),
    
$tableBorder'R'00''''true0falsetrue0'M'true);
    
$pdf->MultiCell(50$rowh,
    
number_format($dtl['unitprice']*$dtl['qty'], 2),
    
$tableBorder'R'01''''true0falsetrue0'M'true);

    
ivc_summary($ttl_var$dtl);
    unset(
$rowh);
    unset(
$dtl);
}
//vdump($ttl_var); exit;
$ttl_row_height $row_height+5;
$pdf->MultiCell(380$ttl_row_height,
'Total',
$tableBorder'L'10);
$pdf->MultiCell(40$ttl_row_height,
numf($ttl_var['wt']). ' gr',
$tableBorder'C'10);
$pdf->MultiCell(40$ttl_row_height,
numf($ttl_var['qty']),
$tableBorder'C'10);
$pdf->SetFont('data_fonts_droidsansfallback'''8);
$pdf->MultiCell(100$ttl_row_height,
number_format($ttl_var['amount'], 2),
$tableBorder'R'11);

//Close and output PDF document
$filename "CreditNote_".$row['cn_nbr'].".pdf";

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