00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00025 require_once("class_ihidden.php");
00026 require_once("class_iselect.php");
00027 require_once("class_icheckbox.php");
00028 require_once('class_exercice.php');
00029 require_once('class_dossier.php');
00030 load_all_script();
00031 $gDossier = dossier::id();
00032 global $g_user;
00033
00034
00035
00036 require_once('class_database.php');
00037
00038 if ($g_user->Admin() == 0 && $g_user->is_local_admin() == 0)
00039 {
00040 $sql = "select jrn_def_id,jrn_def_name
00041 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
00042 join user_sec_jrn on uj_jrn_id=jrn_def_id
00043 where
00044 uj_login='$g_user->login'
00045 and uj_priv in ('R','W')
00046 order by jrn_def_name
00047 ";
00048 $ret = $cn->make_array($sql);
00049 }
00050 else
00051 {
00052 $ret = $cn->make_array("select jrn_def_id,jrn_def_name
00053 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
00054 order by jrn_def_name
00055 ");
00056 }
00057
00058 $NoPriv = $cn->count_sql("select jrn_def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc,uj_priv,
00059 jrn_deb_max_line,jrn_cred_max_line
00060 from jrn_def join jrn_type on jrn_def_type=jrn_type_id
00061 join user_sec_jrn on uj_jrn_id=jrn_def_id
00062 where
00063 uj_login='$g_user->id'
00064 and uj_priv ='X'
00065 ");
00066
00067
00068
00069 $a = count($ret);
00070 $all = array('value' => 0, 'label' => 'Tous les journaux disponibles');
00071 $ret[$a] = $all;
00072 if (count($ret) < 1)
00073 NoAccess();
00074 $exercice = (isset($_GET['exercice'])) ? $_GET['exercice'] : $g_user->get_exercice();
00075
00076
00077
00078
00079 echo '<div class="content">';
00080
00081
00082
00083 echo '<form method="GET">';
00084 echo '<fieldset><legend>' . _('Exercice') . '</legend>';
00085 ;
00086 echo _('Choisissez un autre exercice').' :';
00087 $ex = new Exercice($cn);
00088 $wex = $ex->select('exercice', $exercice, ' onchange="submit(this)"');
00089 echo $wex->input();
00090 echo dossier::hidden();
00091 echo HtmlInput::get_to_hidden(array('ac', 'type'));
00092 echo '</fieldset>';
00093 echo '</form>';
00094 ?>
00095 <?php
00096
00097
00098 echo '<FORM METHOD="GET">' . dossier::hidden();
00099 echo HtmlInput::get_to_hidden(array('ac', 'type'));
00100 echo HtmlInput::hidden('type', 'jrn');
00101 echo HtmlInput::get_to_hidden(array('exercice'));
00102 echo '<TABLE ><TR>';
00103 $w = new ISelect();
00104 $w->table = 1;
00105 $label = "Choisissez le journal";
00106 $w->selected = (isset($_GET['jrn_id'])) ? $_GET['jrn_id'] : '';
00107 print td($label) . $w->input("jrn_id", $ret);
00108 print '</TR>';
00109 print '<TR>';
00110
00111 $filter_year = " where p_exercice='" . sql_string($exercice) . "'";
00112
00113 $periode_start = $cn->make_array("select p_id,to_char(p_start,'DD-MM-YYYY') from parm_periode $filter_year order by p_start,p_end");
00114 $w->selected = (isset($_GET['from_periode'])) ? $_GET['from_periode'] : '';
00115 print td('Depuis') . $w->input('from_periode', $periode_start);
00116 print '</TR>';
00117 print '<TR>';
00118
00119 $periode_end = $cn->make_array("select p_id,to_char(p_end,'DD-MM-YYYY') from parm_periode $filter_year order by p_start,p_end");
00120 $w->selected = (isset($_GET['to_periode'])) ? $_GET['to_periode'] : '';
00121 print td('Jusque ') . $w->input('to_periode', $periode_end);
00122 print "</TR><TR>";
00123 $a = array(
00124 array('value' => 0, 'label' => 'Ecriture comptable'),
00125 array('value' => 1, 'label' => 'Liste opérations'),
00126 array('value' => 2, 'label' => 'Avec Détails opérations ')
00127 );
00128 $w->selected = 1;
00129 print '</TR>';
00130 print '<TR>';
00131 $w->selected = (isset($_GET['p_simple'])) ? $_GET['p_simple'] : '';
00132 echo '<td>Style d\'impression '.HtmlInput::infobulle(32).'</td>' . $w->input('p_simple', $a);
00133 print "</TR>";
00134 echo '</TABLE>';
00135 print HtmlInput::submit('bt_html', 'Visualisation');
00136
00137 echo '</FORM>';
00138 echo '<hr>';
00139
00140
00141
00142
00143
00144
00145
00146 if (isset($_REQUEST['bt_html']))
00147 {
00148 require_once("class_acc_ledger.php");
00149
00150 $d = var_export($_GET, true);
00151 $Jrn = new Acc_Ledger($cn, $_GET['jrn_id']);
00152 $Jrn->get_name();
00153 switch ($_GET['p_simple'])
00154 {
00155 case "0":
00156 $Row = $Jrn->get_row($_GET['from_periode'], $_GET['to_periode']);
00157 break;
00158 case "1":
00159 $Row = $Jrn->get_rowSimple($_GET['from_periode'], $_GET['to_periode']);
00160 break;
00161 case "2":
00162 $Row = $Jrn->get_rowSimple($_GET['from_periode'], $_GET['to_periode']);
00163 break;
00164 default:
00165 var_dump($_GET['p_simple']);
00166 die(__FILE__ . ":" . __LINE__ . " error unknown style ");
00167 }
00168 $rep = "";
00169 $hid = new IHidden();
00170 echo '<div class="content">';
00171 echo '<h2 class="info">' . h($Jrn->name) . '</h2>';
00172 echo "<table>";
00173 echo '<TR>';
00174 echo '<TD><form method="GET" ACTION="?">' . dossier::hidden() .
00175 $hid->input("type", "jrn") . $hid->input('p_action', 'impress') . "</form></TD>";
00176
00177 echo '<TD><form method="GET" ACTION="export.php">' . dossier::hidden() .
00178 HtmlInput::submit('bt_pdf', "Export PDF") .
00179 HtmlInput::hidden('act', 'PDF:ledger') .
00180 $hid->input("type", "jrn") .
00181 $hid->input("jrn_id", $Jrn->id) .
00182 $hid->input("from_periode", $_GET['from_periode']) .
00183 $hid->input("to_periode", $_GET['to_periode']);
00184 echo $hid->input("p_simple", $_GET['p_simple']);
00185 echo HtmlInput::get_to_hidden(array('ac', 'type'));
00186 echo "</form></TD>";
00187
00188 echo '<TD><form method="GET" ACTION="export.php">' . dossier::hidden() .
00189 HtmlInput::submit('bt_csv', "Export CSV") .
00190 HtmlInput::hidden('act', 'CSV:ledger') .
00191 $hid->input("type", "jrn") .
00192 $hid->input("jrn_id", $Jrn->id) .
00193 $hid->input("from_periode", $_GET['from_periode']) .
00194 $hid->input("to_periode", $_GET['to_periode']);
00195 echo $hid->input("p_simple", $_GET['p_simple']);
00196 echo HtmlInput::get_to_hidden(array('ac', 'type'));
00197 echo "</form></TD>";
00198
00199 echo '<td style="vertical-align:top">';
00200 echo HtmlInput::print_window();
00201 echo '</td>';
00202 echo "</TR>";
00203
00204 echo "</table>";
00205 if (count($Jrn->row) == 0
00206 && $Row == null)
00207 exit;
00208
00209
00210
00211
00212
00213 if ($_GET['p_simple'] == 0)
00214 {
00215 echo '<TABLE class="result">';
00216
00217
00218 foreach ($Jrn->row as $op)
00219 {
00220 $class = "";
00221 if ($op['j_date'] != '')
00222 {
00223 $class = "odd";
00224 }
00225
00226 echo "<TR class=\"$class\">";
00227
00228 echo "<TD>" . $op['j_date'] . "</TD>";
00229 echo "<TD >" . $op['jr_pj_number'] . "</TD>";
00230
00231
00232 if ($op['internal'] != '')
00233 echo "<TD>" . HtmlInput::detail_op($op['jr_id'], $op['internal']) . "</TD>";
00234 else
00235 echo td();
00236
00237 echo "<TD >" . $op['poste'] . "</TD>" .
00238 "<TD >" . $op['description'] . "</TD>" .
00239 "<TD style=\"text-align:right\">" . nbm($op['deb_montant']) . "</TD>" .
00240 "<TD style=\"text-align:right\">" . nbm($op['cred_montant']) . "</TD>" .
00241 "</TR>";
00242 }
00243 echo "</table>";
00244
00245
00246 $solde = $Jrn->get_solde($_GET['from_periode'], $_GET['to_periode']);
00247 echo "solde débiteur:" . $solde[0] . "<br>";
00248 echo "solde créditeur:" . $solde[1];
00249 }
00250
00251
00252
00253 elseif ($_GET['p_simple'] == 1)
00254 {
00255 if ( $Jrn->get_type() != 'ACH' && $Jrn->get_type() != 'VEN')
00256 {
00257
00258
00259 echo '<TABLE class="result">';
00260 echo "<TR>" .
00261 "<th> operation </td>" .
00262 "<th>Date</th>" .
00263 "<th> n° de pièce </th>" .
00264 "<th>internal</th>" .
00265 th('Tiers') .
00266 "<th>Commentaire</th>" .
00267 "<th>Total opération</th>" .
00268 "</TR>";
00269
00270 $i = 0;$tot_amount=0;
00271 bcscale(2);
00272 foreach ($Row as $line)
00273 {
00274 $i++;
00275 $class = ($i % 2 == 0) ? ' class="even" ' : ' class="odd" ';
00276 echo "<tr $class>";
00277 echo "<TD>" . $line['num'] . "</TD>";
00278 echo "<TD>" . $line['date'] . "</TD>";
00279 echo "<TD>" . h($line['jr_pj_number']) . "</TD>";
00280 echo "<TD>" . HtmlInput::detail_op($line['jr_id'], $line['jr_internal']) . "</TD>";
00281 $tiers = $Jrn->get_tiers($line['jrn_def_type'], $line['jr_id']);
00282 echo td($tiers);
00283 echo "<TD>" . h($line['comment']) . "</TD>";
00284
00285
00286
00287
00288
00289
00290 if ($line['jrn_def_type'] == 'FIN')
00291 {
00292 $positive = $cn->get_value("select qf_amount from quant_fin where jr_id=$1", array($line['jr_id']));
00293 if ($cn->count() == 0)
00294 $positive = 1;
00295 else
00296 $positive = ($positive > 0) ? 1 : 0;
00297
00298 echo "<TD align=\"right\">";
00299 echo ( $positive == 0 ) ? "<font color=\"red\"> - " . nbm($line['montant']) . "</font>" : nbm($line['montant']);
00300 echo "</TD>";
00301 if ( $positive == 1 ) {
00302 $tot_amount=bcadd($tot_amount,$line['montant']);
00303 } else {
00304 $tot_amount=bcsub($tot_amount,$line['montant']);
00305 }
00306 }
00307 else
00308 {
00309 echo "<TD align=\"right\">" . nbm($line['montant']) . "</TD>";
00310 $tot_amount=bcadd($tot_amount,$line['montant']);
00311 }
00312
00313 echo "</tr>";
00314 }
00315 echo '<tr class="highlight">';
00316 echo '<td>'._('Totaux').'</td>';
00317 echo td().td().td().td().td();
00318 echo '<td class="num">'.nbm($tot_amount).'</td>';
00319 echo '</tr>';
00320 echo "</table>";
00321 } else {
00322
00323
00324
00325 $own=new Own($cn);
00326 require_once 'template/print_ledger_simple.php';
00327
00328 }
00329 }
00330
00331
00332
00333 elseif ($_GET['p_simple'] == 2)
00334 {
00335 foreach ($Row as $line)
00336 {
00337 echo '<div style="margin-top:2px;margin-bottom:10px;border:solid 1px black">';
00338 $class = ' class="odd" style="font-stretch: expanded;font-size:1em;"';
00339 echo '<table class="result" style="font-weight: bolder;font-variant: small-caps;width:100%;">';
00340 echo "<tr $class>";
00341 echo '<TD style="width:5%">' . $line['date'] . "</TD>";
00342 echo '<TD style="width:10%">' . h($line['jr_pj_number']) . "</TD>";
00343 echo '<TD style="width:5%">' . HtmlInput::detail_op($line['jr_id'], $line['jr_internal']) . "</TD>";
00344 $tiers = $Jrn->get_tiers($line['jrn_def_type'], $line['jr_id']);
00345 $ledger_name = $cn->get_value("select jrn_def_name from jrn_def where jrn_def_id=$1", array($line['jr_def_id']));
00346 echo '<TD style="width:20%">' . h($ledger_name) . ' </td>';
00347 echo '<TD style="width:20%">' . h($tiers) . ' </td>';
00348 echo '<TD style="width:30%">' . h($line['comment']) . "</TD>";
00349 echo '<TD style="text-align:right">';
00350 if ($line['jrn_def_type'] == 'FIN')
00351 {
00352 $positive = $cn->get_value("select qf_amount from quant_fin where jr_id=$1", array($line['jr_id']));
00353 if ($cn->count() == 0)
00354 $positive = 1;
00355 else
00356 $positive = ($positive > 0) ? 1 : 0;
00357
00358 echo ( $positive == 0 ) ? "<font color=\"red\"> - " . nbm($line['montant']) . "</font>" : nbm($line['montant']);
00359 }
00360 else
00361 {
00362 if ( isset ($line['TVAC'])) {
00363 echo ( nbm($line['TVAC']) < 0 ) ? "<font color=\"red\"> - " . nbm($line['TVAC']) . "</font>" : nbm($line['TVAC']);
00364 } else
00365 {
00366 echo nbm($line['montant']) ;
00367 }
00368 }
00369 echo "</TD>";
00370 echo "</tr>";
00371 echo '</table>';
00372
00373
00374
00375 $op = new Acc_Operation($cn);
00376 $op->jr_id = $line['jr_id'];
00377 $op->get();
00378 $obj = $op->get_quant();
00379 switch ($obj->signature)
00380 {
00381 case 'FIN':
00382 require 'template/operation_detail_fin.php';
00383 break;
00384 case 'ACH':
00385 require 'template/operation_detail_ach.php';
00386 break;
00387 case 'VEN':
00388 require 'template/operation_detail_ven.php';
00389 break;
00390 case 'ODS':
00391 require 'template/operation_detail_misc.php';
00392 break;
00393 default:
00394 die("unknown type of ledger");
00395 break;
00396 }
00397 echo '</div>';
00398
00399 }
00400 }
00401
00402 echo "</div>";
00403 exit;
00404 }
00405
00406 echo '</div>';
00407 ?>