dolibarr 25.0.0-alpha
card.php
Go to the documentation of this file.
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-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2017-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
6 * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
7 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
29// Load Dolibarr environment
30require '../../main.inc.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php';
41require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
42require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
43require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
49require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
50if (isModEnabled('project')) {
51 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
52 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
53}
54
55
56// Load translation files required by the page
57$langs->loadLangs(array('compta', 'bills', 'banks', 'hrm'));
58
59$id = GETPOSTINT('id');
60$ref = GETPOST('ref', 'alpha');
61$action = GETPOST('action', 'aZ09');
62$confirm = GETPOST('confirm', 'alpha');
63$cancel = GETPOST('cancel', 'alpha');
64$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'chargesocialescard'; // To manage different context of search
65$backtopage = GETPOST('backtopage', 'alpha');
66$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha');
67
68$lineid = GETPOSTINT('lineid');
69
70$fk_project = (GETPOST('fk_project') ? GETPOSTINT('fk_project') : 0);
71
72$dateech = dol_mktime(GETPOSTINT('echhour'), GETPOSTINT('echmin'), GETPOSTINT('echsec'), GETPOSTINT('echmonth'), GETPOSTINT('echday'), GETPOSTINT('echyear'));
73$dateperiod = dol_mktime(GETPOSTINT('periodhour'), GETPOSTINT('periodmin'), GETPOSTINT('periodsec'), GETPOSTINT('periodmonth'), GETPOSTINT('periodday'), GETPOSTINT('periodyear'));
74$label = GETPOST('label', 'alpha');
75$actioncode = GETPOSTINT('actioncode');
76$fk_user = GETPOSTINT('userid') > 0 ? GETPOSTINT('userid') : 0;
77
78// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
79$hookmanager->initHooks(array('taxcard', 'globalcard'));
80
81// Initialize a technical objects
82$object = new ChargeSociales($db);
83$diroutputmassaction = $conf->tax->dir_output.'/temp/massgeneration/'.$user->id;
84$hookmanager->initHooks(array('taxsocialcontributioncard', 'globalcard'));
85
86if (empty($action) && empty($id) && empty($ref)) {
87 $action = 'view';
88}
89
90// Load object
91if ($id > 0 || $ref) {
92 $object->fetch($id, $ref);
93}
94
95$permissiontoread = $user->hasRight('tax', 'charges', 'lire');
96$permissiontoadd = $user->hasRight('tax', 'charges', 'creer'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
97$permissiontodelete = $user->hasRight('tax', 'charges', 'supprimer') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID);
98$permissionnote = $user->hasRight('tax', 'charges', 'creer'); // Used by the include of actions_setnotes.inc.php
99$permissiondellink = $user->hasRight('tax', 'charges', 'creer'); // Used by the include of actions_dellink.inc.php
100$upload_dir = $conf->tax->multidir_output[isset($object->entity) ? $object->entity : 1];
101
102// Security check
103$socid = GETPOSTINT('socid');
104if ($user->socid) {
105 $socid = $user->socid;
106}
107$result = restrictedArea($user, 'tax', $object->id, 'chargesociales', 'charges');
108
109
110/*
111 * Actions
112 */
113
114$parameters = array('socid' => $socid);
115$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
116if ($reshook < 0) {
117 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
118}
119
120if (empty($reshook)) {
121 // Classify paid
122 if ($action == 'confirm_paid' && $permissiontoadd && $confirm == 'yes') {
123 $result = $object->setPaid($user);
124 }
125
126 if ($action == 'reopen' && $user->hasRight('tax', 'charges', 'creer')) {
127 if ($object->paye) {
128 $result = $object->setUnpaid($user);
129 if ($result > 0) {
130 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
131 exit();
132 } else {
133 setEventMessages($object->error, $object->errors, 'errors');
134 }
135 }
136 }
137
138 // Link to a project
139 if ($action == 'classin' && $permissiontoadd) {
140 $object->setProject(GETPOSTINT('fk_project'));
141 }
142
143 if ($action == 'setfk_user' && $permissiontoadd) {
144 $object->fk_user = $fk_user;
145 $result = $object->update($user);
146 if ($result < 0) {
147 setEventMessages($object->error, $object->errors, 'errors');
148 }
149 }
150
151 if ($action == 'setlib' && $permissiontoadd) {
152 $result = $object->setValueFrom('libelle', GETPOST('lib'), '', null, 'text', '', $user, 'TAX_MODIFY');
153 if ($result < 0) {
154 setEventMessages($object->error, $object->errors, 'errors');
155 }
156 }
157
158 // payment mode
159 if ($action == 'setmode' && $permissiontoadd) {
160 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
161 if ($result < 0) {
162 setEventMessages($object->error, $object->errors, 'errors');
163 }
164 }
165
166 // Bank account
167 if ($action == 'setbankaccount' && $permissiontoadd) {
168 $result = $object->setBankAccount(GETPOSTINT('fk_account'));
169 if ($result < 0) {
170 setEventMessages($object->error, $object->errors, 'errors');
171 }
172 }
173
174 // Delete social contribution
175 if ($action == 'confirm_delete' && $permissiontodelete && $confirm == 'yes') {
176 $totalpaid = $object->getSommePaiement();
177 if (empty($totalpaid)) {
178 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
179 $result = $object->delete($user);
180 if ($result > 0) {
181 header("Location: list.php");
182 exit;
183 } else {
184 setEventMessages($object->error, $object->errors, 'errors');
185 }
186 } else {
187 setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors');
188 }
189 }
190
191
192 // Add social contribution
193 if ($action == 'add' && $permissiontoadd) {
194 $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
195
196 if (!$dateech) {
197 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
198 $action = 'create';
199 } elseif (!$dateperiod) {
200 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
201 $action = 'create';
202 } elseif (!($actioncode > 0)) {
203 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors');
204 $action = 'create';
205 } elseif (empty($amount)) {
206 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
207 $action = 'create';
208 } elseif (!is_numeric($amount)) {
209 setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
210 $action = 'create';
211 } else {
212 $object->type = $actioncode;
213 $object->label = GETPOST('label', 'alpha');
214 $object->date_ech = $dateech;
215 $object->periode = $dateperiod;
216 $object->period = $dateperiod;
217 $object->amount = $amount;
218 $object->fk_user = $fk_user;
219 $object->mode_reglement_id = GETPOSTINT('mode_reglement_id');
220 $object->fk_account = GETPOSTINT('fk_account');
221 $object->fk_project = GETPOSTINT('fk_project');
222 $object->paye = ChargeSociales::STATUS_UNPAID;
223
224 $id = $object->create($user);
225 if ($id <= 0) {
226 setEventMessages($object->error, $object->errors, 'errors');
227 $action = 'create';
228 } else {
229 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
230 exit;
231 }
232 }
233 }
234
235 if ($action == 'update' && !$cancel && $permissiontoadd) {
236 $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
237
238 if (!$dateech) {
239 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
240 $action = 'edit';
241 } elseif (!$dateperiod) {
242 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
243 $action = 'edit';
244 } elseif (empty($amount)) {
245 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
246 $action = 'edit';
247 } elseif (!is_numeric($amount)) {
248 setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
249 $action = 'create';
250 } else {
251 $result = $object->fetch($id);
252
253 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
254
255 $object->type = $actioncode;
256 $object->date_ech = $dateech;
257 $object->period = $dateperiod;
258 $object->periode = $dateperiod;
259 $object->amount = $amount;
260 // $object->fk_user = $fk_user;
261
262 $result = $object->update($user);
263 if ($result <= 0) {
264 setEventMessages($object->error, $object->errors, 'errors');
265 } else {
266 // Reload object to get new value of some properties
267 if ($object->oldcopy->type != $object->type) {
268 $object->fetch($id);
269 }
270 }
271 }
272 }
273
274 // Action clone object
275 if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required here
276 $action = '';
277 }
278
279 if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
280 $db->begin();
281
282 $originalId = $object->id;
283
284 if ($object->id > 0) {
285 $object->id = 0;
286 $object->ref = '';
287 $object->paye = 0;
288 if (GETPOST('amount', 'alphanohtml')) {
289 $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
290 }
291
292 if (GETPOST('clone_label', 'alphanohtml')) {
293 $object->label = GETPOST('clone_label', 'alphanohtml');
294 } else {
295 $object->label = $langs->trans("CopyOf").' '.$object->label;
296 }
297
298 if (GETPOSTINT('clone_for_next_month')) { // This can be true only if TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX has been set
299 $object->period = dol_time_plus_duree($object->period, 1, 'm');
300 $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm');
301 } else {
302 // Note date_ech is often a little bit higher than dateperiod
303 $newdateech = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_echmonth'), GETPOSTINT('clone_date_echday'), GETPOSTINT('clone_date_echyear')); // = date of creation or due date
304 $newdateperiod = dol_mktime(0, 0, 0, GETPOSTINT('clone_periodmonth'), GETPOSTINT('clone_periodday'), GETPOSTINT('clone_periodyear'));
305
306 if ($newdateperiod) {
307 $object->period = $newdateperiod;
308 if (empty($newdateech)) {
309 $object->date_ech = $object->period;
310 }
311 }
312 if ($newdateech) {
313 $object->date_ech = $newdateech;
314 if (empty($newdateperiod)) {
315 // TODO We can here get dol_get_last_day of previous month:
316 // $object->period = dol_get_last_day(year of $object->date_ech - 1m, month or $object->date_ech -1m)
317 $object->period = $object->date_ech;
318 }
319 }
320 }
321
322 $resultcheck = $object->check();
323 if ($resultcheck) {
324 $id = $object->create($user);
325 if ($id > 0) {
326 $db->commit();
327 $db->close();
328
329 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
330 exit;
331 } else {
332 $id = $originalId;
333 $db->rollback();
334
335 setEventMessages($object->error, $object->errors, 'errors');
336 }
337 }
338 } else {
339 $db->rollback();
340 dol_print_error($db, $object->error);
341 }
342 }
343
344 // Actions to build doc
345 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
346}
347
348
349/*
350 * View
351 */
352
353$form = new Form($db);
354$formfile = new FormFile($db);
355$formsocialcontrib = new FormSocialContrib($db);
356$bankaccountstatic = new Account($db);
357if (isModEnabled('project')) {
358 $formproject = new FormProjets($db);
359}
360
361$title = $langs->trans("SocialContribution").' - '.$langs->trans("Card");
362$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)';
363llxHeader("", $title, $help_url);
364
365$resteapayer = 0;
366
367
368// Form to create a social contribution
369if ($action == 'create') {
370 print load_fiche_titre($langs->trans("NewSocialContribution"));
371
372 print '<form name="charge" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
373 print '<input type="hidden" name="token" value="'.newToken().'">';
374 print '<input type="hidden" name="action" value="add">';
375
376 print dol_get_fiche_head();
377
378 print '<table class="border centpercent tableforfieldcreate">';
379
380 // Label
381 print "<tr>";
382 print '<td class="titlefieldcreate fieldrequired">';
383 print $langs->trans("Label");
384 print '</td>';
385 print '<td><input type="text" name="label" class="flat minwidth300" value="'.dol_escape_htmltag(GETPOST('label', 'alpha')).'" autofocus></td>';
386 print '</tr>';
387 print '<tr>';
388
389 // Type
390 print '<td class="fieldrequired">';
391 print $langs->trans("Type");
392 print '</td>';
393 print '<td>';
394 $formsocialcontrib->select_type_socialcontrib(GETPOST('actioncode', 'alpha') ? GETPOSTINT('actioncode') : 0, 'actioncode', 1);
395 print '</td>';
396 print '</tr>';
397
398 // Date
399 print '<tr>';
400 print '<td class="fieldrequired">';
401 print $langs->trans("Date");
402 print '</td>';
403 print '<td>';
404 print $form->selectDate(!empty($dateech) ? $dateech : '-1', 'ech', 0, 0, 0, 'charge', 1, 1);
405 print '</td>';
406 print "</tr>\n";
407
408 // Date end period
409 print '<tr>';
410 print '<td class="fieldrequired">';
411 print $form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"));
412 print '</td>';
413 print '<td>';
414 print $form->selectDate(!empty($dateperiod) ? $dateperiod : '-1', 'period', 0, 0, 0, 'charge', 1);
415 print '</td>';
416 print '</tr>';
417
418 // Amount
419 print '<tr>';
420 print '<td class="fieldrequired">';
421 print $langs->trans("Amount");
422 print '</td>';
423 print '<td><input type="text" size="6" name="amount" class="flat" value="'.dol_escape_htmltag(GETPOST('amount', 'alpha')).'"></td>';
424 print '</tr>';
425
426 // Employee
427 print '<tr><td>';
428 print $langs->trans('Employee');
429 print '</td>';
430 print '<td>'.img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers('', 'userid', 1).'</td></tr>';
431
432 // Project
433 if (isModEnabled('project')) {
434 $formproject = new FormProjets($db);
435
436 // Associated project
437 $langs->load("projects");
438
439 print '<tr><td>'.$langs->trans("Project").'</td><td>';
440
441 print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(-1, (string) $fk_project, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
442
443 print '</td></tr>';
444 }
445
446 // Payment Mode
447 print '<tr><td>'.$langs->trans('DefaultPaymentMode').'</td><td colspan="2">';
448 $form->select_types_paiements((string) GETPOSTINT('mode_reglement_id'), 'mode_reglement_id');
449 print '</td></tr>';
450
451 // Bank Account
452 if (isModEnabled("bank")) {
453 print '<tr><td>'.$langs->trans('DefaultBankAccount').'</td><td colspan="2">';
454 print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes(GETPOSTINT('fk_account'), 'fk_account', 0, '', 2, '', 0, '', 1);
455 print '</td></tr>';
456 }
457
458 print '</table>';
459
460 print dol_get_fiche_end();
461
462 print '<div class="center">';
463 print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
464 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
465 print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="history.go(-1)">';
466 print '</div>';
467
468 print '</form>';
469}
470
471// View mode
472if ($id > 0) {
473 $formconfirm = '';
474
475 if ($result > 0) {
476 $head = tax_prepare_head($object);
477
478 $totalpaid = $object->getSommePaiement();
479
480 // Clone confirmation
481 if ($action === 'clone') {
482 $formquestion = array(
483 array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label, 'tdclass' => 'fieldrequired'),
484 );
485 if (getDolGlobalString('TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX')) {
486 $formquestion[] = array('type' => 'checkbox', 'name' => 'clone_for_next_month', 'label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1);
487 } else {
488 $formquestion[] = array('type' => 'date', 'datenow' => 1, 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
489 $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
490 $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100');
491 }
492
493 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneTax', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 0);
494 }
495
496
497 if ($action == 'paid') {
498 $text = $langs->trans('ConfirmPaySocialContribution');
499 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySocialContribution'), $text, "confirm_paid", '', '', 2);
500 }
501
502 // Confirmation of the removal of the Social Contribution
503 if ($action == 'delete') {
504 $text = $langs->trans('ConfirmDeleteSocialContribution');
505 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSocialContribution'), $text, 'confirm_delete', '', '', 2);
506 }
507
508 if ($action == 'edit') {
509 print '<form name="charge" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
510 print '<input type="hidden" name="token" value="'.newToken().'">';
511 print '<input type="hidden" name="action" value="update">';
512 }
513 // Call Hook formConfirm
514 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
515 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
516 if (empty($reshook)) {
517 $formconfirm .= $hookmanager->resPrint;
518 } elseif ($reshook > 0) {
519 $formconfirm = $hookmanager->resPrint;
520 }
521
522
523 print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, $object->picto, 0, '', '', 0, '', ($action == 'edit' ? 0 : 1));
524
525 // Print form confirm
526 print $formconfirm;
527
528
529 // Social contribution card
530 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
531
532 $morehtmlref = '<div class="refidno">';
533 // Ref customer
534 $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->hasRight('tax', 'charges', 'creer'), 'string', '', 0, 1);
535 $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->hasRight('tax', 'charges', 'creer'), 'string', '', null, null, '', 1);
536
537 // Employee
538 if ($action != 'editfk_user') {
539 if ($object->getSommePaiement() > 0 && $object->fk_user > 0) {
540 $userstatic = new User($db);
541 $result = $userstatic->fetch($object->fk_user);
542 if ($result > 0) {
543 $morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(-1);
544 }
545 } else {
546 $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->hasRight('salaries', 'write'), 'string', '', 0, 1);
547 if ($object->fk_user > 0) {
548 $userstatic = new User($db);
549 $result = $userstatic->fetch($object->fk_user);
550 if ($result > 0) {
551 $morehtmlref .= $userstatic->getNomUrl(-1);
552 } else {
553 dol_print_error($db);
554 exit();
555 }
556 }
557 }
558 } else {
559 $morehtmlref .= '<br>'.$langs->trans('Employee').' :&nbsp;';
560 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
561 $morehtmlref .= '<input type="hidden" name="action" value="setfk_user">';
562 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
563 $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1);
564 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
565 $morehtmlref .= '</form>';
566 }
567
568 // Project
569 if (isModEnabled('project')) {
570 $langs->load("projects");
571 $morehtmlref .= '<br>';
572 if ($permissiontoadd) {
573 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
574 if ($action != 'classify') {
575 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.((int) $object->id).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
576 }
577 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, -1, (string) $object->fk_project, ($action == 'classify' ? 'fk_project' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
578 } else {
579 if (!empty($object->fk_project)) {
580 $proj = new Project($db);
581 $proj->fetch($object->fk_project);
582 $morehtmlref .= $proj->getNomUrl(1);
583 if ($proj->title) {
584 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
585 }
586 }
587 }
588 }
589 $morehtmlref .= '</div>';
590
591 $morehtmlright = '';
592
593 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
594
595 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '', 0, $morehtmlright);
596
597 print '<div class="fichecenter">';
598 print '<div class="fichehalfleft">';
599 print '<div class="underbanner clearboth"></div>';
600
601 print '<table class="border centpercent tableforfield">';
602
603 // Type
604 print '<tr><td class="titlefield">';
605 print $langs->trans("Type")."</td><td>";
606 if ($action == 'edit' && $object->getSommePaiement() == 0) {
607 $actionPostValue = GETPOSTINT('actioncode');
608 $formsocialcontrib->select_type_socialcontrib($actionPostValue ? $actionPostValue : $object->type, 'actioncode', 1);
609 } else {
610 print $object->type_label;
611 if (isModEnabled("accounting")) {
612 print ' &nbsp; <pan class="opacitymedium">('.$langs->trans("AccountancyCode").': '.(empty($object->type_accountancy_code) ? $langs->trans("Unknown") : length_accountg($object->type_accountancy_code)).')</span>';
613 }
614 }
615 print "</td>";
616
617 print "</tr>";
618
619 // Date
620 if ($action == 'edit') {
621 print '<tr><td>'.$langs->trans("Date")."</td><td>";
622 print $form->selectDate($object->date_ech, 'ech', 0, 0, 0, 'charge', 1, 1);
623 print "</td></tr>";
624 } else {
625 print "<tr><td>".$langs->trans("Date")."</td><td>".dol_print_date($object->date_ech, 'day')."</td></tr>";
626 }
627
628 // Period end date
629 print "<tr><td>".$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"))."</td>";
630 print "<td>";
631 if ($action == 'edit') {
632 print $form->selectDate($object->period, 'period', 0, 0, 0, 'charge', 1);
633 } else {
634 print dol_print_date($object->period, "day");
635 }
636 print "</td></tr>";
637
638 // Amount
639 if ($action == 'edit') {
640 print '<tr><td>'.$langs->trans("AmountTTC")."</td><td>";
641 print '<input type="text" name="amount" size="12" class="flat" value="'.price($object->amount).'">';
642 print "</td></tr>";
643 } else {
644 print '<tr><td>'.$langs->trans("AmountTTC").'</td><td><span class="amount">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
645 }
646
647 // Mode of payment
648 print '<tr><td>';
649 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
650 print $langs->trans('DefaultPaymentMode');
651 print '</td>';
652 if ($action != 'editmode') {
653 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>';
654 }
655 print '</tr></table>';
656 print '</td><td>';
657 if ($action == 'editmode') {
658 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->mode_reglement_id, 'mode_reglement_id', '', 1, 1);
659 } else {
660 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->mode_reglement_id, 'none');
661 }
662 print '</td></tr>';
663
664 // Bank account
665 if (isModEnabled("bank")) {
666 print '<tr><td class="nowrap">';
667 print '<table class="centpercent nobordernopadding"><tr><td class="nowrap">';
668 print $langs->trans('DefaultBankAccount');
669 print '<td>';
670 if ($action != 'editbankaccount' && $user->hasRight('tax', 'charges', 'creer')) {
671 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>';
672 }
673 print '</tr></table>';
674 print '</td><td>';
675 if ($action == 'editbankaccount') {
676 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'fk_account', 1);
677 } else {
678 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'none');
679 }
680 print '</td>';
681 print '</tr>';
682 }
683
684 // Other attributes
685 $parameters = array();
686 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
687 print $hookmanager->resPrint;
688
689 print '</table>';
690
691 print '</div>';
692 print '<div class="fichehalfright">';
693
694 print '<div class="underbanner clearboth"></div>';
695
696 $nbcols = 3;
697 if (isModEnabled("bank")) {
698 $nbcols++;
699 }
700
701 /*
702 * Payments
703 */
704 $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,";
705 $sql .= " c.code as type_code,c.libelle as paiement_type,";
706 $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';
707 $sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
708 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
709 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
710 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
711 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
712 $sql .= " WHERE p.fk_charge = ".((int) $id);
713 $sql .= " AND p.fk_charge = cs.rowid";
714 $sql .= " AND cs.entity IN (".getEntity('sc').")";
715 $sql .= " ORDER BY dp DESC";
716
717 //print $sql;
718 $resql = $db->query($sql);
719 if ($resql) {
720 $totalpaid = 0;
721
722 $num = $db->num_rows($resql);
723 $i = 0;
724
725 print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
726 print '<table class="noborder paymenttable">';
727 print '<tr class="liste_titre">';
728 print '<td>'.$langs->trans("RefPayment").'</td>';
729 print '<td>'.$langs->trans("Date").'</td>';
730 print '<td>'.$langs->trans("Type").'</td>';
731 if (isModEnabled("bank")) {
732 print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
733 }
734 print '<td class="right">'.$langs->trans("Amount").'</td>';
735 print '</tr>';
736
737 $paymentsocialcontributiontmp = new PaymentSocialContribution($db);
738
739 if ($num > 0) {
740 while ($i < $num) {
741 $objp = $db->fetch_object($resql);
742
743 $paymentsocialcontributiontmp->id = $objp->rowid;
744 $paymentsocialcontributiontmp->ref = $objp->rowid;
745 $paymentsocialcontributiontmp->datep = $db->jdate($objp->dp);
746
747 print '<tr class="oddeven"><td>';
748 print $paymentsocialcontributiontmp->getNomUrl(1);
749 print '</td>';
750
751 print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
752 $labeltype = $langs->trans("PaymentType".$objp->type_code) != "PaymentType".$objp->type_code ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
753 print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
754 if (isModEnabled("bank")) {
755 $bankaccountstatic->id = $objp->baid;
756 $bankaccountstatic->ref = $objp->baref;
757 $bankaccountstatic->label = $objp->baref;
758 $bankaccountstatic->number = $objp->banumber;
759 $bankaccountstatic->currency_code = $objp->bacurrency_code;
760
761 if (isModEnabled('accounting')) {
762 $bankaccountstatic->account_number = $objp->account_number;
763
764 $accountingjournal = new AccountingJournal($db);
765 $accountingjournal->fetch($objp->fk_accountancy_journal);
766 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
767 }
768
769 print '<td class="right">';
770 if ($bankaccountstatic->id) {
771 print $bankaccountstatic->getNomUrl(1, 'transactions');
772 }
773 print '</td>';
774 }
775 print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
776 print "</tr>";
777 $totalpaid += $objp->amount;
778 $i++;
779 }
780 } else {
781 print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
782 print '<td></td><td></td><td></td><td></td>';
783 print '</tr>';
784 }
785
786 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="right nowraponall">'.price($totalpaid)."</td></tr>\n";
787 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").' :</td><td class="right nowraponall">'.price($object->amount)."</td></tr>\n";
788
789 $resteapayer = $object->amount - $totalpaid;
790 $cssforamountpaymentcomplete = 'amountpaymentcomplete';
791
792 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
793 print '<td class="right nowraponall'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
794
795 print "</table>";
796 print '</div>';
797
798 $db->free($resql);
799 } else {
800 dol_print_error($db);
801 }
802
803 print '</div>';
804 print '</div>';
805
806 print '<div class="clearboth"></div>';
807
808 print dol_get_fiche_end();
809
810 if ($action == 'edit') {
811 print $form->buttonsSaveCancel();
812
813 print "</form>\n";
814 }
815
816
817
818 // Buttons for actions
819
820 if ($action != 'edit') {
821 print '<div class="tabsAction">'."\n";
822
823 // Reopen
824 if ($object->paye && $user->hasRight('tax', 'charges', 'creer')) {
825 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>';
826 }
827
828 // Edit
829 if ($object->paye == 0 && $user->hasRight('tax', 'charges', 'creer')) {
830 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>';
831 }
832
833 // Emit payment
834 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')) {
835 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>";
836 }
837
838 // Classify 'paid'
839 if ($object->paye == 0 && round($resteapayer) <= 0 && $user->hasRight('tax', 'charges', 'creer')) {
840 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>';
841 }
842
843 // Clone
844 if ($user->hasRight('tax', 'charges', 'creer')) {
845 print '<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans("ToClone"), $langs->trans("ToClone"), 'clone', DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=clone&token='.newToken(), '', true, array('attr' => array('class' => 'reposition'))).'</div>';
846 }
847
848 // Delete
849 if ($user->hasRight('tax', 'charges', 'supprimer') && empty($totalpaid)) {
850 print '<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id.'&action=delete&token='.newToken(), '', true, array('attr' => array('class' => 'reposition'))).'</div>'."\n";
851 } else {
852 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("DisabledBecausePayments"))).'">'.$langs->trans("Delete").'</a></div>';
853 }
854
855 print "</div>";
856 }
857
858
859 // Select mail models is same action as presend
860 if (GETPOST('modelselected')) {
861 $action = 'presend';
862 }
863
864 if ($action != 'edit' && $action != 'presend') {
865 print '<div class="fichecenter"><div class="fichehalfleft">';
866 print '<a name="builddoc"></a>'; // ancre
867
868 $includedocgeneration = 1;
869
870 // Documents
871 if ($includedocgeneration) {
872 $objref = dol_sanitizeFileName($object->ref);
873 $relativepath = $objref.'/'.$objref.'.pdf';
874 $filedir = $conf->tax->dir_output.'/'.$objref;
875 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
876 $genallowed = 0;
877 $delallowed = $user->hasRight('tax', 'charges', 'creer'); // If you can create/edit, you can remove a file on card
878 print $formfile->showdocuments('tax', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
879 }
880
881 // Show links to link elements
882 //$tmparray = $form->showLinkToObjectBlock($object, null, array('myobject'), 1);
883 //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
884
885
886 print '</div><div class="fichehalfright">';
887
888 /*
889 $MAXEVENT = 10;
890
891 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
892
893 // List of actions on element
894 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
895 $formactions = new FormActions($db);
896 $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
897 */
898
899 print '</div></div>';
900 }
901
902 //Select mail models is same action as presend
903 if (GETPOST('modelselected')) {
904 $action = 'presend';
905 }
906
907 // Presend form
908 $modelmail = 'sc';
909 $defaulttopic = 'InformationMessage';
910 $diroutput = $conf->tax->dir_output;
911 $trackid = 'sc'.$object->id;
912
913 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
914 } else {
915 /* Social contribution not found */
916 dol_print_error(null, $object->error);
917 }
918}
919
920// End of page
921llxFooter();
922$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
length_accountg($account)
Return General accounting account with defined length (used for product and miscellaneous)
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
Definition propal.php:281
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage accounting journals.
Class for managing the social charges.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class to manage generation of HTML components for social contributions management.
Class to manage payments of social contributions.
Class to manage projects.
Class to manage Dolibarr users.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
Definition date.lib.php:127
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
tax_prepare_head(ChargeSociales $object)
Prepare array with list of tabs.
Definition tax.lib.php:44