Newer
Older
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2014-2016 Ferran Marcet <fmarcet@2byte.es>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* \file htdocs/compta/prelevement/class/bonprelevement.class.php
Marcos García de La Fuente
committed
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
Marcos García de La Fuente
committed
require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
*/
class BonPrelevement extends CommonObject
public $element='widthdraw';
public $table_element='prelevement_bons';
public $picto = 'payment';
var $date_echeance;
var $raison_sociale;
var $reference_remise;
var $emetteur_code_guichet;
var $emetteur_numero_compte;
var $emetteur_code_banque;
var $emetteur_number_key;
var $emetteur_iban;
var $emetteur_bic;
var $emetteur_ics;
var $total;
var $_fetched;
var $statut; // 0-Wait, 1-Trans, 2-Done
var $invoice_in_error=array();
* @param string $filename Filename of withdraw receipt
*/
function __construct($db, $filename='')
$error = 0;
$this->filename=$filename;
$this->date_echeance = time();
$this->raison_sociale = "";
$this->reference_remise = "";
$this->emetteur_code_guichet = "";
$this->emetteur_numero_compte = "";
$this->emetteur_code_banque = "";
$this->emetteur_number_key = "";
$this->emetteur_iban = "";
$this->emetteur_bic = "";
$this->emetteur_ics = "";
$this->factures = array();
$this->methodes_trans = array();
$this->methodes_trans[0] = "Internet";
$this->_fetched = 0;
$langs->load("withdrawals");
$this->labelstatut[0]=$langs->trans("StatusWaiting");
$this->labelstatut[1]=$langs->trans("StatusTrans");
$this->labelstatut[2]=$langs->trans("StatusCredited");
return 1;
* @param int $facture_id id invoice to add
* @param int $client_id id invoice customer
* @param int $amount amount of invoice
* @param string $code_banque code of bank withdrawal
* @param string $code_guichet code of bank's office
* @param string $number bank account number
* @param string $number_key number key of account number
* @return int >0 if OK, <0 if KO
function AddFacture($facture_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key)
Rodolphe Quiedeville
committed
{
$result = 0;
$result = $this->addline($line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key);
if ($result == 0)
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_facture (";
$sql.= "fk_facture";
$sql.= ",fk_prelevement_lignes";
$sql.= ") VALUES (";
$sql.= $facture_id;
if ($this->db->query($sql))
{
$result = 0;
}
else
{
$result = -1;
dol_syslog(get_class($this)."::AddFacture Erreur $result");
}
}
else
{
$result = -2;
dol_syslog(get_class($this)."::AddFacture Erreur $result");
}
}
else
{
$result = -3;
dol_syslog(get_class($this)."::AddFacture Erreur $result");
}
return $result;
Rodolphe Quiedeville
committed
}
* @param int $amount amount of invoice
* @param string $code_banque code of bank withdrawal
* @param string $code_guichet code of bank's office
* @param string $number bank account number
* @param string $number_key number key of account number
* @return int >0 if OK, <0 if KO
function addline(&$line_id, $client_id, $client_nom, $amount, $code_banque, $code_guichet, $number, $number_key)
{
$result = -1;
$concat = 0;
if ($concat == 1)
{
/*
$sql = "SELECT rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes";
$sql.= " WHERE fk_prelevement_bons = ".$this->id;
$sql.= " AND fk_soc =".$client_id;
$sql.= " AND code_banque ='".$code_banque."'";
$sql.= " AND code_guichet ='".$code_guichet."'";
$sql.= " AND number ='".$number."'";
$resql=$this->db->query($sql);
if ($resql)
$num = $this->db->num_rows($resql);
}
else
{
$result = -1;
}
}
else
{
/*
$sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_lignes (";
$sql.= "fk_prelevement_bons";
$sql.= ", fk_soc";
$sql.= ", client_nom";
$sql.= ", amount";
$sql.= ", code_banque";
$sql.= ", code_guichet";
$sql.= ", number";
$sql.= ", cle_rib";
$sql.= ") VALUES (";
$sql.= $this->id;
$sql.= ", ".$client_id;
Regis Houssin
committed
$sql.= ", '".$this->db->escape($client_nom)."'";
$sql.= ", '".price2num($amount)."'";
$sql.= ", '".$code_banque."'";
$sql.= ", '".$code_guichet."'";
$sql.= ", '".$number."'";
$sql.= ", '".$number_key."'";
if ($this->db->query($sql))
{
$line_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_lignes");
$result = 0;
}
else
{
dol_syslog(get_class($this)."::addline Error -2");
$result = -2;
}
}
return $result;
}
/**
* @param int $error Id of error
* @return string Error string
function getErrorString($error)
$errors = array();
$errors[1027] = $langs->trans("DateInvalid");
return $errors[abs($error)];
}
/**
* Get object and lines from database
* @param int $rowid Id of object to load
* @param string $ref Ref of direct debit
function fetch($rowid, $ref='')
$sql = "SELECT p.rowid, p.ref, p.amount, p.note";
$sql.= ", p.datec as dc";
$sql.= ", p.date_trans as date_trans";
$sql.= ", p.method_trans, p.fk_user_trans";
$sql.= ", p.fk_user_credit";
$sql.= ", p.statut";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
$sql.= " WHERE p.entity = ".$conf->entity;
if ($rowid > 0) $sql.= " AND p.rowid = ".$rowid;
else $sql.= " AND p.ref = '".$this->db->escape($ref)."'";
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$result=$this->db->query($sql);
if ($result)
{
if ($this->db->num_rows($result))
{
$obj = $this->db->fetch_object($result);
$this->id = $obj->rowid;
$this->ref = $obj->ref;
$this->amount = $obj->amount;
$this->note = $obj->note;
$this->datec = $this->db->jdate($obj->dc);
$this->date_trans = $this->db->jdate($obj->date_trans);
$this->method_trans = $obj->method_trans;
$this->user_trans = $obj->fk_user_trans;
$this->date_credit = $this->db->jdate($obj->date_credit);
$this->user_credit = $obj->fk_user_credit;
$this->statut = $obj->statut;
$this->_fetched = 1;
return 0;
}
else
{
dol_syslog(get_class($this)."::Fetch Erreur aucune ligne retournee");
return -1;
}
}
else
{
return -2;
}
}
/**
* Set credite and set status of linked invoices. Still used ??
*/
function set_credite()
{
if ($this->db->begin())
{
$sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons";
$sql.= " SET statut = 1";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;
$result=$this->db->query($sql);
if (! $result)
{
dol_syslog(get_class($this)."::set_credite Erreur 1");
$error++;
}
{
$facs = array();
$num=count($facs);
for ($i = 0; $i < $num; $i++)
dol_syslog(get_class($this)."::set_credite set_paid fac ".$facs[$i]);
Laurent Destailleur
committed
$fac = new Facture($this->db);
$fac->fetch($facs[$i]);
}
}
$sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes";
$sql.= " SET statut = 2";
$sql.= " WHERE fk_prelevement_bons = ".$this->id;
if (! $this->db->query($sql))
{
dol_syslog(get_class($this)."::set_credite Erreur 1");
$error++;
}
}
/*
{
$this->db->commit();
return 0;
}
else
{
$this->db->rollback();
dol_syslog(get_class($this)."::set_credite ROLLBACK ");
return -1;
}
}
else
{
dol_syslog(get_class($this)."::set_credite Ouverture transaction SQL impossible ");
return -2;
}
}
* Set direct debit order to "credited" status.
* @param User $user Id of user
* @param int $date date of action
function set_infocredit($user, $date)
{
if ($this->_fetched == 1)
{
if ($date >= $this->date_trans)
{
if ($this->db->begin())
{
$sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons ";
$sql.= " SET fk_user_credit = ".$user->id;
$sql.= ", statut = 2";
$sql.= ", date_credit = '".$this->db->idate($date)."'";
$sql.= " WHERE rowid=".$this->id;
$sql.= " AND entity = ".$conf->entity;
$sql.= " AND statut = 1";
if ($this->db->query($sql))
{
$subject = $langs->trans("InfoCreditSubject", $this->ref);
$message = $langs->trans("InfoCreditMessage", $this->ref, dol_print_date($date,'dayhour'));
//Add payment of withdrawal into bank
$bankaccount = $conf->global->PRELEVEMENT_ID_BANKACCOUNT;
$facs = array();
$amounts = array();
$amountsperthirdparty = array();
Marcos García de La Fuente
committed
$facs = $this->getListInvoices(1);
// Loop on each invoice. $facs=array(0=>id, 1=>amount requested)
$num=count($facs);
for ($i = 0; $i < $num; $i++)
{
$fac = new Facture($this->db);
Marcos García de La Fuente
committed
$fac->fetch($facs[$i][0]);
$amounts[$fac->id] = $facs[$i][1];
$amountsperthirdparty[$fac->socid][$fac->id] = $facs[$i][1];
$totalpaye = $fac->getSommePaiement();
$totalcreditnotes = $fac->getSumCreditNotesUsed();
$totaldeposits = $fac->getSumDepositsUsed();
$alreadypayed = $totalpaye + $totalcreditnotes + $totaldeposits;
if (price2num($alreadypayed + $facs[$i][1], 'MT') == $fac->total_ttc) {
$result = $fac->set_paid($user);
}
// Make one payment per customer
foreach ($amountsperthirdparty as $thirdpartyid => $cursoramounts)
$paiement = new Paiement($this->db);
$paiement->datepaye = $date;
$paiement->amounts = $cursoramounts; // Array with detail of dispatching of payments for each invoice
$paiement->paiementid = 3; //
$paiement->num_paiement = $this->ref; // Set ref of direct debit note
$paiement->id_prelevement = $this->id;
$paiement_id = $paiement->create($user);
if ($paiement_id < 0)
{
dol_syslog(get_class($this)."::set_infocredit AddPayment Error");
$error++;
}
else
{
$result=$paiement->addPaymentToBank($user,'payment','(WithdrawalPayment)',$bankaccount,'','');
if ($result < 0)
{
dol_syslog(get_class($this)."::set_infocredit AddPaymentToBank Error");
$error++;
}
}
//var_dump($paiement->amounts);
//var_dump($thirdpartyid);
//var_dump($cursoramounts);
// Update withdrawal line
// TODO: Translate to ligneprelevement.class.php
$sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes";
$sql.= " SET statut = 2";
$sql.= " WHERE fk_prelevement_bons = ".$this->id;
if (! $this->db->query($sql))
{
dol_syslog(get_class($this)."::set_infocredit Update lines Error");
$error++;
}
}
else
{
dol_syslog(get_class($this)."::set_infocredit Update Bons Error");
$error++;
}
/*
* End of procedure
if ($error == 0)
{
$this->db->commit();
return 0;
}
else
{
$this->db->rollback();
dol_syslog("bon-prelevment::set_infocredit ROLLBACK ");
return -1;
}
}
else
{
dol_syslog(get_class($this)."::set_infocredit 1025 Open SQL transaction impossible ");
return -1025;
}
}
else
{
dol_syslog("bon-prelevment::set_infocredit 1027 Date de credit < Date de trans ");
return -1027;
}
}
else
{
return -1026;
}
}
/**
* Set withdrawal to transmited status
* @param int $date date of action
* @param string $method method of transmision to bank
* @return int >0 if OK, <0 if KO
function set_infotrans($user, $date, $method)
{
dol_syslog(get_class($this)."::set_infotrans Start",LOG_INFO);
if ($this->db->begin())
{
$sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons ";
$sql.= " SET fk_user_trans = ".$user->id;
$sql.= " , date_trans = '".$this->db->idate($date)."'";
$sql.= " , method_trans = ".$method;
$sql.= " , statut = 1";
$sql.= " WHERE rowid = ".$this->id;
$sql.= " AND entity = ".$conf->entity;
$sql.= " AND statut = 0";
if ($this->db->query($sql))
{
$this->method_trans = $method;
$subject = $langs->trans("InfoTransSubject", $this->ref);
$message = $langs->trans("InfoTransMessage", $this->ref, dolGetFirstLastname($user->firstname, $user->lastname));
$message .=$langs->trans("InfoTransData", price($this->amount), $this->methodes_trans[$this->method_trans], dol_print_date($date,'day'));
// TODO Call trigger to create a notification using notification module
}
else
{
$error++;
}
if ($error == 0)
{
$this->db->commit();
return 0;
}
else
{
$this->db->rollback();
dol_syslog(get_class($this)."::set_infotrans ROLLBACK", LOG_ERR);
return -1;
}
}
else
{
dol_syslog(get_class($this)."::set_infotrans Ouverture transaction SQL impossible", LOG_CRIT);
return -2;
}
}
* @param int $amounts If you want to get the amount of the order for each invoice
* @return array Id of invoices
Marcos García de La Fuente
committed
private function getListInvoices($amounts=0)
$arr = array();
/*
* Returns all invoices presented
* within a withdrawal receipt
*/
$sql = "SELECT fk_facture";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons as p";
$sql.= " , ".MAIN_DB_PREFIX."prelevement_lignes as pl";
$sql.= " , ".MAIN_DB_PREFIX."prelevement_facture as pf";
$sql.= " WHERE pf.fk_prelevement_lignes = pl.rowid";
$sql.= " AND pl.fk_prelevement_bons = p.rowid";
$sql.= " AND p.rowid = ".$this->id;
$sql.= " AND p.entity = ".$conf->entity;
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
if ($num)
{
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($resql);
Marcos García de La Fuente
committed
if (!$amounts) $arr[$i] = $row[0];
else
{
$arr[$i] = array(
$row[0],
$row[1]
);
}
$i++;
}
}
$this->db->free($resql);
}
else
{
}
return $arr;
}
/**
*/
function SommeAPrelever()
{
$sql = "SELECT sum(pfd.amount) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
$sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
//$sql.= " ,".MAIN_DB_PREFIX."c_paiement as cp";
$sql.= " WHERE f.fk_statut = 1";
$sql.= " AND f.entity = ".$conf->entity;
$sql.= " AND f.rowid = pfd.fk_facture";
$sql.= " AND f.paye = 0";
$sql.= " AND pfd.traite = 0";
$sql.= " AND f.total_ttc > 0";
$resql = $this->db->query($sql);
if ( $resql )
{
$obj = $this->db->fetch_object($resql);
$this->db->free($resql);
return $obj->nb;
}
else
{
$error = 1;
dol_syslog(get_class($this)."::SommeAPrelever Erreur -1");
dol_syslog($this->db->error());
}
}
* TODO delete params banque and agence when not necesary
* @param int $banque dolibarr mysoc bank
* @param int $agence dolibarr mysoc agence
*/
function NbFactureAPrelever($banque=0,$agence=0)
{
$sql = "SELECT count(f.rowid) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
//if ($banque || $agence) $sql.=", ".MAIN_DB_PREFIX."societe_rib as sr";
$sql.= " WHERE f.fk_statut = 1";
$sql.= " AND f.entity = ".$conf->entity;
$sql.= " AND f.rowid = pfd.fk_facture";
$sql.= " AND f.paye = 0";
$sql.= " AND pfd.traite = 0";
$sql.= " AND f.total_ttc > 0";
//if ($banque || $agence) $sql.= " AND f.fk_soc = sr.rowid";
//if ($banque) $sql.= " AND sr.code_banque = '".$conf->global->PRELEVEMENT_CODE_BANQUE."'";
//if ($agence) $sql.= " AND sr.code_guichet = '".$conf->global->PRELEVEMENT_CODE_GUICHET."'";
dol_syslog(get_class($this)."::SommeAPrelever");
$resql = $this->db->query($sql);
if ( $resql )
{
$obj = $this->db->fetch_object($resql);
$this->db->free($resql);
return $obj->nb;
}
else
{
$this->error=get_class($this)."::SommeAPrelever Erreur -1 sql=".$this->db->error();
}
}
* TODO delete params banque and agence when not necesary
* @param int $banque dolibarr mysoc bank
* @param int $agence dolibarr mysoc bank office (guichet)
* @param string $mode real=do action, simu=test only
* @return int <0 if KO, nbre of invoice withdrawed if OK
function Create($banque=0, $agence=0, $mode='real')
dol_syslog(__METHOD__."::Bank=".$banque." Office=".$agence, LOG_DEBUG);
require_once (DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
require_once (DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
$error = 0;
$datetimeprev = time();
$month = strftime("%m", $datetimeprev);
$year = strftime("%Y", $datetimeprev);
$puser = new User($this->db, $conf->global->PRELEVEMENT_USER);
/*
* Read invoices
*/
$factures = array();
$factures_prev = array();
$factures_result = array();
$factures_prev_id=array();
$factures_errors=array();
if (! $error)
{
$sql = "SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc";
$sql.= ", pfd.code_banque, pfd.code_guichet, pfd.number, pfd.cle_rib";
$sql.= ", pfd.amount";
$sql.= ", s.nom as name";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= ", ".MAIN_DB_PREFIX."societe as s";
$sql.= ", ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
//if ($banque || $agence) $sql.= ", ".MAIN_DB_PREFIX."societe_rib as sr";
$sql.= " WHERE f.rowid = pfd.fk_facture";
$sql.= " AND f.entity = ".$conf->entity;
$sql.= " AND s.rowid = f.fk_soc";
//if ($banque || $agence) $sql.= " AND s.rowid = sr.fk_soc";
$sql.= " AND f.fk_statut = 1";
$sql.= " AND f.paye = 0";
$sql.= " AND pfd.traite = 0";
$sql.= " AND f.total_ttc > 0";
//if ($banque) $sql.= " AND sr.code_banque = '".$conf->global->PRELEVEMENT_CODE_BANQUE."'";
//if ($agence) $sql.= " AND sr.code_guichet = '".$conf->global->PRELEVEMENT_CODE_GUICHET."'";
dol_syslog(__METHOD__."::Read invoices, sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row($resql);
$factures[$i] = $row; // All fields
$i++;
}
$this->db->free($resql);
dol_syslog(__METHOD__."::Read invoices, ".$i." invoices to withdraw", LOG_DEBUG);
}
else
{
$error++;
dol_syslog(__METHOD__."::Read invoices error ".$this->db->error(), LOG_ERR);
}
}
if (! $error)
{
require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
$soc = new Societe($this->db);
// Check RIB
dol_syslog(__METHOD__."::Check RIB", LOG_DEBUG);
foreach ($factures as $key => $fac)
{
$fact = new Facture($this->db);
if ($fact->fetch($fac[0]) >= 0) // Field 0 of $fac is rowid of invoice
Laurent Destailleur
committed
if ($soc->fetch($fact->socid) >= 0)
$bac = new CompanyBankAccount($this->db);
{
$factures_prev[$i] = $fac;
/* second tableau necessaire pour BonPrelevement */
$factures_prev_id[$i] = $fac[0];
$i++;
}
else
dol_syslog(__METHOD__."::Check RIB Error on default bank number RIB/IBAN for thirdparty reported by verif() ".$fact->socid." ".$soc->name, LOG_ERR);
$this->invoice_in_error[$fac[0]]="Error on default bank number RIB/IBAN for invoice ".$fact->getNomUrl(0)." for thirdparty (reported by function verif) ".$soc->getNomUrl(0);
}
}
else
dol_syslog(__METHOD__."::Check RIB Failed to read company", LOG_ERR);
}
}
else
dol_syslog(__METHOD__."::Check RIB Failed to read invoice", LOG_ERR);
}
}
}
else
dol_syslog(__METHOD__."::Check RIB No invoice to process", LOG_ERR);
}
}
// Withdraw invoices in factures_prev array
$out=count($factures_prev)." invoices will be withdrawn.";
//print $out."\n";
dol_syslog($out);
{
if ($mode=='real')
{
$ok=1;
}
else
{
print $langs->trans("ModeWarning"); //"Option for real mode was not set, we stop after this simulation\n";
}
}
/*
* We are in real mode.
* We create withdraw receipt and build withdraw into disk
*/
/*
* Traitements
*/
if (!$error)
{
$sql = "SELECT substring(ref from char_length(ref) - 1)";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons";
$sql.= " WHERE ref LIKE '%".$this->db->escape($ref)."%'";
$sql.= " AND entity = ".$conf->entity;
$sql.= " ORDER BY ref DESC LIMIT 1";
dol_syslog(get_class($this)."::Create sql=".$sql, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$row = $this->db->fetch_row($resql);
$ref = "T".$ref.str_pad(dol_substr("00".intval($row[0])+1,0,2),2,"0",STR_PAD_LEFT);
$dir=$conf->prelevement->dir_output.'/receipts';
if (! is_dir($dir)) dol_mkdir($dir);
// Create withdraw receipt in database
$sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons (";
$sql.= " ref, entity, datec";
$sql.= ") VALUES (";
$sql.= "'".$this->db->escape($ref)."'";
$sql.= ", ".$conf->entity;
$sql.= ", '".$this->db->idate($now)."'";
$sql.= ")";
$resql = $this->db->query($sql);
if ($resql)
{
$prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons");
dol_syslog(__METHOD__."::Create withdraw receipt ".$this->db->lasterror(), LOG_ERR);
dol_syslog(__METHOD__."::Get last withdraw receipt ".$this->db->lasterror(), LOG_ERR);
}
/*
* Create withdrawal receipt in database
*/
if (count($factures_prev) > 0)
foreach ($factures_prev as $fac) // Add a link in database for each invoice
{
// Fetch invoice
$fact = new Facture($this->db);
$fact->fetch($fac[0]);
/*
* Add standing order
*
*
* $fac[3] : banque
* $fac[4] : guichet
* $fac[5] : number
* $fac[6] : cle rib
* $fac[7] : amount
* $fac[8] : client nom
* $fac[2] : client id
*/
$ri = $this->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6]);
if ($ri <> 0)
{
$error++;
}