Fix MVC Actions must be done before output
This commit is contained in:
parent
105a53b333
commit
9f1959ffc8
@ -229,6 +229,103 @@ if (empty($reshook))
|
|||||||
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
|
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($massaction == 'withdrawrequest')
|
||||||
|
{
|
||||||
|
$langs->load("withdrawals");
|
||||||
|
|
||||||
|
if (!$user->rights->prelevement->bons->creer)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Checking error
|
||||||
|
$error = 0;
|
||||||
|
|
||||||
|
$arrayofselected=is_array($toselect)?$toselect:array();
|
||||||
|
$listofbills=array();
|
||||||
|
foreach($arrayofselected as $toselectid)
|
||||||
|
{
|
||||||
|
$objecttmp=new Facture($db);
|
||||||
|
$result=$objecttmp->fetch($toselectid);
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
$totalpaye = $objecttmp->getSommePaiement();
|
||||||
|
$totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
|
||||||
|
$totaldeposits = $objecttmp->getSumDepositsUsed();
|
||||||
|
$objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
|
||||||
|
$listofbills[] = $objecttmp;
|
||||||
|
if($objecttmp->paye || $objecttmp->resteapayer==0){
|
||||||
|
$error++;
|
||||||
|
setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
|
||||||
|
} else if($objecttmp->resteapayer<0){
|
||||||
|
$error++;
|
||||||
|
setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
|
||||||
|
}
|
||||||
|
if(!($objecttmp->statut > Facture::STATUS_DRAFT)){
|
||||||
|
$error++;
|
||||||
|
setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
|
||||||
|
}
|
||||||
|
|
||||||
|
$rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
|
||||||
|
$rsql .= " , pfd.date_traite as date_traite";
|
||||||
|
$rsql .= " , pfd.amount";
|
||||||
|
$rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
|
||||||
|
$rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
|
||||||
|
$rsql .= " , ".MAIN_DB_PREFIX."user as u";
|
||||||
|
$rsql .= " WHERE fk_facture = ".$objecttmp->id;
|
||||||
|
$rsql .= " AND pfd.fk_user_demande = u.rowid";
|
||||||
|
$rsql .= " AND pfd.traite = 0";
|
||||||
|
$rsql .= " ORDER BY pfd.date_demande DESC";
|
||||||
|
|
||||||
|
$result_sql = $db->query($rsql);
|
||||||
|
if ($result_sql)
|
||||||
|
{
|
||||||
|
$numprlv = $db->num_rows($result_sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($numprlv>0){
|
||||||
|
$error++;
|
||||||
|
setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'errors');
|
||||||
|
}
|
||||||
|
if(!empty($objecttmp->mode_reglement_id ) && $objecttmp->mode_reglement_id != 3){
|
||||||
|
$error++;
|
||||||
|
setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Massive withdraw request
|
||||||
|
if(!empty($listofbills) && empty($error))
|
||||||
|
{
|
||||||
|
$nbwithdrawrequestok=0;
|
||||||
|
foreach($listofbills as $aBill)
|
||||||
|
{
|
||||||
|
$db->begin();
|
||||||
|
$result = $aBill->demande_prelevement($user, $aBill->resteapayer);
|
||||||
|
if ($result > 0)
|
||||||
|
{
|
||||||
|
$db->commit();
|
||||||
|
$nbwithdrawrequestok++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
$db->rollback();
|
||||||
|
setEventMessages($aBill->error, $aBill->errors, 'errors');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($nbwithdrawrequestok > 0)
|
||||||
|
{
|
||||||
|
setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -461,8 +558,12 @@ if ($resql)
|
|||||||
$arrayofmassactions=array(
|
$arrayofmassactions=array(
|
||||||
'presend'=>$langs->trans("SendByMail"),
|
'presend'=>$langs->trans("SendByMail"),
|
||||||
'builddoc'=>$langs->trans("PDFMerge"),
|
'builddoc'=>$langs->trans("PDFMerge"),
|
||||||
'withdrawrequest'=>$langs->trans("WithdrawRequest")
|
|
||||||
);
|
);
|
||||||
|
if ($conf->prelevement->enabled)
|
||||||
|
{
|
||||||
|
$langs->load("withdrawals");
|
||||||
|
$arrayofmassactions['withdrawrequest']=$langs->trans("MakeWithdrawRequest");
|
||||||
|
}
|
||||||
if ($user->rights->facture->supprimer)
|
if ($user->rights->facture->supprimer)
|
||||||
{
|
{
|
||||||
//if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED))
|
//if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED))
|
||||||
@ -589,99 +690,6 @@ if ($resql)
|
|||||||
dol_fiche_end();
|
dol_fiche_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($massaction == 'withdrawrequest')
|
|
||||||
{
|
|
||||||
if (!$user->rights->prelevement->bons->creer)
|
|
||||||
{
|
|
||||||
$error++;
|
|
||||||
setEventMessages($langs->trans("NotEnoughPermissions"), $objecttmp->errors, 'errors');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
//Checking error
|
|
||||||
$error = 0;
|
|
||||||
|
|
||||||
$listofbills=array();
|
|
||||||
foreach($arrayofselected as $toselectid)
|
|
||||||
{
|
|
||||||
$objecttmp=new Facture($db);
|
|
||||||
$result=$objecttmp->fetch($toselectid);
|
|
||||||
if ($result > 0)
|
|
||||||
{
|
|
||||||
$totalpaye = $objecttmp->getSommePaiement();
|
|
||||||
$totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
|
|
||||||
$totaldeposits = $objecttmp->getSumDepositsUsed();
|
|
||||||
$objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
|
|
||||||
$listofbills[] = $objecttmp;
|
|
||||||
if($objecttmp->paye || $objecttmp->resteapayer==0){
|
|
||||||
$error++;
|
|
||||||
setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
|
|
||||||
} else if($objecttmp->resteapayer<0){
|
|
||||||
$error++;
|
|
||||||
setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
|
|
||||||
}
|
|
||||||
if(!($objecttmp->statut > Facture::STATUS_DRAFT)){
|
|
||||||
$error++;
|
|
||||||
setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
|
|
||||||
}
|
|
||||||
|
|
||||||
$rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
|
|
||||||
$rsql .= " , pfd.date_traite as date_traite";
|
|
||||||
$rsql .= " , pfd.amount";
|
|
||||||
$rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
|
|
||||||
$rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
|
|
||||||
$rsql .= " , ".MAIN_DB_PREFIX."user as u";
|
|
||||||
$rsql .= " WHERE fk_facture = ".$objecttmp->id;
|
|
||||||
$rsql .= " AND pfd.fk_user_demande = u.rowid";
|
|
||||||
$rsql .= " AND pfd.traite = 0";
|
|
||||||
$rsql .= " ORDER BY pfd.date_demande DESC";
|
|
||||||
|
|
||||||
$result_sql = $db->query($rsql);
|
|
||||||
if ($result_sql)
|
|
||||||
{
|
|
||||||
$numprlv = $db->num_rows($result_sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($numprlv>0){
|
|
||||||
$error++;
|
|
||||||
setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'errors');
|
|
||||||
}
|
|
||||||
if(!empty($objecttmp->mode_reglement_id ) && $objecttmp->mode_reglement_id != 3){
|
|
||||||
$error++;
|
|
||||||
setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//Massive withdraw request
|
|
||||||
if(!empty($listofbills) && empty($error)){
|
|
||||||
|
|
||||||
foreach($listofbills as $aBill)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
$db->begin();
|
|
||||||
$result = $aBill->demande_prelevement($user, $aBill->resteapayer);
|
|
||||||
if ($result > 0)
|
|
||||||
{
|
|
||||||
$db->commit();
|
|
||||||
setEventMessages( $langs->trans("RecordSaved"), null, 'mesgs');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
|
|
||||||
$db->rollback();
|
|
||||||
setEventMessages($aBill->error, $aBill->errors, 'errors');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sall)
|
if ($sall)
|
||||||
{
|
{
|
||||||
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
|
foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
|
||||||
|
|||||||
@ -24,6 +24,7 @@ WithdrawStatistics=Direct debit payment statistics
|
|||||||
WithdrawRejectStatistics=Direct debit payment reject statistics
|
WithdrawRejectStatistics=Direct debit payment reject statistics
|
||||||
LastWithdrawalReceipt=Latest %s direct debit receipts
|
LastWithdrawalReceipt=Latest %s direct debit receipts
|
||||||
MakeWithdrawRequest=Make a direct debit payment request
|
MakeWithdrawRequest=Make a direct debit payment request
|
||||||
|
WithdrawRequestsDone=%s direct debit payment requests recorded
|
||||||
ThirdPartyBankCode=Third party bank code
|
ThirdPartyBankCode=Third party bank code
|
||||||
NoInvoiceCouldBeWithdrawed=No invoice withdrawed with success. Check that invoice are on companies with a valid BAN.
|
NoInvoiceCouldBeWithdrawed=No invoice withdrawed with success. Check that invoice are on companies with a valid BAN.
|
||||||
ClassCredited=Classify credited
|
ClassCredited=Classify credited
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user