NEW Can modify the date of payment of a salary (if not reconciled)

This commit is contained in:
Laurent Destailleur 2022-12-29 23:20:46 +01:00
parent 9d777497db
commit 400a168687
5 changed files with 105 additions and 25 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
{

View File

@ -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) {

View File

@ -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 '<div class="fichecenter">';
print '<div class="underbanner clearboth"></div>';
print '<table class="border centpercent">';
print '<table class="border centpercent tableforfield">';
// Ref
/*print '<tr><td class="titlefield">'.$langs->trans('Ref').'</td>';
@ -136,21 +146,26 @@ print $form->showrefnav($object,'id','',1,'rowid','id');
print '</td></tr>';*/
// Date
print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($object->datep, 'day').'</td></tr>';
print '<tr><td>';
print $form->editfieldkey("Date", 'datep', $object->datep, $object, 1, 'datepicker');
print '</td><td>';
print $form->editfieldval("Date", 'datep', $object->datep, $object, 1, 'datepicker');
print "</td>";
print '</tr>';
// Mode
print '<tr><td>'.$langs->trans('Mode').'</td><td colspan="3">';
print '<tr><td>'.$langs->trans('Mode').'</td><td>';
print $langs->trans("PaymentType".$object->type_code);
print '</td></tr>';
// Numero
print '<tr><td>'.$langs->trans('Numero').'</td><td colspan="3">'.$object->num_payment.'</td></tr>';
print '<tr><td>'.$langs->trans('Numero').'</td><td>'.dol_escape_htmltag($object->num_payment).'</td></tr>';
// Montant
print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $outputlangs, 1, -1, -1, $conf->currency).'</td></tr>';
print '<tr><td>'.$langs->trans('Amount').'</td><td colspan="3">'.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).'</td></tr>';
// Note
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($object->note).'</td></tr>';
print '<tr><td>'.$langs->trans('Note').'</td><td colspan="3">'.dol_nl2br($object->note).'</td></tr>';
// Bank account
if (isModEnabled("banque")) {