From d9a1e1b348cb4b0ec1633cd0cf28cef4d0aba351 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Dec 2019 10:01:11 +0100 Subject: [PATCH] Fix several non dolibarr behaviour on input of salary payments --- htdocs/compta/accounting-files.php | 6 +-- htdocs/langs/en_US/main.lang | 1 + htdocs/salaries/card.php | 72 +++++++++++++++++------------- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/htdocs/compta/accounting-files.php b/htdocs/compta/accounting-files.php index a7de150edee..ac019de8088 100644 --- a/htdocs/compta/accounting-files.php +++ b/htdocs/compta/accounting-files.php @@ -136,7 +136,7 @@ if (($action == "searchfiles" || $action == "dl")) { $sql .= " AND t.fk_statut <> ".Don::STATUS_DRAFT; $sql .= " UNION ALL"; // Paiements of salaries - $sql .= " SELECT t.rowid as id, t.label as ref, 1 as paid, amount as total_ht, amount as total_ttc, 0 as total_vat, t.fk_user as fk_soc, datep as date, 'SalaryPayment' as item, CONCAT(CONCAT(u.lastname, ' '), u.firstname) as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum"; + $sql .= " SELECT t.rowid as id, t.ref as ref, 1 as paid, amount as total_ht, amount as total_ttc, 0 as total_vat, t.fk_user as fk_soc, datep as date, 'SalaryPayment' as item, CONCAT(CONCAT(u.lastname, ' '), u.firstname) as thirdparty_name, '' as thirdparty_code, c.code as country_code, '' as vatnum"; $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as t LEFT JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid = t.fk_user LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON c.rowid = u.fk_country"; $sql .= " WHERE datep between ".$wheretail; $sql .= " AND t.entity IN (".($entity == 1 ? '0,1' : $entity).')'; @@ -450,7 +450,7 @@ if (!empty($date_start) && !empty($date_stop)) print '
'; // You can use div-table-responsive-no-min if you dont need reserved height for your table print ''; print ''; - print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "type", "", $param, '', $sortfield, $sortorder, 'nowrap '); + print_liste_field_titre($arrayfields['type']['label'], $_SERVER["PHP_SELF"], "item", "", $param, '', $sortfield, $sortorder, 'nowrap '); print_liste_field_titre($arrayfields['date']['label'], $_SERVER["PHP_SELF"], "date", "", $param, '', $sortfield, $sortorder, 'center nowrap '); print ''; print ''; @@ -465,7 +465,7 @@ if (!empty($date_start) && !empty($date_stop)) print ''; if ($result) { - $TData = dol_sort_array($filesarray, 'date', 'ASC'); + $TData = dol_sort_array($filesarray, $sortfield, $sortorder); if (empty($TData)) { diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index b177abf75fd..fa9f48ee4c4 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -171,6 +171,7 @@ NotValidated=Not validated Save=Save SaveAs=Save As SaveAndStay=Save and stay +SaveAndNew=Save and new TestConnection=Test connection ToClone=Clone ConfirmClone=Choose data you want to clone: diff --git a/htdocs/salaries/card.php b/htdocs/salaries/card.php index c9ccd78c244..798ef8dab4a 100644 --- a/htdocs/salaries/card.php +++ b/htdocs/salaries/card.php @@ -41,11 +41,17 @@ if (! empty($conf->projet->enabled)) $langs->loadLangs(array("compta","banks","bills","users","salaries","hrm")); if (! empty($conf->projet->enabled)) $langs->load("projects"); -$id=GETPOST("id", 'int'); -$action=GETPOST('action', 'aZ09'); -$cancel= GETPOST('cancel', 'aZ09'); +$id = GETPOST("id", 'int'); +$action = GETPOST('action', 'aZ09'); +$cancel = GETPOST('cancel', 'aZ09'); +$accountid = GETPOST("accountid", 'int'); $projectid = (GETPOST('projectid', 'int') ? GETPOST('projectid', 'int') : GETPOST('fk_project', 'int')); +$datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int')); +$datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int')); +$datesp = dol_mktime(12, 0, 0, GETPOST("datespmonth", 'int'), GETPOST("datespday", 'int'), GETPOST("datespyear", 'int')); +$dateep = dol_mktime(12, 0, 0, GETPOST("dateepmonth", 'int'), GETPOST("dateepday", 'int'), GETPOST("dateepyear", 'int')); + // Security check $socid = GETPOST("socid", "int"); if ($user->socid) $socid=$user->socid; @@ -60,6 +66,7 @@ $extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('salarycard', 'globalcard')); + /** * Actions */ @@ -74,34 +81,30 @@ if ($cancel) if ($action == 'classin' && $user->rights->banque->modifier) { $object->fetch($id); - $object->setProject(GETPOST('projectid')); + $object->setProject($projectid); } if ($action == 'add' && empty($cancel)) { $error = 0; - $datep = dol_mktime(12, 0, 0, GETPOST("datepmonth", 'int'), GETPOST("datepday", 'int'), GETPOST("datepyear", 'int')); - $datev = dol_mktime(12, 0, 0, GETPOST("datevmonth", 'int'), GETPOST("datevday", 'int'), GETPOST("datevyear", 'int')); - $datesp = dol_mktime(12, 0, 0, GETPOST("datespmonth", 'int'), GETPOST("datespday", 'int'), GETPOST("datespyear", 'int')); - $dateep = dol_mktime(12, 0, 0, GETPOST("dateepmonth", 'int'), GETPOST("dateepday", 'int'), GETPOST("dateepyear", 'int')); if (empty($datev)) $datev = $datep; $type_payment = dol_getIdFromCode($db, GETPOST("paymenttype", 'alpha'), 'c_paiement', 'code', 'id', 1); - $object->accountid = GETPOST("accountid") > 0 ? GETPOST("accountid", "int") : 0; - $object->fk_user = GETPOST("fk_user") > 0 ? GETPOST("fk_user", "int") : 0; + $object->accountid = GETPOST("accountid", 'int') > 0 ? GETPOST("accountid", "int") : 0; + $object->fk_user = GETPOST("fk_user", 'int') > 0 ? GETPOST("fk_user", "int") : 0; $object->datev = $datev; $object->datep = $datep; - $object->amount = price2num(GETPOST("amount")); - $object->label = GETPOST("label"); + $object->amount = price2num(GETPOST("amount", 'alpha')); + $object->label = GETPOST("label", 'alphanohtml'); $object->datesp = $datesp; $object->dateep = $dateep; - $object->note = GETPOST("note"); + $object->note = GETPOST("note", 'none'); $object->type_payment = ($type_payment > 0 ? $type_payment : 0); - $object->num_payment = GETPOST("num_payment"); + $object->num_payment = GETPOST("num_payment", 'alphanohtml'); $object->fk_user_author = $user->id; - $object->fk_project = GETPOST('fk_project', 'int'); + $object->fk_project = $projectid; // Set user current salary as ref salary for the payment $fuser = new User($db); @@ -146,8 +149,15 @@ if ($action == 'add' && empty($cancel)) if ($ret > 0) { $db->commit(); - header("Location: list.php"); - exit; + + if (GETPOST('saveandnew', 'alpha')) { + 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')); + exit; + } else { + header("Location: list.php"); + exit; + } } else { @@ -272,13 +282,6 @@ if ($action == 'create') print $form->selectDate((empty($datev) ?-1 : $datev), "datev", '', '', '', 'add', 1, 1); print ''; - // Employee - print ''; - // Label print ''; + // Employee + print ''; + // Amount print ''; } @@ -320,14 +328,14 @@ if ($action == 'create') { print ''; } // Type payment print ''; // Number @@ -354,8 +362,10 @@ if ($action == 'create') dol_fiche_end(); print '
'; - print ''; - print '     '; + print ''; + print '     '; + print ''; + print '     '; print ''; print '
';
'.$langs->trans("Ref").''.$langs->trans("Document").'
'; - print $form->editfieldkey('Employee', 'fk_user', '', $object, 0, 'string', '', 1).''; - $noactive = 0; // We keep active and unactive users - print $form->select_dolusers(GETPOST('fk_user', 'int'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, 'AND employee=1', 0, '', 'maxwidth300', $noactive); - print '
'; print $form->editfieldkey('Label', 'label', '', $object, 0, 'string', '', 1).''; @@ -297,6 +300,13 @@ if ($action == 'create') print $form->selectDate($dateep, "dateep", '', '', '', 'add'); print '
'; + print $form->editfieldkey('Employee', 'fk_user', '', $object, 0, 'string', '', 1).''; + $noactive = 0; // We keep active and unactive users + print $form->select_dolusers(GETPOST('fk_user', 'int'), 'fk_user', 1, '', 0, '', '', 0, 0, 0, 'AND employee=1', 0, '', 'maxwidth300', $noactive); + print '
'; print $form->editfieldkey('Amount', 'amount', '', $object, 0, 'string', '', 1).''; @@ -309,9 +319,7 @@ if ($action == 'create') $formproject = new FormProjets($db); print '
'.$langs->trans("Project").''; - - $numproject = $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1); - + $formproject->select_projects(-1, $projectid, 'fk_project', 0, 0, 1, 1); print '
'; print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).''; - $form->select_comptes($_POST["accountid"], "accountid", 0, '', 1); // Affiche liste des comptes courant + $form->select_comptes($accountid, "accountid", 0, '', 1); // Affiche liste des comptes courant print '
'; print $form->editfieldkey('PaymentMode', 'selectpaymenttype', '', $object, 0, 'string', '', 1).''; - $form->select_types_paiements(GETPOST("paymenttype"), "paymenttype", '', 2); + $form->select_types_paiements(GETPOST("paymenttype", 'aZ09'), "paymenttype", '', 2); print '