card.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015-2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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 <http://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/tva/card.php
  23. * \ingroup tax
  24. * \brief Page of VAT payments
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array('compta', 'banks', 'bills'));
  32. $id=GETPOST("id",'int');
  33. $action=GETPOST("action","alpha");
  34. $refund=GETPOST("refund","int");
  35. if (empty($refund)) $refund=0;
  36. // Security check
  37. $socid = GETPOST('socid','int');
  38. if ($user->societe_id) $socid=$user->societe_id;
  39. $result = restrictedArea($user, 'tax', '', '', 'charges');
  40. $object = new Tva($db);
  41. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  42. $hookmanager->initHooks(array('taxvatcard','globalcard'));
  43. /**
  44. * Actions
  45. */
  46. if ($_POST["cancel"] == $langs->trans("Cancel") && ! $id)
  47. {
  48. header("Location: list.php");
  49. exit;
  50. }
  51. if ($action == 'setlib' && $user->rights->tax->charges->creer)
  52. {
  53. $object->fetch($id);
  54. $result = $object->setValueFrom('label', GETPOST('lib','alpha'), '', '', 'text', '', $user, 'TAX_MODIFY');
  55. if ($result < 0)
  56. setEventMessages($object->error, $object->errors, 'errors');
  57. }
  58. if ($action == 'setdatev' && $user->rights->tax->charges->creer)
  59. {
  60. $object->fetch($id);
  61. $object->datev=dol_mktime(12,0,0,GETPOST('datevmonth','int'),GETPOST('datevday','int'),GETPOST('datevyear','int'));
  62. $result=$object->update($user);
  63. if ($result < 0) dol_print_error($db,$object->error);
  64. $action='';
  65. }
  66. if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel"))
  67. {
  68. $error=0;
  69. $datev=dol_mktime(12,0,0, $_POST["datevmonth"], $_POST["datevday"], $_POST["datevyear"]);
  70. $datep=dol_mktime(12,0,0, $_POST["datepmonth"], $_POST["datepday"], $_POST["datepyear"]);
  71. $object->accountid=GETPOST("accountid");
  72. $object->type_payment=GETPOST("type_payment");
  73. $object->num_payment=GETPOST("num_payment");
  74. $object->datev=$datev;
  75. $object->datep=$datep;
  76. $amount = price2num(GETPOST("amount",'alpha'));
  77. if ($refund == 1) {
  78. $amount= -$amount;
  79. }
  80. $object->amount= $amount;
  81. $object->label=GETPOST("label",'alpha');
  82. $object->note=GETPOST("note",'none');
  83. if (empty($object->datev))
  84. {
  85. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateValue")), null, 'errors');
  86. $error++;
  87. }
  88. if (empty($object->datep))
  89. {
  90. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
  91. $error++;
  92. }
  93. if (empty($object->type_payment) || $object->type_payment < 0)
  94. {
  95. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
  96. $error++;
  97. }
  98. if (empty($object->amount))
  99. {
  100. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
  101. $error++;
  102. }
  103. if (! $error)
  104. {
  105. $db->begin();
  106. $ret=$object->addPayment($user);
  107. if ($ret > 0)
  108. {
  109. $db->commit();
  110. header("Location: list.php");
  111. exit;
  112. }
  113. else
  114. {
  115. $db->rollback();
  116. setEventMessages($object->error, $object->errors, 'errors');
  117. $action="create";
  118. }
  119. }
  120. $action='create';
  121. }
  122. if ($action == 'delete')
  123. {
  124. $result=$object->fetch($id);
  125. if ($object->rappro == 0)
  126. {
  127. $db->begin();
  128. $ret=$object->delete($user);
  129. if ($ret > 0)
  130. {
  131. if ($object->fk_bank)
  132. {
  133. $accountline=new AccountLine($db);
  134. $result=$accountline->fetch($object->fk_bank);
  135. if ($result > 0) $result=$accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
  136. }
  137. if ($result >= 0)
  138. {
  139. $db->commit();
  140. header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php');
  141. exit;
  142. }
  143. else
  144. {
  145. $object->error=$accountline->error;
  146. $db->rollback();
  147. setEventMessages($object->error, $object->errors, 'errors');
  148. }
  149. }
  150. else
  151. {
  152. $db->rollback();
  153. setEventMessages($object->error, $object->errors, 'errors');
  154. }
  155. }
  156. else
  157. {
  158. $mesg='Error try do delete a line linked to a conciliated bank transaction';
  159. setEventMessages($mesg, null, 'errors');
  160. }
  161. }
  162. /*
  163. * View
  164. */
  165. $form = new Form($db);
  166. $title=$langs->trans("VAT") . " - " . $langs->trans("Card");
  167. $help_url='';
  168. llxHeader("",$title,$helpurl);
  169. if ($id)
  170. {
  171. $result = $object->fetch($id);
  172. if ($result <= 0)
  173. {
  174. dol_print_error($db);
  175. exit;
  176. }
  177. }
  178. // Formulaire saisie tva
  179. if ($action == 'create')
  180. {
  181. print load_fiche_titre($langs->trans("VAT") . ' - ' . $langs->trans("New"));
  182. if (! empty($conf->use_javascript_ajax))
  183. {
  184. print "\n".'<script type="text/javascript" language="javascript">';
  185. print '$(document).ready(function () {
  186. $("#radiopayment").click(function() {
  187. $("#label").val($(this).data("label"));
  188. });
  189. $("#radiorefund").click(function() {
  190. $("#label").val($(this).data("label"));
  191. });
  192. });';
  193. print '</script>'."\n";
  194. }
  195. print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formvat" method="post">';
  196. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  197. print '<input type="hidden" name="action" value="add">';
  198. print '<div id="selectmethod">';
  199. print '<div class="hideonsmartphone float">';
  200. print $langs->trans("Type").':&nbsp;&nbsp;&nbsp;';
  201. print '</div>';
  202. print '<label for="radiopayment">';
  203. print '<input type="radio" id="radiopayment" data-label="'.$langs->trans('VATPayment').'" class="flat" name="refund" value="0"'.($refund?'':' checked="checked"').'>';
  204. print '&nbsp;';
  205. print $langs->trans("Payment");
  206. print '</label>';
  207. print '&nbsp;&nbsp;&nbsp;';
  208. print '<label for="radiorefund">';
  209. print '<input type="radio" id="radiorefund" data-label="'.$langs->trans('VATRefund').'" class="flat" name="refund" value="1"'.($refund?' checked="checked"':'').'>';
  210. print '&nbsp;';
  211. print $langs->trans("Refund");
  212. print '</label>';
  213. print '</div>';
  214. print "<br>\n";
  215. dol_fiche_head();
  216. print '<table class="border" width="100%">';
  217. print "<tr>";
  218. print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
  219. print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
  220. print '</td></tr>';
  221. print '<tr><td class="fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
  222. print $form->selectDate($datev, "datev", '', '', '', 'add', 1, 1);
  223. print '</td></tr>';
  224. // Label
  225. if ($refund == 1) {
  226. $label = $langs->trans("VATRefund");
  227. } else {
  228. $label = $langs->trans("VATPayment");
  229. }
  230. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input class="minwidth300" name="label" id="label" value="'.($_POST["label"]?GETPOST("label",'',2):$label).'"></td></tr>';
  231. // Amount
  232. print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" size="10" value="'.GETPOST("amount","alpha").'"></td></tr>';
  233. if (! empty($conf->banque->enabled))
  234. {
  235. print '<tr><td class="fieldrequired">'.$langs->trans("BankAccount").'</td><td>';
  236. $form->select_comptes($_POST["accountid"],"accountid",0,"courant=1",1); // Affiche liste des comptes courant
  237. print '</td></tr>';
  238. }
  239. // Type payment
  240. print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
  241. $form->select_types_paiements(GETPOST("type_payment"), "type_payment");
  242. print "</td>\n";
  243. print "</tr>";
  244. // Number
  245. print '<tr><td>'.$langs->trans('Numero');
  246. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  247. print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
  248. // Other attributes
  249. $parameters=array();
  250. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  251. print $hookmanager->resPrint;
  252. print '</table>';
  253. dol_fiche_end();
  254. print '<div class="center">';
  255. print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
  256. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  257. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  258. print '</div>';
  259. print '</form>';
  260. }
  261. // View mode
  262. if ($id)
  263. {
  264. $head=vat_prepare_head($object);
  265. dol_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment');
  266. $morehtmlref='<div class="refidno">';
  267. // Label of social contribution
  268. $morehtmlref.=$form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
  269. $morehtmlref.=$form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
  270. // Project
  271. $morehtmlref.='</div>';
  272. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  273. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
  274. print '<div class="fichecenter">';
  275. print '<div class="underbanner clearboth"></div>';
  276. print '<table class="border" width="100%">';
  277. // Label
  278. //print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
  279. print "<tr>";
  280. print '<td class="titlefield">'.$langs->trans("DatePayment").'</td><td>';
  281. print dol_print_date($object->datep,'day');
  282. print '</td></tr>';
  283. print '<tr><td>';
  284. print $form->editfieldkey($form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")), 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
  285. print '</td><td>';
  286. print $form->editfieldval("PeriodEndDate", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
  287. //print dol_print_date($object->datev,'day');
  288. print '</td></tr>';
  289. print '<tr><td>'.$langs->trans("Amount").'</td><td>'.price($object->amount).'</td></tr>';
  290. if (! empty($conf->banque->enabled))
  291. {
  292. if ($object->fk_account > 0)
  293. {
  294. $bankline=new AccountLine($db);
  295. $bankline->fetch($object->fk_bank);
  296. print '<tr>';
  297. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  298. print '<td>';
  299. print $bankline->getNomUrl(1,0,'showall');
  300. print '</td>';
  301. print '</tr>';
  302. }
  303. }
  304. // Other attributes
  305. $parameters=array();
  306. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  307. print $hookmanager->resPrint;
  308. print '</table>';
  309. print '</div>';
  310. dol_fiche_end();
  311. /*
  312. * Action buttons
  313. */
  314. print "<div class=\"tabsAction\">\n";
  315. if ($object->rappro == 0)
  316. {
  317. if (! empty($user->rights->tax->charges->supprimer))
  318. {
  319. print '<a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete">'.$langs->trans("Delete").'</a>';
  320. }
  321. else
  322. {
  323. print '<a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a>';
  324. }
  325. }
  326. else
  327. {
  328. print '<a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a>';
  329. }
  330. print "</div>";
  331. }
  332. llxFooter();
  333. $db->close();