[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004 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: chargesociales.class.php,v 1.13 2005/07/10 19:31:44 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/chargesociales.class.php,v $ 21 */ 22 23 /** 24 \file htdocs/chargesociales.class.php 25 \ingroup facture 26 \brief Fichier de la classe des charges sociales 27 \version $Revision: 1.13 $ 28 */ 29 30 31 /** \class PaiementCharge 32 \brief Classe permettant la gestion des paiements des charges 33 */ 34 class PaiementCharge { 35 var $db; 36 37 var $id; 38 var $chid; 39 var $paiementtype; 40 var $datepaye; 41 var $amounts; 42 var $num_paiement; 43 var $note; 44 45 function PaiementCharge($DB) { 46 $this->db = $DB; 47 return 1; 48 } 49 50 /** 51 * \brief Creation d'un paiement de charge sociale 52 * \param user Utilisateur qui crée le paiement 53 * \return int <0 si erreur, >0 si ok 54 */ 55 function create($user) { 56 $sql_err = 0; 57 /* 58 * Insertion dans la base 59 */ 60 if ($this->db->begin()) 61 { 62 $total = 0; 63 foreach ($this->amounts as $key => $value) 64 { 65 $facid = $key; 66 $value = trim($value); 67 $amount = round(ereg_replace(",",".",$value), 2); // Un round est ok si nb avec '.' 68 if (is_numeric($amount)) $total += $amount; 69 } 70 $total = ereg_replace(",",".",$total); 71 72 if ($total > 0) 73 { 74 $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount, fk_typepaiement, num_paiement, note, fk_user_creat)"; 75 $sql .= " VALUES ($this->chid, now(), $this->datepaye, '$total', $this->paiementtype, '$this->num_paiement', '$this->note', $user->id)"; 76 77 if ( $this->db->query($sql) ) 78 { 79 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."paiementcharge"); 80 } 81 else 82 { 83 $sql_err++; 84 dolibarr_syslog("chargessociales::create Echec $sql"); 85 } 86 87 } 88 89 if ($total > 0 && $sql_err == 0) 90 { 91 $this->db->commit(); 92 return $this->id; 93 } 94 else 95 { 96 $this->db->rollback(); 97 return -1; 98 } 99 100 } 101 } 102 103 /** 104 * \brief Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank générée 105 * \param id_bank Id de la banque 106 * \return int 1 ou 0 107 */ 108 function update_fk_bank($id_bank) { 109 $sql = "UPDATE llx_paiementcharge set fk_bank = ".$id_bank." where rowid = ".$this->id; 110 $result = $this->db->query($sql); 111 if ($result) 112 { 113 return 1; 114 } 115 else 116 { 117 print $this->db->error() ."<br>".$sql; 118 return 0; 119 } 120 } 121 } 122 123 124 /** \class ChargeSociales 125 \brief Classe permettant la gestion des paiements des charges 126 La tva collectée n'est calculée que sur les factures payées. 127 */ 128 class ChargeSociales { 129 var $db; 130 131 var $id; 132 var $date_ech; 133 var $date_pai; 134 var $lib; 135 var $type; 136 var $type_libelle; 137 var $amount; 138 var $paye; 139 var $periode; 140 141 function ChargeSociales($DB) { 142 $this->db = $DB; 143 144 return 1; 145 } 146 147 /** 148 * \brief Retrouve et charge une charge sociale 149 * \return int 1 si trouve, 0 sinon 150 */ 151 function fetch($id) { 152 $sql = "SELECT cs.rowid,".$this->db->pdate("cs.date_ech")." as date_ech,".$this->db->pdate("cs.date_pai")." as date_pai"; 153 $sql .=", cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, ".$this->db->pdate("cs.periode")." as periode, c.libelle"; 154 $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as cs, ".MAIN_DB_PREFIX."c_chargesociales as c"; 155 $sql .= " WHERE cs.fk_type = c.id"; 156 $sql .=" AND cs.rowid = ".$id; 157 158 if ($this->db->query($sql)) 159 { 160 if ($this->db->num_rows()) 161 { 162 $obj = $this->db->fetch_object(); 163 164 $this->id = $obj->rowid; 165 $this->date_ech = $obj->date_ech; 166 $this->date_pai = $obj->date_pai; 167 $this->lib = $obj->lib; 168 $this->type = $obj->fk_type; 169 $this->type_libelle = $obj->libelle; 170 $this->amount = $obj->amount; 171 $this->paye = $obj->paye; 172 $this->periode = $obj->periode; 173 174 return 1; 175 } 176 else 177 { 178 return 0; 179 } 180 $this->db->free(); 181 } 182 else 183 { 184 print $this->db->error(); 185 return 0; 186 } 187 } 188 189 function solde($year = 0) { 190 191 $sql = "SELECT sum(f.amount) as amount"; 192 $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f WHERE paye = 0"; 193 194 if ($year) { 195 $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' "; 196 } 197 198 $result = $this->db->query($sql); 199 200 if ($result) { 201 if ($this->db->num_rows()) { 202 $obj = $this->db->fetch_object(); 203 return $obj->amount; 204 } else { 205 return 0; 206 } 207 208 $this->db->free(); 209 210 } else { 211 print $this->db->error(); 212 return -1; 213 } 214 } 215 216 /** 217 * \brief Tag la charge comme payée complètement 218 * \param rowid id de la ligne a modifier 219 */ 220 function set_payed($rowid) 221 { 222 $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales set paye=1 WHERE rowid = $rowid ;"; 223 $return = $this->db->query( $sql); 224 } 225 226 227 /** 228 * \brief Renvoi le staut de la charge sous forme de libellé 229 * \return string libellé du statut 230 */ 231 function getLibStatut() { 232 global $langs; 233 234 if ($this->paye == 0) { return $langs->trans("Unpayed"); } 235 else { return $langs->trans("Payed"); } 236 } 237 } 238 239 ?>
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 |
![]() |