PageRenderTime 46ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/compta/paiement/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 389 lines | 261 code | 69 blank | 59 comment | 62 complexity | 61200b7bb5e34744c31e8804a4991078 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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-2012 Regis Houssin <regis.houssin@capnetworks.com>
  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 3 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.'/facture/class/facture.class.php';
  29. require_once DOL_DOCUMENT_ROOT .'/facture/core/modules/facture/modules_facture.php';
  30. if (! empty($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','int');
  36. $action=GETPOST('action','alpha');
  37. $confirm=GETPOST('confirm','alpha');
  38. if ($user->societe_id) $socid=$user->societe_id;
  39. // TODO ajouter regle pour restreindre acces paiement
  40. //$result = restrictedArea($user, 'facture', $id,'');
  41. $mesg='';
  42. $object = new Paiement($db);
  43. /*
  44. * Actions
  45. */
  46. if ($action == 'setnote' && $user->rights->facture->paiement)
  47. {
  48. $db->begin();
  49. $object->fetch($id);
  50. $result = $object->update_note(GETPOST('note'));
  51. if ($result > 0)
  52. {
  53. $db->commit();
  54. $action='';
  55. }
  56. else
  57. {
  58. $mesg='<div class="error">'.$object->error.'</div>';
  59. $db->rollback();
  60. }
  61. }
  62. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->paiement)
  63. {
  64. $db->begin();
  65. $object->fetch($id);
  66. $result = $object->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($object->error).'</div>';
  77. $db->rollback();
  78. }
  79. }
  80. if ($action == 'confirm_valide' && $confirm == 'yes' && $user->rights->facture->paiement)
  81. {
  82. $db->begin();
  83. $object->fetch($id);
  84. if ($object->valide() > 0)
  85. {
  86. $db->commit();
  87. // Loop on each invoice linked to this payment to rebuild PDF
  88. $factures=array();
  89. foreach($factures as $id)
  90. {
  91. $fac = new Facture($db);
  92. $fac->fetch($id);
  93. $outputlangs = $langs;
  94. if (! empty($_REQUEST['lang_id']))
  95. {
  96. $outputlangs = new Translate();
  97. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  98. }
  99. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) facture_pdf_create($db, $fac, $fac->modelpdf, $outputlangs);
  100. }
  101. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
  102. exit;
  103. }
  104. else
  105. {
  106. $langs->load("errors");
  107. $mesg='<div class="error">'.$langs->trans($object->error).'</div>';
  108. $db->rollback();
  109. }
  110. }
  111. if ($action == 'setnum_paiement' && ! empty($_POST['num_paiement']))
  112. {
  113. $object->fetch($id);
  114. $res = $object->update_num($_POST['num_paiement']);
  115. if ($res === 0)
  116. {
  117. $mesg = '<div class="ok">'.$langs->trans('PaymentNumberUpdateSucceeded').'</div>';
  118. }
  119. else
  120. {
  121. $mesg = '<div class="error">'.$langs->trans('PaymentNumberUpdateFailed').'</div>';
  122. }
  123. }
  124. if ($action == 'setdatep' && ! empty($_POST['datepday']))
  125. {
  126. $object->fetch($id);
  127. $datepaye = dol_mktime(12, 0, 0, $_POST['datepmonth'], $_POST['datepday'], $_POST['datepyear']);
  128. $res = $object->update_date($datepaye);
  129. if ($res === 0)
  130. {
  131. $mesg = '<div class="ok">'.$langs->trans('PaymentDateUpdateSucceeded').'</div>';
  132. }
  133. else
  134. {
  135. $mesg = '<div class="error">'.$langs->trans('PaymentDateUpdateFailed').'</div>';
  136. }
  137. }
  138. /*
  139. * View
  140. */
  141. llxHeader();
  142. $thirdpartystatic=new Societe($db);
  143. $result=$object->fetch($id);
  144. if ($result <= 0)
  145. {
  146. dol_print_error($db,'Payement '.$id.' not found in database');
  147. exit;
  148. }
  149. $form = new Form($db);
  150. $h=0;
  151. $head[$h][0] = $_SERVER['PHP_SELF'].'?id='.$id;
  152. $head[$h][1] = $langs->trans("Card");
  153. $hselected = $h;
  154. $h++;
  155. $head[$h][0] = DOL_URL_ROOT.'/compta/paiement/info.php?id='.$id;
  156. $head[$h][1] = $langs->trans("Info");
  157. $h++;
  158. dol_fiche_head($head, $hselected, $langs->trans("PaymentCustomerInvoice"), 0, 'payment');
  159. /*
  160. * Confirmation de la suppression du paiement
  161. */
  162. if ($action == 'delete')
  163. {
  164. $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete','',0,2);
  165. if ($ret == 'html') print '<br>';
  166. }
  167. /*
  168. * Confirmation de la validation du paiement
  169. */
  170. if ($action == 'valide')
  171. {
  172. $facid = $_GET['facid'];
  173. $ret=$form->form_confirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;facid='.$facid, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide','',0,2);
  174. if ($ret == 'html') print '<br>';
  175. }
  176. dol_htmloutput_mesg($mesg);
  177. print '<table class="border" width="100%">';
  178. // Ref
  179. print '<tr><td valign="top" width="20%">'.$langs->trans('Ref').'</td><td colspan="3">'.$object->id.'</td></tr>';
  180. // Date payment
  181. print '<tr><td valign="top">'.$form->editfieldkey("Date",'datep',$object->date,$object,$user->rights->facture->paiement).'</td><td colspan="3">';
  182. print $form->editfieldval("Date",'datep',$object->date,$object,$user->rights->facture->paiement,'datepicker','',null,$langs->trans('PaymentDateUpdateSucceeded'));
  183. print '</td></tr>';
  184. // Payment type (VIR, LIQ, ...)
  185. $labeltype=$langs->trans("PaymentType".$object->type_code)!=("PaymentType".$object->type_code)?$langs->trans("PaymentType".$object->type_code):$object->type_libelle;
  186. print '<tr><td valign="top">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$labeltype.'</td></tr>';
  187. // Payment numero
  188. print '<tr><td valign="top">'.$form->editfieldkey("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
  189. print $form->editfieldval("Numero",'num_paiement',$object->numero,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
  190. print '</td></tr>';
  191. // Amount
  192. print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->montant).'&nbsp;'.$langs->trans('Currency'.$conf->currency).'</td></tr>';
  193. // Note
  194. print '<tr><td valign="top">'.$form->editfieldkey("Note",'note',$object->note,$object,$user->rights->facture->paiement).'</td><td colspan="3">';
  195. print $form->editfieldval("Note",'note',$object->note,$object,$user->rights->facture->paiement,'textarea');
  196. print '</td></tr>';
  197. // Bank account
  198. if (! empty($conf->banque->enabled))
  199. {
  200. if ($object->bank_account)
  201. {
  202. $bankline=new AccountLine($db);
  203. $bankline->fetch($object->bank_line);
  204. print '<tr>';
  205. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  206. print '<td colspan="3">';
  207. print $bankline->getNomUrl(1,0,'showall');
  208. print '</td>';
  209. print '</tr>';
  210. }
  211. }
  212. print '</table>';
  213. /*
  214. * List of invoices
  215. */
  216. $disable_delete = 0;
  217. $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';
  218. $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf,'.MAIN_DB_PREFIX.'facture as f,'.MAIN_DB_PREFIX.'societe as s';
  219. $sql.= ' WHERE pf.fk_facture = f.rowid';
  220. $sql.= ' AND f.fk_soc = s.rowid';
  221. $sql.= ' AND f.entity = '.$conf->entity;
  222. $sql.= ' AND pf.fk_paiement = '.$object->id;
  223. $resql=$db->query($sql);
  224. if ($resql)
  225. {
  226. $num = $db->num_rows($resql);
  227. $i = 0;
  228. $total = 0;
  229. print '<br><table class="noborder" width="100%">';
  230. print '<tr class="liste_titre">';
  231. print '<td>'.$langs->trans('Bill').'</td>';
  232. print '<td>'.$langs->trans('Company').'</td>';
  233. print '<td align="right">'.$langs->trans('ExpectedToPay').'</td>';
  234. print '<td align="right">'.$langs->trans('PayedByThisPayment').'</td>';
  235. print '<td align="right">'.$langs->trans('RemainderToPay').'</td>';
  236. print '<td align="right">'.$langs->trans('Status').'</td>';
  237. print "</tr>\n";
  238. if ($num > 0)
  239. {
  240. $var=True;
  241. while ($i < $num)
  242. {
  243. $objp = $db->fetch_object($resql);
  244. $var=!$var;
  245. print '<tr '.$bc[$var].'>';
  246. $invoice=new Facture($db);
  247. $invoice->fetch($objp->facid);
  248. $paiement = $invoice->getSommePaiement();
  249. $creditnotes=$invoice->getSumCreditNotesUsed();
  250. $deposits=$invoice->getSumDepositsUsed();
  251. $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
  252. $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
  253. // Invoice
  254. print '<td>';
  255. print $invoice->getNomUrl(1);
  256. print "</td>\n";
  257. // Third party
  258. print '<td>';
  259. $thirdpartystatic->id=$objp->socid;
  260. $thirdpartystatic->nom=$objp->nom;
  261. print $thirdpartystatic->getNomUrl(1);
  262. print '</td>';
  263. // Expected to pay
  264. print '<td align="right">'.price($objp->total_ttc).'</td>';
  265. // Amount payed
  266. print '<td align="right">'.price($objp->amount).'</td>';
  267. // Remain to pay
  268. print '<td align="right">'.price($remaintopay).'</td>';
  269. // Status
  270. print '<td align="right">'.$invoice->getLibStatut(5, $alreadypayed).'</td>';
  271. print "</tr>\n";
  272. if ($objp->paye == 1) // If at least one invoice is paid, disable delete
  273. {
  274. $disable_delete = 1;
  275. }
  276. $total = $total + $objp->amount;
  277. $i++;
  278. }
  279. }
  280. $var=!$var;
  281. print "</table>\n";
  282. $db->free($resql);
  283. }
  284. else
  285. {
  286. dol_print_error($db);
  287. }
  288. print '</div>';
  289. /*
  290. * Boutons Actions
  291. */
  292. print '<div class="tabsAction">';
  293. if (! empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
  294. {
  295. if ($user->societe_id == 0 && $object->statut == 0 && $_GET['action'] == '')
  296. {
  297. if ($user->rights->facture->paiement)
  298. {
  299. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;facid='.$objp->facid.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
  300. }
  301. }
  302. }
  303. if ($user->societe_id == 0 && $action == '')
  304. {
  305. if ($user->rights->facture->paiement)
  306. {
  307. if (! $disable_delete)
  308. {
  309. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
  310. }
  311. else
  312. {
  313. print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid")).'">'.$langs->trans('Delete').'</a>';
  314. }
  315. }
  316. }
  317. print '</div>';
  318. llxFooter();
  319. $db->close();
  320. ?>