/var/www/enzatesting.onesolution.hk/01_20240711_full_backup/xls_cncus_template2.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
<?php
$formid 
"Order";
require_once 
"inc/configure.php";
require_once 
"inc/phpexcel_1.7.7/PHPExcel.php";
require_once 
"inc/ord_cn_func.php";


if(
havePermission("GNr")==false
|| havePermission("DPr")==false
//|| havePermission("MDr")==false
//|| havePermission("TDr")==false
){

    
myerror("Invalid Permission");
}


//----------FUNCTIONS-------

function getProduct($cncus_refid){
    global 
$dbh;
    
$result = array();
    
$sql "SELECT
            dbo.cn_cusmain_dtl.cncusmain_refid,
            dbo.cn_cusmain_dtl.qty,
            dbo.cn_cusmain_dtl.wt,
            dbo.cn_cusmain_dtl.uom_wt
            dbo.cn_cusmain_dtl.unitprice,
            dbo.inv_product.itemno,
            dbo.inv_product.name_en,
            dbo.inv_product.name_sc
            FROM
            dbo.cn_cusmain_dtl
            INNER JOIN dbo.inv_product ON dbo_inv_Product. refid = dbo.cn_cusmain_dtl.product_refid
            WHERE
            dbo.cn_cusmain_dtl.cncusmain_refid = :cncus_refid
            ORDER BY
            dbo.cn_cusmain_dtl.qty DESC"
;

   
$sth $dbh->prepare($sql);
   
$sth->execute( array(':cncus_refid' => $cncus_refid) );

   
$i 0;
   while(
$row $sth->fetch()){
   
$result[$i]['itemno'] = $row['itemno'];
   
$result[$i]['desc'] = $row['desc'];
   
$result[$i]['qty'] = $row['qty'];
   
$result[$i]['unitprice'] = $row['unitprice'];
   
$result[$i]['wt'] = $row['wt'];
   
$result[$i]['uom_wt'] = $row['uom_wt'];
   
$result[$i]['amount'] = numf($row['qty'] * numf($row['unitprice']), );
   } 
}

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'];
}

/*--------------------------------END OF FUNCTIONS--------------------------------------*/

$refid setDefaultReqVar("refid"'');

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

if($refid){
    
$sql "SELECT * from cn_cus_main WHERE refid = :refid";
    
$sth $dbh->prepare($sql);
    
$sth->execute(  array(':refid' => $refid) );
} else {
    exit;
}
$row $sth->fetch();
$header $row;
$customer getDB_master_customer($row['cn_customer']);
unset(
$sth);

@
set_time_limit(0);
//ini_set('max_execution_time', '999');
ini_set('post_max_size''10M');
ini_set('memory_limit','1024M');

$objPHPexcel PHPExcel_IOFactory::load('templates/cncus_template_enza.xls');

$objWorksheet $objPHPexcel->getSheetByName('Invoice');

$default_rowh 16;//16pt~21pixel
/*
#company_name        A5
#company_address    A6


#launch_date            H4
#invoice_nbr            H5
*/
$objWorksheet->getCell('A5')->setValuehtml_entity_decode($customer['companyname_en'], ENT_QUOTES) );
$objWorksheet->getCell('A6')->setValuehtml_entity_decode(buildAddressFormat($customer['invaddr1'], $customer['invpostcode'], $customer['invcity'], $customer['invcountry'], $customer['invtelno'], $customer['invfaxno']), ENT_QUOTES) );

$objWorksheet->getCell('H4')->setValuedate_format(date_create($row['launch_date']), 'l, F d, Y') );
$objWorksheet->getCell('H5')->setValue$row['cn_nbr'] );

$excel_row=12;




//exit;
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="CreditNote_'.$header['cn_nbr'].'.xls"');
header('Cache-Control: max-age=0');

$objPHPexcel->setActiveSheetIndex(0);
$objWriter PHPExcel_IOFactory::createWriter($objPHPexcel'Excel5');
$objWriter->save('php://output');

//$objWriter = new PHPExcel_Writer_PDF($objPHPexcel);
//$objWriter->save("test.pdf");

flush();
?>