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) if ($concat == 1)
{ {
/* /*
* On aggr<EFBFBD>ge les lignes * On aggrege les lignes
*/ */
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."prelevement_lignes"; $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."prelevement_lignes";
$sql .= " WHERE fk_prelevement_bons".$this->id; $sql .= " WHERE fk_prelevement_bons".$this->id;
@ -156,7 +156,7 @@ class BonPrelevement extends CommonObject
else else
{ {
/* /*
* Pas de d'agr<EFBFBD>gation * Pas de d'agregation
*/ */
$sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_lignes (fk_prelevement_bons"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_lignes (fk_prelevement_bons";
$sql .= " , fk_soc , client_nom "; $sql .= " , fk_soc , client_nom ";

View File

@ -1,6 +1,6 @@
<?PHP <?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* 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 * 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 * 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 * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
/** /**
\file htdocs/compta/prelevement/fiche.php * \file htdocs/compta/prelevement/fiche.php
\ingroup prelevement * \ingroup prelevement
\brief Fiche prelevement * \brief Fiche prelevement
\version $Id$ * \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
if (!$user->rights->prelevement->bons->lire) if (!$user->rights->prelevement->bons->lire)
accessforbidden(); accessforbidden();
$langs->load("bills"); $langs->load("bills");
$langs->load("withdrawals"); $langs->load("withdrawals");
/* // Security check
* Sécurité accés client
*/
if ($user->societe_id > 0) accessforbidden(); if ($user->societe_id > 0) accessforbidden();
@ -45,86 +43,91 @@ if ($user->societe_id > 0) accessforbidden();
if ($_POST["action"] == 'confirm_credite' && $_POST["confirm"] == yes) if ($_POST["action"] == 'confirm_credite' && $_POST["confirm"] == yes)
{ {
$bon = new BonPrelevement($db,""); $bon = new BonPrelevement($db,"");
$bon->id = $_GET["id"]; $bon->id = $_GET["id"];
$bon->set_credite(); $bon->set_credite();
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
exit;
} }
if ($_POST["action"] == 'infotrans') if ($_POST["action"] == 'infotrans')
{ {
$bon = new BonPrelevement($db,""); $bon = new BonPrelevement($db,"");
$bon->fetch($_GET["id"]); $bon->fetch($_GET["id"]);
if ($_FILES['userfile']['name'] && basename($_FILES['userfile']['name'],".ps") == $bon->ref) 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)
{ {
$dt = dol_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $dir = $conf->prelevement->dir_output.'/bon/';
$bon->set_infotrans($user, $dt, $_POST["methode"]);
}
}
else
{
dol_syslog("Fichier invalide",LOG_WARNING);
}
Header("Location: fiche.php?id=".$_GET["id"]); if (dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $dir . "/" . $_FILES['userfile']['name'],1) > 0)
exit; {
$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') if ($_POST["action"] == 'infocredit')
{ {
$bon = new BonPrelevement($db,""); $bon = new BonPrelevement($db,"");
$bon->Fetch($_GET["id"]); $bon->Fetch($_GET["id"]);
$dt = mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $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) if ($error == 0)
{ {
Header("Location: fiche.php?id=".$_GET["id"]); Header("Location: fiche.php?id=".$_GET["id"]);
} }
else else
{ {
Header("Location: fiche.php?id=".$_GET["id"]."&error=$error"); Header("Location: fiche.php?id=".$_GET["id"]."&error=$error");
} }
} }
/*
* View
*/
llxHeader('',$langs->trans("WithdrawalReceipt")); llxHeader('',$langs->trans("WithdrawalReceipt"));
$h = 0; $h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche.php?id='.$_GET["id"]; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche.php?id='.$_GET["id"];
$head[$h][1] = $langs->trans("Card"); $head[$h][1] = $langs->trans("Card");
$hselected = $h; $hselected = $h;
$h++; $h++;
if ($conf->use_preview_tabs) if ($conf->use_preview_tabs)
{ {
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/bon.php?id='.$_GET["id"]; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/bon.php?id='.$_GET["id"];
$head[$h][1] = $langs->trans("Preview"); $head[$h][1] = $langs->trans("Preview");
$h++; $h++;
} }
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/lignes.php?id='.$_GET["id"]; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/lignes.php?id='.$_GET["id"];
$head[$h][1] = $langs->trans("Lines"); $head[$h][1] = $langs->trans("Lines");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/factures.php?id='.$_GET["id"]; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/factures.php?id='.$_GET["id"];
$head[$h][1] = $langs->trans("Bills"); $head[$h][1] = $langs->trans("Bills");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-rejet.php?id='.$_GET["id"]; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-rejet.php?id='.$_GET["id"];
$head[$h][1] = $langs->trans("Rejects"); $head[$h][1] = $langs->trans("Rejects");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-stat.php?id='.$_GET["id"]; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-stat.php?id='.$_GET["id"];
$head[$h][1] = $langs->trans("Statistics"); $head[$h][1] = $langs->trans("Statistics");
$h++; $h++;
$prev_id = $_GET["id"]; $prev_id = $_GET["id"];
@ -132,105 +135,106 @@ $html = new Form($db);
if ($_GET["id"]) if ($_GET["id"])
{ {
$bon = new BonPrelevement($db,""); $bon = new BonPrelevement($db,"");
if ($bon->fetch($_GET["id"]) == 0) if ($bon->fetch($_GET["id"]) == 0)
{
dol_fiche_head($head, $hselected, $langs->trans("WithdrawalReceipt"));
if (isset($_GET["error"]))
{ {
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>';
}
} }
else
if ($_GET["action"] == 'credite')
{ {
$html->form_confirm("fiche.php?id=".$bon->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite"); dol_print_error($db);
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>';
}
}
else
{
dol_print_error($db);
}
} }
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* Barre d'action */ /* Barre d'action */
@ -240,15 +244,15 @@ if ($_GET["id"])
print "\n</div>\n<div class=\"tabsAction\">\n"; print "\n</div>\n<div class=\"tabsAction\">\n";
if ($_GET["action"] == '') if ($_GET["action"] == '')
{ {
if ($bon->credite == 0) if ($bon->credite == 0)
{ {
print "<a class=\"butAction\" href=\"fiche.php?action=credite&amp;id=$bon->id\">".$langs->trans("ClassCredited")."</a>"; print "<a class=\"butAction\" href=\"fiche.php?action=credite&amp;id=$bon->id\">".$langs->trans("ClassCredited")."</a>";
} }
} }
print "</div>"; print "</div>";

View File

@ -1,5 +1,6 @@
<?PHP <?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* 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 * 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 * 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 * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 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("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/compta/prelevement/ligne-prelevement.class.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."/compta/prelevement/rejet-prelevement.class.php");
require_once(DOL_DOCUMENT_ROOT."/paiement.class.php"); require_once(DOL_DOCUMENT_ROOT."/paiement.class.php");
// Sécurité accés client // Security check
if ($user->societe_id > 0) accessforbidden(); if ($user->societe_id > 0) accessforbidden();
if ($_POST["action"] == 'confirm_rejet') if ($_POST["action"] == 'confirm_rejet')
{ {
if ( $_POST["confirm"] == 'yes') 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["motif"] > 0 && $daterej < time()) $daterej = mktime(2, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
{
$rej = new RejetPrelevement($db, $user); $lipre = new LignePrelevement($db, $user);
$rej->create($user, $_GET["id"], $_POST["motif"], $daterej, $lipre->bon_rowid, $_POST["facturer"]); if ($lipre->fetch($_GET["id"]) == 0)
{
Header("Location: ligne.php?id=".$_GET["id"]);
} if ($_POST["motif"] > 0 && $daterej < time())
else {
{ $rej = new RejetPrelevement($db, $user);
dol_syslog("Motif : ".$_POST["motif"]);
dol_syslog("$daterej $time "); $rej->create($user, $_GET["id"], $_POST["motif"], $daterej, $lipre->bon_rowid, $_POST["facturer"]);
Header("Location: ligne.php?id=".$_GET["id"]."&action=rejet");
} 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; $h = 0;
$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/ligne.php?id='.$_GET["id"]; $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; $hselected = $h;
$h++; $h++;
if ($_GET["id"]) if ($_GET["id"])
{ {
$lipre = new LignePrelevement($db, $user); $lipre = new LignePrelevement($db, $user);
if ($lipre->fetch($_GET["id"]) == 0) 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)
{ {
$rej = new RejetPrelevement($db, $user); $bon = new BonPrelevement($db);
$resf = $rej->fetch($lipre->id); $bon->fetch($lipre->bon_rowid);
if ($resf == 0)
{ dol_fiche_head($head, $hselected, $langs->trans("StandingOrder"));
print '<tr><td width="20%">Motif du rejet</td><td>'.$rej->motif.'</td></tr>';
print '<tr><td width="20%">Date du rejet</td><td>'; print '<table class="border" width="100%">';
if ($rej->date_rejet == 0)
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 */ $rej = new RejetPrelevement($db, $user);
print "Inconnue"; $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 '</table><br />';
} }
print '</td></tr>'; else
} {
else print "Erreur";
{
print '<tr><td width="20%">'.$resf.'</td></tr>';
}
} }
print '</table><br />';
}
else
{
print "Erreur";
}
if ($_GET["action"] == 'rejet')
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)
{ {
$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 '<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>'; $page = $_GET["page"];
print '<td class="valid" colspan="2">'; $sortorder = $_GET["sortorder"];
print '<select name="facturer">'; $sortfield = $_GET["sortfield"];
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"]; if ($page == -1) { $page = 0 ; }
$sortorder = $_GET["sortorder"];
$sortfield = $_GET["sortfield"];
if ($page == -1) { $page = 0 ; } $offset = $conf->liste_limit * $page ;
$pageprev = $page - 1;
$pagenext = $page + 1;
$offset = $conf->liste_limit * $page ; if ($sortorder == "") $sortorder="DESC";
$pageprev = $page - 1; if ($sortfield == "") $sortfield="pl.fk_soc";
$pagenext = $page + 1;
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"];
/* if ($_GET["socid"])
* 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))
{ {
$obj = $db->fetch_object($result); $sql .= " AND s.rowid = ".$_GET["socid"];
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++;
} }
print "</table>"; $sql .= " ORDER BY $sortfield $sortorder " . $db->plimit($conf->liste_limit+1, $offset);
$db->free($result); $result = $db->query($sql);
}
else
{
dol_print_error($db);
}
$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";
/* ************************************************************************** */ print "</tr>\n";
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
print "\n</div>\n<div class=\"tabsAction\">\n"; $i++;
}
if ($_GET["action"] == '') print "</table>";
{
$db->free($result);
if ($bon->credite == 1 && $lipre->statut == 2) }
{ else
print "<a class=\"butAction\" href=\"ligne.php?action=rejet&amp;id=$lipre->id\">".$langs->trans("Emmetre un rejet")."</a>"; {
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$'); llxFooter('$Date$ - $Revision$');

View File

@ -19,59 +19,59 @@
*/ */
/** /**
\file htdocs/includes/modules/action/rapport.pdf.php \file htdocs/includes/modules/action/rapport.pdf.php
\ingroup commercial \ingroup commercial
\brief Fichier de generation de PDF pour les rapports d'actions \brief Fichier de generation de PDF pour les rapports d'actions
\version $Id$ \version $Id$
*/ */
require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); 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/pdf.lib.php');
require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php");
/** /**
\class CommActionRapport \class CommActionRapport
\brief Classe permettant la generation des rapports d'actions \brief Classe permettant la generation des rapports d'actions
*/ */
class CommActionRapport class CommActionRapport
{ {
var $db; var $db;
var $description; var $description;
var $date_edition; var $date_edition;
var $year; var $year;
var $month; var $month;
var $title; var $title;
var $subject; var $subject;
function CommActionRapport($db=0, $month, $year) function CommActionRapport($db=0, $month, $year)
{ {
global $langs; global $langs;
$langs->load("commercial"); $langs->load("commercial");
$this->db = $db; $this->db = $db;
$this->description = ""; $this->description = "";
$this->date_edition = time(); $this->date_edition = time();
$this->month = $month; $this->month = $month;
$this->year = $year; $this->year = $year;
// Dimension page pour format A4 // Dimension page pour format A4
$this->type = 'pdf'; $this->type = 'pdf';
$this->page_largeur = 210; $this->page_largeur = 210;
$this->page_hauteur = 297; $this->page_hauteur = 297;
$this->format = array($this->page_largeur,$this->page_hauteur); $this->format = array($this->page_largeur,$this->page_hauteur);
$this->marge_gauche=5; $this->marge_gauche=5;
$this->marge_droite=5; $this->marge_droite=5;
$this->marge_haute=10; $this->marge_haute=10;
$this->marge_basse=10; $this->marge_basse=10;
$this->title=$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; $this->subject=$langs->trans("ActionsReport").' '.$this->year."-".$this->month;
} }
function generate($socid = 0, $catid = 0, $outputlangs='') function generate($socid = 0, $catid = 0, $outputlangs='')
{ {
global $user,$conf,$langs; global $user,$conf,$langs;
if (! is_object($outputlangs)) $outputlangs=$langs; if (! is_object($outputlangs)) $outputlangs=$langs;
// Force output charset to ISO, because, FPDF expect text encoded in ISO // Force output charset to ISO, because, FPDF expect text encoded in ISO
@ -86,20 +86,20 @@ class CommActionRapport
$outputlangs->setPhpLang(); $outputlangs->setPhpLang();
$dir = $conf->actions->dir_temp."/"; $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 (! file_exists($dir))
{ {
if (create_exdir($dir) < 0) if (create_exdir($dir) < 0)
{ {
$this->error=$langs->trans("ErrorCanNotCreateDir",$dir); $this->error=$langs->trans("ErrorCanNotCreateDir",$dir);
return 0; return 0;
} }
} }
if (file_exists($dir)) if (file_exists($dir))
{ {
// Protection et encryption du pdf // Protection et encryption du pdf
if ($conf->global->PDF_SECURITY_ENCRYPTION) if ($conf->global->PDF_SECURITY_ENCRYPTION)
{ {
$pdf=new FPDI_Protection('P','mm',$this->format); $pdf=new FPDI_Protection('P','mm',$this->format);
@ -116,29 +116,29 @@ class CommActionRapport
$pdf->Open(); $pdf->Open();
$pagenb=0; $pagenb=0;
$pdf->SetDrawColor(128,128,128); $pdf->SetDrawColor(128,128,128);
$pdf->SetFillColor(220,220,220); $pdf->SetFillColor(220,220,220);
$pdf->SetTitle($outputlangs->convToOutputCharset($this->title)); $pdf->SetTitle($outputlangs->convToOutputCharset($this->title));
$pdf->SetSubject($outputlangs->convToOutputCharset($this->subject)); $pdf->SetSubject($outputlangs->convToOutputCharset($this->subject));
$pdf->SetCreator("Dolibarr ".DOL_VERSION); $pdf->SetCreator("Dolibarr ".DOL_VERSION);
$pdf->SetAuthor($outputlangs->convToOutputCharset($user->fullname)); $pdf->SetAuthor($outputlangs->convToOutputCharset($user->fullname));
$pdf->SetKeywords($outputlangs->convToOutputCharset($this->title." ".$this->subject)); $pdf->SetKeywords($outputlangs->convToOutputCharset($this->title." ".$this->subject));
$pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right
$pdf->SetAutoPageBreak(1,0); $pdf->SetAutoPageBreak(1,0);
$nbpage = $this->_pages($pdf, $outputlangs); $nbpage = $this->_pages($pdf, $outputlangs);
$pdf->AliasNbPages(); $pdf->AliasNbPages();
$pdf->Close(); $pdf->Close();
$pdf->Output($file); $pdf->Output($file);
if (! empty($conf->global->MAIN_UMASK)) 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 * Write content of pages
@ -146,13 +146,13 @@ class CommActionRapport
* @param unknown_type $pdf * @param unknown_type $pdf
* @return int 1 * @return int 1
*/ */
function _pages(&$pdf, $outputlangs) function _pages(&$pdf, $outputlangs)
{ {
$height=3; // height for text separation $height=3; // height for text separation
$pagenb=1; $pagenb=1;
$y=$this->_pagehead($pdf, $outputlangs, $pagenb); $y=$this->_pagehead($pdf, $outputlangs, $pagenb);
$y++; $y++;
$pdf->SetFont('Arial','',8); $pdf->SetFont('Arial','',8);
$sql = "SELECT s.nom as societe, s.rowid as socid, s.client,"; $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.= " a.fk_contact, a.note, a.percent as percent,";
$sql.= " c.libelle,"; $sql.= " c.libelle,";
$sql.= " u.login"; $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.= " 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.= " 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, '%m') = ".$this->month;
$sql.= " AND date_format(a.datep, '%Y') = ".$this->year; $sql.= " AND date_format(a.datep, '%Y') = ".$this->year;
$sql.= " ORDER BY a.datep DESC"; $sql.= " ORDER BY a.datep DESC";
dol_syslog("Rapport.pdf::_page sql=".$sql); dol_syslog("Rapport.pdf::_page sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
$i = 0; $i = 0;
$y0=$y1=$y2=$y3=0; $y0=$y1=$y2=$y3=0;
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($resql); $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 // Calculate height of text
$text=dol_trunc(dol_htmlentitiesbr_decode($obj->note),150); $text=dol_trunc(dol_htmlentitiesbr_decode($obj->note),150);
//print 'd'.$text; exit; //print 'd'.$text; exit;
$nboflines=dol_nboflines($text); $nboflines=dol_nboflines($text);
$heightlinemax=max(2*$height,$nboflines*$height); $heightlinemax=max(2*$height,$nboflines*$height);
// Check if there is enough space to print record // Check if there is enough space to print record
if ((1+$y+$heightlinemax) >= ($this->page_hauteur - $this->marge_haute)) if ((1+$y+$heightlinemax) >= ($this->page_hauteur - $this->marge_haute))
{ {
// We need to break page // We need to break page
$pagenb++; $pagenb++;
$y=$this->_pagehead($pdf, $outputlangs, $pagenb); $y=$this->_pagehead($pdf, $outputlangs, $pagenb);
$y++; $y++;
$pdf->SetFont('Arial','',8); $pdf->SetFont('Arial','',8);
} }
$y++; $y++;
$pdf->SetXY($this->marge_gauche, $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); $pdf->MultiCell(22, $height, dol_print_date($obj->dp,"day")."\n".dol_print_date($obj->dp,"hour"), 0, 'L', 0);
$y0 = $pdf->GetY(); $y0 = $pdf->GetY();
$pdf->SetXY(26, $y); $pdf->SetXY(26, $y);
$pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->societe),32), 0, 'L', 0); $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->societe),32), 0, 'L', 0);
$y1 = $pdf->GetY(); $y1 = $pdf->GetY();
$pdf->SetXY(60,$y); $pdf->SetXY(60,$y);
$pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->libelle),32), 0, 'L', 0); $pdf->MultiCell(32, $height, dol_trunc($outputlangs->convToOutputCharset($obj->libelle),32), 0, 'L', 0);
$y2 = $pdf->GetY(); $y2 = $pdf->GetY();
$pdf->SetXY(106,$y); $pdf->SetXY(106,$y);
$pdf->MultiCell(94, $height, $outputlangs->convToOutputCharset($text), 0, 'L', 0); $pdf->MultiCell(94, $height, $outputlangs->convToOutputCharset($text), 0, 'L', 0);
$y3 = $pdf->GetY(); $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 * \brief Affiche en-tete facture
* \param pdf Objet PDF * \param pdf Objet PDF
* \param outputlang Objet lang cible * \param outputlang Objet lang cible
* \param pagenb Page nb * \param pagenb Page nb
*/ */
function _pagehead(&$pdf, $outputlangs, $pagenb) function _pagehead(&$pdf, $outputlangs, $pagenb)
{ {
global $conf,$langs; global $conf,$langs;
// New page // New page
$pdf->AddPage(); $pdf->AddPage();
// Show title // Show title
$pdf->SetFont('Arial','B',10); $pdf->SetFont('Arial','B',10);
$pdf->SetXY($this->marge_gauche, $this->marge_haute); $pdf->SetXY($this->marge_gauche, $this->marge_haute);
$pdf->MultiCell(80, 1, $this->title, 0, 'L', 0); $pdf->MultiCell(80, 1, $this->title, 0, 'L', 0);
$pdf->SetXY($this->page_largeur-$this->marge_droite-40, $this->marge_haute); $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, $pdf->Rect($this->marge_gauche, $y,
$this->page_largeur - $this->marge_gauche - $this->marge_droite, $this->page_largeur - $this->marge_gauche - $this->marge_droite,
$this->page_hauteur - $this->marge_haute - $this->marge_basse); $this->page_hauteur - $this->marge_haute - $this->marge_basse);
$y=$pdf->GetY()+1; $y=$pdf->GetY()+1;
return $y; return $y;
} }
} }
?> ?>

View File

@ -1,6 +1,6 @@
<?PHP <?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 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 * 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 * it under the terms of the GNU General Public License as published by
@ -19,21 +19,28 @@
* $Id$ * $Id$
* $Source$ * $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(); $sapi_type = php_sapi_name();
$script_file=__FILE__;
if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1];
if (substr($sapi_type, 0, 3) == 'cgi') { 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"; 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; 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."/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); require_once(DOL_DOCUMENT_ROOT."/societe.class.php");
@ -61,7 +68,7 @@ $factures_prev = array();
if (!$error) if (!$error)
{ {
$sql = "SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc"; $sql = "SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc";
$sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
@ -72,21 +79,21 @@ if (!$error)
$sql .= " AND pfd.traite = 0"; $sql .= " AND pfd.traite = 0";
$sql .= " AND f.total_ttc > 0"; $sql .= " AND f.total_ttc > 0";
$sql .= " AND f.fk_mode_reglement = 3"; $sql .= " AND f.fk_mode_reglement = 3";
if ( $db->query($sql) ) if ( $db->query($sql) )
{ {
$num = $db->num_rows(); $num = $db->num_rows();
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$row = $db->fetch_row(); $row = $db->fetch_row();
$factures[$i] = $row; $factures[$i] = $row;
$i++; $i++;
} }
$db->free(); $db->free();
dol_syslog("$i factures à prélever"); dol_syslog("$i factures à prélever");
} }
@ -114,17 +121,17 @@ if (!$error)
dol_syslog("Début vérification des RIB"); dol_syslog("Début vérification des RIB");
if (sizeof($factures) > 0) if (sizeof($factures) > 0)
{ {
foreach ($factures as $fac) foreach ($factures as $fac)
{ {
$fact = new Facture($db); $fact = new Facture($db);
if ($fact->fetch($fac[0]) == 1) if ($fact->fetch($fac[0]) == 1)
{ {
$soc = new Societe($db); $soc = new Societe($db);
if ($soc->fetch($fact->socid) == 1) if ($soc->fetch($fact->socid) == 1)
{ {
if ($soc->verif_rib() == 1) if ($soc->verif_rib() == 1)
{ {

View File

@ -1,6 +1,6 @@
<?PHP <?PHP
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005 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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,20 +21,27 @@
*/ */
/** /**
\file scripts/prelevement/prelevement.php * \file scripts/prelevement/prelevement.php
\ingroup prelevement * \ingroup prelevement
\brief Script de prelevement * \brief Script de prelevement
*/ */
// Test si mode batch // Test si mode CLI
$sapi_type = php_sapi_name(); $sapi_type = php_sapi_name();
$script_file=__FILE__;
if (eregi('([^\\\/]+)$',$script_file,$reg)) $script_file=$reg[1];
if (substr($sapi_type, 0, 3) == 'cgi') { 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"; 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; exit;
} }
require_once("../../htdocs/master.inc.php"); // Recupere env dolibarr
require_once(DOL_DOCUMENT_ROOT."/bon-prelevement.class.php"); $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."/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/societe.class.php"); require_once(DOL_DOCUMENT_ROOT."/societe.class.php");
require_once(DOL_DOCUMENT_ROOT."/paiement.class.php"); require_once(DOL_DOCUMENT_ROOT."/paiement.class.php");
@ -59,45 +66,45 @@ $factures_prev = array();
if (!$error) 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 = "SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc";
$sql .= " AND s.rowid = f.fk_soc"; $sql .= ", pfd.code_banque, pfd.code_guichet, pfd.number, pfd.cle_rib";
$sql .= " AND f.fk_statut = 1"; $sql .= ", pfd.amount";
$sql .= " AND f.paye = 0"; $sql .= ", s.nom";
$sql .= " AND pfd.traite = 0"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql .= " AND f.total_ttc > 0"; $sql .= " , ".MAIN_DB_PREFIX."societe as s";
$sql .= " AND f.fk_mode_reglement = 3"; $sql .= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
if ( $db->query($sql) ) $sql .= " WHERE f.rowid = pfd.fk_facture";
{ $sql .= " AND s.rowid = f.fk_soc";
$num = $db->num_rows(); $sql .= " AND f.fk_statut = 1";
$i = 0; $sql .= " AND f.paye = 0";
$sql .= " AND pfd.traite = 0";
while ($i < $num) $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(); $row = $db->fetch_row();
$factures[$i] = $row; $factures[$i] = $row;
$i++; $i++;
} }
$db->free(); $db->free();
dol_syslog("$i factures à prélever"); dol_syslog("$i factures à prélever");
} }
else else
{ {
$error = 1; $error = 1;
dol_syslog("Erreur -1"); dol_syslog("Erreur -1");
dol_syslog($db->error()); dol_syslog($db->error());
} }
} }
/* /*
@ -108,51 +115,51 @@ if (!$error)
if (!$error) if (!$error)
{ {
/* /*
* Vérification des RIB * Vérification des RIB
* *
*/ */
$i = 0; $i = 0;
dol_syslog("Début vérification des RIB"); dol_syslog("Début vérification des RIB");
if (sizeof($factures) > 0) if (sizeof($factures) > 0)
{
foreach ($factures as $fac)
{ {
foreach ($factures as $fac)
{
$fact = new Facture($db); $fact = new Facture($db);
if ($fact->fetch($fac[0]) == 1) if ($fact->fetch($fac[0]) == 1)
{ {
$soc = new Societe($db); $soc = new Societe($db);
if ($soc->fetch($fact->socid) == 1) if ($soc->fetch($fact->socid) == 1)
{ {
if ($soc->verif_rib() == 1) if ($soc->verif_rib() == 1)
{ {
$factures_prev[$i] = $fac; $factures_prev[$i] = $fac;
/* second tableau necessaire pour bon-prelevement */ /* second tableau necessaire pour bon-prelevement */
$factures_prev_id[$i] = $fac[0]; $factures_prev_id[$i] = $fac[0];
$i++; $i++;
} }
else else
{ {
dol_syslog("Erreur de RIB societe $fact->socid $soc->nom"); dol_syslog("Erreur de RIB societe $fact->socid $soc->nom");
} }
} }
else else
{ {
dol_syslog("Impossible de lire la société"); dol_syslog("Impossible de lire la société");
} }
} }
else 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"); dol_syslog(sizeof($factures_prev)." factures seront prélevées");
print 'eeee'.$factures_prev;
if (sizeof($factures_prev) > 0) if (sizeof($factures_prev) > 0)
{ {
/* /*
* Ouverture de la transaction * Ouverture de la transaction
* *
*/ */
if (!$db->query("BEGIN")) 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++;
}
/*
* 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++; $error++;
dol_syslog("Erreur recherche reference"); dol_syslog("Erreur recherche reference");
} }
$ref = $ref . substr("00".($row[0]+1), -2); $ref = $ref . substr("00".($row[0]+1), -2);
$filebonprev = $ref; $filebonprev = $ref;
/* /*
* Creation du bon de prelevement * Creation du bon de prelevement
* *
*/ */
$sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons (ref,datec)"; $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons (ref,datec)";
$sql .= " VALUES ('".$ref."',".$db->idate(mktime()).")"; $sql .= " VALUES ('".$ref."',".$db->idate(mktime()).")";
if ($db->query($sql)) if ($db->query($sql))
{ {
$prev_id = $db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons"); $prev_id = $db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons");
$bonprev = new BonPrelevement($db, DOL_DATA_ROOT."/prelevement/bon/".$filebonprev); $bonprev = new BonPrelevement($db, DOL_DATA_ROOT."/prelevement/bon/".$filebonprev);
$bonprev->id = $prev_id; $bonprev->id = $prev_id;
} }
else else
{ {
$error++; $error++;
dol_syslog("Erreur création du bon de prelevement"); 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 *
* */
* if (!$error)
*/
dol_syslog("Debut prelevement");
dol_syslog("Nombre de factures ".sizeof($factures_prev));
if (sizeof($factures_prev) > 0)
{ {
$bonprev->date_echeance = $datetimeprev; dol_syslog("Début génération des paiements");
$bonprev->reference_remise = $ref; 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; $pai = new Paiement($db);
$bonprev->raison_sociale = PRELEVEMENT_RAISON_SOCIALE;
$bonprev->emetteur_code_etablissement = PRELEVEMENT_CODE_BANQUE; $pai->amounts = array();
$bonprev->emetteur_code_guichet = PRELEVEMENT_CODE_GUICHET; $pai->amounts[$fac[0]] = $fact->total_ttc;
$bonprev->emetteur_numero_compte = PRELEVEMENT_NUMERO_COMPTE; $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
$bonprev->factures = $factures_prev_id; {
$error++;
$bonprev->generate(); 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");
}
/* if (!$error)
* Mise à jour du total {
* /*
*/ * Bon de Prelevement
*
*
*/
$sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; dol_syslog("Debut prelevement");
$sql .= " SET amount = ".price2num($bonprev->total); dol_syslog("Nombre de factures ".sizeof($factures_prev));
$sql .= " WHERE rowid = ".$prev_id;
if (!$db->query($sql)) if (sizeof($factures_prev) > 0)
{ {
$error++; $bonprev->date_echeance = $datetimeprev;
dol_syslog("Erreur mise à jour du total"); $bonprev->reference_remise = $ref;
dol_syslog($sql);
}
/*
* Rollback ou Commit $bonprev->numero_national_emetteur = PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR;
* $bonprev->raison_sociale = PRELEVEMENT_RAISON_SOCIALE;
*/
if (!$error) $bonprev->emetteur_code_etablissement = PRELEVEMENT_CODE_BANQUE;
{ $bonprev->emetteur_code_guichet = PRELEVEMENT_CODE_GUICHET;
$db->query("COMMIT"); $bonprev->emetteur_numero_compte = PRELEVEMENT_NUMERO_COMPTE;
dol_syslog("COMMIT");
}
else $bonprev->factures = $factures_prev_id;
{
$db->query("ROLLBAK"); $bonprev->generate();
dol_syslog("ROLLBACK"); }
} 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(); $db->close();