line.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?php
  2. /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/prelevement/line.php
  23. * \ingroup prelevement
  24. * \brief card of withdraw line
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  33. // Load translation files required by the page
  34. $langs->loadlangs(array('banks', 'categories', 'bills', 'withdrawals'));
  35. // Get supervariables
  36. $action = GETPOST('action', 'aZ09');
  37. $id = GETPOST('id', 'int');
  38. $socid = GETPOST('socid', 'int');
  39. $type = GETPOST('type', 'aZ09');
  40. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  41. $sortorder = GETPOST('sortorder', 'aZ09comma');
  42. $sortfield = GETPOST('sortfield', 'aZ09comma');
  43. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  44. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  45. // If $page is not defined, or '' or -1 or if we click on clear filters
  46. $page = 0;
  47. }
  48. $offset = $limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. if ($sortorder == "") {
  52. $sortorder = "DESC";
  53. }
  54. if ($sortfield == "") {
  55. $sortfield = "pl.fk_soc";
  56. }
  57. if ($type == 'bank-transfer') {
  58. $result = restrictedArea($user, 'paymentbybanktransfer', '', '', '');
  59. } else {
  60. $result = restrictedArea($user, 'prelevement', '', '', 'bons');
  61. }
  62. /*
  63. * Actions
  64. */
  65. if ($action == 'confirm_rejet') {
  66. if (GETPOST("confirm") == 'yes') {
  67. if (GETPOST('remonth', 'int')) {
  68. $daterej = mktime(2, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  69. }
  70. if (empty($daterej)) {
  71. $error++;
  72. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  73. } elseif ($daterej > dol_now()) {
  74. $error++;
  75. $langs->load("error");
  76. setEventMessages($langs->transnoentities("ErrorDateMustBeBeforeToday"), null, 'errors');
  77. }
  78. if (GETPOST('motif', 'alpha') == 0) {
  79. $error++;
  80. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefusedReason")), null, 'errors');
  81. }
  82. if (!$error) {
  83. $lipre = new LignePrelevement($db);
  84. if ($lipre->fetch($id) == 0) {
  85. $rej = new RejetPrelevement($db, $user, $type);
  86. $rej->create($user, $id, GETPOST('motif', 'alpha'), $daterej, $lipre->bon_rowid, GETPOST('facturer', 'int'));
  87. header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
  88. exit;
  89. }
  90. } else {
  91. $action = "rejet";
  92. }
  93. } else {
  94. header("Location: line.php?id=".urlencode($id).'&type='.urlencode($type));
  95. exit;
  96. }
  97. }
  98. /*
  99. * View
  100. */
  101. $invoicestatic = new Facture($db);
  102. $title = $langs->trans("WithdrawalsLine");
  103. if ($type == 'bank-transfer') {
  104. $title = $langs->trans("CreditTransferLine");
  105. }
  106. llxHeader('', $title);
  107. $head = array();
  108. $h = 0;
  109. $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/line.php?id='.$id.'&type='.$type;
  110. $head[$h][1] = $title;
  111. $hselected = $h;
  112. $h++;
  113. if ($id) {
  114. $lipre = new LignePrelevement($db);
  115. if ($lipre->fetch($id) >= 0) {
  116. $bon = new BonPrelevement($db);
  117. $bon->fetch($lipre->bon_rowid);
  118. print dol_get_fiche_head($head, $hselected, $title);
  119. print '<table class="border centpercent tableforfield">';
  120. print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
  121. print $id.'</td></tr>';
  122. print '<tr><td class="titlefield">'.$langs->trans("WithdrawalsReceipts").'</td><td>';
  123. print $bon->getNomUrl(1).'</td></tr>';
  124. print '<tr><td>'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec, 'day').'</td></tr>';
  125. print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($lipre->amount).'</span></td></tr>';
  126. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$lipre->LibStatut($lipre->statut, 1).'</td></tr>';
  127. if ($lipre->statut == 3) {
  128. $rej = new RejetPrelevement($db, $user, $type);
  129. $resf = $rej->fetch($lipre->id);
  130. if ($resf == 0) {
  131. print '<tr><td>'.$langs->trans("RefusedReason").'</td><td>'.$rej->motif.'</td></tr>';
  132. print '<tr><td>'.$langs->trans("RefusedData").'</td><td>';
  133. if ($rej->date_rejet == 0) {
  134. /* Historique pour certaines install */
  135. print $langs->trans("Unknown");
  136. } else {
  137. print dol_print_date($rej->date_rejet, 'day');
  138. }
  139. print '</td></tr>';
  140. print '<tr><td>'.$langs->trans("RefusedInvoicing").'</td><td>'.$rej->invoicing.'</td></tr>';
  141. } else {
  142. print '<tr><td>'.$resf.'</td></tr>';
  143. }
  144. }
  145. print '</table>';
  146. print dol_get_fiche_end();
  147. } else {
  148. dol_print_error($db);
  149. }
  150. if ($action == 'rejet' && $user->rights->prelevement->bons->credit) {
  151. $form = new Form($db);
  152. $soc = new Societe($db);
  153. $soc->fetch($lipre->socid);
  154. $rej = new RejetPrelevement($db, $user, $type);
  155. print '<form name="confirm_rejet" method="post" action="line.php?id='.$id.'">';
  156. print '<input type="hidden" name="token" value="'.newToken().'">';
  157. print '<input type="hidden" name="action" value="confirm_rejet">';
  158. print '<input type="hidden" name="type" value="'.$type.'">';
  159. print '<table class="noborder centpercent">';
  160. print '<tr class="liste_titre">';
  161. print '<td colspan="3">'.$langs->trans("WithdrawalRefused").'</td></tr>';
  162. //Select yes/no
  163. print '<tr><td class="valid">'.$langs->trans("WithdrawalRefusedConfirm").' '.$soc->name.' ?</td>';
  164. print '<td colspan="2" class="valid">';
  165. print $form->selectyesno("confirm", 1, 0);
  166. print '</td></tr>';
  167. //Date
  168. print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedData").'</td>';
  169. print '<td colspan="2" class="valid">';
  170. print $form->selectDate('', '', '', '', '', "confirm_rejet");
  171. print '</td></tr>';
  172. //Reason
  173. print '<tr><td class="fieldrequired valid">'.$langs->trans("RefusedReason").'</td>';
  174. print '<td class="valid">';
  175. print $form->selectarray("motif", $rej->motifs, GETPOSTISSET('motif') ? GETPOST('motif', 'int') : '');
  176. print '</td></tr>';
  177. //Facturer
  178. print '<tr><td class="valid">'.$langs->trans("RefusedInvoicing").'</td>';
  179. print '<td class="valid" colspan="2">';
  180. print $form->selectarray("facturer", $rej->facturer, GETPOSTISSET('facturer') ? GETPOST('facturer', 'int') : '');
  181. print '</td></tr>';
  182. print '</table><br>';
  183. //Confirm Button
  184. print '<div class="center"><input type="submit" class="button button-save" value='.$langs->trans("Confirm").'></div>';
  185. print '</form>';
  186. }
  187. /*
  188. * Action bar
  189. */
  190. print '<div class="tabsAction">';
  191. if ($action == '') {
  192. if ($bon->statut == BonPrelevement::STATUS_CREDITED) {
  193. if ($lipre->statut == 2) {
  194. if ($user->rights->prelevement->bons->credit) {
  195. print '<a class="butActionDelete" href="line.php?action=rejet&type='.$type.'&id='.$lipre->id.'">'.$langs->trans("StandingOrderReject").'</a>';
  196. } else {
  197. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotAllowed").'">'.$langs->trans("StandingOrderReject").'</a>';
  198. }
  199. }
  200. } else {
  201. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotPossibleForThisStatusOfWithdrawReceiptORLine").'">'.$langs->trans("StandingOrderReject").'</a>';
  202. }
  203. }
  204. print '</div>';
  205. /*
  206. * List of invoices
  207. */
  208. $sql = "SELECT pf.rowid";
  209. $sql .= " ,f.rowid as facid, f.ref as ref, f.total_ttc, f.paye, f.fk_statut";
  210. $sql .= " , s.rowid as socid, s.nom as name";
  211. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
  212. $sql .= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
  213. $sql .= " , ".MAIN_DB_PREFIX."prelevement as pf";
  214. if ($type == 'bank-transfer') {
  215. $sql .= " , ".MAIN_DB_PREFIX."facture_fourn as f";
  216. } else {
  217. $sql .= " , ".MAIN_DB_PREFIX."facture as f";
  218. }
  219. $sql .= " , ".MAIN_DB_PREFIX."societe as s";
  220. $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid";
  221. $sql .= " AND pl.fk_prelevement_bons = p.rowid";
  222. $sql .= " AND f.fk_soc = s.rowid";
  223. if ($type == 'bank-transfer') {
  224. $sql .= " AND pf.fk_facture_fourn = f.rowid";
  225. } else {
  226. $sql .= " AND pf.fk_facture = f.rowid";
  227. }
  228. $sql .= " AND f.entity IN (".getEntity('invoice').")";
  229. $sql .= " AND pl.rowid = ".((int) $id);
  230. if ($socid) {
  231. $sql .= " AND s.rowid = ".((int) $socid);
  232. }
  233. $sql .= $db->order($sortfield, $sortorder);
  234. $sql .= $db->plimit($conf->liste_limit + 1, $offset);
  235. $result = $db->query($sql);
  236. if ($result) {
  237. $num = $db->num_rows($result);
  238. $i = 0;
  239. $urladd = "&id=".urlencode($id);
  240. print_barre_liste($langs->trans("Bills"), $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, '');
  241. print"\n<!-- debut table -->\n";
  242. print '<table class="noborder" width="100%" cellpadding="4">';
  243. print '<tr class="liste_titre">';
  244. print '<td>'.$langs->trans("Invoice").'</td><td>'.$langs->trans("ThirdParty").'</td><td class="right">'.$langs->trans("Amount").'</td><td class="right">'.$langs->trans("Status").'</td>';
  245. print '</tr>';
  246. $total = 0;
  247. while ($i < min($num, $conf->liste_limit)) {
  248. $obj = $db->fetch_object($result);
  249. print '<tr class="oddeven"><td>';
  250. print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">';
  251. print img_object($langs->trans("ShowBill"), "bill");
  252. print '</a>&nbsp;';
  253. if ($type == 'bank-transfer') {
  254. print '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
  255. } else {
  256. print '<a href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
  257. }
  258. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">';
  259. print img_object($langs->trans("ShowCompany"), "company").' '.$obj->name."</a></td>\n";
  260. print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
  261. print '<td class="right">';
  262. $invoicestatic->fetch($obj->facid);
  263. print $invoicestatic->getLibStatut(5);
  264. print "</td>\n";
  265. print "</tr>\n";
  266. $i++;
  267. }
  268. print "</table>";
  269. $db->free($result);
  270. } else {
  271. dol_print_error($db);
  272. }
  273. }
  274. // End of page
  275. llxFooter();
  276. $db->close();