PageRenderTime 63ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/paiement.php

https://github.com/asterix14/dolibarr
PHP | 675 lines | 506 code | 89 blank | 80 comment | 98 complexity | 7dec8ae51f234a7ea95358bd6f518480 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerke@telenet.be>
  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, see <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/paiement.php
  23. * \ingroup compta
  24. * \brief Page to create a payment
  25. */
  26. require('../main.inc.php');
  27. require_once(DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php');
  28. require_once(DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php');
  29. require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
  30. $langs->load('companies');
  31. $langs->load('bills');
  32. $langs->load('banks');
  33. $action = GETPOST('action');
  34. $confirm = GETPOST('confirm');
  35. $facid = GETPOST('facid');
  36. $socname = GETPOST('socname');
  37. $accountid = GETPOST('accountid');
  38. $paymentnum = GETPOST('num_paiement');
  39. $sortfield = GETPOST('sortfield');
  40. $sortorder = GETPOST('sortorder');
  41. $page = GETPOST('page');
  42. $amounts=array();
  43. $amountsresttopay=array();
  44. $addwarning=0;
  45. // Security check
  46. $socid=0;
  47. if ($user->societe_id > 0)
  48. {
  49. $socid = $user->societe_id;
  50. }
  51. /*
  52. * Action add_paiement et confirm_paiement
  53. */
  54. if ($action == 'add_paiement' || ($action == 'confirm_paiement' && $confirm=='yes'))
  55. {
  56. $error = 0;
  57. $datepaye = dol_mktime(12, 0 , 0,
  58. $_POST['remonth'],
  59. $_POST['reday'],
  60. $_POST['reyear']);
  61. $paiement_id = 0;
  62. // Verifie si des paiements sont superieurs au montant facture
  63. foreach ($_POST as $key => $value)
  64. {
  65. if (substr($key,0,7) == 'amount_')
  66. {
  67. $cursorfacid = substr($key,7);
  68. $amounts[$cursorfacid] = price2num($_POST[$key]);
  69. $totalpaiement = $totalpaiement + $amounts[$cursorfacid];
  70. $tmpfacture=new Facture($db);
  71. $tmpfacture->fetch($cursorfacid);
  72. $amountsresttopay[$cursorfacid]=price2num($tmpfacture->total_ttc-$tmpfacture->getSommePaiement());
  73. if ($amounts[$cursorfacid] && $amounts[$cursorfacid] > $amountsresttopay[$cursorfacid])
  74. {
  75. $addwarning=1;
  76. $formquestion['text'] = img_warning($langs->trans("PaymentHigherThanReminderToPay")).' '.$langs->trans("HelpPaymentHigherThanReminderToPay");
  77. }
  78. $formquestion[$i++]=array('type' => 'hidden','name' => $key, 'value' => $_POST[$key]);
  79. }
  80. }
  81. // Check parameters
  82. if (! GETPOST('paiementcode'))
  83. {
  84. $fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('PaymentMode')).'</div>';
  85. $error++;
  86. }
  87. if ($conf->banque->enabled)
  88. {
  89. // Si module bank actif, un compte est obligatoire lors de la saisie
  90. // d'un paiement
  91. if (! $_POST['accountid'])
  92. {
  93. $fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('AccountToCredit')).'</div>';
  94. $error++;
  95. }
  96. }
  97. if ($totalpaiement == 0)
  98. {
  99. $fiche_erreur_message = '<div class="error">'.$langs->transnoentities('ErrorFieldRequired',$langs->trans('PaymentAmount')).'</div>';
  100. $error++;
  101. }
  102. if (empty($datepaye))
  103. {
  104. $fiche_erreur_message = '<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('Date')).'</div>';
  105. $error++;
  106. }
  107. }
  108. /*
  109. * Action add_paiement
  110. */
  111. if ($action == 'add_paiement')
  112. {
  113. if ($error)
  114. {
  115. $action = 'create';
  116. }
  117. // Le reste propre a cette action s'affiche en bas de page.
  118. }
  119. /*
  120. * Action confirm_paiement
  121. */
  122. if ($action == 'confirm_paiement' && $confirm == 'yes')
  123. {
  124. $error=0;
  125. $datepaye = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
  126. $db->begin();
  127. // Creation of payment line
  128. $paiement = new Paiement($db);
  129. $paiement->datepaye = $datepaye;
  130. $paiement->amounts = $amounts; // Array with all payments dispatching
  131. $paiement->paiementid = dol_getIdFromCode($db,$_POST['paiementcode'],'c_paiement');
  132. $paiement->num_paiement = $_POST['num_paiement'];
  133. $paiement->note = $_POST['comment'];
  134. if (! $error)
  135. {
  136. $paiement_id = $paiement->create($user,(GETPOST('closepaidinvoices')=='on'?1:0));
  137. if ($paiement_id < 0)
  138. {
  139. $errmsg=$paiement->error;
  140. $error++;
  141. }
  142. }
  143. if (! $error)
  144. {
  145. $result=$paiement->addPaymentToBank($user,'payment','(CustomerInvoicePayment)',$_POST['accountid'],$_POST['chqemetteur'],$_POST['chqbank']);
  146. if ($result < 0)
  147. {
  148. $errmsg=$paiement->error;
  149. $error++;
  150. }
  151. }
  152. if (! $error)
  153. {
  154. $db->commit();
  155. // If payment dispatching on more than one invoice, we keep on summary page, otherwise go on invoice card
  156. $invoiceid=0;
  157. foreach ($paiement->amounts as $key => $amount)
  158. {
  159. $facid = $key;
  160. if (is_numeric($amount) && $amount <> 0)
  161. {
  162. if ($invoiceid != 0) $invoiceid=-1; // There is more than one invoice payed by this payment
  163. else $invoiceid=$facid;
  164. }
  165. }
  166. if ($invoiceid > 0) $loc = DOL_URL_ROOT.'/compta/facture.php?facid='.$invoiceid;
  167. else $loc = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$paiement_id;
  168. Header('Location: '.$loc);
  169. exit;
  170. }
  171. else
  172. {
  173. $db->rollback();
  174. }
  175. }
  176. /*
  177. * View
  178. */
  179. llxHeader();
  180. $form=new Form($db);
  181. if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paiement')
  182. {
  183. $facture = new Facture($db);
  184. $result=$facture->fetch($facid);
  185. if ($result >= 0)
  186. {
  187. $facture->fetch_thirdparty();
  188. $title='';
  189. if ($facture->type != 2) $title.=$langs->trans("EnterPaymentReceivedFromCustomer");
  190. if ($facture->type == 2) $title.=$langs->trans("EnterPaymentDueToCustomer");
  191. print_fiche_titre($title);
  192. dol_htmloutput_errors($errmsg);
  193. // Bouchon
  194. if ($facture->type == 2)
  195. {
  196. print $langs->trans("FeatureNotYetAvailable");
  197. llxFooter();
  198. exit;
  199. }
  200. // Initialize data for confirmation (this is used because data can be change during confirmation)
  201. if ($action == 'add_paiement')
  202. {
  203. $i=0;
  204. $formquestion[$i++]=array('type' => 'hidden','name' => 'facid', 'value' => $facture->id);
  205. $formquestion[$i++]=array('type' => 'hidden','name' => 'socid', 'value' => $facture->socid);
  206. $formquestion[$i++]=array('type' => 'hidden','name' => 'type', 'value' => $facture->type);
  207. }
  208. // Invoice with Paypal transaction
  209. if ($conf->paypalplus->enabled && $conf->global->PAYPAL_ENABLE_TRANSACTION_MANAGEMENT && ! empty($facture->ref_int))
  210. {
  211. if (! empty($conf->global->PAYPAL_BANK_ACCOUNT)) $accountid=$conf->global->PAYPAL_BANK_ACCOUNT;
  212. $paymentnum=$facture->ref_int;
  213. }
  214. if ($conf->use_javascript_ajax && !empty($conf->global->MAIN_JS_ON_PAYMENT))
  215. {
  216. print "\n".'<script type="text/javascript" language="javascript">';
  217. print 'jQuery(document).ready(function () {';
  218. print 'jQuery("#selectpaiementcode").change(function() {
  219. code=jQuery("#selectpaiementcode option:selected").val();
  220. if (code == \'CHQ\')
  221. {
  222. jQuery(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
  223. if (jQuery(\'#fieldchqemetteur\').val() == \'\')
  224. {
  225. jQuery(\'#fieldchqemetteur\').val(jQuery(\'#thirdpartylabel\').val());
  226. }
  227. }
  228. else
  229. {
  230. jQuery(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
  231. }
  232. });
  233. function elemToJson(selector)
  234. {
  235. var subJson = {};
  236. jQuery.map(selector.serializeArray(), function(n,i)
  237. {
  238. subJson[n["name"]] = n["value"];
  239. });
  240. return subJson;
  241. }
  242. function callForResult(imgId)
  243. {
  244. var json = {};
  245. var form = jQuery("#payment_form");
  246. json["amountPayment"] = jQuery("#amountpayment").attr("value");
  247. json["amounts"] = elemToJson(form.find("input[name*=\"amount_\"]"));
  248. json["remains"] = elemToJson(form.find("input[name*=\"remain_\"]"));
  249. if(imgId != null)json["imgClicked"] = imgId;
  250. jQuery.post("ajaxpayment.php", json, function(data)
  251. {
  252. json = jQuery.parseJSON(data);
  253. form.data(json);
  254. for(var key in json)
  255. {
  256. if(key == "result") {
  257. if(json["makeRed"]) {
  258. jQuery("#"+key).css("color", "red");
  259. } else {
  260. jQuery("#"+key).removeAttr("style");
  261. }
  262. json[key]=json["label"]+" "+json[key];
  263. jQuery("#"+key).text(json[key]);
  264. } else {
  265. form.find("input[name*=\""+key+"\"]").each(function() {
  266. jQuery(this).attr("value", json[key]);
  267. });
  268. }
  269. }
  270. });
  271. }
  272. function callToBreakdown(imgSelector) {
  273. var form = jQuery("#payment_form"), imgId;
  274. imgId = imgSelector.attr("id");
  275. callForResult(imgId);
  276. }
  277. jQuery("#payment_form").find("img").click(function() {
  278. callToBreakdown(jQuery(this));
  279. });
  280. jQuery("#payment_form").find("input[name*=\"amount_\"]").change(function() {
  281. callForResult();
  282. });
  283. jQuery("#amountpayment").change(function() {
  284. callForResult();
  285. });
  286. });
  287. </script>'."\n";
  288. }
  289. print '<form id="payment_form" name="add_paiement" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  290. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  291. print '<input type="hidden" name="action" value="add_paiement">';
  292. print '<input type="hidden" name="facid" value="'.$facture->id.'">';
  293. print '<input type="hidden" name="socid" value="'.$facture->socid.'">';
  294. print '<input type="hidden" name="type" value="'.$facture->type.'">';
  295. print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($facture->client->name).'">';
  296. print '<table class="border" width="100%">';
  297. // Third party
  298. print '<tr><td><span class="fieldrequired">'.$langs->trans('Company').'</span></td><td colspan="2">'.$facture->client->getNomUrl(4)."</td></tr>\n";
  299. // Date payment
  300. print '<tr><td><span class="fieldrequired">'.$langs->trans('Date').'</span></td><td>';
  301. $datepayment = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
  302. $datepayment= ($datepayment == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0) : $datepayment);
  303. $form->select_date($datepayment,'','','',0,"add_paiement",1,1);
  304. print '</td>';
  305. print '<td>'.$langs->trans('Comments').'</td></tr>';
  306. $rowspan=5;
  307. if ($conf->use_javascript_ajax && !empty($conf->global->MAIN_JS_ON_PAYMENT)) $rowspan++;
  308. // Payment mode
  309. print '<tr><td><span class="fieldrequired">'.$langs->trans('PaymentMode').'</span></td><td>';
  310. $form->select_types_paiements((GETPOST('paiementcode')?GETPOST('paiementcode'):$facture->mode_reglement_code),'paiementcode','',2);
  311. print "</td>\n";
  312. print '<td rowspan="'.$rowspan.'" valign="top">';
  313. print '<textarea name="comment" wrap="soft" cols="60" rows="'.ROWS_4.'">'.(empty($_POST['comment'])?'':$_POST['comment']).'</textarea></td>';
  314. print '</tr>';
  315. // Payment amount
  316. if ($conf->use_javascript_ajax && !empty($conf->global->MAIN_JS_ON_PAYMENT))
  317. {
  318. print '<tr><td><span class="fieldrequired">'.$langs->trans('AmountPayment').'</span></td>';
  319. print '<td>';
  320. if ($action == 'add_paiement')
  321. {
  322. print '<input id="amountpayment" name="amountpaymenthidden" size="8" type="text" value="'.(empty($_POST['amountpayment'])?'':$_POST['amountpayment']).'" disabled="disabled">';
  323. print '<input name="amountpayment" type="hidden" value="'.(empty($_POST['amountpayment'])?'':$_POST['amountpayment']).'">';
  324. }
  325. else
  326. {
  327. print '<input id="amountpayment" name="amountpayment" size="8" type="text" value="'.(empty($_POST['amountpayment'])?'':$_POST['amountpayment']).'">';
  328. }
  329. print '</td>';
  330. print '</tr>';
  331. }
  332. print '<tr>';
  333. if ($conf->banque->enabled)
  334. {
  335. if ($facture->type != 2) print '<td><span class="fieldrequired">'.$langs->trans('AccountToCredit').'</span></td>';
  336. if ($facture->type == 2) print '<td><span class="fieldrequired">'.$langs->trans('AccountToDebit').'</span></td>';
  337. print '<td>';
  338. $form->select_comptes($accountid,'accountid',0,'',2);
  339. print '</td>';
  340. }
  341. else
  342. {
  343. print '<td colspan="2">&nbsp;</td>';
  344. }
  345. print "</tr>\n";
  346. // Cheque number
  347. print '<tr><td>'.$langs->trans('Numero');
  348. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  349. print '</td>';
  350. print '<td><input name="num_paiement" type="text" value="'.$paymentnum.'"></td></tr>';
  351. // Check transmitter
  352. print '<tr><td class="'.(GETPOST('paiementcode')=='CHQ'?'fieldrequired ':'').'fieldrequireddyn">'.$langs->trans('CheckTransmitter');
  353. print ' <em>('.$langs->trans("ChequeMaker").')</em>';
  354. print '</td>';
  355. print '<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST('chqemetteur').'"></td></tr>';
  356. // Bank name
  357. print '<tr><td>'.$langs->trans('Bank');
  358. print ' <em>('.$langs->trans("ChequeBank").')</em>';
  359. print '</td>';
  360. print '<td><input name="chqbank" size="30" type="text" value="'.GETPOST('chqbank').'"></td></tr>';
  361. print '</table>';
  362. /*
  363. * List of unpaid invoices
  364. */
  365. $sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.type, ';
  366. $sql.= ' f.datef as df';
  367. $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f';
  368. $sql.= ' WHERE f.fk_soc = '.$facture->socid;
  369. $sql.= ' AND f.paye = 0';
  370. $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled
  371. if ($facture->type != 2)
  372. {
  373. $sql .= ' AND type in (0,1,3)'; // Standard invoice, replacement, deposit
  374. }
  375. else
  376. {
  377. $sql .= ' AND type = 2'; // If paying back a credit note, we show all credit notes
  378. }
  379. $resql = $db->query($sql);
  380. if ($resql)
  381. {
  382. $num = $db->num_rows($resql);
  383. if ($num > 0)
  384. {
  385. $i = 0;
  386. //print '<tr><td colspan="3">';
  387. print '<br>';
  388. print '<table class="noborder" width="100%">';
  389. print '<tr class="liste_titre">';
  390. print '<td>'.$langs->trans('Invoice').'</td>';
  391. print '<td align="center">'.$langs->trans('Date').'</td>';
  392. print '<td align="right">'.$langs->trans('AmountTTC').'</td>';
  393. print '<td align="right">'.$langs->trans('Received').'</td>';
  394. print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
  395. print '<td align="right">'.$langs->trans('PaymentAmount').'</td>';
  396. print '<td align="right">&nbsp;</td>';
  397. print "</tr>\n";
  398. $var=True;
  399. $total=0;
  400. $totalrecu=0;
  401. $totalrecucreditnote=0;
  402. $totalrecudeposits=0;
  403. while ($i < $num)
  404. {
  405. $objp = $db->fetch_object($resql);
  406. $var=!$var;
  407. $invoice=new Facture($db);
  408. $invoice->fetch($objp->facid);
  409. $paiement = $invoice->getSommePaiement();
  410. $creditnotes=$invoice->getSumCreditNotesUsed();
  411. $deposits=$invoice->getSumDepositsUsed();
  412. $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
  413. $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
  414. print '<tr '.$bc[$var].'>';
  415. print '<td>';
  416. print $invoice->getNomUrl(1,'');
  417. print "</td>\n";
  418. // Date
  419. print '<td align="center">'.dol_print_date($db->jdate($objp->df),'day')."</td>\n";
  420. // Prix
  421. print '<td align="right">'.price($objp->total_ttc).'</td>';
  422. // Recu
  423. print '<td align="right">'.price($paiement);
  424. if ($creditnotes) print '+'.price($creditnotes);
  425. if ($deposits) print '+'.price($deposits);
  426. print '</td>';
  427. // Remain to pay
  428. print '<td align="right">'.price($remaintopay).'</td>';
  429. $test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits));
  430. // Amount
  431. print '<td align="right">';
  432. // Add remind amount
  433. $namef = 'amount_'.$objp->facid;
  434. $nameRemain = 'remain_'.$objp->facid;
  435. if ($action != 'add_paiement')
  436. {
  437. if ($conf->use_javascript_ajax && !empty($conf->global->MAIN_JS_ON_PAYMENT))
  438. {
  439. print img_picto($langs->trans('AddRemind'),'rightarrow.png','id="'.$objp->facid.'" "');
  440. }
  441. print '<input type=hidden name="'.$nameRemain.'" value="'.$remaintopay.'">';
  442. print '<input type="text" size="8" name="'.$namef.'" value="'.$_POST[$namef].'">';
  443. }
  444. else
  445. {
  446. print '<input type="text" size="8" name="'.$namef.'_disabled" value="'.$_POST[$namef].'" disabled="disabled">';
  447. print '<input type="hidden" name="'.$namef.'" value="'.$_POST[$namef].'">';
  448. }
  449. print "</td>";
  450. // Warning
  451. print '<td align="center" width="16">';
  452. if ($amounts[$invoice->id] && $amounts[$invoice->id] > $amountsresttopay[$invoice->id])
  453. {
  454. print ' '.img_warning($langs->trans("PaymentHigherThanReminderToPay"));
  455. }
  456. print '</td>';
  457. print "</tr>\n";
  458. $total+=$objp->total;
  459. $total_ttc+=$objp->total_ttc;
  460. $totalrecu+=$paiement;
  461. $totalrecucreditnote+=$creditnotes;
  462. $totalrecudeposits+=$deposits;
  463. $i++;
  464. }
  465. if ($i > 1)
  466. {
  467. // Print total
  468. print '<tr class="liste_total">';
  469. print '<td colspan="2" align="left">'.$langs->trans('TotalTTC').'</td>';
  470. print '<td align="right"><b>'.price($total_ttc).'</b></td>';
  471. print '<td align="right"><b>'.price($totalrecu);
  472. if ($totalrecucreditnote) print '+'.price($totalrecucreditnote);
  473. if ($totalrecudeposits) print '+'.price($totalrecudeposits);
  474. print '</b></td>';
  475. print '<td align="right"><b>'.price(price2num($total_ttc - $totalrecu - $totalrecucreditnote - $totalrecudeposits,'MT')).'</b></td>';
  476. print '<td align="right" id="result" style="font-weight:bold;"></td>';
  477. print '<td align="center">&nbsp;</td>';
  478. print "</tr>\n";
  479. }
  480. print "</table>";
  481. //print "</td></tr>\n";
  482. }
  483. $db->free($resql);
  484. }
  485. else
  486. {
  487. dol_print_error($db);
  488. }
  489. // Bouton Enregistrer
  490. if ($action != 'add_paiement')
  491. {
  492. // print '<tr><td colspan="3" align="center">';
  493. print '<center><br><input type="checkbox" checked="checked" name="closepaidinvoices"> '.$langs->trans("ClosePaidInvoicesAutomatically");
  494. /*if ($conf->prelevement->enabled)
  495. {
  496. $langs->load("withdrawals");
  497. if ($conf->global->WITHDRAW_DISABLE_AUTOCREATE_ONPAYMENTS) print '<br>'.$langs->trans("IfInvoiceNeedOnWithdrawPaymentWontBeClosed");
  498. }*/
  499. print '<br><input type="submit" class="button" value="'.$langs->trans('Save').'"><br><br></center>';
  500. // print '</td></tr>';
  501. }
  502. // Message d'erreur
  503. if ($fiche_erreur_message)
  504. {
  505. print $fiche_erreur_message;
  506. }
  507. // Form to confirm payment
  508. if ($action == 'add_paiement')
  509. {
  510. $preselectedchoice=$addwarning?'no':'yes';
  511. print '<br>';
  512. $text=$langs->trans('ConfirmCustomerPayment',$totalpaiement,$langs->trans("Currency".$conf->monnaie));
  513. if (GETPOST('closepaidinvoices'))
  514. {
  515. $text.='<br>'.$langs->trans("AllCompletelyPayedInvoiceWillBeClosed");
  516. print '<input type="hidden" name="closepaidinvoices" value="'.GETPOST('closepaidinvoices').'">';
  517. }
  518. $form->form_confirm($_SERVER['PHP_SELF'].'?facid='.$facture->id.'&socid='.$facture->socid.'&type='.$facture->type,$langs->trans('ReceivedCustomersPayments'),$text,'confirm_paiement',$formquestion,$preselectedchoice);
  519. }
  520. print "</form>\n";
  521. }
  522. }
  523. /**
  524. * Show list of payments
  525. */
  526. if (! GETPOST('action'))
  527. {
  528. if ($page == -1) $page = 0 ;
  529. $limit = $conf->liste_limit;
  530. $offset = $limit * $page ;
  531. if (! $sortorder) $sortorder='DESC';
  532. if (! $sortfield) $sortfield='p.datep';
  533. $sql = 'SELECT p.datep as dp, p.amount, f.amount as fa_amount, f.facnumber';
  534. $sql .=', f.rowid as facid, c.libelle as paiement_type, p.num_paiement';
  535. $sql .= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'c_paiement as c';
  536. $sql .= ' WHERE p.fk_facture = f.rowid AND p.fk_paiement = c.id';
  537. if ($socid)
  538. {
  539. $sql .= ' AND f.fk_soc = '.$socid;
  540. }
  541. $sql .= ' ORDER BY '.$sortfield.' '.$sortorder;
  542. $sql .= $db->plimit($limit +1 ,$offset);
  543. $resql = $db->query($sql);
  544. if ($resql)
  545. {
  546. $num = $db->num_rows($resql);
  547. $i = 0;
  548. $var=True;
  549. print_barre_liste($langs->trans('Payments'), $page, 'paiement.php','',$sortfield,$sortorder,'',$num);
  550. print '<table class="noborder" width="100%">';
  551. print '<tr class="liste_titre">';
  552. print_liste_field_titre($langs->trans('Invoice'),'paiement.php','facnumber','','','',$sortfield,$sortorder);
  553. print_liste_field_titre($langs->trans('Date'),'paiement.php','dp','','','',$sortfield,$sortorder);
  554. print_liste_field_titre($langs->trans('Type'),'paiement.php','libelle','','','',$sortfield,$sortorder);
  555. print_liste_field_titre($langs->trans('Amount'),'paiement.php','fa_amount','','','align="right"',$sortfield,$sortorder);
  556. print '<td>&nbsp;</td>';
  557. print "</tr>\n";
  558. while ($i < min($num,$limit))
  559. {
  560. $objp = $db->fetch_object($resql);
  561. $var=!$var;
  562. print '<tr '.$bc[$var].'>';
  563. print '<td><a href="facture.php?facid='.$objp->facid.'">'.$objp->facnumber."</a></td>\n";
  564. print '<td>'.dol_print_date($db->jdate($objp->dp))."</td>\n";
  565. print '<td>'.$objp->paiement_type.' '.$objp->num_paiement."</td>\n";
  566. print '<td align="right">'.price($objp->amount).'</td><td>&nbsp;</td>';
  567. print '</tr>';
  568. $i++;
  569. }
  570. print '</table>';
  571. }
  572. }
  573. $db->close();
  574. llxFooter();
  575. ?>