noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
export_fiche_balance_csv.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*!\file
00023  * \brief Called by impress->category, export in CVS the history of a category
00024  * of card
00025  */
00026 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00027 header('Pragma: public');
00028 header('Content-type: application/csv');
00029 header('Content-Disposition: attachment;filename="bal-fiche.csv"',FALSE);
00030 
00031 // Security we check if user does exist and his privilege
00032 require_once('class_user.php');
00033 require_once('class_database.php');
00034 require_once('class_dossier.php');
00035 require_once('ac_common.php');
00036 $allcard=(isset($_GET['allcard']))?1:0;
00037 
00038 /* balance */
00039 if ( $_GET['histo'] == 4 || $_GET['histo'] == 5)
00040 {
00041     $fd=new Fiche_Def($cn,$_REQUEST['cat']);
00042     if ( $allcard==1 && $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false )
00043     {
00044       exit;
00045     }
00046         // all card
00047         if ($allcard==1)
00048         {
00049                 $afiche=$cn->get_array("select fd_id from vw_fiche_def where ad_id=".ATTR_DEF_ACCOUNT." order by fd_label asc");
00050         }
00051         else
00052         {
00053                 $afiche[0]=array('fd_id'=>$_REQUEST['cat']);
00054         }
00055         printf('"Quick code";"Nom";"poste comptable";"debit";"credit";"solde";"D/C";');
00056                 printf("\n");
00057         for ($e = 0; $e < count($afiche); $e++)
00058         {
00059                 $aCard = $cn->get_array("select f_id,ad_value from fiche join fiche_Detail using (f_id)  where ad_id=1 and fd_id=$1 order by 2 ", array($afiche[$e]['fd_id']));
00060 
00061                 if (empty($aCard))
00062                 {
00063                         continue;
00064                 }
00065 
00066                 for ($i = 0; $i < count($aCard); $i++)
00067                 {
00068                         if (isDate($_REQUEST['start']) == null || isDate($_REQUEST['end']) == null)
00069                                 exit;
00070                         $filter = " (j_date >= to_date('" . $_REQUEST['start'] . "','DD.MM.YYYY') " .
00071                                         " and  j_date <= to_date('" . $_REQUEST['end'] . "','DD.MM.YYYY')) ";
00072                         $oCard = new Fiche($cn, $aCard[$i]['f_id']);
00073                         $solde = $oCard->get_solde_detail($filter);
00074                         if ($solde['debit'] == 0 && $solde['credit'] == 0)
00075                                 continue;
00076                         /* only not purged card */
00077                         if ($_GET['histo'] == 5 && $solde['solde'] == 0)
00078                                 continue;
00079                         $side = '';
00080                         if (bcsub($solde['credit'], $solde['debit']) < 0)
00081                                 $side = 'Deb.';
00082                         if (bcsub($solde['credit'], $solde['debit']) > 0)
00083                                 $side = 'Cred.';
00084 
00085                         printf('"%s";"%s";"%s";%s;%s;%s;"%s"', $oCard->strAttribut(ATTR_DEF_QUICKCODE), $oCard->strAttribut(ATTR_DEF_NAME),  $oCard->strAttribut(ATTR_DEF_ACCOUNT),nb($solde['debit']), nb($solde['credit']), nb(abs($solde['solde'])), $side);
00086                         printf("\n");
00087                 }
00088         }
00089 }
00090 else
00091 {
00092         // all card
00093         if ($allcard == 1)
00094         {
00095                 $afiche = $cn->get_array("select fd_id from vw_fiche_def where ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
00096         }
00097         else
00098         {
00099                 $afiche[0] = array('fd_id' => $_REQUEST['cat']);
00100         }
00101         $fic=new Fiche($cn);
00102         for ($e = 0; $e < count($afiche); $e++)
00103         {
00104                 $array = Fiche::get_fiche_def($cn, $afiche[$e]['fd_id'], 'name_asc');
00105 
00106                 foreach ($array as $card)
00107                 {
00108                         $row = new Fiche($cn, $card['f_id']);
00109                         $letter = new Lettering_Card($cn);
00110                         $letter->set_parameter('quick_code', $row->strAttribut(ATTR_DEF_QUICKCODE));
00111                         $letter->set_parameter('start', $_GET['start']);
00112                         $letter->set_parameter('end', $_GET['end']);
00113                         // all
00114                         if ($_GET['histo'] == 0)
00115                         {
00116                                 $letter->get_all();
00117                         }
00118 
00119                         // lettered
00120                         if ($_GET['histo'] == 1)
00121                         {
00122                                 $letter->get_letter();
00123                         }
00124                         // unlettered
00125                         if ($_GET['histo'] == 2)
00126                         {
00127                                 $letter->get_unletter();
00128                         }
00129                         if ($_GET['histo'] == 6)
00130                         {
00131                                 $letter->get_letter_diff();
00132                         }
00133                         /* skip if nothing to display */
00134                         if (count($letter->content) == 0)
00135                                 continue;
00136                         printf('"%s";"%s";"%s"'."\n",$row->strAttribut(ATTR_DEF_QUICKCODE), $row->strAttribut(ATTR_DEF_NAME),$row->strAttribut(ATTR_DEF_ACCOUNT));
00137 
00138                         printf('"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s";"%s"',
00139                                         _('Date'),
00140                                 _('ref'),
00141                                 _('Interne'),
00142                                 _('Comm'),
00143                                 _('Débit'),
00144                                 _('Crébit'),
00145                                 _('Prog.'),
00146                                 _('D/C'),
00147                                 _('Let.'),
00148                                         _("Diff Let."));
00149                         printf("\n");
00150                         $amount_deb = 0;
00151                         $amount_cred = 0;
00152                         $prog = 0;
00153                         bcscale(2);
00154                         for ($i = 0; $i < count($letter->content); $i++)
00155                         {
00156                                 $row = $letter->content[$i];
00157                                 printf ('"%s";',$row['j_date_fmt']);
00158                                 printf ('"%s";',$row['jr_pj_number']);
00159                                 printf ('"%s";',$row['jr_internal']);
00160                                 printf ('"%s";',$row['jr_comment']);
00161                                 if ($row['j_debit'] == 't')
00162                                 {
00163                                         printf("%s;",nb($row['j_montant']));
00164                                         $amount_deb=bcadd($amount_deb,$row['j_montant']);
00165                                         $prog = bcadd($prog, $row['j_montant']);
00166                                         printf (";");
00167                                 }
00168                                 else
00169                                 {
00170                                         printf(";");
00171                                         printf("%s;",nb($row['j_montant']));
00172                                         $amount_cred=bcadd($amount_cred,$row['j_montant']);
00173                                         $prog = bcsub($prog, $row['j_montant']);
00174                                 }
00175                                 printf ("%s;\"%s\";",abs(nb($prog)),$fic->get_amount_side($prog));
00176                                 if ($row['letter'] != -1)
00177                                 {
00178                                         printf('"%s";',  strtoupper(base_convert($row['letter'],10,36)));
00179                                         printf("%s",nb($row['letter_diff']));
00180                                 }
00181                                 else
00182                                         printf(";");
00183                                 printf("\n");
00184                         }
00185                         if ($prog < 0 )
00186                                 $msg="Solde Debit";
00187                         elseif ($prog>0)
00188                                 $msg="Solde Credit";
00189                         else
00190                                 $msg="soldé";
00191 
00192                         printf(';;;"%s";%s;%s;%s;"%s"',
00193                                         $msg,nb($amount_deb),nb($amount_cred),nb(abs($prog)),$fic->get_amount_side($prog));
00194                         printf("\n");
00195                 }
00196         }
00197 }
00198 exit;
00199 
00200 
 All Data Structures Namespaces Files Functions Variables Enumerations