/var/www/hkosl.com/oneMotorChunHing_delete20240201/html/printInvoice55.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
<?php
require_once('pdf/config/lang/eng.php');
require_once(
'pdf/tcpdf.php');
require_once(
"inc/configure.php");

$invoiceno = (int)$_GET['invoiceno'];
$headerY 0;

class 
InvoicePDF extends TCPDF{

    public function 
Header(){
        
$image_file 'invoice.jpg';
        
$this->Image($image_file11010''150);
        
$inv $GLOBALS['invoiceno'];
        
$sql "SELECT a.invoiceno, a.custid, a.custno, a.custnameeng, a.telno, a.faxno
                    , a.email, b.username, a.orderdate, a.billaddress, a.discount, paymentmethod
                    , paymentterm, sum(c.amount)-a.discount as totalamount
                    , a.status, a.attn, a.licno, a.caryear, a.mileage, a.modelno, a.chassisno
                from OM_INVOICE_HDR a, SYS_USER b, OM_INVOICE_DTL c, SYS_PAYMENTMETHOD d
                    , SYS_PAYMENTTERM e
                where a.salesid = b.userid
                    and a.invoiceno = c.invoiceno
                    and a.invoiceno = 
$inv
                    and a.paymentmethodid = d.paymentmethodid
                    and a.paymenttermid = e.paymenttermid
                    and salesman = 1
                group by a.invoiceno, a.custid, a.custno
                    , a.custnameeng, a.telno, a.faxno
                    , a.orderdate, b.username, a.discount
                    , paymentmethod, paymentterm, a.status
                    , a.attn"
;
        
$result mysql_query($sql);
        if(
$row mysql_fetch_array($result,MYSQL_ASSOC)){
            
$custno                $row{'custno'};
            
$catid                $row{'catid'};
            
$custnameeng        $row{'custnameeng'};
            
$telno                $row{'telno'};
            
$faxno                $row{'faxno'};
            
$email                $row{'email'};
            
$salesman            $row{'username'};
            
$orderdate            $row{'orderdate'};
            
$totalamount        $row{'totalamount'};
            
$billaddress        $row{'billaddress'};
            
$attn                $row{'attn'};
            
$paymentmethodid    $row{'paymentmethodid'};
            
$paymenttermid        $row{'paymenttermid'};
            
$headerdiscount        $row{'discount'};
            
$deliverymethod        $row{'deliverymethod'};
            
$status                $row{'status'};
            
$paymentmethod        $row{'paymentmethod'};
            
$paymentterm        $row{'paymentterm'};
            
$licno                $row['licno'];
            
$caryear            $row['caryear'];
            
$mileage            $row['mileage'];
            
$modelno            $row['modelno'];
            
$chassisno            $row['chassisno'];            
        }

        
$sql2 =    "select data from header order by num";
        
$result2 mysql_query($sql2);
        
$arr = array();

        while(
$row2 mysql_fetch_array($result2MYSQL_NUM)){
            
array_push($arr$row2[0]);
        }

        
$html '<h1 style="margin-bottom: 0px; margin-top: 0px; text-align: center; font-size: 223%;">'
                
.'<br /><br />'
                
.'</h1><div  style="text-align:center; font-size: 80%; margin-top: 0px;">'
                
.'<br />'
                
.'<br />'
                
.'</div>';

        
$i 6;

        
$html .= '<br /><table><tr><td rowspan="2" width="65%" style="text-align:right; vertical-align:text-bottom;"><h1>'
                
.'</h1></td><td width="100" style="text-align:right">'.$arr[$i++]
                .
'</td><td width="90">&nbsp;'.$GLOBALS['invoiceno'].'</td></tr><tr><td style="text-align:right">'.$arr[$i++]
                .
'</td><td>&nbsp;'.$orderdate.'</td></tr></table>';
        
$html .= '<table border="2" cellpadding="0" cellspacing="0"><tr><td><table border="1" cellpadding="3"><tr><td>'.$arr[$i++].'</td><td>'.$arr[$i++].'</td></tr><tr><td>'
                
.$arr[$i++].'&#09;'.$custnameeng.'<br />'.$arr[$i++].'&#09;'.$billaddress
                
.'<br />'.$arr[$i++].'&#09;'.$telno.'<br />'.$arr[$i++].'&#09;'.$faxno.'</td><td>'
                
.$arr[$i++].'&#09;'.$licno.'&#09;'.$arr[$i++].' '.$caryear.'<br />'.$arr[$i++].'&#09;'.$modelno.'<br />'
                
.$arr[$i++].'&#09;'.$chassisno.'<br />'.$arr[$i++].'&#09;'.$mileage
                
.'</td></tr></table></td></tr></table>';
        
$html .= '<table border="2" cellpadding="0" cellspacing="0"><tr><td><table border="1" style="text-align: center;" cellpadding="4"><tr><td style="vertical-align:middle" width="61%">'.$arr[$i++]
                .
'</td><td width="14%">'.$arr[$i++].'</td><td width="10%">'
                
.$arr[$i++].'</td><td width="15%">'.$arr[$i++]
                .
'</td></tr></table></td></tr></table>';

        
$this->writeHTML($htmltruefalsetruefalse'');
        
$GLOBALS['headerY'] = $this->GetY();
    }

    public function 
Footer(){
        
$this->SetY(-15);
        
$this->SetFont('adobemingstd-lighti''I'8);
        
$this->Cell(010'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0false'C'0''0false'T''M');
    }
}

$pdf = new InvoicePDF(PDF_PAGE_ORIENTATIONPDF_UNITPDF_PAGE_FORMATtrue'UTF-8'false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('One Solution');
$pdf->SetTitle('Invoice');
$pdf->SetSubject('Invoice');
$pdf->SetKeywords('oneMotor');
$pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTH'Invoice'.'''');

// set header and footer fonts
$pdf->setHeaderFont(Array('adobemingstd-lighti'''12));
$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_LEFTPDF_MARGIN_TOPPDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUEPDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// set default font subsetting mode
$pdf->setFontSubsetting(true);

// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
//$pdf->SetFont('dejavusans', '', 14, '', true);
$pdf->setFont('adobemingstd-lighti'''12);

// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();

$pdf->SetCellPadding(6);
$pdf->setPageUnit('pt');
$pdf->SetTopMargin(283);
if(
$headerY 298){
    
$pdf->SetTopMargin(283+(15*(($headerY-297.97)/15)));
}

$border0 = array(
'L' => array('width' => 1.6'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)),
'R' => array('width' => 0.8'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)));

$border1 = array(
'LB' => array('width' => 1.6'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)),
'RT' => array('width' => 0.8'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)));

$border3 = array(
'RB' => array('width' => 1.6'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)),
'T' => array('width' => 0.8'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)));

$border4 = array(
'R' => array('width' => 1.6'cap' => 'butt''join' => 'miter''dash' => 0'color' => array(000)));

$border5 = array(
'LR' => array('width' => 0.8'cap' => 'butt''join' => 'miter''dash' => 0'color' => array(000)));

$border7 = array(
'L' => array('width' => 1.6'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)),
'RB' => array('width' => 0.8'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)));

$border8 = array(
'RBL' => array('width' => 0.8'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)));

$border9 = array(
'R' => array('width' => 1.6'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)),
'LB' => array('width' => 0.8'cap' => 'square''join' => 'miter''dash' => 0'color' => array(000)));

$sql "select * from OM_INVOICE_DTL where invoiceno = $invoiceno order by lineno";
$result mysql_query($sql);
$rowCount mysql_num_rows($result);
$rowNum 0;
while (
$row mysql_fetch_assoc($result)){
    
$prodno $row['prodno'];
    
$prodname $row['prodname'];
    
$price $row['price'];
    
$qty $row['qty'];
    
$amount    $row['amount'];

    if(
$rowNum == 23){
        
$pdf->writeHTMLCell(326.621''''$prodno $prodname"$border7);
        
$pdf->writeHTMLCell(74.921''''number_format($price,2), $border8,0,false,true,'R');
        
$pdf->writeHTMLCell(53.521''''round($qty,1), $border8,0,false,true,'C');

        if(
$amount == 0.00){
            
$pdf->writeHTMLCell(80.321''''""$border9,0,false,true,'R');
        }
        else{
            
$pdf->writeHTMLCell(80.321''''number_format($amount,2), $border9,0,false,true,'R');
        }
        
$rowNum 0;
        
$pdf->AddPage();
    }
    else{
        
$pdf->writeHTMLCell(326.621''''$prodno $prodname"$border0);
        
$pdf->writeHTMLCell(74.921''''number_format($price,2), $border5,0,false,true,'R');
        
$pdf->writeHTMLCell(53.521''''round($qty,1), $border5,0,false,true,'C');

        if(
$amount == 0.00){
            
$pdf->writeHTMLCell(80.321''''""$border4,0,false,true,'R');
        }
        else{
            
$pdf->writeHTMLCell(80.321''''number_format($amount,2), $border4,0,false,true,'R');
        }
        
$pdf->Ln(21);
        
$rowNum++;
    }
    
$subamount += $amount;
}

$sql4 "select status, remarks from OM_INVOICE_HDR where invoiceno = $invoiceno";
$result4 mysql_query($sql4);
$row4 mysql_fetch_assoc($result4);
$status2 $row4['status'];
$remarks2 $row4['remarks'];

if(
$status2 == 3){
    if(
$rowNum == 23){
        
$pdf->Cell(326.621"  *** VOID ***"$border7);    
        
$pdf->Cell(74.921""$border8,0,'R');
        
$pdf->Cell(53.521""$border8,0,'C');
        
$pdf->Cell(80.321""$border9,0,'R');
        
$pdf->Ln(21);
        
$rowNum 0;
        
$pdf->AddPage();
    }
    else{
        
$pdf->Cell(326.621"  *** VOID ***"$border0);    
        
$pdf->Cell(74.921""$border5,0,'R');
        
$pdf->Cell(53.521""$border5,0,'C');
        
$pdf->Cell(80.321""$border4,0,'R');
        
$pdf->Ln(21);
        
$rowNum++;
    }
}

if(!empty(
$remarks2)){

    
$cellheight $pdf->getStringHeight(326.6" Remarks:\n".$remarks2falsetrue''$border0);
    
$cellheight += 5;

    
$pdf->MultiCell(326.6$cellheight"Remarks:\n".$remarks2$border0'L'false0);
    
$pdf->MultiCell(74.9$cellheight""$border5'R'false0);
    
$pdf->MultiCell(53.5$cellheight""$border5'R'false0);
    
$pdf->MultiCell(80.3$cellheight""$border4'R'false0);
    
$pdf->Ln($cellheight);

    
$rowNum += ceil($cellheight/21);
}

while(
$rowCount 8){
        
$pdf->Cell(326.621""$border0);    
        
$pdf->Cell(74.921""$border5,0,'R');
        
$pdf->Cell(53.521""$border5,0,'C');
        
$pdf->Cell(80.321""$border4,0,'R');
        
$pdf->Ln(21);
        
$rowCount++;
}

if((
$rowNum%24) != 0){
    
$pdf->Ln(6);
}

$arr3 = array();
$result3 mysql_query("select data from header where num >= 45 order by num");
while(
$row3 mysql_fetch_array($result3MYSQL_NUM)){
    
array_push($arr3$row3[0]);
}
$j 0;

$pdf->writeHTMLCell(45526''''end($arr3), $border10falsetrue'R');
$j++;

if(
$status2 == 3){
    
$pdf->Cell(80.326'0.00'$border3,0,'R');
}
else{
    
$pdf->Cell(80.326number_format($subamount,2), $border3,0,'R');
}
$pdf->Ln(34);

if((
$rowCount >= 19) && ($rowCount <= 23)){
    
$pdf->Ln(90);
}

$html .= '<table><tr><td width="40%">'.$arr3[$j++].'</td><td width="20%"></td><td width="40%">'.$arr3[$j++]
        .
'</td></tr><tr><td> <br />'
        
.'<br /> ';

$html .= ' <br /> <br /> </td></tr><tr><td style="height:10px;"><hr /></td><td></td><td><hr />'
        
.$arr3[$j++].'</td></tr></table>';

if(
$rowCount == 17 || $rowCount == 18){
    
$html .= '&nbsp;<br />&nbsp;<br />';
}

$html .= '<div style="font-size:70%;" >'.$arr3[$j++]."</div>";

$pdf->writeHTML($htmltruefalsetruefalse'');

ob_clean();
$pdf->Output('invoice.pdf''I');
?>