card.php 11 KB

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