card.php 33 KB

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