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