noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
opening.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 /**\file
00023  * \brief The opening of the exercices. it takes the saldo of the
00024  * choosen foolder / exercice and import it as a misc operation in the
00025  * current folder
00026 
00027  *
00028  *
00029  *
00030  */
00031 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00032 require_once("class_iselect.php");
00033 require_once('class_acc_ledger.php');
00034 
00035 $sa = (isset($_REQUEST['sa'])) ? $_REQUEST['sa'] : '';
00036 $g_user->Check();
00037 
00038 require_once 'user_menu.php';
00039 
00040 // Correct (last step)
00041 if (isset($_POST['correct']))
00042 {
00043         $ledger = new Acc_Ledger($cn, $_REQUEST['p_jrn']);
00044         require_once 'operation_ods_new.inc.php';
00045         exit();
00046 }
00047 
00048 // confirm before saving
00049 if ( isset($_POST['summary']))
00050 {
00051         try {
00052                 $ledger = new Acc_Ledger($cn, $_REQUEST['p_jrn']);
00053                 $ledger->with_concerned=false;
00054                         $ledger->verify($_POST);
00055                         require_once 'operation_ods_confirm.inc.php';
00056         } catch (Exception $e)
00057         {
00058                 echo alert($e->getMessage());
00059                 require('operation_ods_new.inc.php');
00060 
00061         }
00062         exit();
00063 }
00064 
00065 // record
00066 if (isset($_POST['save']))
00067 {
00068         $array = $_POST;
00069         $ledger = new Acc_Ledger($cn, $_REQUEST['p_jrn']);
00070         $ledger->with_concerned=false;
00071         try
00072         {
00073                 $ledger->save($array);
00074                 $jr_id = $cn->get_value('select jr_id from jrn where jr_internal=$1', array($ledger->internal));
00075 
00076                 echo '<h2> Op&eacute;ration enregistr&eacute;e  Piece ' . h($ledger->pj) . '</h2>';
00077                 if (strcmp($ledger->pj, $_POST['e_pj']) != 0)
00078                 {
00079                         echo '<h3 class="notice">' . _('Attention numéro pièce existante, elle a du être adaptée') . '</h3>';
00080                 }
00081                 printf('<a class="detail" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a><hr>', $jr_id, dossier::id(), $ledger->internal);
00082 
00083                 // show feedback
00084                 echo '<div id="jrn_name_div">'; echo '<h2 id="jrn_name" style="display:inline">' . $ledger->get_name() . '</h2>'; echo '</div>';
00085                 echo $ledger->confirm($_POST, true);
00086         }
00087         catch (Exception $e)
00088         {
00089                 require('operation_ods_new.inc.php');
00090                 alert($e->getMessage());
00091         }
00092         exit();
00093 }
00094 
00095 
00096 /* --------------------------------------------------
00097  * step 1 if nothing is asked we show the available folders
00098  */
00099 if ($sa == '')
00100 {
00101         echo '<div class="content">';
00102         
00103         echo '<h1 class="legend"> Etape 1 </h1>';
00104 
00105         echo 'Choississez le dossier où sont les soldes à importer';
00106         $avail = $g_user->get_available_folder();
00107 
00108         if (empty($avail))
00109         {
00110                 echo '*** Aucun dossier ***';
00111                 exit();
00112         }
00113         echo '<form class="print" method="post">';
00114         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00115         echo HtmlInput::hidden('sa', 'step2');
00116         echo dossier::hidden();
00117         $wAvail = new ISelect();
00118         /* compute select list */
00119         $array = array();
00120         $i = 0;
00121         foreach ($avail as $r)
00122         {
00123                 $array[$i]['value'] = $r['dos_id'];
00124                 $array[$i]['label'] = $r['dos_name'];
00125                 $i++;
00126         }
00127 
00128         $wAvail->value = $array;
00129         echo 'Choix du dossier :' . $wAvail->input('f');
00130         echo HtmlInput::submit('ok', 'Continuer');
00131 
00132         echo '</form>';
00133         echo '</div>';
00134         echo '</div>';
00135         exit();
00136 }
00137 /* --------------------------------------------------
00138  * Step 2 choose now the exercice of this folder
00139  */
00140 $back = 'do.php?ac=' . $_REQUEST['ac'] . '&' . dossier::get();
00141 if ($sa == 'step2')
00142 {
00143         echo '<div class="content">' .
00144         '<div><h1 class="legend">Etape 2</h1>' .
00145         '<h2 class="info">' . dossier::name($_REQUEST['f']) . '</h2>' .
00146         '<form class="print" method="post">' .
00147         ' Choississez l\'exercice du dossier ';
00148         echo dossier::hidden();
00149         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00150         echo HtmlInput::hidden('sa', 'step3');
00151         echo HtmlInput::hidden('f', $_REQUEST['f']);
00152         $cn = new Database($_REQUEST['f']);
00153         $periode = $cn->make_array("select distinct p_exercice,p_exercice from parm_periode order by p_exercice");
00154         $w = new ISelect();
00155         $w->table = 0;
00156         $w->label = 'Periode';
00157         $w->readonly = false;
00158         $w->value = $periode;
00159         $w->name = "p_periode";
00160         echo 'P&eacute;riode : ' . $w->input();
00161         echo HtmlInput::submit('ok', 'Continuer');
00162         echo dossier::hidden();
00163         echo "</form>";
00164         echo HtmlInput::button_anchor('Retour', $back);
00165         exit(0);
00166 }
00167 /* --------------------------------------------------
00168  * select the ledger where we will import the data
00169  */
00170 if ($sa == 'step3')
00171 {
00172         echo '<div class="content">' .
00173         '<div><h1 class="legend">Etape 3</h1>' .
00174         '<h2 class="info">' . dossier::name($_REQUEST['f']) . '</h2>' .
00175         '<form class="print" method="post">' .
00176         ' Choississez le journal qui contiendra l\'opération d\'ouverture ';
00177         echo dossier::hidden();
00178         echo HtmlInput::hidden('p_action', 'ouv');
00179         echo HtmlInput::hidden('sa', 'step4');
00180         echo HtmlInput::hidden('f', $_REQUEST['f']);
00181         echo HtmlInput::hidden('p_periode', $_REQUEST['p_periode']);
00182         $wLedger = new ISelect();
00183         $g_user = new User(new Database(dossier::id()));
00184         $avail = $g_user->get_ledger('ODS');
00185         /* compute select list */
00186         $array = array();
00187         $i = 0;
00188         foreach ($avail as $r)
00189         {
00190                 $array[$i]['value'] = $r['jrn_def_id'];
00191                 $array[$i]['label'] = $r['jrn_def_name'];
00192                 $i++;
00193         }
00194         $wLedger->value = $array;
00195         echo $wLedger->input('p_jrn');
00196         echo HtmlInput::submit('ok', 'Continuer');
00197         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00198         echo dossier::hidden();
00199         echo "</form>";
00200         echo HtmlInput::button_anchor('Retour', $back . '&sa=step2&f=' . $_REQUEST['f']);
00201         exit(0);
00202 }
00203 /* --------------------------------------------------
00204  * Step 4 we import data from the selected folder and year and
00205  * transform it into a misc operation
00206  */
00207 if ($sa == 'step4')
00208 {
00209         echo '<div class="content">';
00210         echo '<div><h1 class="legend"> Dernière étape</h1>';
00211         $cn_target = new Database($_REQUEST['f']);
00212         $saldo = new Acc_Ledger($cn_target, 0);
00213         $array = $saldo->get_saldo_exercice($_REQUEST['p_periode']);
00214         /*  we need to transform the array into a Acc_Ledger array */
00215         $result = array();
00216         $result['desc'] = 'Ecriture d\'ouverture';
00217         $result['nb_item'] = sizeof($array);
00218         $result['p_jrn'] = $_REQUEST['p_jrn'];
00219         $idx = 0;
00220 
00221         foreach ($array as $row)
00222         {
00223                 $qcode = 'qc_' . $idx;
00224                 $poste = 'poste' . $idx;
00225                 $amount = 'amount' . $idx;
00226                 $ck = 'ck' . $idx;
00227                 $result[$qcode] = $row['j_qcode'];
00228                 if (trim($row['j_qcode']) == '')
00229                         $result[$poste] = $row['j_poste'];
00230                 $result[$amount] = abs($row['solde']);
00231                 if ($row['solde'] > 0)
00232                         $result[$ck] = 'on';
00233                 $idx++;
00234         }
00235         $cn = new Database(dossier::id());
00236 
00237         $jrn = new Acc_Ledger($cn, $_REQUEST['p_jrn']);
00238 
00239         echo '<form class="print" method="post">';
00240         echo HtmlInput::hidden('ac', $_REQUEST['ac']);
00241         echo HtmlInput::hidden('sa', 'step5');
00242         echo HtmlInput::hidden('f', $_REQUEST['f']);
00243         echo HtmlInput::hidden('p_periode',$_REQUEST['p_periode']);
00244         echo dossier::hidden();
00245         echo HtmlInput::hidden('p_jrn', $_REQUEST['p_jrn']);
00246         echo $jrn->input($result, 0);
00247         echo '<hr>';
00248         echo '<h2 class="notice">Ne corrigez pas encore, cliquez continuer pour passer à l\'étape suivante</h2>';
00249         echo HtmlInput::submit('correct_it', 'Continuer');
00250         echo '</form>';
00251         echo HtmlInput::button_anchor('Retour', $back);
00252 
00253         echo '</div>';
00254 }
00255 // if sa=step4 then record it
00256 //
00257 if ($_REQUEST['sa'] == 'step5')
00258 {
00259         $ledger = new Acc_Ledger($cn, $_REQUEST['p_jrn']);
00260         require_once 'operation_ods_new.inc.php';
00261 }
00262 
 All Data Structures Namespaces Files Functions Variables Enumerations