From c4f27cc29f1376d90d0c73bdd1f334ccb8649fd8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 18 Apr 2021 16:43:09 +0200 Subject: [PATCH] Debug module salary --- htdocs/salaries/card.php | 13 +++++----- htdocs/salaries/class/salary.class.php | 10 ++++++-- htdocs/salaries/list.php | 4 +++ htdocs/user/bank.php | 35 ++++++++++++++++++-------- 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/htdocs/salaries/card.php b/htdocs/salaries/card.php index ad28bcca999..5b6134d192d 100755 --- a/htdocs/salaries/card.php +++ b/htdocs/salaries/card.php @@ -213,10 +213,11 @@ if ($action == 'add' && empty($cancel)) { } if (!$error) { + $db->begin(); + $ret = $object->create($user); if ($ret < 0) $error++; if (!empty($auto_create_paiement) && !$error) { - $db->begin(); // Create a line of payments $paiement = new PaymentSalary($db); $paiement->chid = $object->id; @@ -243,15 +244,11 @@ if ($action == 'add' && empty($cancel)) { setEventMessages($paiement->error, null, 'errors'); } } - - if (!$error) { - $db->commit(); - } else { - $db->rollback(); - } } if (empty($error)) { + $db->commit(); + 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')); @@ -260,6 +257,8 @@ if ($action == 'add' && empty($cancel)) { header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $object->id); exit; } + } else { + $db->rollback(); } } diff --git a/htdocs/salaries/class/salary.class.php b/htdocs/salaries/class/salary.class.php index 85ccfc0a1db..94ede5d7a4d 100644 --- a/htdocs/salaries/class/salary.class.php +++ b/htdocs/salaries/class/salary.class.php @@ -498,6 +498,12 @@ class Salary extends CommonObject $label = ''.$langs->trans("Salary").''; $label .= '
'; $label .= ''.$langs->trans('Ref').': '.$this->ref; + if ($this->label) { + $label .= '
'.$langs->trans('Label').': '.$this->label; + } + if ($this->datesp && $this->dateep) { + $label .= '
'.$langs->trans('Period').': '.dol_print_date($this->datesp, 'day').' - '.dol_print_date($this->dateep, 'day'); + } $url = DOL_URL_ROOT.'/salaries/card.php?id='.$this->id; @@ -647,9 +653,9 @@ class Salary extends CommonObject /** * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) * - * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto * @param double $alreadypaid 0=No payment already done, >0=Some payments were already done (we recommand to put here amount payed if you have it, 1 otherwise) - * @return string Libelle + * @return string Label */ public function getLibStatut($mode = 0, $alreadypaid = -1) { diff --git a/htdocs/salaries/list.php b/htdocs/salaries/list.php index b35b890b994..382e05e4f0d 100644 --- a/htdocs/salaries/list.php +++ b/htdocs/salaries/list.php @@ -532,6 +532,10 @@ while ($i < ($limit ? min($num, $limit) : $num)) { $salstatic->id = $obj->rowid; $salstatic->ref = $obj->rowid; + $salstatic->label = $obj->label; + $salstatic->paye = $obj->paye; + $salstatic->datesp = $db->jdate($obj->datesp); + $salstatic->dateep = $db->jdate($obj->dateep); // Show here line of result print ''; diff --git a/htdocs/user/bank.php b/htdocs/user/bank.php index df5757992f0..356e23a5de0 100644 --- a/htdocs/user/bank.php +++ b/htdocs/user/bank.php @@ -40,6 +40,7 @@ if (!empty($conf->expensereport->enabled)) { require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; } if (!empty($conf->salaries->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php'; require_once DOL_DOCUMENT_ROOT.'/salaries/class/paymentsalary.class.php'; } @@ -354,16 +355,18 @@ if ($action != 'edit' && $action != 'create') { // If not bank account yet, $ac // Latest payments of salaries if (!empty($conf->salaries->enabled) && - $user->rights->salaries->read && (in_array($object->id, $childids) || $object->id == $user->id) + (($user->rights->salaries->read && (in_array($object->id, $childids) || $object->id == $user->id)) || (!empty($user->rights->salaries->readall))) ) { $payment_salary = new PaymentSalary($db); + $salary = new Salary($db); - $sql = "SELECT ps.rowid, s.datesp, s.dateep, ps.amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as ps"; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as s ON (s.rowid = ps.fk_salary)"; + $sql = "SELECT s.rowid as sid, s.ref as sref, s.label, s.datesp, s.dateep, s.paye, SUM(ps.amount) as alreadypaid"; + $sql .= " FROM ".MAIN_DB_PREFIX."salary as s"; + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_salary as ps ON (s.rowid = ps.fk_salary)"; $sql .= " WHERE s.fk_user = ".$object->id; - $sql .= " AND ps.entity = ".$conf->entity; - $sql .= " ORDER BY ps.rowid DESC"; + $sql .= " AND s.entity IN (".getEntity('salary').")"; + $sql .= " GROUP BY s.rowid, s.ref, s.label, s.datesp, s.dateep, s.paye"; + $sql .= " ORDER BY s.dateep DESC"; $resql = $db->query($sql); if ($resql) { @@ -372,7 +375,7 @@ if ($action != 'edit' && $action != 'create') { // If not bank account yet, $ac print ''; print ''; - print '
'; + print ''; print ''; @@ -380,16 +383,26 @@ if ($action != 'edit' && $action != 'create') { // If not bank account yet, $ac while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object($resql); + $payment_salary->id = $objp->rowid; + $payment_salary->ref = $objp->ref; + $payment_salary->datep = $db->jdate($objp->datep); + + $salary->id = $objp->sid; + $salary->ref = $objp->sref ? $objp->sref : $objp->sid; + $salary->label = $objp->label; + $salary->datesp = $db->jdate($objp->datesp); + $salary->dateep = $db->jdate($objp->dateep); + $salary->paye = $objp->paye; + print ''; print ''; print '\n"; print '\n"; - print ''; + //print ''; + print ''; print ''; $i++;
'.$langs->trans("LastSalaries", ($num <= $MAXLIST ? "" : $MAXLIST)).''.$langs->trans("AllSalaries").''.$num.''; print '
'.$langs->trans("LastSalaries", ($num <= $MAXLIST ? "" : $MAXLIST)).''.$langs->trans("AllSalaries").''.$num.'
'; - $payment_salary->id = $objp->rowid; - $payment_salary->ref = $objp->rowid; - print $payment_salary->getNomUrl(1); + print $salary->getNomUrl(1); print ''.dol_print_date($db->jdate($objp->datesp), 'day')."'.dol_print_date($db->jdate($objp->dateep), 'day')."'.price($objp->amount).''.price($objp->amount).''.$salary->getLibStatut(5, $objp->alreadypaid).'