PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/fourn/paiement/card.php

https://github.com/atm-maxime/dolibarr
PHP | 411 lines | 271 code | 66 blank | 74 comment | 63 complexity | 2b98a3b876f5c604d14f4a928b97cc2c MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, CC-BY-SA-4.0, BSD-3-Clause, LGPL-2.1, MPL-2.0-no-copyleft-exception, LGPL-3.0, LGPL-2.0, MIT
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  4. * Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2014 Marcos GarcĂ­a <marcosgdf@gmail.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 <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/fourn/paiement/card.php
  22. * \ingroup facture, fournisseur
  23. * \brief Tab to show a payment of a supplier invoice
  24. * \remarks Fichier presque identique a compta/paiement/card.php
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  29. require DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  30. require DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  31. require DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  32. $langs->loadLangs(array('bills', 'banks', 'companies', 'suppliers'));
  33. $id = GETPOST('id', 'int');
  34. $action = GETPOST('action', 'alpha');
  35. $confirm = GETPOST('confirm', 'alpha');
  36. $object = new PaiementFourn($db);
  37. // PDF
  38. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  39. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  40. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  41. /*
  42. * Actions
  43. */
  44. if ($action == 'setnote' && $user->rights->fournisseur->facture->creer)
  45. {
  46. $db->begin();
  47. $object->fetch($id);
  48. $result = $object->update_note(GETPOST('note', 'none'));
  49. if ($result > 0)
  50. {
  51. $db->commit();
  52. $action = '';
  53. }
  54. else
  55. {
  56. setEventMessages($object->error, $object->errors, 'errors');
  57. $db->rollback();
  58. }
  59. }
  60. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer)
  61. {
  62. $db->begin();
  63. $object->fetch($id);
  64. $result = $object->delete();
  65. if ($result > 0)
  66. {
  67. $db->commit();
  68. header('Location: '.DOL_URL_ROOT.'/fourn/facture/paiement.php');
  69. exit;
  70. }
  71. else
  72. {
  73. setEventMessages($object->error, $object->errors, 'errors');
  74. $db->rollback();
  75. }
  76. }
  77. if ($action == 'confirm_valide' && $confirm == 'yes' &&
  78. ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->facture->creer))
  79. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate)))
  80. )
  81. {
  82. $db->begin();
  83. $object->fetch($id);
  84. if ($object->valide() >= 0)
  85. {
  86. $db->commit();
  87. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
  88. exit;
  89. }
  90. else
  91. {
  92. setEventMessages($object->error, $object->errors, 'errors');
  93. $db->rollback();
  94. }
  95. }
  96. if ($action == 'setnum_paiement' && !empty($_POST['num_paiement']))
  97. {
  98. $object->fetch($id);
  99. $res = $object->update_num($_POST['num_paiement']);
  100. if ($res === 0)
  101. {
  102. setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
  103. }
  104. else
  105. {
  106. setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
  107. }
  108. }
  109. if ($action == 'setdatep' && !empty($_POST['datepday']))
  110. {
  111. $object->fetch($id);
  112. $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'));
  113. $res = $object->update_date($datepaye);
  114. if ($res === 0)
  115. {
  116. setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
  117. }
  118. else
  119. {
  120. setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
  121. }
  122. }
  123. // Build document
  124. $upload_dir = $conf->fournisseur->payment->dir_output;
  125. // TODO: get the appropriate permisson
  126. $permissiontoadd = true;
  127. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  128. /*
  129. * View
  130. */
  131. llxHeader();
  132. $result = $object->fetch($id);
  133. $form = new Form($db);
  134. $formfile = new FormFile($db);
  135. $head = payment_supplier_prepare_head($object);
  136. dol_fiche_head($head, 'payment', $langs->trans('SupplierPayment'), -1, 'payment');
  137. if ($result > 0)
  138. {
  139. /*
  140. * Confirmation de la suppression du paiement
  141. */
  142. if ($action == 'delete')
  143. {
  144. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
  145. }
  146. /*
  147. * Confirmation de la validation du paiement
  148. */
  149. if ($action == 'valide')
  150. {
  151. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide');
  152. }
  153. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/paiement.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  154. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref');
  155. print '<div class="fichecenter">';
  156. print '<div class="underbanner clearboth"></div>';
  157. print '<table class="border centpercent">';
  158. /*print '<tr>';
  159. print '<td width="20%" colspan="2">'.$langs->trans('Ref').'</td><td colspan="3">';
  160. print $form->showrefnav($object,'id','',1,'rowid','ref');
  161. print '</td></tr>';*/
  162. // Date payment
  163. print '<tr><td class="titlefield" colspan="2">'.$form->editfieldkey("Date", 'datep', $object->date, $object, $object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
  164. print $form->editfieldval("Date", 'datep', $object->date, $object, $object->statut == 0 && $user->rights->fournisseur->facture->creer, 'datehourpicker', '', null, $langs->trans('PaymentDateUpdateSucceeded'));
  165. print '</td></tr>';
  166. // Payment mode
  167. $labeltype = $langs->trans("PaymentType".$object->type_code) != ("PaymentType".$object->type_code) ? $langs->trans("PaymentType".$object->type_code) : $object->type_label;
  168. print '<tr><td colspan="2">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$labeltype;
  169. print $object->num_paiement ? ' - '.$object->num_paiement : '';
  170. print '</td></tr>';
  171. // Payment numero
  172. /* TODO Add field num_payment into payment table and save it
  173. print '<tr><td colspan="2">'.$form->editfieldkey("Numero",'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
  174. print $form->editfieldval("Numero",'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
  175. print '</td></tr>';
  176. */
  177. // Amount
  178. print '<tr><td colspan="2">'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->montant, '', $langs, 0, 0, -1, $conf->currency).'</td></tr>';
  179. if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
  180. {
  181. print '<tr><td colspan="2">'.$langs->trans('Status').'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>';
  182. }
  183. $allow_delete = 1;
  184. // Bank account
  185. if (!empty($conf->banque->enabled))
  186. {
  187. if ($object->bank_account)
  188. {
  189. $bankline = new AccountLine($db);
  190. $bankline->fetch($object->bank_line);
  191. if ($bankline->rappro)
  192. {
  193. $allow_delete = 0;
  194. $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
  195. }
  196. print '<tr>';
  197. print '<td colspan="2">'.$langs->trans('BankAccount').'</td>';
  198. print '<td colspan="3">';
  199. $accountstatic = new Account($db);
  200. $accountstatic->fetch($bankline->fk_account);
  201. print $accountstatic->getNomUrl(1);
  202. print '</td>';
  203. print '</tr>';
  204. print '<tr>';
  205. print '<td colspan="2">'.$langs->trans('BankTransactionLine').'</td>';
  206. print '<td colspan="3">';
  207. print $bankline->getNomUrl(1, 0, 'showconciliated');
  208. print '</td>';
  209. print '</tr>';
  210. }
  211. }
  212. // Note
  213. print '<tr><td colspan="2">'.$form->editfieldkey("Note", 'note', $object->note, $object, $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
  214. print $form->editfieldval("Note", 'note', $object->note, $object, $user->rights->fournisseur->facture->creer, 'textarea');
  215. print '</td></tr>';
  216. print '</table>';
  217. print '</div>';
  218. print '<br>';
  219. /**
  220. * Liste des factures
  221. */
  222. $sql = 'SELECT f.rowid, f.ref, f.ref_supplier, f.total_ttc, pf.amount, f.rowid as facid, f.paye, f.fk_statut, s.nom as name, s.rowid as socid';
  223. $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
  224. $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
  225. $sql .= ' AND pf.fk_paiementfourn = '.$object->id;
  226. $resql = $db->query($sql);
  227. if ($resql)
  228. {
  229. $num = $db->num_rows($resql);
  230. $i = 0;
  231. $total = 0;
  232. print '<b>'.$langs->trans("Invoices").'</b><br>';
  233. print '<table class="noborder centpercent">';
  234. print '<tr class="liste_titre">';
  235. print '<td>'.$langs->trans('Ref').'</td>';
  236. print '<td>'.$langs->trans('RefSupplier').'</td>';
  237. print '<td>'.$langs->trans('Company').'</td>';
  238. print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
  239. print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
  240. print '<td class="right">'.$langs->trans('Status').'</td>';
  241. print "</tr>\n";
  242. if ($num > 0)
  243. {
  244. $facturestatic = new FactureFournisseur($db);
  245. while ($i < $num)
  246. {
  247. $objp = $db->fetch_object($resql);
  248. $facturestatic->id = $objp->facid;
  249. $facturestatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
  250. print '<tr class="oddeven">';
  251. // Ref
  252. print '<td>';
  253. print $facturestatic->getNomUrl(1);
  254. print "</td>\n";
  255. // Ref supplier
  256. print '<td>'.$objp->ref_supplier."</td>\n";
  257. // Third party
  258. print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$objp->name.'</a></td>';
  259. // Expected to pay
  260. print '<td class="right">'.price($objp->total_ttc).'</td>';
  261. // Payed
  262. print '<td class="right">'.price($objp->amount).'</td>';
  263. // Status
  264. print '<td class="right">'.$facturestatic->LibStatut($objp->paye, $objp->fk_statut, 6, 1).'</td>';
  265. print "</tr>\n";
  266. if ($objp->paye == 1)
  267. {
  268. $allow_delete = 0;
  269. $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
  270. }
  271. $total = $total + $objp->amount;
  272. $i++;
  273. }
  274. }
  275. print "</table>\n";
  276. $db->free($resql);
  277. }
  278. else
  279. {
  280. dol_print_error($db);
  281. }
  282. print '</div>';
  283. /*
  284. * Boutons Actions
  285. */
  286. print '<div class="tabsAction">';
  287. if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION))
  288. {
  289. if ($user->socid == 0 && $object->statut == 0 && $action == '')
  290. {
  291. if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->facture->creer))
  292. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate)))
  293. {
  294. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=valide">'.$langs->trans('Valid').'</a>';
  295. }
  296. }
  297. }
  298. if ($user->socid == 0 && $action == '')
  299. {
  300. if ($user->rights->fournisseur->facture->supprimer)
  301. {
  302. if ($allow_delete)
  303. {
  304. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
  305. }
  306. else
  307. {
  308. print '<a class="butActionRefused classfortooltip" href="#" title="'.$title_button.'">'.$langs->trans('Delete').'</a>';
  309. }
  310. }
  311. }
  312. print '</div>';
  313. print '<div class="fichecenter"><div class="fichehalfleft">';
  314. // Documents generes
  315. include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
  316. $modellist = ModelePDFSuppliersPayments::liste_modeles($db);
  317. if (is_array($modellist))
  318. {
  319. $ref = dol_sanitizeFileName($object->ref);
  320. $filedir = $conf->fournisseur->payment->dir_output.'/'.dol_sanitizeFileName($object->ref);
  321. $urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;
  322. $genallowed = $user->rights->fournisseur->facture->lire;
  323. $delallowed = $user->rights->fournisseur->facture->creer;
  324. $modelpdf = (!empty($object->modelpdf) ? $object->modelpdf : (empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF) ? '' : $conf->global->SUPPLIER_PAYMENT_ADDON_PDF));
  325. print $formfile->showdocuments('supplier_payment', $ref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0, '', '', '', $societe->default_lang);
  326. $somethingshown = $formfile->numoffiles;
  327. }
  328. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  329. //print '<br>';
  330. // List of actions on element
  331. /*include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  332. $formactions=new FormActions($db);
  333. $somethingshown = $formactions->showactions($object,'supplier_payment',$socid,1,'listaction'.($genallowed?'largetitle':''));
  334. */
  335. print '</div></div></div>';
  336. }
  337. else
  338. {
  339. $langs->load("errors");
  340. print $langs->trans("ErrorRecordNotFound");
  341. }
  342. dol_fiche_end();
  343. // End of page
  344. llxFooter();
  345. $db->close();