noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
acc_tva.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 this class is used for the table tva_rate
24 */
25
26/*!\brief Acc_Tva is used for to map the table tva_rate
27 * parameter are
28- private static $cn; database connection
29- private static $variable=array("id"=>"tva_id",
30 "label"=>"tva_label",
31 "rate"=>"tva_rate",
32 "comment"=>"tva_comment",
33 "account"=>"tva_poste"
34 tva_peppol_code
35 'vx_code'
36 * );
37
38*/
40{
41 private static $variable=array("id"=>"tva_id",
42 "label"=>"tva_label",
43 "rate"=>"tva_rate",
44 "comment"=>"tva_comment",
45 "account"=>"tva_poste",
46 "both_side"=>'tva_both_side',
47 'tva_reverse_account'=>'tva_reverse_account',
48 'tva_code'=>'tva_code',
49 "tva_peppol_code"=>"tva_peppol_code",
50 'vx_code'=>'vx_code'
51
52 );
53 public $tva_id,
63 ;
64
65 private $cn; //!< Database connection
66
68
69 function __construct (Database $cn,$p_tva_id=-1)
70 {
71 $this->cn=$cn;
72 $this->tva_rate_sql=new Tva_Rate_SQL($cn,$p_tva_id);
73 $this->tva_id=$p_tva_id;
74 $this->tva_label=&$this->tva_rate_sql->tva_label;
75 $this->tva_rate=&$this->tva_rate_sql->tva_rate;
76 $this->tva_comment=&$this->tva_rate_sql->tva_comment;
77 $this->tva_poste=&$this->tva_rate_sql->tva_poste;
78 $this->tva_both_side=&$this->tva_rate_sql->tva_both_side;
79 $this->tva_code=&$this->tva_rate_sql->tva_code;
80 $this->tva_reverse_account=&$this->tva_rate_sql->tva_reverse_account;
81 $this->tva_peppol_code=&$this->tva_rate_sql->tva_peppol_code;
82 $this->vx_code=&$this->tva_rate_sql->vx_code;
83
84 }
85 /**
86 * @return Tva_Rate_SQL
87 */
88 public function getTvaRateSql(): Tva_Rate_SQL
89 {
91 }
92
93 /**
94 * @param Tva_Rate_SQL $tva_rate_sql
95 */
97 {
98 $this->tva_rate_sql = $tva_rate_sql;
99 return $this;
100 }
101
102 public function get_parameter($p_string)
103 {
104 if ( array_key_exists($p_string,self::$variable) )
105 {
106 $idx=self::$variable[$p_string];
107 return $this->$idx;
108 }
109
110 throw new Exception("ACC98"."Attribut inexistant $p_string",EXC_INVALID);
111 }
112 public function set_parameter($p_string,$p_value)
113 {
114 if ( array_key_exists($p_string,self::$variable) )
115 {
116 $idx=self::$variable[$p_string];
117 $this->$idx=$p_value;
118 }
119 else
120 throw new Exception("ACC108"."Attribut inexistant $p_string",EXC_INVALID);
121
122
123 }
124
125 /**
126 *@brief Load the VAT, return 0 if the TVA_ID exists otherwise -1
127 *@note if the label is not found then we get an message error, so the best is probably
128 *to initialize the VAT object with default value
129 *
130 */
131 public function load():int
132 {
133 $this->tva_rate_sql->setp("tva_id",$this->tva_id);
134
135 if ( ! $this->tva_rate_sql->load() ) return -1;
136 return 0;
137 }
138 /*!\brief get the account of the side (debit or credit)
139 *\param $p_side is d or C
140 *\return the account to use
141 *\note call first load if tva_poste is empty
142 */
143 public function get_side($p_side)
144 {
145 if ( strlen($this->tva_poste??"") == 0 ) $this->load();
146 list($deb,$cred)=explode(",",$this->tva_poste);
147 switch ($p_side)
148 {
149 case 'd':
150 return $deb;
151 break;
152 case 'c':
153 return $cred;
154 break;
155 default:
156 throw (new Exception (__FILE__.':'.__LINE__." param est d ou c, on a recu [ $p_side ]"));
157 }
158 }
159
160 /**
161 * @brief retrieve TVA rate thanks the code that could be the tva_id or tva_code. Check first if p_code is a
162 * TVA_CODE and if not, check if it is a TVA_ID
163 * @param $db Database connection
164 * @param $p_code either tva_id or tva_code
165 * @return Acc_Tva or Acc_TVA with tva_id=-1
166 */
167 static function build($db,$p_code):Acc_Tva {
168 if (empty($p_code)) return new Acc_Tva($db,-1);
169 $tva_id = $db->get_value("select tva_id from public.tva_rate where tva_code=upper(trim($1))",[$p_code]);
170 if ( $db->size() == 1) {
171 return new Acc_Tva($db,$tva_id);
172 }
173 if (isNumber($p_code) == 0) return new Acc_Tva($db,-1);
174 $exist = $db->get_value("select count(*) from public.tva_rate where tva_id=$1",[$p_code]);
175 if ( $exist == 1) {
176 return new Acc_Tva($db,$p_code);
177 }
178 return new Acc_Tva($db,-1);
179
180 }
181}
isNumber($p_int)
if(!headers_sent())
– pour utiliser unoconv démarrer un server libreoffice commande libreoffice –headless –accept="socket...
$input_from cn
Acc_Tva is used for to map the table tva_rate parameter are.
setTvaRateSql(Tva_Rate_SQL $tva_rate_sql)
static build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
__construct(Database $cn, $p_tva_id=-1)
set_parameter($p_string, $p_value)
static $variable
get_parameter($p_string)
load()
Load the VAT, return 0 if the TVA_ID exists otherwise -1.
get_side($p_side)
get the account of the side (debit or credit)
$cn
Database connection.
Tva_Rate_SQL $tva_rate_sql
contains the class for connecting to Noalyss
const EXC_INVALID
Definition constant.php:358
for($i=0;$i< $nb_jrn;$i++) $deb