diff --git a/htdocs/compta/paiement/card.php b/htdocs/compta/paiement/card.php index cc39a790527..073365fa876 100644 --- a/htdocs/compta/paiement/card.php +++ b/htdocs/compta/paiement/card.php @@ -84,7 +84,7 @@ if ($action == 'setnote' && $user->hasRight('facture', 'paiement')) { } } -if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->paiement) { +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('facture', 'paiement')) { $db->begin(); $result = $object->delete(); @@ -105,7 +105,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture-> } } -if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->facture->paiement) { +if ($action == 'confirm_validate' && $confirm == 'yes' && $user->hasRight('facture', 'paiement')) { $db->begin(); if ($object->validate($user) > 0) { @@ -175,7 +175,7 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->facture } } -if ($action == 'setnum_paiement' && GETPOST('num_paiement')) { +if ($action == 'setnum_paiement' && GETPOST('num_paiement') && $user->hasRight('facture', 'paiement')) { $res = $object->update_num(GETPOST('num_paiement')); if ($res === 0) { setEventMessages($langs->trans('PaymentNumberUpdateSucceeded'), null, 'mesgs'); @@ -184,7 +184,7 @@ if ($action == 'setnum_paiement' && GETPOST('num_paiement')) { } } -if ($action == 'setdatep' && GETPOST('datepday')) { +if ($action == 'setdatep' && GETPOST('datepday') && $user->hasRight('facture', 'paiement')) { $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int')); $res = $object->update_date($datepaye); if ($res === 0) { @@ -193,7 +193,8 @@ if ($action == 'setdatep' && GETPOST('datepday')) { setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors'); } } -if ($action == 'createbankpayment' && !empty($user->rights->facture->paiement)) { + +if ($action == 'createbankpayment' && $user->hasRight('facture', 'paiement')) { $db->begin(); // Create the record into bank for the amount of payment $object diff --git a/htdocs/compta/payment_sc/card.php b/htdocs/compta/payment_sc/card.php index 39bac75ba0c..7d7742c3f01 100644 --- a/htdocs/compta/payment_sc/card.php +++ b/htdocs/compta/payment_sc/card.php @@ -63,7 +63,7 @@ if ($id > 0) { */ // Delete payment -if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->charges->supprimer) { +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('tax', 'charges', 'supprimer')) { $db->begin(); $result = $object->delete($user); @@ -77,6 +77,16 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->tax->char } } +if ($action == 'setdatep' && GETPOST('datepday') && $user->hasRight('tax', 'charges', 'creer')) { + $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int')); + $res = $object->update_date($datepaye); + if ($res === 0) { + setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs'); + } else { + setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors'); + } +} + /* * View diff --git a/htdocs/salaries/class/paymentsalary.class.php b/htdocs/salaries/class/paymentsalary.class.php index 029e5732f9b..a2de50aeed4 100644 --- a/htdocs/salaries/class/paymentsalary.class.php +++ b/htdocs/salaries/class/paymentsalary.class.php @@ -602,12 +602,66 @@ class PaymentSalary extends CommonObject } } + /** + * Updates the payment date. + * Old name of function is update_date() + * + * @param int $date New date + * @return int <0 if KO, 0 if OK + */ + public function updatePaymentDate($date) + { + $error = 0; + + if (!empty($date)) { + $this->db->begin(); + + dol_syslog(get_class($this)."::updatePaymentDate with date = ".$date, LOG_DEBUG); + + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " SET datep = '".$this->db->idate($date)."'"; + $sql .= " WHERE rowid = ".((int) $this->id); + + $result = $this->db->query($sql); + if (!$result) { + $error++; + $this->error = 'Error -1 '.$this->db->error(); + } + + $type = $this->element; + + $sql = "UPDATE ".MAIN_DB_PREFIX.'bank'; + $sql .= " SET dateo = '".$this->db->idate($date)."', datev = '".$this->db->idate($date)."'"; + $sql .= " WHERE rowid IN (SELECT fk_bank FROM ".MAIN_DB_PREFIX."bank_url WHERE type = '".$this->db->escape($type)."' AND url_id = ".((int) $this->id).")"; + $sql .= " AND rappro = 0"; + + $result = $this->db->query($sql); + if (!$result) { + $error++; + $this->error = 'Error -1 '.$this->db->error(); + } + + if (!$error) { + } + + if (!$error) { + $this->datep = $date; + + $this->db->commit(); + return 0; + } else { + $this->db->rollback(); + return -2; + } + } + return -1; //no date given or already validated + } /** - * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) + * Return the label of the status * - * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto - * @return string Libelle + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Label of status */ public function getLibStatut($mode = 0) { @@ -616,11 +670,11 @@ class PaymentSalary extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** - * Renvoi le libelle d'un statut donne + * Return the status * - * @param int $status Statut - * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto - * @return string Libelle du statut + * @param int $status Id status + * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @return string Label of status */ public function LibStatut($status, $mode = 0) { diff --git a/htdocs/salaries/paiement_salary.php b/htdocs/salaries/paiement_salary.php index 30279ee3538..9f90e4c9ac9 100644 --- a/htdocs/salaries/paiement_salary.php +++ b/htdocs/salaries/paiement_salary.php @@ -57,7 +57,7 @@ restrictedArea($user, 'salaries', $object->id, 'salary', ''); * Actions */ -if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) { +if (($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) && $user->hasRight('salaries', 'write')) { $error = 0; if ($cancel) { diff --git a/htdocs/salaries/payment_salary/card.php b/htdocs/salaries/payment_salary/card.php index c9f0a151901..c6d73c5ec7f 100644 --- a/htdocs/salaries/payment_salary/card.php +++ b/htdocs/salaries/payment_salary/card.php @@ -20,10 +20,10 @@ */ /** - * \file htdocs/compta/payment_sc/card.php - * \ingroup facture - * \brief Onglet payment of a salary - * \remarks Fichier presque identique a fournisseur/paiement/card.php + * \file htdocs/salaries/payment_salary/card.php + * \ingroup salary + * \brief Tab to pay a salary + * \remarks File very similar with fournisseur/paiement/card.php */ // Load Dolibarr environment @@ -56,7 +56,7 @@ restrictedArea($user, 'salaries', $object->fk_salary, 'salary', ''); // $object */ // Delete payment -if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->salaries->delete) { +if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('salaries', 'delete')) { $db->begin(); $result = $object->delete($user); @@ -70,6 +70,16 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->salaries- } } +if ($action == 'setdatep' && GETPOST('datepday') && $user->hasRight('salaries', 'write')) { + $datepaye = dol_mktime(GETPOST('datephour', 'int'), GETPOST('datepmin', 'int'), GETPOST('datepsec', 'int'), GETPOST('datepmonth', 'int'), GETPOST('datepday', 'int'), GETPOST('datepyear', 'int'), 'tzuserrel'); + $res = $object->updatePaymentDate($datepaye); + if ($res === 0) { + setEventMessages($langs->trans('PaymentDateUpdateSucceeded'), null, 'mesgs'); + } else { + setEventMessages($langs->trans('PaymentDateUpdateFailed'), null, 'errors'); + } +} + /* * View @@ -127,7 +137,7 @@ dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'id', ''); print '
| '.$langs->trans('Ref').' | '; @@ -136,21 +146,26 @@ print $form->showrefnav($object,'id','',1,'rowid','id'); print '|||
| '.$langs->trans('Date').' | '.dol_print_date($object->datep, 'day').' | ||
| '; +print $form->editfieldkey("Date", 'datep', $object->datep, $object, 1, 'datepicker'); +print ' | '; +print $form->editfieldval("Date", 'datep', $object->datep, $object, 1, 'datepicker'); +print " | "; +print '||
| '.$langs->trans('Mode').' | '; +print ' | ||
| '.$langs->trans('Mode').' | '; print $langs->trans("PaymentType".$object->type_code); print ' | ||
| '.$langs->trans('Numero').' | '.$object->num_payment.' | ||
| '.$langs->trans('Numero').' | '.dol_escape_htmltag($object->num_payment).' | ||
| '.$langs->trans('Amount').' | '.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).' | ||
| '.$langs->trans('Amount').' | '.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).' | ||
| '.$langs->trans('Note').' | '.nl2br($object->note).' | ||
| '.$langs->trans('Note').' | '.dol_nl2br($object->note).' | ||