00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00024 $fDate = date('dmy-Hi');
00025 header('Pragma: public');
00026 header('Content-type: application/csv');
00027 header('Content-Disposition: attachment;filename="jrn-'.$fDate.'.csv"',FALSE);
00028 include_once ("ac_common.php");
00029 require_once('class_own.php');
00030 require_once 'class_acc_ledger_sold.php';
00031 require_once 'class_acc_ledger_purchase.php';
00032 require_once('class_dossier.php');
00033 $gDossier=dossier::id();
00034
00035 require_once('class_database.php');
00036 require_once("class_acc_ledger.php");
00037
00038
00039
00040
00041 $get_jrn=HtmlInput::default_value_get('jrn_id', -1);
00042 $get_option=HtmlInput::default_value_get('p_simple', -1);
00043 $get_from_periode= HtmlInput::default_value_get('from_periode', null);
00044 $get_to_periode=HtmlInput::default_value_get('to_periode', NULL);
00045
00046
00047 if ( $get_jrn ==-1 || $get_option == -1 || $get_from_periode == null || $get_to_periode == null)
00048 {
00049 die (_('Options invalides'));
00050 }
00051
00052
00053 require_once ('class_user.php');
00054 $g_user->Check();
00055 $g_user->check_dossier($gDossier);
00056
00057
00058
00059
00060
00061 if ($get_jrn!=0 && $g_user->check_jrn($get_jrn) =='X')
00062 {
00063 NoAccess();
00064 exit();
00065 }
00066
00067 $Jrn=new Acc_Ledger($cn,$get_jrn);
00068
00069 $Jrn->get_name();
00070 $jrn_type=$Jrn->get_type();
00071
00072
00073
00074
00075 if ($get_option == 2)
00076 {
00077 if ($jrn_type != 'ACH' && $jrn_type != 'VEN' || $Jrn->id == 0)
00078 {
00079 $get_option = 0;
00080 }
00081 else
00082 {
00083 switch ($jrn_type)
00084 {
00085 case 'VEN':
00086 $ledger = new Acc_Ledger_Sold($cn, $get_jrn);
00087 $ret_detail = $ledger->get_detail_sale($get_from_periode, $get_to_periode);
00088 $a_heading= Acc_Ledger_Sold::heading_detail_sale();
00089
00090 break;
00091 case 'ACH':
00092 $ledger = new Acc_Ledger_Purchase($cn, $get_jrn);
00093 $ret_detail = $ledger->get_detail_purchase($get_from_periode, $get_to_periode);
00094 $a_heading= Acc_Ledger_Purchase::heading_detail_purchase();
00095 break;
00096 default:
00097 die(__FILE__ . ":" . __LINE__ . 'Journal invalide');
00098 break;
00099 }
00100 if ($ret_detail == null)
00101 return;
00102 $nb = Database::num_row($ret_detail);
00103 $output=fopen("php://output","w");
00104
00105 for ($i = 0;$i < $nb ; $i++) {
00106 $row=Database::fetch_array($ret_detail, $i);
00107 if ( $i == 0 ) {
00108 fputcsv($output,$a_heading,';');
00109 }
00110 $a_row=array();
00111 for ($j=0;$j < count($row) / 2;$j++) {
00112 $a_row[]=$row[$j];
00113 }
00114 fputcsv($output,$a_row,';');
00115 unset($a_row);
00116 }
00117 }
00118 }
00119
00120
00121
00122
00123 if ( $get_option == 0 )
00124 {
00125 $Jrn->get_row( $get_from_periode, $get_to_periode );
00126
00127 if ( count($Jrn->row) == 0)
00128 exit;
00129 foreach ( $Jrn->row as $op )
00130 {
00131
00132 $desc=$op['description'];
00133 $desc=str_replace("<b>","",$desc);
00134 $desc=str_replace("</b>","",$desc);
00135 $desc=str_replace("<i>","",$desc);
00136 $desc=str_replace("</i>","",$desc);
00137 $desc=str_replace('"',"'",$desc);
00138 $desc=str_replace(";",",",$desc);
00139
00140 printf("\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";%s;%s\n",
00141 $op['j_id'],
00142 $op['jr_pj_number'],
00143 $op['internal'],
00144 $op['j_date'],
00145 $op['poste'],
00146 $desc,
00147 nb($op['deb_montant']),
00148 nb($op['cred_montant'])
00149 );
00150
00151 }
00152 exit;
00153 }
00154
00155
00156
00157
00158
00159 if ($get_option == 1)
00160 {
00161
00162
00163 if ( $jrn_type == 'ODS' || $jrn_type == 'FIN' || $jrn_type=='GL')
00164 {
00165 $Row=$Jrn->get_rowSimple($get_from_periode,
00166 $get_to_periode,
00167 0);
00168 printf ('" operation";'.
00169 '"Date";'.
00170 '"N° Pièce";'.
00171 '"Tiers";'.
00172 '"commentaire";'.
00173 '"internal";'.
00174 '"montant";'.
00175 "\r\n");
00176 foreach ($Row as $line)
00177 {
00178
00179 echo $line['num'].";";
00180 echo $line['date'].";";
00181 echo $line['jr_pj_number'].";";
00182 echo $Jrn->get_tiers($line['jrn_def_type'],$line['jr_id']).";";
00183 echo $line['comment'].";";
00184 echo $line['jr_internal'].";";
00185
00186
00187
00188
00189 if ( $line['jrn_def_type'] == 'FIN' ) {
00190 $positive = $cn->get_value("select qf_amount from quant_fin ".
00191 " where jr_id=".$line['jr_id']);
00192
00193 echo nb($positive);
00194 echo ";";
00195 }
00196 else
00197 {
00198 echo nb($line['montant']).";";
00199 }
00200
00201 printf("\r\n");
00202 }
00203 }
00204
00205
00206
00207
00208
00209 if ( $jrn_type=='ACH' || $jrn_type=='VEN')
00210 {
00211 $Row=$Jrn->get_rowSimple($get_from_periode,
00212 $get_to_periode,
00213 0);
00214 $cn->prepare('reconcile_date',"select to_char(jr_date,'DD.MM.YY') as str_date,* "
00215 . "from jrn "
00216 . "where "
00217 . "jr_id in (select jra_concerned from jrn_rapt where jr_id = $1 union all select jr_id from jrn_rapt where jra_concerned=$1)");
00218
00219 $own=new Own($cn);
00220 $col_tva="";
00221
00222 if ( $own->MY_TVA_USE=='Y')
00223 {
00224 $a_Tva=$cn->get_array("select tva_id,tva_label from tva_rate order by tva_rate,tva_label,tva_id");
00225 foreach($a_Tva as $line_tva)
00226 {
00227 $col_tva.='"Tva '.$line_tva['tva_label'].'";';
00228 }
00229 }
00230 echo '"Date";"Paiement";"operation";"Pièce";"Client/Fourn.";"Commentaire";"inter.";"HTVA";"privé";"DNA";"tva non ded.";"TVA NP";'.$col_tva.'"TVAC";"opérations liées"'."\n\r";
00231 foreach ($Row as $line)
00232 {
00233 printf('"%s";"%s";"%s";"%s";"%s";%s;%s;%s;%s;%s;%s;%s;',
00234 $line['date'],
00235 $line['date_paid'],
00236 $line['num'],
00237 $line['jr_pj_number'],
00238 $Jrn->get_tiers($line['jrn_def_type'],$line['jr_id']),
00239 $line['comment'],
00240 $line['jr_internal'],
00241 nb($line['HTVA']),
00242 nb($line['dep_priv']),
00243 nb($line['dna']),
00244 nb($line['tva_dna']),
00245 nb($line['tva_np'])
00246 );
00247 $a_tva_amount=array();
00248
00249 foreach ($a_Tva as $l) {
00250 $t_id=$l["tva_id"];
00251 $a_tva_amount[$t_id]=0;
00252 }
00253 foreach ($line['TVA'] as $lineTVA)
00254 {
00255 $idx_tva=$lineTVA[1][0];
00256 $a_tva_amount[$idx_tva]=$lineTVA[1][2];
00257 }
00258 if ($own->MY_TVA_USE == 'Y' )
00259 {
00260 foreach ($a_Tva as $line_tva)
00261 {
00262 $a=$line_tva['tva_id'];
00263 echo nb($a_tva_amount[$a]).';';
00264 }
00265 }
00266 echo nb ($line['TVAC']);
00267
00268
00269
00270 $ret_reconcile=$cn->execute('reconcile_date',array($line['jr_id']));
00271 $max=Database::num_row($ret_reconcile);
00272 if ($max > 0) {
00273 $sep=";";
00274 for ($e=0;$e<$max;$e++) {
00275 $row=Database::fetch_array($ret_reconcile, $e);
00276 echo $sep.$row['str_date'].'; '. $row['jr_internal'];
00277 }
00278 }
00279 printf("\r\n");
00280
00281 }
00282 }
00283 }
00284 ?>