card.php 31 KB

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