Plugins  LAST
 All Data Structures Files Functions Variables Pages
raw.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of NOALYSS.
5  *
6  * NOALYSS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * NOALYSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NOALYSS; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 /* $Revision$ */
21 
22 // Copyright (c) 2002 Author Dany De Bontridder dany@alchimerys.be
23 
24 /*!\file
25  * \brief raw file for PDF ewa
26  */
27 //require_once('amortis_constant.php');
28 
29 $act = HtmlInput::default_value_get("act", null);
30 
31 /**
32  * export operation in CSV
33  */
34 if ($act == 'export_operation')
35 {
36  // -- parameter
37  $p_from = HtmlInput::default_value_get("p_from", null);
38  $p_to = HtmlInput::default_value_get("p_to", null);
39 
40  // -- check date
41  if ( $p_from==null || isDate($p_from)==null || $p_to == null || isDate($p_to) == null) {
42  die (_('Date invalide'));
43  }
44  // Security : filter by ledger
45  $ledger=$g_user->get_ledger_sql('ALL',3);
46 
47  // SQL stmt
48  $sql = "
49  select to_char(j_date,'DD.MM.YYYY') as str_date,
50  jrn_def_code,
51  jr_internal,
52  jr_pj_number,
53  j_poste,
54  j_qcode,
55  case when coalesce(j_text,'')='' then pcm_lib else j_text end as text,
56  j_montant,
57  case when j_debit='t' then 'D' else 'C' end as dc,
58  comptaproc.get_letter_jnt(j_id) AS lettrage
59 
60  from jrnx
61  join jrn on (j_grpt=jr_grpt_id)
62  join tmp_pcmn on j_poste=pcm_val
63  join jrn_def on jrn_def_id=jr_def_id
64  where
65  j_date between to_date($1,'DD.MM.YYYY') and to_date($2,'DD.MM.YYYY')
66  and $ledger order by j_date
67  ";
68 
69  $ret = $cn->exec_sql($sql, array($p_from, $p_to));
70  $file_name='export_operation-'.date('ymd').'.csv';
71  header('Pragma: public');
72  header('Content-type: application/csv');
73  header('Content-Disposition: attachment;filename="'.$file_name.'"', FALSE);
74  $nb=Database::num_row($ret);
75  printf('"%s";',_("Date DMY"));
76  printf('"%s";',_("Journal"));
77  printf('"%s";',_("n° interne"));
78  printf('"%s";',_("piece"));
79  printf('"%s";',_("poste"));
80  printf('"%s";',_("Code"));
81  printf('"%s";',_("texte"));
82  printf('"%s";',_("montant"));
83  printf('"%s";',_("DC"));
84  printf('"%s"',_("lettrage"));
85  printf ("\r\n");
86 
87  for ($i=0;$i < $nb;$i++)
88  {
89  $row=Database::fetch_array($ret,$i);
90  printf('"%s";',$row['str_date']);
91  printf('"%s";',$row['jrn_def_code']);
92  printf('"%s";',$row['jr_internal']);
93  printf('"%s";',$row['jr_pj_number']);
94  printf('"%s";',$row['j_poste']);
95  printf('"%s";',$row['j_qcode']);
96  printf('"%s";',$row['text']);
97  printf('%s;',nb($row['j_montant']));
98  printf('"%s";',$row['dc']);
99  printf('"%s"',$row['lettrage']);
100  printf ("\r\n");
101  }
102 }
103 /**
104  * Download receipt
105  */
106 if ($act=='download_receipt')
107 {
108  extract ($_REQUEST);
109 
110  $zip_file=HtmlInput::default_value_request('file', 'null');
111  if ($zip_file=='null')
112  {
113  die('No file asked');
114  }
115 
116  $zip_file=$_ENV['TMP']."/".$zip_file;
117 
118  header('Pragma: public');
119  header('Content-type: application/zip');
120  header('Content-Disposition: attachment; filename="'.$file.'"');
121  $h_file=fopen($zip_file, "r");
122  if ($h_file!=true)
123  {
124  die('cannot open file');
125  }
126  $buffer=fread($h_file, filesize($zip_file));
127  echo $buffer;
128 }
129 ?>
$sql
Definition: raw.php:28
$ret
for($i=0;$i< Database::num_row($ret);$i++) $row
$cn
Definition: raw.php:26
$_REQUEST['sb']
Definition: am_print.php:39
$file
Definition: import_bank.php:60
$act
Definition: raw.php:29