forked from Wavyzz/dolibarr
First changes to prepare cron module
This commit is contained in:
250
htdocs/cron/functions_cron.lib.php
Normal file
250
htdocs/cron/functions_cron.lib.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?PHP
|
||||
/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2007-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 cron/functions_cron.lib.php
|
||||
* \ingroup core
|
||||
* \brief Functions for miscellanous cron tasks
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \deprecated Function no more used
|
||||
*/
|
||||
function batch_fournisseur_updateturnover($year)
|
||||
{
|
||||
global $conf, $user, $db, $langs;
|
||||
|
||||
$fournisseurs = array();
|
||||
$fournisseurs_ca_achat = array();
|
||||
$products = array();
|
||||
$real_products = array();
|
||||
|
||||
|
||||
$sql = "SELECT fk_soc, date_format(datef,'%Y'),sum(total_ht) ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn";
|
||||
$sql .= " GROUP BY fk_soc, date_format(datef,'%Y') ";
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$fournisseurs_ca_achat[$row[0]][$row[1]] = $row[2];
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
$sql = "SELECT fk_product,fk_soc ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$products[$row[0]] = $row[1];
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Recuperation des id produits en lieu et place
|
||||
* des id de sous-produits
|
||||
*/
|
||||
foreach($products as $key => $value)
|
||||
{
|
||||
$sql = "SELECT fk_product ";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_subproduct";
|
||||
$sql.= " WHERE fk_product_subproduct ='".$key."';";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
if ($db->num_rows($resql) > 0)
|
||||
{
|
||||
$row = $db->fetch_row($resql);
|
||||
$real_products[$row[0]] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$real_products[$key] = $value;
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Recuperation des id produits en lieu et place
|
||||
* des id de sous-produits
|
||||
*/
|
||||
$ca_products = array();
|
||||
$ca_fourns = array();
|
||||
foreach($real_products as $key => $value)
|
||||
{
|
||||
$sql = "SELECT sum(fd.total_ht) ";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f";
|
||||
$sql.= " WHERE fk_product ='".$key."'";
|
||||
$sql.= " AND f.rowid = fd.fk_facture";
|
||||
$sql .=" AND date_format(f.datef,'%Y') = '".$year."';";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
|
||||
$row = $db->fetch_row($resql);
|
||||
$ca_products[$key] = $row[0];
|
||||
$ca_fourns[$value] += $row[0];
|
||||
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Mets a jour la table fournisseur
|
||||
*
|
||||
*/
|
||||
foreach($ca_fourns as $key => $value)
|
||||
{
|
||||
$sqld = "DELETE FROM ".MAIN_DB_PREFIX."fournisseur_ca";
|
||||
$sqld .= " WHERE year = ".$year." AND fk_societe=".$key;
|
||||
$resqld = $db->query($sqld);
|
||||
if (! $resqld)
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -1;
|
||||
}
|
||||
|
||||
$sqli = "INSERT INTO ".MAIN_DB_PREFIX."fournisseur_ca";
|
||||
$sqli .= " VALUES ($key,".$db->idate(mktime()).",$year,'".price2num($value)."'";
|
||||
$sqli.= ",'". $fournisseurs_ca_achat[$key][$year] ."');";
|
||||
$resqli = $db->query($sqli);
|
||||
if (! $resqli)
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Mets a jour la table produit
|
||||
*/
|
||||
foreach($ca_products as $key => $value)
|
||||
{
|
||||
$sqld = "DELETE FROM ".MAIN_DB_PREFIX."product_ca";
|
||||
$sqld .= " WHERE year = ".$year." AND fk_product=".$key;
|
||||
$resqld = $db->query($sqld);
|
||||
if (! $resqld)
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -1;
|
||||
}
|
||||
|
||||
$sqli = "INSERT INTO ".MAIN_DB_PREFIX."product_ca(fk_product, date_calcul, year, ca_genere)";
|
||||
$sqli .= " VALUES (".$key.",".$db->idate(mktime()).",".$year.",'".price2num($value)."')";
|
||||
$resqli = $db->query($sqli);
|
||||
if (! $resqli)
|
||||
{
|
||||
dol_print_error($db);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* \brief Update table facture_stats
|
||||
* \deprecated Function no more used
|
||||
*/
|
||||
function batch_fournisseur_statsinvoice()
|
||||
{
|
||||
global $conf, $user, $db, $langs;
|
||||
|
||||
$now=gmmktime();
|
||||
|
||||
$sql = "SELECT paye, count(*)";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture";
|
||||
$sql .= " GROUP BY paye";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$sqli = "INSERT INTO ".MAIN_DB_PREFIX."facture_stats";
|
||||
$sqli .= " VALUES (".$db->idate(mktime()).",".$db->idate($now).",'paye $row[0]',$row[1])";
|
||||
|
||||
$resqli = $db->query($sqli);
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
|
||||
$sql = "SELECT paye, sum(total)";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture";
|
||||
$sql .= " GROUP BY paye";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$sqli = "INSERT INTO ".MAIN_DB_PREFIX."facture_stats";
|
||||
$sqli .= " VALUES (".$db->idate(mktime()).",".$db->idate($now).",'total $row[0]','$row[1]')";
|
||||
|
||||
$resqli = $db->query($sqli);
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
?>
|
||||
@@ -19,10 +19,10 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
\file htdocs/fourn/fiche.php
|
||||
\ingroup fournisseur, facture
|
||||
\brief Page de fiche fournisseur
|
||||
\version $Id$
|
||||
* \file htdocs/fourn/fiche-stats.php
|
||||
* \ingroup fournisseur, facture
|
||||
* \brief Page de fiche fournisseur
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
require('./pre.inc.php');
|
||||
@@ -55,10 +55,7 @@ $societe = new Fournisseur($db);
|
||||
|
||||
if ( $societe->fetch($socid) )
|
||||
{
|
||||
$addons[0][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$socid;
|
||||
$addons[0][1] = $societe->nom;
|
||||
|
||||
llxHeader('',$langs->trans('SupplierCard').' : '.$societe->nom, $addons);
|
||||
llxHeader('',$langs->trans('SupplierCard'));
|
||||
|
||||
/*
|
||||
* Affichage onglets
|
||||
@@ -85,16 +82,28 @@ if ( $societe->fetch($socid) )
|
||||
print '<tr><td valign="top" width="50%">';
|
||||
|
||||
$file = get_exdir($societe->id, 3) . "ca_genere-".$societe->id.".png";
|
||||
|
||||
if (file_exists($file))
|
||||
{
|
||||
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_fourn&file='.$file;
|
||||
print '<img src="'.$url.'" alt="CA genere">';
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("NoneOrBatchFileNeverRan",'batch_fournisseur_updateturnover.php, batch_fournisseur_buildgraph.php');
|
||||
}
|
||||
|
||||
print '</td><td valign="top" width="50%">';
|
||||
|
||||
$file = get_exdir($societe->id, 3) . "ca_achat-".$societe->id.".png";
|
||||
|
||||
if (file_exists($file))
|
||||
{
|
||||
$url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_fourn&file='.$file;
|
||||
print '<img src="'.$url.'" alt="CA">';
|
||||
}
|
||||
else
|
||||
{
|
||||
print $langs->trans("NoneOrBatchFileNeverRan",'batch_fournisseur_updateturnover.php, batch_fournisseur_buildgraph.php');
|
||||
}
|
||||
|
||||
print '</td></tr>';
|
||||
print '</table>' . "\n";
|
||||
|
||||
@@ -54,10 +54,7 @@ $form = new Form($db);
|
||||
|
||||
if ( $societe->fetch($socid) )
|
||||
{
|
||||
$addons[0][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$socid;
|
||||
$addons[0][1] = $societe->nom;
|
||||
|
||||
llxHeader('',$langs->trans('SupplierCard').' : '.$societe->nom, $addons);
|
||||
llxHeader('',$langs->trans('SupplierCard'));
|
||||
|
||||
/*
|
||||
* Affichage onglets
|
||||
|
||||
@@ -33,3 +33,4 @@ AddCustomerInvoice=Create customer invoice
|
||||
AddSupplierOrder=Create supplier order
|
||||
AddSupplierInvoice=Create supplier invoice
|
||||
ListOfSupplierProductForSupplier=List of products and prices for supplier <b>%s</b>
|
||||
NoneOrBatchFileNeverRan=None or batch <b>%s</b> not ran recently
|
||||
@@ -33,3 +33,4 @@ AddCustomerInvoice=Créer facture/avoir client
|
||||
AddSupplierOrder=Créer commande fournisseur
|
||||
AddSupplierInvoice=Créer facture fournisseur
|
||||
ListOfSupplierProductForSupplier=Liste des produits et prix du fournisseurs <b>%s</b>
|
||||
NoneOrBatchFileNeverRan=Aucun ou batch <b>%s</b> non exécuté récemment
|
||||
168
scripts/cron/batch_fournisseur_buildgraph.php
Normal file
168
scripts/cron/batch_fournisseur_buildgraph.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?PHP
|
||||
/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2007-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/cron/fournisseur-graph.php
|
||||
\ingroup fournisseur
|
||||
\brief Script de generation graph ca fournisseur depuis tables fournisseur_ca
|
||||
\deprecated Ces graph ne sont pas utilises.
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
// 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 $script_file en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
// 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."/core/dolgraph.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/cron/functions_cron.lib.php");
|
||||
|
||||
print '***** '.$script_file.' ('.$version.') *****'."\n";
|
||||
print '--- start'."\n";
|
||||
|
||||
|
||||
$error=0;
|
||||
$verbose = 0;
|
||||
|
||||
for ($i = 1 ; $i < sizeof($argv) ; $i++)
|
||||
{
|
||||
if ($argv[$i] == "-v")
|
||||
{
|
||||
$verbose = 1;
|
||||
}
|
||||
if ($argv[$i] == "-vv")
|
||||
{
|
||||
$verbose = 2;
|
||||
}
|
||||
if ($argv[$i] == "-vvv")
|
||||
{
|
||||
$verbose = 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$dir = DOL_DATA_ROOT."/fournisseur/temp";
|
||||
$result=create_exdir($dir);
|
||||
if ($result < 0)
|
||||
{
|
||||
dol_print_error('','Failed to create dir '.$dir);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$sql = "SELECT distinct(fk_societe)";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."fournisseur_ca";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
$fournisseurs = array();
|
||||
if ($resql)
|
||||
{
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$fdir = $dir.'/'.get_exdir($row[0],3);
|
||||
|
||||
if ($verbose) print $fdir."\n";
|
||||
|
||||
//print 'Create fdir='.$fdir;
|
||||
$result=create_exdir($fdir);
|
||||
|
||||
$fournisseurs[$row[0]] = $fdir;
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $sql;
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach ($fournisseurs as $id => $fdir)
|
||||
{
|
||||
$values_gen = array();
|
||||
$values_ach = array();
|
||||
$legends = array();
|
||||
$sql = "SELECT year, ca_genere, ca_achat";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."fournisseur_ca";
|
||||
$sql .= " WHERE fk_societe = $id";
|
||||
$sql .= " ORDER BY year ASC";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$i = 0;
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$values_gen[$i] = $row[1];
|
||||
$values_ach[$i] = $row[2];
|
||||
$legends[$i] = $row[0];
|
||||
|
||||
$i++;
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $sql;
|
||||
}
|
||||
|
||||
$graph = new DolGraph();
|
||||
|
||||
$file = $fdir ."ca_genere-".$id.".png";
|
||||
$title = "CA genere par ce fournisseur (euros HT)";
|
||||
|
||||
$graph->SetTitle($title);
|
||||
$graph->BarAnnualArtichow($file, $values_ach, $legends);
|
||||
|
||||
if ($verbose)
|
||||
print "$file\n";
|
||||
|
||||
$file = $fdir ."ca_achat-".$id.".png";
|
||||
$title = "Charges pour ce fournisseur (euros HT)";
|
||||
|
||||
$graph->SetTitle($title);
|
||||
$graph->BarAnnualArtichow($file, $values_ach, $legends);
|
||||
|
||||
if ($verbose)
|
||||
print "$file\n";
|
||||
}
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
print '--- end ok'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '--- end error code='.$error."\n";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2007-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2007-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
|
||||
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
\file scripts/cron/facture-paye-stats.php
|
||||
\file scripts/cron/batch_fournisseur_statsinvoice.php
|
||||
\ingroup invoice
|
||||
\brief Script de mise a jour de la table facture_stats de statistiques
|
||||
\deprecated Ce script et ces tables ne sont pas utilisees.
|
||||
@@ -40,6 +40,10 @@ $version='$Revision$';
|
||||
$path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]);
|
||||
|
||||
require_once($path."../../htdocs/master.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/cron/functions_cron.lib.php");
|
||||
|
||||
print '***** '.$script_file.' ('.$version.') *****'."\n";
|
||||
print '--- start'."\n";
|
||||
|
||||
|
||||
$error=0;
|
||||
@@ -61,43 +65,19 @@ for ($i = 1 ; $i < sizeof($argv) ; $i++)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
$sql = "SELECT paye, count(*)";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture";
|
||||
$sql .= " GROUP BY paye";
|
||||
$db->begin();
|
||||
|
||||
$resql = $db->query($sql);
|
||||
$result=batch_fournisseur_statsinvoice();
|
||||
|
||||
if ($resql)
|
||||
if ($result > 0)
|
||||
{
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$sqli = "INSERT INTO ".MAIN_DB_PREFIX."facture_stats";
|
||||
$sqli .= " VALUES (".$db->idate(mktime()).",".$this->db->idate(mktime()).",'paye $row[0]',$row[1])";
|
||||
|
||||
$resqli = $db->query($sqli);
|
||||
$db->commit();
|
||||
print '--- end ok'."\n";
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
|
||||
$sql = "SELECT paye, sum(total)";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture";
|
||||
$sql .= " GROUP BY paye";
|
||||
|
||||
$resql = $db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
else
|
||||
{
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$sqli = "INSERT INTO ".MAIN_DB_PREFIX."facture_stats";
|
||||
$sqli .= " VALUES (".$this->db->idate(mktime()).",".$this->db->idate(mktime()).",'total $row[0]','$row[1]')";
|
||||
|
||||
$resqli = $db->query($sqli);
|
||||
}
|
||||
$db->free($resql);
|
||||
print '--- end error code='.$result."\n";
|
||||
$db->rollback();
|
||||
}
|
||||
|
||||
?>
|
||||
97
scripts/cron/batch_fournisseur_updateturnover.php
Normal file
97
scripts/cron/batch_fournisseur_updateturnover.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?PHP
|
||||
/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2007-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/cron/batch_fournisseur_updateturnover.php
|
||||
* \ingroup fournisseur
|
||||
* \brief Update table Calcul le CA genere par chaque fournisseur et met a jour les tables fournisseur_ca et produit_ca
|
||||
* \deprecated Ce script et ces tables ne sont pas utilisees.
|
||||
* \version $Id$
|
||||
*/
|
||||
|
||||
// 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 $script_file en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: $script_file now\n";
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
|
||||
// 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."/cron/functions_cron.lib.php");
|
||||
|
||||
print '***** '.$script_file.' ('.$version.') *****'."\n";
|
||||
print '--- start'."\n";
|
||||
|
||||
$error=0;
|
||||
$verbose = 0;
|
||||
|
||||
$now = gmmktime();
|
||||
$year = strftime('%Y',$now);
|
||||
|
||||
for ($i = 1 ; $i < sizeof($argv) ; $i++)
|
||||
{
|
||||
if ($argv[$i] == "-v")
|
||||
{
|
||||
$verbose = 1;
|
||||
}
|
||||
if ($argv[$i] == "-vv")
|
||||
{
|
||||
$verbose = 2;
|
||||
}
|
||||
if ($argv[$i] == "-vvv")
|
||||
{
|
||||
$verbose = 3;
|
||||
}
|
||||
if ($argv[$i] == "-y")
|
||||
{
|
||||
$year = $argv[$i+1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$db->begin();
|
||||
|
||||
$result=batch_fournisseur_updateturnover($year);
|
||||
|
||||
if ($result > 0)
|
||||
{
|
||||
$db->commit();
|
||||
print '--- end ok'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '--- end error code='.$result."\n";
|
||||
$db->rollback();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -20,7 +20,7 @@
|
||||
/**
|
||||
\file scripts/cron/product-graph.php
|
||||
\ingroup product
|
||||
\brief Crée les graphiques pour les produits
|
||||
\brief Cr<EFBFBD>e les graphiques pour les produits
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
@@ -40,6 +40,10 @@ $path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]);
|
||||
|
||||
require_once($path."../../htdocs/master.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/cron/functions_cron.lib.php");
|
||||
|
||||
print '***** '.$script_file.' ('.$version.') *****'."\n";
|
||||
print '--- start'."\n";
|
||||
|
||||
|
||||
$error=0;
|
||||
@@ -207,5 +211,13 @@ foreach ( $products as $id => $fdir)
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
print '--- end ok'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '--- end error code='.$error."\n";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -20,7 +20,7 @@
|
||||
/**
|
||||
\file scripts/cron/stock-graph.php
|
||||
\ingroup stock
|
||||
\brief Créé le graph de valorisation du stock
|
||||
\brief Cr<EFBFBD><EFBFBD> le graph de valorisation du stock
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
@@ -40,6 +40,10 @@ $path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]);
|
||||
|
||||
require_once($path."../../htdocs/master.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/core/dolgraph.class.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."//cron/functions_cron.lib.php");
|
||||
|
||||
print '***** '.$script_file.' ('.$version.') *****'."\n";
|
||||
print '--- start'."\n";
|
||||
|
||||
|
||||
/*
|
||||
@@ -157,7 +161,7 @@ for ($i = $max_day + 1 ; $i < ($day + 1) ; $i++)
|
||||
}
|
||||
|
||||
|
||||
// PMP = (quantités en stock x pmp ancien + nouvelles quantités x prix d'acquisition)/ (anciennes quantités + nouvelles quantités)
|
||||
// PMP = (quantit<EFBFBD>s en stock x pmp ancien + nouvelles quantit<EFBFBD>s x prix d'acquisition)/ (anciennes quantit<EFBFBD>s + nouvelles quantit<EFBFBD>s)
|
||||
|
||||
/*
|
||||
* For each warehouse
|
||||
@@ -165,7 +169,7 @@ for ($i = $max_day + 1 ; $i < ($day + 1) ; $i++)
|
||||
foreach ($entrepots as $key => $ent)
|
||||
{
|
||||
$file = $dir ."/entrepot-".$key."-".$year.".png";
|
||||
$title = "Valorisation PMP du stock de l'entrepôt (euros HT) sur l'année ".$year;
|
||||
$title = "Valorisation PMP du stock de l'entrep<EFBFBD>t (euros HT) sur l'ann<EFBFBD>e ".$year;
|
||||
|
||||
if ($total[$key] > 0)
|
||||
graph_datas($file, $title, $values[$key], $legends);
|
||||
@@ -178,7 +182,7 @@ foreach ($entrepots as $key => $ent)
|
||||
* For all warehouses
|
||||
*/
|
||||
$file = $dir."/entrepot-".$year.".png";
|
||||
$title = "Valorisation PMP (Prix Moyen Pondéré) du stock global (euros HT) sur l'année ".$year;
|
||||
$title = "Valorisation PMP (Prix Moyen Pond<EFBFBD>r<EFBFBD>) du stock global (euros HT) sur l'ann<EFBFBD>e ".$year;
|
||||
|
||||
if ($total[$key] > 0)
|
||||
graph_datas($file, $title, $values[0], $legends);
|
||||
@@ -222,4 +226,14 @@ function graph_datas($file, $title, $values, $legends)
|
||||
$px->SetLabelInterval(31);
|
||||
$px->draw($file);
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
print '--- end ok'."\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print '--- end error code='.$error."\n";
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,219 +0,0 @@
|
||||
<?PHP
|
||||
/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2007-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
|
||||
* 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/cron/fournisseur-calcul-ca_genere.php
|
||||
\ingroup fournisseur
|
||||
\brief Calcul le CA g<>n<EFBFBD>r<EFBFBD> par chaque fournisseur et met a jour les tables fournisseur_ca et produit_ca
|
||||
\deprecated Ce script et ces tables ne sont pas utilisees.
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
// 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 $script_file en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
/*
|
||||
if (! isset($argv[1]) || ! $argv[1]) {
|
||||
print "Usage: $script_file now\n";
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
|
||||
// Recupere env dolibarr
|
||||
$version='$Revision$';
|
||||
$path=eregi_replace($script_file,'',$_SERVER["PHP_SELF"]);
|
||||
|
||||
require_once($path."../../htdocs/master.inc.php");
|
||||
|
||||
$error=0;
|
||||
$verbose = 0;
|
||||
|
||||
$now = time();
|
||||
$year = strftime('%Y',$now);
|
||||
|
||||
for ($i = 1 ; $i < sizeof($argv) ; $i++)
|
||||
{
|
||||
if ($argv[$i] == "-v")
|
||||
{
|
||||
$verbose = 1;
|
||||
}
|
||||
if ($argv[$i] == "-vv")
|
||||
{
|
||||
$verbose = 2;
|
||||
}
|
||||
if ($argv[$i] == "-vvv")
|
||||
{
|
||||
$verbose = 3;
|
||||
}
|
||||
if ($argv[$i] == "-y")
|
||||
{
|
||||
$year = $argv[$i+1];
|
||||
}
|
||||
}
|
||||
|
||||
$fournisseurs = array();
|
||||
$fournisseurs_ca_achat = array();
|
||||
$products = array();
|
||||
$real_products = array();
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
$sql = "SELECT fk_soc, date_format(datef,'%Y'),sum(total_ht) ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn";
|
||||
$sql .= " GROUP BY fk_soc, date_format(datef,'%Y') ";
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$fournisseurs_ca_achat[$row[0]][$row[1]] = $row[2];
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $sql;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
$sql = "SELECT fk_product,fk_soc ";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$products[$row[0]] = $row[1];
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $sql;
|
||||
}
|
||||
/*
|
||||
* Recuperation des id produits en lieu et place
|
||||
* des id de sous-produits
|
||||
*/
|
||||
foreach($products as $key => $value)
|
||||
{
|
||||
$sql = "SELECT fk_product ";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_subproduct";
|
||||
$sql.= " WHERE fk_product_subproduct ='".$key."';";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
if ($db->num_rows($resql) > 0)
|
||||
{
|
||||
$row = $db->fetch_row($resql);
|
||||
$real_products[$row[0]] = $value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$real_products[$key] = $value;
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $sql;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Recuperation des id produits en lieu et place
|
||||
* des id de sous-produits
|
||||
*/
|
||||
$ca_products = array();
|
||||
$ca_fourns = array();
|
||||
foreach($real_products as $key => $value)
|
||||
{
|
||||
$sql = "SELECT sum(fd.total_ht) ";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."facturedet as fd, ".MAIN_DB_PREFIX."facture as f";
|
||||
$sql.= " WHERE fk_product ='".$key."'";
|
||||
$sql.= " AND f.rowid = fd.fk_facture";
|
||||
$sql .=" AND date_format(f.datef,'%Y') = '".$year."';";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
|
||||
$row = $db->fetch_row($resql);
|
||||
$ca_products[$key] = $row[0];
|
||||
$ca_fourns[$value] += $row[0];
|
||||
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $sql;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Mets a jour la table fournisseur
|
||||
*
|
||||
*/
|
||||
foreach($ca_fourns as $key => $value)
|
||||
{
|
||||
$sqld = "DELETE FROM ".MAIN_DB_PREFIX."fournisseur_ca";
|
||||
$sqld .= " WHERE year = $year AND fk_societe=$key;";
|
||||
|
||||
$resqld = $db->query($sqld);
|
||||
|
||||
$sqli = "INSERT INTO ".MAIN_DB_PREFIX."fournisseur_ca";
|
||||
$sqli .= " VALUES ($key,".$db->idate(mktime()).",$year,'".price2num($value)."'";
|
||||
$sqli.= ",'". $fournisseurs_ca_achat[$key][$year] ."');";
|
||||
|
||||
$resqli = $db->query($sqli);
|
||||
}
|
||||
/*
|
||||
* Mets a jour la table produit
|
||||
*
|
||||
*/
|
||||
foreach($ca_products as $key => $value)
|
||||
{
|
||||
$sqld = "DELETE FROM ".MAIN_DB_PREFIX."product_ca";
|
||||
$sqld .= " WHERE year = ".$year." AND fk_societe=".$key;
|
||||
|
||||
$resqld = $db->query($sqld);
|
||||
|
||||
$sqli = "INSERT INTO ".MAIN_DB_PREFIX."product_ca";
|
||||
$sqli .= " VALUES (".$key.",".$db->idate(mktime()).",".$year.",'".price2num($value)."')";
|
||||
|
||||
$resqli = $db->query($sqli);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,156 +0,0 @@
|
||||
<?PHP
|
||||
/* Copyright (C) 2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2007 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/cron/fournisseur-graph.php
|
||||
\ingroup fournisseur
|
||||
\brief Script de g<>n<EFBFBD>ration graph ca fournisseur depuis tables fournisseur_ca
|
||||
\deprecated Ces graph ne sont pas utilises.
|
||||
\version $Id$
|
||||
*/
|
||||
|
||||
// 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 $script_file en ligne de commande, vous devez utiliser l'interpreteur PHP pour le mode CLI.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
// 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."/core/dolgraph.class.php");
|
||||
|
||||
|
||||
$error=0;
|
||||
$verbose = 0;
|
||||
|
||||
for ($i = 1 ; $i < sizeof($argv) ; $i++)
|
||||
{
|
||||
if ($argv[$i] == "-v")
|
||||
{
|
||||
$verbose = 1;
|
||||
}
|
||||
if ($argv[$i] == "-vv")
|
||||
{
|
||||
$verbose = 2;
|
||||
}
|
||||
if ($argv[$i] == "-vvv")
|
||||
{
|
||||
$verbose = 3;
|
||||
}
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
$dir = DOL_DATA_ROOT."/fournisseur/temp";
|
||||
if (!is_dir($dir) )
|
||||
{
|
||||
if (! create_exdir($dir,0755))
|
||||
{
|
||||
die ("Can't create $dir\n");
|
||||
}
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
$sql = "SELECT distinct(fk_societe)";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."fournisseur_ca";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
$fournisseurs = array();
|
||||
if ($resql)
|
||||
{
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$fdir = $dir.'/'.get_exdir($row[0],3);
|
||||
|
||||
if ($verbose)
|
||||
print $fdir."\n";
|
||||
create_exdir($fdir);
|
||||
|
||||
$fournisseurs[$row[0]] = $fdir;
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $sql;
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
foreach ($fournisseurs as $id => $fdir)
|
||||
{
|
||||
$values_gen = array();
|
||||
$values_ach = array();
|
||||
$legends = array();
|
||||
$sql = "SELECT year, ca_genere, ca_achat";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."fournisseur_ca";
|
||||
$sql .= " WHERE fk_societe = $id";
|
||||
$sql .= " ORDER BY year ASC";
|
||||
|
||||
$resql = $db->query($sql) ;
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$i = 0;
|
||||
while ($row = $db->fetch_row($resql))
|
||||
{
|
||||
$values_gen[$i] = $row[1];
|
||||
$values_ach[$i] = $row[2];
|
||||
$legends[$i] = $row[0];
|
||||
|
||||
$i++;
|
||||
}
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
{
|
||||
print $sql;
|
||||
}
|
||||
|
||||
$graph = new DolGraph();
|
||||
|
||||
$file = $fdir ."ca_genere-".$id.".png";
|
||||
$title = "CA g<>n<EFBFBD>r<EFBFBD> par ce fournisseur (euros HT)";
|
||||
|
||||
$graph->SetTitle($title);
|
||||
$graph->BarAnnualArtichow($file, $values_ach, $legends);
|
||||
|
||||
if ($verbose)
|
||||
print "$file\n";
|
||||
|
||||
$file = $fdir ."ca_achat-".$id.".png";
|
||||
$title = "Charges pour ce fournisseur (euros HT)";
|
||||
|
||||
$graph->SetTitle($title);
|
||||
$graph->BarAnnualArtichow($file, $values_ach, $legends);
|
||||
|
||||
if ($verbose)
|
||||
print "$file\n";
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user