New: Widthrawal module is no more experimental

This commit is contained in:
Laurent Destailleur 2010-06-14 21:16:52 +00:00
parent 53b95f75ff
commit f1b30d3caa
10 changed files with 160 additions and 294 deletions

View File

@ -34,6 +34,7 @@ For users:
- New: Works even if Web hosting provider has disabled glob function. - New: Works even if Web hosting provider has disabled glob function.
- New: Can now send supplier order by mail. - New: Can now send supplier order by mail.
- New: task #10076 : Show content of message in notification module. - New: task #10076 : Show content of message in notification module.
- New: Widthrawal module is no more experimental.
- Fix: Format number was wrong for ar_AR language. - Fix: Format number was wrong for ar_AR language.
- Fix: Can change password if has only permission change password. - Fix: Can change password if has only permission change password.
- Fix: Project PDF document show the tasks. - Fix: Project PDF document show the tasks.

View File

@ -1,7 +1,7 @@
<?php <?php
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -29,6 +29,7 @@
require("../../main.inc.php"); require("../../main.inc.php");
require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/lib/invoice.lib.php');
require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
require_once(DOL_DOCUMENT_ROOT.'/core/class/discount.class.php');
if (!$user->rights->facture->lire) if (!$user->rights->facture->lire)
accessforbidden(); accessforbidden();
@ -86,7 +87,7 @@ if ($_GET["action"] == "delete")
* View * View
*/ */
$now=gmmktime(); $now=dol_now();
llxHeader('',$langs->trans("Bill")); llxHeader('',$langs->trans("Bill"));
@ -98,10 +99,10 @@ $html = new Form($db);
/* */ /* */
/* *************************************************************************** */ /* *************************************************************************** */
if ($_GET["facid"] > 0) if ($_REQUEST["facid"] > 0 || $_REQUEST["ref"])
{ {
$fac = New Facture($db); $fac = new Facture($db);
if ( $fac->fetch($_GET["facid"], $user->societe_id) > 0) if ($fac->fetch($_REQUEST["facid"], $_REQUEST["ref"]) > 0)
{ {
if ($mesg) print $mesg.'<br>'; if ($mesg) print $mesg.'<br>';
@ -115,22 +116,33 @@ if ($_GET["facid"] > 0)
} }
$head = facture_prepare_head($fac); $head = facture_prepare_head($fac);
dol_fiche_head($head, 'standingorders', $langs->trans('InvoiceCustomer')); dol_fiche_head($head, 'standingorders', $langs->trans('InvoiceCustomer'),0,'bill');
/* /*
* Facture * Facture
*/ */
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Reference du facture // Ref
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">'; print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="5">';
print $fac->ref; $morehtmlref='';
$discount=new DiscountAbsolute($db);
$result=$discount->fetch(0,$fac->id);
if ($result > 0)
{
$morehtmlref=' ('.$langs->trans("CreditNoteConvertedIntoDiscount",$discount->getNomUrl(1,'discount')).')';
}
if ($result < 0)
{
dol_print_error('',$discount->error);
}
print $html->showrefnav($fac,'ref','',1,'facnumber','ref',$morehtmlref);
print "</td></tr>"; print "</td></tr>";
// Societe // Societe
print '<tr><td width="20%">'.$langs->trans("Company").'</td>'; print '<tr><td width="20%">'.$langs->trans("Company").'</td>';
print '<td colspan="5">'; print '<td colspan="5">'.$soc->getNomUrl(1,'compta');
print '<a href="'.DOL_URL_ROOT.'/compta/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></td>'; print '</td>';
print '</tr>'; print '</tr>';
// Dates // Dates
@ -164,8 +176,7 @@ if ($_GET["facid"] > 0)
print '</div>'; print '</div>';
/* /*
* Demande de pr<EFBFBD>l<EFBFBD>vement * Withdrawal request
*
*/ */
$sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande"; $sql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
@ -186,21 +197,29 @@ if ($_GET["facid"] > 0)
} }
/*
* Buttons
*/
print "<div class=\"tabsAction\">\n"; print "<div class=\"tabsAction\">\n";
// Add a withdraw request // Add a withdraw request
if ($fac->statut > 0 && $fac->paye == 0 && $fac->mode_reglement_code == 'PRE' && $num == 0) if ($fac->statut > 0 && $fac->paye == 0 && $num == 0)
{ {
if ($user->rights->facture->creer) if ($user->rights->prelevement->bons->configurer)
{ {
print '<a class="butAction" href="prelevement.php?facid='.$fac->id.'&amp;action=new">'.$langs->trans("MakeWithdrawRequest").'</a>'; print '<a class="butAction" href="prelevement.php?facid='.$fac->id.'&amp;action=new">'.$langs->trans("MakeWithdrawRequest").'</a>';
} }
else
{
print '<a class="butActionRefused" href="#">'.$langs->trans("MakeWithdrawRequest").'</a>';
} }
}
print "</div><br/>"; print "</div><br/>";
/* /*
* Pr<EFBFBD>l<EFBFBD>vement * Withdrawals
*/ */
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
@ -299,7 +318,7 @@ if ($_GET["facid"] > 0)
} }
else else
{ {
/* Facture non trouv<75>e */ /* Invoice not found */
print $langs->trans("ErrorBillNotFound",$_GET["facid"]); print $langs->trans("ErrorBillNotFound",$_GET["facid"]);
} }
} }

View File

@ -1135,8 +1135,7 @@ class BonPrelevement extends CommonObject
} }
/** /**
* Generation d'un bon de prelevement * Generate a withdrawal file
*
*/ */
function Generate() function Generate()
{ {
@ -1144,8 +1143,9 @@ class BonPrelevement extends CommonObject
$result = -1; $result = -1;
$this->file = fopen ($this->filename,"w"); dol_syslog("BonPrelevement::Generate build file ".$this->filename);
$this->file = fopen ($this->filename,"w");
/* /*
* En-tete Emetteur * En-tete Emetteur
@ -1163,13 +1163,14 @@ class BonPrelevement extends CommonObject
$i = 0; $i = 0;
if ($this->db->query($sql)) $resql=$this->db->query($sql);
if ($resql)
{ {
$num = $this->db->num_rows(); $num = $this->db->num_rows($resql);
while ($i < $num) while ($i < $num)
{ {
$row = $this->db->fetch_row(); $row = $this->db->fetch_row($resql);
$this->EnregDestinataire($row[0], $this->EnregDestinataire($row[0],
$row[1], $row[1],

View File

@ -74,7 +74,7 @@ $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/create.php';
$head[$h][1] = $langs->trans("NewStandingOrder"); $head[$h][1] = $langs->trans("NewStandingOrder");
$h++; $h++;
dol_fiche_head($head, $hselected, $langs->trans("StandingOrders")); dol_fiche_head($head, $hselected, $langs->trans("StandingOrders"), 0, 'payment');
$nb=$bprev->NbFactureAPrelever(); $nb=$bprev->NbFactureAPrelever();
@ -90,10 +90,10 @@ print '<tr><td>'.$langs->trans("NbOfInvoiceToWithdraw").'</td>';
print '<td align="right">'; print '<td align="right">';
print $nb; print $nb;
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'.$langs->trans("NbOfInvoiceToWithdraw").' '.$langs->trans("ThirdPartyBankCode").'='.PRELEVEMENT_CODE_BANQUE.'</td><td align="right">'; print '<tr><td>'.$langs->trans("NbOfInvoiceToWithdraw").' '.$langs->trans("ThirdPartyBankCode").'='.$conf->global->PRELEVEMENT_CODE_BANQUE.'</td><td align="right">';
print $nb1; print $nb1;
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'.$langs->trans("NbOfInvoiceToWithdraw").' '.$langs->trans("ThirdPartyDeskCode").'='.PRELEVEMENT_CODE_GUICHET.'</td><td align="right">'; print '<tr><td>'.$langs->trans("NbOfInvoiceToWithdraw").' '.$langs->trans("ThirdPartyDeskCode").'='.$conf->global->PRELEVEMENT_CODE_GUICHET.'</td><td align="right">';
print $nb11; print $nb11;
print '</td></tr>'; print '</td></tr>';

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -65,7 +65,7 @@ print '<td align="right">';
print $bprev->NbFactureAPrelever(); print $bprev->NbFactureAPrelever();
print '</td></tr>'; print '</td></tr>';
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'><td>'.$langs->trans("AmountToWithdraw").'</td>'; print '<tr class="liste_total"><td>'.$langs->trans("AmountToWithdraw").'</td>';
print '<td align="right">'; print '<td align="right">';
print price($bprev->SommeAPrelever()); print price($bprev->SommeAPrelever());
print '</td></tr></table><br>'; print '</td></tr></table><br>';
@ -76,8 +76,8 @@ print '</td><td valign="top" width="70%">';
* Factures * Factures
*/ */
$sql = "SELECT f.facnumber, f.rowid, s.nom, s.rowid as socid"; $sql = "SELECT f.facnumber, f.rowid, s.nom, s.rowid as socid";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
$sql.= ", ".MAIN_DB_PREFIX."societe as s"; $sql.= " ".MAIN_DB_PREFIX."societe as s";
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql.= " , ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
$sql.= " WHERE s.rowid = f.fk_soc"; $sql.= " WHERE s.rowid = f.fk_soc";

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -82,28 +82,28 @@ class modPrelevement extends DolibarrModules
$this->rights_class = 'prelevement'; $this->rights_class = 'prelevement';
$this->rights[1][0] = 151; $this->rights[1][0] = 151;
$this->rights[1][1] = 'Consulter les prelevements'; $this->rights[1][1] = 'Read withdrawals';
$this->rights[1][2] = 'r'; $this->rights[1][2] = 'r';
$this->rights[1][3] = 1; $this->rights[1][3] = 1;
$this->rights[1][4] = 'bons'; $this->rights[1][4] = 'bons';
$this->rights[1][5] = 'lire'; $this->rights[1][5] = 'lire';
$this->rights[2][0] = 152; $this->rights[2][0] = 152;
$this->rights[2][1] = 'Configurer les prelevements'; $this->rights[2][1] = 'Create/modify a withdrawal request';
$this->rights[2][2] = 'w'; $this->rights[2][2] = 'w';
$this->rights[2][3] = 0; $this->rights[2][3] = 0;
$this->rights[2][4] = 'bons'; $this->rights[2][4] = 'bons';
$this->rights[2][5] = 'configurer'; $this->rights[2][5] = 'configurer';
$this->rights[3][0] = 153; $this->rights[3][0] = 153;
$this->rights[3][1] = 'Consulter les bons de prelevements'; $this->rights[3][1] = 'Read a widthrawal receipt';
$this->rights[3][2] = 'r'; $this->rights[3][2] = 'r';
$this->rights[3][3] = 0; $this->rights[3][3] = 0;
$this->rights[3][4] = 'bons'; $this->rights[3][4] = 'bons';
$this->rights[3][5] = 'lire'; $this->rights[3][5] = 'lire';
$this->rights[4][0] = 154; $this->rights[4][0] = 154;
$this->rights[4][1] = 'Creer un bon de prelevement'; $this->rights[4][1] = 'Create/modify a withdrawal receipt';
$this->rights[4][2] = 'w'; $this->rights[4][2] = 'w';
$this->rights[4][3] = 0; $this->rights[4][3] = 0;
$this->rights[4][4] = 'bons'; $this->rights[4][4] = 'bons';

View File

@ -451,7 +451,7 @@ Permission144=Delete tasks
Permission146=Read providers Permission146=Read providers
Permission147=Read stats Permission147=Read stats
Permission151=Read standing orders Permission151=Read standing orders
Permission152=Setup standing orders Permission152=Create/modify a standing orders request
Permission153=Read standing orders receipts Permission153=Read standing orders receipts
Permission161=Read contracts Permission161=Read contracts
Permission162=Create/modify contracts Permission162=Create/modify contracts

View File

@ -452,7 +452,7 @@ Permission144= Supprimer tous les projets et tâches (y compris privés dont je
Permission146= Consulter les fournisseurs Permission146= Consulter les fournisseurs
Permission147= Consulter les stats Permission147= Consulter les stats
Permission151= Consulter les prélèvements Permission151= Consulter les prélèvements
Permission152= Configurer les prélèvements Permission152= Créer/modifier une demande de prélèvements
Permission153= Consulter les bons de prélèvements Permission153= Consulter les bons de prélèvements
Permission161= Consulter les contrats de services Permission161= Consulter les contrats de services
Permission162= Créer/modifier les contrats de services Permission162= Créer/modifier les contrats de services

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-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2005-2010 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
@ -18,7 +18,7 @@
*/ */
/** /**
* \file scripts/prelevement/prelevement.php * \file scripts/withdrawals/build_withdrawal_file.php
* \ingroup prelevement * \ingroup prelevement
* \brief Script de prelevement * \brief Script de prelevement
* \version $Id$ * \version $Id$
@ -30,7 +30,7 @@ $path=dirname(__FILE__).'/';
// Test if batch mode // Test if batch mode
if (substr($sapi_type, 0, 3) == 'cgi') { if (substr($sapi_type, 0, 3) == 'cgi') {
echo "Error: You ar usingr PH for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
exit; exit;
} }
@ -51,12 +51,16 @@ $month = strftime("%m", $datetimeprev);
$year = strftime("%Y", $datetimeprev); $year = strftime("%Y", $datetimeprev);
$user = new user($db); $user = new user($db);
$user->fetch(PRELEVEMENT_USER); $user->fetch($conf->global->PRELEVEMENT_USER);
/* print "***** ".$script_file." (".$version.") *****\n";
* View if (! isset($argv[1])) { // Check parameters
*/ print "This script check invoices with a withdrawal request and\n";
print "then create payment and build a withdraw file.\n";
print "Usage: ".$script_file." simu|real\n";
exit;
}
$factures = array(); $factures = array();
$factures_prev = array(); $factures_prev = array();
@ -80,21 +84,22 @@ if (!$error)
$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) ) $resql= $db->query($sql);
if ($resql)
{ {
$num = $db->num_rows(); $num = $db->num_rows($resql);
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$row = $db->fetch_row(); $row = $db->fetch_row($resql);
$factures[$i] = $row; $factures[$i] = $row;
$i++; $i++;
} }
$db->free(); $db->free($resql);
dol_syslog("$i factures a prelever"); dol_syslog($i." invoices to withdraw.");
} }
else else
{ {
@ -117,7 +122,7 @@ if (!$error)
* *
*/ */
$i = 0; $i = 0;
dol_syslog("Debut verification des RIB"); print "Start to check bank numbers RIB/IBAN.\n";
if (sizeof($factures) > 0) if (sizeof($factures) > 0)
{ {
@ -139,67 +144,78 @@ if (!$error)
} }
else else
{ {
dol_syslog("Erreur de RIB societe $fact->socid $soc->nom"); print "Bad value for bank RIB/IBAN: Third party id=".$fact->socid.", name=".$soc->nom."\n";
dol_syslog("Bad value for bank RIB/IBAN ".$fact->socid." ".$soc->nom);
} }
} }
else else
{ {
dol_syslog("Impossible de lire la societe"); print "Failed to read third party\n";
dol_syslog("Failed to read third party");
} }
} }
else else
{ {
dol_syslog("Impossible de lire la facture");
print "Failed to read invoice\n";
dol_syslog("Failed to read invoice");
} }
} }
} }
else else
{ {
dol_syslog("Aucune factures a traiter"); print "No invoices to process\n";
dol_syslog("No invoice to process");
} }
} }
/* /*
* * Run withdrawal
*
*
*/ */
dol_syslog(sizeof($factures_prev)." factures seront prelevees"); $ok=0;
print 'eeee'.$factures_prev;
$out=sizeof($factures_prev)." invoices will be withdrawn.";
print $out."\n";
dol_syslog($out);
if (sizeof($factures_prev) > 0) if (sizeof($factures_prev) > 0)
{ {
/* if ($argv[1]==='real')
* Ouverture de la transaction
*
*/
if (!$db->query("BEGIN"))
{ {
$error++; $ok=1;
}
else
{
print "Option for real mode was not set, we stop after this simulation\n";
}
} }
if ($ok)
{
/* /*
* Traitements * We are in real mode.
* * We create withdraw receipt, payments and build withdraw into disk
*/ */
$db->begin();
if (!$error) if (!$error)
{ {
$ref = "T".substr($year,-2).$month; $ref = "T".substr($year,-2).$month;
/*
*
*
*/
$sql = "SELECT count(*)"; $sql = "SELECT count(*)";
$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons"; $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_bons";
$sql.= " WHERE ref LIKE '".$ref."%'"; $sql.= " WHERE ref LIKE '".$ref."%'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
if ($db->query($sql)) $resql=$db->query($sql);
if ($resql)
{ {
$row = $db->fetch_row(); $row = $db->fetch_row($resql);
} }
else else
{ {
@ -213,7 +229,6 @@ if (sizeof($factures_prev) > 0)
/* /*
* Creation du bon de prelevement * Creation du bon de prelevement
*
*/ */
$sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons (";
@ -223,33 +238,30 @@ if (sizeof($factures_prev) > 0)
$sql.= ") VALUES ("; $sql.= ") VALUES (";
$sql.= "'".$ref."'"; $sql.= "'".$ref."'";
$sql.= ", ".$conf->entity; $sql.= ", ".$conf->entity;
$sql.= ", ".$db->idate(mktime()); $sql.= ", '".$db->idate(mktime())."'";
$sql.= ")"; $sql.= ")";
if ($db->query($sql)) $resql=$db->query($sql);
if ($resql)
{ {
$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, $this->prelevement."/receipts/".$filebonprev); $bonprev = new BonPrelevement($db, $conf->prelevement->dir_output."/receipts/".$filebonprev);
$bonprev->id = $prev_id; $bonprev->id = $prev_id;
} }
else else
{ {
$error++; $error++;
dol_syslog("Erreur creation du bon de prelevement"); dol_syslog("Failed to create withdrawal ticket");
} }
} }
/*
*
*
*
*/
if (!$error) if (!$error)
{ {
dol_syslog("Debut generation des paiements"); dol_syslog("Start generation of payments");
dol_syslog("Nombre de factures ".sizeof($factures_prev)); dol_syslog("Number of invoices: ".sizeof($factures_prev));
if (sizeof($factures_prev) > 0) if (sizeof($factures_prev) > 0)
{ {
@ -262,14 +274,16 @@ if (sizeof($factures_prev) > 0)
$pai->amounts = array(); $pai->amounts = array();
$pai->amounts[$fac[0]] = $fact->total_ttc; $pai->amounts[$fac[0]] = $fact->total_ttc;
$pai->datepaye = $db->idate($datetimeprev); $pai->datepaye = $datetimeprev;
$pai->paiementid = 3; // prelevement $pai->paiementid = 3; // prelevement
$pai->num_paiement = $ref; $pai->num_paiement = $ref;
if ($pai->create($user, 1) == -1) // on appelle en no_commit if ($pai->create($user, 1) == -1) // on appelle en no_commit
{ {
$error++; $error++;
dol_syslog("Erreur creation paiement facture ".$fac[0]); $out="Failed to create payments for invoice ".$fac[0];
print $out."\n";
dol_syslog($out);
} }
else else
{ {
@ -304,7 +318,7 @@ if (sizeof($factures_prev) > 0)
*/ */
$sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande"; $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_facture_demande";
$sql.= " SET traite = 1"; $sql.= " SET traite = 1";
$sql.= ", date_traite = ".$db->idate(mktime()); $sql.= ", date_traite = '".$db->idate(mktime())."'";
$sql.= ", fk_prelevement_bons = ".$prev_id; $sql.= ", fk_prelevement_bons = ".$prev_id;
$sql.= " WHERE rowid = ".$fac[1]; $sql.= " WHERE rowid = ".$fac[1];
@ -315,27 +329,24 @@ if (sizeof($factures_prev) > 0)
else else
{ {
$error++; $error++;
dol_syslog("Erreur mise a jour des demandes"); dol_syslog("Erreur mise a jour des demandes ".$db->error());
dol_syslog($db->error());
} }
} }
} }
} }
dol_syslog("Fin des paiements"); dol_syslog("End payments");
} }
if (!$error) if (!$error)
{ {
/* /*
* Bon de Prelevement * Bon de Prelevement
*
*
*/ */
dol_syslog("Debut prelevement"); dol_syslog("Start generation of widthdrawal");
dol_syslog("Nombre de factures ".sizeof($factures_prev)); dol_syslog("Number of invoices ".sizeof($factures_prev));
if (sizeof($factures_prev) > 0) if (sizeof($factures_prev) > 0)
{ {
@ -353,6 +364,7 @@ if (sizeof($factures_prev) > 0)
$bonprev->factures = $factures_prev_id; $bonprev->factures = $factures_prev_id;
// Build file
$bonprev->generate(); $bonprev->generate();
} }
dol_syslog( $filebonprev ) ; dol_syslog( $filebonprev ) ;
@ -382,13 +394,12 @@ if (sizeof($factures_prev) > 0)
*/ */
if (!$error) if (!$error)
{ {
$db->query("COMMIT"); $db->commit();
dol_syslog("COMMIT");
} }
else else
{ {
$db->query("ROLLBAK"); $db->rollback();
dol_syslog("ROLLBACK"); dol_syslog("Error",LOG_ERROR);
} }
} }

View File

@ -1,166 +0,0 @@
<?PHP
/* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* \file scripts/prelevement/prelevement-verif.php
* \ingroup prelevement
* \brief Verifie que les societes qui doivent etre prelevees ont bien un RIB correct
* \version $Id$
*/
$sapi_type = php_sapi_name();
$script_file = basename(__FILE__);
$path=dirname(__FILE__).'/';
// Test if batch mode
if (substr($sapi_type, 0, 3) == 'cgi') {
echo "Error: You ar usingr PH for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n";
exit;
}
// Recupere env dolibarr
$version='$Revision$';
require_once($path."../../htdocs/master.inc.php");
require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php");
require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
$error = 0;
$puser = new user($db);
$puser->fetch(PRELEVEMENT_USER);
dol_syslog("Prelevements effectues par ".$puser->fullname." [".PRELEVEMENT_USER."]");
dol_syslog("Raison sociale : ".PRELEVEMENT_RAISON_SOCIALE);
dol_syslog("Numero Nation Emetteur : ".PRELEVEMENT_NUMERO_NATIONAL_EMETTEUR);
dol_syslog("Code etablissement : ".PRELEVEMENT_CODE_BANQUE);
dol_syslog("Code guichet : ". PRELEVEMENT_CODE_GUICHET);
dol_syslog("Numero compte : ".PRELEVEMENT_NUMERO_COMPTE);
/*
*
* Lectures des factures a prelever
*
*/
$factures = array();
$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";
$sql .= " WHERE f.fk_statut = 1";
$sql .= " AND f.rowid = pfd.fk_facture";
$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 a prelever");
}
else
{
$error = 1;
dol_syslog("Erreur -1");
dol_syslog($db->error());
}
}
/*
*
* Verification des clients
*
*/
if (!$error)
{
/*
* Verification des RIB
*
*/
$i = 0;
dol_syslog("Debut verification 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)
{
$factures_prev[$i] = $fac;
$i++;
}
else
{
dol_syslog("Erreur de RIB societe $fact->socid $soc->nom");
}
}
else
{
dol_syslog("Impossible de lire la societe");
}
}
else
{
dol_syslog("Impossible de lire la facture");
}
}
}
else
{
dol_syslog("Aucune factures a traiter");
}
}
dol_syslog(sizeof($factures_prev)." factures sur ".sizeof($factures)." seront prelevees");
$db->close();
?>