From f5d7ac2bc194d91281c3503f09620677022268a7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 2 May 2023 17:04:22 +0200 Subject: [PATCH] NEW Can upload a file with drag and drop on social contributions --- htdocs/compta/sociales/card.php | 459 ++++++++++++++-------------- htdocs/compta/sociales/document.php | 6 +- htdocs/compta/sociales/info.php | 6 +- htdocs/compta/sociales/note.php | 4 +- htdocs/fourn/facture/card.php | 5 +- 5 files changed, 240 insertions(+), 240 deletions(-) diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 4983236af4e..45d03f273c3 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -32,8 +32,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsocialcontrib.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/paymentsocialcontribution.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/tax.lib.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; if (isModEnabled('project')) { include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; @@ -108,224 +109,226 @@ if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } -// Classify paid -if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') { - $object->fetch($id); - $result = $object->setPaid($user); -} - -if ($action == 'reopen' && $user->rights->tax->charges->creer) { - $result = $object->fetch($id); - if ($object->paye) { - $result = $object->setUnpaid($user); - if ($result > 0) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit(); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } +if (empty($reshook)) { + // Classify paid + if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes') { + $object->fetch($id); + $result = $object->setPaid($user); } -} -// Link to a project -if ($action == 'classin' && $user->rights->tax->charges->creer) { - $object->fetch($id); - $object->setProject(GETPOST('fk_project')); -} - -if ($action == 'setfk_user' && $user->rights->tax->charges->creer) { - $object->fetch($id); - $object->fk_user = $fk_user; - $object->update($user); -} - -if ($action == 'setlib' && $user->rights->tax->charges->creer) { - $object->fetch($id); - $result = $object->setValueFrom('libelle', GETPOST('lib'), '', '', 'text', '', $user, 'TAX_MODIFY'); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } -} - -// payment mode -if ($action == 'setmode' && $user->rights->tax->charges->creer) { - $object->fetch($id); - $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } -} - -// Bank account -if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) { - $object->fetch($id); - $result = $object->setBankAccount(GETPOST('fk_account', 'int')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } -} - -// Delete social contribution -if ($action == 'confirm_delete' && $confirm == 'yes') { - $object->fetch($id); - $totalpaid = $object->getSommePaiement(); - if (empty($totalpaid)) { - $result = $object->delete($user); - if ($result > 0) { - header("Location: list.php"); - exit; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } else { - setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors'); - } -} - - -// Add social contribution -if ($action == 'add' && $user->rights->tax->charges->creer) { - $amount = price2num(GETPOST('amount', 'alpha'), 'MT'); - - if (!$dateech) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); - $action = 'create'; - } elseif (!$dateperiod) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors'); - $action = 'create'; - } elseif (!($actioncode > 0)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors'); - $action = 'create'; - } elseif (empty($amount)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); - $action = 'create'; - } elseif (!is_numeric($amount)) { - setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors'); - $action = 'create'; - } else { - $object->type = $actioncode; - $object->label = GETPOST('label', 'alpha'); - $object->date_ech = $dateech; - $object->periode = $dateperiod; - $object->amount = $amount; - $object->fk_user = $fk_user; - $object->mode_reglement_id = (int) GETPOST('mode_reglement_id', 'int'); - $object->fk_account = (int) GETPOST('fk_account', 'int'); - $object->fk_project = (int) GETPOST('fk_project', 'int'); - - $id = $object->create($user); - if ($id <= 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'create'; - } - } -} - - -if ($action == 'update' && !GETPOST("cancel") && $user->rights->tax->charges->creer) { - $amount = price2num(GETPOST('amount', 'alpha'), 'MT'); - - if (!$dateech) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); - $action = 'edit'; - } elseif (!$dateperiod) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors'); - $action = 'edit'; - } elseif (empty($amount)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); - $action = 'edit'; - } elseif (!is_numeric($amount)) { - setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors'); - $action = 'create'; - } else { + if ($action == 'reopen' && $user->rights->tax->charges->creer) { $result = $object->fetch($id); - - $object->date_ech = $dateech; - $object->periode = $dateperiod; - $object->amount = $amount; - $object->fk_user = $fk_user; - - $result = $object->update($user); - if ($result <= 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } -} - -// Action clone object -if ($action == 'confirm_clone' && $confirm != 'yes') { - $action = ''; -} - -if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) { - $db->begin(); - - $originalId = $id; - - $object->fetch($id); - - if ($object->id > 0) { - $object->id = $object->ref = null; - $object->paye = 0; - if (GETPOST('amount', 'alphanohtml')) { - $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2); - } - - if (GETPOST('clone_label', 'alphanohtml')) { - $object->label = GETPOST('clone_label', 'alphanohtml'); - } else { - $object->label = $langs->trans("CopyOf").' '.$object->label; - } - - if (GETPOST('clone_for_next_month', 'int')) { // This can be true only if TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX has been set - $object->periode = dol_time_plus_duree($object->periode, 1, 'm'); - $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm'); - } else { - // Note date_ech is often a little bit higher than dateperiod - $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int')); - $newdateech = dol_mktime(0, 0, 0, GETPOST('clone_date_echmonth', 'int'), GETPOST('clone_date_echday', 'int'), GETPOST('clone_date_echyear', 'int')); - if ($newdateperiod) { - $object->periode = $newdateperiod; - if (empty($newdateech)) { - $object->date_ech = $object->periode; - } - } - if ($newdateech) { - $object->date_ech = $newdateech; - if (empty($newdateperiod)) { - // TODO We can here get dol_get_last_day of previous month: - // $object->periode = dol_get_last_day(year of $object->date_ech - 1m, month or $object->date_ech -1m) - $object->periode = $object->date_ech; - } - } - } - - $resultcheck = $object->check(); - if ($resultcheck) { - $id = $object->create($user); - if ($id > 0) { - $db->commit(); - $db->close(); - - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; + if ($object->paye) { + $result = $object->setUnpaid($user); + if ($result > 0) { + header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); + exit(); } else { - $id = $originalId; - $db->rollback(); - setEventMessages($object->error, $object->errors, 'errors'); } } - } else { - $db->rollback(); - dol_print_error($db, $object->error); } + + // Link to a project + if ($action == 'classin' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $object->setProject(GETPOST('fk_project')); + } + + if ($action == 'setfk_user' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $object->fk_user = $fk_user; + $object->update($user); + } + + if ($action == 'setlib' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $result = $object->setValueFrom('libelle', GETPOST('lib'), '', '', 'text', '', $user, 'TAX_MODIFY'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + // payment mode + if ($action == 'setmode' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + // Bank account + if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $result = $object->setBankAccount(GETPOST('fk_account', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + // Delete social contribution + if ($action == 'confirm_delete' && $confirm == 'yes') { + $object->fetch($id); + $totalpaid = $object->getSommePaiement(); + if (empty($totalpaid)) { + $result = $object->delete($user); + if ($result > 0) { + header("Location: list.php"); + exit; + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + } else { + setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors'); + } + } + + + // Add social contribution + if ($action == 'add' && $user->rights->tax->charges->creer) { + $amount = price2num(GETPOST('amount', 'alpha'), 'MT'); + + if (!$dateech) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); + $action = 'create'; + } elseif (!$dateperiod) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors'); + $action = 'create'; + } elseif (!($actioncode > 0)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Type")), null, 'errors'); + $action = 'create'; + } elseif (empty($amount)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); + $action = 'create'; + } elseif (!is_numeric($amount)) { + setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors'); + $action = 'create'; + } else { + $object->type = $actioncode; + $object->label = GETPOST('label', 'alpha'); + $object->date_ech = $dateech; + $object->periode = $dateperiod; + $object->amount = $amount; + $object->fk_user = $fk_user; + $object->mode_reglement_id = (int) GETPOST('mode_reglement_id', 'int'); + $object->fk_account = (int) GETPOST('fk_account', 'int'); + $object->fk_project = (int) GETPOST('fk_project', 'int'); + + $id = $object->create($user); + if ($id <= 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'create'; + } + } + } + + + if ($action == 'update' && !GETPOST("cancel") && $user->rights->tax->charges->creer) { + $amount = price2num(GETPOST('amount', 'alpha'), 'MT'); + + if (!$dateech) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors'); + $action = 'edit'; + } elseif (!$dateperiod) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Period")), null, 'errors'); + $action = 'edit'; + } elseif (empty($amount)) { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors'); + $action = 'edit'; + } elseif (!is_numeric($amount)) { + setEventMessages($langs->trans("ErrorFieldMustBeANumeric", $langs->transnoentities("Amount")), null, 'errors'); + $action = 'create'; + } else { + $result = $object->fetch($id); + + $object->date_ech = $dateech; + $object->periode = $dateperiod; + $object->amount = $amount; + $object->fk_user = $fk_user; + + $result = $object->update($user); + if ($result <= 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } + + // Action clone object + if ($action == 'confirm_clone' && $confirm != 'yes') { + $action = ''; + } + + if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->charges->creer)) { + $db->begin(); + + $originalId = $id; + + $object->fetch($id); + + if ($object->id > 0) { + $object->id = $object->ref = null; + $object->paye = 0; + if (GETPOST('amount', 'alphanohtml')) { + $object->amount = price2num(GETPOST('amount', 'alphanohtml'), 'MT', 2); + } + + if (GETPOST('clone_label', 'alphanohtml')) { + $object->label = GETPOST('clone_label', 'alphanohtml'); + } else { + $object->label = $langs->trans("CopyOf").' '.$object->label; + } + + if (GETPOST('clone_for_next_month', 'int')) { // This can be true only if TAX_ADD_CLONE_FOR_NEXT_MONTH_CHECKBOX has been set + $object->periode = dol_time_plus_duree($object->periode, 1, 'm'); + $object->date_ech = dol_time_plus_duree($object->date_ech, 1, 'm'); + } else { + // Note date_ech is often a little bit higher than dateperiod + $newdateperiod = dol_mktime(0, 0, 0, GETPOST('clone_periodmonth', 'int'), GETPOST('clone_periodday', 'int'), GETPOST('clone_periodyear', 'int')); + $newdateech = dol_mktime(0, 0, 0, GETPOST('clone_date_echmonth', 'int'), GETPOST('clone_date_echday', 'int'), GETPOST('clone_date_echyear', 'int')); + if ($newdateperiod) { + $object->periode = $newdateperiod; + if (empty($newdateech)) { + $object->date_ech = $object->periode; + } + } + if ($newdateech) { + $object->date_ech = $newdateech; + if (empty($newdateperiod)) { + // TODO We can here get dol_get_last_day of previous month: + // $object->periode = dol_get_last_day(year of $object->date_ech - 1m, month or $object->date_ech -1m) + $object->periode = $object->date_ech; + } + } + } + + $resultcheck = $object->check(); + if ($resultcheck) { + $id = $object->create($user); + if ($id > 0) { + $db->commit(); + $db->close(); + + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } else { + $id = $originalId; + $db->rollback(); + + setEventMessages($object->error, $object->errors, 'errors'); + } + } + } else { + $db->rollback(); + dol_print_error($db, $object->error); + } + } + + // Actions to build doc + include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } - - - /* * View */ @@ -338,6 +341,8 @@ if (isModEnabled('project')) { $formproject = new FormProjets($db); } +$now = dol_now(); + $title = $langs->trans("SocialContribution").' - '.$langs->trans("Card"); $help_url = 'EN:Module_Taxes_and_social_contributions|FR:Module Taxes et dividendes|ES:Módulo Impuestos y cargas sociales (IVA, impuestos)'; llxHeader("", $title, $help_url); @@ -347,7 +352,7 @@ llxHeader("", $title, $help_url); if ($action == 'create') { print load_fiche_titre($langs->trans("NewSocialContribution")); - print '
'; + print ''; print ''; print ''; @@ -499,10 +504,17 @@ if ($id > 0) { $formconfirm = $hookmanager->resPrint; } + /* + * View card + */ + print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill', 0, '', '', 0, '', 1); + // Print form confirm print $formconfirm; - print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill'); + + // Social contribution card + $linkback = ''.$langs->trans("BackToList").''; $morehtmlref = '
'; // Ref customer @@ -543,32 +555,21 @@ if ($id > 0) { // Project if (isModEnabled('project')) { $langs->load("projects"); - $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($user->rights->tax->charges->creer) { + $morehtmlref .= '
'; + if ($permissiontoadd) { + $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); if ($action != 'classify') { - $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; - } - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects(0, $object->fk_project, 'fk_project', 0, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref .= ''; - $morehtmlref .= ''; - } else { - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, 0, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300'); + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; } + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'fk_project' : 'none'), 0, 0, 0, 1, '', 'maxwidth300'); } else { if (!empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); - $morehtmlref .= ' : '.$proj->getNomUrl(1); + $morehtmlref .= $proj->getNomUrl(1); if ($proj->title) { - $morehtmlref .= ' - '.$proj->title; + $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; } - } else { - $morehtmlref .= ''; } } } @@ -576,8 +577,6 @@ if ($id > 0) { $morehtmlright = ''; - $linkback = ''.$langs->trans("BackToList").''; - $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); diff --git a/htdocs/compta/sociales/document.php b/htdocs/compta/sociales/document.php index a8d5327b285..80929bc9e9c 100644 --- a/htdocs/compta/sociales/document.php +++ b/htdocs/compta/sociales/document.php @@ -124,13 +124,13 @@ if ($object->id) { // Project if (isModEnabled('project')) { $langs->load("projects"); - $morehtmlref .= '
'.$langs->trans('Project').' : '; if (!empty($object->fk_project)) { + $morehtmlref .= '
'; $proj = new Project($db); $proj->fetch($object->fk_project); - $morehtmlref .= ' : '.$proj->getNomUrl(1); + $morehtmlref .= $proj->getNomUrl(1); if ($proj->title) { - $morehtmlref .= ' - '.$proj->title; + $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; } } else { $morehtmlref .= ''; diff --git a/htdocs/compta/sociales/info.php b/htdocs/compta/sociales/info.php index a2005b0a25a..3b8c98f21cc 100644 --- a/htdocs/compta/sociales/info.php +++ b/htdocs/compta/sociales/info.php @@ -93,13 +93,13 @@ $morehtmlref .= $form->editfieldval("Label", 'lib', $object->label, $object, $us // Project if (isModEnabled('project')) { $langs->load("projects"); - $morehtmlref .= '
'.$langs->trans('Project').' : '; if (!empty($object->fk_project)) { + $morehtmlref .= '
'; $proj = new Project($db); $proj->fetch($object->fk_project); - $morehtmlref .= ' : '.$proj->getNomUrl(1); + $morehtmlref .= $proj->getNomUrl(1); if ($proj->title) { - $morehtmlref .= ' - '.$proj->title; + $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; } } else { $morehtmlref .= ''; diff --git a/htdocs/compta/sociales/note.php b/htdocs/compta/sociales/note.php index 0f85b6ddf06..1670b1e65fb 100644 --- a/htdocs/compta/sociales/note.php +++ b/htdocs/compta/sociales/note.php @@ -96,11 +96,11 @@ if ($id > 0 || !empty($ref)) { // Project if (isModEnabled('project')) { $langs->load("projects"); - $morehtmlref .= '
'.$langs->trans('Project').' : '; if (!empty($object->fk_project)) { + $morehtmlref .= '
'; $proj = new Project($db); $proj->fetch($object->fk_project); - $morehtmlref .= ' : '.$proj->getNomUrl(1); + $morehtmlref .= $proj->getNomUrl(1); if ($proj->title) { $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index e43b25b26f1..e98bc12cba2 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -69,7 +69,7 @@ if (isModEnabled('incoterm')) { } $id = (GETPOST('facid', 'int') ? GETPOST('facid', 'int') : GETPOST('id', 'int')); -$socid = GETPOST('socid', 'int'); + $action = GETPOST('action', 'aZ09'); $confirm = GETPOST("confirm"); $ref = GETPOST('ref', 'alpha'); @@ -110,10 +110,11 @@ if ($id > 0 || !empty($ref)) { } // Security check -$socid = ''; +$socid = GETPOST('socid', 'int'); if (!empty($user->socid)) { $socid = $user->socid; } + $isdraft = (($object->statut == FactureFournisseur::STATUS_DRAFT) ? 1 : 0); $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture', 'fk_soc', 'rowid', $isdraft);