noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
fiche.inc.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  *   This file is part of NOALYSS.
00005  *
00006  *   NOALYSS is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   NOALYSS is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with NOALYSS; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 /**\file
00022  * \brief printing of category of card  : balance, historic
00023  */
00024 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00025 include_once('class_database.php');
00026 include_once('class_fiche.php');
00027 require_once('class_lettering.php');
00028 
00029 $gDossier = dossier::id();
00030 $cn = new Database($gDossier);
00031 global $g_user, $g_failed;
00032 ;
00033 
00034 /**
00035  * Show first the form
00036  */
00037 /* category */
00038 $categorie = new ISelect('cat');
00039 $categorie->value = $cn->make_array('select fd_id,fd_label from fiche_def order by fd_label');
00040 $categorie->selected = (isset($_GET['cat'])) ? $_GET['cat'] : 0;
00041 $str_categorie = $categorie->input();
00042 
00043 $icall = new ICheckBox("allcard", 1);
00044 $icall->selected = (isset($_GET['allcard'])) ? 1 : 0;
00045 $str_icall = $icall->input();
00046 /* periode */
00047 $exercice = $g_user->get_exercice();
00048 $iperiode = new Periode($cn);
00049 list ($first, $last) = $iperiode->get_limit($exercice);
00050 
00051 $periode_start = new IDate('start');
00052 $periode_end = new IDate('end');
00053 
00054 $periode_start->value = (isset($_GET['start'])) ? $_GET['start'] : $first->first_day();
00055 $periode_end->value = (isset($_GET['end'])) ? $_GET['end'] : $last->last_day();
00056 
00057 $str_start = $periode_start->input();
00058 $str_end = $periode_end->input();
00059 
00060 /* histo ou summary */
00061 $histo = new ISelect('histo');
00062 $histo->value = array(
00063         array('value' => -1, 'label' => _('Liste')),
00064         array('value' => 0, 'label' => _('Historique')),
00065         array('value' => 1, 'label' => _('Historique Lettré')),
00066         array('value' => 6, 'label' => _('Historique Lettré et montants différents')),
00067         array('value' => 2, 'label' => _('Historique non Lettré')),
00068         array('value' => 3, 'label' => _('Résumé')),
00069         array('value' => 4, 'label' => _('Balance')),
00070         array('value' => 5, 'label' => _('Balance non soldée'))
00071 );
00072 $histo->javascript = 'onchange="if (this.value==3 || this.value==-1) {
00073                    g(&quot;trstart&quot;).style.display=&quot;none&quot;;g(&quot;trend&quot;).style.display=&quot;none&quot;;g(&quot;allcard&quot;).style.display=&quot;none&quot;;}
00074                    else  {g(&quot;trstart&quot;).style.display=&quot;&quot;;g(&quot;trend&quot;).style.display=&quot;&quot;;g(&quot;allcard&quot;).style.display=&quot;&quot;;}"';
00075 
00076 $histo->selected = (isset($_GET['histo'])) ? $_GET['histo'] : -1;
00077 $str_histo = $histo->input();
00078 echo '<div class="content">';
00079 echo '<FORM method="GET">';
00080 echo dossier::hidden();
00081 echo HtmlInput::hidden('ac', $_GET['ac']);
00082 require_once('template/impress_cat_card.php');
00083 echo HtmlInput::submit('cat_display', _('Recherche'));
00084 echo '</FORM>';
00085 $search_card=new IText('card_search');
00086 $search_card_js=sprintf('onclick="boxsearch_card(\'%d\')"',dossier::id());
00087 ?>
00088 <div id="box_search_card">
00089 
00090                 <?php echo _('Recherche de fiche')?> <?php echo HtmlInput::infobulle(18)?> :<?php echo $search_card->input()?>
00091                 <?php echo HtmlInput::button_anchor("Chercher","javascript:void(0)","",$search_card_js)?>
00092 </div>
00093 <?php
00094 echo '</div>';
00095 $str = "if (g('histo').value==3 || g('histo').value== -1 ) {
00096      g('trstart').style.display='none';g('trend').style.display='none';g('allcard').style.display='none';}
00097      else  {g('trstart').style.display='';g('trend').style.display='';g('allcard').style.display='';}
00098          if (  g('histo').value== -1 ) { g('allcard').style.display='';}
00099 
00100         ";
00101 echo create_script($str);
00102 echo '<hr>';
00103 
00104 //-----------------------------------------------------
00105 if (!isset($_GET['cat_display']))
00106         exit();
00107 
00108 $fd_id = $_GET['cat'];
00109 
00110 $array = Fiche::get_fiche_def($cn, $_GET['cat'], 'name_asc');
00111 
00112 $h_add_card_b = new IButton('add_card');
00113 $h_add_card_b->label = _('Créer une nouvelle fiche');
00114 $h_add_card_b->javascript = "dis_blank_card({gDossier:$gDossier,fd_id:$fd_id,ref:2})";
00115 $str_add_card = ($g_user->check_action(FICADD) == 1) ? $h_add_card_b->input() : "";
00116 
00117 /*
00118  * You show now the result
00119  */
00120 if ($array == null)
00121 {
00122         echo '<div class="content">';
00123         echo '<h2 class="info2"> Aucune fiche trouvée</h2>';
00124         echo $str_add_card;
00125         echo '</div>';
00126         exit();
00127 }
00128 
00129 $allcard = (isset($_GET['allcard'])) ? 1 : 0;
00130 if ( $allcard == 0 ){
00131         $fiche_def=new Fiche_Def($cn,$_GET['cat']);
00132         $fiche_def->get();
00133         echo h1($fiche_def->label,"");
00134         echo h2($fiche_def->fd_description,"");
00135 }
00136 /* * *********************************************************************************************************************************
00137  * Liste
00138  *
00139  * ******************************************************************************************************************************** */
00140 if ($_GET['histo'] == -1)
00141 {
00142         $write = $g_user->check_action(FICADD);
00143         /**
00144          * If ask for move or delete
00145          */
00146         if (isset($_POST['action']))
00147         {
00148                 if ($write == 1)
00149                 {
00150                         $ack = $_POST['f_id'];
00151                         /**
00152                          * Move
00153                          */
00154                         if (isset($_POST['move']))
00155                         {
00156                                 for ($i = 0; $i < count($ack); $i++)
00157                                 {
00158                                         $fiche = new Fiche($cn, $ack[$i]);
00159                                         $fiche->move_to($_POST['move_to']);
00160                                 }
00161                         }
00162                         /**
00163                          * Delete
00164                          */
00165                         if (isset($_POST['delete']))
00166                         {
00167                                 $msg="";
00168                                 for ($i = 0; $i < count($ack); $i++)
00169                                 {
00170                                         $fiche = new Fiche($cn, $ack[$i]);
00171                                         if ( $fiche->remove(true) == 1 )
00172                                         {
00173                                                 $msg.="\n ".$fiche->strAttribut(ATTR_DEF_QUICKCODE);
00174                                         }
00175                                 }
00176                                 if ($msg != "")
00177                                 {
00178                                         echo '<div class="content">';   
00179                                         echo h2(_("Fiche non effacées"), ' class="error"  ');
00180                                         echo '<p class="error">'._(" Ces fiches n'ont pas été effacées  ").$msg;
00181                                         echo '</div>';
00182                                 }
00183                         }
00184                 }
00185                 else
00186                 {
00187                         echo NoAccess();
00188                 }
00189         }
00190         $sql = "select f_id from fiche ";
00191         if ($allcard == 1)
00192         {
00193                 $cond = "";
00194         }
00195         else
00196         {
00197                 $cond = " where f.fd_id = " . sql_string($_GET['cat']);
00198         }
00199         // Create nav bar
00200         $max = $cn->get_value("select count(*) from fiche as f " . $cond);
00201 
00202         $step = $_SESSION['g_pagesize'];
00203         $page = (isset($_GET['offset'])) ? $_GET['page'] : 1;
00204         $offset = (isset($_GET['offset'])) ? $_GET['offset'] : 0;
00205         $bar = navigation_bar($offset, $max, $step, $page);
00206         $limit = ($step == -1 ) ? "" : " limit " . $step;
00207         $res = $cn->exec_sql("
00208                 select f_id,
00209                         (select ad_value from fiche_detail as fd1 where ad_id=1 and fd1.f_id=f.f_id) as name,
00210                         (select ad_value from fiche_detail as fd1 where ad_id=23 and fd1.f_id=f.f_id) as qcode,
00211                         fd_label,
00212                         (select ad_value from fiche_detail as fd1 where ad_id=5 and fd1.f_id=f.f_id) as poste
00213                 from fiche as f join fiche_def as fd on (fd.fd_id=f.fd_id)
00214                 $cond   order by 2,4 offset $offset $limit
00215         ");
00216         $nb_line = Database::num_row($res);
00217         if ($write != 1 || $allcard != 0 )  $str_add_card="";
00218 
00219         require_once 'template/fiche_list.php';
00220         echo '<hr>'.$bar;
00221         exit();
00222 }
00223 /* * *********************************************************************************************************************************
00224  * Summary
00225  *
00226  * ******************************************************************************************************************************** */
00227 if ($_GET['histo'] == 3)
00228 {
00229         $cat_card = new Fiche_Def($cn);
00230         $cat_card->id = $_GET['cat'];
00231         $aHeading = $cat_card->getAttribut();
00232         if ( $allcard == 0) echo $str_add_card;
00233         require_once('template/result_cat_card_summary.php');
00234 
00235         $hid = new IHidden();
00236         echo '<form method="GET" ACTION="export.php">' . dossier::hidden() .
00237         HtmlInput::submit('bt_csv', "Export CSV") .
00238         HtmlInput::hidden('act', "CSV:fiche") .
00239         $hid->input("type", "fiche") .
00240         $hid->input("ac", $_REQUEST['ac']) .
00241         $hid->input("fd_id", $_REQUEST['cat']);
00242         echo "</form>";
00243 
00244         exit();
00245 }
00246 $export_pdf = '<FORM METHOD="get" ACTION="export.php" style="display:inline">';
00247 $export_pdf.=HtmlInput::hidden('cat', $_GET['cat']);
00248 $export_pdf.=HtmlInput::hidden('act', "PDF:fiche_balance") .
00249                 $export_pdf.=HtmlInput::hidden('start', $_GET['start']);
00250 $export_pdf.=HtmlInput::hidden('end', $_GET['end']);
00251 $export_pdf.=HtmlInput::hidden('histo', $_GET['histo']);
00252 $export_pdf.=HtmlInput::request_to_hidden(array('allcard'));
00253 $export_pdf.=dossier::hidden();
00254 $export_pdf.=HtmlInput::submit('pdf', 'Export en PDF');
00255 $export_pdf.='</FORM>';
00256 
00257 $export_print = HtmlInput::print_window();
00258 
00259 $export_csv = '<FORM METHOD="get" ACTION="export.php" style="display:inline">';
00260 $export_csv.=HtmlInput::hidden('cat', $_GET['cat']);
00261 $export_csv.=HtmlInput::hidden('act', 'CSV:fiche_balance');
00262 $export_csv.=HtmlInput::hidden('start', $_GET['start']);
00263 $export_csv.=HtmlInput::hidden('end', $_GET['end']);
00264 $export_csv.=HtmlInput::hidden('histo', $_GET['histo']);
00265 $export_csv.=HtmlInput::request_to_hidden(array('allcard'));
00266 $export_csv.=dossier::hidden();
00267 $export_csv.=HtmlInput::submit('CSV', 'Export en CSV');
00268 $export_csv.='</FORM>';
00269 
00270 /********************************************************************************************************************************
00271  * Balance
00272  *
00273  **********************************************************************************************************************************/
00274 if ($_GET['histo'] == 4 || $_GET['histo'] == 5)
00275 {
00276         if (isDate($_REQUEST['start']) == null || isDate($_REQUEST['end']) == null)
00277         {
00278                 echo h2('Date invalide !', 'class="error"');
00279                 alert('Date invalide !');
00280                 exit;
00281         }
00282         if ( $allcard == 0 ) echo $str_add_card;
00283         echo $export_pdf;
00284         echo $export_csv;
00285         echo $export_print;
00286 
00287         $fd = new Fiche_Def($cn, $_REQUEST['cat']);
00288         if ($allcard == 0 && $fd->hasAttribute(ATTR_DEF_ACCOUNT) == false)
00289         {
00290                 echo alert("Cette catégorie n'ayant pas de poste comptable n'a pas de balance");
00291                 exit;
00292         }
00293         // all card
00294         if ($allcard == 1)
00295         {
00296                 $afiche = $cn->get_array("select fd_id from vw_fiche_def where ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
00297         }
00298         else
00299         {
00300                 $afiche[0] = array('fd_id' => $_REQUEST['cat']);
00301         }
00302 
00303         for ($e = 0; $e < count($afiche); $e++)
00304         {
00305                 $ret = $cn->exec_sql("select f_id,ad_value from fiche join fiche_detail using(f_id) where fd_id=$1 and ad_id=1 order by 2 ", array($afiche[$e]['fd_id']));
00306                 if ($cn->count() == 0)
00307                 {
00308                         if ($allcard == 0)
00309                         {
00310                                 echo _("Aucune fiche trouvée");
00311                                 exit;
00312                         } else
00313                                 continue;
00314                 }
00315                 echo '<h2>' . $cn->get_value("select fd_label from fiche_def where fd_id=$1", array($afiche[$e]['fd_id'])) . '</h2>';
00316                 $id="table_".$afiche[$e]."_id";
00317                 echo _('Filtre rapide:').HtmlInput::filter_table($id, '0,1,2', '1'); 
00318                 echo '<table class="sortable" id="'.$id.'" class="result" style="width:80%;margin-left:10%">';
00319                 echo tr(
00320                                 th('Quick Code') .
00321                                 th('Libellé') .
00322                                 '<th>Poste'.HtmlInput::infobulle(27).'</th>'.
00323                                 th('Débit', 'style="text-align:right"') .
00324                                 th('Crédit', 'style="text-align:right"') .
00325                                 th('Solde', 'style="text-align:right"') .
00326                                 th('D/C', 'style="text-align:right"')
00327                 );
00328                 $idx = 0;$sum_deb=0;$sum_cred=0;$sum_solde=0;bcscale(4);
00329                 for ($i = 0; $i < Database::num_row($ret); $i++)
00330                 {
00331                         $filter = " (j_date >= to_date('" . $_REQUEST['start'] . "','DD.MM.YYYY') " .
00332                                         " and  j_date <= to_date('" . $_REQUEST['end'] . "','DD.MM.YYYY')) ";
00333                         $aCard = Database::fetch_array($ret, $i);
00334                         $oCard = new Fiche($cn, $aCard['f_id']);
00335                         $solde = $oCard->get_solde_detail($filter);
00336                         if ($solde['debit'] == 0 && $solde['credit'] == 0)
00337                                 continue;
00338                         /* only not purged card */
00339                         if ($_GET['histo'] == 5 && $solde['debit'] == $solde['credit'])
00340                                 continue;
00341                         $class =($idx % 2 == 0) ?  'class="odd"':'class="even"';
00342                         $idx++;
00343                         $sum_cred=bcadd($sum_cred,$solde['credit']);
00344                         $sum_deb=bcadd($sum_deb,$solde['debit']);
00345                         $sum_solde=bcsub($sum_deb,$sum_cred);
00346                         echo tr(
00347                                         td(HtmlInput::history_card($oCard->id, $oCard->strAttribut(ATTR_DEF_QUICKCODE))) .
00348                                         td($oCard->strAttribut(ATTR_DEF_NAME)) .
00349                                         td($oCard->strAttribut(ATTR_DEF_ACCOUNT)).
00350                                         td(nbm($solde['debit']), 'class="sorttable_numeric" sorttable_customkey="'.$solde['debit'].'" style="text-align:right"') .
00351                                         td(nbm($solde['credit']), 'class="sorttable_numeric" sorttable_customkey="'.$solde['debit'].'" style="text-align:right"') .
00352                                         td(nbm(abs($solde['solde'])), 'class="sorttable_numeric" sorttable_customkey="'.$solde['solde'].'" style="text-align:right"') .
00353                                         td((($solde['debit'] < $solde['credit']) ? 'CRED' : 'DEB'), 'style="text-align:right"'), $class
00354                         );
00355 
00356 
00357 
00358                 }
00359                 echo '<tfoot>';
00360                 echo tr(
00361                                 td('').
00362                                 td(_('Totaux')).
00363                                 td('').
00364                                 td(nbm($sum_deb), 'style="text-align:right"').
00365                                 td(nbm($sum_cred), 'style="text-align:right"').
00366                                 td(nbm(abs($sum_solde)), 'style="text-align:right"').
00367                                 td((($sum_deb < $sum_cred) ? 'CRED' : 'DEB'), 'style="text-align:right"'),"");
00368                 echo '</tfoot>';
00369                 echo '</table>';
00370         }
00371         if ( $allcard == 0 ) echo $str_add_card;
00372         echo $export_pdf;
00373         echo $export_csv;
00374         echo $export_print;
00375 
00376         exit();
00377 }
00378 if (isDate($_REQUEST['start']) == null || isDate($_REQUEST['end']) == null)
00379 {
00380         echo h2('Date invalide !', 'class="error"');
00381         alert('Date invalide !');
00382         exit;
00383 }
00384 /***********************************************************************************************************************************
00385  * Lettering
00386  *
00387  **********************************************************************************************************************************/
00388 // all card
00389 if ($allcard == 1)
00390 {
00391         $afiche = $cn->get_array("select fd_id from vw_fiche_def where ad_id=" . ATTR_DEF_ACCOUNT . " order by fd_label asc");
00392 }
00393 else
00394 {
00395         $afiche[0] = array('fd_id' => $_REQUEST['cat']);
00396 }
00397 if ( $allcard == 0) echo $str_add_card;
00398 echo $export_csv;
00399 echo $export_pdf;
00400 echo $export_print;
00401 $fiche = new Fiche($cn);
00402 for ($e = 0; $e < count($afiche); $e++)
00403 {
00404         $array = Fiche::get_fiche_def($cn, $afiche[$e]['fd_id'], 'name_asc');
00405 
00406         foreach ($array as $card)
00407         {
00408                 $row = new Fiche($cn, $card['f_id']);
00409                 $letter = new Lettering_Card($cn);
00410                 $letter->set_parameter('quick_code', $row->strAttribut(ATTR_DEF_QUICKCODE));
00411                 $letter->set_parameter('start', $_GET['start']);
00412                 $letter->set_parameter('end', $_GET['end']);
00413                 // all
00414                 if ($_GET['histo'] == 0)
00415                 {
00416                         $letter->get_all();
00417                 }
00418 
00419                 // lettered
00420                 if ($_GET['histo'] == 1)
00421                 {
00422                         $letter->get_letter();
00423                 }
00424                 // unlettered
00425                 if ($_GET['histo'] == 2)
00426                 {
00427                         $letter->get_unletter();
00428                 }
00429                 if ($_GET['histo'] == 6)
00430                 {
00431                         $letter->get_letter_diff();
00432                 }
00433                 /* skip if nothing to display */
00434                 if (count($letter->content) == 0)
00435                         continue;
00436                 $detail_card = HtmlInput::card_detail($row->strAttribut(ATTR_DEF_QUICKCODE), $row->strAttribut(ATTR_DEF_NAME))."poste :".$row->strAttribut(ATTR_DEF_ACCOUNT).HtmlInput::infobulle(27);
00437 
00438                 echo '<h2 style="font-size:14px;text-align:left;margin-left:10px;padding-left:50px;border:solid 1px blue;width:70%;text-decoration:underline">' . $detail_card . '</h2>';
00439 
00440                 echo '<table style="width:90%;padding-left:5%;padding-right:5%">';
00441                 echo '<tr>';
00442                 echo th(_('Date'));
00443                 echo th(_('ref'));
00444                 echo th(_('Interne'));
00445                 echo th(_('Comm'));
00446                 echo th(_('Montant'), 'style="width:auto" colspan="2"');
00447                 echo th(_('Prog.'));
00448                 echo th(_('Let.'));
00449                 echo '</tr>';
00450                 $amount_deb = 0;
00451                 $amount_cred = 0;
00452                 $prog = 0;
00453                 bcscale(2);
00454                 for ($i = 0; $i < count($letter->content); $i++)
00455                 {
00456                     $row = $letter->content[$i];
00457                      $html_letter="";
00458                         if ($row['letter']!=-1) {
00459                             $html_letter=strtoupper(base_convert($row['letter'],10,36));
00460                         }
00461                         if ($i % 2 == 0)
00462                                 echo '<tr class="even" name="tr_'.$html_letter.'_">';
00463                         else
00464                                 echo '<tr class="odd" name="tr_'.$html_letter.'_">';
00465                         
00466                         echo td($row['j_date_fmt']);
00467                         echo td(h($row['jr_pj_number']));
00468                         echo td(HtmlInput::detail_op($row['jr_id'], $row['jr_internal']));
00469                         echo td(h($row['jr_comment']));
00470                         if ($row['j_debit'] == 't')
00471                         {
00472                                 echo td(nbm($row['j_montant']), ' style="text-align:right"');
00473                                 $amount_deb=bcadd($amount_deb,$row['j_montant']);
00474                                 $prog = bcadd($prog, $row['j_montant']);
00475                                 echo td("");
00476                         }
00477                         else
00478                         {
00479                                 echo td("");
00480                                 echo td(nbm($row['j_montant']), ' style="text-align:right"');
00481                                 $amount_cred=bcadd($amount_cred,$row['j_montant']);
00482                                 $prog = bcsub($prog, $row['j_montant']);
00483                         }
00484                         $side = "&nbsp;" . $fiche->get_amount_side($prog);
00485                         echo td(nbm($prog) . $side, 'style="text-align:right"');
00486                         $html_let="";
00487                         if ($row['letter']!=-1) {
00488                             $span_error = "";
00489                                 if ($row['letter_diff'] != 0)
00490                                         $span_error = $g_failed;
00491                                 echo '<td>'.HtmlInput::show_reconcile("", $html_letter,$span_error).'</td>';
00492                         }
00493                         else
00494                                 echo td('');
00495                         echo '</tr>';
00496                 }
00497                 echo '</table>';
00498                 echo '<table>';
00499                 echo '<tr>';
00500                 echo td(_('Debit'));
00501                 echo td(nbm($amount_deb), ' style="font-weight:bold;text-align:right"');
00502                 echo '</tr>';
00503                 echo '<tr>';
00504                 echo td(_('Credit'));
00505                 echo td(nbm($amount_cred), ' style="font-weight:bold;text-align:right"');
00506                 echo '</tr>';
00507                 echo '<tr>';
00508                 if ($amount_deb > $amount_cred)
00509                         $s = 'solde débiteur';
00510                 else
00511                         $s = 'solde crediteur';
00512                 echo td($s);
00513                 echo td(nbm(abs(round($amount_cred - $amount_deb, 2))), ' style="font-weight:bold;text-align:right"');
00514                 echo '</tr>';
00515                 echo '</table>';
00516         }
00517 }
00518 if ( $allcard == 0) echo $str_add_card;
00519 echo $export_csv;
00520 echo $export_pdf;
00521 echo $export_print;
00522 ?>
00523 
 All Data Structures Namespaces Files Functions Variables Enumerations