Massive withdrawal request
This commit is contained in:
parent
1878647d26
commit
39a92df647
@ -460,7 +460,8 @@ 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 ($user->rights->facture->supprimer)
|
if ($user->rights->facture->supprimer)
|
||||||
{
|
{
|
||||||
@ -587,6 +588,95 @@ 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');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//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)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -489,3 +489,4 @@ DeleteRepeatableInvoice=Supprimer facture modèle
|
|||||||
ConfirmDeleteRepeatableInvoice=Est-ce votre sûr de vouloir supprimer la facture modèle ?
|
ConfirmDeleteRepeatableInvoice=Est-ce votre sûr de vouloir supprimer la facture modèle ?
|
||||||
CreateOneBillByThird=Créer une facture par tiers (sinon, une facture par commande)
|
CreateOneBillByThird=Créer une facture par tiers (sinon, une facture par commande)
|
||||||
BillCreated=%s facture(s) créée(s)
|
BillCreated=%s facture(s) créée(s)
|
||||||
|
WithdrawRequest=Demande de prélèvement
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user