Fix: Delete a social contribution payment fails
This commit is contained in:
parent
853969d90d
commit
2637707760
@ -47,7 +47,7 @@ if ($_POST["action"] == 'add_paiement')
|
|||||||
if ($_POST["cancel"])
|
if ($_POST["cancel"])
|
||||||
{
|
{
|
||||||
$loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid;
|
$loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid;
|
||||||
Header("Location: $loc");
|
Header("Location: ".$loc);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +63,11 @@ if ($_POST["action"] == 'add_paiement')
|
|||||||
$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date"));
|
$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date"));
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
if ($conf->banque->enabled && ! $_POST["accountid"] > 0)
|
||||||
|
{
|
||||||
|
$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit"));
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
@ -108,7 +113,7 @@ if ($_POST["action"] == 'add_paiement')
|
|||||||
$langs->load("banks");
|
$langs->load("banks");
|
||||||
$label = $langs->transnoentities("SocialContributionPayment");
|
$label = $langs->transnoentities("SocialContributionPayment");
|
||||||
$acc = new Account($db, $_POST["accountid"]);
|
$acc = new Account($db, $_POST["accountid"]);
|
||||||
$bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -abs($total), $paiement->num_paiement, '', $user);
|
$bank_line_id = $acc->addline($paiement->datepaye, $paiement->paiementtype, $label, -$total, $paiement->num_paiement, '', $user);
|
||||||
|
|
||||||
// Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a genere l'ecriture bancaire
|
// Mise a jour fk_bank dans llx_paiementcharge. On connait ainsi le paiement qui a genere l'ecriture bancaire
|
||||||
if ($bank_line_id > 0)
|
if ($bank_line_id > 0)
|
||||||
@ -125,7 +130,7 @@ if ($_POST["action"] == 'add_paiement')
|
|||||||
$db->commit();
|
$db->commit();
|
||||||
|
|
||||||
$loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid;
|
$loc = DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$chid;
|
||||||
Header("Location: $loc");
|
Header("Location: ".$loc);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -136,7 +141,7 @@ if ($_POST["action"] == 'add_paiement')
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$db->rollback();
|
$db->rollback();
|
||||||
$mesg = "Failed to create payment: paiement_id=$paymentid ".$db->error();
|
$mesg = "Failed to create payment: paiement_id=".$paymentid." ".$db->error();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,13 +213,14 @@ if ($_GET["action"] == 'create')
|
|||||||
print "<input type=\"hidden\" name=\"chid\" value=\"$chid\">";
|
print "<input type=\"hidden\" name=\"chid\" value=\"$chid\">";
|
||||||
|
|
||||||
print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
|
print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td>';
|
||||||
$datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
|
$datepaye = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
|
||||||
|
$datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0;
|
||||||
$html->select_date($datepayment,'','','','',"add_paiement",1,1);
|
$html->select_date($datepayment,'','','','',"add_paiement",1,1);
|
||||||
print "</td>";
|
print "</td>";
|
||||||
print '<td>'.$langs->trans("Comments").'</td></tr>';
|
print '<td>'.$langs->trans("Comments").'</td></tr>';
|
||||||
|
|
||||||
print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
|
print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
|
||||||
$html->select_types_paiements($charge->paiementtype, "paiementtype");
|
$html->select_types_paiements(isset($_POST["paiementtype"])?$_POST["paiementtype"]:$charge->paiementtype, "paiementtype");
|
||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
|
|
||||||
print '<td rowspan="3" valign="top"><textarea name="comment" wrap="soft" cols="40" rows="'.ROWS_3.'"></textarea></td></tr>';
|
print '<td rowspan="3" valign="top"><textarea name="comment" wrap="soft" cols="40" rows="'.ROWS_3.'"></textarea></td></tr>';
|
||||||
@ -222,7 +228,7 @@ if ($_GET["action"] == 'create')
|
|||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td class="fieldrequired">'.$langs->trans('AccountToCredit').'</td>';
|
print '<td class="fieldrequired">'.$langs->trans('AccountToCredit').'</td>';
|
||||||
print '<td>';
|
print '<td>';
|
||||||
$html->select_comptes($charge->accountid, "accountid", 0, "courant=1"); // Affiche liste des comptes courant
|
$html->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$charge->accountid, "accountid", 0, "courant=1",1); // Affiche liste des comptes courant
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans('Numero');
|
print '<tr><td>'.$langs->trans('Numero');
|
||||||
@ -235,7 +241,8 @@ if ($_GET["action"] == 'create')
|
|||||||
$num = 1;
|
$num = 1;
|
||||||
$i = 0;
|
$i = 0;
|
||||||
print '<tr><td colspan="3">';
|
print '<tr><td colspan="3">';
|
||||||
print '<table class="noborder" width="100%">';
|
|
||||||
|
print '<table class="nobordernopadding" width="100%">';
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
//print '<td>'.$langs->trans("SocialContribution").'</td>';
|
//print '<td>'.$langs->trans("SocialContribution").'</td>';
|
||||||
print '<td align="left">'.$langs->trans("DateDue").'</td>';
|
print '<td align="left">'.$langs->trans("DateDue").'</td>';
|
||||||
|
|||||||
@ -51,17 +51,18 @@ $mesg='';
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && $user->rights->facture->paiement)
|
// Delete payment
|
||||||
|
if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' && $user->rights->tax->charges->supprimer)
|
||||||
{
|
{
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
$paiement = new PaiementCharge($db);
|
$paiement = new PaiementCharge($db);
|
||||||
$paiement->fetch($_GET['id']);
|
$paiement->fetch($_REQUEST['id']);
|
||||||
$result = $paiement->delete();
|
$result = $paiement->delete($user);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
Header("Location: liste.php");
|
Header("Location: ".DOL_URL_ROOT."/compta/charges/index.php?mode=sconly");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -71,12 +72,13 @@ if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes' &&
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' && $user->rights->facture->paiement)
|
// Create payment
|
||||||
|
if ($_REQUEST['action'] == 'confirm_valide' && $_REQUEST['confirm'] == 'yes' && $user->rights->tax->charges->creer)
|
||||||
{
|
{
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
$paiement = new PaiementCharge($db);
|
$paiement = new PaiementCharge($db);
|
||||||
$paiement->id = $_GET['id'];
|
$paiement->id = $_REQUEST['id'];
|
||||||
if ($paiement->valide() > 0)
|
if ($paiement->valide() > 0)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit();
|
||||||
@ -283,9 +285,9 @@ print '</div>';
|
|||||||
/*
|
/*
|
||||||
* Boutons Actions
|
* Boutons Actions
|
||||||
*/
|
*/
|
||||||
/*
|
|
||||||
print '<div class="tabsAction">';
|
print '<div class="tabsAction">';
|
||||||
|
|
||||||
|
/*
|
||||||
if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
|
if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
|
||||||
{
|
{
|
||||||
if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET['action'] == '')
|
if ($user->societe_id == 0 && $paiement->statut == 0 && $_GET['action'] == '')
|
||||||
@ -296,10 +298,11 @@ if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
if ($user->societe_id == 0 && $_GET['action'] == '')
|
if ($_GET['action'] == '')
|
||||||
{
|
{
|
||||||
if ($user->rights->facture->paiement)
|
if ($user->rights->tax->charges->supprimer)
|
||||||
{
|
{
|
||||||
if (! $disable_delete)
|
if (! $disable_delete)
|
||||||
{
|
{
|
||||||
@ -313,7 +316,7 @@ if ($user->societe_id == 0 && $_GET['action'] == '')
|
|||||||
}
|
}
|
||||||
|
|
||||||
print '</div>';
|
print '</div>';
|
||||||
*/
|
|
||||||
|
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|
||||||
|
|||||||
@ -396,6 +396,8 @@ if ($chid > 0)
|
|||||||
else {
|
else {
|
||||||
print "<tr><td>".$langs->trans("DateDue")."</td><td>".dol_print_date($cha->date_ech,'day')."</td></tr>";
|
print "<tr><td>".$langs->trans("DateDue")."</td><td>".dol_print_date($cha->date_ech,'day')."</td></tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Amount
|
||||||
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($cha->amount).'</td></tr>';
|
print '<tr><td>'.$langs->trans("AmountTTC").'</td><td>'.price($cha->amount).'</td></tr>';
|
||||||
|
|
||||||
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$cha->getLibStatut(4).'</td></tr>';
|
print '<tr><td>'.$langs->trans("Status").'</td><td>'.$cha->getLibStatut(4).'</td></tr>';
|
||||||
@ -432,7 +434,7 @@ if ($chid > 0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Emettre paiement
|
// Emettre paiement
|
||||||
if ($cha->paye == 0 && round($resteapayer) > 0 && $user->rights->tax->charges->creer)
|
if ($cha->paye == 0 && ((price2num($cha->amount) < 0 && round($resteapayer) < 0) || (price2num($cha->amount) > 0 && round($resteapayer) > 0)) && $user->rights->tax->charges->creer)
|
||||||
{
|
{
|
||||||
print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/paiement_charge.php?id=$cha->id&action=create\">".$langs->trans("DoPayment")."</a>";
|
print "<a class=\"butAction\" href=\"".DOL_URL_ROOT."/compta/paiement_charge.php?id=$cha->id&action=create\">".$langs->trans("DoPayment")."</a>";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -398,6 +398,7 @@ class PaiementCharge extends CommonObject
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$now=dol_now();
|
||||||
|
|
||||||
// Clean parameters
|
// Clean parameters
|
||||||
if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge);
|
if (isset($this->fk_charge)) $this->fk_charge=trim($this->fk_charge);
|
||||||
@ -419,14 +420,14 @@ class PaiementCharge extends CommonObject
|
|||||||
$total += $amount;
|
$total += $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($total > 0)
|
if ($total != 0)
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount,";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."paiementcharge (fk_charge, datec, datep, amount,";
|
||||||
$sql.= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
|
$sql.= " fk_typepaiement, num_paiement, note, fk_user_creat, fk_bank)";
|
||||||
$sql.= " VALUES ($this->chid, ".$this->db->idate(mktime()).", ";
|
$sql.= " VALUES ($this->chid, '".$this->db->idate($now)."', ";
|
||||||
$sql.= $this->db->idate($this->datepaye).", ";
|
$sql.= " '".$this->db->idate($this->datepaye)."', ";
|
||||||
$sql.= price2num($total);
|
$sql.= price2num($total);
|
||||||
$sql.= ", ".$this->paiementtype.", '".$this->num_paiement."', '".addslashes($this->note)."', ".$user->id.",";
|
$sql.= ", ".$this->paiementtype.", '".addslashes($this->num_paiement)."', '".addslashes($this->note)."', ".$user->id.",";
|
||||||
$sql.= "0)";
|
$sql.= "0)";
|
||||||
|
|
||||||
dol_syslog("PaiementCharge::create sql=".$sql);
|
dol_syslog("PaiementCharge::create sql=".$sql);
|
||||||
@ -442,7 +443,7 @@ class PaiementCharge extends CommonObject
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($total > 0 && ! $error)
|
if ($total != 0 && ! $error)
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return $this->id;
|
return $this->id;
|
||||||
@ -622,14 +623,27 @@ class PaiementCharge extends CommonObject
|
|||||||
global $conf, $langs;
|
global $conf, $langs;
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge";
|
|
||||||
$sql.= " WHERE rowid=".$this->id;
|
|
||||||
|
|
||||||
$this->db->begin();
|
$this->db->begin();
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url";
|
||||||
|
$sql.= " WHERE type='payment_sc' AND url_id=".$this->id;
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::delete sql=".$sql);
|
dol_syslog(get_class($this)."::delete sql=".$sql);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge";
|
||||||
|
$sql.= " WHERE rowid=".$this->id;
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::delete sql=".$sql);
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
|
||||||
|
}
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user