noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
pre_op_advanced.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief definition of the class Pre_Op_Advanced
24 */
25
26/*---------------------------------------------------------------------- */
27/*!\brief concerns the predefined operation for the operation from 'Ecriture direct'
28 */
30{
31 function __construct($cn)
32 {
33 parent::__construct($cn);
34 }
35 /**
36 * @brief get the post and stove them into data member , before saving them in the db
37 * @see save
38 */
39 function get_post()
40 {
41 $http = new \HttpInput();
42 $nb = $http->post("nb_item", "number");
43
44 for ($i=0;$i<$nb;$i++)
45 {
46 $poste=$http->post("poste".$i,"string", null);
47 $qcode=$http->post("qc_".$i,"string", null);
48
49 if ( $poste == null && $qcode == null ) continue;
50
51 if ($poste != null && trim ($poste) != "")
52 {
53 $this->{'poste'.$i}=$poste;
54 $this->{'isqc'.$i}='f';
55 }
56
57 if ( $qcode != null && trim ($qcode) != "") {
58 $this->{'isqc'.$i}=(trim($http->post('qc_'.$i)) != "")?'t':'f';
59 $this->{'poste'.$i}=trim ($qcode);
60 }
61 $http->set_empty(0);
62 $this->{"amount".$i}=$http->post('amount'.$i);
63 $http->set_empty("");
64 $this->{"ld".$i}=$http->post("ld".$i);
65
66 $this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f';
67
68 }
69 }
70 /*!
71 * \brief save the detail and op in the database
72 *
73 */
74 function save($p_od_id,$p_nb_item)
75 {
76 try
77 {
78 // save the selling
79 for ($i=0;$i<$p_nb_item;$i++)
80 {
81 if ( ! isset ($this->{"poste".$i}))
82 continue;
83
84 $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'.
85 'opd_debit,od_id,opd_qc,opd_comment)'.
86 ' values($1,$2,$3,$4,$5,$6) '
87 );
88
89 $this->db->exec_sql($sql,[$this->{"poste".$i},
90 $this->{"amount".$i},
91 $this->{"ck".$i},
92 $p_od_id,
93 $this->{'isqc'.$i},
94 $this->{"ld".$i}]);
95
96 }
97
98 }
99 catch (Exception $e)
100 {
101 record_log($e->getMessage().$e->getTraceAsString());
102 throw $e;
103 }
104
105 }
106 /*!\brief compute an array accordingly with the FormVenView function
107 */
108 function compute_array($p_od_id)
109 {
110 $count=0;
111 $array=array();
112 $p_array=$this->load($p_od_id);
113 if (empty($p_array)) return array();
114 foreach ($p_array as $row)
115 {
116 $tmp_array=array("qc_".$count=>'',
117 "poste".$count=>'',
118 "amount".$count=>$row['opd_amount'],
119 'ck'.$count=>$row['opd_debit'],
120 "ld".$count=>$row['opd_comment']
121 );
122
123 if ( $row['opd_qc'] == 't' )
124 $tmp_array['qc_'.$count]=$row['opd_poste'];
125 else
126 $tmp_array['poste'.$count]=$row['opd_poste'];
127
128
129 if ( $row['opd_debit'] == 'f' )
130 unset ($tmp_array['ck'.$count]);
131
132 $array+=$tmp_array;
133 $count++;
134
135 }
136
137 return $array;
138 }
139 /*!\brief load the data from the database and return an array
140 * \return an array
141 */
142 function load($p_od_id)
143 {
144 $sql="select opd_id,opd_poste,opd_amount,opd_debit,opd_comment,".
145 " opd_qc from op_predef_detail where od_id=$1 ".
146 " order by opd_id";
147 $res=$this->db->exec_sql($sql,[$p_od_id]);
149 if ($array == false ) return array();
150 return $array;
151 }
152 /**
153 * Display the form for modifying or adding new predefined operation
154 * @param array $p_array is the result of compute_array or blank
155 * @return string containing HTML code of the form
156 * @throws Exception
157 * @see compute_array
158 * @see load
159 *
160 */
162 {
163 global $g_parameter, $g_user;
164 $legder=new Acc_Ledger($this->db,$p_array['p_jrn']);
165
166 $legder->nb=$legder->get_min_row();
167
168 $add_js = "";
169
170 $ret = "";
171 if ($g_user->check_action(FICADD) == 1)
172 {
173 /* Add button */
174 $f_add_button = new IButton('add_card');
175 $f_add_button->label = _('Créer une nouvelle fiche');
176 $f_add_button->set_attribute('ipopup', 'ipop_newcard');
177 $f_add_button->set_attribute('jrn', $legder->id);
178 $f_add_button->javascript = " this.jrn=\$('p_jrn').value;select_card_type(this);";
179 $f_add_button->input();
180 }
181
182 $nb_row = (isset($p_array['nb_item']) ) ? $p_array['nb_item' ]: $legder->nb;
183
184 $ret.=HtmlInput::hidden('nb_item', $nb_row);
185 $ret.=dossier::hidden();
186
187 $ret.=dossier::hidden();
188
189 $ret.=HtmlInput::hidden('jrn_type', "ODS");
190 $info = Icon_Action::infobulle(0);
191 $info_poste = Icon_Action::infobulle(9);
192 if ($g_user->check_action(FICADD) == 1) $ret.=$f_add_button->input();
193 $ret.='<div class="fieldset" style="overflow:auto;height:400px">';
194 $ret.='<table id="quick_item" style="width:100%">';
195 $ret.='<tr>' .
196 '<th style="text-align:left">Quickcode' . $info . '</th>' .
197 '<th style="text-align:left">' . _('Poste') . $info_poste . '</th>' .
198 '<th style="text-align:left">' . _('Libellé') . '</th>' .
199 '<th style="text-align:left">' . _('Montant') . '</th>' .
200 '<th style="text-align:left">' . _('Débit') . '</th>' .
201 '</tr>';
202
203
204 for ($i = 0; $i < $nb_row; $i++)
205 {
206 // Quick Code
207 $quick_code = new ICard('qc_' . $i);
208 $quick_code->set_dblclick("fill_ipopcard(this);");
209 $quick_code->set_attribute('ipopup', 'ipopcard');
210
211 // name of the field to update with the name of the card
212 $quick_code->set_attribute('label', "ld" . $i);
213 $quick_code->set_attribute('jrn', $legder->id);
214
215 // name of the field to update with the name of the card
216 $quick_code->set_attribute('typecard', 'filter');
217
218 // Add the callback function to filter the card on the jrn
219 $quick_code->set_callback('filter_card');
220 $quick_code->set_function('fill_data');
221 $quick_code->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
222
223 $quick_code->jrn = $legder->id;
224 $quick_code->value = (isset($p_array['qc_' . $i])) ? $p_array['qc_' . $i]: "";
225
226 $label = '';
227 if ($quick_code->value != '')
228 {
229 $Fiche = new Fiche($legder->db);
230 $Fiche->get_by_qcode($quick_code->value);
231 $label = $Fiche->strAttribut(ATTR_DEF_NAME);
232 }
233
234
235 // Account
236 $poste = new IPoste();
237 $poste->name = 'poste' . $i;
238 $poste->set_attribute('jrn', $legder->id);
239 $poste->set_attribute('ipopup', 'ipop_account');
240 $poste->set_attribute('label', 'ld' . $i);
241 $poste->set_attribute('account', 'poste' . $i);
242 $poste->set_attribute('dossier', Dossier::id());
243
244 $poste->value = (isset($p_array['poste' . $i])) ?$p_array['poste' . $i]: ''
245 ;
246 $poste->dbl_click_history();
247
248
249 if ($poste->value != '')
250 {
251 $Poste = new Acc_Account($legder->db);
252 $Poste->find_by_value($poste->value);
253 $label = $Poste->get_lib();
254 }
255
256 // Description of the line
257 $line_desc = new IText();
258 $line_desc->name = 'ld' . $i;
259 $line_desc->size = 30;
260 $line_desc->value = (isset($p_array["ld" . $i])) ? $p_array["ld" . $i] :
261 $label;
262
263 // Amount
264 $amount = new INum();
265 $amount->size = 10;
266 $amount->name = 'amount' . $i;
267 $amount->value = (isset($p_array['amount' . $i])) ?$p_array['amount' . $i] : ''
268 ;
269 $amount->javascript = ' onChange="format_number(this);checkTotalDirect()"';
270 // D/C
271 $deb = new ICheckBox();
272 $deb->name = 'ck' . $i;
273 $deb->selected = (isset($p_array['ck' . $i])) ? true : false;
274 $deb->javascript = ' onChange="checkTotalDirect()"';
275
276 $ret.='<tr>';
277 $ret.='<td>' . $quick_code->input() . $quick_code->search() . '</td>';
278 $ret.='<td>' . $poste->input() .
279 '<script> document.getElementById(\'poste' . $i . '\').onblur=function(){ if (trim(this.value) !=\'\') {document.getElementById(\'qc_' . $i . '\').value="";}}</script>' .
280 '</td>';
281 $ret.='<td>' . $line_desc->input() . '</td>';
282 $ret.='<td>' . $amount->input() . '</td>';
283 $ret.='<td>' . $deb->input() . '</td>';
284 $ret.='</tr>';
285 // If readonly == 1 then show CA
286 }
287 $ret.='</table>';
288 $ret.="</div>";
289 $ret.=Html_Input_Noalyss::ledger_add_item("M");
290 return $ret;
291 }
292}
tr($p_string, $p_extra='')
Definition ac_common.php:88
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
td($p_string='', $p_extra='')
surround the string with td
Definition ac_common.php:83
global $g_parameter
global $g_user
if no group available , then stop
_("actif, passif,charge,...")
Manage the account from the table tmp_pcmn.
Class for jrn, class acc_ledger for manipulating the ledger AND some acc.
static fetch_all($ret)
wrapper for the function pg_fetch_all
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Html Input.
Input HTML for the card show buttons, in the file, you have to add card.js How to use :
Html Input.
This class handles only the numeric input, the input will call a javascript to change comma to period...
show a button, for selecting a account and a input text for manually inserting an account the differe...
Html Input.
static infobulle($p_comment)
Display a info in a bubble, text is in message_javascript.
concerns the predefined operation for the operation from 'Ecriture direct'
compute_array($p_od_id)
compute an array accordingly with the FormVenView function
get_post()
get the post and stove them into data member , before saving them in the db
save($p_od_id, $p_nb_item)
save the detail and op in the database
display($p_array)
Display the form for modifying or adding new predefined operation.
load($p_od_id)
load the data from the database and return an array
mother of the pre_op_XXX, it contains only one data : an object Pre_Operation. The child class contai...
$all table
const ATTR_DEF_NAME
Definition constant.php:216
const FICADD
$_POST['ac']
Definition do.php:312
$count
$SecUser db
for($i=0;$i< $nb_jrn;$i++) $deb