FIX Remove a total that has no sense

This commit is contained in:
Laurent Destailleur 2016-04-22 17:11:12 +02:00
parent 2cc24db6a2
commit 25b7f0ab62
3 changed files with 63 additions and 32 deletions

View File

@ -200,7 +200,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
$i++; $i++;
} }
print '<tr class="liste_total"><td colspan="3" class="liste_total">'.$langs->trans("Total").'</td>'; print '<tr class="liste_total"><td colspan="3" class="liste_total">'.$langs->trans("Total").'</td>';
print '<td align="right" class="liste_total">'.price($total)."</td>"; print '<td align="right" class="liste_total"></td>'; // A total here has no sense
print '<td align="center" class="liste_total">&nbsp;</td>'; print '<td align="center" class="liste_total">&nbsp;</td>';
print '<td align="center" class="liste_total">&nbsp;</td>'; print '<td align="center" class="liste_total">&nbsp;</td>';
print '<td align="center" class="liste_total">&nbsp;</td>'; print '<td align="center" class="liste_total">&nbsp;</td>';
@ -278,7 +278,7 @@ if (! empty($conf->tax->enabled) && $user->rights->tax->charges->lire)
$i++; $i++;
} }
print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").'</td>'; print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").'</td>';
print '<td align="right">'.price($total)."</td>"; print '<td align="right">'.price($total).'</td>';
print '<td align="center">&nbsp;</td>'; print '<td align="center">&nbsp;</td>';
print '<td align="center">&nbsp;</td>'; print '<td align="center">&nbsp;</td>';
print '<td align="right">'.price($total)."</td>"; print '<td align="right">'.price($total)."</td>";
@ -463,7 +463,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read)
$i++; $i++;
} }
print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").'</td>'; print '<tr class="liste_total"><td colspan="2">'.$langs->trans("Total").'</td>';
print '<td align="right">'."</td>"; print '<td align="right"></td>'; // A total here has no sense
print '<td align="center">&nbsp;</td>'; print '<td align="center">&nbsp;</td>';
print '<td align="center">&nbsp;</td>'; print '<td align="center">&nbsp;</td>';
print '<td align="right">'.price($total)."</td>"; print '<td align="right">'.price($total)."</td>";

View File

@ -39,6 +39,7 @@ $socid = GETPOST('socid','int');
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); $result = restrictedArea($user, 'tax', $id, 'chargesociales','charges');
$object = new ChargeSociales($db);
@ -49,19 +50,32 @@ $result = restrictedArea($user, 'tax', $id, 'chargesociales','charges');
/* *************************************************************************** */ /* *************************************************************************** */
// Classify paid // Classify paid
if ($action == 'confirm_paid' && $confirm == 'yes') if ($action == 'confirm_paid' && $user->rights->tax->charges->creer && $confirm == 'yes')
{ {
$chargesociales = new ChargeSociales($db); $object->fetch($id);
$chargesociales->fetch($id); $result = $object->set_paid($user);
$result = $chargesociales->set_paid($user); }
if ($action == 'reopen' && $user->rights->tax->charges->creer) {
$result = $object->fetch($id);
if ($object->paye)
{
$result = $object->set_unpaid($user);
if ($result > 0)
{
header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id);
exit();
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
} }
// Delete social contribution // Delete social contribution
if ($action == 'confirm_delete' && $confirm == 'yes') if ($action == 'confirm_delete' && $confirm == 'yes')
{ {
$chargesociales=new ChargeSociales($db); $object->fetch($id);
$chargesociales->fetch($id); $result=$object->delete($user);
$result=$chargesociales->delete($user);
if ($result > 0) if ($result > 0)
{ {
header("Location: index.php"); header("Location: index.php");
@ -69,7 +83,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes')
} }
else else
{ {
setEventMessages($chargesociales->error, $chargesociales->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
} }
@ -77,8 +91,8 @@ if ($action == 'confirm_delete' && $confirm == 'yes')
// Add social contribution // Add social contribution
if ($action == 'add' && $user->rights->tax->charges->creer) if ($action == 'add' && $user->rights->tax->charges->creer)
{ {
$dateech=@dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear')); $dateech=dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear'));
$dateperiod=@dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear')); $dateperiod=dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear'));
$amount=price2num(GETPOST('amount')); $amount=price2num(GETPOST('amount'));
$actioncode=GETPOST('actioncode'); $actioncode=GETPOST('actioncode');
if (! $dateech) if (! $dateech)
@ -108,18 +122,16 @@ if ($action == 'add' && $user->rights->tax->charges->creer)
} }
else else
{ {
$chargesociales=new ChargeSociales($db); $object->type=$actioncode;
$object->lib=GETPOST('label');
$object->date_ech=$dateech;
$object->periode=$dateperiod;
$object->amount=$amount;
$chargesociales->type=$actioncode; $id=$object->create($user);
$chargesociales->lib=GETPOST('label');
$chargesociales->date_ech=$dateech;
$chargesociales->periode=$dateperiod;
$chargesociales->amount=$amount;
$id=$chargesociales->create($user);
if ($id <= 0) if ($id <= 0)
{ {
setEventMessages($chargesociales->error, $chargesociales->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
$action='create'; $action='create';
} }
} }
@ -153,18 +165,17 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->cr
} }
else else
{ {
$chargesociales=new ChargeSociales($db); $result=$object->fetch($id);
$result=$chargesociales->fetch($id);
$chargesociales->lib=GETPOST('label'); $object->lib=GETPOST('label');
$chargesociales->date_ech=$dateech; $object->date_ech=$dateech;
$chargesociales->periode=$dateperiod; $object->periode=$dateperiod;
$chargesociales->amount=price2num($amount); $object->amount=price2num($amount);
$result=$chargesociales->update($user); $result=$object->update($user);
if ($result <= 0) if ($result <= 0)
{ {
setEventMessages($chargesociales->error, $chargesociales->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
} }
} }
@ -178,7 +189,6 @@ if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->tax->char
$originalId = $id; $originalId = $id;
$object = new ChargeSociales($db);
$object->fetch($id); $object->fetch($id);
if ($object->id > 0) if ($object->id > 0)
@ -499,6 +509,12 @@ if ($id > 0)
{ {
print "<div class=\"tabsAction\">\n"; print "<div class=\"tabsAction\">\n";
// Reopen
if ($object->paye && $user->rights->tax->charges->creer)
{
print "<a class=\"butAction\" href=\"".dol_buildpath("/compta/sociales/charges.php",1). "?id=$object->id&amp;action=reopen\">".$langs->trans("ReOpen")."</a>";
}
// Edit // Edit
if ($object->paye == 0 && $user->rights->tax->charges->creer) if ($object->paye == 0 && $user->rights->tax->charges->creer)
{ {

View File

@ -339,6 +339,21 @@ class ChargeSociales extends CommonObject
if ($return) return 1; if ($return) return 1;
else return -1; else return -1;
} }
/**
* Remove tag payed on social contribution
*
* @param User $user Object user making change
* @return int <0 if KO, >0 if OK
*/
function set_unpaid($user)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET";
$sql.= " paye = 0";
$sql.= " WHERE rowid = ".$this->id;
$return = $this->db->query($sql);
if ($return) return 1;
else return -1;
}
/** /**
* Retourne le libelle du statut d'une charge (impaye, payee) * Retourne le libelle du statut d'une charge (impaye, payee)