[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004 Éric Seigne <eric.seigne@ryxeo.com> 4 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 5 * Copyright (C) 2004 Christophe Combelles <ccomb@free.fr> 6 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com> 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 * 22 * $Id: paiement.php,v 1.34 2005/12/03 04:15:45 eldy Exp $ 23 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/fourn/facture/paiement.php,v $ 24 */ 25 26 /** 27 \file htdocs/fourn/facture/paiement.php 28 \ingroup fournisseur,facture 29 \brief Paiements des factures fournisseurs 30 \version $Revision: 1.34 $ 31 */ 32 33 34 require ('./pre.inc.php'); 35 require ('./paiementfourn.class.php'); 36 37 $langs->load('bills'); 38 $langs->load('banks'); 39 40 $facid=isset($_GET['facid'])?$_GET['facid']:$_POST['facid']; 41 $action=isset($_GET['action'])?$_GET['action']:$_POST['action']; 42 43 $sortfield = isset($_GET['sortfield'])?$_GET['sortfield']:$_POST['sortfield']; 44 $sortorder = isset($_GET['sortorder'])?$_GET['sortorder']:$_POST['sortorder']; 45 $page=isset($_GET['page'])?$_GET['page']:$_POST['page']; 46 47 48 /* 49 * Sécurité accés client 50 */ 51 if ($user->societe_id > 0) 52 { 53 $action = ''; 54 $socidp = $user->societe_id; 55 } 56 /* 57 * Actions 58 */ 59 if ($action == 'add_paiement') 60 { 61 $error = 0; 62 63 $datepaye = $db->idate(mktime(12, 0 , 0, 64 $_POST['remonth'], 65 $_POST['reday'], 66 $_POST['reyear'])); 67 $paiement_id = 0; 68 $total = 0; 69 // Génère tableau des montants amounts 70 $amounts = array(); 71 foreach ($_POST as $key => $value) 72 { 73 if (substr($key,0,7) == 'amount_') 74 { 75 $other_facid = substr($key,7); 76 $amounts[$other_facid] = $_POST[$key]; 77 $total = $total + $amounts[$other_facid]; 78 } 79 } 80 81 // Effectue les vérifications des parametres 82 if ($_POST['paiementid'] <= 0) 83 { 84 $fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->trans('PaymentMode')).'</div>'; 85 $error++; 86 } 87 88 if ($conf->banque->enabled) 89 { 90 // Si module bank actif, un compte est obligatoire lors de la saisie 91 // d'un paiement 92 if (! $_POST['accountid']) 93 { 94 $fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->trans('AccountToCredit')).'</div>'; 95 $error++; 96 } 97 } 98 99 if ($total <= 0) 100 { 101 $fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->trans('Amount')).'</div>'; 102 $error++; 103 } 104 105 if (! $error) 106 { 107 $db->begin(); 108 109 // Creation de la ligne paiement 110 $paiement = new PaiementFourn($db); 111 $paiement->datepaye = $datepaye; 112 $paiement->amounts = $amounts; // Tableau de montant 113 $paiement->paiementid = $_POST['paiementid']; 114 $paiement->num_paiement = $_POST['num_paiement']; 115 $paiement->note = $_POST['comment']; 116 117 $paiement_id = $paiement->create($user); 118 if ($paiement_id > 0) 119 { 120 if ($conf->banque->enabled) 121 { 122 // Insertion dans llx_bank 123 $label = 'Règlement fournisseur'; 124 $acc = new Account($db, $_POST['accountid']); 125 //paiementid contient "CHQ ou VIR par exemple" 126 $bank_line_id = $acc->addline($paiement->datepaye, 127 $paiement->paiementid, 128 $label, 129 0.0 - $paiement->total, 130 $paiement->num_paiement, 131 '', 132 $user); 133 134 // Mise a jour fk_bank dans llx_paiement. 135 // On connait ainsi le paiement qui a généré l'écriture bancaire 136 if ($bank_line_id > 0) 137 { 138 $paiement->update_fk_bank($bank_line_id); 139 // Mise a jour liens (pour chaque facture concernées par le paiement) 140 foreach ($paiement->amounts as $key => $value) 141 { 142 $facid = $key; 143 $fac = new FactureFournisseur($db); 144 $fac->fetch($facid); 145 $fac->fetch_fournisseur(); 146 $acc->add_url_line($bank_line_id, 147 $paiement_id, 148 DOL_URL_ROOT.'/fourn/paiement/fiche.php?id=', 149 '(paiement)', 150 'payment'); 151 $acc->add_url_line($bank_line_id, 152 $fac->fournisseur->id, 153 DOL_URL_ROOT.'/fourn/fiche.php?socid=', 154 $fac->fournisseur->nom, 155 'company'); 156 } 157 } 158 else 159 { 160 $error++; 161 } 162 } 163 } 164 else 165 { 166 $this->error=$paiement->error; 167 $error++; 168 } 169 170 if ($error == 0) 171 { 172 $loc = DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$paiement_id; 173 $db->commit(); 174 Header('Location: '.$loc); 175 exit; 176 } 177 else 178 { 179 $db->rollback(); 180 } 181 } 182 } 183 184 /* 185 * Affichage 186 */ 187 188 llxHeader(); 189 190 $html=new Form($db); 191 192 if ($fiche_erreur_message) 193 { 194 print '<tr><td colspan="3" align="center">'.$fiche_erreur_message.'</td></tr>'; 195 } 196 197 if ($action == 'create' || $action == 'add_paiement') 198 { 199 $facture = new FactureFournisseur($db); 200 $facture->fetch($facid); 201 202 $sql = 'SELECT s.nom,s.idp, f.amount, f.total_ttc as total, f.facnumber'; 203 $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'facture_fourn as f WHERE f.fk_soc = s.idp'; 204 $sql .= ' AND f.rowid = '.$facid; 205 $resql = $db->query($sql); 206 if ($resql) 207 { 208 $num = $db->num_rows($resql); 209 if ($num) 210 { 211 $obj = $db->fetch_object($resql); 212 $total = $obj->total; 213 214 print_titre($langs->trans('DoPayment')); 215 print '<form action="paiement.php" method="post">'; 216 print '<input type="hidden" name="action" value="add_paiement">'; 217 print '<input type="hidden" name="facid" value="'.$facid.'">'; 218 print '<input type="hidden" name="facnumber" value="'.$obj->facnumber.'">'; 219 print '<input type="hidden" name="socid" value="'.$obj->idp.'">'; 220 print '<input type="hidden" name="societe" value="'.$obj->nom.'">'; 221 222 print '<table class="border" width="100%">'; 223 224 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans('Payment').'</td>'; 225 print '<tr><td>'.$langs->trans('Company').'</td><td colspan="2">'.$obj->nom.'</td></tr>'; 226 print '<tr><td>'.$langs->trans('Date').'</td><td>'; 227 if (!empty($_POST['remonth']) && !empty($_POST['reday']) && !empty($_POST['reyear'])) 228 $sel_date=mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); 229 else 230 $sel_date=''; 231 $html->select_date($sel_date); 232 print '</td>'; 233 print '<td>'.$langs->trans('Comments').'</td></tr>'; 234 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>'; 235 $html->select_types_paiements(empty($_POST['paiementid'])?'':$_POST['paiementid'],'paiementid'); 236 print '</td>'; 237 print '<td rowspan="3" valign="top">'; 238 print '<textarea name="comment" wrap="soft" cols="40" rows="4">'.(empty($_POST['comment'])?'':$_POST['comment']).'</textarea></td></tr>'; 239 print '<tr><td>'.$langs->trans('Numero').'</td><td><input name="num_paiement" type="text" value="'.(empty($_POST['num_paiement'])?'':$_POST['num_paiement']).'"><br><em>Numéro du chèque / virement</em></td></tr>'; 240 if ($conf->banque->enabled) 241 { 242 print '<tr><td>'.$langs->trans('Account').'</td><td>'; 243 $html->select_comptes(empty($_POST['accountid'])?(defined('FACTURE_RIB_NUMBER')?FACTURE_RIB_NUMBER:''):$_POST['accountid'],'accountid',0,'',1); 244 print '</td></tr>'; 245 } 246 else 247 { 248 print '<tr><td colspan="2"> </td></tr>'; 249 } 250 /* 251 * Autres factures impayées 252 */ 253 $sql = 'SELECT f.rowid as facid,f.facnumber,f.total_ttc,'.$db->pdate('f.datef').' as df'; 254 $sql .= ', sum(pf.amount) as am'; 255 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f'; 256 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; 257 $sql .= ' WHERE f.fk_soc = '.$facture->socidp; 258 $sql .= ' AND f.paye = 0'; 259 $sql .= ' AND f.fk_statut = 1'; // Statut=0 => non validée, Statut=2 => annulée 260 $sql .= ' GROUP BY f.facnumber'; 261 $resql = $db->query($sql); 262 if ($resql) 263 { 264 $num = $db->num_rows($resql); 265 if ($num > 0) 266 { 267 $i = 0; 268 print '<tr><td colspan="3">'; 269 print '<table class="noborder" width="100%">'; 270 print '<tr class="liste_titre">'; 271 print '<td>'.$langs->trans('Bill').'</td><td align="center">'.$langs->trans('Date').'</td>'; 272 print '<td align="right">'.$langs->trans('AmountTTC').'</td>'; 273 print '<td align="right">'.$langs->trans('AlreadyPayed').'</td>'; 274 print '<td align="right">'.$langs->trans('RemainderToPay').'</td>'; 275 print '<td align="center">'.$langs->trans('Amount').'</td>'; 276 print '</tr>'; 277 278 $var=True; 279 $total=0; 280 $totalrecu=0; 281 while ($i < $num) 282 { 283 $objp = $db->fetch_object($resql); 284 $var=!$var; 285 print '<tr '.$bc[$var].'>'; 286 print '<td><a href="fiche.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->facnumber; 287 print '</a></td>'; 288 if ($objp->df > 0 ) 289 { 290 print '<td align="center">'; 291 print dolibarr_print_date($objp->df).'</td>'; 292 } 293 else 294 { 295 print '<td align="center"><b>!!!</b></td>'; 296 } 297 print '<td align="right">'.price($objp->total_ttc).'</td>'; 298 print '<td align="right">'.price($objp->am).'</td>'; 299 print '<td align="right">'.price($objp->total_ttc - $objp->am).'</td>'; 300 print '<td align="center">'; 301 $namef = 'amount_'.$objp->facid; 302 print '<input type="text" size="8" name="'.$namef.'">'; 303 print "</td></tr>\n"; 304 $total+=$objp->total; 305 $total_ttc+=$objp->total_ttc; 306 $totalrecu+=$objp->am; 307 $i++; 308 } 309 if ($i > 1) 310 { 311 // Print total 312 print '<tr class="liste_total">'; 313 print '<td colspan="2" align="left">'.$langs->trans('TotalTTC').':</td>'; 314 print '<td align="right"><b>'.price($total_ttc).'</b></td>'; 315 print '<td align="right"><b>'.price($totalrecu).'</b></td>'; 316 print '<td align="right"><b>'.price($total_ttc - $totalrecu).'</b></td>'; 317 print '<td align="center"> </td>'; 318 print "</tr>\n"; 319 } 320 print "</table></td></tr>\n"; 321 } 322 $db->free($resql); 323 } 324 else 325 { 326 dolibarr_print_error($db); 327 } 328 329 /* 330 * 331 */ 332 print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans('Save').'"></td></tr>'; 333 print '</table>'; 334 print '</form>'; 335 } 336 } 337 } 338 339 /* 340 * Affichage liste 341 */ 342 if (! $_GET['action'] && ! $_POST['action']) 343 { 344 if ($page == -1) $page = 0 ; 345 $limit = $conf->liste_limit; 346 $offset = $limit * $page ; 347 348 if (! $sortorder) $sortorder='DESC'; 349 if (! $sortfield) $sortfield='p.datep'; 350 351 $sql = 'SELECT p.rowid, '.$db->pdate('p.datep').' as dp, p.amount'; 352 $sql .= ', f.amount as fa_amount, f.facnumber, s.nom'; 353 $sql .= ', f.rowid as facid, c.libelle as paiement_type, p.num_paiement'; 354 $sql .= ', ba.rowid as bid, ba.label'; 355 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn AS p'; 356 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn AS pf ON p.rowid=pf.fk_paiementfourn'; 357 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn AS f ON f.rowid=pf.fk_facturefourn '; 358 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement AS c ON p.fk_paiement = c.id'; 359 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON s.idp = f.fk_soc'; 360 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; 361 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid'; 362 if ($socidp) 363 { 364 $sql .= ' WHERE f.fk_soc = '.$socidp; 365 } 366 $sql .= ' ORDER BY '.$sortfield.' '.$sortorder; 367 $sql .= $db->plimit($limit + 1 ,$offset); 368 /* 369 $sql = "SELECT p.rowid,".$db->pdate("p.datep")." as dp, p.amount,"; 370 $sql.= " p.statut, p.num_paiement,"; 371 $sql.= " c.libelle as paiement_type,"; 372 $sql.= " ba.rowid as bid, ba.label"; 373 $sql.= " FROM ".MAIN_DB_PREFIX."paiement as p,"; 374 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON p.fk_bank = b.rowid"; 375 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid"; 376 if ($socidp) 377 { 378 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; 379 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid"; 380 } 381 $sql.= " WHERE p.fk_paiement = c.id"; 382 if ($socidp) 383 { 384 $sql.= " AND f.fk_soc = ".$socidp; 385 } 386 if ($_GET["search_montant"]) 387 { 388 $sql .=" AND p.amount=".ereg_replace(",",".",$_GET["search_montant"]); 389 } 390 */ 391 392 $resql = $db->query($sql); 393 if ($resql) 394 { 395 $num = $db->num_rows($resql); 396 $i = 0; 397 $var=True; 398 399 print_barre_liste($langs->trans('Payments'), $page, 'paiement.php','',$sortfield,$sortorder,'',$num); 400 print '<table class="noborder" width="100%">'; 401 print '<tr class="liste_titre">'; 402 print '<td>'.$langs->trans('Ref').'</td>'; 403 print_liste_field_titre($langs->trans('Bill'),'paiement.php','facnumber','','','',$sortfield); 404 print_liste_field_titre($langs->trans('Company'),'paiement.php','s.nom','','','',$sortfield); 405 print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','','','',$sortfield); 406 print_liste_field_titre($langs->trans('Type'),'paiement.php','c.libelle','','','',$sortfield); 407 print_liste_field_titre($langs->trans('Account'),'paiement.php','ba.label','','','',$sortfield); 408 print_liste_field_titre($langs->trans('AmountTTC'),'paiement.php','fa_amount','','','align="right"',$sortfield); 409 print '<td> </td>'; 410 print "</tr>\n"; 411 412 while ($i < min($num,$limit)) 413 { 414 $objp = $db->fetch_object($resql); 415 $var=!$var; 416 print '<tr '.$bc[$var].'>'; 417 print '<td><a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans('ShowPayment'),'payment').' '.$objp->rowid.'</a></td>'; 418 print '<td><a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$objp->facid.'">'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->facnumber.'</a></td>'; 419 print '<td>'.$objp->nom.'</td>'; 420 print '<td>'.dolibarr_print_date($objp->dp)."</td>\n"; 421 print '<td>'.$objp->paiement_type.' '.$objp->num_paiement."</td>\n"; 422 print '<td>'; 423 if ($objp->bid) print '<a href="'.DOL_URL_ROOT.'/compta/bank/account.php?account='.$objp->bid.'">'.img_object($langs->trans("ShowAccount"),'account').' '.$objp->label.'</a>'; 424 else print ' '; 425 print '</td>'; 426 print '<td align="right">'.price($objp->amount).'</td><td> </td>'; 427 print '</tr>'; 428 $i++; 429 } 430 print "</table>"; 431 } 432 else 433 { 434 dolibarr_print_error($db); 435 } 436 } 437 438 $db->close(); 439 440 llxFooter('$Date: 2005/12/03 04:15:45 $ - $Revision: 1.34 $'); 441 ?>
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 |
![]() |