diff --git a/htdocs/cron/functions_cron.lib.php b/htdocs/cron/functions_cron.lib.php new file mode 100644 index 00000000000..4c9813f8c9a --- /dev/null +++ b/htdocs/cron/functions_cron.lib.php @@ -0,0 +1,250 @@ + + * Copyright (C) 2007-2009 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * 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; +} +?> diff --git a/htdocs/fourn/fiche-stats.php b/htdocs/fourn/fiche-stats.php index ed84b85a2da..4cab8d213e9 100644 --- a/htdocs/fourn/fiche-stats.php +++ b/htdocs/fourn/fiche-stats.php @@ -19,11 +19,11 @@ */ /** - \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'); require_once(DOL_DOCUMENT_ROOT."/contact.class.php"); @@ -45,64 +45,73 @@ $result = restrictedArea($user, 'societe',$socid,''); /* * Actions */ - + /* * View - */ + */ $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')); - llxHeader('',$langs->trans('SupplierCard').' : '.$societe->nom, $addons); + /* + * Affichage onglets + */ + $head = societe_prepare_head($societe); - /* - * Affichage onglets - */ - $head = societe_prepare_head($societe); + dol_fiche_head($head, 'supplierstat', $langs->trans("ThirdParty")); - dol_fiche_head($head, 'supplierstat', $langs->trans("ThirdParty")); - - print ''; - print ''; + print '
'.$langs->trans("Name").''.$societe->nom.'
'; + print ''; - print ''; + print ''; - print ''; - - print "
'.$langs->trans("Name").''.$societe->nom.'
'.$langs->trans('Prefix').''.$societe->prefix_comm.'
'.$langs->trans('Prefix').''.$societe->prefix_comm.'
'; - print $langs->trans('SupplierCode').''; - print $societe->code_fournisseur; - if ($societe->check_codefournisseur() <> 0) print ' '.$langs->trans("WrongSupplierCode"); - print '

"; + print ''; + print $langs->trans('SupplierCode').''; + print $societe->code_fournisseur; + if ($societe->check_codefournisseur() <> 0) print ' '.$langs->trans("WrongSupplierCode"); + print ''; - print ''; - print '
'; + print "

"; - $file = get_exdir($societe->id, 3) . "ca_genere-".$societe->id.".png"; + print ''; + print ''; - print '
'; - $url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_fourn&file='.$file; - print 'CA genere'; + $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 'CA genere'; + } + else + { + print $langs->trans("NoneOrBatchFileNeverRan",'batch_fournisseur_updateturnover.php, batch_fournisseur_buildgraph.php'); + } - print ''; + print ''; - $file = get_exdir($societe->id, 3) . "ca_achat-".$societe->id.".png"; - - $url=DOL_URL_ROOT.'/viewimage.php?modulepart=graph_fourn&file='.$file; - print 'CA'; - - print '
' . "\n"; - print ''; + $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 'CA'; + } + else + { + print $langs->trans("NoneOrBatchFileNeverRan",'batch_fournisseur_updateturnover.php, batch_fournisseur_buildgraph.php'); + } + + print ''; + print '' . "\n"; + print ''; } else { - dol_print_error($db); + dol_print_error($db); } $db->close(); diff --git a/htdocs/fourn/fiche.php b/htdocs/fourn/fiche.php index d5ed9a48b75..28e26979565 100644 --- a/htdocs/fourn/fiche.php +++ b/htdocs/fourn/fiche.php @@ -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 diff --git a/htdocs/langs/en_US/suppliers.lang b/htdocs/langs/en_US/suppliers.lang index 3f75c2a7c36..26f994b8e30 100644 --- a/htdocs/langs/en_US/suppliers.lang +++ b/htdocs/langs/en_US/suppliers.lang @@ -32,4 +32,5 @@ AddCustomerOrder=Create customer order AddCustomerInvoice=Create customer invoice AddSupplierOrder=Create supplier order AddSupplierInvoice=Create supplier invoice -ListOfSupplierProductForSupplier=List of products and prices for supplier %s \ No newline at end of file +ListOfSupplierProductForSupplier=List of products and prices for supplier %s +NoneOrBatchFileNeverRan=None or batch %s not ran recently \ No newline at end of file diff --git a/htdocs/langs/fr_FR/suppliers.lang b/htdocs/langs/fr_FR/suppliers.lang index c795fcac2a7..52c194b81ec 100644 --- a/htdocs/langs/fr_FR/suppliers.lang +++ b/htdocs/langs/fr_FR/suppliers.lang @@ -32,4 +32,5 @@ AddCustomerOrder=Créer commande client AddCustomerInvoice=Créer facture/avoir client AddSupplierOrder=Créer commande fournisseur AddSupplierInvoice=Créer facture fournisseur -ListOfSupplierProductForSupplier=Liste des produits et prix du fournisseurs %s \ No newline at end of file +ListOfSupplierProductForSupplier=Liste des produits et prix du fournisseurs %s +NoneOrBatchFileNeverRan=Aucun ou batch %s non exécuté récemment \ No newline at end of file diff --git a/scripts/cron/batch_fournisseur_buildgraph.php b/scripts/cron/batch_fournisseur_buildgraph.php new file mode 100644 index 00000000000..6b72019a484 --- /dev/null +++ b/scripts/cron/batch_fournisseur_buildgraph.php @@ -0,0 +1,168 @@ + + * Copyright (C) 2007-2009 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * 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"; +} + +?> diff --git a/scripts/cron/facture-paye-stats.php b/scripts/cron/batch_fournisseur_statsinvoice.php similarity index 64% rename from scripts/cron/facture-paye-stats.php rename to scripts/cron/batch_fournisseur_statsinvoice.php index c693647ee9e..76ed6cca49e 100644 --- a/scripts/cron/facture-paye-stats.php +++ b/scripts/cron/batch_fournisseur_statsinvoice.php @@ -1,6 +1,6 @@ - * Copyright (C) 2007-2008 Laurent Destailleur + * Copyright (C) 2007-2009 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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->free($resql); + $db->commit(); + print '--- end ok'."\n"; } - -$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(); } ?> diff --git a/scripts/cron/batch_fournisseur_updateturnover.php b/scripts/cron/batch_fournisseur_updateturnover.php new file mode 100644 index 00000000000..215511c9d95 --- /dev/null +++ b/scripts/cron/batch_fournisseur_updateturnover.php @@ -0,0 +1,97 @@ + + * Copyright (C) 2007-2009 Laurent Destailleur + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * 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(); +} + +?> diff --git a/scripts/cron/product-graph.php b/scripts/cron/batch_product_buildgraph.php similarity index 93% rename from scripts/cron/product-graph.php rename to scripts/cron/batch_product_buildgraph.php index d7326a2edc0..e11a7d5222f 100644 --- a/scripts/cron/product-graph.php +++ b/scripts/cron/batch_product_buildgraph.php @@ -20,7 +20,7 @@ /** \file scripts/cron/product-graph.php \ingroup product - \brief Crée les graphiques pour les produits + \brief Cr�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"; +} ?> diff --git a/scripts/cron/stock-graph.php b/scripts/cron/batch_stock_buildgraph.php similarity index 88% rename from scripts/cron/stock-graph.php rename to scripts/cron/batch_stock_buildgraph.php index 1fd2b8abd4d..403c725a816 100644 --- a/scripts/cron/stock-graph.php +++ b/scripts/cron/batch_stock_buildgraph.php @@ -20,7 +20,7 @@ /** \file scripts/cron/stock-graph.php \ingroup stock - \brief Créé le graph de valorisation du stock + \brief Cr�� 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�s en stock x pmp ancien + nouvelles quantit�s x prix d'acquisition)/ (anciennes quantit�s + nouvelles quantit�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�t (euros HT) sur l'ann�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�r�) du stock global (euros HT) sur l'ann�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"; +} + ?> diff --git a/scripts/cron/fournisseur-calcul-ca_genere.php b/scripts/cron/fournisseur-calcul-ca_genere.php deleted file mode 100644 index 3970d2a715f..00000000000 --- a/scripts/cron/fournisseur-calcul-ca_genere.php +++ /dev/null @@ -1,219 +0,0 @@ - - * Copyright (C) 2007-2008 Laurent Destailleur - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * 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éré 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); -} - -?> diff --git a/scripts/cron/fournisseur-graph.php b/scripts/cron/fournisseur-graph.php deleted file mode 100644 index 9061616bcf6..00000000000 --- a/scripts/cron/fournisseur-graph.php +++ /dev/null @@ -1,156 +0,0 @@ - - * Copyright (C) 2007 Laurent Destailleur - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * 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é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éré 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"; -} - -?>