card.php 33 KB

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