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

$invoiceno $_GET['invoiceno'];

class 
InvoicePDF extends TCPDF{

    public function 
Header(){
    
        
$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]);
        }
        
$i 0;
        
        
$html '<h1 style="margin-bottom: 0px; margin-top: 0px; text-align: center; font-size: 170%;">'
                
.$arr[$i++].'<br />'.$arr[$i++].'</h1><div  style="text-align:center; font-size: 80%; margin-top: 0px;">'
                
.$arr[$i++].'<br />'.$arr[$i++].'<br />'.$arr[$i++].'</div>';
                
        
$i++;
            
        
$html .= '<br /><table><tr><td rowspan="2" width="65%" style="text-align:right; vertical-align:text-bottom;"><h1>'
                
.$arr[25].'</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="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>';
        
$html .= '<table border="1" style="text-align: center;" cellpadding="4"><tr><td style="vertical-align:middle" width="55%">'.$arr[$i++]
                .
'</td><td width="15%">'.$arr[$i++].'</td><td width="12%">'
                
.$arr[$i++].'</td><td width="18%">'.$arr[$i++]
                .
'</td></tr></table>';
                
        
$this->writeHTML($htmltruefalsetruefalse'');
    }
    
    public function 
Footer(){
        
// Position at 15 mm from bottom
        
$this->SetY(-15);
        
// Set font
        
$this->SetFont('adobemingstd-lighti''I'8);
        
// Page number
        
$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('Man Fok');
$pdf->SetTitle('Invoice');
$pdf->SetSubject('Invoice');
$pdf->SetKeywords('One Solution, oneMotor');

$pdf->SetHeaderData(PDF_HEADER_LOGOPDF_HEADER_LOGO_WIDTH'Invoice'.'''');

// set header and footer fonts
//$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$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();

$html '<table border="1" cellpadding="4">';

$sql "select * from OM_INVOICE_DTL
        where invoiceno = 
$invoiceno 
        order by lineno"
;
        
$result mysql_query($sql);

$rowCount mysql_num_rows($result);

while (
$row mysql_fetch_assoc($result)){

    
$prodno $row['prodno'];
    
$prodname $row['prodname'];
    
$price $row['price'];
    
$qty $row['qty'];
    
$amount    $row['amount'];
    
    
$html .= '<tr><td style="vertical-align:middle" width="55%">&nbsp;'.$prodno.' '.$prodname.'</td><td width="15%" style="text-align: center;">'
            
.number_format($price,2).'</td><td width="12%" style="text-align: center;">'.round($qty,0).' '.$uom
            
.'</td><td width="18%" style="text-align: center;">'
            
.number_format($amount,2).'</td></tr>';

    
$subamount += $amount;
}

while(
$rowCount 8){
    
        
$html .= "<tr><td></td><td></td><td></td><td></td></tr>";
        
$rowCount++;
}

$result3 mysql_query("select data from header where num >= 45 order by num");

$arr3 = array();
while(
$row3 mysql_fetch_array($result3MYSQL_NUM)){
    
array_push($arr3$row3[0]);
}
$j 0;

$html .= '<tr><td></td><td colspan="2" style="text-align: right; vertical-align:middle">'
        
.$arr3[$j++].'&nbsp;</td><td style="text-align: center;">'.number_format($subamount,2).'</td></tr></table><br />';
        
$html .= '<table><tr><td width="40%">'.$arr3[$j++].'</td><td width="20%"></td><td width="40%">'.$arr3[$j++]
        .
'</td></tr><tr><td> <br /> <br /> <br /> <br /> <br /> <br /> </td></tr><tr><td style="height:60px;"><hr /></td><td></td><td><hr />'
        
.$arr3[$j++].'</td></tr></table>';
        
$html .= $arr3[$j++];

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

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