noalyss Version-9
opening.inc.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * NOALYSS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with NOALYSS; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21// Copyright Author Dany De Bontridder danydb@aevalys.eu
22/* * \file
23 * \brief The opening of the exercices. it takes the saldo of the
24 * choosen foolder / exercice and import it as a misc operation in the
25 * current folder
26
27 *
28 *
29 *
30 */
31if (!defined('ALLOWED'))
32 die('Appel direct ne sont pas permis');
35
36$sa=$http->request("sa", "string", "");
37$g_user->Check();
38
39require_once NOALYSS_INCLUDE.'/lib/user_menu.php';
40
41// Correct (last step)
42if (isset($_POST['correct']))
43{
44 $p_jrn=$http->request("p_jrn", "number");
46 require_once NOALYSS_INCLUDE.'/operation_ods_new.inc.php';
47 return;
48}
49
50// confirm before saving
51if (isset($_POST['summary']))
52{
53 try
54 {
55 $p_jrn=$http->request("p_jrn", "number");
57 $ledger->with_concerned=false;
58 $ledger->verify($_POST);
59 require_once NOALYSS_INCLUDE.'/operation_ods_confirm.inc.php';
60 }
61 catch (Exception $e)
62 {
63 echo alert($e->getMessage());
64 require(NOALYSS_INCLUDE.'/operation_ods_new.inc.php');
65 }
66 return;
67}
68
69// record
70if (isset($_POST['save']))
71{
72 $p_jrn=$http->request("p_jrn", "number");
75 $ledger->with_concerned=false;
76 try
77 {
78 $ledger->save($array);
79 $jr_id=$cn->get_value('select jr_id from jrn where jr_internal=$1',
80 array($ledger->internal));
81
82 echo '<h2>'._("Opération enregistrée")." "._("Piece ").h($ledger->pj).'</h2>';
83 if (strcmp($ledger->pj, $_POST['e_pj'])!=0)
84 {
85 echo '<h3 class="notice">'._('Attention numéro pièce existante, elle a du être adaptée').'</h3>';
86 }
87 printf('<a class="detail" style="display:inline" href="javascript:modifyOperation(%d,%d)">%s</a><hr>',
88 $jr_id, dossier::id(), $ledger->internal);
89
90 // show feedback
91 echo '<div id="jrn_name_div">'; echo '<h1 id="jrn_name" style="display:inline">'.$ledger->get_name().'</h1>'; echo '</div>';
92 echo $ledger->confirm($_POST, true);
93 }
94 catch (Exception $e)
95 {
96 require(NOALYSS_INCLUDE.'/operation_ods_new.inc.php');
97 alert($e->getMessage());
98 }
99 return;
100}
101
102
103/* --------------------------------------------------
104 * step 1 if nothing is asked we show the available folders
105 */
106if ($sa=='')
107{
108 echo '<div class="content">';
109
110 echo '<h1 class="legend">'._("Etape 1 : choix du dossier").' </h1>';
111
112 echo _('Choisissez le dossier où sont les soldes à importer');
113 $avail=$g_user->get_available_folder();
114
115 if (empty($avail))
116 {
117 echo '*** '._("Aucun dossier").' ***';
118 return;
119 }
120 echo '<form class="print" method="post">';
121 echo HtmlInput::hidden('ac', $_REQUEST['ac']);
122 echo HtmlInput::hidden('sa', 'step2');
123 echo dossier::hidden();
124 $wAvail=new ISelect();
125 /* compute select list */
126 $array=array();
127 $i=0;
128 foreach ($avail as $r)
129 {
130 $array[$i]['value']=$r['dos_id'];
131 $array[$i]['label']=$r['dos_name'];
132 $i++;
133 }
134 $wAvail->selected=Dossier::id();
135 $wAvail->value=$array;
136 printf (_('Choix du dossier : %s'),
137 $wAvail->input('f'));
138 echo HtmlInput::submit('ok', _('Continuer'));
139
140 echo '</form>';
141 echo '</div>';
142 echo '</div>';
143 return;
144}
145/* --------------------------------------------------
146 * Step 2 choose now the exercice of this folder
147 */
148$back='do.php?ac='.$http->request("ac").'&'.dossier::get();
149if ($sa=='step2')
150{
151 echo '<div class="content">'.
152 '<div><h1 class="legend">'._('Etape 2 : période').'</h1>'.
153 '<h2 class="info">'.dossier::name($_REQUEST['f']).'</h2>'.
154 '<form class="print" method="post">'.
155 _("Choisissez l'exercice clôturé (exercice N-1) du dossier à reporter pour les a-nouveaux (exercice N)");
156 echo dossier::hidden();
157 echo HtmlInput::hidden('ac', $_REQUEST['ac']);
158 echo HtmlInput::hidden('sa', 'step3');
159 echo HtmlInput::hidden('f', $_REQUEST['f']);
160 $cn=new Database($_REQUEST['f']);
161 $periode=$cn->make_array("select distinct p_exercice,p_exercice from parm_periode order by p_exercice");
162 $w=new ISelect();
163 $w->table=0;
164 $w->label=_('Periode N-1');
165 $w->readonly=false;
166 $w->value=$periode;
167 $w->name="p_periode";
168 $w->selected=$g_user->get_exercice()-1;
169 echo "<p>";
170 echo _('Période N-1').' : '.$w->input();
171 echo "</p>";
172 echo HtmlInput::submit('ok', _('Continuer'));
173 echo dossier::hidden();
174 echo "</form>";
175 echo HtmlInput::button_anchor(_('Retour'), $back);
176 exit(0);
177}
178/* --------------------------------------------------
179 * select the ledger where we will import the data
180 */
181if ($sa=='step3')
182{
183 echo '<div class="content">'.
184 '<div><h1 class="legend">Etape 3</h1>'.
185 '<h2 class="info">'.dossier::name($_REQUEST['f']).'</h2>'.
186 '<form class="print" method="post">'.
187 _(" Choisissez le journal qui contiendra l'opération d'ouverture ");
188 echo dossier::hidden();
189 echo HtmlInput::hidden('p_action', 'ouv');
190 echo HtmlInput::hidden('sa', 'step4');
191 echo HtmlInput::hidden('f', $_REQUEST['f']);
192 echo HtmlInput::hidden('p_periode', $_REQUEST['p_periode']);
193 $wLedger=new ISelect();
194 $g_user=new Noalyss_user($cn);
195 $avail=$g_user->get_ledger('ODS');
196 /* compute select list */
197 $array=array();
198 $i=0;
199 foreach ($avail as $r)
200 {
201 $array[$i]['value']=$r['jrn_def_id'];
202 $array[$i]['label']=$r['jrn_def_name'];
203 $i++;
204 }
205 $wLedger->value=$array;
206 echo $wLedger->input('p_jrn');
207 echo HtmlInput::submit('ok', 'Continuer');
208 echo HtmlInput::hidden('ac', $_REQUEST['ac']);
209 echo dossier::hidden();
210 echo "</form>";
211 echo HtmlInput::button_anchor('Retour',
212 $back.'&sa=step2&f='.$_REQUEST['f']);
213 exit(0);
214}
215/* --------------------------------------------------
216 * Step 4 we import data from the selected folder and year and
217 * transform it into a misc operation
218 */
219if ($sa=='step4')
220{
221 echo '<div class="content">';
222 echo '<div><h1 class="legend">'._("étape 4").'</h1>';
223 $dossier_id=$http->request("f","number");
224 $p_periode=$http->request("p_periode","number");
225 $p_jrn=$http->request("p_jrn","number");
226 $cn_target=new Database($dossier_id);
227 $saldo=new Acc_Ledger($cn_target, 0);
228 $array=$saldo->get_saldo_exercice($p_periode);
229 /* we need to transform the array into a Acc_Ledger array */
230
231 $result=array();
232 $result['desc']=sprintf(_("Ecriture d'ouverture %d"),$g_user->get_exercice());
233 $result['nb_item']=sizeof($array);
234 $result['p_jrn']=$p_jrn;
235 $result["ac"]=$http->request("ac");
236 $result['p_periode']=$p_periode;
237 $result['gDossier']=Dossier::id();
238 $result['jr_optype']="OPE";
239 // default date = first day of Exercice
240 $periode=new Periode($cn,$g_user->get_periode());
241 list($periode_start,$periode_end)=$periode->get_limit($g_user->get_exercice());
242 $result["e_date"]=$periode_start->first_day();
243
244 $idx=0;
245
246 foreach ($array as $row)
247 {
248 $qcode='qc_'.$idx;
249 $poste='poste'.$idx;
250 $amount='amount'.$idx;
251 $ck='ck'.$idx;
252 $result[$qcode]=$row['j_qcode'];
253 if (trim($row['j_qcode']??"")=='')
254 $result[$poste]=$row['j_poste'];
255 $result[$amount]=abs($row['solde']);
256 if ($row['solde']>0)
257 $result[$ck]='on';
258 $idx++;
259 }
265 require_once NOALYSS_INCLUDE.'/operation_ods_new.inc.php';
266
267 echo '</div>';
268}
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:738
global $g_user
if no group available , then stop
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$idx
$jr_id
Definition: ajax_ledger.php:44
$dossier_id
Definition: ajax_poste.php:43
$_REQUEST['ac']
foreach($array as $idx=> $m) $w
$input_from id
Definition: balance.inc.php:63
contains the class for connecting to Noalyss
static id()
return the 'gDossier' value after a check
static connect()
static hidden($p_name, $p_value, $p_id="")
static button_anchor($p_label, $p_value, $p_name="", $p_javascript="", $p_class="smallbutton")
create a button with a ref
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
manage the http input (get , post, request) and extract from an array
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
For the periode tables parm_periode and jrn_periode.
$_POST['ac']
Definition: do.php:310
for($e=0; $e< count($afiche); $e++) exit
$periode_start
Definition: fiche.inc.php:50
$periode_end
Definition: fiche.inc.php:51
if(isset( $_POST[ 'correct'])) if(isset($_POST['summary'])) if(isset( $_POST[ 'save'])) if($sa=='') $back
$http
Definition: opening.inc.php:33
$sa
Definition: opening.inc.php:36
$p_mesg
Definition: opening.inc.php:34