Clean code

This commit is contained in:
Laurent Destailleur 2021-03-04 17:23:12 +01:00
parent 10a6774ede
commit 6eafc3b774
4 changed files with 37 additions and 172 deletions

View File

@ -207,7 +207,7 @@ if (($action == 'searchfiles' || $action == 'dl')) {
$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).')';
//$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT;
//$sql.=" AND fk_statut <> ".PaymentSalary::STATUS_DRAFT;
}
// Social contributions
if (GETPOST('selectsocialcontributions')) {

View File

@ -415,6 +415,8 @@ while ($j < $numlt) {
$num = $db->num_rows($result);
$i = 0;
$total = 0;
print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "pv.datev", "", $param, 'width="120"', $sortfield, $sortorder);
@ -456,6 +458,8 @@ while ($j < $numlt) {
print "</tr>";
print "</table>";
print '</div>';
$db->free($result);
} else {
dol_print_error($db);
@ -464,115 +468,6 @@ while ($j < $numlt) {
$j++;
}
// Payment Salary
/*
if (!empty($conf->salaries->enabled) && !empty($user->rights->salaries->read))
{
$sal = new Salary($db);
print "<br>";
print load_fiche_titre($langs->trans("SalariesPayments").($year ? ' ('.$langs->trans("Year").' '.$year.')' : ''), '', '');
$sql = "SELECT s.rowid, s.amount, s.label, s.datep as datep, s.datev as datev, s.datesp, s.dateep, s.salary, s.fk_bank, u.salary as current_salary,";
$sql .= " pct.code as payment_code,";
$sql .= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel";
$sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as s";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON s.fk_bank = b.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pct ON s.fk_typepayment = pct.id";
$sql .= " , ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE s.entity IN (".getEntity('user').")";
$sql .= " AND u.rowid = s.fk_user";
if ($year > 0)
{
$sql .= " AND (s.datesp between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'";
$sql .= " OR s.dateep between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."')";
}
if (preg_match('/^s\./', $sortfield)) $sql .= $db->order($sortfield, $sortorder);
$result = $db->query($sql);
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
$total = 0;
print '<table class="noborder centpercent">';
print '<tr class="liste_titre">';
print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "s.dateep", "", $param, 'width="140px"', $sortfield, $sortorder);
print_liste_field_titre("Label", $_SERVER["PHP_SELF"], "s.label", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "s.rowid", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "s.datep", "", $param, 'align="center"', $sortfield, $sortorder);
print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder);
if (!empty($conf->banque->enabled)) print_liste_field_titre("Account", $_SERVER["PHP_SELF"], "ba.label", "", $param, "", $sortfield, $sortorder);
print_liste_field_titre("PayedByThisPayment", $_SERVER["PHP_SELF"], "s.amount", "", $param, 'class="right"', $sortfield, $sortorder);
print "</tr>\n";
while ($i < $num)
{
$obj = $db->fetch_object($result);
$total = $total + $obj->amount;
print '<tr class="oddeven">';
print '<td class="left">'.dol_print_date($db->jdate($obj->dateep), 'day').'</td>'."\n";
print "<td>".$obj->label."</td>\n";
// Ref payment
$sal_static->id = $obj->rowid;
$sal_static->ref = $obj->rowid;
print '<td class="left">'.$sal_static->getNomUrl(1)."</td>\n";
// Date
print '<td class="center">'.dol_print_date($db->jdate($obj->datep), 'day')."</td>\n";
// Type payment
print '<td>';
if ($obj->payment_code) print $langs->trans("PaymentTypeShort".$obj->payment_code).' ';
print $obj->num_payment.'</td>';
// Account
if (!empty($conf->banque->enabled))
{
print '<td>';
if ($obj->fk_bank > 0)
{
//$accountstatic->fetch($obj->fk_bank);
$accountstatic->id = $obj->bid;
$accountstatic->ref = $obj->bref;
$accountstatic->number = $obj->bnumber;
$accountstatic->accountancy_number = $obj->account_number;
$accountstatic->accountancy_journal = $obj->accountancy_journal;
$accountstatic->label = $obj->blabel;
print $accountstatic->getNomUrl(1);
} else print '&nbsp;';
print '</td>';
}
// Paid
print '<td class="right">'.price($obj->amount)."</td>";
print "</tr>\n";
$i++;
}
print '<tr class="liste_total"><td colspan="6">'.$langs->trans("Total").'</td>';
print '<td class="right">'.price($total)."</td>";
print "</tr>";
print "</table>";
$db->free($result);
print "<br>";
} else {
dol_print_error($db);
}
}
*/
print '</form>';
$parameters = array('user' => $user);

View File

@ -34,7 +34,7 @@ function salaries_prepare_head($object)
$head = array();
$head[$h][0] = DOL_URL_ROOT.'/salaries/card.php?id='.$object->id;
$head[$h][1] = $langs->trans("Salary");
$head[$h][1] = $langs->trans("Salary");
$head[$h][2] = 'card';
$h++;

View File

@ -37,8 +37,7 @@ $amounts = array();
// Security check
$socid = 0;
if ($user->socid > 0)
{
if ($user->socid > 0) {
$socid = $user->socid;
}
@ -47,61 +46,51 @@ if ($user->socid > 0)
* Actions
*/
if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes'))
{
if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'yes')) {
$error = 0;
if ($_POST["cancel"])
{
if ($_POST["cancel"]) {
$loc = DOL_URL_ROOT.'/salaries/card.php?id='.$chid;
header("Location: ".$loc);
exit;
}
$datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
$datepaye = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST("reday", 'int'), GETPOST("reyear", 'int'));
if (!$_POST["paiementtype"] > 0)
{
if (!(GETPOST("paiementtype", 'int') > 0)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode")), null, 'errors');
$error++;
$action = 'create';
}
if ($datepaye == '')
{
if ($datepaye == '') {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Date")), null, 'errors');
$error++;
$action = 'create';
}
if (!empty($conf->banque->enabled) && !($_POST["accountid"] > 0))
{
if (!empty($conf->banque->enabled) && !(GETPOST("accountid", 'int') > 0)) {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AccountToCredit")), null, 'errors');
$error++;
$action = 'create';
}
if (!$error)
{
if (!$error) {
$paymentid = 0;
// Read possible payments
foreach ($_POST as $key => $value)
{
if (substr($key, 0, 7) == 'amount_')
{
foreach ($_POST as $key => $value) {
if (substr($key, 0, 7) == 'amount_') {
$other_chid = substr($key, 7);
$amounts[$other_chid] = price2num($_POST[$key]);
}
}
if (count($amounts) <= 0)
{
if (count($amounts) <= 0) {
$error++;
setEventMessages($langs->trans("ErrorNoPaymentDefined"), null, 'errors');
$action = 'create';
}
if (!$error)
{
if (!$error) {
$db->begin();
// Create a line of payments
@ -114,36 +103,30 @@ if ($action == 'add_payment' || ($action == 'confirm_paiement' && $confirm == 'y
$paiement->note = GETPOST("note", 'none');
$paiement->note_private = GETPOST("note", 'none');
if (!$error)
{
if (!$error) {
$paymentid = $paiement->create($user, (GETPOST('closepaidsalary') == 'on' ? 1 : 0));
if ($paymentid < 0)
{
if ($paymentid < 0) {
$error++;
setEventMessages($paiement->error, null, 'errors');
$action = 'create';
}
}
if (!$error)
{
if (!$error) {
$result = $paiement->addPaymentToBank($user, 'payment_salary', '(SalaryPayment)', GETPOST('accountid', 'int'), '', '');
if (!($result > 0))
{
if (!($result > 0)) {
$error++;
setEventMessages($paiement->error, null, 'errors');
$action = 'create';
}
}
if (!$error)
{
if (!$error) {
$db->commit();
$loc = DOL_URL_ROOT.'/salaries/card.php?id='.$chid;
header('Location: '.$loc);
exit;
}
else {
} else {
$db->rollback();
}
}
@ -161,16 +144,14 @@ $form = new Form($db);
// Formulaire de creation d'un paiement de charge
if ($action == 'create')
{
if ($action == 'create') {
$salary = new Salary($db);
$salary->fetch($chid);
$salary->accountid = $salary->fk_account ? $salary->fk_account : $salary->accountid;
$salary->paiementtype = $salary->mode_reglement_id ? $salary->mode_reglement_id : $salary->paiementtype;
$total = $salary->amount;
if (!empty($conf->use_javascript_ajax))
{
if (!empty($conf->use_javascript_ajax)) {
print "\n".'<script type="text/javascript" language="javascript">';
//Add js for AutoFill
@ -187,11 +168,6 @@ if ($action == 'create')
print load_fiche_titre($langs->trans("DoPayment"));
print "<br>\n";
if ($mesg)
{
print "<div class=\"error\">$mesg</div>";
}
print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="id" value="'.$chid.'">';
@ -213,8 +189,7 @@ if ($action == 'create')
$sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p";
$sql .= " WHERE p.fk_salary = ".$chid;
$resql = $db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $db->fetch_object($resql);
$sumpaid = $obj->total;
$db->free();
@ -274,18 +249,15 @@ if ($action == 'create')
$total = 0;
$totalrecu = 0;
while ($i < $num)
{
while ($i < $num) {
$objp = $salary;
print '<tr class="oddeven">';
if ($objp->dateep > 0)
{
if ($objp->dateep > 0) {
print '<td class="left">'.dol_print_date($objp->dateep, 'day').'</td>'."\n";
}
else {
print "<td align=\"center\"><b>!!!</b></td>\n";
} else {
print '<td align="center"><b>!!!</b></td>'."\n";
}
print '<td class="right">'.price($objp->amount)."</td>";
@ -295,17 +267,16 @@ if ($action == 'create')
print '<td class="right">'.price($objp->amount - $sumpaid)."</td>";
print '<td class="center">';
if ($sumpaid < $objp->amount)
{
if ($sumpaid < $objp->amount) {
$namef = "amount_".$objp->id;
$nameRemain = "remain_".$objp->id;
if (!empty($conf->use_javascript_ajax))
print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'");
if (!empty($conf->use_javascript_ajax)) {
print img_picto("Auto fill", 'rightarrow', "class='AutoFillAmount' data-rowid='".$namef."' data-value='".($objp->amount - $sumpaid)."'");
}
$remaintopay = $objp->amount - $sumpaid;
print '<input type=hidden class="sum_remain" name="'.$nameRemain.'" value="'.$remaintopay.'">';
print '<input type="text" size="8" name="'.$namef.'" id="'.$namef.'">';
}
else {
} else {
print '-';
}
print "</td>";
@ -316,8 +287,7 @@ if ($action == 'create')
$totalrecu += $objp->am;
$i++;
}
if ($i > 1)
{
if ($i > 1) {
// Print total
print '<tr class="oddeven">';
print '<td colspan="2" class="left">'.$langs->trans("Total").':</td>';