From c5d655afc296e5c86f24ea0ca6502331794177a4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 28 Mar 2009 19:59:12 +0000 Subject: [PATCH] Some fix in standingorder module --- .../prelevement/bon-prelevement.class.php | 4 +- htdocs/compta/prelevement/fiche.php | 308 +++++----- htdocs/compta/prelevement/ligne.php | 457 ++++++++------- .../includes/modules/action/rapport.pdf.php | 264 ++++----- scripts/prelevement/prelevement-verif.php | 51 +- scripts/prelevement/prelevement.php | 547 +++++++++--------- 6 files changed, 831 insertions(+), 800 deletions(-) diff --git a/htdocs/compta/prelevement/bon-prelevement.class.php b/htdocs/compta/prelevement/bon-prelevement.class.php index 9c305fc0bb4..2a6858edc4a 100644 --- a/htdocs/compta/prelevement/bon-prelevement.class.php +++ b/htdocs/compta/prelevement/bon-prelevement.class.php @@ -135,7 +135,7 @@ class BonPrelevement extends CommonObject if ($concat == 1) { /* - * On aggr�ge les lignes + * On aggrege les lignes */ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."prelevement_lignes"; $sql .= " WHERE fk_prelevement_bons".$this->id; @@ -156,7 +156,7 @@ class BonPrelevement extends CommonObject else { /* - * Pas de d'agr�gation + * Pas de d'agregation */ $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_lignes (fk_prelevement_bons"; $sql .= " , fk_soc , client_nom "; diff --git a/htdocs/compta/prelevement/fiche.php b/htdocs/compta/prelevement/fiche.php index 169b05cd8a0..0f877525df7 100644 --- a/htdocs/compta/prelevement/fiche.php +++ b/htdocs/compta/prelevement/fiche.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2008 Laurent Destailleur + * Copyright (C) 2005-2009 Laurent Destailleur * * 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 @@ -16,26 +16,24 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - + /** - \file htdocs/compta/prelevement/fiche.php - \ingroup prelevement - \brief Fiche prelevement - \version $Id$ -*/ + * \file htdocs/compta/prelevement/fiche.php + * \ingroup prelevement + * \brief Fiche prelevement + * \version $Id$ + */ require("./pre.inc.php"); if (!$user->rights->prelevement->bons->lire) - accessforbidden(); +accessforbidden(); $langs->load("bills"); $langs->load("withdrawals"); -/* - * Sécurité accés client - */ +// Security check if ($user->societe_id > 0) accessforbidden(); @@ -45,86 +43,91 @@ if ($user->societe_id > 0) accessforbidden(); if ($_POST["action"] == 'confirm_credite' && $_POST["confirm"] == yes) { - $bon = new BonPrelevement($db,""); - $bon->id = $_GET["id"]; - $bon->set_credite(); + $bon = new BonPrelevement($db,""); + $bon->id = $_GET["id"]; + $bon->set_credite(); - Header("Location: fiche.php?id=".$_GET["id"]); + Header("Location: fiche.php?id=".$_GET["id"]); + exit; } if ($_POST["action"] == 'infotrans') { - $bon = new BonPrelevement($db,""); - $bon->fetch($_GET["id"]); + $bon = new BonPrelevement($db,""); + $bon->fetch($_GET["id"]); - if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $bon->ref) - { - $dir = $conf->prelevement->dir_output.'/bon/'; - - if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . $_FILES['userfile']['name'],1) > 0) + if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $bon->ref) { - $dt = dol_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); - - $bon->set_infotrans($user, $dt, $_POST["methode"]); - } - } - else - { - dol_syslog("Fichier invalide",LOG_WARNING); - } + $dir = $conf->prelevement->dir_output.'/bon/'; - Header("Location: fiche.php?id=".$_GET["id"]); - exit; + if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . $_FILES['userfile']['name'],1) > 0) + { + $dt = dol_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); + + $bon->set_infotrans($user, $dt, $_POST["methode"]); + } + } + else + { + dol_syslog("Fichier invalide",LOG_WARNING); + } + + Header("Location: fiche.php?id=".$_GET["id"]); + exit; } if ($_POST["action"] == 'infocredit') { - $bon = new BonPrelevement($db,""); - $bon->Fetch($_GET["id"]); - $dt = mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); + $bon = new BonPrelevement($db,""); + $bon->Fetch($_GET["id"]); + $dt = mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); - $error = $bon->set_infocredit($user, $dt); + $error = $bon->set_infocredit($user, $dt); - if ($error == 0) - { - Header("Location: fiche.php?id=".$_GET["id"]); - } - else - { - Header("Location: fiche.php?id=".$_GET["id"]."&error=$error"); - } + if ($error == 0) + { + Header("Location: fiche.php?id=".$_GET["id"]); + } + else + { + Header("Location: fiche.php?id=".$_GET["id"]."&error=$error"); + } } +/* + * View + */ + llxHeader('',$langs->trans("WithdrawalReceipt")); $h = 0; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("Card"); $hselected = $h; -$h++; +$h++; if ($conf->use_preview_tabs) { - $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/bon.php?id='.$_GET["id"]; - $head[$h][1] = $langs->trans("Preview"); - $h++; + $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/bon.php?id='.$_GET["id"]; + $head[$h][1] = $langs->trans("Preview"); + $h++; } $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/lignes.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("Lines"); -$h++; +$h++; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/factures.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("Bills"); -$h++; +$h++; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-rejet.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("Rejects"); -$h++; +$h++; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-stat.php?id='.$_GET["id"]; $head[$h][1] = $langs->trans("Statistics"); -$h++; +$h++; $prev_id = $_GET["id"]; @@ -132,105 +135,106 @@ $html = new Form($db); if ($_GET["id"]) { - $bon = new BonPrelevement($db,""); + $bon = new BonPrelevement($db,""); - if ($bon->fetch($_GET["id"]) == 0) - { - dol_fiche_head($head, $hselected, $langs->trans("WithdrawalReceipt")); - - if (isset($_GET["error"])) + if ($bon->fetch($_GET["id"]) == 0) { - print '
'.$bon->ReadError($_GET["error"]).'
'; + dol_fiche_head($head, $hselected, $langs->trans("WithdrawalReceipt")); + + if (isset($_GET["error"])) + { + print '
'.$bon->ReadError($_GET["error"]).'
'; + } + + + + if ($_GET["action"] == 'credite') + { + $html->form_confirm("fiche.php?id=".$bon->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite"); + print '
'; + } + + print ''; + + print ''; + print ''; + print ''; + print ''; + + print ''; + + if($bon->date_trans <> 0) + { + $muser = new User($db, $bon->user_trans); + $muser->fetch(); + + print ''; + print ''; + } + if($bon->date_credit <> 0) + { + print ''; + } + + print '
'.$langs->trans("Ref").''.$bon->getNomUrl(1).'
'.$langs->trans("Date").''.dol_print_date($bon->datec,'dayhour').'
'.$langs->trans("Amount").''.price($bon->amount).'
'.$langs->trans("File").''; + + $relativepath = 'bon/'.$bon->ref; + + print ''.$bon->ref.''; + + print '
Statut'; + print ' '; + print $lipre->statuts[$lipre->statut].'
Date Transmission / Par'; + print dol_print_date($bon->date_trans,'dayhour'); + print ' par '.$muser->fullname.'
Methode Transmission'; + print $bon->methodes_trans[$bon->method_trans]; + print '
Credit on'; + print dol_print_date($bon->date_credit,'dayhour'); + print '

'; + + if($bon->date_trans == 0) + { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
Date Transmission'; + print $html->select_date('','','','','',"userfile"); + print '
Methode Transmission'; + print $html->select_array("methode",$bon->methodes_trans); + print '
'.$langs->trans("File").''; + print ''; + print '
'; + print '
'; + print ''; + print '
'; + } + + if($bon->date_trans <> 0 && $bon->date_credit == 0) + { + print '
'; + print ''; + print ''; + print ''; + print ''; + print '
Crédité le'; + print $html->select_date('','','','','',"infocredit"); + print '
'; + print ''; + print '
'; + } + } - - - - if ($_GET["action"] == 'credite') + else { - $html->form_confirm("fiche.php?id=".$bon->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite"); - print '
'; + dol_print_error($db); } - - print ''; - - print ''; - print ''; - print ''; - print ''; - - print ''; - - if($bon->date_trans <> 0) - { - $muser = new User($db, $bon->user_trans); - $muser->fetch(); - - print ''; - print ''; - } - if($bon->date_credit <> 0) - { - print ''; - } - - print '
'.$langs->trans("Ref").''.$bon->getNomUrl(1).'
'.$langs->trans("Date").''.dol_print_date($bon->datec,'dayhour').'
'.$langs->trans("Amount").''.price($bon->amount).'
'.$langs->trans("File").''; - - $relativepath = 'bon/'.$bon->ref; - - print ''.$bon->ref.''; - - print '
Statut'; - print ' '; - print $lipre->statuts[$lipre->statut].'
Date Transmission / Par'; - print dol_print_date($bon->date_trans,'dayhour'); - print ' par '.$muser->fullname.'
Methode Transmission'; - print $bon->methodes_trans[$bon->method_trans]; - print '
Credit on'; - print dol_print_date($bon->date_credit,'dayhour'); - print '

'; - - if($bon->date_trans == 0) - { - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '
Date Transmission'; - print $html->select_date('','','','','',"userfile"); - print '
Methode Transmission'; - print $html->select_array("methode",$bon->methodes_trans); - print '
'.$langs->trans("File").''; - print ''; - print '
'; - print '
'; - print ''; - print '
'; - } - - if($bon->date_trans <> 0 && $bon->date_credit == 0) - { - print '
'; - print ''; - print ''; - print ''; - print ''; - print '
Crédité le'; - print $html->select_date('','','','','',"infocredit"); - print '
'; - print ''; - print '
'; - } - - } - else - { - dol_print_error($db); - } } + /* ************************************************************************** */ /* */ /* Barre d'action */ @@ -240,15 +244,15 @@ if ($_GET["id"]) print "\n\n
\n"; if ($_GET["action"] == '') -{ - - if ($bon->credite == 0) - { - print "id\">".$langs->trans("ClassCredited").""; - } +{ + + if ($bon->credite == 0) + { + print "id\">".$langs->trans("ClassCredited").""; + } + - } print "
"; diff --git a/htdocs/compta/prelevement/ligne.php b/htdocs/compta/prelevement/ligne.php index 874014b5de9..0e9f9c1b813 100644 --- a/htdocs/compta/prelevement/ligne.php +++ b/htdocs/compta/prelevement/ligne.php @@ -1,5 +1,6 @@ + * Copyright (C) 2005-2008 Laurent Destailleur * * 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 @@ -14,279 +15,291 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ */ - + +/** + * \file htdocs/compta/prelevement/ligne.php + * \ingroup prelevement + * \brief card of withdraw line + * \version $Id$ + */ + require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/compta/prelevement/ligne-prelevement.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/prelevement/rejet-prelevement.class.php"); require_once(DOL_DOCUMENT_ROOT."/paiement.class.php"); -// Sécurité accés client +// Security check if ($user->societe_id > 0) accessforbidden(); if ($_POST["action"] == 'confirm_rejet') { - if ( $_POST["confirm"] == 'yes') - { - - $daterej = mktime(2, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - - $lipre = new LignePrelevement($db, $user); - - if ($lipre->fetch($_GET["id"]) == 0) + if ( $_POST["confirm"] == 'yes') { - - if ($_POST["motif"] > 0 && $daterej < time()) - { - $rej = new RejetPrelevement($db, $user); - - $rej->create($user, $_GET["id"], $_POST["motif"], $daterej, $lipre->bon_rowid, $_POST["facturer"]); - - Header("Location: ligne.php?id=".$_GET["id"]); - } - else - { - dol_syslog("Motif : ".$_POST["motif"]); - dol_syslog("$daterej $time "); - Header("Location: ligne.php?id=".$_GET["id"]."&action=rejet"); - } + + $daterej = mktime(2, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + + $lipre = new LignePrelevement($db, $user); + + if ($lipre->fetch($_GET["id"]) == 0) + { + + if ($_POST["motif"] > 0 && $daterej < time()) + { + $rej = new RejetPrelevement($db, $user); + + $rej->create($user, $_GET["id"], $_POST["motif"], $daterej, $lipre->bon_rowid, $_POST["facturer"]); + + Header("Location: ligne.php?id=".$_GET["id"]); + exit; + } + else + { + dol_syslog("Motif : ".$_POST["motif"]); + dol_syslog("$daterej $time "); + Header("Location: ligne.php?id=".$_GET["id"]."&action=rejet"); + exit; + } + } + } + else + { + Header("Location: ligne.php?id=".$_GET["id"]); + exit; } - } - else - { - Header("Location: ligne.php?id=".$_GET["id"]); - } } +/* + * View + */ -llxHeader('','Prélèvement'); +llxHeader('',$langs->trans("StandingOrder")); $h = 0; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/ligne.php?id='.$_GET["id"]; -$head[$h][1] = $langs->trans("Fiche"); +$head[$h][1] = $langs->trans("Card"); $hselected = $h; -$h++; +$h++; if ($_GET["id"]) { - $lipre = new LignePrelevement($db, $user); + $lipre = new LignePrelevement($db, $user); - if ($lipre->fetch($_GET["id"]) == 0) - { - $bon = new BonPrelevement($db); - $bon->fetch($lipre->bon_rowid); - - dol_fiche_head($head, $hselected, 'Prélèvement : '. $lipre->bon_ref); - - print ''; - - print ''; - print ''; - print ''; - - if ($lipre->statut == 3) + if ($lipre->fetch($_GET["id"]) == 0) { - $rej = new RejetPrelevement($db, $user); - $resf = $rej->fetch($lipre->id); - if ($resf == 0) - { - print ''; - print '
Bons de prélèvement'; - print ''.$lipre->bon_ref.'
Montant'.price($lipre->amount).'
Statut'; - print ' '; - print $lipre->statuts[$lipre->statut].'
Motif du rejet'.$rej->motif.'
Date du rejet'; - if ($rej->date_rejet == 0) + $bon = new BonPrelevement($db); + $bon->fetch($lipre->bon_rowid); + + dol_fiche_head($head, $hselected, $langs->trans("StandingOrder")); + + print ''; + + print ''; + print ''; + print ''; + + if ($lipre->statut == 3) { - /* Historique pour certaines install */ - print "Inconnue"; + $rej = new RejetPrelevement($db, $user); + $resf = $rej->fetch($lipre->id); + if ($resf == 0) + { + print ''; + print ''; + } + else + { + print ''; + } } - else - { - print dol_print_date($rej->date_rejet,'day'); - } - print ''; - } - else - { - print ''; - } + + + print '
'.$langs->trans("WithdrawalReceipt").''; + print ''.$lipre->bon_ref.'
'.$langs->trans("Amount").''.price($lipre->amount).'
'.$langs->trans("Status").''; + print ' '; + print $lipre->statuts[$lipre->statut].'
Motif du rejet'.$rej->motif.'
Date du rejet'; + if ($rej->date_rejet == 0) + { + /* Historique pour certaines install */ + print $langs->trans("Unknown"); + } + else + { + print dol_print_date($rej->date_rejet,'day'); + } + print '
'.$resf.'
'.$resf.'

'; + } + else + { + print "Erreur"; } - print '

'; - } - else - { - print "Erreur"; - } - - - if ($_GET["action"] == 'rejet') - { - $html = new Form($db); - - $soc = new Societe($db); - $soc->fetch($lipre->socid); - - $rej = new RejetPrelevement($db, $user); - - print '
'; - print ''; - print ''; - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '
Rejet de prélèvement
Etes-vous sûr de vouloir saisir un rejet de prélèvement pour la société '.$soc->nom.' ?'; - print ''; - print '
Date du rejet'; - print $html->select_date('','','','','',"confirm_rejet"); - print '
Motif du rejet'; - print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print '
Rejet de prélèvement
Etes-vous sûr de vouloir saisir un rejet de prélèvement pour la société '.$soc->nom.' ?'; + print ''; + print '
Date du rejet'; + print $html->select_date('','','','','',"confirm_rejet"); + print '
Motif du rejet'; + print ''; + print ''; + print '
Facturation du rejet'; + print ''; + print '
'; } - print ''; - print '
'; - print '
Facturation du rejet'; - print ''; - print '
'; - } + $page = $_GET["page"]; + $sortorder = $_GET["sortorder"]; + $sortfield = $_GET["sortfield"]; - $page = $_GET["page"]; - $sortorder = $_GET["sortorder"]; - $sortfield = $_GET["sortfield"]; + if ($page == -1) { $page = 0 ; } - if ($page == -1) { $page = 0 ; } + $offset = $conf->liste_limit * $page ; + $pageprev = $page - 1; + $pagenext = $page + 1; - $offset = $conf->liste_limit * $page ; - $pageprev = $page - 1; - $pagenext = $page + 1; + if ($sortorder == "") $sortorder="DESC"; + if ($sortfield == "") $sortfield="pl.fk_soc"; - if ($sortorder == "") $sortorder="DESC"; - if ($sortfield == "") $sortfield="pl.fk_soc"; + /* + * Liste des factures + * + * + */ + $sql = "SELECT pf.rowid"; + $sql .= " ,f.rowid as facid, f.facnumber as ref, f.total_ttc"; + $sql .= " , s.rowid as socid, s.nom"; + $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 .= " , ".MAIN_DB_PREFIX."facture as f"; + $sql .= " , ".MAIN_DB_PREFIX."societe as s"; + $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid"; + $sql .= " AND pl.fk_prelevement_bons = p.rowid"; + $sql .= " AND f.fk_soc = s.rowid"; + $sql .= " AND pf.fk_facture = f.rowid"; + $sql .= " AND pl.rowid=".$_GET["id"]; - /* - * Liste des factures - * - * - */ - $sql = "SELECT pf.rowid"; - $sql .= " ,f.rowid as facid, f.facnumber as ref, f.total_ttc"; - $sql .= " , s.rowid as socid, s.nom"; - $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 .= " , ".MAIN_DB_PREFIX."facture as f"; - $sql .= " , ".MAIN_DB_PREFIX."societe as s"; - $sql .= " WHERE pf.fk_prelevement_lignes = pl.rowid"; - $sql .= " AND pl.fk_prelevement_bons = p.rowid"; - $sql .= " AND f.fk_soc = s.rowid"; - $sql .= " AND pf.fk_facture = f.rowid"; - $sql .= " AND pl.rowid=".$_GET["id"]; - - if ($_GET["socid"]) - { - $sql .= " AND s.rowid = ".$_GET["socid"]; - } - - $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset); - - $result = $db->query($sql); - - if ($result) - { - $num = $db->num_rows($result); - $i = 0; - - $urladd = "&id=".$_GET["id"]; - - print_barre_liste("Factures", $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num); - print"\n\n"; - print ''; - print ''; - print 'Montant'; - print ''; - - $var=True; - - $total = 0; - - while ($i < min($num,$conf->liste_limit)) + if ($_GET["socid"]) { - $obj = $db->fetch_object($result); - - print "\n"; - - print '\n"; - - print '\n"; - - - print "\n"; - - $i++; + $sql .= " AND s.rowid = ".$_GET["socid"]; } - print "
FactureSociété 
"; - - print ''; - print img_object($langs->trans("ShowBill"),"bill"); - print ' '; - - print ''.$obj->ref."'; - print img_object($langs->trans("ShowCompany"),"company"). ' '.stripslashes($obj->nom)."'.price($obj->total_ttc)."
"; + $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset); - $db->free($result); - } - else - { - dol_print_error($db); - } + $result = $db->query($sql); - $db->close(); + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + + $urladd = "&id=".$_GET["id"]; + + print_barre_liste("Factures", $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, ''); + + print"\n\n"; + print ''; + print ''; + print ''; + print ''; + + $var=True; + + $total = 0; + + $var=false; + while ($i < min($num,$conf->liste_limit)) + { + $obj = $db->fetch_object($result); + + print "\n"; + + print '\n"; + + print '\n"; - /* ************************************************************************** */ - /* */ - /* Barre d'action */ - /* */ - /* ************************************************************************** */ + print "\n"; - print "\n\n
\n"; + $i++; + } - if ($_GET["action"] == '') - { - - if ($bon->credite == 1 && $lipre->statut == 2) - { - print "id\">".$langs->trans("Emmetre un rejet").""; + print "
'.$langs->trans("Invoice").''.$langs->trans("Company").''.$langs->trans("Amount").'
"; + + print ''; + print img_object($langs->trans("ShowBill"),"bill"); + print ' '; + + print ''.$obj->ref."'; + print img_object($langs->trans("ShowCompany"),"company"). ' '.stripslashes($obj->nom)."'.price($obj->total_ttc)."
"; + + $db->free($result); + } + else + { + dol_print_error($db); } - } - print ""; + $db->close(); + + + /* ************************************************************************** */ + /* */ + /* Barre d'action */ + /* */ + /* ************************************************************************** */ + + print "\n\n
\n"; + + if ($_GET["action"] == '') + { + + if ($bon->credite == 1 && $lipre->statut == 2) + { + print "id\">".$langs->trans("Emmetre un rejet").""; + } + } + + print "
"; } llxFooter('$Date$ - $Revision$'); diff --git a/htdocs/includes/modules/action/rapport.pdf.php b/htdocs/includes/modules/action/rapport.pdf.php index b523f36726e..c907f4f5bb2 100644 --- a/htdocs/includes/modules/action/rapport.pdf.php +++ b/htdocs/includes/modules/action/rapport.pdf.php @@ -19,59 +19,59 @@ */ /** - \file htdocs/includes/modules/action/rapport.pdf.php - \ingroup commercial - \brief Fichier de generation de PDF pour les rapports d'actions - \version $Id$ -*/ + \file htdocs/includes/modules/action/rapport.pdf.php + \ingroup commercial + \brief Fichier de generation de PDF pour les rapports d'actions + \version $Id$ + */ require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); require_once(DOL_DOCUMENT_ROOT.'/lib/pdf.lib.php'); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); /** - \class CommActionRapport - \brief Classe permettant la generation des rapports d'actions -*/ + \class CommActionRapport + \brief Classe permettant la generation des rapports d'actions + */ class CommActionRapport { - var $db; - var $description; - var $date_edition; - var $year; - var $month; + var $db; + var $description; + var $date_edition; + var $year; + var $month; - var $title; - var $subject; + var $title; + var $subject; - function CommActionRapport($db=0, $month, $year) - { - global $langs; - $langs->load("commercial"); + function CommActionRapport($db=0, $month, $year) + { + global $langs; + $langs->load("commercial"); - $this->db = $db; - $this->description = ""; - $this->date_edition = time(); - $this->month = $month; - $this->year = $year; + $this->db = $db; + $this->description = ""; + $this->date_edition = time(); + $this->month = $month; + $this->year = $year; - // Dimension page pour format A4 - $this->type = 'pdf'; - $this->page_largeur = 210; - $this->page_hauteur = 297; - $this->format = array($this->page_largeur,$this->page_hauteur); - $this->marge_gauche=5; - $this->marge_droite=5; - $this->marge_haute=10; - $this->marge_basse=10; + // Dimension page pour format A4 + $this->type = 'pdf'; + $this->page_largeur = 210; + $this->page_hauteur = 297; + $this->format = array($this->page_largeur,$this->page_hauteur); + $this->marge_gauche=5; + $this->marge_droite=5; + $this->marge_haute=10; + $this->marge_basse=10; - $this->title=$langs->trans("ActionsReport").' '.$this->year."-".$this->month; - $this->subject=$langs->trans("ActionsReport").' '.$this->year."-".$this->month; - } + $this->title=$langs->trans("ActionsReport").' '.$this->year."-".$this->month; + $this->subject=$langs->trans("ActionsReport").' '.$this->year."-".$this->month; + } - function generate($socid = 0, $catid = 0, $outputlangs='') - { - global $user,$conf,$langs; + function generate($socid = 0, $catid = 0, $outputlangs='') + { + global $user,$conf,$langs; if (! is_object($outputlangs)) $outputlangs=$langs; // Force output charset to ISO, because, FPDF expect text encoded in ISO @@ -86,20 +86,20 @@ class CommActionRapport $outputlangs->setPhpLang(); $dir = $conf->actions->dir_temp."/"; - $file = $dir . "actions-".$this->month."-".$this->year.".pdf"; + $file = $dir . "actions-".$this->month."-".$this->year.".pdf"; - if (! file_exists($dir)) - { - if (create_exdir($dir) < 0) - { - $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); - return 0; - } - } + if (! file_exists($dir)) + { + if (create_exdir($dir) < 0) + { + $this->error=$langs->trans("ErrorCanNotCreateDir",$dir); + return 0; + } + } - if (file_exists($dir)) - { - // Protection et encryption du pdf + if (file_exists($dir)) + { + // Protection et encryption du pdf if ($conf->global->PDF_SECURITY_ENCRYPTION) { $pdf=new FPDI_Protection('P','mm',$this->format); @@ -116,29 +116,29 @@ class CommActionRapport $pdf->Open(); $pagenb=0; $pdf->SetDrawColor(128,128,128); - $pdf->SetFillColor(220,220,220); + $pdf->SetFillColor(220,220,220); $pdf->SetTitle($outputlangs->convToOutputCharset($this->title)); - $pdf->SetSubject($outputlangs->convToOutputCharset($this->subject)); - $pdf->SetCreator("Dolibarr ".DOL_VERSION); - $pdf->SetAuthor($outputlangs->convToOutputCharset($user->fullname)); - $pdf->SetKeywords($outputlangs->convToOutputCharset($this->title." ".$this->subject)); + $pdf->SetSubject($outputlangs->convToOutputCharset($this->subject)); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($outputlangs->convToOutputCharset($user->fullname)); + $pdf->SetKeywords($outputlangs->convToOutputCharset($this->title." ".$this->subject)); $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right $pdf->SetAutoPageBreak(1,0); - $nbpage = $this->_pages($pdf, $outputlangs); + $nbpage = $this->_pages($pdf, $outputlangs); - $pdf->AliasNbPages(); - $pdf->Close(); + $pdf->AliasNbPages(); + $pdf->Close(); - $pdf->Output($file); + $pdf->Output($file); if (! empty($conf->global->MAIN_UMASK)) - @chmod($file, octdec($conf->global->MAIN_UMASK)); + @chmod($file, octdec($conf->global->MAIN_UMASK)); - return 1; - } - } + return 1; + } + } /** * Write content of pages @@ -146,13 +146,13 @@ class CommActionRapport * @param unknown_type $pdf * @return int 1 */ - function _pages(&$pdf, $outputlangs) - { + function _pages(&$pdf, $outputlangs) + { $height=3; // height for text separation - $pagenb=1; + $pagenb=1; $y=$this->_pagehead($pdf, $outputlangs, $pagenb); - $y++; + $y++; $pdf->SetFont('Arial','',8); $sql = "SELECT s.nom as societe, s.rowid as socid, s.client,"; @@ -160,96 +160,96 @@ class CommActionRapport $sql.= " a.fk_contact, a.note, a.percent as percent,"; $sql.= " c.libelle,"; $sql.= " u.login"; - $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."user as u"; - $sql.= " WHERE a.fk_soc = s.rowid AND c.id=a.fk_action AND a.fk_user_author = u.rowid"; - $sql.= " AND date_format(a.datep, '%m') = ".$this->month; - $sql.= " AND date_format(a.datep, '%Y') = ".$this->year; - $sql.= " ORDER BY a.datep DESC"; + $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."user as u"; + $sql.= " WHERE a.fk_soc = s.rowid AND c.id=a.fk_action AND a.fk_user_author = u.rowid"; + $sql.= " AND date_format(a.datep, '%m') = ".$this->month; + $sql.= " AND date_format(a.datep, '%Y') = ".$this->year; + $sql.= " ORDER BY a.datep DESC"; - dol_syslog("Rapport.pdf::_page sql=".$sql); - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - $i = 0; - $y0=$y1=$y2=$y3=0; + dol_syslog("Rapport.pdf::_page sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + $num = $this->db->num_rows($resql); + $i = 0; + $y0=$y1=$y2=$y3=0; - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); - $y = max($y, $pdf->GetY(), $y0, $y1, $y2, $y3); + $y = max($y, $pdf->GetY(), $y0, $y1, $y2, $y3); - // Calculate height of text - $text=dol_trunc(dol_htmlentitiesbr_decode($obj->note),150); - //print 'd'.$text; exit; - $nboflines=dol_nboflines($text); - $heightlinemax=max(2*$height,$nboflines*$height); + // Calculate height of text + $text=dol_trunc(dol_htmlentitiesbr_decode($obj->note),150); + //print 'd'.$text; exit; + $nboflines=dol_nboflines($text); + $heightlinemax=max(2*$height,$nboflines*$height); // Check if there is enough space to print record - if ((1+$y+$heightlinemax) >= ($this->page_hauteur - $this->marge_haute)) - { - // We need to break page - $pagenb++; + if ((1+$y+$heightlinemax) >= ($this->page_hauteur - $this->marge_haute)) + { + // We need to break page + $pagenb++; $y=$this->_pagehead($pdf, $outputlangs, $pagenb); - $y++; + $y++; $pdf->SetFont('Arial','',8); - } - $y++; + } + $y++; - $pdf->SetXY($this->marge_gauche, $y); - $pdf->MultiCell(22, $height, dol_print_date($obj->dp,"day")."\n".dol_print_date($obj->dp,"hour"), 0, 'L', 0); - $y0 = $pdf->GetY(); + $pdf->SetXY($this->marge_gauche, $y); + $pdf->MultiCell(22, $height, dol_print_date($obj->dp,"day")."\n".dol_print_date($obj->dp,"hour"), 0, 'L', 0); + $y0 = $pdf->GetY(); - $pdf->SetXY(26, $y); - $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->societe),32), 0, 'L', 0); - $y1 = $pdf->GetY(); + $pdf->SetXY(26, $y); + $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->societe),32), 0, 'L', 0); + $y1 = $pdf->GetY(); - $pdf->SetXY(60,$y); - $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->libelle),32), 0, 'L', 0); - $y2 = $pdf->GetY(); + $pdf->SetXY(60,$y); + $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->libelle),32), 0, 'L', 0); + $y2 = $pdf->GetY(); - $pdf->SetXY(106,$y); - $pdf->MultiCell(94, $height, $outputlangs->convToOutputCharset($text), 0, 'L', 0); - $y3 = $pdf->GetY(); + $pdf->SetXY(106,$y); + $pdf->MultiCell(94, $height, $outputlangs->convToOutputCharset($text), 0, 'L', 0); + $y3 = $pdf->GetY(); - //$pdf->MultiCell(94,2,"y=$y y3=$y3",0,'L',0); + //$pdf->MultiCell(94,2,"y=$y y3=$y3",0,'L',0); - $i++; - } - } + $i++; + } + } - return 1; - } + return 1; + } - /** - * \brief Affiche en-tete facture - * \param pdf Objet PDF - * \param outputlang Objet lang cible - * \param pagenb Page nb - */ - function _pagehead(&$pdf, $outputlangs, $pagenb) - { + /** + * \brief Affiche en-tete facture + * \param pdf Objet PDF + * \param outputlang Objet lang cible + * \param pagenb Page nb + */ + function _pagehead(&$pdf, $outputlangs, $pagenb) + { global $conf,$langs; // New page - $pdf->AddPage(); + $pdf->AddPage(); - // Show title - $pdf->SetFont('Arial','B',10); - $pdf->SetXY($this->marge_gauche, $this->marge_haute); - $pdf->MultiCell(80, 1, $this->title, 0, 'L', 0); + // Show title + $pdf->SetFont('Arial','B',10); + $pdf->SetXY($this->marge_gauche, $this->marge_haute); + $pdf->MultiCell(80, 1, $this->title, 0, 'L', 0); $pdf->SetXY($this->page_largeur-$this->marge_droite-40, $this->marge_haute); - $pdf->MultiCell(40, 1, $pagenb.'/{nb}', 0, 'R', 0); + $pdf->MultiCell(40, 1, $pagenb.'/{nb}', 0, 'R', 0); - $y=$pdf->GetY()+2; + $y=$pdf->GetY()+2; $pdf->Rect($this->marge_gauche, $y, - $this->page_largeur - $this->marge_gauche - $this->marge_droite, - $this->page_hauteur - $this->marge_haute - $this->marge_basse); + $this->page_largeur - $this->marge_gauche - $this->marge_droite, + $this->page_hauteur - $this->marge_haute - $this->marge_basse); $y=$pdf->GetY()+1; return $y; - } + } } ?> diff --git a/scripts/prelevement/prelevement-verif.php b/scripts/prelevement/prelevement-verif.php index 740a6ac897d..dbf956b41a5 100644 --- a/scripts/prelevement/prelevement-verif.php +++ b/scripts/prelevement/prelevement-verif.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005 Laurent Destailleur +/* Copyright (C) 2005 Rodolphe Quiedeville + * Copyright (C) 2005-2009 Laurent Destailleur * * 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 @@ -19,21 +19,28 @@ * $Id$ * $Source$ */ - -/** - \file scripts/prelevement/prelevement-verif.php - \ingroup prelevement - \brief Vérifie que les sociétés qui doivent être prélevées ont bien un RIB correct -*/ -// Test si mode batch +/** + * \file scripts/prelevement/prelevement-verif.php + * \ingroup prelevement + * \brief Vérifie que les sociétés qui doivent être prélevées ont bien un RIB correct + */ + +// Test si mode CLI $sapi_type = php_sapi_name(); +$script_file=__FILE__; +if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1]; + if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n"; - exit; + echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer $script_file en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n"; + exit; } -require_once("../../htdocs/master.inc.php"); +// Recupere env dolibarr +$version='$Revision$'; +$path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]); + +require_once($path."../../htdocs/master.inc.php"); require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); @@ -61,7 +68,7 @@ $factures_prev = array(); if (!$error) { - + $sql = "SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; @@ -72,21 +79,21 @@ if (!$error) $sql .= " AND pfd.traite = 0"; $sql .= " AND f.total_ttc > 0"; $sql .= " AND f.fk_mode_reglement = 3"; - + if ( $db->query($sql) ) { $num = $db->num_rows(); - + $i = 0; - + while ($i < $num) { $row = $db->fetch_row(); - + $factures[$i] = $row; - + $i++; - } + } $db->free(); dol_syslog("$i factures à prélever"); } @@ -114,17 +121,17 @@ if (!$error) dol_syslog("Début vérification des RIB"); if (sizeof($factures) > 0) - { + { foreach ($factures as $fac) { $fact = new Facture($db); - + if ($fact->fetch($fac[0]) == 1) { $soc = new Societe($db); if ($soc->fetch($fact->socid) == 1) { - + if ($soc->verif_rib() == 1) { diff --git a/scripts/prelevement/prelevement.php b/scripts/prelevement/prelevement.php index 9fa70683e23..7c75fba444b 100644 --- a/scripts/prelevement/prelevement.php +++ b/scripts/prelevement/prelevement.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005 Laurent Destailleur +/* Copyright (C) 2005 Rodolphe Quiedeville + * Copyright (C) 2005-2009 Laurent Destailleur * * 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 @@ -21,20 +21,27 @@ */ /** - \file scripts/prelevement/prelevement.php - \ingroup prelevement - \brief Script de prelevement -*/ + * \file scripts/prelevement/prelevement.php + * \ingroup prelevement + * \brief Script de prelevement + */ -// Test si mode batch +// Test si mode CLI $sapi_type = php_sapi_name(); +$script_file=__FILE__; +if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1]; + if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer mailing-send.php en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n"; - exit; + echo "Erreur: Vous utilisez l'interpreteur PHP pour le mode CGI. Pour executer $script_file en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n"; + exit; } -require_once("../../htdocs/master.inc.php"); -require_once(DOL_DOCUMENT_ROOT."/bon-prelevement.class.php"); +// Recupere env dolibarr +$version='$Revision$'; +$path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]); + +require_once($path."../../htdocs/master.inc.php"); +require_once(DOL_DOCUMENT_ROOT."/compta/prelevement/bon-prelevement.class.php"); require_once(DOL_DOCUMENT_ROOT."/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); require_once(DOL_DOCUMENT_ROOT."/paiement.class.php"); @@ -59,45 +66,45 @@ $factures_prev = 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"; - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; - $sql .= " , ".MAIN_DB_PREFIX."societe as s"; - $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; - $sql .= " WHERE f.rowid = pfd.fk_facture"; - $sql .= " AND s.rowid = f.fk_soc"; - $sql .= " AND f.fk_statut = 1"; - $sql .= " AND f.paye = 0"; - $sql .= " AND pfd.traite = 0"; - $sql .= " AND f.total_ttc > 0"; - $sql .= " AND f.fk_mode_reglement = 3"; - - if ( $db->query($sql) ) - { - $num = $db->num_rows(); - $i = 0; - - while ($i < $num) + $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"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= " , ".MAIN_DB_PREFIX."societe as s"; + $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; + + $sql .= " WHERE f.rowid = pfd.fk_facture"; + $sql .= " AND s.rowid = f.fk_soc"; + $sql .= " AND f.fk_statut = 1"; + $sql .= " AND f.paye = 0"; + $sql .= " AND pfd.traite = 0"; + $sql .= " AND f.total_ttc > 0"; + $sql .= " AND f.fk_mode_reglement = 3"; + + if ( $db->query($sql) ) { + $num = $db->num_rows(); + $i = 0; + + while ($i < $num) + { $row = $db->fetch_row(); - + $factures[$i] = $row; - + $i++; - } - $db->free(); - dol_syslog("$i factures à prélever"); - } - else - { - $error = 1; - dol_syslog("Erreur -1"); - dol_syslog($db->error()); - } + } + $db->free(); + dol_syslog("$i factures à prélever"); + } + else + { + $error = 1; + dol_syslog("Erreur -1"); + dol_syslog($db->error()); + } } /* @@ -108,51 +115,51 @@ if (!$error) if (!$error) { - /* - * Vérification des RIB - * - */ - $i = 0; - dol_syslog("Début vérification des RIB"); + /* + * Vérification des RIB + * + */ + $i = 0; + dol_syslog("Début vérification des RIB"); - if (sizeof($factures) > 0) - { - foreach ($factures as $fac) + if (sizeof($factures) > 0) { + foreach ($factures as $fac) + { $fact = new Facture($db); - + if ($fact->fetch($fac[0]) == 1) - { - $soc = new Societe($db); - if ($soc->fetch($fact->socid) == 1) - { - if ($soc->verif_rib() == 1) - { - $factures_prev[$i] = $fac; - /* second tableau necessaire pour bon-prelevement */ - $factures_prev_id[$i] = $fac[0]; - $i++; - } - else - { - dol_syslog("Erreur de RIB societe $fact->socid $soc->nom"); - } - } - else - { - dol_syslog("Impossible de lire la société"); - } - } + { + $soc = new Societe($db); + if ($soc->fetch($fact->socid) == 1) + { + if ($soc->verif_rib() == 1) + { + $factures_prev[$i] = $fac; + /* second tableau necessaire pour bon-prelevement */ + $factures_prev_id[$i] = $fac[0]; + $i++; + } + else + { + dol_syslog("Erreur de RIB societe $fact->socid $soc->nom"); + } + } + else + { + dol_syslog("Impossible de lire la société"); + } + } else - { - dol_syslog("Impossible de lire la facture"); - } + { + dol_syslog("Impossible de lire la facture"); + } + } + } + else + { + dol_syslog("Aucune factures a traiter"); } - } - else - { - dol_syslog("Aucune factures a traiter"); - } } /* @@ -162,220 +169,220 @@ if (!$error) */ dol_syslog(sizeof($factures_prev)." factures seront prélevées"); - +print 'eeee'.$factures_prev; if (sizeof($factures_prev) > 0) { - /* - * Ouverture de la transaction - * - */ + /* + * Ouverture de la transaction + * + */ - if (!$db->query("BEGIN")) - { - $error++; - } - - /* - * Traitements - * - */ - - if (!$error) - { - $ref = "T".substr($year,-2).$month; - - /* - * - * - */ - $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."prelevement_bons"; - $sql .= " WHERE ref LIKE '$ref%'"; - - if ($db->query($sql)) - { - $row = $db->fetch_row(); - } - else + if (!$db->query("BEGIN")) { + $error++; + } + + /* + * Traitements + * + */ + + if (!$error) + { + $ref = "T".substr($year,-2).$month; + + /* + * + * + */ + $sql = "SELECT count(*) FROM ".MAIN_DB_PREFIX."prelevement_bons"; + $sql .= " WHERE ref LIKE '$ref%'"; + + if ($db->query($sql)) + { + $row = $db->fetch_row(); + } + else + { $error++; dol_syslog("Erreur recherche reference"); - } + } - $ref = $ref . substr("00".($row[0]+1), -2); + $ref = $ref . substr("00".($row[0]+1), -2); - $filebonprev = $ref; - - /* - * Creation du bon de prelevement - * - */ - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons (ref,datec)"; - $sql .= " VALUES ('".$ref."',".$db->idate(mktime()).")"; - - if ($db->query($sql)) - { + $filebonprev = $ref; + + /* + * Creation du bon de prelevement + * + */ + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons (ref,datec)"; + $sql .= " VALUES ('".$ref."',".$db->idate(mktime()).")"; + + if ($db->query($sql)) + { $prev_id = $db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons"); $bonprev = new BonPrelevement($db, DOL_DATA_ROOT."/prelevement/bon/".$filebonprev); $bonprev->id = $prev_id; - } - else - { + } + else + { $error++; dol_syslog("Erreur création du bon de prelevement"); - } - - } - - /* - * - * - * - */ - if (!$error) - { - dol_syslog("Début génération des paiements"); - dol_syslog("Nombre de factures ".sizeof($factures_prev)); - - if (sizeof($factures_prev) > 0) - { - foreach ($factures_prev as $fac) - { - $fact = new Facture($db); - $fact->fetch($fac[0]); - - $pai = new Paiement($db); - - $pai->amounts = array(); - $pai->amounts[$fac[0]] = $fact->total_ttc; - $pai->datepaye = $db->idate($datetimeprev); - $pai->paiementid = 3; // prélèvement - $pai->num_paiement = $ref; - - if ($pai->create($user, 1) == -1) // on appelle en no_commit - { - $error++; - dol_syslog("Erreur creation paiement facture ".$fac[0]); } - else - { - /* - * Validation du paiement - */ - $pai->valide(); - /* - * Ajout d'une ligne de prélèvement - * - * - * $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++; - } - - /* - * Mise à jour des demandes - * - */ - $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande"; - $sql .= " SET traite = 1"; - $sql .= ", date_traite=".$db->idate(mktime()); - $sql .= ", fk_prelevement_bons = ".$prev_id; - $sql .= " WHERE rowid=".$fac[1]; - - if ($db->query($sql)) - { - - } - else - { - $error++; - dol_syslog("Erreur mise a jour des demandes"); - dol_syslog($db->error()); - } - - } - } } - - dol_syslog("Fin des paiements"); - } - if (!$error) - { - /* - * Bon de Prelevement - * - * - */ - - dol_syslog("Debut prelevement"); - dol_syslog("Nombre de factures ".sizeof($factures_prev)); - - if (sizeof($factures_prev) > 0) + /* + * + * + * + */ + if (!$error) { - $bonprev->date_echeance = $datetimeprev; - $bonprev->reference_remise = $ref; + dol_syslog("Début génération des paiements"); + dol_syslog("Nombre de factures ".sizeof($factures_prev)); + if (sizeof($factures_prev) > 0) + { + foreach ($factures_prev as $fac) + { + $fact = new Facture($db); + $fact->fetch($fac[0]); - $bonprev->numero_national_emetteur = PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR; - $bonprev->raison_sociale = PRELEVEMENT_RAISON_SOCIALE; + $pai = new Paiement($db); - $bonprev->emetteur_code_etablissement = PRELEVEMENT_CODE_BANQUE; - $bonprev->emetteur_code_guichet = PRELEVEMENT_CODE_GUICHET; - $bonprev->emetteur_numero_compte = PRELEVEMENT_NUMERO_COMPTE; + $pai->amounts = array(); + $pai->amounts[$fac[0]] = $fact->total_ttc; + $pai->datepaye = $db->idate($datetimeprev); + $pai->paiementid = 3; // prélèvement + $pai->num_paiement = $ref; - - $bonprev->factures = $factures_prev_id; - - $bonprev->generate(); + if ($pai->create($user, 1) == -1) // on appelle en no_commit + { + $error++; + dol_syslog("Erreur creation paiement facture ".$fac[0]); + } + else + { + /* + * Validation du paiement + */ + $pai->valide(); + + /* + * Ajout d'une ligne de prélèvement + * + * + * $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++; + } + + /* + * Mise à jour des demandes + * + */ + $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande"; + $sql .= " SET traite = 1"; + $sql .= ", date_traite=".$db->idate(mktime()); + $sql .= ", fk_prelevement_bons = ".$prev_id; + $sql .= " WHERE rowid=".$fac[1]; + + if ($db->query($sql)) + { + + } + else + { + $error++; + dol_syslog("Erreur mise a jour des demandes"); + dol_syslog($db->error()); + } + + } + } + } + + dol_syslog("Fin des paiements"); } - dol_syslog( $filebonprev ) ; - dol_syslog("Fin prelevement"); - } - /* - * Mise à jour du total - * - */ + if (!$error) + { + /* + * Bon de Prelevement + * + * + */ - $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; - $sql .= " SET amount = ".price2num($bonprev->total); - $sql .= " WHERE rowid = ".$prev_id; + dol_syslog("Debut prelevement"); + dol_syslog("Nombre de factures ".sizeof($factures_prev)); - if (!$db->query($sql)) - { - $error++; - dol_syslog("Erreur mise à jour du total"); - dol_syslog($sql); - } + if (sizeof($factures_prev) > 0) + { + $bonprev->date_echeance = $datetimeprev; + $bonprev->reference_remise = $ref; - /* - * Rollback ou Commit - * - */ - if (!$error) - { - $db->query("COMMIT"); - dol_syslog("COMMIT"); - } - else - { - $db->query("ROLLBAK"); - dol_syslog("ROLLBACK"); - } + + $bonprev->numero_national_emetteur = PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR; + $bonprev->raison_sociale = PRELEVEMENT_RAISON_SOCIALE; + + $bonprev->emetteur_code_etablissement = PRELEVEMENT_CODE_BANQUE; + $bonprev->emetteur_code_guichet = PRELEVEMENT_CODE_GUICHET; + $bonprev->emetteur_numero_compte = PRELEVEMENT_NUMERO_COMPTE; + + + $bonprev->factures = $factures_prev_id; + + $bonprev->generate(); + } + dol_syslog( $filebonprev ) ; + dol_syslog("Fin prelevement"); + } + + /* + * Mise à jour du total + * + */ + + $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; + $sql .= " SET amount = ".price2num($bonprev->total); + $sql .= " WHERE rowid = ".$prev_id; + + if (!$db->query($sql)) + { + $error++; + dol_syslog("Erreur mise à jour du total"); + dol_syslog($sql); + } + + /* + * Rollback ou Commit + * + */ + if (!$error) + { + $db->query("COMMIT"); + dol_syslog("COMMIT"); + } + else + { + $db->query("ROLLBAK"); + dol_syslog("ROLLBACK"); + } } $db->close();