Plugins  LAST
 All Data Structures Files Functions Variables Pages
Functions
tool_function.php File Reference

contains functions for tools More...

Go to the source code of this file.

Functions

 check_jrid ()
 check that the array jr_id is not empty More...
 
 change_accounting (&$cn)
 change the accounting in the selected operation More...
 
 change_card_account (&$cn)
 change the accounting in the selected operation by a card (with a possible different accounting More...
 
 change_card (&$cn)
 change the accounting and card in the selected operations More...
 
 change_ledger (&$cn)
 change the ledger for the selected operation More...
 
 display_search_receipt (&$cn)
 display search box More...
 
 display_result_receipt (&$cn)
 display result of search receipt More...
 
 display_download_receipt ()
 
 display_numb_receipt ()
 display the prefix + from number More...
 
 change_receipt (&$cn)
 change the number of receipt More...
 
 download_receipt (Database &$cn)
 Download all receipt. More...
 

Detailed Description

contains functions for tools

Definition in file tool_function.php.

Function Documentation

change_accounting ( $cn)

change the accounting in the selected operation

Parameters
$cndatabase connx
Note
use the $_POST variables
  • sposte accounting source
  • tposte accounting target
  • jr_id[]

Definition at line 53 of file tool_function.php.

References $_REQUEST, $cn, $id, $msg, $row, $source, $target, and check_jrid().

54 {
55  $msg= check_jrid();
56  if( $msg != "")
57  {
58  echo " <p class=\"error\">$msg</p>"; return;
59  }
60  $source=$cn->get_value('select pcm_val from tmp_pcmn where pcm_val=$1',array($_POST['sposte']));
61  $target=$cn->get_value('select pcm_val from tmp_pcmn where pcm_val=$1',array($_POST['tposte']));
62  if ( $source == '' || $target == '')
63  {
64  echo '<p class="error"> Il manque soit le poste comptable source soit le poste comptable destination ou l\'un des deux postes n\'existe pas</p>';
65  return;
66  }
67  $cn->prepare('update_account','update jrnx set j_poste = $1 where j_id in (select j_id from jrnx join jrn on (jr_grpt_id=j_grpt) and jr_id=$2) and j_poste=$3
68  RETURNING j_id ');
69  $cn->prepare('retrieve','select jr_date,jr_comment,jr_montant,jr_internal from jrn where jr_id=$1');
70  echo h2info('Opération changée');
71  echo 'compte : '.$_REQUEST['sposte'].' vers '.$_REQUEST['tposte'];
72  $count=0;
73  echo '<table class="result">';
74  foreach ($_POST['jr_id'] as $id)
75  {
76  $update=$cn->execute('update_account',array(trim($_POST['tposte']),$id,trim($_POST['sposte'])));
77  if ( Database::num_row($update) ==0 ) continue;
78  $feedback=$cn->execute('retrieve',array($id));
79  if ( Database::num_row($feedback) != 0)
80  {
81  $count++;
82  $row=Database::fetch_array($feedback,0);
83  echo '<tr>';
84  echo td(format_date($row['jr_date']));
85  echo td(HtmlInput::detail_op($id,$row['jr_internal']));
86  echo td($row['jr_comment']);
87  echo td(nbm($row['jr_montant'],2,' class="num"'));
88  echo '</tr>';
89  }
90  }
91  echo '</table>';
92  echo '<p> Nombre d\'opérations changées :'.$count.'</p>';
93 }
$msg
for($i=0;$i< Database::num_row($ret);$i++) $row
check_jrid()
check that the array jr_id is not empty
$target
Definition: search_view.php:22
$source
Definition: search_view.php:23
$_REQUEST['sb']
Definition: am_print.php:39
global $cn
change_card ( $cn)

change the accounting and card in the selected operations

Parameters
$cndatabase connx
Note
use the $_POST variables
  • csource accounting source
  • ctarget accounting target
  • jr_id[]

Definition at line 160 of file tool_function.php.

References $_REQUEST, $cn, $id, $msg, $row, $source, $target, and check_jrid().

161 {
162  $msg= check_jrid();
163  if( $msg != "")
164  {
165  echo " <p class=\"error\">$msg</p>"; return;
166  }
167  $source=$cn->get_value('select f_id from fiche_detail where ad_id=23 and ad_value=trim(upper($1))',array($_POST['csource']));
168  $target=$cn->get_value('select f_id from fiche_detail where ad_id=23 and ad_value=trim(upper($1))',array($_POST['ctarget']));
169 
170  if ( $source == '' || $target == '')
171  {
172  echo '<p class="error"> Il manque soit la fiche source soit le fiche destination ou l\'une des deux fiches n\'existe pas</p>';
173  return;
174  }
175  /*
176  *retrieve info about card : accounting
177  */
178  $source_account=$cn->get_value('select ad_value from fiche_detail where ad_id=5 and f_id=$1',array($source));
179  $target_account=$cn->get_value('select ad_value from fiche_detail where ad_id=5 and f_id=$1',array($target));
180 
181  /*
182  * test if accounting valid
183  */
184  if ( $source_account == '' || $target_account == '')
185  {
186  echo '<p class="error"> L\'une des deux fiche n\'a pas de poste comptable</p>';
187  return;
188  }
189 
190  /*
191  *Prepare stmt
192  */
193  $cn->prepare('update_account','update jrnx set f_id = $1, j_poste=$2, j_qcode=trim(upper($3 ))
194  where j_id in (select j_id from jrnx join jrn on (jr_grpt_id=j_grpt) and jr_id=$4) and j_qcode=upper(trim($5)) RETURNING j_id');
195  /*
196  * Change also in quant_sold
197  */
198  $cn->prepare('update_sold_mer','update quant_sold set qs_fiche=$1 where
199  j_id in (select j_id from jrnx join jrn on (jr_grpt_id=j_grpt) and jr_id=$2) and qs_fiche=$3');
200 
201  $cn->prepare('update_sold_cust','update quant_sold set qs_client=$1 where
202  j_id in (select j_id from jrnx join jrn on (jr_grpt_id=j_grpt) and jr_id=$2) and qs_client=$3');
203 
204  /*
205  * Change also in quant_purchase
206  */
207  $cn->prepare('update_pur_mer','update quant_purchase set qp_fiche=$1 where
208  j_id in (select j_id from jrnx join jrn on (jr_grpt_id=j_grpt) and jr_id=$2) and qp_fiche=$3');
209 
210  $cn->prepare('update_pur_cust','update quant_purchase set qp_supplier=$1 where
211  j_id in (select j_id from jrnx join jrn on (jr_grpt_id=j_grpt) and jr_id=$2) and qp_supplier=$3');
212  /*
213  * quant_fin
214  */
215  $cn->prepare('update_fin_bk','update quant_fin set qf_bank=$1 where
216  jr_id=$2 and qf_bank=$3');
217 
218  $cn->prepare('update_fin_oth','update quant_fin set qf_other=$1 where
219  jr_id=$2 and qf_other=$3');
220 
221 
222 
223  $cn->prepare('retrieve','select jr_date,jr_comment,jr_montant,jr_internal,jrn_def_type from jrn join jrn_def on (jr_def_id=jrn_def_id) where jr_id=$1');
224  echo h2info('Opération changée');
225  echo 'Fiche : '.$_REQUEST['csource'].' vers '.$_REQUEST['ctarget'];
226  $count=0;
227  echo '<table class="result">';
228  $cn->start();
229 
230  foreach ($_POST['jr_id'] as $id)
231  {
232  $feedback=$cn->execute('retrieve',array($id));
233  $change_row=Database::num_row($feedback);
234  if ($change_row != 0)
235  {
236  $row=Database::fetch_array($feedback,0);
237  switch ( $row['jrn_def_type'])
238  {
239  case 'VEN':
240  $cn->execute('update_sold_mer',array($target,$id,$source));
241  $cn->execute('update_sold_cust',array($target,$id,$source));
242  break;
243  case 'ACH':
244  $cn->execute('update_pur_mer',array($target,$id,$source));
245  $cn->execute('update_pur_cust',array($target,$id,$source));
246  break;
247  case 'FIN':
248  $cn->execute('update_fin_bk',array($target,$id,$source));
249  $cn->execute('update_fin_oth',array($target,$id,$source));
250  break;
251 
252  }
253  }
254 
255  $update=$cn->execute('update_account',array($target,$target_account,$_POST['ctarget'],$id,$_POST['csource']));
256 
257  if ( Database::num_row($update) ==0 ) continue;
258 
259  if ( $change_row != 0)
260  {
261  $count++;
262 
263  echo '<tr>';
264  echo td(format_date($row['jr_date']));
265  echo td(HtmlInput::detail_op($id,$row['jr_internal']));
266  echo td($row['jr_comment']);
267  echo td(nbm($row['jr_montant']),2,' class="num"');
268  echo '</tr>';
269  }
270 
271  }
272  echo '</table>';
273  $cn->commit();
274  echo '<p> Nombre d\'opérations changée :'.$count.'</p>';
275 }
$msg
for($i=0;$i< Database::num_row($ret);$i++) $row
check_jrid()
check that the array jr_id is not empty
$target
Definition: search_view.php:22
$source
Definition: search_view.php:23
$_REQUEST['sb']
Definition: am_print.php:39
global $cn
change_card_account ( $cn)

change the accounting in the selected operation by a card (with a possible different accounting

Parameters
$cndatabase connx
Note
use the $_POST variables
  • csource1 accounting source
  • ctarget1 card target
  • jr_id[]

Definition at line 102 of file tool_function.php.

References $_REQUEST, $cn, $id, $msg, $row, $source, $target, and check_jrid().

103 {
104  $msg= check_jrid();
105  if( $msg != "")
106  {
107  echo " <p class=\"error\">$msg</p>"; return;
108  }
109  $source=$cn->get_value('select pcm_val from tmp_pcmn where pcm_val=$1',array($_POST['csource1']));
110  $target=$cn->get_value('select f_id from fiche_detail where ad_id=23 and ad_value=trim(upper($1))',array($_POST['ctarget1']));
111 
112  if ( $source == '' || $target == '')
113  {
114  echo '<p class="error"> Il manque soit le poste comptable source soit la fiche destination ou l\'un des deux n\'existe pas</p>';
115  return;
116  }
117 
118  // accounting target
119  $target_account=$cn->get_value('select pcm_val from tmp_pcmn where pcm_val in (select ad_value from fiche_detail where ad_id=5 and f_id=$1)',array($target));
120  if ($target_account == '') {
121  echo '<p class="error"> Le poste comptable de la fiche n\'existe pas</span>';
122  return;
123  }
124  $cn->prepare('update_account','update jrnx set j_poste = $1,j_qcode=upper($2),f_id=$3 where j_id in (select j_id from jrnx join jrn on (jr_grpt_id=j_grpt) and jr_id=$4) and j_poste=$5
125  RETURNING j_id ');
126  $cn->prepare('retrieve','select jr_date,jr_comment,jr_montant,jr_internal from jrn where jr_id=$1');
127  echo h2info('Opération changée');
128  echo 'compte : '.$_REQUEST['sposte'].' vers '.$_REQUEST['tposte'];
129  $count=0;
130  echo '<table class="result">';
131  foreach ($_POST['jr_id'] as $id)
132  {
133  $update=$cn->execute('update_account',array(trim($target_account),trim($_POST['ctarget1']),$target,$id,trim($_POST['csource1'])));
134  if ( Database::num_row($update) ==0 ) continue;
135  $feedback=$cn->execute('retrieve',array($id));
136  if ( Database::num_row($feedback) != 0)
137  {
138  $count++;
139  $row=Database::fetch_array($feedback,0);
140  echo '<tr>';
141  echo td(format_date($row['jr_date']));
142  echo td(HtmlInput::detail_op($id,$row['jr_internal']));
143  echo td($row['jr_comment']);
144  echo td(nbm($row['jr_montant'],2,' class="num"'));
145  echo '</tr>';
146  }
147  }
148  echo '</table>';
149  echo '<p> Nombre d\'opérations changées :'.$count.'</p>';
150 }
$msg
for($i=0;$i< Database::num_row($ret);$i++) $row
check_jrid()
check that the array jr_id is not empty
$target
Definition: search_view.php:22
$source
Definition: search_view.php:23
$_REQUEST['sb']
Definition: am_print.php:39
global $cn
change_ledger ( $cn)

change the ledger for the selected operation

Parameters
$cndatabase connx
Note
use the $_POST variables
  • csource accounting source
  • ctarget accounting target
  • jr_id[]

Definition at line 284 of file tool_function.php.

References $cn, $id, $msg, $row, and check_jrid().

285 {
286  $msg= check_jrid();
287  if( $msg != "")
288  {
289  echo " <p class=\"error\">$msg</p>"; return;
290  }
291  /*
292  * Type must be the same
293  */
294  $type_source=$cn->get_value('select jrn_def_type from jrn_def where jrn_def_id=$1',array($_POST['sledger']));
295  $type_target=$cn->get_value('select jrn_def_type from jrn_def where jrn_def_id=$1',array($_POST['tledger']));
296 
297  if ( $type_target != $type_source)
298  {
299  echo " <p class=\"error\">Les journaux doivent être de même type</p>"; return;
300  }
301  $cn->prepare('update_ledger_x','update jrnx set j_jrn_def = $1 where j_id in (select j_id from jrnx join jrn on (jr_grpt_id=j_grpt) and jr_id=$2) and j_jrn_def=$3
302  RETURNING j_id ');
303  $cn->prepare('update_ledger','update jrn set jr_def_id = $1 where jr_id = $2 and jr_def_id=$3
304  RETURNING jr_id ');
305 
306  $cn->prepare('retrieve','select jr_date,jr_comment,jr_montant,jr_internal from jrn where jr_id=$1');
307  echo h2info('Opération changée');
308  $source_name=$cn->get_value("select '('||jrn_def_type||') '||jrn_def_name from jrn_def where
309  jrn_def_id=$1",array($_POST['sledger']));
310 
311  $target_name=$cn->get_value("select '('||jrn_def_type||') '||jrn_def_name from jrn_def where
312  jrn_def_id=$1",array($_POST['tledger']));
313 
314 
315  echo 'compte : '.$source_name.' vers '.$target_name;
316  $count=0;
317  echo '<table class="result">';
318  $cn->start();
319  foreach ($_POST['jr_id'] as $id)
320  {
321  $update=$cn->execute('update_ledger_x',array(trim($_POST['tledger']),$id,trim($_POST['sledger'])));
322  $cn->execute('update_ledger',array(trim($_POST['tledger']),$id,trim($_POST['sledger'])));
323 
324  if ( Database::num_row($update) ==0 ) continue;
325  $feedback=$cn->execute('retrieve',array($id));
326  if ( Database::num_row($feedback) != 0)
327  {
328  $count++;
329  $row=Database::fetch_array($feedback,0);
330  echo '<tr>';
331  echo td(format_date($row['jr_date']));
332  echo td(HtmlInput::detail_op($id,$row['jr_internal']));
333  echo td($row['jr_comment']);
334  echo td(nbm($row['jr_montant'],2,' class="num"'));
335  echo '</tr>';
336  }
337  }
338  echo '</table>';
339  $cn->commit();
340 
341  echo '<p> Nombre d\'opérations changée'.$count.'</p>';
342 
343 }
$msg
for($i=0;$i< Database::num_row($ret);$i++) $row
check_jrid()
check that the array jr_id is not empty
global $cn
change_receipt ( $cn)

change the number of receipt

Parameters
$cndatabase connx

Definition at line 414 of file tool_function.php.

References $cn, $id, $msg, and check_jrid().

415 {
416  $msg=check_jrid();
417  if ($msg!="")
418  {
419  echo " <p class=\"error\">$msg</p>";
420  return;
421  }
422  $cn->prepare('update_receipt', 'update jrn set jr_pj_number=$1 where jr_id =$2');
423  $start=$_POST['number'];
424  $nb=1;
425  if (trim($start)==""||$_POST['istep']==2)
426  $nb=0;
427 
428  $cn->start();
429  foreach ($_POST['jr_id'] as $id)
430  {
431  if ($nb==1)
432  $pj=trim($_POST['prefix']).sprintf("%d", $start);
433  else
434  $pj=trim($_POST['prefix']);
435  if (trim($pj)=='')
436  $pj=null;
437 
438  $result_update=$cn->execute('update_receipt', array($pj, $id));
439  if ($nb==1)
440  $start++;
441  }
442  $cn->commit();
443 }
$msg
check_jrid()
check that the array jr_id is not empty
global $cn
check_jrid ( )

check that the array jr_id is not empty

Returns
html error string or empty

Definition at line 30 of file tool_function.php.

Referenced by change_accounting(), change_card(), change_card_account(), change_ledger(), and change_receipt().

31 {
32  if (isset($_POST['jr_id']))
33  {
34  if (empty($_POST['jr_id']))
35  {
36  return "Erreur : aucune opération n'est sélectionnée";
37  }
38  }
39  else
40  return "Erreur : aucune opération n'est sélectionnée";
41 
42  return "";
43 }
display_download_receipt ( )

Definition at line 388 of file tool_function.php.

389 {
390  echo HtmlInput::submit('download_receipt','Télécharger',' onclick="$(\'act\').value=\'download\'" ');
391 }
display_numb_receipt ( )

display the prefix + from number

Note
use the variable from $_GET

Definition at line 396 of file tool_function.php.

References $hidden.

397 {
398  $prefix=new IText('prefix');
399  $number=new INum('number');
400  $submit=HtmlInput::submit('chg_receipt','Valider',' onclick="$(\'act\').value=\'numbering\'" ');
401  $hidden=HtmlInput::get_to_hidden(array('ledger','dend','dstart'));
402  $with_step=new ISelect('istep');
403  $with_step->value=array(
404  array('value'=>1,'label'=>'Non'),
405  array('value'=>2,'label'=>'Oui')
406  );
407 
408  require_once('template/numbering.php');
409 }
display_result_receipt ( $cn)

display result of search receipt

Parameters
$cndatabase connx
Note
from $_REQUEST retrieve dstart,dend and ledger

Definition at line 373 of file tool_function.php.

References $checkbox, $cn, $nb_row, $ret, and $sql.

374 {
375  $sql="select jr_id,jr_internal,to_char(jr_date,'DD.MM.YY') as str_date, jr_date,jr_montant,jr_comment,jr_pj_number
376  from jrn
377  where
378  jr_def_id=$1 and jr_date >= to_date($2,'DD.MM.YYYY')
379  and jr_date <= to_date($3,'DD.MM.YYYY')
380  order by jr_date asc,substring(jr_pj_number,'[0-9]+$')::numeric asc
381  ";
382  $ret=$cn->exec_sql($sql,array($_GET['ledger'],$_GET['dstart'],$_GET['dend']));
383  $nb_row=Database::num_row($ret);
384  $checkbox=new ICheckBox('jr_id[]');
385 
386  require_once('template/result_receipt.php');
387 }
$ret
$checkbox
Definition: search_view.php:8
$nb_row
Definition: search_view.php:6
$sql
global $cn
display_search_receipt ( $cn)

display search box

Parameters
$cndatabase connx

Definition at line 349 of file tool_function.php.

References $array, $cn, $hidden, and $sql.

350 {
351  $idate_start=new IDate('dstart');
352  $idate_start->value=HtmlInput::default_value('dstart','',$_GET);
353  $idate_end=new IDate('dend');
354  $idate_end->value=HtmlInput::default_value('dend','',$_GET);
355 
356  $sql="select jrn_def_id, '('||jrn_def_type||') '||jrn_def_name from jrn_def order by jrn_def_name asc";
357  $array=$cn->make_array($sql);
358  $iledger=new ISelect('ledger');
359  $iledger->value=$array;
360  $iledger->selected=HtmlInput::default_value('ledger','',$_GET);
361 
362  $hidden=HtmlInput::get_to_hidden(array('sa','plugin_code','gDossier'));
363 
364  $submit=HtmlInput::submit('search','Rechercher');
365  $hide= HtmlInput::button('accounting_hide_bt','Annuler','onclick="$(\'div_receipt\').hide();"');
366  require_once('template/search_box.php');
367 }
if(isset($_POST['remove'])) $array
$sql
global $cn
download_receipt ( Database &  $cn)

Download all receipt.

Parameters
type$cn

Definition at line 449 of file tool_function.php.

References $_REQUEST, $date, $file, $res, $row, id, and style.

450 {
451  $dirname=tempnam($_ENV['TMP'], 'receipt');
452  unlink($dirname);
453  mkdir($dirname);
454  $cn->start();
455  $feedback=array();
456  $jr_id = HtmlInput::default_value_post('jr_id',array());
457  if (empty ($jr_id ) ) {
458  echo '<div class="notice">'._('Aucune opération sélectionnée').'</div>';
459  return;
460  }
461 //--- take all the invoice
462  foreach ( $_POST['jr_id'] as $value)
463  {
464  $a_invoice=$cn->get_array("select jr_pj_name,jr_pj from jrn where jr_id = $1", array($value));
465  $invoice=$a_invoice[0];
466  if ($invoice['jr_pj_name']!=""&&$invoice['jr_pj']!="")
467  {
468  $file=$dirname.'/'.$invoice['jr_pj_name'];
469  $cn->lo_export($invoice['jr_pj'], $file);
470  $feedback[]=_('Ajout pièce ').$invoice['jr_pj_name'];
471  }
472  }
473 // -- zip file
474  $date=date('ymd.Hi');
475  $zip_file=$_ENV['TMP']."/"."receipt-".$date.".zip";
476 
477 // --- create the zip
478  $zip=new Zip_Extended();
479  $res=$zip->open($zip_file, ZipArchive::CREATE);
480  if ($res!=true)
481  {
482  die("Cannot create zip file");
483  }
484  $zip->add_recurse_folder($dirname."/");
485  $zip->close();
486 //-- send the zip
487  $link=http_build_query(array('gDossier'=>Dossier::id(), 'ac'=>$_REQUEST['ac'], 'plugin_code'=>$_REQUEST['plugin_code'],'act'=>'download_receipt', 'file'=>basename($zip_file)));
488  ?>
489  <p>
490  <h2>
491  <?php echo _('Pièce'); ?>
492  </h2>
493  <ol>
494  <?php foreach ($feedback as $row): ?>
495 
496  <li>
497  <?php echo $row ?>
498  </li>
499  <?php endforeach; ?>
500  </ol>
501  </p>
502  <p>
503  <a class="button" style="display:inline;" href="extension.raw.php?<?php echo $link; ?>"> <?php echo _('Télécharger le fichier') ?></a>
504  </p>
505  <?php
506 }
$note style
$select_type id
for($i=0;$i< Database::num_row($ret);$i++) $row
$res
$_REQUEST['sb']
Definition: am_print.php:39
$file
Definition: import_bank.php:60
global $cn