Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_impacc_tool.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * Copyright (C) 2016 Dany De Bontridder <dany@alchimerys.be>
5  *
6  * This program 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 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 //!\file
21 //!\brief usefull static functions
22 
23 
24 require_once NOALYSS_INCLUDE."/class/class_acc_ledger.php";
25 require_once NOALYSS_INCLUDE."/class/class_acc_ledger_fin.php";
26 require_once NOALYSS_INCLUDE."/class/class_acc_ledger_purchase.php";
27 require_once NOALYSS_INCLUDE."/class/class_acc_ledger_sold.php";
28 /// Different tools used directly by the objects , some parts of this code should
29 /// Move to the right class in a later development
31 {
32 
33  /// Factory pattern to get a ledger of the right type
34  /// based on $p_jrn_def_id which is the id of the table jrn_def
35  /// This code should be moved to Acc_Ledger
36  //!\param $p_jrn_def_id is the id of the ledger
37  //!\return Acc_Ledger , Acc_Ledger_Purchase , Acc_Ledger_Fin or Acc_Ledger_Sold
38  //!\exception Exception if no ledger is found
39  static function ledger_factory($p_jrn_def_id)
40  {
41  $cn=Dossier::connect();
42  $tmp=new Acc_Ledger($cn, $p_jrn_def_id);
43  $ledger=null;
44  switch ($tmp->get_type())
45  {
46  case "ACH":
47  $ledger=new Acc_Ledger_Purchase($cn, $p_jrn_def_id);
48  break;
49  case "ODS":
50  $ledger=new Acc_Ledger($cn, $p_jrn_def_id);
51  break;
52  case "VEN":
53  $ledger=new Acc_Ledger_Sold($cn, $p_jrn_def_id);
54  break;
55  case "FIN":
56  $ledger=new Acc_Ledger_Fin($cn, $p_jrn_def_id);
57  break;
58 
59  default:
60  throw new Exception(_("journal inconnu"), 1);
61  break;
62  }
63  return $ledger;
64  }
65  /// Mark a group of rows transferred as a single operation
66  //!\param $p_code_group is import_detail::id_code_group
67  //!\param $p_import_id import id (import_file.id = import_detail.import_id)
68  static function mark_group_transferred($p_code_group,$p_import_id)
69  {
70  $cn=Dossier::connect();
71  $sql=" update impacc.import_detail set id_status=2 where id_code_group=$1 and import_id=$2 ";
72  $cn->exec_sql($sql, array($p_code_group,$p_import_id));
73  }
74  ///convert_amount($array[$i]->id_amount_novat,$this->detail->s_thousand,$this->s_decimal);
75  static function convert_amount($p_amount,$p_thousand,$p_decimal)
76  {
77  if ( $p_thousand == 1) $p_amount=str_replace(',', '', $p_amount);
78  if ( $p_thousand == 2) $p_amount=str_replace('.', '', $p_amount);
79  if ($p_decimal == 1) $p_amount=str_replace(',', '.', $p_amount);
80  return $p_amount;
81  }
82 
83  /// Find the correct TVA from the table impacc.parameter_tva
84  //!\param $p_code is the tva code from the file
85  static function convert_tva($p_code)
86  {
87  $cn=Dossier::connect();
88  $tva_id=$cn->get_value("select tva_id from impacc.parameter_tva where tva_code=$1",array($p_code));
89  return $tva_id;
90  }
91 }
Different tools used directly by the objects , some parts of this code should Move to the right class...
static convert_amount($p_amount, $p_thousand, $p_decimal)
convert_amount($array[$i]->id_amount_novat,$this->detail->s_thousand,$this->s_decimal); ...
static convert_tva($p_code)
Find the correct TVA from the table impacc.parameter_tva.
static mark_group_transferred($p_code_group, $p_import_id)
Mark a group of rows transferred as a single operation.
static ledger_factory($p_jrn_def_id)
Factory pattern to get a ledger of the right type based on $p_jrn_def_id which is the id of the table...
$sql
global $cn