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 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
* \ingroup prelevement
* \brief Fichier de la classe des bons de prelevements
*/
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.'/societe/class/societe.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
*/
class BonPrelevement extends CommonObject
var $db;
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->numero_national_emetteur = "";
$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 string $client_nom name of cliente
* @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 $client_id id invoice customer
* @param string $client_nom name of cliente
* @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 array Array of errors
function ReadError($error)
{
$errors = array();
$errors[1027] = "Date invalide";
return $errors[abs($error)];
}
/**
* Get object and lines from database
*
* @param int $rowid id of object to load
* @return int >0 if OK, <0 if KO
$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.rowid = ".$rowid;
$sql.= " AND p.entity = ".$conf->entity;
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
*/
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++;
}
if ($error == 0)
{
$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]);
}
}
if ($error == 0)
{
$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++;
}
}
/*
*/
if ($error == 0)
{
$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;
}
}
*
* @param User $user id of user
* @param timestamp $date date of action
* @return int >0 if OK, <0 if KO
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();
Marcos García de La Fuente
committed
$facs = $this->getListInvoices(1);
$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];
$result = $fac->set_paid($user);
}
$paiement = new Paiement($this->db);
$paiement->datepaye = $date ;
$paiement->amounts = $amounts;
$paiement->paiementid = 3; //
$paiement->num_paiement = $this->ref ;
$paiement_id = $paiement->create($user);
if ($paiement_id < 0)
{
dol_syslog(get_class($this)."::set_credite AddPayment Error");
$result=$paiement->addPaymentToBank($user,'payment','(WithdrawalPayment)',$bankaccount,'','');
dol_syslog(get_class($this)."::set_credite AddPaymentToBank Error");
$error++;
}
}
// Update prelevement 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_credite 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 User $user id of user
* @param timestamp $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();
/*
* Renvoie toutes les factures presente
* dans un bon de prelevement
*/
$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.= " 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);
return $obj->nb;
$this->db->free($resql);
}
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->name;
}
}
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)
{
$ref = substr($year,-2).$month;
$sql = "SELECT substring(ref from char_length(ref) - 1)";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons";
$sql.= " WHERE ref LIKE '%".$ref."%'";
$sql.= " AND entity = ".$conf->entity;
$sql.= " ORDER BY ref DESC LIMIT 1";
dol_syslog(get_class($this)."::Create sql=".$sql, LOG_DEBUG);
dol_syslog(__METHOD__."::Treatments", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$row = $this->db->fetch_row($resql);
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
$ref = "T".$ref.str_pad(dol_substr("00".intval($row[0])+1),2,"0",STR_PAD_LEFT);
$filebonprev = $ref;
// 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.= ")";
dol_syslog(__METHOD__, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons");
$dir=$conf->prelevement->dir_output.'/receipts';
$file=$filebonprev;
if (! is_dir($dir)) dol_mkdir($dir);
$bonprev = new BonPrelevement($this->db, $dir."/".$file);
$bonprev->id = $prev_id;
}
else
{
$error++;
dol_syslog(__METHOD__."::Create withdraw receipt ".$this->db->error(), LOG_ERR);
}
dol_syslog(__METHOD__."::Get last withdraw receipt ".$this->db->error(), LOG_ERR);
}
/*
{
foreach ($factures_prev as $fac)
{
// 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 = $bonprev->AddFacture($fac[0], $fac[2], $fac[8], $fac[7], $fac[3], $fac[4], $fac[5], $fac[6]);
if ($ri <> 0)
{
$error++;
}
/*
* Update orders
*
*/
$sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande";
$sql.= " SET traite = 1";
$sql.= ", date_traite = '".$this->db->idate($now)."'";
$sql.= ", fk_prelevement_bons = ".$prev_id;
$sql.= " WHERE rowid = ".$fac[1];
dol_syslog(__METHOD__."::Update Orders::Sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if (! $resql)
dol_syslog(__METHOD__."::Update Orders::Error=".$this->db->error() ,LOG_ERR);