[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * 5 * This program 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 * This program 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 this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: tva.class.php,v 1.12 2005/11/20 19:44:07 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/tva.class.php,v $ 21 */ 22 23 /** 24 \file htdocs/tva.class.php 25 \ingroup compta 26 \brief Fichier de la classe de tva 27 \remarks La tva collectée n'est calculée que sur les factures payées. 28 \version $Revision: 1.12 $ 29 */ 30 31 32 /** \class Tva 33 \brief Classe permettant la gestion de la tva 34 */ 35 36 class Tva 37 { 38 var $db; 39 var $note; 40 41 /* 42 * \brief Constructeur 43 * \param DB Handler d'accès base 44 */ 45 function Tva($DB) 46 { 47 $this->db = $DB; 48 49 return 1; 50 } 51 52 /* 53 * \brief Hum la fonction s'appelle 'Solde' elle doit a mon avis calcluer le solde de TVA, non ? 54 * 55 */ 56 function solde($year = 0) 57 { 58 59 $reglee = $this->tva_sum_reglee($year); 60 61 $payee = $this->tva_sum_payee($year); 62 $collectee = $this->tva_sum_collectee($year); 63 64 $solde = $reglee - ($collectee - $payee) ; 65 66 return $solde; 67 } 68 69 /* 70 * \brief Total de la TVA des factures emises par la societe. 71 * 72 */ 73 74 function tva_sum_collectee($year = 0) 75 { 76 77 $sql = "SELECT sum(f.tva) as amount"; 78 $sql .= " FROM ".MAIN_DB_PREFIX."facture as f WHERE f.paye = 1"; 79 80 if ($year) 81 { 82 $sql .= " AND f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' "; 83 } 84 85 $result = $this->db->query($sql); 86 87 if ($result) 88 { 89 if ($this->db->num_rows()) 90 { 91 $obj = $this->db->fetch_object($result); 92 return $obj->amount; 93 } 94 else 95 { 96 return 0; 97 } 98 99 $this->db->free(); 100 101 } 102 else 103 { 104 print $this->db->error(); 105 return -1; 106 } 107 } 108 109 /* 110 * \brief Tva payée 111 * 112 */ 113 114 function tva_sum_payee($year = 0) 115 { 116 117 $sql = "SELECT sum(f.total_tva) as total_tva"; 118 $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; 119 120 if ($year) 121 { 122 $sql .= " WHERE f.datef >= '$year-01-01' AND f.datef <= '$year-12-31' "; 123 } 124 $result = $this->db->query($sql); 125 126 if ($result) 127 { 128 if ($this->db->num_rows()) 129 { 130 $obj = $this->db->fetch_object($result); 131 return $obj->total_tva; 132 } 133 else 134 { 135 return 0; 136 } 137 138 $this->db->free(); 139 140 } 141 else 142 { 143 print $this->db->error(); 144 return -1; 145 } 146 } 147 148 149 /* 150 * \brief Tva réglée 151 * Total de la TVA réglee aupres de qui de droit 152 * 153 */ 154 155 function tva_sum_reglee($year = 0) 156 { 157 158 $sql = "SELECT sum(f.amount) as amount"; 159 $sql .= " FROM ".MAIN_DB_PREFIX."tva as f"; 160 161 if ($year) 162 { 163 $sql .= " WHERE f.datev >= '$year-01-01' AND f.datev <= '$year-12-31' "; 164 } 165 166 $result = $this->db->query($sql); 167 168 if ($result) 169 { 170 if ($this->db->num_rows()) 171 { 172 $obj = $this->db->fetch_object($result); 173 return $obj->amount; 174 } 175 else 176 { 177 return 0; 178 } 179 180 $this->db->free(); 181 182 } 183 else 184 { 185 print $this->db->error(); 186 return -1; 187 } 188 } 189 190 191 /* 192 * \brief Ajoute un paiement de TVA 193 */ 194 195 function add_payement($user) 196 { 197 global $conf,$langs; 198 199 $this->db->begin(); 200 201 // Validation parameteres 202 $this->amount=price2num($this->amount); 203 if ($conf->banque->enabled) 204 { 205 if (! $this->accountid) 206 { 207 $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Account")); 208 return -3; 209 } 210 } 211 if ($this->amount <= 0) 212 { 213 $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Amount")); 214 return -4; 215 } 216 217 // Insertion dans table des paiement tva 218 $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva (datep, datev, amount"; 219 if ($this->note) $sql.=", note"; 220 if ($this->label) $sql.=", label"; 221 $sql.= ") "; 222 $sql.= " VALUES ('".$this->db->idate($this->datep)."',"; 223 $sql.= "'".$this->db->idate($this->datev)."'," . $this->amount; 224 if ($this->note) $sql.=", '".addslashes($this->note)."'"; 225 if ($this->label) $sql.=", '".addslashes($this->label)."'"; 226 $sql.= ")"; 227 228 $result = $this->db->query($sql); 229 if ($result) 230 { 231 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."tva"); // \todo devrait s'appeler paiementtva 232 if ($this->id > 0) 233 { 234 if ($conf->banque->enabled) 235 { 236 // Insertion dans llx_bank 237 238 require_once (DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php'); 239 240 $acc = new Account($this->db, $this->accountid); 241 $bank_line_id = $acc->addline($this->db->idate($this->datep), $this->paymenttype, $this->label, -abs($this->amount), '', '', $user); 242 243 // Mise a jour fk_bank dans llx_paiementtva. On connait ainsi la ligne de tva qui a généré l'écriture bancaire 244 if ($bank_line_id) { 245 // $tva->update_fk_bank($bank_line_id); 246 } 247 248 // Mise a jour liens (pour chaque charge concernée par le paiement) 249 //foreach ($paiement->amounts as $key => $value) 250 //{ 251 // $chid = $key; 252 // $fac = new Facture($db); 253 // $fac->fetch($chid); 254 // $fac->fetch_client(); 255 // $acc->add_url_line($bank_line_id, $paiement_id, DOL_URL_ROOT.'/compta/paiement/fiche.php?id=', "(paiement)"); 256 // $acc->add_url_line($bank_line_id, $fac->client->id, DOL_URL_ROOT.'/compta/fiche.php?socid=', $fac->client->nom); 257 //} 258 } 259 $this->db->commit(); 260 return $this->id; 261 } 262 else 263 { 264 $this->error=$this->db->error(); 265 $this->db->rollback(); 266 return -2; 267 } 268 } 269 else 270 { 271 $this->error=$this->db->error(); 272 $this->db->rollback(); 273 return -1; 274 } 275 } 276 } 277 278 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |