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