/var/www/(Del)pathways.org.hk/MIS20140127/old20140414/Receipt/receipt_Export.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
<?php 
error_reporting
(E_ALL E_NOTICE E_WARNING);
ini_set('display_errors'1);

include_once 
'../include/DBConnect.php'
include_once 
'../receipt/changemoney.php'
require_once 
'../include/Classes/PHPExcel.php' ;
require_once 
'../include/Classes/PHPExcel/IOFactory.php' ;
require_once 
'../include/Classes/PHPExcel/Writer/Excel2007.php';

$Export_id $_GET['id'];
$maxlength 50;
$payofmaxlength 160;
$name;
$money;
$payof;
$payway;
$bank_name;
$cheque_no;
$campus;
$type;
$paydate;
$loadname;
$receiptNo;

$query "Select receipt_code, receipt_date, receipt_from, payment_of, total_amount, is_cash, bank_name, cheque_code, is_normal, campus_id from receipt where deleted = 0 and receipt_id = '$Export_id'";
$result $dbh->query($query);
$result->setFetchMode(PDO::FETCH_OBJ);
while (
$row $result->fetch()) {
    
$receiptNo $row->receipt_code;
    
$paydate $row->receipt_date;
    
$name $row->receipt_from;
    
$money $row->total_amount;
    
$payof $row->payment_of;
    
$bank_name $row->bank_name;
    
$cheque_no $row->cheque_code;
    if (
$row->is_cash == 0)
        
$payway 'By cash :';
    else if (
$row->is_cash == 1)
        
$payway 'By cheque :';
    if (
$row->is_normal == 0) {
        if (
$row->campus_id == 1) {
            
$loadname 'Pathway_receipt_S.xlsx';
        } else if (
$row->campus_id == 2) {
            
$loadname 'Pathway_receipt_K.xlsx';
        }
    } else if (
$row->is_normal == 1) {
                if (
$row->campus_id == 1) {
            
$loadname 'Pathway_receipt_C_S.xlsx';
        } else if (
$row->campus_id == 2) {
            
$loadname 'Pathway_receipt_C_K.xlsx';
        }
    }
}

function 
umoney($str){
    return 
$str;
}

$PHPExcel = new PHPExcel();
$reader PHPExcel_IOFactory::createReader('Excel2007');
$PHPExcel $reader->load($loadname);
$PHPExcel->getProperties()->setCreator("Pathways");
$PHPExcel->getProperties()->setTitle("Receipt");

$PHPExcel->setActiveSheetIndex(0);
$PHPExcel->getActiveSheet()->setCellValue('B6'$name);
$fline;
$sline;
if (
strlen(umoney($money)) < $maxlength) {
    
$PHPExcel->getActiveSheet()->setCellValue('B8'umoney($money));
} elseif (
strlen(umoney($money)) > $maxlength) {
    
$string umoney($money);
    
$string wordwrap($string$maxlength);
    
$fline substr($string0strpos($string"\n"));
    
$sline substr($stringstrpos($string"\n"));
    
$PHPExcel->getActiveSheet()->setCellValue('B8'$fline);
    
$PHPExcel->getActiveSheet()->setCellValue('B9'$sline);
}
if (
$payof $payofmaxlength) {
    
$PHPExcel->getActiveSheet()->setCellValue('B10'$payof);
} elseif (
$payof $payofmaxlength) {
    
$string $payof;
    
$string wordwrap($string$payofmaxlength);
    
$fline substr($string0strpos($string"\n"));
    
$sline substr($stringstrpos($string"\n"));
    
$PHPExcel->getActiveSheet()->setCellValue('B10'$fline);
    
$PHPExcel->getActiveSheet()->setCellValue('B11'$sline);
}
$PHPExcel->getActiveSheet()->setCellValue('A11'$payway);
if (
$payway == 'By cheque :') {
    
$PHPExcel->getActiveSheet()->setCellValue('B12'$bank_name ' ' $cheque_no);
}
$PHPExcel->getActiveSheet()->setCellValue('E8'$money);
$PHPExcel->getActiveSheet()->setCellValue('E6'$paydate);
$PHPExcel->getActiveSheet()->setCellValue('E4'$receiptNo);


    
header('Content-Type: application/vnd.ms-excel');
    
header('Content-Disposition: attachment;filename="Voucher_'.$gl_transaction->voucherno.'.xls"');
    
header('Cache-Control: max-age=0');
    
$PHPExcel->setActiveSheetIndex(0);
    
$objWriter PHPExcel_IOFactory::createWriter($PHPExcel'Excel5');
    
$objWriter->save('php://output');