@@ -16,6 +16,65 @@ public function action_index()
16
16
xml::to_XML (Transactions::get (NULL , 'IF(transfer_date = 0,1,0),transfer_date; ' , NULL , TRUE ), $ accounting_node , 'entry ' , 'id ' );
17
17
}
18
18
19
+ public function action_dlvouchers ()
20
+ {
21
+ set_time_limit (0 );
22
+ $ files = array ();
23
+
24
+ /** /
25
+ if (date('m') < 4) $quarter = 1;
26
+ elseif (date('m') < 7) $quarter = 2;
27
+ elseif (date('m') < 10) $quarter = 3;
28
+ else $quarter = 4;
29
+
30
+ if ($quarter == 1) $year = intval(date('Y') - 1);
31
+ else $year = intval(date('Y'));
32
+
33
+ $where = 'YEAR(accounting_date) = '.$year.' AND MONTH(accounting_date) BETWEEN ';
34
+
35
+ if ($quarter == 1) $where .= '10 AND 12';
36
+ elseif ($quarter == 2) $where .= '1 AND 3';
37
+ elseif ($quarter == 3) $where .= '4 AND 6';
38
+ elseif ($quarter == 4) $where .= '7 AND 9';
39
+ /**/
40
+
41
+ if ( ! isset ($ _GET ['from_date ' ])) $ _GET ['from_date ' ] = '1970-01-01 ' ;
42
+ if ( ! isset ($ _GET ['to_date ' ])) $ _GET ['to_date ' ] = date ('Y-m-d ' );
43
+
44
+ $ from_date = date ('Y-m-d ' , strtotime ($ _GET ['from_date ' ]));
45
+ $ to_date = date ('Y-m-d ' , strtotime ($ _GET ['to_date ' ]));
46
+
47
+ $ where = 'transfer_date >= \'' .$ from_date .'\' AND transfer_date <= \'' .$ to_date .'\'' ;
48
+
49
+ foreach (Transactions::get (NULL , 'IF(transfer_date = 0,1,0),transfer_date; ' , $ where , TRUE ) as $ transaction )
50
+ if ( ! empty ($ transaction ['vouchers ' ]))
51
+ foreach ($ transaction ['vouchers ' ] as $ voucher_file )
52
+ $ files [date ('Y-m-d ' , strtotime ($ transaction ['transfer_date ' ]))][] = APPPATH .'user_content/vouchers/ ' .$ transaction ['id ' ].'/ ' .$ voucher_file ;
53
+
54
+ if (count ($ files ))
55
+ {
56
+ $ zipname = APPPATH .'user_content/ ' .$ from_date .'_-_ ' .$ to_date .'_vouchers.zip ' ;
57
+ $ zip = new ZipArchive ;
58
+ if ($ zip ->open ($ zipname , ZIPARCHIVE ::CREATE | ZIPARCHIVE ::OVERWRITE ) === TRUE )
59
+ {
60
+ foreach ($ files as $ date => $ files )
61
+ foreach ($ files as $ file )
62
+ if (file_exists ($ file ))
63
+ $ zip ->addFile ($ file , $ date .' - ' .pathinfo ($ file , PATHINFO_BASENAME ));
64
+
65
+ $ zip ->close ();
66
+
67
+ header ('Content-Type: application/zip ' );
68
+ header ('Content-disposition: attachment; filename= ' .pathinfo ($ zipname , PATHINFO_BASENAME ));
69
+ header ('Content-Length: ' .filesize ($ zipname ));
70
+ echo file_get_contents ($ zipname );
71
+ unlink ($ zipname );
72
+ die ();
73
+ } else die ('error opening ziparchive ' );
74
+ }
75
+ else die ('no vouchers found ' );
76
+ }
77
+
19
78
public function action_entry ()
20
79
{
21
80
// Set employees node
0 commit comments