--- /tmp/dsg/dolibarr/htdocs/salaries/github_19.0.3_card.php +++ /tmp/dsg/dolibarr/htdocs/salaries/client_card.php @@ -2,2 +2,2 @@ -/* Copyright (C) 2011-2023 Alexandre Spangaro - * Copyright (C) 2014-2020 Laurent Destailleur +/* Copyright (C) 2011-2019 Alexandre Spangaro + * Copyright (C) 2014 Laurent Destailleur @@ -6,4 +6 @@ - * Copyright (C) 2018-2022 Frédéric France - * Copyright (C) 2021 Gauthier VERDOL - * Copyright (C) 2023 Maxime Nicolas - * Copyright (C) 2023 Benjamin GREMBI + * Copyright (C) 2018 Frédéric France @@ -31 +27,0 @@ -// Load Dolibarr environment @@ -34,2 +29,0 @@ -require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; @@ -40,3 +34,2 @@ -require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; -if (isModEnabled('project')) { +if (!empty($conf->projet->enabled)) +{ @@ -48,7 +41,4 @@ -$langs->loadLangs(array("compta", "banks", "bills", "users", "salaries", "hrm", "trips")); -if (isModEnabled('project')) { - $langs->load("projects"); -} - -$id = GETPOSTINT('id'); -$ref = GETPOST('ref', 'alpha'); +$langs->loadLangs(array("compta", "banks", "bills", "users", "salaries", "hrm")); +if (!empty($conf->projet->enabled)) $langs->load("projects"); + +$id = GETPOST("id", 'int'); @@ -56,6 +46,2 @@ -$cancel = GETPOST('cancel', 'alpha'); -$backtopage = GETPOST('backtopage', 'alpha'); -$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); -$confirm = GETPOST('confirm'); - -$label = GETPOST('label', 'alphanohtml'); +$cancel = GETPOST('cancel', 'aZ09'); +$accountid = GETPOST('accountid', 'int') > 0 ? GETPOST('accountid', 'int') : 0; @@ -63,6 +48,0 @@ -$accountid = GETPOST('accountid', 'int') > 0 ? GETPOST('accountid', 'int') : 0; -if (GETPOSTISSET('auto_create_paiement') || $action === 'add') { - $auto_create_paiement = GETPOST("auto_create_paiement", "int"); -} else { - $auto_create_paiement = !getDolGlobalString('CREATE_NEW_SALARY_WITHOUT_AUTO_PAYMENT'); -} @@ -74,3 +54,7 @@ -$fk_user = GETPOSTINT('userid'); - -$object = new Salary($db); + +// Security check +$socid = GETPOST("socid", "int"); +if ($user->socid) $socid = $user->socid; +$result = restrictedArea($user, 'salaries', '', '', ''); + +$object = new PaymentSalary($db); @@ -78,2 +61,0 @@ - -$childids = $user->getAllChildIds(1); @@ -87,32 +69,2 @@ -if ($id > 0 || !empty($ref)) { - $object->fetch($id, $ref); - - // Check current user can read this salary - $canread = 0; - if ($user->hasRight('salaries', 'readall')) { - $canread = 1; - } - if ($user->hasRight('salaries', 'read') && $object->fk_user > 0 && in_array($object->fk_user, $childids)) { - $canread = 1; - } - if (!$canread) { - accessforbidden(); - } -} - -// Security check -$socid = GETPOSTINT('socid'); -if ($user->socid) { - $socid = $user->socid; -} - -restrictedArea($user, 'salaries', $object->id, 'salary', ''); - -$permissiontoread = $user->hasRight('salaries', 'read'); -$permissiontoadd = $user->hasRight('salaries', 'write'); // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php -$permissiontodelete = $user->hasRight('salaries', 'delete') || ($permissiontoadd && isset($object->status) && $object->status == $object::STATUS_UNPAID); - -$upload_dir = $conf->salaries->multidir_output[$conf->entity]; - - -/* + +/** @@ -122,45 +74,4 @@ -$parameters = array(); -// Note that $action and $object may be modified by some hooks -$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); -if ($reshook < 0) { - setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -} - -if (empty($reshook)) { - $error = 0; - - $backurlforlist = DOL_URL_ROOT.'/salaries/list.php'; - - if (empty($backtopage) || ($cancel && empty($id))) { - if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) { - if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) { - $backtopage = $backurlforlist; - } else { - $backtopage = DOL_URL_ROOT.'/salaries/card.php?id='.($id > 0 ? $id : '__ID__'); - } - } - } - - if ($cancel) { - //var_dump($cancel); - //var_dump($backtopage);exit; - if (!empty($backtopageforcancel)) { - header("Location: ".$backtopageforcancel); - exit; - } elseif (!empty($backtopage)) { - header("Location: ".$backtopage); - exit; - } - $action = ''; - } - - // Actions to send emails - $triggersendname = 'COMPANY_SENTBYMAIL'; - $paramname = 'id'; - $mode = 'emailfromthirdparty'; - $trackid = 'sal'.$object->id; - include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - - //var_dump($upload_dir);var_dump($permissiontoadd);var_dump($action);exit; - // Actions to build doc - include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; +if ($cancel) +{ + header("Location: list.php"); + exit; @@ -170 +81,2 @@ -if ($action == 'classin' && $permissiontoadd) { +if ($action == 'classin' && $user->rights->banque->modifier) +{ @@ -175,56 +87,2 @@ -// set label -if ($action == 'setlabel' && $permissiontoadd) { - $object->fetch($id); - $object->label = $label; - $object->update($user); -} - -// Classify paid -if ($action == 'confirm_paid' && $permissiontoadd && $confirm == 'yes') { - $object->fetch($id); - $result = $object->setPaid($user); -} - -if ($action == 'setfk_user' && $permissiontoadd) { - $result = $object->fetch($id); - if ($result > 0) { - $object->fk_user = $fk_user; - $object->update($user); - } else { - dol_print_error($db); - exit; - } -} - -if ($action == 'reopen' && $permissiontoadd) { - $result = $object->fetch($id); - if ($object->paye) { - $result = $object->set_unpaid($user); - if ($result > 0) { - header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id); - exit(); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } - } -} - -// payment mode -if ($action == 'setmode' && $permissiontoadd) { - $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' && $permissiontoadd) { - $object->fetch($id); - $result = $object->setBankAccount(GETPOST('fk_account', 'int')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } -} - -if ($action == 'add' && empty($cancel)) { +if ($action == 'add' && empty($cancel)) +{ @@ -233,6 +91,3 @@ - if (empty($datev)) { - $datev = $datep; - } - - $type_payment = GETPOST("paymenttype", 'alpha'); - $amount = price2num(GETPOST("amount", 'alpha'), 'MT', 2); + if (empty($datev)) $datev = $datep; + + $type_payment = dol_getIdFromCode($db, GETPOST("paymenttype", 'alpha'), 'c_paiement', 'code', 'id', 1); @@ -244 +99 @@ - $object->amount = $amount; + $object->amount = price2num(GETPOST("amount", 'alpha')); @@ -248 +103 @@ - $object->note = GETPOST("note", 'restricthtml'); + $object->note = GETPOST("note", 'none'); @@ -249,0 +105 @@ + $object->num_payment = GETPOST("num_payment", 'alphanohtml'); @@ -258,11 +114,6 @@ - // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) { - $error++; - } - - if (!empty($auto_create_paiement) && empty($datep)) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DATE_PAIEMENT")), null, 'errors'); - $error++; - } - if (empty($datesp) || empty($dateep)) { + // Fill array 'array_options' with data from add form + $ret = $extrafields->setOptionalsFromPost(null, $object); + if ($ret < 0) $error++; + + if (empty($datep) || empty($datev) || empty($datesp) || empty($dateep)) + { @@ -272 +123,2 @@ - if (empty($object->fk_user) || $object->fk_user < 0) { + if (empty($object->fk_user) || $object->fk_user < 0) + { @@ -276 +128,2 @@ - if (!empty($auto_create_paiement) && (empty($type_payment) || $type_payment < 0)) { + if (empty($type_payment) || $type_payment < 0) + { @@ -280 +133,2 @@ - if (empty($object->amount)) { + if (empty($object->amount)) + { @@ -284 +138,2 @@ - if (isModEnabled("banque") && !empty($auto_create_paiement) && !$object->accountid > 0) { + if (!empty($conf->banque->enabled) && !$object->accountid > 0) + { @@ -289 +144,2 @@ - if (!$error) { + if (!$error) + { @@ -293,35 +149,2 @@ - if ($ret < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - if (!empty($auto_create_paiement) && !$error) { - // Create a line of payments - $paiement = new PaymentSalary($db); - $paiement->fk_salary = $object->id; - $paiement->chid = $object->id; // deprecated - $paiement->datep = $datep; - $paiement->datev = $datev; - $paiement->amounts = array($object->id=>$amount); // Tableau de montant - $paiement->fk_typepayment = $type_payment; - $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); - $paiement->note_private = GETPOST("note", 'restricthtml'); - - if (!$error) { - $paymentid = $paiement->create($user, (int) GETPOST('closepaidsalary')); - if ($paymentid < 0) { - $error++; - setEventMessages($paiement->error, null, 'errors'); - $action = 'create'; - } - } - - if (!$error) { - $result = $paiement->addPaymentToBank($user, 'payment_salary', '(SalaryPayment)', GETPOST('accountid', 'int'), '', ''); - if (!($result > 0)) { - $error++; - setEventMessages($paiement->error, null, 'errors'); - } - } - } - - if (empty($error)) { + if ($ret > 0) + { @@ -331,2 +154,2 @@ - setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); - header("Location: card.php?action=create&fk_project=" . urlencode($projectid) . "&accountid=" . urlencode($accountid) . '&paymenttype=' . urlencode(GETPOST('paymenttype', 'aZ09')) . '&datepday=' . GETPOST("datepday", 'int') . '&datepmonth=' . GETPOST("datepmonth", 'int') . '&datepyear=' . GETPOST("datepyear", 'int')); + setEventMessages($langs->trans("RecordSaved"), '', 'mesgs'); + header("Location: card.php?action=create&fk_project=".urlencode($projectid)."&accountid=".urlencode($accountid).'&paymenttype='.urlencode(GETPOST('paymenttype', 'az09')).'&datepday='.GETPOST("datepday", 'int').'&datepmonth='.GETPOST("datepmonth", 'int').'&datepyear='.GETPOST("datepyear", 'int')); @@ -335 +158 @@ - header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $object->id); + header("Location: list.php"); @@ -338,21 +161,3 @@ - } else { - $db->rollback(); - } - } - - $action = 'create'; -} - -if ($action == 'confirm_delete') { - $result = $object->fetch($id); - $totalpaid = $object->getSommePaiement(); - - if (empty($totalpaid)) { - $db->begin(); - - $ret = $object->delete($user); - if ($ret > 0) { - $db->commit(); - header("Location: ".DOL_URL_ROOT.'/salaries/list.php'); - exit; - } else { + } + else + { @@ -361,25 +166,41 @@ - } - } else { - setEventMessages($langs->trans('DisabledBecausePayments'), null, 'errors'); - } -} - - -if ($action == 'update' && !GETPOST("cancel") && $permissiontoadd) { - $amount = price2num(GETPOST('amount'), 'MT', 2); - - if (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->amount = price2num($amount); - $object->datesp = price2num($datesp); - $object->dateep = price2num($dateep); - - $result = $object->update($user); - if ($result <= 0) { + $action = "create"; + } + } + + $action = 'create'; +} + +if ($action == 'delete') +{ + $result = $object->fetch($id); + + if ($object->rappro == 0) + { + $db->begin(); + + $ret = $object->delete($user); + if ($ret > 0) + { + if ($object->fk_bank) + { + $accountline = new AccountLine($db); + $result = $accountline->fetch($object->fk_bank); + if ($result > 0) $result = $accountline->delete($user); // $result may be 0 if not found (when bank entry was deleted manually and fk_bank point to nothing) + } + + if ($result >= 0) + { + $db->commit(); + header("Location: ".DOL_URL_ROOT.'/salaries/list.php'); + exit; + } + else + { + $object->error = $accountline->error; + $db->rollback(); + setEventMessages($object->error, $object->errors, 'errors'); + } + } + else + { + $db->rollback(); @@ -389,80 +210,6 @@ -} - -if ($action == 'confirm_clone' && $confirm != 'yes') { - $action = ''; -} - -if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) { - $db->begin(); - - $originalId = $id; - - $object->fetch($id); - - if ($object->id > 0) { - $object->paye = 0; - $object->id = $object->ref = null; - - 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; - } - - $newdatestart = dol_mktime(0, 0, 0, GETPOST('clone_date_startmonth', 'int'), GETPOST('clone_date_startday', 'int'), GETPOST('clone_date_startyear', 'int')); - $newdateend = dol_mktime(0, 0, 0, GETPOST('clone_date_endmonth', 'int'), GETPOST('clone_date_endday', 'int'), GETPOST('clone_date_endyear', 'int')); - - if ($newdatestart) { - $object->datesp = $newdatestart; - } - if ($newdateend) { - $object->dateep = $newdateend; - } - - $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); - } -} - -// Action to update one extrafield -if ($action == "update_extras" && $permissiontoadd) { - $object->fetch(GETPOST('id', 'int')); - - $attributekey = GETPOST('attribute', 'alpha'); - $attributekeylong = 'options_'.$attributekey; - - if (GETPOSTISSET($attributekeylong.'day') && GETPOSTISSET($attributekeylong.'month') && GETPOSTISSET($attributekeylong.'year')) { - // This is properties of a date - $object->array_options['options_'.$attributekey] = dol_mktime(GETPOST($attributekeylong.'hour', 'int'), GETPOST($attributekeylong.'min', 'int'), GETPOST($attributekeylong.'sec', 'int'), GETPOST($attributekeylong.'month', 'int'), GETPOST($attributekeylong.'day', 'int'), GETPOST($attributekeylong.'year', 'int')); - //var_dump(dol_print_date($object->array_options['options_'.$attributekey]));exit; - } else { - $object->array_options['options_'.$attributekey] = GETPOST($attributekeylong, 'alpha'); - } - - $result = $object->insertExtraFields(empty($triggermodname) ? '' : $triggermodname, $user); - if ($result > 0) { - setEventMessages($langs->trans('RecordSaved'), null, 'mesgs'); - $action = 'view'; - } else { - setEventMessages($object->error, $object->errors, 'errors'); - $action = 'edit_extras'; - } -} + else + { + setEventMessages('Error try do delete a line linked to a conciliated bank transaction', null, 'errors'); + } +} + @@ -473,0 +221,2 @@ +llxHeader("", $langs->trans("SalaryPayment")); + @@ -475,14 +224,5 @@ -$formfile = new FormFile($db); -if (isModEnabled('project')) { - $formproject = new FormProjets($db); -} - -$title = $langs->trans('Salary')." - ".$object->ref; -if ($action == 'create') { - $title = $langs->trans("NewSalary"); -} -$help_url = ""; -llxHeader('', $title, $help_url); - - -if ($id > 0) { +if (!empty($conf->projet->enabled)) $formproject = new FormProjets($db); + +if ($id) +{ + $object = new PaymentSalary($db); @@ -490 +230,2 @@ - if ($result <= 0) { + if ($result <= 0) + { @@ -497,2 +238,3 @@ -if ($action == 'create' && $permissiontoadd) { - $year_current = dol_print_date(dol_now('gmt'), "%Y", 'gmt'); +if ($action == 'create') +{ + $year_current = strftime("%Y", dol_now()); @@ -501 +243,2 @@ - if ($pastmonth == 0) { + if ($pastmonth == 0) + { @@ -515,6 +258,6 @@ - if (empty($datesp) || empty($dateep)) { // We define date_start and date_end - $datesp = dol_get_first_day($pastmonthyear, $pastmonth, false); - $dateep = dol_get_last_day($pastmonthyear, $pastmonth, false); - } - - print '
'; + if (empty($datesp) || empty($dateep)) // We define date_start and date_end + { + $datesp = dol_get_first_day($pastmonthyear, $pastmonth, false); $dateep = dol_get_last_day($pastmonthyear, $pastmonth, false); + } + + print ''; @@ -523,40 +266,4 @@ - if ($backtopage) { - print ''; - } - if ($backtopageforcancel) { - print ''; - } - - print load_fiche_titre($langs->trans("NewSalary"), '', 'salary'); - - if (!empty($conf->use_javascript_ajax)) { - print "\n".''."\n"; - } - - print dol_get_fiche_head(''); + + print load_fiche_titre($langs->trans("NewSalaryPayment"), '', 'object_payment'); + + dol_fiche_head('', ''); @@ -565,0 +273,30 @@ + // Date payment + print ''; + print $form->editfieldkey('DatePayment', 'datep', '', $object, 0, 'string', '', 1).''; + print $form->selectDate((empty($datep) ?-1 : $datep), "datep", '', '', '', 'add', 1, 1); + print ''; + + // Date value for bank + print ''; + print $form->editfieldkey('DateValue', 'datev', '', $object, 0).''; + print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1); + print ''; + + // Label + print ''; + print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).''; + print 'trans("SalaryPayment")).'">'; + print ''; + + // Date start period + print ''; + print $form->editfieldkey('DateStartPeriod', 'datesp', '', $object, 0, 'string', '', 1).''; + print $form->selectDate($datesp, "datesp", '', '', '', 'add'); + print ''; + + // Date end period + print ''; + print $form->editfieldkey('DateEndPeriod', 'dateep', '', $object, 0, 'string', '', 1).''; + print $form->selectDate($dateep, "dateep", '', '', '', 'add'); + print ''; + @@ -567 +304 @@ - print ''; + print ''; @@ -570,19 +307 @@ - print img_picto('', 'user', 'class="paddingrighonly"').$form->select_dolusers(GETPOST('fk_user', 'int'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, 'AND employee=1', 0, '', 'maxwidth300', $noactive); - print ''; - - // Label - print ''; - print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).''; - print 'trans("Salary")).'">'; - print ''; - - // Date start period - print ''; - print $form->editfieldkey('DateStartPeriod', 'datesp', '', $object, 0, 'string', '', 1).''; - print $form->selectDate($datesp, "datesp", '', '', '', 'add'); - print ''; - - // Date end period - print ''; - print $form->editfieldkey('DateEndPeriod', 'dateep', '', $object, 0, 'string', '', 1).''; - print $form->selectDate($dateep, "dateep", '', '', '', 'add'); + print $form->select_dolusers(GETPOST('fk_user', 'int'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, 'AND employee=1', 0, '', 'maxwidth300', $noactive); @@ -594,4 +313,2 @@ - print '  '; - print '