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