PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/paiement.php

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