noalyss Version-9
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
35*/
37{
38 private static $variable=array("id"=>"tva_id",
39 "label"=>"tva_label",
40 "rate"=>"tva_rate",
41 "comment"=>"tva_comment",
42 "account"=>"tva_poste",
43 "both_side"=>'tva_both_side',
44 'tva_reverse_account'=>'tva_reverse_account',
45 'tva_code'=>'tva_code');
46 public $tva_id,
54
55 private $cn; //!< Database connection
56
58
59 function __construct ($p_init,$p_tva_id=-1)
60 {
61 $this->cn=$p_init;
62 $this->tva_rate_sql=new Tva_Rate_SQL($p_init,$p_tva_id);
63 $this->tva_id=$p_tva_id;
64 $this->tva_label=&$this->tva_rate_sql->tva_label;
65 $this->tva_rate=&$this->tva_rate_sql->tva_rate;
66 $this->tva_comment=&$this->tva_rate_sql->tva_comment;
67 $this->tva_poste=&$this->tva_rate_sql->tva_poste;
68 $this->tva_both_side=&$this->tva_rate_sql->tva_both_side;
69 $this->tva_code=&$this->tva_rate_sql->tva_code;
70 $this->tva_reverse_account=&$this->tva_rate_sql->tva_reverse_account;
71
72 }
73 /**
74 * @return Tva_Rate_SQL
75 */
76 public function getTvaRateSql(): Tva_Rate_SQL
77 {
79 }
80
81 /**
82 * @param Tva_Rate_SQL $tva_rate_sql
83 */
85 {
86 $this->tva_rate_sql = $tva_rate_sql;
87 return $this;
88 }
89
90 public function get_parameter($p_string)
91 {
92 if ( array_key_exists($p_string,self::$variable) )
93 {
94 $idx=self::$variable[$p_string];
95 return $this->$idx;
96 }
97
98 throw new Exception("ACC98"."Attribut inexistant $p_string",EXC_INVALID);
99 }
100 public function set_parameter($p_string,$p_value)
101 {
102 if ( array_key_exists($p_string,self::$variable) )
103 {
104 $idx=self::$variable[$p_string];
105 $this->$idx=$p_value;
106 }
107 else
108 throw new Exception("ACC108"."Attribut inexistant $p_string",EXC_INVALID);
109
110
111 }
112
113 /**
114 *@brief Load the VAT, return 0 if the TVA_ID exists otherwise -1
115 *@note if the label is not found then we get an message error, so the best is probably
116 *to initialize the VAT object with default value
117 *
118 */
119 public function load():int
120 {
121 $this->tva_rate_sql->setp("tva_id",$this->tva_id);
122
123 if ( ! $this->tva_rate_sql->load() ) return -1;
124 return 0;
125 }
126 /*!\brief get the account of the side (debit or credit)
127 *\param $p_side is d or C
128 *\return the account to use
129 *\note call first load if tva_poste is empty
130 */
131 public function get_side($p_side)
132 {
133 if ( strlen($this->tva_poste??"") == 0 ) $this->load();
134 list($deb,$cred)=explode(",",$this->tva_poste);
135 switch ($p_side)
136 {
137 case 'd':
138 return $deb;
139 break;
140 case 'c':
141 return $cred;
142 break;
143 default:
144 throw (new Exception (__FILE__.':'.__LINE__." param est d ou c, on a recu [ $p_side ]"));
145 }
146 }
147
148 /**
149 * @brief retrieve TVA rate thanks the code that could be the tva_id or tva_code. Check first if p_code is a
150 * TVA_CODE and if not, check if it is a TVA_ID
151 * @param $db Database connection
152 * @param $p_code either tva_id or tva_code
153 * @return Acc_Tva or Acc_TVA with tva_id=-1
154 */
155 static function build($db,$p_code):Acc_Tva {
156 if (empty($p_code)) return new Acc_Tva($db,-1);
157 $tva_id = $db->get_value("select tva_id from public.tva_rate where tva_code=upper(trim($1))",[$p_code]);
158 if ( $db->size() == 1) {
159 return new Acc_Tva($db,$tva_id);
160 }
161 if (isNumber($p_code) == 0) return new Acc_Tva($db,-1);
162 $exist = $db->get_value("select count(*) from public.tva_rate where tva_id=$1",[$p_code]);
163 if ( $exist == 1) {
164 return new Acc_Tva($db,$p_code);
165 }
166 return new Acc_Tva($db,-1);
167
168 }
169}
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($p_init, $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
const EXC_INVALID
Definition constant.php:346
for($i=0;$i< $nb_jrn;$i++) $deb