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