noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_pre_op_advanced.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 require_once NOALYSS_INCLUDE.'/class/class_pre_operation.php';
26 
27 /*---------------------------------------------------------------------- */
28 /*!\brief concerns the predefined operation for the operation from 'Ecriture direct'
29  */
31 {
32  var $op;
33  function __construct($cn)
34  {
35  parent::__construct($cn);
36  $this->operation->od_direct='t';
37  }
38  function get_post()
39  {
40  parent::get_post();
41 
42  extract($_POST, EXTR_SKIP);
43 
44  for ($i=0;$i<$this->operation->nb_item;$i++)
45  {
46  $poste=HtmlInput::default_value_post("poste".$i, null);
47  $qcode=HtmlInput::default_value_post("qc_".$i, 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($_POST['qc_'.$i]) != "")?'t':'f';
59  $this->{'poste'.$i}=trim ($qcode);
60  }
61  $this->{"amount".$i}=$_POST['amount'.$i];
62  $this->{"ck".$i}=(isset($_POST['ck'.$i]))?'t':'f';
63 
64  }
65  }
66  /*!
67  * \brief save the detail and op in the database
68  *
69  */
70  function save()
71  {
72  try
73  {
74  if ($this->operation->save() == false )
75  return;
76  $this->db->start();
77  // save the selling
78  for ($i=0;$i<$this->operation->nb_item;$i++)
79  {
80  if ( ! isset ($this->{"poste".$i}))
81  continue;
82 
83  $sql=sprintf('insert into op_predef_detail (opd_poste,opd_amount,'.
84  'opd_debit,od_id,opd_qc)'.
85  ' values '.
86  "('%s',%.2f,'%s',%d,'%s')",
87  $this->{"poste".$i},
88  $this->{"amount".$i},
89  $this->{"ck".$i},
90  $this->operation->od_id,
91  $this->{'isqc'.$i}
92  );
93 
94  $this->db->exec_sql($sql);
95 
96  }
97  $this->db->commit();
98 
99  }
100  catch (Exception $e)
101  {
102  echo ($e->getMessage());
103  $this->db->rollback();
104  }
105 
106  }
107  /*!\brief compute an array accordingly with the FormVenView function
108  */
109  function compute_array()
110  {
111  $count=0;
112  $a_op=$this->operation->load();
113  $array=$this->operation->compute_array($a_op);
114  $array['desc']=$array['e_comm'];
115  $p_array=$this->load();
116  if (empty($p_array)) return array();
117  foreach ($p_array as $row)
118  {
119  $tmp_array=array("qc_".$count=>'',
120  "poste".$count=>'',
121  "amount".$count=>$row['opd_amount'],
122  'ck'.$count=>$row['opd_debit']
123  );
124 
125  if ( $row['opd_qc'] == 't' )
126  $tmp_array['qc_'.$count]=$row['opd_poste'];
127  else
128  $tmp_array['poste'.$count]=$row['opd_poste'];
129 
130 
131  if ( $row['opd_debit'] == 'f' )
132  unset ($tmp_array['ck'.$count]);
133 
134  $array+=$tmp_array;
135  $count++;
136 
137  }
138 
139  return $array;
140  }
141  /*!\brief load the data from the database and return an array
142  * \return an array
143  */
144  function load()
145  {
146  $sql="select opd_id,opd_poste,opd_amount,opd_debit,".
147  " opd_qc from op_predef_detail where od_id=".$this->operation->od_id.
148  " order by opd_id";
149  $res=$this->db->exec_sql($sql);
151  return $array;
152  }
153  function set_od_id($p_id)
154  {
155  $this->operation->od_id=$p_id;
156  }
157  function display($p_array)
158  {
159  global $g_parameter, $g_user;
160  require_once NOALYSS_INCLUDE.'/class/class_acc_ledger.php';
161  $legder=new Acc_Ledger($this->db,$this->jrn_def_id);
162  $legder->nb=$legder->get_min_row();
163 
164  if ($p_array != null)
165  extract($p_array, EXTR_SKIP);
166  $add_js = "";
167 
168  $ret = "";
169  if ($g_user->check_action(FICADD) == 1)
170  {
171  /* Add button */
172  $f_add_button = new IButton('add_card');
173  $f_add_button->label = _('Créer une nouvelle fiche');
174  $f_add_button->set_attribute('ipopup', 'ipop_newcard');
175  $f_add_button->set_attribute('jrn', $legder->id);
176  $f_add_button->javascript = " this.jrn=\$('p_jrn').value;select_card_type(this);";
177  $f_add_button->input();
178  }
179 
180  $nb_row = (isset($nb_item) ) ? $nb_item : $legder->nb;
181 
182  $ret.=HtmlInput::hidden('nb_item', $nb_row);
183  $ret.=HtmlInput::hidden('p_jrn', $this->jrn_def_id);
184  $ret.=dossier::hidden();
185 
186  $ret.=dossier::hidden();
187 
188  $ret.=HtmlInput::hidden('jrn_type', $legder->get_type());
189  $info = HtmlInput::infobulle(0);
190  $info_poste = HtmlInput::infobulle(9);
191  if ($g_user->check_action(FICADD) == 1)
192  $ret.=$f_add_button->input();
193  $ret.='<table id="quick_item" style="width:100%">';
194  $ret.='<tr>' .
195  '<th style="text-align:left">Quickcode' . $info . '</th>' .
196  '<th style="text-align:left">' . _('Poste') . $info_poste . '</th>' .
197  '<th style="text-align:left">' . _('Libellé') . '</th>' .
198  '<th style="text-align:left">' . _('Montant') . '</th>' .
199  '<th style="text-align:left">' . _('Débit') . '</th>' .
200  '</tr>';
201 
202 
203  for ($i = 0; $i < $nb_row; $i++)
204  {
205  // Quick Code
206  $quick_code = new ICard('qc_' . $i);
207  $quick_code->set_dblclick("fill_ipopcard(this);");
208  $quick_code->set_attribute('ipopup', 'ipopcard');
209 
210  // name of the field to update with the name of the card
211  $quick_code->set_attribute('label', "ld" . $i);
212  $quick_code->set_attribute('jrn', $legder->id);
213 
214  // name of the field to update with the name of the card
215  $quick_code->set_attribute('typecard', 'filter');
216 
217  // Add the callback function to filter the card on the jrn
218  $quick_code->set_callback('filter_card');
219  $quick_code->set_function('fill_data');
220  $quick_code->javascript = sprintf(' onchange="fill_data_onchange(\'%s\');" ', $quick_code->name);
221 
222  $quick_code->jrn = $legder->id;
223  $quick_code->value = (isset(${'qc_' . $i})) ? ${'qc_' . $i} : "";
224 
225  $label = '';
226  if ($quick_code->value != '')
227  {
228  $Fiche = new Fiche($legder->db);
229  $Fiche->get_by_qcode($quick_code->value);
230  $label = $Fiche->strAttribut(ATTR_DEF_NAME);
231  }
232 
233 
234  // Account
235  $poste = new IPoste();
236  $poste->name = 'poste' . $i;
237  $poste->set_attribute('jrn', $legder->id);
238  $poste->set_attribute('ipopup', 'ipop_account');
239  $poste->set_attribute('label', 'ld' . $i);
240  $poste->set_attribute('account', 'poste' . $i);
241  $poste->set_attribute('dossier', Dossier::id());
242 
243  $poste->value = (isset(${'poste' . $i})) ? ${"poste" . $i} : ''
244  ;
245  $poste->dbl_click_history();
246 
247 
248  if ($poste->value != '')
249  {
250  $Poste = new Acc_Account($legder->db);
251  $Poste->set_parameter('value', $poste->value);
252  $label = $Poste->get_lib();
253  }
254 
255  // Description of the line
256  $line_desc = new IText();
257  $line_desc->name = 'ld' . $i;
258  $line_desc->size = 30;
259  $line_desc->value = (isset(${"ld" . $i})) ? ${"ld" . $i} :
260  $label;
261 
262  // Amount
263  $amount = new INum();
264  $amount->size = 10;
265  $amount->name = 'amount' . $i;
266  $amount->value = (isset(${'amount' . $i})) ? ${"amount" . $i} : ''
267  ;
268  $amount->javascript = ' onChange="format_number(this);checkTotalDirect()"';
269  // D/C
270  $deb = new ICheckBox();
271  $deb->name = 'ck' . $i;
272  $deb->selected = (isset(${'ck' . $i})) ? true : false;
273  $deb->javascript = ' onChange="checkTotalDirect()"';
274 
275  $ret.='<tr>';
276  $ret.='<td>' . $quick_code->input() . $quick_code->search() . '</td>';
277  $ret.='<td>' . $poste->input() .
278  '<script> document.getElementById(\'poste' . $i . '\').onblur=function(){ if (trim(this.value) !=\'\') {document.getElementById(\'qc_' . $i . '\').value="";}}</script>' .
279  '</td>';
280  $ret.='<td>' . $line_desc->input() . '</td>';
281  $ret.='<td>' . $amount->input() . '</td>';
282  $ret.='<td>' . $deb->input() . '</td>';
283  $ret.='</tr>';
284  // If readonly == 1 then show CA
285  }
286  $ret.='</table>';
287  return $ret;
288  }
289 }
$_POST['ac']
Definition: do.php:279
static default_value_post($ind, $default)
return default if the value if the value doesn't exist in $_POST
static fetch_all($ret)
wrapper for the function pg_fetch_all
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
static infobulle($p_comment)
const FICADD
Manage the account from the table tmp_pcmn.
show a button, for selecting a account and a input text for manually inserting an account the differe...
save()
save the detail and op in the database
load()
load the data from the database and return an array
compute_array()
compute an array accordingly with the FormVenView function
function document
Definition: smoke.js:7
if(!isset($_REQUEST['act'])||!isset($_REQUEST['jr_id'])||!isset($_REQUEST['div'])) global $g_parameter
Definition: ajax_ledger.php:46
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: class_fiche.php:44
for($i=0;$i<$nb_jrn;$i++) $deb
global $g_user
Find the default module or the first one.
Definition: action.inc.php:24
Class for jrn, class acc_ledger for manipulating the ledger.
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
mother of the pre_op_XXX, it contains only one data : an object Pre_Operation. The child class contai...
static id()
return the $_REQUEST['gDossier'] after a check
$count
Definition: modele.inc.php:255
Input HTML for the card show buttons, in the file, you have to add card.js How to use : ...
tr($p_string, $p_extra='')
Definition: ac_common.php:88
return false
$SecUser db
concerns the predefined operation for the operation from 'Ecriture direct'
$select_type table
const ATTR_DEF_NAME
Definition: constant.php:185
static hidden($p_name, $p_value, $p_id="")
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: class_inum.php:40