Some fix in standingorder module

This commit is contained in:
Laurent Destailleur 2009-03-28 19:59:12 +00:00
parent 5c57487b4c
commit c5d655afc2
6 changed files with 831 additions and 800 deletions

View File

@ -135,7 +135,7 @@ class BonPrelevement extends CommonObject
if ($concat == 1)
{
/*
* On aggr<EFBFBD>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<EFBFBD>gation
* Pas de d'agregation
*/
$sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_lignes (fk_prelevement_bons";
$sql .= " , fk_soc , client_nom ";

View File

@ -1,6 +1,6 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 '<div class="error">'.$bon->ReadError($_GET["error"]).'</div>';
dol_fiche_head($head, $hselected, $langs->trans("WithdrawalReceipt"));
if (isset($_GET["error"]))
{
print '<div class="error">'.$bon->ReadError($_GET["error"]).'</div>';
}
if ($_GET["action"] == 'credite')
{
$html->form_confirm("fiche.php?id=".$bon->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite");
print '<br />';
}
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td>'.$bon->getNomUrl(1).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec,'dayhour').'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Amount").'</td><td>'.price($bon->amount).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("File").'</td><td>';
$relativepath = 'bon/'.$bon->ref;
print '<a href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart=prelevement&amp;file='.urlencode($relativepath).'">'.$bon->ref.'</a>';
print '</td></tr>';
print '<tr><td width="20%">Statut</td><td>';
print '<img src="./statut'.$bon->statut.'.png">&nbsp;';
print $lipre->statuts[$lipre->statut].'</td></tr>';
if($bon->date_trans <> 0)
{
$muser = new User($db, $bon->user_trans);
$muser->fetch();
print '<tr><td width="20%">Date Transmission / Par</td><td>';
print dol_print_date($bon->date_trans,'dayhour');
print ' par '.$muser->fullname.'</td></tr>';
print '<tr><td width="20%">Methode Transmission</td><td>';
print $bon->methodes_trans[$bon->method_trans];
print '</td></tr>';
}
if($bon->date_credit <> 0)
{
print '<tr><td width="20%">Credit on</td><td>';
print dol_print_date($bon->date_credit,'dayhour');
print '</td></tr>';
}
print '</table><br />';
if($bon->date_trans == 0)
{
print '<form method="post" name="userfile" action="fiche.php?id='.$bon->id.'" enctype="multipart/form-data">';
print '<input type="hidden" name="action" value="infotrans">';
print '<table class="border" width="100%">';
print '<tr><td width="20%">Date Transmission</td><td>';
print $html->select_date('','','','','',"userfile");
print '</td></tr>';
print '<tr><td width="20%">Methode Transmission</td><td>';
print $html->select_array("methode",$bon->methodes_trans);
print '</td></tr>';
print '<tr><td width="20%">'.$langs->trans("File").'</td><td>';
print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
print '<input class="flat" type="file" name="userfile" size="80"><br />';
print '</td></tr>';
print '<tr><td colspan="2" align="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Send").'">';
print '</td></tr>';
print '</table></form>';
}
if($bon->date_trans <> 0 && $bon->date_credit == 0)
{
print '<form name="infocredit" method="post" action="fiche.php?id='.$bon->id.'">';
print '<input type="hidden" name="action" value="infocredit">';
print '<table class="border" width="100%">';
print '<tr><td width="20%">Crédité le</td><td>';
print $html->select_date('','','','','',"infocredit");
print '</td></tr>';
print '<tr><td colspan="2" align="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Send").'">';
print '</td></tr>';
print '</table></form>';
}
}
if ($_GET["action"] == 'credite')
else
{
$html->form_confirm("fiche.php?id=".$bon->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite");
print '<br />';
dol_print_error($db);
}
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td>'.$bon->getNomUrl(1).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Date").'</td><td>'.dol_print_date($bon->datec,'dayhour').'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Amount").'</td><td>'.price($bon->amount).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("File").'</td><td>';
$relativepath = 'bon/'.$bon->ref;
print '<a href="'.DOL_URL_ROOT.'/document.php?type=text/plain&amp;modulepart=prelevement&amp;file='.urlencode($relativepath).'">'.$bon->ref.'</a>';
print '</td></tr>';
print '<tr><td width="20%">Statut</td><td>';
print '<img src="./statut'.$bon->statut.'.png">&nbsp;';
print $lipre->statuts[$lipre->statut].'</td></tr>';
if($bon->date_trans <> 0)
{
$muser = new User($db, $bon->user_trans);
$muser->fetch();
print '<tr><td width="20%">Date Transmission / Par</td><td>';
print dol_print_date($bon->date_trans,'dayhour');
print ' par '.$muser->fullname.'</td></tr>';
print '<tr><td width="20%">Methode Transmission</td><td>';
print $bon->methodes_trans[$bon->method_trans];
print '</td></tr>';
}
if($bon->date_credit <> 0)
{
print '<tr><td width="20%">Credit on</td><td>';
print dol_print_date($bon->date_credit,'dayhour');
print '</td></tr>';
}
print '</table><br />';
if($bon->date_trans == 0)
{
print '<form method="post" name="userfile" action="fiche.php?id='.$bon->id.'" enctype="multipart/form-data">';
print '<input type="hidden" name="action" value="infotrans">';
print '<table class="border" width="100%">';
print '<tr><td width="20%">Date Transmission</td><td>';
print $html->select_date('','','','','',"userfile");
print '</td></tr>';
print '<tr><td width="20%">Methode Transmission</td><td>';
print $html->select_array("methode",$bon->methodes_trans);
print '</td></tr>';
print '<tr><td width="20%">'.$langs->trans("File").'</td><td>';
print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
print '<input class="flat" type="file" name="userfile" size="80"><br />';
print '</td></tr>';
print '<tr><td colspan="2" align="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Send").'">';
print '</td></tr>';
print '</table></form>';
}
if($bon->date_trans <> 0 && $bon->date_credit == 0)
{
print '<form name="infocredit" method="post" action="fiche.php?id='.$bon->id.'">';
print '<input type="hidden" name="action" value="infocredit">';
print '<table class="border" width="100%">';
print '<tr><td width="20%">Crédité le</td><td>';
print $html->select_date('','','','','',"infocredit");
print '</td></tr>';
print '<tr><td colspan="2" align="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Send").'">';
print '</td></tr>';
print '</table></form>';
}
}
else
{
dol_print_error($db);
}
}
/* ************************************************************************** */
/* */
/* Barre d'action */
@ -240,15 +244,15 @@ if ($_GET["id"])
print "\n</div>\n<div class=\"tabsAction\">\n";
if ($_GET["action"] == '')
{
if ($bon->credite == 0)
{
print "<a class=\"butAction\" href=\"fiche.php?action=credite&amp;id=$bon->id\">".$langs->trans("ClassCredited")."</a>";
}
{
if ($bon->credite == 0)
{
print "<a class=\"butAction\" href=\"fiche.php?action=credite&amp;id=$bon->id\">".$langs->trans("ClassCredited")."</a>";
}
}
print "</div>";

View File

@ -1,5 +1,6 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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 '<table class="border" width="100%">';
print '<tr><td width="20%">Bons de prélèvement</td><td>';
print '<a href="fiche.php?id='.$lipre->bon_rowid.'">'.$lipre->bon_ref.'</a></td></tr>';
print '<tr><td width="20%">Montant</td><td>'.price($lipre->amount).'</td></tr>';
print '<tr><td width="20%">Statut</td><td>';
print '<img src="./statut'.$lipre->statut.'.png">&nbsp;';
print $lipre->statuts[$lipre->statut].'</td></tr>';
if ($lipre->statut == 3)
if ($lipre->fetch($_GET["id"]) == 0)
{
$rej = new RejetPrelevement($db, $user);
$resf = $rej->fetch($lipre->id);
if ($resf == 0)
{
print '<tr><td width="20%">Motif du rejet</td><td>'.$rej->motif.'</td></tr>';
print '<tr><td width="20%">Date du rejet</td><td>';
if ($rej->date_rejet == 0)
$bon = new BonPrelevement($db);
$bon->fetch($lipre->bon_rowid);
dol_fiche_head($head, $hselected, $langs->trans("StandingOrder"));
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("WithdrawalReceipt").'</td><td>';
print '<a href="fiche.php?id='.$lipre->bon_rowid.'">'.$lipre->bon_ref.'</a></td></tr>';
print '<tr><td width="20%">'.$langs->trans("Amount").'</td><td>'.price($lipre->amount).'</td></tr>';
print '<tr><td width="20%">'.$langs->trans("Status").'</td><td>';
print '<img src="./statut'.$lipre->statut.'.png">&nbsp;';
print $lipre->statuts[$lipre->statut].'</td></tr>';
if ($lipre->statut == 3)
{
/* Historique pour certaines install */
print "Inconnue";
$rej = new RejetPrelevement($db, $user);
$resf = $rej->fetch($lipre->id);
if ($resf == 0)
{
print '<tr><td width="20%">Motif du rejet</td><td>'.$rej->motif.'</td></tr>';
print '<tr><td width="20%">Date du rejet</td><td>';
if ($rej->date_rejet == 0)
{
/* Historique pour certaines install */
print $langs->trans("Unknown");
}
else
{
print dol_print_date($rej->date_rejet,'day');
}
print '</td></tr>';
}
else
{
print '<tr><td width="20%">'.$resf.'</td></tr>';
}
}
else
{
print dol_print_date($rej->date_rejet,'day');
}
print '</td></tr>';
}
else
{
print '<tr><td width="20%">'.$resf.'</td></tr>';
}
print '</table><br />';
}
else
{
print "Erreur";
}
print '</table><br />';
}
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 '<form name="confirm_rejet" method="post" action="ligne.php?id='.$_GET["id"].'">';
print '<input type="hidden" name="action" value="confirm_rejet">';
print '<table class="border" width="100%">';
print '<tr><td colspan="3">Rejet de prélèvement</td></tr>';
print '<tr><td class="valid">Etes-vous sûr de vouloir saisir un rejet de prélèvement pour la société '.$soc->nom.' ?</td>';
print '<td colspan="2" class="valid">';
print '<select name="confirm">';
print '<option value="yes">oui</option>';
print '<option value="no" selected="true">non</option>';
print '</select>';
print '</td></tr>';
print '<tr><td class="valid">Date du rejet</td>';
print '<td colspan="2" class="valid">';
print $html->select_date('','','','','',"confirm_rejet");
print '</td></tr>';
print '<tr><td class="valid">Motif du rejet</td>';
print '<td class="valid">';
print '<select name="motif">';
print '<option value="0">(Motif du Rejet)</option>';
foreach($rej->motifs as $key => $value)
if ($_GET["action"] == 'rejet')
{
$html = new Form($db);
$soc = new Societe($db);
$soc->fetch($lipre->socid);
$rej = new RejetPrelevement($db, $user);
print '<form name="confirm_rejet" method="post" action="ligne.php?id='.$_GET["id"].'">';
print '<input type="hidden" name="action" value="confirm_rejet">';
print '<table class="border" width="100%">';
print '<tr><td colspan="3">Rejet de prélèvement</td></tr>';
print '<tr><td class="valid">Etes-vous sûr de vouloir saisir un rejet de prélèvement pour la société '.$soc->nom.' ?</td>';
print '<td colspan="2" class="valid">';
print '<select name="confirm">';
print '<option value="yes">oui</option>';
print '<option value="no" selected="true">non</option>';
print '</select>';
print '</td></tr>';
print '<tr><td class="valid">Date du rejet</td>';
print '<td colspan="2" class="valid">';
print $html->select_date('','','','','',"confirm_rejet");
print '</td></tr>';
print '<tr><td class="valid">Motif du rejet</td>';
print '<td class="valid">';
print '<select name="motif">';
print '<option value="0">(Motif du Rejet)</option>';
foreach($rej->motifs as $key => $value)
{
print '<option value="'.$key.'">'.$value.'</option>';
}
print '</select>';
print '</td>';
print '<td class="valid" align="center">';
print '<input type="submit" value="Confirmer"></td></tr>';
print '<tr><td class="valid">Facturation du rejet</td>';
print '<td class="valid" colspan="2">';
print '<select name="facturer">';
print '<option value="0">Ne Pas Facturer le rejet</option>';
print '<option value="1">Facturer le rejet au client</option>';
print '</select>';
print '</td>';
print '</table></form>';
}
print '</select>';
print '</td>';
print '<td class="valid" align="center">';
print '<input type="submit" value="Confirmer"></td></tr>';
print '<tr><td class="valid">Facturation du rejet</td>';
print '<td class="valid" colspan="2">';
print '<select name="facturer">';
print '<option value="0">Ne Pas Facturer le rejet</option>';
print '<option value="1">Facturer le rejet au client</option>';
print '</select>';
print '</td>';
print '</table></form>';
}
$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 = "&amp;id=".$_GET["id"];
print_barre_liste("Factures", $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num);
print"\n<!-- debut table -->\n";
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
print '<tr class="liste_titre">';
print '<td>Facture</td><td>Société</td>Montant</td>';
print '<td>&nbsp;</td></tr>';
$var=True;
$total = 0;
while ($i < min($num,$conf->liste_limit))
if ($_GET["socid"])
{
$obj = $db->fetch_object($result);
print "<tr $bc[$var]><td>";
print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->facid.'">';
print img_object($langs->trans("ShowBill"),"bill");
print '</a>&nbsp;';
print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->socid.'">';
print img_object($langs->trans("ShowCompany"),"company"). ' '.stripslashes($obj->nom)."</a></td>\n";
print '<td align="center">'.price($obj->total_ttc)."</td>\n";
print "</tr>\n";
$i++;
$sql .= " AND s.rowid = ".$_GET["socid"];
}
print "</table>";
$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 = "&amp;id=".$_GET["id"];
print_barre_liste("Factures", $page, "factures.php", $urladd, $sortfield, $sortorder, '', $num, 0, '');
print"\n<!-- debut table -->\n";
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Invoice").'</td><td>'.$langs->trans("Company").'</td><td align="right">'.$langs->trans("Amount").'</td>';
print '</tr>';
$var=True;
$total = 0;
$var=false;
while ($i < min($num,$conf->liste_limit))
{
$obj = $db->fetch_object($result);
print "<tr $bc[$var]><td>";
print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->facid.'">';
print img_object($langs->trans("ShowBill"),"bill");
print '</a>&nbsp;';
print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?facid='.$obj->facid.'">'.$obj->ref."</a></td>\n";
print '<td><a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$obj->socid.'">';
print img_object($langs->trans("ShowCompany"),"company"). ' '.stripslashes($obj->nom)."</a></td>\n";
print '<td align="right">'.price($obj->total_ttc)."</td>\n";
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
print "</tr>\n";
print "\n</div>\n<div class=\"tabsAction\">\n";
$i++;
}
if ($_GET["action"] == '')
{
if ($bon->credite == 1 && $lipre->statut == 2)
{
print "<a class=\"butAction\" href=\"ligne.php?action=rejet&amp;id=$lipre->id\">".$langs->trans("Emmetre un rejet")."</a>";
print "</table>";
$db->free($result);
}
else
{
dol_print_error($db);
}
}
print "</div>";
$db->close();
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
print "\n</div>\n<div class=\"tabsAction\">\n";
if ($_GET["action"] == '')
{
if ($bon->credite == 1 && $lipre->statut == 2)
{
print "<a class=\"butAction\" href=\"ligne.php?action=rejet&amp;id=$lipre->id\">".$langs->trans("Emmetre un rejet")."</a>";
}
}
print "</div>";
}
llxFooter('$Date$ - $Revision$');

View File

@ -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;
}
}
}
?>

View File

@ -1,6 +1,6 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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)
{

View File

@ -1,6 +1,6 @@
<?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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();