noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
compta_fin_rec.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 
00021 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00022 
00023 /**\file
00024  *
00025  *
00026  * \brief reconcile operation
00027  *
00028  */
00029 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00030 global $g_failed,$g_succeed;
00031 require_once 'class_acc_ledger_fin.php';
00032 bcscale(2);
00033 echo '<div class="content">';
00034 $Ledger = new Acc_Ledger_Fin($cn, 0);
00035 if (!isset($_REQUEST['p_jrn']))
00036 {
00037         $a = $Ledger->get_first('fin');
00038         $Ledger->id = $a['jrn_def_id'];
00039 }
00040 else
00041         $Ledger->id = $_REQUEST['p_jrn'];
00042 $jrn_priv = $g_user->get_ledger_access($Ledger->id);
00043 if (isset($_GET["p_jrn"]) && $jrn_priv == "X")
00044 {
00045         NoAccess();
00046         exit();
00047 }
00048 //-------------------------
00049 // save
00050 //-------------------------
00051 if (isset($_POST['save']))
00052 {
00053         if (trim($_POST['ext']) != '' && isset($_POST['op']))
00054         {
00055                 $array = $_POST['op'];
00056                 $tot = 0;
00057                 $cn->start();
00058                 for ($i = 0; $i < count($array); $i++)
00059                 {
00060                         $cn->exec_sql('update jrn set jr_pj_number=$1 where jr_id=$2', array($_POST['ext'], $array[$i]));
00061                         $tot = bcadd($tot, $cn->get_value('select qf_amount from quant_fin where jr_id=$1', array($array[$i])));
00062                 }
00063                 $diff = bcsub($_POST['end_extrait'], $_POST['start_extrait']);
00064                 if ($diff != 0 && $diff != $tot)
00065                 {
00066                         $remain=bcsub($tot,$diff);
00067                         $cn->rollback();
00068                         alert("D'après l'extrait il y aurait du avoir un montant de $diff à rapprocher alors qu'il y a $tot rapprochés, mise à jour annulée, la différence est de $remain");
00069                         echo '<div class="error">';
00070                         echo '<p>'.$g_failed._("D'après l'extrait il y aurait du avoir un montant de $diff à rapprocher alors qu'il y a $tot rapprochés, la différence est de $remain <br>mise à jour annulée").'</p>';
00071                         echo '</div>';
00072                 }
00073                 else
00074                   {
00075                     echo '<div class="content">'.$g_succeed.' Mise à jour extrait '.$_POST['ext'].'</div>';
00076                   }
00077 
00078                 $cn->commit();
00079         }
00080 }
00081 //-------------------------
00082 // show the operation of this ledger
00083 // without receipt number
00084 //-------------------------
00085 echo '<div class="content">';
00086 echo '<form method="get">';
00087 echo HtmlInput::get_to_hidden(array('gDossier', 'ledger_type', 'ac', 'sa'));
00088 $wLedger = $Ledger->select_ledger('FIN', 3);
00089 if ($wLedger == null)
00090         exit('Pas de journal disponible');
00091 echo '<div id="jrn_name_div">';
00092 echo '<h2 id="jrn_name" style="display:inline">' . $Ledger->get_name() . '</h2>';
00093 echo '</div>';
00094 $wLedger->javascript = "onchange='this.form.submit()';";
00095 echo $wLedger->input();
00096 echo HtmlInput::submit('ref', 'Rafraîchir');
00097 echo '</form>';
00098 echo '<span id="bkname" style="display:block">' . hb(h($Ledger->get_bank_name())) . '</span>';
00099 
00100 echo '<form method="post" id="rec1">';
00101 
00102 echo dossier::hidden();
00103 echo HtmlInput::get_to_hidden(array('sa', 'p_action', 'p_jrn'));
00104 
00105 $operation = $cn->get_array("select jr_id,jr_internal,
00106                                                                 jr_comment,
00107                                                                 to_char(jr_date,'DD.MM.YYYY') as fmt_date,
00108                                                                 jr_montant,
00109                                                                 to_char(jr_date,'YYYYMMDD') as raw_date
00110                               from jrn where jr_def_id=$1 and (jr_pj_number is null or jr_pj_number='') order by jr_date", array($Ledger->id));
00111 
00112 echo '<p>';
00113 $iextrait = new IText('ext');
00114 if ( isset ($_POST['ext'])) $iextrait->value=$_POST['ext']; else $iextrait->value = $Ledger->guess_pj();
00115 $nstart_extrait = new INum('start_extrait');
00116 if( isset($_POST['start_extrait'])) $nstart_extrait->value=$_POST['start_extrait'];
00117 $nend_extrait = new INum('end_extrait');
00118 if( isset($_POST['end_extrait'])) $nend_extrait->value=$_POST['end_extrait'];
00119 
00120 echo "Extrait / relevé :" . $iextrait->input();
00121 echo 'solde Début' . $nstart_extrait->input();
00122 echo 'solde Fin' . $nend_extrait->input();
00123 echo IButton::tooggle_checkbox('rec1');
00124 echo '</p>';
00125 echo '<p>';
00126 echo _('Filtre').HtmlInput::infobulle(25);
00127 echo HtmlInput::filter_table("t_rec_bk", "0,1,2,3","1");
00128 echo '</p>';
00129 echo HtmlInput::submit('save', 'Mettre à jour le n° de relevé bancaire');
00130 echo '<span style="display:block">';
00131 
00132 
00133         echo '</span>';
00134 echo '<table id="t_rec_bk" class="sortable" style="width:80%;margin-left:10%">';
00135 $r ='<th class=" sorttable_sorted_reverse">'.'Date '.HtmlInput::infobulle(17).'<span id="sorttable_sortrevind">&nbsp;&blacktriangle;</span>'.'</th>';
00136 $r.=th('Libellé');
00137 $r.=th('N° interne');
00138 $r.=th('Montant', ' style="text-align:right"');
00139 $r.=th('Selection', ' style="text-align:center" ');
00140 echo tr($r);
00141 $iradio = new ICheckBox('op[]');
00142 $tot_not_reconcilied = 0;
00143 $diff = 0;
00144 for ($i = 0; $i < count($operation); $i++)
00145 {
00146         $row = $operation[$i];
00147         $r = '';
00148         $js = HtmlInput::detail_op($row['jr_id'], $row['jr_internal']);
00149         $r.='<td sorttable_customkey="'.$row['raw_date'].'">'.$row['fmt_date'].'</td>';
00150         $r.=td($row['jr_comment']);
00151         $r.=td($js);
00152         $amount=$cn->get_value('select qf_amount from quant_fin where jr_id=$1', array($row['jr_id']));
00153         $r.='<td class="num" class="sorttable_numeric" sorttable_customkey="'.$amount.'" style="text-align:right">'.nbm ($amount).'</td>';
00154 
00155         $diff=bcadd($diff,$amount);
00156         $tot_not_reconcilied+=$row['jr_montant'];
00157         $iradio->value = $row['jr_id'];
00158         $iradio->selected=false;
00159         if (isset($_POST['op']))
00160         {
00161                 for ($x=0;$x<count($_POST['op']);$x++)
00162                 {
00163                         if ($row['jr_id']==$_POST['op'][$x])
00164                         {
00165                                 $iradio->selected=true;
00166                                 break;
00167                         }
00168                 }
00169         }
00170         $r.=td(HtmlInput::hidden('jrid['.$i.']', $row['jr_id']) . $iradio->input(), ' style="text-align:center" ');
00171         if ($i % 2 == 0)
00172                 echo tr($r, ' class="odd" ');
00173         else
00174                 echo tr($r,' class="even" ');
00175 }
00176 echo '</table>';
00177 $bk_card = new Fiche($cn);
00178 $bk_card->id = $Ledger->get_bank();
00179 $filter_year = "  j_tech_per in (select p_id from parm_periode where  p_exercice='" . $g_user->get_exercice() . "')";
00180 
00181 /*  get saldo for not reconcilied operations  */
00182 $saldo_not_reconcilied = $bk_card->get_solde_detail($filter_year . " and j_grpt in (select jr_grpt_id from jrn where trim(jr_pj_number) ='' or jr_pj_number is null)");
00183 
00184 /*  get saldo for reconcilied operation  */
00185 $saldo_reconcilied = $bk_card->get_solde_detail($filter_year . " and j_grpt in (select jr_grpt_id from jrn where trim(jr_pj_number) != '' and jr_pj_number is not null)");
00186 
00187 /* solde compte */
00188 $saldo = $bk_card->get_solde_detail($filter_year);
00189 
00190 echo '<table>';
00191 echo '<tr>';
00192 echo td("Solde compte  ");
00193 echo td(nbm(bcsub($saldo['debit'] , $saldo['credit'])), ' style="text-align:right"');
00194 echo '</tr>';
00195 
00196 echo '<tr>';
00197 echo td("Solde non rapproché ");
00198 echo td(nbm (bcsub($saldo_not_reconcilied['debit'], $saldo_not_reconcilied['credit'])), ' style="text-align:right"');
00199 echo '</tr>';
00200 
00201 echo '<tr>';
00202 echo td("Solde  rapproché ");
00203 echo td(nbm(bcsub($saldo_reconcilied['debit'] , $saldo_reconcilied['credit'])), ' style="text-align:right"');
00204 echo '</tr>';
00205 
00206 
00207 echo '<tr>';
00208 echo td("Total montant ");
00209 echo td(nbm ($tot_not_reconcilied), ' style="text-align:right"');
00210 echo '</tr>';
00211 
00212 echo '</table>';
00213 
00214 echo HtmlInput::submit('save', 'Mettre à jour le n° de relevé bancaire');
00215 echo '</form>';
00216 echo '</div>';
00217 exit();
00218 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations