card.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. <?php
  2. /* Copyright (C) 2017-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/compta/bank/various_payment/card.php
  20. * \ingroup bank
  21. * \brief Page of various expenses
  22. */
  23. // Load Dolibarr environment
  24. require '../../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  32. if (isModEnabled('project')) {
  33. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  35. }
  36. // Load translation files required by the page
  37. $langs->loadLangs(array("compta", "banks", "bills", "users", "accountancy", "categories"));
  38. // Get parameters
  39. $id = GETPOST('id', 'int');
  40. $action = GETPOST('action', 'alpha');
  41. $confirm = GETPOST('confirm');
  42. $cancel = GETPOST('cancel', 'aZ09');
  43. $backtopage = GETPOST('backtopage', 'alpha');
  44. $accountid = GETPOST("accountid") > 0 ? GETPOST("accountid", "int") : 0;
  45. $label = GETPOST("label", "alpha");
  46. $sens = GETPOST("sens", "int");
  47. $amount = price2num(GETPOST("amount", "alpha"));
  48. $paymenttype = GETPOST("paymenttype", "aZ09");
  49. $accountancy_code = GETPOST("accountancy_code", "alpha");
  50. $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int'));
  51. if (isModEnabled('accounting') && !empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
  52. $subledger_account = GETPOST("subledger_account", "alpha") > 0 ? GETPOST("subledger_account", "alpha") : '';
  53. } else {
  54. $subledger_account = GETPOST("subledger_account", "alpha");
  55. }
  56. // Security check
  57. $socid = GETPOST("socid", "int");
  58. if ($user->socid) {
  59. $socid = $user->socid;
  60. }
  61. $result = restrictedArea($user, 'banque', '', '', '');
  62. $object = new PaymentVarious($db);
  63. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  64. $hookmanager->initHooks(array('variouscard', 'globalcard'));
  65. /**
  66. * Actions
  67. */
  68. $parameters = array();
  69. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  70. if ($reshook < 0) {
  71. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  72. }
  73. if (empty($reshook)) {
  74. // Link to a project
  75. if ($action == 'classin' && $user->rights->banque->modifier) {
  76. $object->fetch($id);
  77. $object->setProject(GETPOST('projectid'));
  78. }
  79. if ($cancel) {
  80. if ($action != 'addlink') {
  81. $urltogo = $backtopage ? $backtopage : dol_buildpath('/compta/bank/various_payment/list.php', 1);
  82. header("Location: ".$urltogo);
  83. exit;
  84. }
  85. if ($id > 0 || !empty($ref)) {
  86. $ret = $object->fetch($id, $ref);
  87. }
  88. $action = '';
  89. }
  90. if ($action == 'add') {
  91. $error = 0;
  92. $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int'));
  93. $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int'));
  94. if (empty($datev)) {
  95. $datev = $datep;
  96. }
  97. $object->ref = ''; // TODO
  98. $object->accountid = GETPOST("accountid", 'int') > 0 ? GETPOST("accountid", "int") : 0;
  99. $object->datev = $datev;
  100. $object->datep = $datep;
  101. $object->amount = price2num(GETPOST("amount", 'alpha'));
  102. $object->label = GETPOST("label", 'restricthtml');
  103. $object->note = GETPOST("note", 'restricthtml');
  104. $object->type_payment = dol_getIdFromCode($db, GETPOST('paymenttype'), 'c_paiement', 'code', 'id', 1);
  105. $object->num_payment = GETPOST("num_payment", 'alpha');
  106. $object->chqemetteur = GETPOST("chqemetteur", 'alpha');
  107. $object->chqbank = GETPOST("chqbank", 'alpha');
  108. $object->fk_user_author = $user->id;
  109. $object->category_transaction = GETPOST("category_transaction", 'alpha');
  110. $object->accountancy_code = GETPOST("accountancy_code") > 0 ? GETPOST("accountancy_code", "alpha") : "";
  111. $object->subledger_account = $subledger_account;
  112. $object->sens = GETPOSTINT('sens');
  113. $object->fk_project = GETPOSTINT('fk_project');
  114. if (empty($datep) || empty($datev)) {
  115. $langs->load('errors');
  116. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  117. $error++;
  118. }
  119. if (empty($object->amount)) {
  120. $langs->load('errors');
  121. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Amount")), null, 'errors');
  122. $error++;
  123. }
  124. if (isModEnabled("banque") && !$object->accountid > 0) {
  125. $langs->load('errors');
  126. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors');
  127. $error++;
  128. }
  129. if (empty($object->type_payment) || $object->type_payment < 0) {
  130. $langs->load('errors');
  131. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PaymentMode")), null, 'errors');
  132. $error++;
  133. }
  134. if (isModEnabled('accounting') && !$object->accountancy_code) {
  135. $langs->load('errors');
  136. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("AccountAccounting")), null, 'errors');
  137. $error++;
  138. }
  139. if ($object->sens < 0) {
  140. $langs->load('errors');
  141. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Sens")), null, 'errors');
  142. $error++;
  143. }
  144. if (!$error) {
  145. $db->begin();
  146. $ret = $object->create($user);
  147. if ($ret > 0) {
  148. $db->commit();
  149. $urltogo = ($backtopage ? $backtopage : DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
  150. header("Location: ".$urltogo);
  151. exit;
  152. } else {
  153. $db->rollback();
  154. setEventMessages($object->error, $object->errors, 'errors');
  155. $action = "create";
  156. }
  157. }
  158. $action = 'create';
  159. }
  160. if ($action == 'confirm_delete' && $confirm == 'yes') {
  161. $result = $object->fetch($id);
  162. if ($object->rappro == 0) {
  163. $db->begin();
  164. $ret = $object->delete($user);
  165. if ($ret > 0) {
  166. if ($object->fk_bank) {
  167. $accountline = new AccountLine($db);
  168. $result = $accountline->fetch($object->fk_bank);
  169. if ($result > 0) {
  170. $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing)
  171. }
  172. }
  173. if ($result >= 0) {
  174. $db->commit();
  175. header("Location: ".DOL_URL_ROOT.'/compta/bank/various_payment/list.php');
  176. exit;
  177. } else {
  178. $object->error = $accountline->error;
  179. $db->rollback();
  180. setEventMessages($object->error, $object->errors, 'errors');
  181. }
  182. } else {
  183. $db->rollback();
  184. setEventMessages($object->error, $object->errors, 'errors');
  185. }
  186. } else {
  187. setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors');
  188. }
  189. }
  190. if ($action == 'setsubledger_account') {
  191. $db->begin();
  192. $result = $object->fetch($id);
  193. $object->subledger_account = $subledger_account;
  194. $res = $object->update($user);
  195. if ($res > 0) {
  196. $db->commit();
  197. } else {
  198. $db->rollback();
  199. setEventMessages($object->error, $object->errors, 'errors');
  200. }
  201. }
  202. }
  203. // Action clone object
  204. if ($action == 'confirm_clone' && $confirm != 'yes') {
  205. $action = '';
  206. }
  207. if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->banque->modifier)) {
  208. $db->begin();
  209. $originalId = $id;
  210. $object->fetch($id);
  211. if ($object->id > 0) {
  212. $object->id = $object->ref = null;
  213. if (GETPOST('clone_label', 'alphanohtml')) {
  214. $object->label = GETPOST('clone_label', 'alphanohtml');
  215. } else {
  216. $object->label = $langs->trans("CopyOf").' '.$object->label;
  217. }
  218. $newdatepayment = dol_mktime(0, 0, 0, GETPOST('clone_date_paymentmonth', 'int'), GETPOST('clone_date_paymentday', 'int'), GETPOST('clone_date_paymentyear', 'int'));
  219. $newdatevalue = dol_mktime(0, 0, 0, GETPOST('clone_date_valuemonth', 'int'), GETPOST('clone_date_valueday', 'int'), GETPOST('clone_date_valueyear', 'int'));
  220. if ($newdatepayment) {
  221. $object->datep = $newdatepayment;
  222. }
  223. if (!empty($newdatevalue)) {
  224. $object->datev = $newdatevalue;
  225. } else {
  226. $object->datev = $newdatepayment;
  227. }
  228. if (GETPOSTISSET("clone_sens")) {
  229. $object->sens = GETPOST("clone_sens", 'int');
  230. } else {
  231. $object->sens = $object->sens;
  232. }
  233. if (GETPOST("clone_amount", "alpha")) {
  234. $object->amount = price2num(GETPOST("clone_amount", "alpha"));
  235. } else {
  236. $object->amount = price2num($object->amount);
  237. }
  238. if ($object->check()) {
  239. $id = $object->create($user);
  240. if ($id > 0) {
  241. $db->commit();
  242. $db->close();
  243. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  244. exit;
  245. } else {
  246. $id = $originalId;
  247. $db->rollback();
  248. setEventMessages($object->error, $object->errors, 'errors');
  249. }
  250. } else {
  251. $id = $originalId;
  252. $db->rollback();
  253. setEventMessages($object->error, $object->errors, 'errors');
  254. }
  255. } else {
  256. $db->rollback();
  257. dol_print_error($db, $object->error);
  258. }
  259. }
  260. /*
  261. * View
  262. */
  263. $form = new Form($db);
  264. if (isModEnabled('accounting')) {
  265. $formaccounting = new FormAccounting($db);
  266. }
  267. if (isModEnabled('project')) {
  268. $formproject = new FormProjets($db);
  269. }
  270. if ($id) {
  271. $object = new PaymentVarious($db);
  272. $result = $object->fetch($id);
  273. if ($result <= 0) {
  274. dol_print_error($db);
  275. exit;
  276. }
  277. }
  278. $title = $object->ref." - ".$langs->trans('Card');
  279. if ($action == 'create') {
  280. $title = $langs->trans("NewVariousPayment");
  281. }
  282. $help_url = 'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
  283. llxHeader('', $title, $help_url);
  284. $options = array();
  285. // Load bank groups
  286. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
  287. $bankcateg = new BankCateg($db);
  288. foreach ($bankcateg->fetchAll() as $bankcategory) {
  289. $options[$bankcategory->id] = $bankcategory->label;
  290. }
  291. // Create mode
  292. if ($action == 'create') {
  293. // Update fields properties in realtime
  294. if (!empty($conf->use_javascript_ajax)) {
  295. print "\n".'<script type="text/javascript">';
  296. print '$(document).ready(function () {
  297. setPaymentType();
  298. $("#selectpaymenttype").change(function() {
  299. setPaymentType();
  300. });
  301. function setPaymentType()
  302. {
  303. console.log("setPaymentType");
  304. var code = $("#selectpaymenttype option:selected").val();
  305. if (code == \'CHQ\' || code == \'VIR\')
  306. {
  307. if (code == \'CHQ\')
  308. {
  309. $(\'.fieldrequireddyn\').addClass(\'fieldrequired\');
  310. }
  311. if ($(\'#fieldchqemetteur\').val() == \'\')
  312. {
  313. var emetteur = jQuery(\'#thirdpartylabel\').val();
  314. $(\'#fieldchqemetteur\').val(emetteur);
  315. }
  316. }
  317. else
  318. {
  319. $(\'.fieldrequireddyn\').removeClass(\'fieldrequired\');
  320. $(\'#fieldchqemetteur\').val(\'\');
  321. }
  322. }
  323. ';
  324. print ' });'."\n";
  325. print ' </script>'."\n";
  326. }
  327. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  328. print '<input type="hidden" name="token" value="'.newToken().'">';
  329. print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
  330. print '<input type="hidden" name="action" value="add">';
  331. print load_fiche_titre($langs->trans("NewVariousPayment"), '', 'object_payment');
  332. print dol_get_fiche_head('', '');
  333. print '<table class="border centpercent">';
  334. // Date payment
  335. print '<tr><td class="titlefieldcreate">';
  336. print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).'</td><td>';
  337. print $form->selectDate((empty($datep) ?-1 : $datep), "datep", '', '', '', 'add', 1, 1);
  338. print '</td></tr>';
  339. // Date value for bank
  340. print '<tr><td>';
  341. print $form->editfieldkey('DateValue', 'datev', '', $object, 0).'</td><td>';
  342. print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1);
  343. print '</td></tr>';
  344. // Label
  345. print '<tr><td>';
  346. print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).'</td><td>';
  347. print '<input name="label" id="label" class="minwidth300 maxwidth150onsmartphone" value="'.($label ? $label : $langs->trans("VariousPayment")).'">';
  348. print '</td></tr>';
  349. // Amount
  350. print '<tr><td>';
  351. print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).'</td><td>';
  352. print '<input name="amount" id="amount" class="minwidth50 maxwidth100" value="'.$amount.'">';
  353. print '</td></tr>';
  354. // Bank
  355. if (isModEnabled("banque")) {
  356. print '<tr><td>';
  357. print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).'</td><td>';
  358. print img_picto('', 'bank_account', 'class="pictofixedwidth"');
  359. print $form->select_comptes($accountid, "accountid", 0, '', 2, '', 0, '', 1); // Show list of main accounts (comptes courants)
  360. print '</td></tr>';
  361. }
  362. // Type payment
  363. print '<tr><td><span class="fieldrequired">'.$langs->trans('PaymentMode').'</span></td><td>';
  364. $form->select_types_paiements($paymenttype, 'paymenttype', '', 2);
  365. print "</td>\n";
  366. print '</tr>';
  367. // Number
  368. if (isModEnabled("banque")) {
  369. print '<tr><td><label for="num_payment">'.$langs->trans('Numero');
  370. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  371. print '</label></td>';
  372. print '<td><input name="num_payment" class="maxwidth150onsmartphone" id="num_payment" type="text" value="'.GETPOST("num_payment").'"></td></tr>'."\n";
  373. // Check transmitter
  374. print '<tr><td class="'.(GETPOST('paymenttype') == 'CHQ' ? 'fieldrequired ' : '').'fieldrequireddyn"><label for="fieldchqemetteur">'.$langs->trans('CheckTransmitter');
  375. print ' <em>('.$langs->trans("ChequeMaker").')</em>';
  376. print '</label></td>';
  377. print '<td><input id="fieldchqemetteur" name="chqemetteur" size="30" type="text" value="'.GETPOST('chqemetteur', 'alphanohtml').'"></td></tr>';
  378. // Bank name
  379. print '<tr><td><label for="chqbank">'.$langs->trans('Bank');
  380. print ' <em>('.$langs->trans("ChequeBank").')</em>';
  381. print '</label></td>';
  382. print '<td><input id="chqbank" name="chqbank" size="30" type="text" value="'.GETPOST('chqbank', 'alphanohtml').'"></td></tr>';
  383. }
  384. // Accountancy account
  385. if (isModEnabled('accounting')) {
  386. // TODO Remove the fieldrequired and allow instead to edit a various payment to enter accounting code
  387. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("AccountAccounting").'</td>';
  388. print '<td>';
  389. print $formaccounting->select_account($accountancy_code, 'accountancy_code', 1, null, 1, 1);
  390. print '</td></tr>';
  391. } else { // For external software
  392. print '<tr><td class="titlefieldcreate">'.$langs->trans("AccountAccounting").'</td>';
  393. print '<td><input class="minwidth100 maxwidthonsmartphone" name="accountancy_code" value="'.$accountancy_code.'">';
  394. print '</td></tr>';
  395. }
  396. // Subledger account
  397. if (isModEnabled('accounting')) {
  398. print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
  399. print '<td>';
  400. if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
  401. print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1, '');
  402. } else {
  403. print '<input type="text" class="maxwidth200 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
  404. }
  405. print '</td></tr>';
  406. } else { // For external software
  407. print '<tr><td>'.$langs->trans("SubledgerAccount").'</td>';
  408. print '<td><input class="minwidth100 maxwidthonsmartphone" name="subledger_account" value="'.$subledger_account.'">';
  409. print '</td></tr>';
  410. }
  411. // Sens
  412. print '<tr><td>';
  413. $labelsens = $form->textwithpicto('Sens', $langs->trans("AccountingDirectionHelp"));
  414. print $form->editfieldkey($labelsens, 'sens', '', $object, 0, 'string', '', 1).'</td><td>';
  415. $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
  416. print $form->selectarray('sens', $sensarray, $sens, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100', 1);
  417. print '</td></tr>';
  418. // Project
  419. if (isModEnabled('project')) {
  420. $formproject = new FormProjets($db);
  421. // Associated project
  422. $langs->load("projects");
  423. print '<tr><td>'.$langs->trans("Project").'</td><td>';
  424. print img_picto('', 'bank_account', 'class="pictofixedwidth"');
  425. print $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
  426. print '</td></tr>';
  427. }
  428. // Other attributes
  429. $parameters = array();
  430. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  431. print $hookmanager->resPrint;
  432. // Category
  433. if (is_array($options) && count($options) && $conf->categorie->enabled) {
  434. print '<tr><td>'.$langs->trans("RubriquesTransactions").'</td><td>';
  435. print img_picto('', 'category').Form::selectarray('category_transaction', $options, GETPOST('category_transaction'), 1, 0, 0, '', 0, 0, 0, '', 'minwidth300', 1);
  436. print '</td></tr>';
  437. }
  438. print '</table>';
  439. print dol_get_fiche_end();
  440. print $form->buttonsSaveCancel();
  441. print '</form>';
  442. }
  443. /* ************************************************************************** */
  444. /* */
  445. /* View mode */
  446. /* */
  447. /* ************************************************************************** */
  448. if ($id) {
  449. $alreadyaccounted = $object->getVentilExportCompta();
  450. $head = various_payment_prepare_head($object);
  451. // Clone confirmation
  452. if ($action === 'clone') {
  453. $set_value_help = $form->textwithpicto('', $langs->trans($langs->trans("AccountingDirectionHelp")));
  454. $sensarray = array('0' => $langs->trans("Debit"), '1' => $langs->trans("Credit"));
  455. $formquestion = array(
  456. array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label),
  457. array('type' => 'date', 'tdclass'=>'fieldrequired', 'name' => 'clone_date_payment', 'label' => $langs->trans("DatePayment"), 'value' => -1),
  458. array('type' => 'date', 'name' => 'clone_date_value', 'label' => $langs->trans("DateValue"), 'value' => -1),
  459. array('type' => 'other', 'tdclass'=>'fieldrequired', 'name' => 'clone_accountid', 'label' => $langs->trans("BankAccount"), 'value' => $form->select_comptes($object->fk_account, "accountid", 0, '', 1, '', 0, 'minwidth200', 1)),
  460. array('type' => 'text', 'name' => 'clone_amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount)),
  461. array('type' => 'select', 'name' => 'clone_sens', 'label' => $langs->trans("Sens").' '.$set_value_help, 'values' => $sensarray, 'default' => $object->sens),
  462. );
  463. print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneVariousPayment', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 350);
  464. }
  465. // Confirmation of the removal of the Various Payment
  466. if ($action == 'delete') {
  467. $text = $langs->trans('ConfirmDeleteVariousPayment');
  468. print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteVariousPayment'), $text, 'confirm_delete', '', '', 2);
  469. }
  470. print dol_get_fiche_head($head, 'card', $langs->trans("VariousPayment"), -1, $object->picto);
  471. $morehtmlref = '<div class="refidno">';
  472. // Project
  473. if (isModEnabled('project')) {
  474. $langs->load("projects");
  475. $morehtmlref .= $langs->trans('Project').' ';
  476. if ($user->rights->banque->modifier) {
  477. if ($action != 'classify') {
  478. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  479. }
  480. if ($action == 'classify') {
  481. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  482. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  483. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  484. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  485. $morehtmlref .= $formproject->select_projects(0, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  486. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  487. $morehtmlref .= '</form>';
  488. } else {
  489. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
  490. }
  491. } else {
  492. if (!empty($object->fk_project)) {
  493. $proj = new Project($db);
  494. $proj->fetch($object->fk_project);
  495. $morehtmlref .= $proj->getNomUrl(1);
  496. } else {
  497. $morehtmlref .= '';
  498. }
  499. }
  500. }
  501. $morehtmlref .= '</div>';
  502. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/bank/various_payment/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  503. $morehtmlright = '';
  504. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
  505. print '<div class="fichecenter">';
  506. print '<div class="underbanner clearboth"></div>';
  507. print '<table class="border centpercent tableforfield">';
  508. // Label
  509. print '<tr><td class="titlefield">'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
  510. // Payment date
  511. print "<tr>";
  512. print '<td>'.$langs->trans("DatePayment").'</td><td>';
  513. print dol_print_date($object->datep, 'day');
  514. print '</td></tr>';
  515. // Value date
  516. print '<tr><td>'.$langs->trans("DateValue").'</td><td>';
  517. print dol_print_date($object->datev, 'day');
  518. print '</td></tr>';
  519. // Debit / Credit
  520. if ($object->sens == '1') {
  521. $sens = $langs->trans("Credit");
  522. } else {
  523. $sens = $langs->trans("Debit");
  524. }
  525. print '<tr><td>'.$langs->trans("Sens").'</td><td>'.$sens.'</td></tr>';
  526. print '<tr><td>'.$langs->trans("Amount").'</td><td><span class="amount">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
  527. // Accountancy code
  528. print '<tr><td class="nowrap">';
  529. print $langs->trans("AccountAccounting");
  530. print '</td><td>';
  531. if (isModEnabled('accounting')) {
  532. $accountingaccount = new AccountingAccount($db);
  533. $accountingaccount->fetch('', $object->accountancy_code, 1);
  534. print $accountingaccount->getNomUrl(0, 1, 1, '', 1);
  535. } else {
  536. print $object->accountancy_code;
  537. }
  538. print '</td></tr>';
  539. // Subledger account
  540. print '<tr><td class="nowrap">';
  541. print $form->editfieldkey('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0);
  542. print '</td><td>';
  543. print $form->editfieldval('SubledgerAccount', 'subledger_account', $object->subledger_account, $object, (!$alreadyaccounted && $user->rights->banque->modifier), 'string', '', 0);
  544. print '</td></tr>';
  545. $bankaccountnotfound = 0;
  546. if (isModEnabled('banque')) {
  547. print '<tr>';
  548. print '<td>'.$langs->trans('BankTransactionLine').'</td>';
  549. print '<td colspan="3">';
  550. if ($object->fk_bank > 0) {
  551. $bankline = new AccountLine($db);
  552. $result = $bankline->fetch($object->fk_bank);
  553. if ($result <= 0) {
  554. $bankaccountnotfound = 1;
  555. } else {
  556. print $bankline->getNomUrl(1, 0, 'showall');
  557. }
  558. } else {
  559. $bankaccountnotfound = 1;
  560. print '<span class="opacitymedium">'.$langs->trans("NoRecordfound").'</span>';
  561. }
  562. print '</td>';
  563. print '</tr>';
  564. }
  565. // Other attributes
  566. $parameters = array('socid'=>$object->id);
  567. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  568. print '</table>';
  569. print '</div>';
  570. print '<div class="clearboth"></div>';
  571. print dol_get_fiche_end();
  572. /*
  573. * Action bar
  574. */
  575. print '<div class="tabsAction">'."\n";
  576. // TODO
  577. // Add button modify
  578. // Clone
  579. if ($user->rights->banque->modifier) {
  580. print '<div class="inline-block divButAction"><a class="butAction" href="'.dol_buildpath("/compta/bank/various_payment/card.php", 1).'?id='.$object->id.'&amp;action=clone">'.$langs->trans("ToClone")."</a></div>";
  581. }
  582. // Delete
  583. if (empty($object->rappro) || $bankaccountnotfound) {
  584. if (!empty($user->rights->banque->modifier)) {
  585. if ($alreadyaccounted) {
  586. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("Accounted").'">'.$langs->trans("Delete").'</a></div>';
  587. } else {
  588. print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
  589. }
  590. } else {
  591. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("NotAllowed"))).'">'.$langs->trans("Delete").'</a></div>';
  592. }
  593. } else {
  594. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("LinkedToAConciliatedTransaction").'">'.$langs->trans("Delete").'</a></div>';
  595. }
  596. print "</div>";
  597. }
  598. // End of page
  599. llxFooter();
  600. $db->close();