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

/htdocs/fourn/paiement/card.php

http://github.com/Dolibarr/dolibarr
PHP | 423 lines | 264 code | 75 blank | 84 comment | 90 complexity | 93df93d21f0e81b330b381c12e2da7c9 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-3.0, LGPL-2.0, CC-BY-SA-4.0, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, 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_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  31. require_once 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. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  38. $hookmanager->initHooks(array('supplierpaymentcard', 'globalcard'));
  39. // Load object
  40. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once.
  41. $result = restrictedArea($user, $object->element, $object->id, 'paiementfourn', '');
  42. // Security check
  43. if ($user->socid) {
  44. $socid = $user->socid;
  45. }
  46. // Now check also permission on thirdparty of invoices of payments. Thirdparty were loaded by the fetch_object before based on first invoice.
  47. // It should be enough because all payments are done on invoices of the same thirdparty.
  48. if ($socid && $socid != $object->thirdparty->id) {
  49. accessforbidden();
  50. }
  51. /*
  52. * Actions
  53. */
  54. if ($action == 'setnote' && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)) {
  55. $db->begin();
  56. $object->fetch($id);
  57. $result = $object->update_note(GETPOST('note', 'restricthtml'));
  58. if ($result > 0) {
  59. $db->commit();
  60. $action = '';
  61. } else {
  62. setEventMessages($object->error, $object->errors, 'errors');
  63. $db->rollback();
  64. }
  65. }
  66. if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer) {
  67. $db->begin();
  68. $object->fetch($id);
  69. $result = $object->delete();
  70. if ($result > 0) {
  71. $db->commit();
  72. header('Location: '.DOL_URL_ROOT.'/fourn/paiement/list.php');
  73. exit;
  74. } else {
  75. setEventMessages($object->error, $object->errors, 'errors');
  76. $db->rollback();
  77. }
  78. }
  79. if ($action == 'confirm_validate' && $confirm == 'yes' &&
  80. ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && (!empty($user->rights->fournisseur->facture->creer) || !empty($user->rights->supplier_invoice->creer)))
  81. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate)))
  82. ) {
  83. $db->begin();
  84. $object->fetch($id);
  85. if ($object->validate() >= 0) {
  86. $db->commit();
  87. header('Location: '.$_SERVER['PHP_SELF'].'?id='.$object->id);
  88. exit;
  89. } else {
  90. setEventMessages($object->error, $object->errors, 'errors');
  91. $db->rollback();
  92. }
  93. }
  94. if ($action == 'setnum_paiement' && !empty($_POST['num_paiement'])) {
  95. $object->fetch($id);
  96. $res = $object->update_num($_POST['num_paiement']);
  97. if ($res === 0) {
  98. setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs');
  99. } else {
  100. setEventMessages($langs->trans('PaymentNumberUpdateFailed'), null, 'errors');
  101. }
  102. }
  103. if ($action == 'setdatep' && !empty($_POST['datepday'])) {
  104. $object->fetch($id);
  105. $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'));
  106. $res = $object->update_date($datepaye);
  107. if ($res === 0) {
  108. setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs');
  109. } else {
  110. setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors');
  111. }
  112. }
  113. // Build document
  114. $upload_dir = $conf->fournisseur->payment->dir_output;
  115. // TODO: get the appropriate permission
  116. $permissiontoadd = true;
  117. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  118. // Actions to send emails
  119. $triggersendname = 'PAYMENTRECEIPT_SENTBYMAIL';
  120. $paramname = 'id';
  121. $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
  122. $trackid = 'pre'.$object->id;
  123. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  124. /*
  125. * View
  126. */
  127. llxHeader();
  128. $result = $object->fetch($id);
  129. $form = new Form($db);
  130. $formfile = new FormFile($db);
  131. $head = payment_supplier_prepare_head($object);
  132. print dol_get_fiche_head($head, 'payment', $langs->trans('SupplierPayment'), -1, 'payment');
  133. if ($result > 0) {
  134. /*
  135. * Confirmation of payment's delete
  136. */
  137. if ($action == 'delete') {
  138. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
  139. }
  140. /*
  141. * Confirmation of payment's validation
  142. */
  143. if ($action == 'validate') {
  144. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_validate');
  145. }
  146. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/paiement/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  147. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref');
  148. print '<div class="fichecenter">';
  149. print '<div class="underbanner clearboth"></div>';
  150. print '<table class="border centpercent">';
  151. /*print '<tr>';
  152. print '<td width="20%">'.$langs->trans('Ref').'</td><td>';
  153. print $form->showrefnav($object,'id','',1,'rowid','ref');
  154. print '</td></tr>';*/
  155. // Date of payment
  156. print '<tr><td class="titlefield">'.$form->editfieldkey("Date", 'datep', $object->date, $object, $object->statut == 0 && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)).'</td>';
  157. print '<td>';
  158. print $form->editfieldval("Date", 'datep', $object->date, $object, $object->statut == 0 && ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer), 'datehourpicker', '', null, $langs->trans('PaymentDateUpdateSucceeded'));
  159. print '</td></tr>';
  160. // Payment mode
  161. $labeltype = $langs->trans("PaymentType".$object->type_code) != ("PaymentType".$object->type_code) ? $langs->trans("PaymentType".$object->type_code) : $object->type_label;
  162. print '<tr><td>'.$langs->trans('PaymentMode').'</td>';
  163. print '<td>'.$labeltype;
  164. print $object->num_payment ? ' - '.$object->num_payment : '';
  165. print '</td></tr>';
  166. // Payment numero
  167. /* TODO Add field num_payment into payment table and save it
  168. print '<tr><td>'.$form->editfieldkey("Numero",'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer).'</td>';
  169. print '<td>';
  170. print $form->editfieldval("Numero",'num_paiement',$object->num_paiement,$object,$object->statut == 0 && $user->rights->fournisseur->facture->creer,'string','',null,$langs->trans('PaymentNumberUpdateSucceeded'));
  171. print '</td></tr>';
  172. */
  173. // Amount
  174. print '<tr><td>'.$langs->trans('Amount').'</td>';
  175. print '<td>'.price($object->amount, '', $langs, 0, 0, -1, $conf->currency).'</td></tr>';
  176. if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
  177. print '<tr><td>'.$langs->trans('Status').'</td>';
  178. print '<td>'.$object->getLibStatut(4).'</td></tr>';
  179. }
  180. $allow_delete = 1;
  181. // Bank account
  182. if (!empty($conf->banque->enabled)) {
  183. if ($object->fk_account) {
  184. $bankline = new AccountLine($db);
  185. $bankline->fetch($object->bank_line);
  186. if ($bankline->rappro) {
  187. $allow_delete = 0;
  188. $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemoveConciliatedPayment"));
  189. }
  190. print '<tr>';
  191. print '<td>'.$langs->trans('BankAccount').'</td>';
  192. print '<td>';
  193. $accountstatic = new Account($db);
  194. $accountstatic->fetch($bankline->fk_account);
  195. print $accountstatic->getNomUrl(1);
  196. print '</td>';
  197. print '</tr>';
  198. print '<tr>';
  199. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  200. print '<td>';
  201. print $bankline->getNomUrl(1, 0, 'showconciliated');
  202. print '</td>';
  203. print '</tr>';
  204. }
  205. }
  206. // Note
  207. print '<tr><td>'.$form->editfieldkey("Comments", 'note', $object->note, $object, ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer)).'</td>';
  208. print '<td>';
  209. print $form->editfieldval("Note", 'note', $object->note, $object, ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer), 'textarea');
  210. print '</td></tr>';
  211. print '</table>';
  212. print '</div>';
  213. print '<br>';
  214. /**
  215. * List of seller's invoices
  216. */
  217. $sql = 'SELECT f.rowid, f.rowid as facid, f.ref, f.ref_supplier, f.type, f.paye, f.total_ht, f.total_tva, f.total_ttc, f.datef as date, f.fk_statut as status,';
  218. $sql .= ' pf.amount, s.nom as name, s.rowid as socid';
  219. $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf,'.MAIN_DB_PREFIX.'facture_fourn as f,'.MAIN_DB_PREFIX.'societe as s';
  220. $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND f.fk_soc = s.rowid';
  221. $sql .= ' AND pf.fk_paiementfourn = '.((int) $object->id);
  222. $resql = $db->query($sql);
  223. if ($resql) {
  224. $num = $db->num_rows($resql);
  225. $i = 0;
  226. $total = 0;
  227. print '<table class="noborder centpercent">';
  228. print '<tr class="liste_titre">';
  229. print '<td>'.$langs->trans('Invoice').'</td>';
  230. print '<td>'.$langs->trans('RefSupplier').'</td>';
  231. print '<td>'.$langs->trans('Company').'</td>';
  232. print '<td class="right">'.$langs->trans('ExpectedToPay').'</td>';
  233. print '<td class="right">'.$langs->trans('PayedByThisPayment').'</td>';
  234. print '<td class="right">'.$langs->trans('Status').'</td>';
  235. print "</tr>\n";
  236. if ($num > 0) {
  237. $facturestatic = new FactureFournisseur($db);
  238. while ($i < $num) {
  239. $objp = $db->fetch_object($resql);
  240. $facturestatic->id = $objp->facid;
  241. $facturestatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
  242. $facturestatic->date = $db->jdate($objp->date);
  243. $facturestatic->type = $objp->type;
  244. $facturestatic->total_ht = $objp->total_ht;
  245. $facturestatic->total_tva = $objp->total_tva;
  246. $facturestatic->total_ttc = $objp->total_ttc;
  247. $facturestatic->statut = $objp->status;
  248. $facturestatic->alreadypaid = -1; // unknown
  249. print '<tr class="oddeven">';
  250. // Ref
  251. print '<td>';
  252. print $facturestatic->getNomUrl(1);
  253. print "</td>\n";
  254. // Ref supplier
  255. print '<td>'.$objp->ref_supplier."</td>\n";
  256. // Third party
  257. print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$objp->socid.'">'.img_object($langs->trans('ShowCompany'), 'company').' '.$objp->name.'</a></td>';
  258. // Expected to pay
  259. print '<td class="right">'.price($objp->total_ttc).'</td>';
  260. // Paid
  261. print '<td class="right">'.price($objp->amount).'</td>';
  262. // Status
  263. print '<td class="right">'.$facturestatic->LibStatut($objp->paye, $objp->status, 6, 1).'</td>';
  264. print "</tr>\n";
  265. if ($objp->paye == 1) {
  266. $allow_delete = 0;
  267. $title_button = dol_escape_htmltag($langs->transnoentitiesnoconv("CantRemovePaymentWithOneInvoicePaid"));
  268. }
  269. $total = $total + $objp->amount;
  270. $i++;
  271. }
  272. }
  273. print "</table>\n";
  274. $db->free($resql);
  275. } else {
  276. dol_print_error($db);
  277. }
  278. print '</div>';
  279. /*
  280. * Actions Buttons
  281. */
  282. print '<div class="tabsAction">';
  283. // Send by mail
  284. if ($user->socid == 0 && $action == '') {
  285. $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS));
  286. if ($usercansend) {
  287. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>';
  288. } else {
  289. print '<span class="butActionRefused classfortooltip">'.$langs->trans('SendMail').'</span>';
  290. }
  291. }
  292. // Payment validation
  293. if (!empty($conf->global->BILL_ADD_PAYMENT_VALIDATION)) {
  294. if ($user->socid == 0 && $object->statut == 0 && $action == '') {
  295. if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && (!empty($user->rights->fournisseur->facture->creer) || !empty($user->rights->supplier_invoice->creer)))
  296. || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_invoice_advance->validate))) {
  297. print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=validate">'.$langs->trans('Valid').'</a>';
  298. }
  299. }
  300. }
  301. // Delete payment
  302. if ($user->socid == 0 && $action == '') {
  303. if ($user->rights->fournisseur->facture->supprimer) {
  304. if ($allow_delete) {
  305. print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans('Delete').'</a>';
  306. } else {
  307. print '<a class="butActionRefused classfortooltip" href="#" title="'.$title_button.'">'.$langs->trans('Delete').'</a>';
  308. }
  309. }
  310. }
  311. print '</div>';
  312. print '<div class="fichecenter"><div class="fichehalfleft">';
  313. // Generated documents
  314. include_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_payment/modules_supplier_payment.php';
  315. $modellist = ModelePDFSuppliersPayments::liste_modeles($db);
  316. if (is_array($modellist)) {
  317. $ref = dol_sanitizeFileName($object->ref);
  318. $filedir = $conf->fournisseur->payment->dir_output.'/'.dol_sanitizeFileName($object->ref);
  319. $urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;
  320. $genallowed = ($user->rights->fournisseur->facture->lire || $user->rights->supplier_invoice->lire);
  321. $delallowed = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer);
  322. $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF) ? '' : $conf->global->SUPPLIER_PAYMENT_ADDON_PDF));
  323. print $formfile->showdocuments('supplier_payment', $ref, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0, '', '', '', $societe->default_lang);
  324. $somethingshown = $formfile->numoffiles;
  325. }
  326. print '</div><div class="fichehalfright">';
  327. //print '<br>';
  328. // List of actions on element
  329. /*include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  330. $formactions=new FormActions($db);
  331. $somethingshown = $formactions->showactions($object,'supplier_payment',$socid,1,'listaction'.($genallowed?'largetitle':''));
  332. */
  333. print '</div></div>';
  334. // Presend form
  335. $modelmail = ''; //TODO: Add new 'payment receipt' model in email models
  336. $defaulttopic = 'SendPaymentReceipt';
  337. $diroutput = $conf->fournisseur->payment->dir_output;
  338. $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
  339. $trackid = 'pre'.$object->id;
  340. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  341. } else {
  342. $langs->load("errors");
  343. print $langs->trans("ErrorRecordNotFound");
  344. }
  345. print dol_get_fiche_end();
  346. // End of page
  347. llxFooter();
  348. $db->close();