card.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. <?php
  2. /* Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
  4. * Copyright (C) 2016-2018 Frédéric France <frederic.france@netlogic.fr>
  5. * Copyright (C) 2017-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  6. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/compta/sociales/card.php
  23. * \ingroup tax
  24. * \brief Social contribution card page
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  36. if (isModEnabled('project')) {
  37. include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  38. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  39. }
  40. if (isModEnabled('accounting')) {
  41. include_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  42. }
  43. // Load translation files required by the page
  44. $langs->loadLangs(array('compta', 'bills', 'banks', 'hrm'));
  45. $id = GETPOST('id', 'int');
  46. $ref = GETPOST('ref', 'alpha');
  47. $action = GETPOST('action', 'aZ09');
  48. $confirm = GETPOST('confirm', 'alpha');
  49. $cancel = GETPOST('cancel', 'aZ09');
  50. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectcard'; // To manage different context of search
  51. $backtopage = GETPOST('backtopage', 'alpha');
  52. $backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
  53. $lineid = GETPOST('lineid', 'int');
  54. $fk_project = (GETPOST('fk_project') ? GETPOST('fk_project', 'int') : 0);
  55. $dateech = dol_mktime(GETPOST('echhour'), GETPOST('echmin'), GETPOST('echsec'), GETPOST('echmonth'), GETPOST('echday'), GETPOST('echyear'));
  56. $dateperiod = dol_mktime(GETPOST('periodhour'), GETPOST('periodmin'), GETPOST('periodsec'), GETPOST('periodmonth'), GETPOST('periodday'), GETPOST('periodyear'));
  57. $label = GETPOST('label', 'alpha');
  58. $actioncode = GETPOST('actioncode');
  59. $fk_user = GETPOST('userid', 'int');
  60. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  61. $hookmanager->initHooks(array('taxcard', 'globalcard'));
  62. // Initialize technical objects
  63. $object = new ChargeSociales($db);
  64. $extrafields = new ExtraFields($db);
  65. $diroutputmassaction = $conf->tax->dir_output.'/temp/massgeneration/'.$user->id;
  66. $hookmanager->initHooks(array('taxsocialcontributioncard', 'globalcard'));
  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];
  80. // Security check
  81. $socid = GETPOST('socid', 'int');
  82. if ($user->socid) {
  83. $socid = $user->socid;
  84. }
  85. $result = restrictedArea($user, 'tax', $object->id, 'chargesociales', 'charges');
  86. /*
  87. * Actions
  88. */
  89. $parameters = array('socid' => $socid);
  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. // Classify paid
  95. if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') {
  96. $object->fetch($id);
  97. $result = $object->setPaid($user);
  98. }
  99. if ($action == 'reopen' && $user->rights->tax->charges->creer) {
  100. $result = $object->fetch($id);
  101. if ($object->paye) {
  102. $result = $object->setUnpaid($user);
  103. if ($result > 0) {
  104. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  105. exit();
  106. } else {
  107. setEventMessages($object->error, $object->errors, 'errors');
  108. }
  109. }
  110. }
  111. // Link to a project
  112. if ($action == 'classin' && $user->rights->tax->charges->creer) {
  113. $object->fetch($id);
  114. $object->setProject(GETPOST('fk_project'));
  115. }
  116. if ($action == 'setfk_user' && $user->rights->tax->charges->creer) {
  117. $object->fetch($id);
  118. $object->fk_user = $fk_user;
  119. $object->update($user);
  120. }
  121. if ($action == 'setlib' && $user->rights->tax->charges->creer) {
  122. $object->fetch($id);
  123. $result = $object->setValueFrom('libelle', GETPOST('lib'), '', '', 'text', '', $user, 'TAX_MODIFY');
  124. if ($result < 0) {
  125. setEventMessages($object->error, $object->errors, 'errors');
  126. }
  127. }
  128. // payment mode
  129. if ($action == 'setmode' && $user->rights->tax->charges->creer) {
  130. $object->fetch($id);
  131. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
  132. if ($result < 0) {
  133. setEventMessages($object->error, $object->errors, 'errors');
  134. }
  135. }
  136. // Bank account
  137. if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) {
  138. $object->fetch($id);
  139. $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
  140. if ($result < 0) {
  141. setEventMessages($object->error, $object->errors, 'errors');
  142. }
  143. }
  144. // Delete social contribution
  145. if ($action == 'confirm_delete' && $confirm == 'yes') {
  146. $object->fetch($id);
  147. $totalpaid = $object->getSommePaiement();
  148. if (empty($totalpaid)) {
  149. $result = $object->delete($user);
  150. if ($result > 0) {
  151. header("Location: list.php");
  152. exit;
  153. } else {
  154. setEventMessages($object->error, $object->errors, 'errors');
  155. }
  156. } else {
  157. setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
  158. }
  159. }
  160. // Add social contribution
  161. if ($action == 'add' && $user->rights->tax->charges->creer) {
  162. $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
  163. if (!$dateech) {
  164. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
  165. $action = 'create';
  166. } elseif (!$dateperiod) {
  167. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
  168. $action = 'create';
  169. } elseif (!($actioncode > 0)) {
  170. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
  171. $action = 'create';
  172. } elseif (empty($amount)) {
  173. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
  174. $action = 'create';
  175. } elseif (!is_numeric($amount)) {
  176. setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
  177. $action = 'create';
  178. } else {
  179. $object->type = $actioncode;
  180. $object->label = GETPOST('label', 'alpha');
  181. $object->date_ech = $dateech;
  182. $object->periode = $dateperiod;
  183. $object->amount = $amount;
  184. $object->fk_user = $fk_user;
  185. $object->mode_reglement_id = (int) GETPOST('mode_reglement_id', 'int');
  186. $object->fk_account = (int) GETPOST('fk_account', 'int');
  187. $object->fk_project = (int) GETPOST('fk_project', 'int');
  188. $id = $object->create($user);
  189. if ($id <= 0) {
  190. setEventMessages($object->error, $object->errors, 'errors');
  191. $action = 'create';
  192. }
  193. }
  194. }
  195. if ($action == 'update' && !GETPOST("cancel") && $user->rights->tax->charges->creer) {
  196. $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
  197. if (!$dateech) {
  198. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
  199. $action = 'edit';
  200. } elseif (!$dateperiod) {
  201. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
  202. $action = 'edit';
  203. } elseif (empty($amount)) {
  204. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
  205. $action = 'edit';
  206. } elseif (!is_numeric($amount)) {
  207. setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
  208. $action = 'create';
  209. } else {
  210. $result = $object->fetch($id);
  211. $object->date_ech = $dateech;
  212. $object->periode = $dateperiod;
  213. $object->amount = $amount;
  214. $object->fk_user = $fk_user;
  215. $result = $object->update($user);
  216. if ($result <= 0) {
  217. setEventMessages($object->error, $object->errors, 'errors');
  218. }
  219. }
  220. }
  221. // Action clone object
  222. if ($action == 'confirm_clone' && $confirm != 'yes') {
  223. $action = '';
  224. }
  225. if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) {
  226. $db->begin();
  227. $originalId = $id;
  228. $object->fetch($id);
  229. if ($object->id > 0) {
  230. $object->id = $object->ref = null;
  231. $object->paye = 0;
  232. if (GETPOST('amount', 'alphanohtml')) {
  233. $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
  234. }
  235. if (GETPOST('clone_label', 'alphanohtml')) {
  236. $object->label = GETPOST('clone_label', 'alphanohtml');
  237. } else {
  238. $object->label = $langs->trans("CopyOf").' '.$object->label;
  239. }
  240. if (GETPOST('clone_for_next_month', 'int')) { // This can be true only if TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX has been set
  241. $object->periode = dol_time_plus_duree($object->periode, 1, 'm');
  242. $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm');
  243. } else {
  244. // Note date_ech is often a little bit higher than dateperiod
  245. $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int'));
  246. $newdateech = dol_mktime(0, 0, 0, GETPOST('clone_date_echmonth', 'int'), GETPOST('clone_date_echday', 'int'), GETPOST('clone_date_echyear', 'int'));
  247. if ($newdateperiod) {
  248. $object->periode = $newdateperiod;
  249. if (empty($newdateech)) {
  250. $object->date_ech = $object->periode;
  251. }
  252. }
  253. if ($newdateech) {
  254. $object->date_ech = $newdateech;
  255. if (empty($newdateperiod)) {
  256. // TODO We can here get dol_get_last_day of previous month:
  257. // $object->periode = dol_get_last_day(year of $object->date_ech - 1m, month or $object->date_ech -1m)
  258. $object->periode = $object->date_ech;
  259. }
  260. }
  261. }
  262. $resultcheck = $object->check();
  263. if ($resultcheck) {
  264. $id = $object->create($user);
  265. if ($id > 0) {
  266. $db->commit();
  267. $db->close();
  268. header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
  269. exit;
  270. } else {
  271. $id = $originalId;
  272. $db->rollback();
  273. setEventMessages($object->error, $object->errors, 'errors');
  274. }
  275. }
  276. } else {
  277. $db->rollback();
  278. dol_print_error($db, $object->error);
  279. }
  280. }
  281. /*
  282. * View
  283. */
  284. $form = new Form($db);
  285. $formfile = new FormFile($db);
  286. $formsocialcontrib = new FormSocialContrib($db);
  287. $bankaccountstatic = new Account($db);
  288. if (isModEnabled('project')) {
  289. $formproject = new FormProjets($db);
  290. }
  291. $title = $langs->trans("SocialContribution").' - '.$langs->trans("Card");
  292. $help_url = 'EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:M&oacute;dulo Impuestos y cargas sociales (IVA, impuestos)';
  293. llxHeader("", $title, $help_url);
  294. // Form to create a social contribution
  295. if ($action == 'create') {
  296. print load_fiche_titre($langs->trans("NewSocialContribution"));
  297. print '<form name="charge" method="post" action="'.$_SERVER["PHP_SELF"].'">';
  298. print '<input type="hidden" name="token" value="'.newToken().'">';
  299. print '<input type="hidden" name="action" value="add">';
  300. print dol_get_fiche_head();
  301. print '<table class="border centpercent">';
  302. // Label
  303. print "<tr>";
  304. print '<td class="titlefieldcreate fieldrequired">';
  305. print $langs->trans("Label");
  306. print '</td>';
  307. print '<td><input type="text" name="label" class="flat minwidth300" value="'.dol_escape_htmltag(GETPOST('label', 'alpha')).'" autofocus></td>';
  308. print '</tr>';
  309. print '<tr>';
  310. // Type
  311. print '<td class="fieldrequired">';
  312. print $langs->trans("Type");
  313. print '</td>';
  314. print '<td>';
  315. $formsocialcontrib->select_type_socialcontrib(GETPOST("actioncode", 'alpha') ?GETPOST("actioncode", 'alpha') : '', 'actioncode', 1);
  316. print '</td>';
  317. print '</tr>';
  318. // Date
  319. print '<tr>';
  320. print '<td class="fieldrequired">';
  321. print $langs->trans("Date");
  322. print '</td>';
  323. print '<td>';
  324. print $form->selectDate(!empty($dateech) ? $dateech : '-1', 'ech', 0, 0, 0, 'charge', 1, 1);
  325. print '</td>';
  326. print "</tr>\n";
  327. // Date end period
  328. print '<tr>';
  329. print '<td class="fieldrequired">';
  330. print $form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"));
  331. print '</td>';
  332. print '<td>';
  333. print $form->selectDate(!empty($dateperiod) ? $dateperiod : '-1', 'period', 0, 0, 0, 'charge', 1);
  334. print '</td>';
  335. print '</tr>';
  336. // Amount
  337. print '<tr>';
  338. print '<td class="fieldrequired">';
  339. print $langs->trans("Amount");
  340. print '</td>';
  341. print '<td><input type="text" size="6" name="amount" class="flat" value="'.dol_escape_htmltag(GETPOST('amount', 'alpha')).'"></td>';
  342. print '</tr>';
  343. // Employee
  344. print '<tr><td>';
  345. print $langs->trans('Employee');
  346. print '</td>';
  347. print '<td>'.img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($fk_user, 'userid', 1).'</td></tr>';
  348. // Project
  349. if (isModEnabled('project')) {
  350. $formproject = new FormProjets($db);
  351. // Associated project
  352. $langs->load("projects");
  353. print '<tr><td>'.$langs->trans("Project").'</td><td>';
  354. print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(-1, $fk_project, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
  355. print '</td></tr>';
  356. }
  357. // Payment Mode
  358. print '<tr><td>'.$langs->trans('DefaultPaymentMode').'</td><td colspan="2">';
  359. $form->select_types_paiements(GETPOST('mode_reglement_id', 'int'), 'mode_reglement_id');
  360. print '</td></tr>';
  361. // Bank Account
  362. if (isModEnabled("banque")) {
  363. print '<tr><td>'.$langs->trans('DefaultBankAccount').'</td><td colspan="2">';
  364. print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes(GETPOST('fk_account', 'int'), 'fk_account', 0, '', 2, '', 0, '', 1);
  365. print '</td></tr>';
  366. }
  367. print '</table>';
  368. print dol_get_fiche_end();
  369. print '<div class="center">';
  370. print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
  371. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  372. print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="javascript:history.go(-1)">';
  373. print '</div>';
  374. print '</form>';
  375. }
  376. // View mode
  377. if ($id > 0) {
  378. $object = new ChargeSociales($db);
  379. $result = $object->fetch($id);
  380. $formconfirm = '';
  381. if ($result > 0) {
  382. $head = tax_prepare_head($object);
  383. $totalpaid = $object->getSommePaiement();
  384. // Clone confirmation
  385. if ($action === 'clone') {
  386. $formquestion = array(
  387. array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label, 'tdclass'=>'fieldrequired'),
  388. );
  389. if (!empty($conf->global->TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX)) {
  390. $formquestion[] = array('type' => 'checkbox', 'name' => 'clone_for_next_month', 'label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1);
  391. } else {
  392. $formquestion[] = array('type' => 'date', 'datenow'=>1, 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
  393. $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
  394. $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100');
  395. }
  396. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneTax', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 280);
  397. }
  398. if ($action == 'paid') {
  399. $text = $langs->trans('ConfirmPaySocialContribution');
  400. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySocialContribution'), $text, "confirm_paid", '', '', 2);
  401. }
  402. // Confirmation of the removal of the Social Contribution
  403. if ($action == 'delete') {
  404. $text = $langs->trans('ConfirmDeleteSocialContribution');
  405. $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSocialContribution'), $text, 'confirm_delete', '', '', 2);
  406. }
  407. if ($action == 'edit') {
  408. print "<form name=\"charge\" action=\"".$_SERVER["PHP_SELF"]."?id=$object->id&amp;action=update\" method=\"post\">";
  409. print '<input type="hidden" name="token" value="'.newToken().'">';
  410. }
  411. // Call Hook formConfirm
  412. $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
  413. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  414. if (empty($reshook)) {
  415. $formconfirm .= $hookmanager->resPrint;
  416. } elseif ($reshook > 0) {
  417. $formconfirm = $hookmanager->resPrint;
  418. }
  419. // Print form confirm
  420. print $formconfirm;
  421. print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill');
  422. $morehtmlref = '<div class="refidno">';
  423. // Ref customer
  424. $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', 0, 1);
  425. $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->rights->tax->charges->creer, 'string', '', null, null, '', 1);
  426. // Employee
  427. if ($action != 'editfk_user') {
  428. if ($object->getSommePaiement() > 0 && !empty($object->fk_user)) {
  429. $userstatic = new User($db);
  430. $result = $userstatic->fetch($object->fk_user);
  431. if ($result > 0) {
  432. $morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(1);
  433. }
  434. } else {
  435. $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->rights->salaries->write, 'string', '', 0, 1);
  436. if (!empty($object->fk_user)) {
  437. $userstatic = new User($db);
  438. $result = $userstatic->fetch($object->fk_user);
  439. if ($result > 0) {
  440. $morehtmlref .= $userstatic->getNomUrl(1);
  441. } else {
  442. dol_print_error($db);
  443. exit();
  444. }
  445. }
  446. }
  447. } else {
  448. $morehtmlref .= '<br>'.$langs->trans('Employee').' :&nbsp;';
  449. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  450. $morehtmlref .= '<input type="hidden" name="action" value="setfk_user">';
  451. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  452. $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1);
  453. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  454. $morehtmlref .= '</form>';
  455. }
  456. // Project
  457. if (isModEnabled('project')) {
  458. $langs->load("projects");
  459. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  460. if ($user->rights->tax->charges->creer) {
  461. if ($action != 'classify') {
  462. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  463. }
  464. if ($action == 'classify') {
  465. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  466. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  467. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  468. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  469. $morehtmlref .= $formproject->select_projects(0, $object->fk_project, 'fk_project', 0, 0, 1, 0, 1, 0, 0, '', 1);
  470. $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  471. $morehtmlref .= '</form>';
  472. } else {
  473. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, 0, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
  474. }
  475. } else {
  476. if (!empty($object->fk_project)) {
  477. $proj = new Project($db);
  478. $proj->fetch($object->fk_project);
  479. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  480. if ($proj->title) {
  481. $morehtmlref .= ' - '.$proj->title;
  482. }
  483. } else {
  484. $morehtmlref .= '';
  485. }
  486. }
  487. }
  488. $morehtmlref .= '</div>';
  489. $morehtmlright = '';
  490. $linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  491. $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
  492. dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright);
  493. print '<div class="fichecenter">';
  494. print '<div class="fichehalfleft">';
  495. print '<div class="underbanner clearboth"></div>';
  496. print '<table class="border centpercent">';
  497. // Type
  498. print '<tr><td class="titlefield">';
  499. print $langs->trans("Type")."</td><td>".$object->type_label."</td>";
  500. print "</tr>";
  501. // Date
  502. if ($action == 'edit') {
  503. print '<tr><td>'.$langs->trans("Date")."</td><td>";
  504. print $form->selectDate($object->date_ech, 'ech', 0, 0, 0, 'charge', 1, 1);
  505. print "</td></tr>";
  506. } else {
  507. print "<tr><td>".$langs->trans("Date")."</td><td>".dol_print_date($object->date_ech, 'day')."</td></tr>";
  508. }
  509. // Period end date
  510. print "<tr><td>".$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"))."</td>";
  511. print "<td>";
  512. if ($action == 'edit') {
  513. print $form->selectDate($object->periode, 'period', 0, 0, 0, 'charge', 1);
  514. } else {
  515. print dol_print_date($object->periode, "day");
  516. }
  517. print "</td></tr>";
  518. // Amount
  519. if ($action == 'edit') {
  520. print '<tr><td>'.$langs->trans("AmountTTC")."</td><td>";
  521. print '<input type="text" name="amount" size="12" class="flat" value="'.price($object->amount).'">';
  522. print "</td></tr>";
  523. } else {
  524. print '<tr><td>'.$langs->trans("AmountTTC").'</td><td><span class="amount">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
  525. }
  526. // Mode of payment
  527. print '<tr><td>';
  528. print '<table class="nobordernopadding" width="100%"><tr><td>';
  529. print $langs->trans('DefaultPaymentMode');
  530. print '</td>';
  531. if ($action != 'editmode') {
  532. 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>';
  533. }
  534. print '</tr></table>';
  535. print '</td><td>';
  536. if ($action == 'editmode') {
  537. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id');
  538. } else {
  539. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
  540. }
  541. print '</td></tr>';
  542. // Bank account
  543. if (isModEnabled("banque")) {
  544. print '<tr><td class="nowrap">';
  545. print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
  546. print $langs->trans('DefaultBankAccount');
  547. print '<td>';
  548. if ($action != 'editbankaccount' && $user->rights->tax->charges->creer) {
  549. 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>';
  550. }
  551. print '</tr></table>';
  552. print '</td><td>';
  553. if ($action == 'editbankaccount') {
  554. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
  555. } else {
  556. $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
  557. }
  558. print '</td>';
  559. print '</tr>';
  560. }
  561. // Other attributes
  562. $parameters = array();
  563. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  564. print $hookmanager->resPrint;
  565. print '</table>';
  566. print '</div>';
  567. print '<div class="fichehalfright">';
  568. $nbcols = 3;
  569. if (isModEnabled("banque")) {
  570. $nbcols++;
  571. }
  572. /*
  573. * Payments
  574. */
  575. $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,";
  576. $sql .= " c.code as type_code,c.libelle as paiement_type,";
  577. $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';
  578. $sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
  579. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
  580. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
  581. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
  582. $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
  583. $sql .= " WHERE p.fk_charge = ".((int) $id);
  584. $sql .= " AND p.fk_charge = cs.rowid";
  585. $sql .= " AND cs.entity IN (".getEntity('sc').")";
  586. $sql .= " ORDER BY dp DESC";
  587. //print $sql;
  588. $resql = $db->query($sql);
  589. if ($resql) {
  590. $totalpaid = 0;
  591. $num = $db->num_rows($resql);
  592. $i = 0;
  593. $total = 0;
  594. 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
  595. print '<table class="noborder paymenttable">';
  596. print '<tr class="liste_titre">';
  597. print '<td>'.$langs->trans("RefPayment").'</td>';
  598. print '<td>'.$langs->trans("Date").'</td>';
  599. print '<td>'.$langs->trans("Type").'</td>';
  600. if (isModEnabled("banque")) {
  601. print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
  602. }
  603. print '<td class="right">'.$langs->trans("Amount").'</td>';
  604. print '</tr>';
  605. $paymentsocialcontributiontmp = new PaymentSocialContribution($db);
  606. if ($num > 0) {
  607. while ($i < $num) {
  608. $objp = $db->fetch_object($resql);
  609. $paymentsocialcontributiontmp->id = $objp->rowid;
  610. $paymentsocialcontributiontmp->ref = $objp->rowid;
  611. $paymentsocialcontributiontmp->datep = $db->jdate($objp->dp);
  612. print '<tr class="oddeven"><td>';
  613. print $paymentsocialcontributiontmp->getNomUrl(1);
  614. print '</td>';
  615. print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
  616. $labeltype = $langs->trans("PaymentType".$objp->type_code) != ("PaymentType".$objp->type_code) ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
  617. print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
  618. if (isModEnabled("banque")) {
  619. $bankaccountstatic->id = $objp->baid;
  620. $bankaccountstatic->ref = $objp->baref;
  621. $bankaccountstatic->label = $objp->baref;
  622. $bankaccountstatic->number = $objp->banumber;
  623. $bankaccountstatic->currency_code = $objp->bacurrency_code;
  624. if (isModEnabled('accounting')) {
  625. $bankaccountstatic->account_number = $objp->account_number;
  626. $accountingjournal = new AccountingJournal($db);
  627. $accountingjournal->fetch($objp->fk_accountancy_journal);
  628. $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  629. }
  630. print '<td class="right">';
  631. if ($bankaccountstatic->id) {
  632. print $bankaccountstatic->getNomUrl(1, 'transactions');
  633. }
  634. print '</td>';
  635. }
  636. print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
  637. print "</tr>";
  638. $totalpaid += $objp->amount;
  639. $i++;
  640. }
  641. } else {
  642. print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
  643. print '<td></td><td></td><td></td><td></td>';
  644. print '</tr>';
  645. }
  646. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="right">'.price($totalpaid)."</td></tr>\n";
  647. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").' :</td><td class="right">'.price($object->amount)."</td></tr>\n";
  648. $resteapayer = $object->amount - $totalpaid;
  649. $cssforamountpaymentcomplete = 'amountpaymentcomplete';
  650. print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
  651. print '<td class="right'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
  652. print "</table>";
  653. print '</div>';
  654. $db->free($resql);
  655. } else {
  656. dol_print_error($db);
  657. }
  658. print '</div>';
  659. print '</div>';
  660. print '<div class="clearboth"></div>';
  661. print dol_get_fiche_end();
  662. if ($action == 'edit') {
  663. print $form->buttonsSaveCancel();
  664. print "</form>\n";
  665. }
  666. // Buttons for actions
  667. if ($action != 'edit') {
  668. print '<div class="tabsAction">'."\n";
  669. // Reopen
  670. if ($object->paye && $user->rights->tax->charges->creer) {
  671. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans("ReOpen").'</a></div>';
  672. }
  673. // Edit
  674. if ($object->paye == 0 && $user->rights->tax->charges->creer) {
  675. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a></div>';
  676. }
  677. // Emit payment
  678. 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) {
  679. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/paiement_charge.php?id='.$object->id.'&action=create&token='.newToken().'">'.$langs->trans("DoPayment")."</a></div>";
  680. }
  681. // Classify 'paid'
  682. if ($object->paye == 0 && round($resteapayer) <= 0 && $user->rights->tax->charges->creer) {
  683. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=paid&token='.newToken().'">'.$langs->trans("ClassifyPaid").'</a></div>';
  684. }
  685. // Clone
  686. if ($user->rights->tax->charges->creer) {
  687. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=clone&token='.newToken().'">'.$langs->trans("ToClone")."</a></div>";
  688. }
  689. // Delete
  690. if ($user->rights->tax->charges->supprimer && empty($totalpaid)) {
  691. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=delete&token='.newToken().'">'.$langs->trans("Delete").'</a></div>';
  692. } else {
  693. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("DisabledBecausePayments"))).'">'.$langs->trans("Delete").'</a></div>';
  694. }
  695. print "</div>";
  696. }
  697. // Select mail models is same action as presend
  698. if (GETPOST('modelselected')) {
  699. $action = 'presend';
  700. }
  701. if ($action != 'presend') {
  702. print '<div class="fichecenter"><div class="fichehalfleft">';
  703. print '<a name="builddoc"></a>'; // ancre
  704. $includedocgeneration = 1;
  705. // Documents
  706. if ($includedocgeneration) {
  707. $objref = dol_sanitizeFileName($object->ref);
  708. $relativepath = $objref.'/'.$objref.'.pdf';
  709. $filedir = $conf->tax->dir_output.'/'.$objref;
  710. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  711. //$genallowed = $user->rights->tax->charges->lire; // If you can read, you can build the PDF to read content
  712. $genallowed = 0;
  713. $delallowed = $user->rights->tax->charges->creer; // If you can create/edit, you can remove a file on card
  714. print $formfile->showdocuments('tax', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
  715. }
  716. // Show links to link elements
  717. //$linktoelem = $form->showLinkToObjectBlock($object, null, array('myobject'));
  718. //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  719. print '</div><div class="fichehalfright">';
  720. /*
  721. $MAXEVENT = 10;
  722. $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
  723. // List of actions on element
  724. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  725. $formactions = new FormActions($db);
  726. $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
  727. */
  728. print '</div></div>';
  729. }
  730. //Select mail models is same action as presend
  731. if (GETPOST('modelselected')) {
  732. $action = 'presend';
  733. }
  734. // Presend form
  735. $modelmail = 'sc';
  736. $defaulttopic = 'InformationMessage';
  737. $diroutput = $conf->tax->dir_output;
  738. $trackid = 'sc'.$object->id;
  739. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  740. } else {
  741. /* Social contribution not found */
  742. dol_print_error('', $object->error);
  743. }
  744. }
  745. // End of page
  746. llxFooter();
  747. $db->close();