card.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.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 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/compta/prelevement/card.php
  22. * \ingroup prelevement
  23. * \brief Card of a direct debit
  24. */
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('banks', 'categories', 'bills', 'withdrawals'));
  32. if (!$user->rights->prelevement->bons->lire)
  33. accessforbidden();
  34. // Security check
  35. if ($user->socid > 0) accessforbidden();
  36. // Get supervariables
  37. $action = GETPOST('action', 'alpha');
  38. $id = GETPOST('id', 'int');
  39. $ref = GETPOST('ref', 'alpha');
  40. $socid = GETPOST('socid', 'int');
  41. // Load variable for pagination
  42. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  43. $sortfield = GETPOST('sortfield', 'alpha');
  44. $sortorder = GETPOST('sortorder', 'alpha');
  45. $page = GETPOST('page', 'int');
  46. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  47. $offset = $limit * $page;
  48. $pageprev = $page - 1;
  49. $pagenext = $page + 1;
  50. if (!$sortfield) $sortfield = 'pl.fk_soc';
  51. if (!$sortorder) $sortorder = 'DESC';
  52. $object = new BonPrelevement($db, "");
  53. // Load object
  54. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once // Must be include, not include_once. Include fetch and fetch_thirdparty but not fetch_optionals
  55. $hookmanager->initHooks(array('directdebitprevcard', 'globalcard'));
  56. /*
  57. * Actions
  58. */
  59. $parameters = array('socid' => $socid);
  60. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  61. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  62. if (empty($reshook))
  63. {
  64. if ($action == 'confirm_delete')
  65. {
  66. $res = $object->delete($user);
  67. if ($res > 0)
  68. {
  69. header("Location: index.php");
  70. exit;
  71. }
  72. }
  73. // Seems to no be used and replaced with $action == 'infocredit'
  74. if ($action == 'confirm_credite' && GETPOST('confirm', 'alpha') == 'yes')
  75. {
  76. $res = $object->set_credite();
  77. if ($res >= 0)
  78. {
  79. header("Location: card.php?id=".$id);
  80. exit;
  81. }
  82. }
  83. if ($action == 'infotrans' && $user->rights->prelevement->bons->send)
  84. {
  85. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  86. $dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  87. /*
  88. if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $object->ref)
  89. {
  90. $dir = $conf->prelevement->dir_output.'/receipts';
  91. if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . dol_unescapefile($_FILES['userfile']['name']),1) > 0)
  92. {
  93. $object->set_infotrans($user, $dt, GETPOST('methode','alpha'));
  94. }
  95. header("Location: card.php?id=".$id);
  96. exit;
  97. }
  98. else
  99. {
  100. dol_syslog("Fichier invalide",LOG_WARNING);
  101. $mesg='BadFile';
  102. }*/
  103. $error = $object->set_infotrans($user, $dt, GETPOST('methode', 'alpha'));
  104. if ($error)
  105. {
  106. header("Location: card.php?id=".$id."&error=$error");
  107. exit;
  108. }
  109. }
  110. // Set direct debit order to credited, create payment and close invoices
  111. if ($action == 'infocredit' && $user->rights->prelevement->bons->credit)
  112. {
  113. $dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  114. $error = $object->set_infocredit($user, $dt);
  115. if ($error)
  116. {
  117. header("Location: card.php?id=".$id."&error=$error");
  118. exit;
  119. }
  120. }
  121. }
  122. /*
  123. * View
  124. */
  125. $form = new Form($db);
  126. llxHeader('', $langs->trans("WithdrawalsReceipts"));
  127. if ($id > 0 || $ref)
  128. {
  129. $head = prelevement_prepare_head($object);
  130. dol_fiche_head($head, 'prelevement', $langs->trans("WithdrawalsReceipts"), -1, 'payment');
  131. if (GETPOST('error', 'alpha') != '')
  132. {
  133. print '<div class="error">'.$object->getErrorString(GETPOST('error', 'alpha')).'</div>';
  134. }
  135. /*if ($action == 'credite')
  136. {
  137. print $form->formconfirm("card.php?id=".$object->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite",'',1,1);
  138. }*/
  139. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/prelevement/bons.php">'.$langs->trans("BackToList").'</a>';
  140. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref');
  141. print '<div class="fichecenter">';
  142. print '<div class="underbanner clearboth"></div>';
  143. print '<table class="border centpercent tableforfield">';
  144. //print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>'.$object->getNomUrl(1).'</td></tr>';
  145. print '<tr><td class="titlefield">'.$langs->trans("Date").'</td><td>'.dol_print_date($object->datec, 'day').'</td></tr>';
  146. print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
  147. // Status
  148. /*
  149. print '<tr><td>'.$langs->trans('Status').'</td>';
  150. print '<td>'.$object->getLibStatut(1).'</td>';
  151. print '</tr>';
  152. */
  153. if ($object->date_trans <> 0)
  154. {
  155. $muser = new User($db);
  156. $muser->fetch($object->user_trans);
  157. print '<tr><td>'.$langs->trans("TransData").'</td><td>';
  158. print dol_print_date($object->date_trans, 'day');
  159. print ' '.$langs->trans("By").' '.$muser->getFullName($langs).'</td></tr>';
  160. print '<tr><td>'.$langs->trans("TransMetod").'</td><td>';
  161. print $object->methodes_trans[$object->method_trans];
  162. print '</td></tr>';
  163. }
  164. if ($object->date_credit <> 0)
  165. {
  166. print '<tr><td>'.$langs->trans('CreditDate').'</td><td>';
  167. print dol_print_date($object->date_credit, 'day');
  168. print '</td></tr>';
  169. }
  170. print '</table>';
  171. print '<br>';
  172. print '<div class="underbanner clearboth"></div>';
  173. print '<table class="border centpercent tableforfield">';
  174. $acc = new Account($db);
  175. $result = $acc->fetch($conf->global->PRELEVEMENT_ID_BANKACCOUNT);
  176. print '<tr><td class="titlefield">';
  177. print $langs->trans("BankToReceiveWithdraw");
  178. print '</td>';
  179. print '<td>';
  180. if ($acc->id > 0)
  181. print $acc->getNomUrl(1);
  182. print '</td>';
  183. print '</tr>';
  184. print '<tr><td class="titlefield">';
  185. print $langs->trans("WithdrawalFile").'</td><td>';
  186. $relativepath = 'receipts/'.$object->ref.'.xml';
  187. print '<a data-ajax="false" href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart=prelevement&amp;file='.urlencode($relativepath).'">'.$relativepath.'</a>';
  188. print '</td></tr></table>';
  189. print '</div>';
  190. dol_fiche_end();
  191. $formconfirm = '';
  192. // Confirmation to delete
  193. if ($action == 'delete')
  194. {
  195. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('Delete'), $langs->trans('ConfirmDeleteObject'), 'confirm_delete', '', 0, 1);
  196. }
  197. // Call Hook formConfirm
  198. /*$parameters = array();
  199. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  200. if (empty($reshook)) $formconfirm.=$hookmanager->resPrint;
  201. elseif ($reshook > 0) $formconfirm=$hookmanager->resPrint;*/
  202. // Print form confirm
  203. print $formconfirm;
  204. if (empty($object->date_trans) && $user->rights->prelevement->bons->send && $action == 'settransmitted')
  205. {
  206. print '<form method="post" name="userfile" action="card.php?id='.$object->id.'" enctype="multipart/form-data">';
  207. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  208. print '<input type="hidden" name="action" value="infotrans">';
  209. print '<table class="noborder centpercent">';
  210. print '<tr class="liste_titre">';
  211. print '<td colspan="3">'.$langs->trans("NotifyTransmision").'</td></tr>';
  212. print '<tr class="oddeven"><td>'.$langs->trans("TransData").'</td><td>';
  213. print $form->selectDate('', '', '', '', '', "userfile", 1, 1);
  214. print '</td></tr>';
  215. print '<tr class="oddeven"><td>'.$langs->trans("TransMetod").'</td><td>';
  216. print $form->selectarray("methode", $object->methodes_trans);
  217. print '</td></tr>';
  218. /*print '<tr><td width="20%">'.$langs->trans("File").'</td><td>';
  219. print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
  220. print '<input class="flat" type="file" name="userfile"><br>';
  221. print '</td></tr>';*/
  222. print '</table><br>';
  223. print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("SetToStatusSent")).'"></div>';
  224. print '</form>';
  225. print '<br>';
  226. }
  227. if (!empty($object->date_trans) && $object->date_credit == 0 && $user->rights->prelevement->bons->credit && $action == 'setcredited')
  228. {
  229. print '<form name="infocredit" method="post" action="card.php?id='.$object->id.'">';
  230. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  231. print '<input type="hidden" name="action" value="infocredit">';
  232. print '<table class="noborder centpercent">';
  233. print '<tr class="liste_titre">';
  234. print '<td colspan="3">'.$langs->trans("NotifyCredit").'</td></tr>';
  235. print '<tr class="oddeven"><td>'.$langs->trans('CreditDate').'</td><td>';
  236. print $form->selectDate('', '', '', '', '', "infocredit", 1, 1);
  237. print '</td></tr>';
  238. print '</table>';
  239. print '<br>'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice");
  240. print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("ClassCredited")).'"></div>';
  241. print '</form>';
  242. print '<br>';
  243. }
  244. // Actions
  245. if ($action != 'settransmitted' && $action != 'setcredited')
  246. {
  247. print "\n<div class=\"tabsAction\">\n";
  248. if (empty($object->date_trans) && $user->rights->prelevement->bons->send)
  249. {
  250. print "<a class=\"butAction\" href=\"card.php?action=settransmitted&id=".$object->id."\">".$langs->trans("SetToStatusSent")."</a>";
  251. }
  252. if (!empty($object->date_trans) && $object->date_credit == 0)
  253. {
  254. print "<a class=\"butAction\" href=\"card.php?action=setcredited&id=".$object->id."\">".$langs->trans("ClassCredited")."</a>";
  255. }
  256. print "<a class=\"butActionDelete\" href=\"card.php?action=delete&id=".$object->id."\">".$langs->trans("Delete")."</a>";
  257. print "</div>";
  258. }
  259. $ligne = new LignePrelevement($db, $user);
  260. /*
  261. * Lines into withdraw request
  262. */
  263. $sql = "SELECT pl.rowid, pl.statut, pl.amount,";
  264. $sql .= " s.rowid as socid, s.nom as name";
  265. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl";
  266. $sql .= ", ".MAIN_DB_PREFIX."prelevement_bons as pb";
  267. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  268. $sql .= " WHERE pl.fk_prelevement_bons = ".$id;
  269. $sql .= " AND pl.fk_prelevement_bons = pb.rowid";
  270. $sql .= " AND pb.entity = ".$conf->entity;
  271. $sql .= " AND pl.fk_soc = s.rowid";
  272. if ($socid) $sql .= " AND s.rowid = ".$socid;
  273. $sql .= $db->order($sortfield, $sortorder);
  274. // Count total nb of records
  275. $nbtotalofrecords = '';
  276. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  277. {
  278. $result = $db->query($sql);
  279. $nbtotalofrecords = $db->num_rows($result);
  280. if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
  281. {
  282. $page = 0;
  283. $offset = 0;
  284. }
  285. }
  286. $sql .= $db->plimit($limit + 1, $offset);
  287. $result = $db->query($sql);
  288. if ($result)
  289. {
  290. $num = $db->num_rows($result);
  291. $i = 0;
  292. $urladd = "&amp;id=".$id;
  293. print_barre_liste($langs->trans("Lines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
  294. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  295. print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
  296. print '<tr class="liste_titre">';
  297. print_liste_field_titre("Lines", $_SERVER["PHP_SELF"], "pl.rowid", '', $urladd);
  298. print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "s.nom", '', $urladd);
  299. print_liste_field_titre("Amount", $_SERVER["PHP_SELF"], "pl.amount", "", $urladd, 'class="right"');
  300. print_liste_field_titre('');
  301. print "</tr>\n";
  302. $total = 0;
  303. while ($i < min($num, $conf->liste_limit))
  304. {
  305. $obj = $db->fetch_object($result);
  306. print '<tr class="oddeven">';
  307. // Status of line
  308. print "<td>";
  309. print $ligne->LibStatut($obj->statut, 2);
  310. print "&nbsp;";
  311. print '<a href="'.DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$obj->rowid.'">';
  312. print sprintf("%06s", $obj->rowid);
  313. print '</a></td>';
  314. $thirdparty = new Societe($db);
  315. $thirdparty->fetch($obj->socid);
  316. print '<td>';
  317. print $thirdparty->getNomUrl(1);
  318. print "</td>\n";
  319. print '<td class="right">'.price($obj->amount)."</td>\n";
  320. print '<td>';
  321. if ($obj->statut == 3)
  322. {
  323. print '<b>'.$langs->trans("StatusRefused").'</b>';
  324. }
  325. else
  326. {
  327. print "&nbsp;";
  328. }
  329. print '</td></tr>';
  330. $total += $obj->amount;
  331. $i++;
  332. }
  333. if ($num > 0)
  334. {
  335. print '<tr class="liste_total">';
  336. print '<td>'.$langs->trans("Total").'</td>';
  337. print '<td>&nbsp;</td>';
  338. print '<td class="right">';
  339. if (empty($offset) && $num <= $limit) // If we have all record on same page, then the following test/warning can be done
  340. {
  341. if ($total != $object->amount) print img_warning("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines");
  342. }
  343. print price($total);
  344. print "</td>\n";
  345. print '<td>&nbsp;</td>';
  346. print "</tr>\n";
  347. }
  348. print "</table>";
  349. print '</div>';
  350. $db->free($result);
  351. }
  352. else
  353. {
  354. dol_print_error($db);
  355. }
  356. }
  357. // End of page
  358. llxFooter();
  359. $db->close();