card.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/compta/tva/card.php
  24. * \ingroup tax
  25. * \brief Page of VAT payments
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/paymentvat.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/vat.lib.php';
  35. if (!empty($conf->accounting->enabled)) {
  36. include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  37. }
  38. // Load translation files required by the page
  39. $langs->loadLangs(array('compta', 'banks', 'bills'));
  40. $id = GETPOST("id", 'int');
  41. $ref = GETPOST('ref', 'alpha');
  42. $action = GETPOST("action", "aZ09");
  43. $confirm = GETPOST('confirm', 'alpha');
  44. $cancel = GETPOST('cancel', 'aZ09');
  45. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search
  46. $backtopage = GETPOST('backtopage', 'alpha');
  47. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  48. $refund = GETPOST("refund", "int");
  49. if (GETPOSTISSET('auto_create_paiement') || $action === 'add') {
  50. $auto_create_payment = GETPOST("auto_create_paiement", "int");
  51. } else {
  52. $auto_create_payment = empty($conf->global->CREATE_NEW_VAT_WITHOUT_AUTO_PAYMENT);
  53. }
  54. if (empty($refund)) {
  55. $refund = 0;
  56. }
  57. $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int'));
  58. $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int'));
  59. // Initialize technical objects
  60. $object = new Tva($db);
  61. $extrafields = new ExtraFields($db);
  62. $diroutputmassaction = $conf->tax->dir_output.'/temp/massgeneration/'.$user->id;
  63. $hookmanager->initHooks(array('taxvatcard', 'globalcard'));
  64. // Fetch optionals attributes and labels
  65. $extrafields->fetch_name_optionals_label($object->table_element);
  66. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  67. // Initialize array of search criterias
  68. $search_all = GETPOST("search_all", 'alpha');
  69. $search = array();
  70. foreach ($object->fields as $key => $val) {
  71. if (GETPOST('search_'.$key, 'alpha')) {
  72. $search[$key] = GETPOST('search_'.$key, 'alpha');
  73. }
  74. }
  75. if (empty($action) && empty($id) && empty($ref)) {
  76. $action = 'view';
  77. }
  78. // Load object
  79. if ($id > 0) {
  80. $object->fetch($id);
  81. }
  82. $permissiontoread = $user->rights->tax->charges->lire;
  83. $permissiontoadd = $user->rights->tax->charges->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
  84. $permissiontodelete = $user->rights->tax->charges->supprimer || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_DRAFT);
  85. $permissionnote = $user->rights->tax->charges->creer; // Used by the include of actions_setnotes.inc.php
  86. $permissiondellink = $user->rights->tax->charges->creer; // Used by the include of actions_dellink.inc.php
  87. $upload_dir = $conf->tax->multidir_output[isset($object->entity) ? $object->entity : 1].'/vat';
  88. // Security check
  89. $socid = GETPOST('socid', 'int');
  90. if ($user->socid) {
  91. $socid = $user->socid;
  92. }
  93. $result = restrictedArea($user, 'tax', '', 'tva', 'charges');
  94. /*
  95. * Actions
  96. */
  97. $parameters = array();
  98. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  99. if ($reshook < 0) {
  100. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  101. }
  102. if ($cancel && !$id) {
  103. header("Location: list.php");
  104. exit;
  105. }
  106. if ($action == 'setlib' && $user->rights->tax->charges->creer) {
  107. $object->fetch($id);
  108. $result = $object->setValueFrom('label', GETPOST('lib', 'alpha'), '', '', 'text', '', $user, 'TAX_MODIFY');
  109. if ($result < 0) {
  110. setEventMessages($object->error, $object->errors, 'errors');
  111. }
  112. }
  113. if ($action == 'setdatev' && $user->rights->tax->charges->creer) {
  114. $object->fetch($id);
  115. $object->datev = $datev;
  116. $result = $object->update($user);
  117. if ($result < 0) {
  118. dol_print_error($db, $object->error);
  119. }
  120. $action = '';
  121. }
  122. // payment mode
  123. if ($action == 'setmode' && $user->rights->tax->charges->creer) {
  124. $object->fetch($id);
  125. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
  126. if ($result < 0) {
  127. setEventMessages($object->error, $object->errors, 'errors');
  128. }
  129. }
  130. // Bank account
  131. if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) {
  132. $object->fetch($id);
  133. $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
  134. if ($result < 0) {
  135. setEventMessages($object->error, $object->errors, 'errors');
  136. }
  137. }
  138. // Classify paid
  139. if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') {
  140. $object->fetch($id);
  141. $result = $object->setPaid($user);
  142. }
  143. if ($action == 'reopen' && $user->rights->tax->charges->creer) {
  144. $result = $object->fetch($id);
  145. if ($object->paye) {
  146. $result = $object->setUnpaid($user);
  147. if ($result > 0) {
  148. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  149. exit();
  150. } else {
  151. setEventMessages($object->error, $object->errors, 'errors');
  152. }
  153. }
  154. }
  155. if ($action == 'add' && !$cancel) {
  156. $error = 0;
  157. $object->fk_account = GETPOST("accountid", 'int');
  158. $object->type_payment = GETPOST("type_payment", 'alphanohtml');
  159. $object->num_payment = GETPOST("num_payment", 'alphanohtml');
  160. $object->datev = $datev;
  161. $object->datep = $datep;
  162. $amount = price2num(GETPOST("amount", 'alpha'));
  163. if ($refund == 1) {
  164. $amount = -$amount;
  165. }
  166. $object->amount = $amount;
  167. $object->label = GETPOST("label", 'alpha');
  168. $object->note = GETPOST("note", 'restricthtml');
  169. $object->note_private = GETPOST("note", 'restricthtml');
  170. if (empty($object->datep)) {
  171. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors');
  172. $error++;
  173. }
  174. if (empty($object->datev)) {
  175. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PeriodEndDate")), null, 'errors');
  176. $error++;
  177. }
  178. if (!empty($auto_create_payment) && (empty($object->type_payment) || $object->type_payment < 0)) {
  179. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
  180. $error++;
  181. }
  182. if (empty($object->amount)) {
  183. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
  184. $error++;
  185. }
  186. if (!empty($auto_create_payment) && ($object->fk_account <= 0)) {
  187. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountToCredit")), null, 'errors');
  188. $error++;
  189. }
  190. if (!$error) {
  191. $ret = $object->create($user);
  192. if ($ret < 0) {
  193. $error++;
  194. }
  195. // Auto create payment
  196. if (!empty($auto_create_payment) && !$error) {
  197. $db->begin();
  198. // Create a line of payments
  199. $paiement = new PaymentVAT($db);
  200. $paiement->chid = $object->id;
  201. $paiement->datepaye = $datep;
  202. $paiement->amounts = array($object->id=>$amount); // Tableau de montant
  203. $paiement->paiementtype = GETPOST("type_payment", 'alphanohtml');
  204. $paiement->num_payment = GETPOST("num_payment", 'alphanohtml');
  205. $paiement->note = GETPOST("note", 'restricthtml');
  206. if (!$error) {
  207. $paymentid = $paiement->create($user, (int) GETPOST('closepaidtva'));
  208. if ($paymentid < 0) {
  209. $error++;
  210. setEventMessages($paiement->error, null, 'errors');
  211. $action = 'create';
  212. }
  213. }
  214. if (!$error) {
  215. $result = $paiement->addPaymentToBank($user, 'payment_vat', '(VATPayment)', GETPOST('accountid', 'int'), '', '');
  216. if (!($result > 0)) {
  217. $error++;
  218. setEventMessages($paiement->error, null, 'errors');
  219. }
  220. }
  221. if (!$error) {
  222. $db->commit();
  223. } else {
  224. $db->rollback();
  225. }
  226. }
  227. if (empty($error)) {
  228. header("Location: card.php?id=" . $object->id);
  229. exit;
  230. }
  231. }
  232. $action = 'create';
  233. }
  234. if ($action == 'confirm_delete' && $confirm == 'yes') {
  235. $result = $object->fetch($id);
  236. $totalpaid = $object->getSommePaiement();
  237. if (empty($totalpaid)) {
  238. $db->begin();
  239. $ret = $object->delete($user);
  240. if ($ret > 0) {
  241. if ($object->fk_bank) {
  242. $accountline = new AccountLine($db);
  243. $result = $accountline->fetch($object->fk_bank);
  244. if ($result > 0) {
  245. $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
  246. }
  247. }
  248. if ($result >= 0) {
  249. $db->commit();
  250. header("Location: ".DOL_URL_ROOT.'/compta/tva/list.php');
  251. exit;
  252. } else {
  253. $object->error = $accountline->error;
  254. $db->rollback();
  255. setEventMessages($object->error, $object->errors, 'errors');
  256. }
  257. } else {
  258. $db->rollback();
  259. setEventMessages($object->error, $object->errors, 'errors');
  260. }
  261. } else {
  262. setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
  263. }
  264. }
  265. if ($action == 'update' && !GETPOST("cancel") && $user->rights->tax->charges->creer) {
  266. $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
  267. if (empty($amount)) {
  268. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
  269. $action = 'edit';
  270. } elseif (!is_numeric($amount)) {
  271. setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
  272. $action = 'create';
  273. } else {
  274. $result = $object->fetch($id);
  275. $object->amount = $amount;
  276. $result = $object->update($user);
  277. if ($result <= 0) {
  278. setEventMessages($object->error, $object->errors, 'errors');
  279. }
  280. }
  281. }
  282. // Action clone object
  283. if ($action == 'confirm_clone' && $confirm != 'yes') {
  284. $action = '';
  285. }
  286. if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) {
  287. $db->begin();
  288. $originalId = $id;
  289. $object->fetch($id);
  290. if ($object->id > 0) {
  291. $object->id = $object->ref = null;
  292. $object->paye = 0;
  293. if (GETPOST('clone_label', 'alphanohtml')) {
  294. $object->label = GETPOST('clone_label', 'alphanohtml');
  295. } else {
  296. $object->label = $langs->trans("CopyOf").' '.$object->label;
  297. }
  298. $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int'));
  299. if ($newdateperiod) {
  300. $object->datev = $newdateperiod;
  301. }
  302. //if ($object->check()) {
  303. $id = $object->create($user);
  304. if ($id > 0) {
  305. $db->commit();
  306. $db->close();
  307. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  308. exit;
  309. } else {
  310. $id = $originalId;
  311. $db->rollback();
  312. setEventMessages($object->error, $object->errors, 'errors');
  313. }
  314. //}
  315. } else {
  316. $db->rollback();
  317. dol_print_error($db, $object->error);
  318. }
  319. }
  320. /*
  321. * View
  322. */
  323. $form = new Form($db);
  324. $formfile = new FormFile($db);
  325. $formproject = new FormProjets($db);
  326. $title = $langs->trans("VAT")." - ".$langs->trans("Card");
  327. $help_url = '';
  328. llxHeader('', $title, $help_url);
  329. if ($id) {
  330. $result = $object->fetch($id);
  331. if ($result <= 0) {
  332. dol_print_error($db);
  333. exit;
  334. }
  335. }
  336. // Form to enter VAT
  337. if ($action == 'create') {
  338. print load_fiche_titre($langs->trans("VAT").' - '.$langs->trans("New"));
  339. if (!empty($conf->use_javascript_ajax)) {
  340. print "\n".'<script type="text/javascript">';
  341. print /** @lang JavaScript */'
  342. $(document).ready(function () {
  343. let onAutoCreatePaiementChange = function () {
  344. if($("#auto_create_paiement").is(":checked")) {
  345. $("#label_fk_account").addClass("fieldrequired");
  346. $("#label_type_payment").addClass("fieldrequired");
  347. $(".hide_if_no_auto_create_payment").show();
  348. } else {
  349. $("#label_fk_account").removeClass("fieldrequired");
  350. $("#label_type_payment").removeClass("fieldrequired");
  351. $(".hide_if_no_auto_create_payment").hide();
  352. }
  353. };
  354. $("#radiopayment").click(function() {
  355. $("#label").val($(this).data("label"));
  356. });
  357. $("#radiorefund").click(function() {
  358. $("#label").val($(this).data("label"));
  359. });
  360. $("#auto_create_paiement").click(function () {
  361. onAutoCreatePaiementChange();
  362. });
  363. onAutoCreatePaiementChange();
  364. });
  365. ';
  366. print '</script>'."\n";
  367. }
  368. print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" name="formvat" method="post">';
  369. print '<input type="hidden" name="token" value="'.newToken().'">';
  370. print '<input type="hidden" name="action" value="add">';
  371. print dol_get_fiche_head();
  372. print '<table class="border centpercent">';
  373. print '<tr><td class="titlefieldcreate fieldrequired">';
  374. //print $langs->trans("Type");
  375. print '</td><td>';
  376. print '<div id="selectmethod">';
  377. print '<label for="radiopayment">';
  378. print '<input type="radio" id="radiopayment" data-label="'.$langs->trans('VATPayment').'" class="flat" name="refund" value="0"'.($refund ? '' : ' checked="checked"').'>';
  379. print '&nbsp;';
  380. print $langs->trans("Payment");
  381. print '</label>';
  382. print '&nbsp;&nbsp;&nbsp;';
  383. print '<label for="radiorefund">';
  384. print '<input type="radio" id="radiorefund" data-label="'.$langs->trans('VATRefund').'" class="flat" name="refund" value="1"'.($refund ? ' checked="checked"' : '').'>';
  385. print '&nbsp;';
  386. print $langs->trans("Refund");
  387. print '</label>';
  388. print '</div>';
  389. print '</td>';
  390. print "</tr>\n";
  391. // Label
  392. if ($refund == 1) {
  393. $label = $langs->trans("VATRefund");
  394. } else {
  395. $label = $langs->trans("VATPayment");
  396. }
  397. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input class="minwidth300" name="label" id="label" value="'.(GETPOSTISSET("label") ? GETPOST("label", '', 2) : $label).'" autofocus></td></tr>';
  398. print '<tr><td class="titlefieldcreate fieldrequired">'.$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")).'</td><td>';
  399. print $form->selectDate((GETPOST("datevmonth", 'int') ? $datev : -1), "datev", '', '', '', 'add', 1, 1);
  400. print '</td></tr>';
  401. // Amount
  402. print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input name="amount" class="right width75" value="'.GETPOST("amount", "alpha").'"></td></tr>';
  403. print '<tr><td colspan="2"><hr></td></tr>';
  404. // Auto create payment
  405. print '<tr><td><label for="auto_create_paiement">'.$langs->trans('AutomaticCreationPayment').'</label></td>';
  406. print '<td><input id="auto_create_paiement" name="auto_create_paiement" type="checkbox" ' . (empty($auto_create_payment) ? '' : 'checked="checked"') . ' value="1"></td></tr>'."\n";
  407. print '<tr class="hide_if_no_auto_create_payment">';
  408. print '<td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
  409. print $form->selectDate($datep, "datep", '', '', '', 'add', 1, 1);
  410. print '</td></tr>';
  411. // Type payment
  412. print '<tr><td class="fieldrequired" id="label_type_payment">'.$langs->trans("PaymentMode").'</td><td>';
  413. $form->select_types_paiements(GETPOST("type_payment", 'int'), "type_payment", '', 0, 1, 0, 0, 1, 'maxwidth500 widthcentpercentminusx');
  414. print "</td>\n";
  415. print "</tr>";
  416. if (!empty($conf->banque->enabled)) {
  417. // Bank account
  418. print '<tr><td class="fieldrequired" id="label_fk_account">'.$langs->trans("BankAccount").'</td><td>';
  419. print img_picto('', 'bank_account', 'pictofixedwidth');
  420. $form->select_comptes(GETPOST("accountid", 'int'), "accountid", 0, "courant=1", 1, '', 0, 'maxwidth500 widthcentpercentminusx'); // List of bank account available
  421. print '</td></tr>';
  422. }
  423. // Number
  424. print '<tr class="hide_if_no_auto_create_payment"><td>'.$langs->trans('Numero');
  425. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  426. print '<td><input name="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
  427. // Comments
  428. print '<tr class="hide_if_no_auto_create_payment">';
  429. print '<td class="tdtop">'.$langs->trans("Comments").'</td>';
  430. print '<td class="tdtop"><textarea name="note" wrap="soft" rows="'.ROWS_3.'" class="quatrevingtpercent">'.GETPOST('note', 'restricthtml').'</textarea></td>';
  431. print '</tr>';
  432. // Other attributes
  433. $parameters = array();
  434. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  435. print $hookmanager->resPrint;
  436. print '</table>';
  437. print dol_get_fiche_end();
  438. print '<div class="center">';
  439. print '<div class="hide_if_no_auto_create_payment paddingbottom">';
  440. print '<input type="checkbox" checked value="1" name="closepaidtva"> <span class="">'.$langs->trans("ClosePaidVATAutomatically").'</span>';
  441. print '<br>';
  442. print '</div>';
  443. print '<input type="submit" class="button button-save" value="'.$langs->trans("Save").'">';
  444. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  445. print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  446. print '</div>';
  447. print '</form>';
  448. }
  449. // View mode
  450. if ($id > 0) {
  451. $head = vat_prepare_head($object);
  452. $totalpaid = $object->getSommePaiement();
  453. // Clone confirmation
  454. if ($action === 'clone') {
  455. $formquestion = array(
  456. array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
  457. );
  458. //$formquestion[] = array('type' => 'date', 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
  459. $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
  460. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVAT', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 240);
  461. }
  462. if ($action == 'paid') {
  463. $text = $langs->trans('ConfirmPayVAT');
  464. print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PayVAT'), $text, "confirm_paid", '', '', 2);
  465. }
  466. if ($action == 'delete') {
  467. $text = $langs->trans('ConfirmDeleteVAT');
  468. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVAT'), $text, 'confirm_delete', '', '', 2);
  469. }
  470. if ($action == 'edit') {
  471. print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
  472. print '<input type="hidden" name="token" value="'.newToken().'">';
  473. }
  474. print dol_get_fiche_head($head, 'card', $langs->trans("VATPayment"), -1, 'payment');
  475. $morehtmlref = '<div class="refidno">';
  476. // Label of social contribution
  477. $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
  478. $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
  479. // Project
  480. $morehtmlref .= '</div>';
  481. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/tva/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  482. $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  483. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '');
  484. print '<div class="fichecenter">';
  485. print '<div class="fichehalfleft">';
  486. print '<div class="underbanner clearboth"></div>';
  487. print '<table class="border centpercent">';
  488. // Label
  489. //print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
  490. /*print "<tr>";
  491. print '<td class="titlefield">'.$langs->trans("DatePayment").'</td><td>';
  492. print dol_print_date($object->datep, 'day');
  493. print '</td></tr>';*/
  494. print '<tr><td>';
  495. print $form->editfieldkey($form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo")), 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
  496. print '</td><td>';
  497. print $form->editfieldval("PeriodEndDate", 'datev', $object->datev, $object, $user->rights->tax->charges->creer, 'day');
  498. //print dol_print_date($object->datev,'day');
  499. print '</td></tr>';
  500. if ($action == 'edit') {
  501. print '<tr><td class="fieldrequired">' . $langs->trans("Amount") . '</td><td><input name="amount" size="10" value="' . price($object->amount) . '"></td></tr>';
  502. } else {
  503. print '<tr><td>' . $langs->trans("Amount") . '</td><td>' . price($object->amount) . '</td></tr>';
  504. }
  505. // Mode of payment
  506. print '<tr><td>';
  507. print '<table class="nobordernopadding" width="100%"><tr><td>';
  508. print $langs->trans('PaymentMode');
  509. print '</td>';
  510. if ($action != 'editmode') {
  511. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
  512. }
  513. print '</tr></table>';
  514. print '</td><td>';
  515. if ($action == 'editmode') {
  516. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'mode_reglement_id');
  517. } else {
  518. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->type_payment, 'none');
  519. }
  520. print '</td></tr>';
  521. // Bank account
  522. if (!empty($conf->banque->enabled)) {
  523. print '<tr><td class="nowrap">';
  524. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  525. print $langs->trans('BankAccount');
  526. print '<td>';
  527. if ($action != 'editbankaccount' && $user->rights->tax->charges->creer) {
  528. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
  529. }
  530. print '</tr></table>';
  531. print '</td><td>';
  532. if ($action == 'editbankaccount') {
  533. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
  534. } else {
  535. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
  536. }
  537. print '</td>';
  538. print '</tr>';
  539. }
  540. // Other attributes
  541. $parameters = array();
  542. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  543. print $hookmanager->resPrint;
  544. print '</table>';
  545. print '</div>';
  546. print '<div class="fichehalfright">';
  547. $nbcols = 3;
  548. if (!empty($conf->banque->enabled)) {
  549. $nbcols++;
  550. }
  551. /*
  552. * Payments
  553. */
  554. $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,";
  555. $sql .= " c.code as type_code,c.libelle as paiement_type,";
  556. $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.currency_code as bacurrency_code, ba.fk_accountancy_journal';
  557. $sql .= " FROM ".MAIN_DB_PREFIX."payment_vat as p";
  558. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
  559. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
  560. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
  561. $sql .= ", ".MAIN_DB_PREFIX."tva as tva";
  562. $sql .= " WHERE p.fk_tva = ".((int) $id);
  563. $sql .= " AND p.fk_tva = tva.rowid";
  564. $sql .= " AND tva.entity IN (".getEntity('tax').")";
  565. $sql .= " ORDER BY dp DESC";
  566. //print $sql;
  567. $resql = $db->query($sql);
  568. if ($resql) {
  569. $totalpaid = 0;
  570. $num = $db->num_rows($resql);
  571. $i = 0;
  572. $total = 0;
  573. 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
  574. print '<table class="noborder paymenttable">';
  575. print '<tr class="liste_titre">';
  576. print '<td>'.$langs->trans("RefPayment").'</td>';
  577. print '<td>'.$langs->trans("Date").'</td>';
  578. print '<td>'.$langs->trans("Type").'</td>';
  579. if (!empty($conf->banque->enabled)) {
  580. print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
  581. }
  582. print '<td class="right">'.$langs->trans("Amount").'</td>';
  583. print '</tr>';
  584. if ($num > 0) {
  585. $bankaccountstatic = new Account($db);
  586. while ($i < $num) {
  587. $objp = $db->fetch_object($resql);
  588. print '<tr class="oddeven"><td>';
  589. print '<a href="'.DOL_URL_ROOT.'/compta/payment_vat/card.php?id='.$objp->rowid.'">'.img_object($langs->trans("Payment"), "payment").' '.$objp->rowid.'</a>';
  590. print '</td>';
  591. print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
  592. $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
  593. print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
  594. if (!empty($conf->banque->enabled)) {
  595. $bankaccountstatic->id = $objp->baid;
  596. $bankaccountstatic->ref = $objp->baref;
  597. $bankaccountstatic->label = $objp->baref;
  598. $bankaccountstatic->number = $objp->banumber;
  599. $bankaccountstatic->currency_code = $objp->bacurrency_code;
  600. if (!empty($conf->accounting->enabled)) {
  601. $bankaccountstatic->account_number = $objp->account_number;
  602. $accountingjournal = new AccountingJournal($db);
  603. $accountingjournal->fetch($objp->fk_accountancy_journal);
  604. $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  605. }
  606. print '<td class="right">';
  607. if ($bankaccountstatic->id) {
  608. print $bankaccountstatic->getNomUrl(1, 'transactions');
  609. }
  610. print '</td>';
  611. }
  612. print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
  613. print "</tr>";
  614. $totalpaid += $objp->amount;
  615. $i++;
  616. }
  617. } else {
  618. print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
  619. print '<td></td><td></td><td></td><td></td>';
  620. print '</tr>';
  621. }
  622. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid")." :</td><td class=\"right\">".price($totalpaid)."</td></tr>\n";
  623. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected")." :</td><td class=\"right\">".price($object->amount)."</td></tr>\n";
  624. $resteapayer = $object->amount - $totalpaid;
  625. $cssforamountpaymentcomplete = 'amountpaymentcomplete';
  626. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
  627. print '<td class="right'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
  628. print "</table>";
  629. print '</div>';
  630. $db->free($resql);
  631. } else {
  632. dol_print_error($db);
  633. }
  634. print '</div>';
  635. print '</div>';
  636. print '<div class="clearboth"></div>';
  637. print dol_get_fiche_end();
  638. if ($action == 'edit') {
  639. print $form->buttonsSaveCancel();
  640. print "</form>\n";
  641. }
  642. // Buttons for actions
  643. print '<div class="tabsAction">'."\n";
  644. if ($action != 'edit') {
  645. // Reopen
  646. if ($object->paye && $user->rights->tax->charges->creer) {
  647. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen")."</a></div>";
  648. }
  649. // Edit
  650. if ($object->paye == 0 && $user->rights->tax->charges->creer) {
  651. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify")."</a></div>";
  652. }
  653. // Emit payment
  654. if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->rights->tax->charges->creer) {
  655. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/paiement_vat.php?id='.$object->id.'&action=create&token='.newToken().'">'.$langs->trans("DoPayment").'</a></div>';
  656. }
  657. // Classify 'paid'
  658. if ($object->paye == 0
  659. && (
  660. (round($resteapayer) <= 0 && $object->amount > 0)
  661. || (round($resteapayer) >= 0 && $object->amount < 0)
  662. )
  663. && $user->rights->tax->charges->creer) {
  664. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&token='.newToken().'&action=paid">'.$langs->trans("ClassifyPaid")."</a></div>";
  665. }
  666. // Clone
  667. if ($user->rights->tax->charges->creer) {
  668. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/tva/card.php?id='.$object->id.'&token='.newToken().'&action=clone">'.$langs->trans("ToClone")."</a></div>";
  669. }
  670. if (!empty($user->rights->tax->charges->supprimer) && empty($totalpaid)) {
  671. print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
  672. } else {
  673. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("DisabledBecausePayments"))).'">'.$langs->trans("Delete").'</a></div>';
  674. }
  675. }
  676. print '</div>'."\n";
  677. // Select mail models is same action as presend
  678. if (GETPOST('modelselected')) {
  679. $action = 'presend';
  680. }
  681. if ($action != 'presend') {
  682. print '<div class="fichecenter"><div class="fichehalfleft">';
  683. print '<a name="builddoc"></a>'; // ancre
  684. $includedocgeneration = 1;
  685. // Documents
  686. if ($includedocgeneration) {
  687. $objref = dol_sanitizeFileName($object->ref);
  688. $relativepath = $objref.'/'.$objref.'.pdf';
  689. $filedir = $conf->tax->dir_output.'/vat/'.$objref;
  690. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  691. //$genallowed = $user->rights->tax->charges->lire; // If you can read, you can build the PDF to read content
  692. $genallowed = 0;
  693. $delallowed = $user->rights->tax->charges->creer; // If you can create/edit, you can remove a file on card
  694. print $formfile->showdocuments('tax-vat', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  695. }
  696. // Show links to link elements
  697. //$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
  698. //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  699. print '</div><div class="fichehalfright">';
  700. /*
  701. $MAXEVENT = 10;
  702. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
  703. // List of actions on element
  704. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  705. $formactions = new FormActions($db);
  706. $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  707. */
  708. print '</div></div>';
  709. }
  710. //Select mail models is same action as presend
  711. if (GETPOST('modelselected')) {
  712. $action = 'presend';
  713. }
  714. // Presend form
  715. $modelmail = 'vat';
  716. $defaulttopic = 'InformationMessage';
  717. $diroutput = $conf->tax->dir_output;
  718. $trackid = 'vat'.$object->id;
  719. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  720. }
  721. llxFooter();
  722. $db->close();