card.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /* Copyright (C) 2011-2014 Juanjo Menent <jmenent@2byte.es>
  3. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  4. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/compta/localtax/card.php
  21. * \ingroup tax
  22. * \brief Page of second or third tax payments (like IRPF for spain, ...)
  23. */
  24. // Load Dolibarr environment
  25. require '../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/compta/localtax/class/localtax.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array('compta', 'banks', 'bills'));
  31. $id = GETPOST("id", 'int');
  32. $action = GETPOST("action", "aZ09");
  33. $cancel = GETPOST('cancel', 'aZ09');
  34. $refund = GETPOST("refund", "int");
  35. if (empty($refund)) {
  36. $refund = 0;
  37. }
  38. $lttype = GETPOST('localTaxType', 'int');
  39. // Security check
  40. $socid = GETPOST('socid', 'int');
  41. if ($user->socid) {
  42. $socid = $user->socid;
  43. }
  44. $result = restrictedArea($user, 'tax', '', '', 'charges');
  45. $object = new Localtax($db);
  46. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  47. $hookmanager->initHooks(array('localtaxvatcard', 'globalcard'));
  48. /**
  49. * Actions
  50. */
  51. if ($cancel && !$id) {
  52. header("Location: list.php?localTaxType=".$lttype);
  53. exit;
  54. }
  55. if ($action == 'add' && !$cancel) {
  56. $db->begin();
  57. $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth"), GETPOST("datevday"), GETPOST("datevyear"));
  58. $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth"), GETPOST("datepday"), GETPOST("datepyear"));
  59. $object->accountid = GETPOST("accountid", 'int');
  60. $object->paymenttype = GETPOST("paiementtype");
  61. $object->datev = $datev;
  62. $object->datep = $datep;
  63. $object->amount = price2num(GETPOST("amount"));
  64. $object->label = GETPOST("label");
  65. $object->ltt = $lttype;
  66. $ret = $object->addPayment($user);
  67. if ($ret > 0) {
  68. $db->commit();
  69. header("Location: list.php?localTaxType=".$lttype);
  70. exit;
  71. } else {
  72. $db->rollback();
  73. setEventMessages($object->error, $object->errors, 'errors');
  74. $_GET["action"] = "create";
  75. }
  76. }
  77. //delete payment of localtax
  78. if ($action == 'delete') {
  79. $result = $object->fetch($id);
  80. if ($object->rappro == 0) {
  81. $db->begin();
  82. $ret = $object->delete($user);
  83. if ($ret > 0) {
  84. if ($object->fk_bank) {
  85. $accountline = new AccountLine($db);
  86. $result = $accountline->fetch($object->fk_bank);
  87. if ($result > 0) {
  88. $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
  89. }
  90. }
  91. if ($result >= 0) {
  92. $db->commit();
  93. header("Location: ".DOL_URL_ROOT.'/compta/localtax/list.php?localTaxType='.$object->ltt);
  94. exit;
  95. } else {
  96. $object->error = $accountline->error;
  97. $db->rollback();
  98. setEventMessages($object->error, $object->errors, 'errors');
  99. }
  100. } else {
  101. $db->rollback();
  102. setEventMessages($object->error, $object->errors, 'errors');
  103. }
  104. } else {
  105. $mesg = 'Error try do delete a line linked to a conciliated bank transaction';
  106. setEventMessages($mesg, null, 'errors');
  107. }
  108. }
  109. /*
  110. * View
  111. */
  112. if ($id) {
  113. $result = $object->fetch($id);
  114. if ($result <= 0) {
  115. dol_print_error($db);
  116. exit;
  117. }
  118. }
  119. $form = new Form($db);
  120. $title = $langs->trans("LT".$object->ltt)." - ".$langs->trans("Card");
  121. $help_url = '';
  122. llxHeader('', $title, $helpurl);
  123. if ($action == 'create') {
  124. print load_fiche_titre($langs->transcountry($lttype == 2 ? "newLT2Payment" : "newLT1Payment", $mysoc->country_code));
  125. print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formlocaltax" method="post">'."\n";
  126. print '<input type="hidden" name="token" value="'.newToken().'">';
  127. print '<input type="hidden" name="localTaxType" value="'.$lttype.'">';
  128. print '<input type="hidden" name="action" value="add">';
  129. print dol_get_fiche_head();
  130. print '<table class="border centpercent">';
  131. // Date of payment
  132. print "<tr>";
  133. print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
  134. print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
  135. print '</td></tr>';
  136. // End date of period
  137. print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
  138. print $form->selectDate($datev, "datev", '', '', '', 'add', 1, 1);
  139. print '</td></tr>';
  140. // Label
  141. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input name="label" class="minwidth200" value="'.(GETPOSTISSET("label") ? GETPOST("label", '', 2) : $langs->transcountry(($lttype == 2 ? "LT2Payment" : "LT1Payment"), $mysoc->country_code)).'"></td></tr>';
  142. // Amount
  143. print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount").'"></td></tr>';
  144. if (isModEnabled("banque")) {
  145. // Type payment
  146. print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
  147. print $form->select_types_paiements(GETPOST("paiementtype"), "paiementtype", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx', 1);
  148. print "</td>\n";
  149. print "</tr>";
  150. // Bank account
  151. print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("Account").'</td><td>';
  152. print img_picto('', 'bank_account', 'pictofixedwidth');
  153. $form->select_comptes(GETPOST("accountid", "int"), "accountid", 0, "courant=1", 2, '', 0, 'maxwidth500 widthcentpercentminusx'); // Affiche liste des comptes courant
  154. print '</td></tr>';
  155. // Number
  156. print '<tr><td>'.$langs->trans('Numero');
  157. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  158. print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
  159. }
  160. // Other attributes
  161. $parameters = array();
  162. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  163. print $hookmanager->resPrint;
  164. print '</table>';
  165. print dol_get_fiche_end();
  166. print $form->buttonsSaveCancel();
  167. print '</form>';
  168. }
  169. // View mode
  170. if ($id) {
  171. $h = 0;
  172. $head[$h][0] = DOL_URL_ROOT.'/compta/localtax/card.php?id='.$object->id;
  173. $head[$h][1] = $langs->trans('Card');
  174. $head[$h][2] = 'card';
  175. $h++;
  176. print dol_get_fiche_head($head, 'card', $langs->transcountry("LT".$object->ltt, $mysoc->country_code), -1, 'payment');
  177. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/localtax/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  178. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
  179. print '<div class="fichecenter">';
  180. print '<div class="underbanner clearboth"></div>';
  181. print '<table class="border centpercent">';
  182. print "<tr>";
  183. print '<td class="titlefield">'.$langs->trans("Ref").'</td><td>';
  184. print $object->ref;
  185. print '</td></tr>';
  186. print "<tr>";
  187. print '<td>'.$langs->trans("DatePayment").'</td><td>';
  188. print dol_print_date($object->datep, 'day');
  189. print '</td></tr>';
  190. print '<tr><td>'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
  191. print dol_print_date($object->datev, 'day');
  192. print '</td></tr>';
  193. print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
  194. if (isModEnabled("banque")) {
  195. if ($object->fk_account > 0) {
  196. $bankline = new AccountLine($db);
  197. $bankline->fetch($object->fk_bank);
  198. print '<tr>';
  199. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  200. print '<td>';
  201. print $bankline->getNomUrl(1, 0, 'showall');
  202. print '</td>';
  203. print '</tr>';
  204. }
  205. }
  206. // Other attributes
  207. $parameters = array();
  208. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  209. print $hookmanager->resPrint;
  210. print '</table>';
  211. print '</div>';
  212. print dol_get_fiche_end();
  213. /*
  214. * Action bar
  215. */
  216. print "<div class=\"tabsAction\">\n";
  217. if ($object->rappro == 0) {
  218. print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a>';
  219. } else {
  220. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConcialitedTransaction").'">'.$langs->trans("Delete").'</a>';
  221. }
  222. print "</div>";
  223. }
  224. // End of page
  225. llxFooter();
  226. $db->close();