PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/compta/paiement/fiche.php

https://github.com/asterix14/dolibarr
PHP | 392 lines | 265 code | 68 blank | 59 comment | 62 complexity | 5215872de12a4b623cbe1db27eecc339 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2004 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-2009 Regis Houssin <regis@dolibarr.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/compta/paiement/fiche.php
  22. * \ingroup facture
  23. * \brief Page of a customer payment
  24. * \remarks Nearly same file than fournisseur/paiement/fiche.php
  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 ."/core/modules/facture/modules_facture.php");
  30. if ($conf->banque->enabled) require_once(DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php');
  31. $langs->load('bills');
  32. $langs->load('banks');
  33. $langs->load('companies');
  34. // Security check
  35. $id=GETPOST("id");
  36. $action=GETPOST("action");
  37. if ($user->societe_id) $socid=$user->societe_id;
  38. // TODO ajouter regle pour restreindre acces paiement
  39. //$result = restrictedArea($user, 'facture', $id,'');
  40. $mesg='';
  41. /*
  42. * Actions
  43. */
  44. if ($action == 'setnote' && $user->rights->facture->paiement)
  45. {
  46. $db->begin();
  47. $paiement = new Paiement($db);
  48. $paiement->fetch($id);
  49. $result = $paiement->update_note(GETPOST('note'));
  50. if ($result > 0)
  51. {
  52. $db->commit();
  53. $action='';
  54. }
  55. else
  56. {
  57. $mesg='<div class="error">'.$paiement->error.'</div>';
  58. $db->rollback();
  59. }
  60. }
  61. if ($action == 'confirm_delete' && GETPOST('confirm') == 'yes' && $user->rights->facture->paiement)
  62. {
  63. $db->begin();
  64. $paiement = new Paiement($db);
  65. $paiement->fetch($id);
  66. $result = $paiement->delete();
  67. if ($result > 0)
  68. {
  69. $db->commit();
  70. Header("Location: liste.php");
  71. exit;
  72. }
  73. else
  74. {
  75. $langs->load("errors");
  76. $mesg='<div class="error">'.$langs->trans($paiement->error).'</div>';
  77. $db->rollback();
  78. }
  79. }
  80. if ($action == 'confirm_valide' && GETPOST('confirm') == 'yes' && $user->rights->facture->paiement)
  81. {
  82. $db->begin();
  83. $paiement = new Paiement($db);
  84. $paiement->fetch($id);
  85. if ($paiement->valide() > 0)
  86. {
  87. $db->commit();
  88. // Loop on each invoice linked to this payment to rebuild PDF
  89. $factures=array();
  90. foreach($factures as $id)
  91. {
  92. $fac = new Facture($db);
  93. $fac->fetch($id);
  94. $outputlangs = $langs;
  95. if (! empty($_REQUEST['lang_id']))
  96. {
  97. $outputlangs = new Translate("",$conf);
  98. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  99. }
  100. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $fac, '', $fac->modelpdf, $outputlangs, $hookmanager);
  101. }
  102. Header('Location: fiche.php?id='.$paiement->id);
  103. exit;
  104. }
  105. else
  106. {
  107. $langs->load("errors");
  108. $mesg='<div class="error">'.$langs->trans($paiement->error).'</div>';
  109. $db->rollback();
  110. }
  111. }
  112. if ($action == 'setnum' && !empty($_POST['num']))
  113. {
  114. $paiement = new Paiement($db);
  115. $paiement->fetch($id);
  116. $res = $paiement->update_num($_POST['num']);
  117. if ($res === 0)
  118. {
  119. $mesg = '<div class="ok">'.$langs->trans('PaymentNumberUpdateSucceeded').'</div>';
  120. }
  121. else
  122. {
  123. $mesg = '<div class="error">'.$langs->trans('PaymentNumberUpdateFailed').'</div>';
  124. }
  125. }
  126. if ($action == 'setdate' && !empty($_POST['dateday']))
  127. {
  128. $paiement = new Paiement($db);
  129. $paiement->fetch($id);
  130. $datepaye = dol_mktime(12, 0, 0, $_POST['datemonth'], $_POST['dateday'], $_POST['dateyear']);
  131. $res = $paiement->update_date($datepaye);
  132. if ($res === 0)
  133. {
  134. $mesg = '<div class="ok">'.$langs->trans('PaymentDateUpdateSucceeded').'</div>';
  135. }
  136. else
  137. {
  138. $mesg = '<div class="error">'.$langs->trans('PaymentDateUpdateFailed').'</div>';
  139. }
  140. }
  141. /*
  142. * View
  143. */
  144. llxHeader();
  145. $thirdpartystatic=new Societe($db);
  146. $paiement = new Paiement($db);
  147. $result=$paiement->fetch($id);
  148. if ($result <= 0)
  149. {
  150. dol_print_error($db,'Payement '.$id.' not found in database');
  151. exit;
  152. }
  153. $form = new Form($db);
  154. $h=0;
  155. $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/fiche.php?id='.$id;
  156. $head[$h][1] = $langs->trans("Card");
  157. $hselected = $h;
  158. $h++;
  159. $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/info.php?id='.$id;
  160. $head[$h][1] = $langs->trans("Info");
  161. $h++;
  162. dol_fiche_head($head, $hselected, $langs->trans("PaymentCustomerInvoice"), 0, 'payment');
  163. /*
  164. * Confirmation de la suppression du paiement
  165. */
  166. if ($action == 'delete')
  167. {
  168. $ret=$form->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
  169. if ($ret == 'html') print '<br>';
  170. }
  171. /*
  172. * Confirmation de la validation du paiement
  173. */
  174. if ($action == 'valide')
  175. {
  176. $facid = $_GET['facid'];
  177. $ret=$form->form_confirm('fiche.php?id='.$paiement->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
  178. if ($ret == 'html') print '<br>';
  179. }
  180. dol_htmloutput_mesg($mesg);
  181. print '<table class="border" width="100%">';
  182. // Ref
  183. print '<tr><td valign="top" width="20%">'.$langs->trans('Ref').'</td><td colspan="3">'.$paiement->id.'</td></tr>';
  184. // Date payment
  185. print '<tr><td valign="top">'.$form->editfieldkey("Date",'date',$paiement->date,$paiement,$user->rights->facture->paiement).'</td><td colspan="3">';
  186. print $form->editfieldval("Date",'date',$paiement->date,$paiement,$user->rights->facture->paiement,'day');
  187. print '</td></tr>';
  188. // Payment type (VIR, LIQ, ...)
  189. $labeltype=$langs->trans("PaymentType".$paiement->type_code)!=("PaymentType".$paiement->type_code)?$langs->trans("PaymentType".$paiement->type_code):$paiement->type_libelle;
  190. print '<tr><td valign="top">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$labeltype.'</td></tr>';
  191. // Payment numero
  192. print '<tr><td valign="top">'.$form->editfieldkey("Numero",'num',$paiement->numero,$paiement,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
  193. print $form->editfieldval("Numero",'num',$paiement->numero,$paiement,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'string');
  194. print '</td></tr>';
  195. // Amount
  196. print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).'&nbsp;'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
  197. // Note
  198. print '<tr><td valign="top">'.$form->editfieldkey("Note",'note',$paiement->note,$paiement,$user->rights->facture->paiement).'</td><td colspan="3">';
  199. print $form->editfieldval("Note",'note',$paiement->note,$paiement,$user->rights->facture->paiement,'text');
  200. print '</td></tr>';
  201. // Bank account
  202. if ($conf->banque->enabled)
  203. {
  204. if ($paiement->bank_account)
  205. {
  206. $bankline=new AccountLine($db);
  207. $bankline->fetch($paiement->bank_line);
  208. print '<tr>';
  209. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  210. print '<td colspan="3">';
  211. print $bankline->getNomUrl(1,0,'showall');
  212. print '</td>';
  213. print '</tr>';
  214. }
  215. }
  216. print '</table>';
  217. /*
  218. * List of invoices
  219. */
  220. $disable_delete = 0;
  221. $sql = 'SELECT f.rowid as facid, f.facnumber, f.type, f.total_ttc, f.paye, f.fk_statut, pf.amount, s.nom, s.rowid as socid';
  222. $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
  223. $sql.= ' WHERE pf.fk_facture = f.rowid';
  224. $sql.= ' AND f.fk_soc = s.rowid';
  225. $sql.= ' AND s.entity = '.$conf->entity;
  226. $sql.= ' AND pf.fk_paiement = '.$paiement->id;
  227. $resql=$db->query($sql);
  228. if ($resql)
  229. {
  230. $num = $db->num_rows($resql);
  231. $i = 0;
  232. $total = 0;
  233. print '<br><table class="noborder" width="100%">';
  234. print '<tr class="liste_titre">';
  235. print '<td>'.$langs->trans('Bill').'</td>';
  236. print '<td>'.$langs->trans('Company').'</td>';
  237. print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
  238. print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
  239. print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
  240. print '<td align="right">'.$langs->trans('Status').'</td>';
  241. print "</tr>\n";
  242. if ($num > 0)
  243. {
  244. $var=True;
  245. while ($i < $num)
  246. {
  247. $objp = $db->fetch_object($resql);
  248. $var=!$var;
  249. print '<tr '.$bc[$var].'>';
  250. $invoice=new Facture($db);
  251. $invoice->fetch($objp->facid);
  252. $paiement = $invoice->getSommePaiement();
  253. $creditnotes=$invoice->getSumCreditNotesUsed();
  254. $deposits=$invoice->getSumDepositsUsed();
  255. $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
  256. $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
  257. // Invoice
  258. print '<td>';
  259. print $invoice->getNomUrl(1);
  260. print "</td>\n";
  261. // Third party
  262. print '<td>';
  263. $thirdpartystatic->id=$objp->socid;
  264. $thirdpartystatic->nom=$objp->nom;
  265. print $thirdpartystatic->getNomUrl(1);
  266. print '</td>';
  267. // Expected to pay
  268. print '<td align="right">'.price($objp->total_ttc).'</td>';
  269. // Amount payed
  270. print '<td align="right">'.price($objp->amount).'</td>';
  271. // Remain to pay
  272. print '<td align="right">'.price($remaintopay).'</td>';
  273. // Status
  274. print '<td align="right">'.$invoice->getLibStatut(5, $alreadypayed).'</td>';
  275. print "</tr>\n";
  276. if ($objp->paye == 1) // If at least one invoice is paid, disable delete
  277. {
  278. $disable_delete = 1;
  279. }
  280. $total = $total + $objp->amount;
  281. $i++;
  282. }
  283. }
  284. $var=!$var;
  285. print "</table>\n";
  286. $db->free($resql);
  287. }
  288. else
  289. {
  290. dol_print_error($db);
  291. }
  292. print '</div>';
  293. /*
  294. * Boutons Actions
  295. */
  296. print '<div class="tabsAction">';
  297. if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
  298. {
  299. if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET['action'] == '')
  300. {
  301. if ($user->rights->facture->paiement)
  302. {
  303. print '<a class="butAction" href="fiche.php?id='.$id.'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
  304. }
  305. }
  306. }
  307. if ($user->societe_id == 0 && $action == '')
  308. {
  309. if ($user->rights->facture->paiement)
  310. {
  311. if (! $disable_delete)
  312. {
  313. print '<a class="butActionDelete" href="fiche.php?id='.$id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
  314. }
  315. else
  316. {
  317. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
  318. }
  319. }
  320. }
  321. print '</div>';
  322. $db->close();
  323. llxFooter();
  324. ?>