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