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 }
229 }
230 }
231
232 if ($action == 'update' && !$cancel && $permissiontoadd) {
233 $amount = price2num(GETPOST('amount', 'alpha'), 'MT');
234
235 if (!$dateech) {
236 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
237 $action = 'edit';
238 } elseif (!$dateperiod) {
239 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors');
240 $action = 'edit';
241 } elseif (empty($amount)) {
242 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
243 $action = 'edit';
244 } elseif (!is_numeric($amount)) {
245 setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors');
246 $action = 'create';
247 } else {
248 $result = $object->fetch($id);
249
250 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
251
252 $object->type = $actioncode;
253 $object->date_ech = $dateech;
254 $object->period = $dateperiod;
255 $object->periode = $dateperiod;
256 $object->amount = $amount;
257 // $object->fk_user = $fk_user;
258
259 $result = $object->update($user);
260 if ($result <= 0) {
261 setEventMessages($object->error, $object->errors, 'errors');
262 } else {
263 // Reload object to get new value of some properties
264 if ($object->oldcopy->type != $object->type) {
265 $object->fetch($id);
266 }
267 }
268 }
269 }
270
271 // Action clone object
272 if ($action == 'confirm_clone' && $confirm != 'yes') { // Test on permission not required here
273 $action = '';
274 }
275
276 if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
277 $db->begin();
278
279 $originalId = $object->id;
280
281 if ($object->id > 0) {
282 $object->id = 0;
283 $object->ref = '';
284 $object->paye = 0;
285 if (GETPOST('amount', 'alphanohtml')) {
286 $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2);
287 }
288
289 if (GETPOST('clone_label', 'alphanohtml')) {
290 $object->label = GETPOST('clone_label', 'alphanohtml');
291 } else {
292 $object->label = $langs->trans("CopyOf").' '.$object->label;
293 }
294
295 if (GETPOSTINT('clone_for_next_month')) { // This can be true only if TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX has been set
296 $object->period = dol_time_plus_duree($object->period, 1, 'm');
297 $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm');
298 } else {
299 // Note date_ech is often a little bit higher than dateperiod
300 $newdateech = dol_mktime(0, 0, 0, GETPOSTINT('clone_date_echmonth'), GETPOSTINT('clone_date_echday'), GETPOSTINT('clone_date_echyear')); // = date of creation or due date
301 $newdateperiod = dol_mktime(0, 0, 0, GETPOSTINT('clone_periodmonth'), GETPOSTINT('clone_periodday'), GETPOSTINT('clone_periodyear'));
302
303 if ($newdateperiod) {
304 $object->period = $newdateperiod;
305 if (empty($newdateech)) {
306 $object->date_ech = $object->period;
307 }
308 }
309 if ($newdateech) {
310 $object->date_ech = $newdateech;
311 if (empty($newdateperiod)) {
312 // TODO We can here get dol_get_last_day of previous month:
313 // $object->period = dol_get_last_day(year of $object->date_ech - 1m, month or $object->date_ech -1m)
314 $object->period = $object->date_ech;
315 }
316 }
317 }
318
319 $resultcheck = $object->check();
320 if ($resultcheck) {
321 $id = $object->create($user);
322 if ($id > 0) {
323 $db->commit();
324 $db->close();
325
326 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
327 exit;
328 } else {
329 $id = $originalId;
330 $db->rollback();
331
332 setEventMessages($object->error, $object->errors, 'errors');
333 }
334 }
335 } else {
336 $db->rollback();
337 dol_print_error($db, $object->error);
338 }
339 }
340
341 // Actions to build doc
342 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
343}
344
345
346/*
347 * View
348 */
349
350$form = new Form($db);
351$formfile = new FormFile($db);
352$formsocialcontrib = new FormSocialContrib($db);
353$bankaccountstatic = new Account($db);
354if (isModEnabled('project')) {
355 $formproject = new FormProjets($db);
356}
357
358$title = $langs->trans("SocialContribution").' - '.$langs->trans("Card");
359$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)';
360llxHeader("", $title, $help_url);
361
362$resteapayer = 0;
363
364
365// Form to create a social contribution
366if ($action == 'create') {
367 print load_fiche_titre($langs->trans("NewSocialContribution"));
368
369 print '<form name="charge" method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
370 print '<input type="hidden" name="token" value="'.newToken().'">';
371 print '<input type="hidden" name="action" value="add">';
372
373 print dol_get_fiche_head();
374
375 print '<table class="border centpercent tableforfieldcreate">';
376
377 // Label
378 print "<tr>";
379 print '<td class="titlefieldcreate fieldrequired">';
380 print $langs->trans("Label");
381 print '</td>';
382 print '<td><input type="text" name="label" class="flat minwidth300" value="'.dol_escape_htmltag(GETPOST('label', 'alpha')).'" autofocus></td>';
383 print '</tr>';
384 print '<tr>';
385
386 // Type
387 print '<td class="fieldrequired">';
388 print $langs->trans("Type");
389 print '</td>';
390 print '<td>';
391 $formsocialcontrib->select_type_socialcontrib(GETPOST('actioncode', 'alpha') ? GETPOSTINT('actioncode') : 0, 'actioncode', 1);
392 print '</td>';
393 print '</tr>';
394
395 // Date
396 print '<tr>';
397 print '<td class="fieldrequired">';
398 print $langs->trans("Date");
399 print '</td>';
400 print '<td>';
401 print $form->selectDate(!empty($dateech) ? $dateech : '-1', 'ech', 0, 0, 0, 'charge', 1, 1);
402 print '</td>';
403 print "</tr>\n";
404
405 // Date end period
406 print '<tr>';
407 print '<td class="fieldrequired">';
408 print $form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"));
409 print '</td>';
410 print '<td>';
411 print $form->selectDate(!empty($dateperiod) ? $dateperiod : '-1', 'period', 0, 0, 0, 'charge', 1);
412 print '</td>';
413 print '</tr>';
414
415 // Amount
416 print '<tr>';
417 print '<td class="fieldrequired">';
418 print $langs->trans("Amount");
419 print '</td>';
420 print '<td><input type="text" size="6" name="amount" class="flat" value="'.dol_escape_htmltag(GETPOST('amount', 'alpha')).'"></td>';
421 print '</tr>';
422
423 // Employee
424 print '<tr><td>';
425 print $langs->trans('Employee');
426 print '</td>';
427 print '<td>'.img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers('', 'userid', 1).'</td></tr>';
428
429 // Project
430 if (isModEnabled('project')) {
431 $formproject = new FormProjets($db);
432
433 // Associated project
434 $langs->load("projects");
435
436 print '<tr><td>'.$langs->trans("Project").'</td><td>';
437
438 print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects(-1, (string) $fk_project, 'fk_project', 0, 0, 1, 1, 0, 0, 0, '', 1);
439
440 print '</td></tr>';
441 }
442
443 // Payment Mode
444 print '<tr><td>'.$langs->trans('DefaultPaymentMode').'</td><td colspan="2">';
445 $form->select_types_paiements((string) GETPOSTINT('mode_reglement_id'), 'mode_reglement_id');
446 print '</td></tr>';
447
448 // Bank Account
449 if (isModEnabled("bank")) {
450 print '<tr><td>'.$langs->trans('DefaultBankAccount').'</td><td colspan="2">';
451 print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes(GETPOSTINT('fk_account'), 'fk_account', 0, '', 2, '', 0, '', 1);
452 print '</td></tr>';
453 }
454
455 print '</table>';
456
457 print dol_get_fiche_end();
458
459 print '<div class="center">';
460 print '<input type="submit" class="button button-add" value="'.$langs->trans("Add").'">';
461 print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
462 print '<input type="button" class="button button-cancel" value="'.$langs->trans("Cancel").'" onClick="history.go(-1)">';
463 print '</div>';
464
465 print '</form>';
466}
467
468// View mode
469if ($id > 0) {
470 $formconfirm = '';
471
472 if ($result > 0) {
473 $head = tax_prepare_head($object);
474
475 $totalpaid = $object->getSommePaiement();
476
477 // Clone confirmation
478 if ($action === 'clone') {
479 $formquestion = array(
480 array('type' => 'text', 'name' => 'clone_label', 'label' => $langs->trans("Label"), 'value' => $langs->trans("CopyOf").' '.$object->label, 'tdclass' => 'fieldrequired'),
481 );
482 if (getDolGlobalString('TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX')) {
483 $formquestion[] = array('type' => 'checkbox', 'name' => 'clone_for_next_month', 'label' => $langs->trans("CloneTaxForNextMonth"), 'value' => 1);
484 } else {
485 $formquestion[] = array('type' => 'date', 'datenow' => 1, 'name' => 'clone_date_ech', 'label' => $langs->trans("Date"), 'value' => -1);
486 $formquestion[] = array('type' => 'date', 'name' => 'clone_period', 'label' => $langs->trans("PeriodEndDate"), 'value' => -1);
487 $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100');
488 }
489
490 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneTax', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 0);
491 }
492
493
494 if ($action == 'paid') {
495 $text = $langs->trans('ConfirmPaySocialContribution');
496 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySocialContribution'), $text, "confirm_paid", '', '', 2);
497 }
498
499 // Confirmation of the removal of the Social Contribution
500 if ($action == 'delete') {
501 $text = $langs->trans('ConfirmDeleteSocialContribution');
502 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSocialContribution'), $text, 'confirm_delete', '', '', 2);
503 }
504
505 if ($action == 'edit') {
506 print '<form name="charge" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
507 print '<input type="hidden" name="token" value="'.newToken().'">';
508 print '<input type="hidden" name="action" value="update">';
509 }
510 // Call Hook formConfirm
511 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
512 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
513 if (empty($reshook)) {
514 $formconfirm .= $hookmanager->resPrint;
515 } elseif ($reshook > 0) {
516 $formconfirm = $hookmanager->resPrint;
517 }
518
519
520 print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, $object->picto, 0, '', '', 0, '', ($action == 'edit' ? 0 : 1));
521
522 // Print form confirm
523 print $formconfirm;
524
525
526 // Social contribution card
527 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/sociales/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
528
529 $morehtmlref = '<div class="refidno">';
530 // Ref customer
531 $morehtmlref .= $form->editfieldkey("Label", 'lib', $object->label, $object, $user->hasRight('tax', 'charges', 'creer'), 'string', '', 0, 1);
532 $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $user->hasRight('tax', 'charges', 'creer'), 'string', '', null, null, '', 1);
533
534 // Employee
535 if ($action != 'editfk_user') {
536 if ($object->getSommePaiement() > 0 && $object->fk_user > 0) {
537 $userstatic = new User($db);
538 $result = $userstatic->fetch($object->fk_user);
539 if ($result > 0) {
540 $morehtmlref .= '<br>' .$langs->trans('Employee').' : '.$userstatic->getNomUrl(1);
541 }
542 } else {
543 $morehtmlref .= '<br>' . $form->editfieldkey("Employee", 'fk_user', $object->label, $object, $user->hasRight('salaries', 'write'), 'string', '', 0, 1);
544 if ($object->fk_user > 0) {
545 $userstatic = new User($db);
546 $result = $userstatic->fetch($object->fk_user);
547 if ($result > 0) {
548 $morehtmlref .= $userstatic->getNomUrl(1);
549 } else {
550 dol_print_error($db);
551 exit();
552 }
553 }
554 }
555 } else {
556 $morehtmlref .= '<br>'.$langs->trans('Employee').' :&nbsp;';
557 $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
558 $morehtmlref .= '<input type="hidden" name="action" value="setfk_user">';
559 $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
560 $morehtmlref .= $form->select_dolusers($object->fk_user, 'userid', 1);
561 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
562 $morehtmlref .= '</form>';
563 }
564
565 // Project
566 if (isModEnabled('project')) {
567 $langs->load("projects");
568 $morehtmlref .= '<br>';
569 if ($permissiontoadd) {
570 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
571 if ($action != 'classify') {
572 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.((int) $object->id).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
573 }
574 $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');
575 } else {
576 if (!empty($object->fk_project)) {
577 $proj = new Project($db);
578 $proj->fetch($object->fk_project);
579 $morehtmlref .= $proj->getNomUrl(1);
580 if ($proj->title) {
581 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
582 }
583 }
584 }
585 }
586 $morehtmlref .= '</div>';
587
588 $morehtmlright = '';
589
590 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
591
592 dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', '', 0, $morehtmlright);
593
594 print '<div class="fichecenter">';
595 print '<div class="fichehalfleft">';
596 print '<div class="underbanner clearboth"></div>';
597
598 print '<table class="border centpercent tableforfield">';
599
600 // Type
601 print '<tr><td class="titlefield">';
602 print $langs->trans("Type")."</td><td>";
603 if ($action == 'edit' && $object->getSommePaiement() == 0) {
604 $actionPostValue = GETPOSTINT('actioncode');
605 $formsocialcontrib->select_type_socialcontrib($actionPostValue ? $actionPostValue : $object->type, 'actioncode', 1);
606 } else {
607 print $object->type_label;
608 if (isModEnabled("accounting")) {
609 print ' &nbsp; <pan class="opacitymedium">('.$langs->trans("AccountancyCode").': '.(empty($object->type_accountancy_code) ? $langs->trans("Unknown") : length_accountg($object->type_accountancy_code)).')</span>';
610 }
611 }
612 print "</td>";
613
614 print "</tr>";
615
616 // Date
617 if ($action == 'edit') {
618 print '<tr><td>'.$langs->trans("Date")."</td><td>";
619 print $form->selectDate($object->date_ech, 'ech', 0, 0, 0, 'charge', 1, 1);
620 print "</td></tr>";
621 } else {
622 print "<tr><td>".$langs->trans("Date")."</td><td>".dol_print_date($object->date_ech, 'day')."</td></tr>";
623 }
624
625 // Period end date
626 print "<tr><td>".$form->textwithpicto($langs->trans("PeriodEndDate"), $langs->trans("LastDayTaxIsRelatedTo"))."</td>";
627 print "<td>";
628 if ($action == 'edit') {
629 print $form->selectDate($object->period, 'period', 0, 0, 0, 'charge', 1);
630 } else {
631 print dol_print_date($object->period, "day");
632 }
633 print "</td></tr>";
634
635 // Amount
636 if ($action == 'edit') {
637 print '<tr><td>'.$langs->trans("AmountTTC")."</td><td>";
638 print '<input type="text" name="amount" size="12" class="flat" value="'.price($object->amount).'">';
639 print "</td></tr>";
640 } else {
641 print '<tr><td>'.$langs->trans("AmountTTC").'</td><td><span class="amount">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</span></td></tr>';
642 }
643
644 // Mode of payment
645 print '<tr><td>';
646 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
647 print $langs->trans('DefaultPaymentMode');
648 print '</td>';
649 if ($action != 'editmode') {
650 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>';
651 }
652 print '</tr></table>';
653 print '</td><td>';
654 if ($action == 'editmode') {
655 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->mode_reglement_id, 'mode_reglement_id', '', 1, 1);
656 } else {
657 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->mode_reglement_id, 'none');
658 }
659 print '</td></tr>';
660
661 // Bank account
662 if (isModEnabled("bank")) {
663 print '<tr><td class="nowrap">';
664 print '<table class="centpercent nobordernopadding"><tr><td class="nowrap">';
665 print $langs->trans('DefaultBankAccount');
666 print '<td>';
667 if ($action != 'editbankaccount' && $user->hasRight('tax', 'charges', 'creer')) {
668 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>';
669 }
670 print '</tr></table>';
671 print '</td><td>';
672 if ($action == 'editbankaccount') {
673 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'fk_account', 1);
674 } else {
675 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'none');
676 }
677 print '</td>';
678 print '</tr>';
679 }
680
681 // Other attributes
682 $parameters = array();
683 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
684 print $hookmanager->resPrint;
685
686 print '</table>';
687
688 print '</div>';
689 print '<div class="fichehalfright">';
690
691 print '<div class="underbanner clearboth"></div>';
692
693 $nbcols = 3;
694 if (isModEnabled("bank")) {
695 $nbcols++;
696 }
697
698 /*
699 * Payments
700 */
701 $sql = "SELECT p.rowid, p.num_paiement as num_payment, p.datep as dp, p.amount,";
702 $sql .= " c.code as type_code,c.libelle as paiement_type,";
703 $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';
704 $sql .= " FROM ".MAIN_DB_PREFIX."paiementcharge as p";
705 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
706 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
707 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepaiement = c.id";
708 $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs";
709 $sql .= " WHERE p.fk_charge = ".((int) $id);
710 $sql .= " AND p.fk_charge = cs.rowid";
711 $sql .= " AND cs.entity IN (".getEntity('sc').")";
712 $sql .= " ORDER BY dp DESC";
713
714 //print $sql;
715 $resql = $db->query($sql);
716 if ($resql) {
717 $totalpaid = 0;
718
719 $num = $db->num_rows($resql);
720 $i = 0;
721
722 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
723 print '<table class="noborder paymenttable">';
724 print '<tr class="liste_titre">';
725 print '<td>'.$langs->trans("RefPayment").'</td>';
726 print '<td>'.$langs->trans("Date").'</td>';
727 print '<td>'.$langs->trans("Type").'</td>';
728 if (isModEnabled("bank")) {
729 print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
730 }
731 print '<td class="right">'.$langs->trans("Amount").'</td>';
732 print '</tr>';
733
734 $paymentsocialcontributiontmp = new PaymentSocialContribution($db);
735
736 if ($num > 0) {
737 while ($i < $num) {
738 $objp = $db->fetch_object($resql);
739
740 $paymentsocialcontributiontmp->id = $objp->rowid;
741 $paymentsocialcontributiontmp->ref = $objp->rowid;
742 $paymentsocialcontributiontmp->datep = $db->jdate($objp->dp);
743
744 print '<tr class="oddeven"><td>';
745 print $paymentsocialcontributiontmp->getNomUrl(1);
746 print '</td>';
747
748 print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
749 $labeltype = $langs->trans("PaymentType".$objp->type_code) != "PaymentType".$objp->type_code ? $langs->trans("PaymentType".$objp->type_code) : $objp->paiement_type;
750 print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
751 if (isModEnabled("bank")) {
752 $bankaccountstatic->id = $objp->baid;
753 $bankaccountstatic->ref = $objp->baref;
754 $bankaccountstatic->label = $objp->baref;
755 $bankaccountstatic->number = $objp->banumber;
756 $bankaccountstatic->currency_code = $objp->bacurrency_code;
757
758 if (isModEnabled('accounting')) {
759 $bankaccountstatic->account_number = $objp->account_number;
760
761 $accountingjournal = new AccountingJournal($db);
762 $accountingjournal->fetch($objp->fk_accountancy_journal);
763 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
764 }
765
766 print '<td class="right">';
767 if ($bankaccountstatic->id) {
768 print $bankaccountstatic->getNomUrl(1, 'transactions');
769 }
770 print '</td>';
771 }
772 print '<td class="right"><span class="amount">'.price($objp->amount)."</span></td>\n";
773 print "</tr>";
774 $totalpaid += $objp->amount;
775 $i++;
776 }
777 } else {
778 print '<tr class="oddeven"><td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
779 print '<td></td><td></td><td></td><td></td>';
780 print '</tr>';
781 }
782
783 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").' :</td><td class="right nowraponall">'.price($totalpaid)."</td></tr>\n";
784 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").' :</td><td class="right nowraponall">'.price($object->amount)."</td></tr>\n";
785
786 $resteapayer = $object->amount - $totalpaid;
787 $cssforamountpaymentcomplete = 'amountpaymentcomplete';
788
789 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay")." :</td>";
790 print '<td class="right nowraponall'.($resteapayer ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayer)."</td></tr>\n";
791
792 print "</table>";
793 print '</div>';
794
795 $db->free($resql);
796 } else {
797 dol_print_error($db);
798 }
799
800 print '</div>';
801 print '</div>';
802
803 print '<div class="clearboth"></div>';
804
805 print dol_get_fiche_end();
806
807 if ($action == 'edit') {
808 print $form->buttonsSaveCancel();
809
810 print "</form>\n";
811 }
812
813
814
815 // Buttons for actions
816
817 if ($action != 'edit') {
818 print '<div class="tabsAction">'."\n";
819
820 // Reopen
821 if ($object->paye && $user->hasRight('tax', 'charges', 'creer')) {
822 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>';
823 }
824
825 // Edit
826 if ($object->paye == 0 && $user->hasRight('tax', 'charges', 'creer')) {
827 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>';
828 }
829
830 // Emit payment
831 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')) {
832 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>";
833 }
834
835 // Classify 'paid'
836 if ($object->paye == 0 && round($resteapayer) <= 0 && $user->hasRight('tax', 'charges', 'creer')) {
837 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>';
838 }
839
840 // Clone
841 if ($user->hasRight('tax', 'charges', 'creer')) {
842 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>';
843 }
844
845 // Delete
846 if ($user->hasRight('tax', 'charges', 'supprimer') && empty($totalpaid)) {
847 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";
848 } else {
849 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.(dol_escape_htmltag($langs->trans("DisabledBecausePayments"))).'">'.$langs->trans("Delete").'</a></div>';
850 }
851
852 print "</div>";
853 }
854
855
856 // Select mail models is same action as presend
857 if (GETPOST('modelselected')) {
858 $action = 'presend';
859 }
860
861 if ($action != 'edit' && $action != 'presend') {
862 print '<div class="fichecenter"><div class="fichehalfleft">';
863 print '<a name="builddoc"></a>'; // ancre
864
865 $includedocgeneration = 1;
866
867 // Documents
868 if ($includedocgeneration) {
869 $objref = dol_sanitizeFileName($object->ref);
870 $relativepath = $objref.'/'.$objref.'.pdf';
871 $filedir = $conf->tax->dir_output.'/'.$objref;
872 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
873 $genallowed = 0;
874 $delallowed = $user->hasRight('tax', 'charges', 'creer'); // If you can create/edit, you can remove a file on card
875 print $formfile->showdocuments('tax', $objref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $langs->defaultlang);
876 }
877
878 // Show links to link elements
879 //$tmparray = $form->showLinkToObjectBlock($object, null, array('myobject'), 1);
880 //$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
881
882
883 print '</div><div class="fichehalfright">';
884
885 /*
886 $MAXEVENT = 10;
887
888 $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', dol_buildpath('/mymodule/myobject_agenda.php', 1).'?id='.$object->id);
889
890 // List of actions on element
891 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
892 $formactions = new FormActions($db);
893 $somethingshown = $formactions->showactions($object, $object->element.'@'.$object->module, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
894 */
895
896 print '</div></div>';
897 }
898
899 //Select mail models is same action as presend
900 if (GETPOST('modelselected')) {
901 $action = 'presend';
902 }
903
904 // Presend form
905 $modelmail = 'sc';
906 $defaulttopic = 'InformationMessage';
907 $diroutput = $conf->tax->dir_output;
908 $trackid = 'sc'.$object->id;
909
910 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
911 } else {
912 /* Social contribution not found */
913 dol_print_error(null, $object->error);
914 }
915}
916
917// End of page
918llxFooter();
919$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:280
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
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)
Add a delay to a date.
Definition date.lib.php:126
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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)
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:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
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