diff --git a/htdocs/product/stats/commande.php b/htdocs/product/stats/commande.php index 472b9ce4a45..2ae1dcd1582 100644 --- a/htdocs/product/stats/commande.php +++ b/htdocs/product/stats/commande.php @@ -2,6 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014 Florian Henry * * 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 @@ -27,6 +28,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; $langs->load("orders"); $langs->load("products"); @@ -38,7 +40,8 @@ $ref = GETPOST('ref', 'alpha'); // Security check $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); -if ($user->societe_id) $socid=$user->societe_id; +$socid=''; +if (! empty($user->societe_id)) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array @@ -55,13 +58,23 @@ $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder="DESC"; if (! $sortfield) $sortfield="c.date_commande"; +$search_month = GETPOST('search_month', 'aplha'); +$search_year = GETPOST('search_year', 'int'); +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) { + $search_month=''; + $search_year=''; +} /* * View */ +$orderstatic=new Commande($db); +$societestatic=new Societe($db); + $form = new Form($db); +$formother= new FormOther($db); if ($id > 0 || ! empty($ref)) { @@ -76,9 +89,6 @@ if ($id > 0 || ! empty($ref)) if ($result > 0) { - /* - * En mode visu - */ $head=product_prepare_head($product, $user); $titre=$langs->trans("CardProduct".$product->type); $picto=($product->type==1?'service':'product'); @@ -87,7 +97,6 @@ if ($id > 0 || ! empty($ref)) $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action); // Note that $action and $object may have been modified by hook if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - print ''; // Reference @@ -117,83 +126,138 @@ if ($id > 0 || ! empty($ref)) print ''; - - $sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client, c.rowid, c.total_ht as total_ht, c.ref,"; - $sql.= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid, d.qty"; - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user "; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= ", ".MAIN_DB_PREFIX."commande as c"; - $sql.= ", ".MAIN_DB_PREFIX."commandedet as d"; - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; - $sql.= " AND d.fk_commande = c.rowid"; - $sql.= " AND d.fk_product =".$product->id; - if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if ($socid) $sql.= " AND c.fk_soc = ".$socid; - $sql.= " ORDER BY $sortfield $sortorder "; - $sql.= $db->plimit($conf->liste_limit +1, $offset); - - $result = $db->query($sql); - if ($result) + if ($user->rights->commande->lire) { - $num = $db->num_rows($result); - - print_barre_liste($langs->trans("CustomersOrders"),$page,$_SERVER["PHP_SELF"],"&id=$product->id",$sortfield,$sortorder,'',$num,0,''); - - $i = 0; - print "
"; - - print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"c.rowid","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"c.date_commande","","&id=".$product->id,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$product->id,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.total_ht","","&id=".$product->id,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"c.fk_statut","","&id=".$product->id,'align="right"',$sortfield,$sortorder); - print "\n"; - - $commandestatic=new Commande($db); - - if ($num > 0) + $sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client, c.rowid, d.total_ht as total_ht, c.ref,"; + $sql .= " c.ref_client,"; + $sql.= " c.date_commande, c.fk_statut as statut, c.facture, c.rowid as commandeid, d.qty"; + if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user "; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql.= ", ".MAIN_DB_PREFIX."commande as c"; + $sql.= ", ".MAIN_DB_PREFIX."commandedet as d"; + if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql.= " WHERE c.fk_soc = s.rowid"; + $sql.= " AND c.entity = ".$conf->entity; + $sql.= " AND d.fk_commande = c.rowid"; + $sql.= " AND d.fk_product =".$product->id; + if (! empty($search_month)) + $sql.= ' AND MONTH(f.datef) IN (' . $search_month . ')'; + if (! empty($search_year)) + $sql.= ' AND YEAR(f.datef) IN (' . $search_year . ')'; + if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; + if ($socid) $sql.= " AND c.fk_soc = ".$socid; + $sql.= " ORDER BY $sortfield $sortorder "; + + //Calcul total qty and amount for global if full scan list + $total_ht=0; + $total_qty=0; + $totalrecords=0; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $result = $db->query($sql); + if ($result) { + $totalrecords = $db->num_rows($result); + while ($objp = $db->fetch_object($result)) { + $total_ht+=$objp->total_ht; + $total_qty+=$objp->qty; + } + } + } + + $sql.= $db->plimit($conf->liste_limit +1, $offset); + + $result = $db->query($sql); + if ($result) { - $var=True; - while ($i < $num && $i < $conf->liste_limit) + $num = $db->num_rows($result); + + if (! empty($id)) + $option .= '&id='.$product->id; + if (! empty($search_month)) + $option .= '&search_month='.$search_month; + if (! empty($search_year)) + $option .= '&search_year='.$search_year; + + print '' . "\n"; + if (! empty($sortfield)) + print ''; + if (! empty($sortorder)) + print ''; + if (! empty($page)) { + print ''; + $option .= '&page=' . $page; + } + + print_barre_liste($langs->trans("CustomersOrders"),$page,$_SERVER["PHP_SELF"],"&id=$product->id",$sortfield,$sortorder,'',$num,$totalrecords,''); + print '
'; + print $langs->trans('Period').'('.$langs->trans("DateInvoice") .') '; + print $langs->trans('Month') . ': '; + print $langs->trans('Year') . ':' . $formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + print ''; + print ''; + print '
'; + + $i = 0; + print '
'; + print ''; + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"c.rowid","",$option,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","",$option,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","",$option,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"c.date_commande","",$option,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","",$option,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.total_ht","",$option,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"c.fk_statut","",$option,'align="right"',$sortfield,$sortorder); + print "\n"; + + if ($num > 0) { - $objp = $db->fetch_object($result); - $var=!$var; - - print ""; - print '\n"; - print ''; - print "\n"; - print ""; - print "\n"; - print "\n"; - print ''; - print "\n"; - $i++; + $var=True; + while ($i < $num && $i < $conf->liste_limit) + { + $objp = $db->fetch_object($result); + $var=!$var; + + print ''; + print '\n"; + $societestatic->fetch($objp->socid); + print ''; + print "\n"; + print '"; + print '\n"; + print '\n"; + print ''; + print "\n"; + $i++; + + if (!empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $total_ht+=$objp->total_ht; + $total_qty+=$objp->qty; + } + } } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "
'.img_object($langs->trans("ShowOrder"),"order").' '; - print $objp->ref; - print "'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'".$objp->code_client.""; - print dol_print_date($db->jdate($objp->date_commande))."".$objp->qty."".price($objp->total_ht)."'.$commandestatic->LibStatut($objp->statut,$objp->facture,5).'
'; + $orderstatic->id=$objp->commandeid; + $orderstatic->ref=$objp->ref; + $orderstatic->ref_client=$objp->ref_client; + print $orderstatic->getNomUrl(1); + print "'.$societestatic->getNomUrl(1).'".$objp->code_client."'; + print dol_print_date($db->jdate($objp->date_commande))."'.$objp->qty."'.price($objp->total_ht)."'.$commandestatic->LibStatut($objp->statut,$objp->facture,5).'
' . $langs->trans('Total') . ''.$total_qty.''.price($total_ht).'
"; + print ''; + print '
'; + } else { + dol_print_error($db); } + $db->free($result); } - else - { - dol_print_error($db); - } - print ""; - print '
'; - $db->free($result); } -} -else -{ +} else { dol_print_error(); } - llxFooter(); $db->close(); diff --git a/htdocs/product/stats/commande_fournisseur.php b/htdocs/product/stats/commande_fournisseur.php index 73de0374ebe..3141b3266e9 100644 --- a/htdocs/product/stats/commande_fournisseur.php +++ b/htdocs/product/stats/commande_fournisseur.php @@ -2,6 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014 Florian Henry * * 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,15 +19,15 @@ */ /** - * \file htdocs/product/stats/commande_fournisseur.php - * \ingroup product service commande - * \brief Page des stats des commandes fournisseurs pour un produit + * \file htdocs/product/stats/commande_fournisseur.php + * \ingroup product service commande + * \brief Page des stats des commandes fournisseurs pour un produit */ - require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php'; +require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; $langs->load("orders"); $langs->load("products"); @@ -38,157 +39,233 @@ $ref = GETPOST('ref', 'alpha'); // Security check $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); -if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype); +$socid = ''; +if (! empty($user->societe_id)) + $socid = $user->societe_id; +$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -$hookmanager->initHooks(array('productstatssupplyorder')); +$hookmanager->initHooks(array ( + 'productstatssupplyorder' +)); $mesg = ''; -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOST("page", 'int'); +if ($page == - 1) { + $page = 0; +} $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (! $sortorder) $sortorder="DESC"; -if (! $sortfield) $sortfield="c.date_commande"; +if (! $sortorder) + $sortorder = "DESC"; +if (! $sortfield) + $sortfield = "c.date_commande"; +$search_month = GETPOST('search_month', 'aplha'); +$search_year = GETPOST('search_year', 'int'); +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) { + $search_month = ''; + $search_year = ''; +} /* * View */ -$form = new Form($db); +$commandefournstatic = new CommandeFournisseur($db); +$societestatic = new Societe($db); -if ($id > 0 || ! empty($ref)) -{ +$form = new Form($db); +$formother = new FormOther($db); + +if ($id > 0 || ! empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); - - $parameters=array('id'=>$id); - $reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - - llxHeader("","",$langs->trans("CardProduct".$product->type)); - - if ($result > 0) - { - $head=product_prepare_head($product, $user); - $titre=$langs->trans("CardProduct".$product->type); - $picto=($product->type==1?'service':'product'); + + $parameters = array ( + 'id' => $id + ); + $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + + llxHeader("", "", $langs->trans("CardProduct" . $product->type)); + + if ($result > 0) { + $head = product_prepare_head($product, $user); + $titre = $langs->trans("CardProduct" . $product->type); + $picto = ($product->type == 1 ? 'service' : 'product'); dol_fiche_head($head, 'referers', $titre, 0, $picto); - - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action); // Note that $action and $object may have been modified by hook - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - + + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook + if ($reshook < 0) + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + print ''; - + // Reference print ''; - print ''; - + print ''; + print ''; + // Libelle - print ''; - + print ''; + print ''; + // Status (to sell) - print ''; - + // Status (to buy) - print ''; - - show_stats_for_company($product,$socid); - + + show_stats_for_company($product, $socid); + print "
'.$langs->trans("Ref").''; - print $form->showrefnav($product,'ref','',1,'ref'); - print '
' . $langs->trans("Ref") . ''; + print $form->showrefnav($product, 'ref', '', 1, 'ref'); + print '
'.$langs->trans("Label").''.$product->libelle.'
' . $langs->trans("Label") . '' . $product->libelle . '
'.$langs->trans("Status").' ('.$langs->trans("Sell").')'; - print $product->getLibStatut(2,0); + print '
' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ')'; + print $product->getLibStatut(2, 0); print '
'.$langs->trans("Status").' ('.$langs->trans("Buy").')'; - print $product->getLibStatut(2,1); + print '
' . $langs->trans("Status") . ' (' . $langs->trans("Buy") . ')'; + print $product->getLibStatut(2, 1); print '
"; + print ''; - - $sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client,"; - $sql.= " c.rowid, c.total_ht as total_ht, c.ref,"; - $sql.= " c.date_commande, c.fk_statut as statut, c.rowid as commandeid, d.qty"; - if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user "; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; - $sql.= ", ".MAIN_DB_PREFIX."commande_fournisseurdet as d"; - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity = ".$conf->entity; - $sql.= " AND d.fk_commande = c.rowid"; - $sql.= " AND d.fk_product =".$product->id; - if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if ($socid) $sql.= " AND c.fk_soc = ".$socid; - $sql.= " ORDER BY $sortfield $sortorder "; - $sql.= $db->plimit($conf->liste_limit +1, $offset); - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - - print_barre_liste($langs->trans("SuppliersOrders"),$page,$_SERVER["PHP_SELF"],"&id=$product->id",$sortfield,$sortorder,'',$num,0,''); - - $i = 0; - print ""; - - print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"c.rowid","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("SupplierCode"),$_SERVER["PHP_SELF"],"s.code_client","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"c.date_commande","","&id=".$product->id,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$product->id,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"c.total_ht","","&id=".$product->id,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"c.fk_statut","","&id=".$product->id,'align="right"',$sortfield,$sortorder); - print "\n"; - - $commandestatic=new CommandeFournisseur($db); - - if ($num > 0) - { - $var=True; - while ($i < $num && $i < $conf->liste_limit) - { - $objp = $db->fetch_object($result); - $var=!$var; - - $commandestatic->id=$objp->commandeid; - $commandestatic->ref=$objp->ref; - $commandestatic->statut=$objp->statut; - - print ""; - print '\n"; - print "\n"; - print ''; - print "\n"; - print '"; - print "\n"; - print '\n"; - print ''; - print "\n"; - $i++; + + if ($user->rights->fournisseur->commande->lire) { + $sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client,"; + $sql .= " c.rowid, d.total_ht as total_ht, c.ref,"; + $sql .= " c.date_commande, c.fk_statut as statut, c.rowid as commandeid, d.qty"; + if (! $user->rights->societe->client->voir && ! $socid) + $sql .= ", sc.fk_soc, sc.fk_user "; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; + $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as c"; + $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseurdet as d"; + if (! $user->rights->societe->client->voir && ! $socid) + $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; + $sql .= " WHERE c.fk_soc = s.rowid"; + $sql .= " AND c.entity = " . $conf->entity; + $sql .= " AND d.fk_commande = c.rowid"; + $sql .= " AND d.fk_product =" . $product->id; + if (! empty($search_month)) + $sql .= ' AND MONTH(f.datef) IN (' . $search_month . ')'; + if (! empty($search_year)) + $sql .= ' AND YEAR(f.datef) IN (' . $search_year . ')'; + if (! $user->rights->societe->client->voir && ! $socid) + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; + if ($socid) + $sql .= " AND c.fk_soc = " . $socid; + $sql .= " ORDER BY $sortfield $sortorder "; + + // Calcul total qty and amount for global if full scan list + $total_ht = 0; + $total_qty = 0; + $totalrecords = 0; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $result = $db->query($sql); + if ($result) { + $totalrecords = $db->num_rows($result); + while ( $objp = $db->fetch_object($result) ) { + $total_ht += $objp->total_ht; + $total_qty += $objp->qty; + } } } + + $sql .= $db->plimit($conf->liste_limit + 1, $offset); + + $result = $db->query($sql); + if ($result) { + $num = $db->num_rows($result); + + if (! empty($id)) + $option .= '&id=' . $product->id; + if (! empty($search_month)) + $option .= '&search_month=' . $search_month; + if (! empty($search_year)) + $option .= '&search_year=' . $search_year; + + print '' . "\n"; + if (! empty($sortfield)) + print ''; + if (! empty($sortorder)) + print ''; + if (! empty($page)) { + print ''; + $option .= '&page=' . $page; + } + + print_barre_liste($langs->trans("SuppliersOrders"), $page, $_SERVER["PHP_SELF"], "&id=$product->id", $sortfield, $sortorder, '', $num, $totalrecords, ''); + print '
'; + print $langs->trans('Period') . '(' . $langs->trans("DateInvoice") . ') '; + print $langs->trans('Month') . ': '; + print $langs->trans('Year') . ':' . $formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + print ''; + print ''; + print '
'; + + $i = 0; + print '
'.$commandestatic->getNomUrl(1)."'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'".$objp->code_client."'.dol_print_date($db->jdate($objp->date_commande))."".$objp->qty."'.price($objp->total_ht)."'.$commandestatic->getLibStatut(4).'
'; + print ''; + print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "c.rowid", "", $option, '', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("SupplierCode"), $_SERVER["PHP_SELF"], "s.code_client", "", $option, '', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("OrderDate"), $_SERVER["PHP_SELF"], "c.date_commande", "", $option, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Qty"), $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("AmountHT"), $_SERVER["PHP_SELF"], "c.total_ht", "", $option, 'align="right"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "c.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder); + print "\n"; + + if ($num > 0) { + $var = True; + while ( $i < $num && $i < $conf->liste_limit ) { + $objp = $db->fetch_object($result); + $var = ! $var; + + print ''; + print '\n"; + $societestatic->fetch($objp->socid); + print ''; + print "\n"; + print '"; + print '\n"; + print '\n"; + print ''; + print "\n"; + $i ++; + + if (! empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $total_ht += $objp->total_ht; + $total_qty += $objp->qty; + } + } + } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "
'; + $commandestatic->id = $objp->commandeid; + $commandestatic->ref = $objp->ref; + $commandestatic->statut = $objp->statut; + print $commandestatic->getNomUrl(1); + print "' . $societestatic->getNomUrl(1) . '" . $objp->code_client . "'; + print dol_print_date($db->jdate($objp->date_commande)) . "' . $objp->qty . "' . price($objp->total_ht) . "' . $commandestatic->getLibStatut(4) . '
' . $langs->trans('Total') . '' . $total_qty . '' . price($total_ht) . '
"; + print ''; + print '
'; + } else { + dol_print_error($db); + } + $db->free($result); } - else - { - dol_print_error($db); - } - print ""; - print '
'; - $db->free($result); } -} -else -{ +} else { dol_print_error(); } - llxFooter(); $db->close(); diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php index 49e5651b065..b59bc008f17 100644 --- a/htdocs/product/stats/facture.php +++ b/htdocs/product/stats/facture.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2014 Florian Henry * * 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 @@ -28,6 +29,7 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; $langs->load("companies"); $langs->load("bills"); @@ -36,12 +38,11 @@ $langs->load("products"); $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); -$socid=''; -if (! empty($user->societe_id)) $socid=$user->societe_id; - // Security check $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); +$socid=''; +if (! empty($user->societe_id)) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array @@ -58,16 +59,23 @@ $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder="DESC"; if (! $sortfield) $sortfield="f.datef"; +$search_month = GETPOST('search_month', 'aplha'); +$search_year = GETPOST('search_year', 'int'); +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) { + $search_month=''; + $search_year=''; +} /* * View */ $invoicestatic=new Facture($db); +$societestatic=new Societe($db); $form = new Form($db); - +$formother= new FormOther($db); if ($id > 0 || ! empty($ref)) { @@ -80,9 +88,6 @@ if ($id > 0 || ! empty($ref)) llxHeader("","",$langs->trans("CardProduct".$product->type)); - /* - * En mode visu - */ if ($result > 0) { $head=product_prepare_head($product, $user); @@ -125,7 +130,7 @@ if ($id > 0 || ! empty($ref)) if ($user->rights->facture->lire) { $sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client,"; - $sql.= " f.facnumber, f.total as total_ht,"; + $sql.= " f.facnumber, d.total_ht as total_ht,"; $sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, d.qty"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user "; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; @@ -136,33 +141,79 @@ if ($id > 0 || ! empty($ref)) $sql.= " AND f.entity = ".$conf->entity; $sql.= " AND d.fk_facture = f.rowid"; $sql.= " AND d.fk_product =".$product->id; + if (! empty($search_month)) + $sql.= ' AND MONTH(f.datef) IN (' . $search_month . ')'; + if (! empty($search_year)) + $sql.= ' AND YEAR(f.datef) IN (' . $search_year . ')'; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if ($socid) $sql.= " AND f.fk_soc = $socid"; + if ($socid) $sql.= " AND f.fk_soc = ".$socid; $sql.= " ORDER BY $sortfield $sortorder "; + + //Calcul total qty and amount for global if full scan list + $total_ht=0; + $total_qty=0; + $totalrecords=0; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $result = $db->query($sql); + if ($result) { + $totalrecords = $db->num_rows($result); + while ($objp = $db->fetch_object($result)) { + $total_ht+=$objp->total_ht; + $total_qty+=$objp->qty; + } + } + } + $sql.= $db->plimit($conf->liste_limit +1, $offset); $result = $db->query($sql); - if ($result) { + if ($result) + { $num = $db->num_rows($result); - - print_barre_liste($langs->trans("CustomersInvoices"),$page,$_SERVER["PHP_SELF"],"&id=$product->id",$sortfield,$sortorder,'',$num,0,''); + + if (! empty($id)) + $option .= '&id='.$product->id; + if (! empty($search_month)) + $option .= '&search_month='.$search_month; + if (! empty($search_year)) + $option .= '&search_year='.$search_year; + + print '
' . "\n"; + if (! empty($sortfield)) + print ''; + if (! empty($sortorder)) + print ''; + if (! empty($page)) { + print ''; + $option .= '&page=' . $page; + } + + print_barre_liste($langs->trans("CustomersInvoices"),$page,$_SERVER["PHP_SELF"],"&id=".$product->id,$sortfield,$sortorder,'',$num,$totalrecords,''); + print '
'; + print $langs->trans('Period').'('.$langs->trans("DateInvoice") .') '; + print $langs->trans('Month') . ': '; + print $langs->trans('Year') . ':' . $formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + print ''; + print ''; + print '
'; $i = 0; print ''; - print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&id=".$product->id,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$product->id,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total","","&id=".$product->id,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&id=".$product->id,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","",$option,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","",$option,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","",$option,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","",$option,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","",$option,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total","",$option,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","",$option,'align="right"',$sortfield,$sortorder); print "\n"; - if ($num > 0) { + if ($num > 0) + { $var=True; - while ($i < $num && $i < $conf->liste_limit) { + while ($i < $num && $i < $conf->liste_limit) + { $objp = $db->fetch_object($result); $var=!$var; @@ -172,7 +223,8 @@ if ($id > 0 || ! empty($ref)) $invoicestatic->ref=$objp->facnumber; print $invoicestatic->getNomUrl(1); print "\n"; - print ''; + $societestatic->fetch($objp->socid); + print ''; print "\n"; print '"; @@ -181,9 +233,21 @@ if ($id > 0 || ! empty($ref)) print ''; print "\n"; $i++; + + if (!empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $total_ht+=$objp->total_ht; + $total_qty+=$objp->qty; + } } } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print "
'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).''.$societestatic->getNomUrl(1).'".$objp->code_client."'; print dol_print_date($db->jdate($objp->datef),'day')."'.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).'
' . $langs->trans('Total') . ''.$total_qty.''.price($total_ht).'
"; + print '
'; print '
'; } else { dol_print_error($db); @@ -195,6 +259,5 @@ if ($id > 0 || ! empty($ref)) dol_print_error(); } - llxFooter(); $db->close(); diff --git a/htdocs/product/stats/facture_fournisseur.php b/htdocs/product/stats/facture_fournisseur.php index d8e30bdae6a..0feb415cc43 100644 --- a/htdocs/product/stats/facture_fournisseur.php +++ b/htdocs/product/stats/facture_fournisseur.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2013 Juanjo Menent + * Copyright (C) 2014 Florian Henry * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,15 +20,16 @@ */ /** - * \file htdocs/product/stats/facture_fournisseur.php - * \ingroup product service facture - * \brief Page des stats des factures fournisseurs pour un produit + * \file htdocs/product/stats/facture_fournisseur.php + * \ingroup product service facture + * \brief Page des stats des factures fournisseurs pour un produit */ require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; +require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; $langs->load("companies"); $langs->load("bills"); @@ -40,164 +42,223 @@ $ref = GETPOST('ref', 'alpha'); // Security check $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); -if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype); +$socid = ''; +if (! empty($user->societe_id)) $socid=$user->societe_id; +$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('productstatssupplyinvoice')); $mesg = ''; -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOST("page", 'int'); if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (! $sortorder) $sortorder="DESC"; -if (! $sortfield) $sortfield="f.datef"; - +if (! $sortorder) $sortorder = "DESC"; +if (! $sortfield) $sortfield = "f.datef"; +$search_month = GETPOST('search_month', 'aplha'); +$search_year = GETPOST('search_year', 'int'); +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) { + $search_month = ''; + $search_year = ''; +} /* * View */ -$supplierinvoicestatic=new FactureFournisseur($db); +$supplierinvoicestatic = new FactureFournisseur($db); +$societestatic = new Societe($db); $form = new Form($db); +$formother = new FormOther($db); if ($id > 0 || ! empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); - - $parameters=array('id'=>$id); - $reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action); // Note that $action and $object may have been modified by some hooks + + $parameters = array('id' => $id); + $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - - llxHeader("","",$langs->trans("CardProduct".$product->type)); - - if ($result > 0) - { - /* - * En mode visu - */ - $head=product_prepare_head($product, $user); - $titre=$langs->trans("CardProduct".$product->type); - $picto=($product->type==1?'service':'product'); + + llxHeader("", "", $langs->trans("CardProduct" . $product->type)); + + if ($result > 0) + { + $head = product_prepare_head($product, $user); + $titre = $langs->trans("CardProduct" . $product->type); + $picto = ($product->type == 1 ? 'service' : 'product'); dol_fiche_head($head, 'referers', $titre, 0, $picto); - - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action); // Note that $action and $object may have been modified by hook + + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - - print ''; - - // Reference - print ''; - print ''; - print ''; - - // Libelle - print ''; - print ''; - + + print '
'.$langs->trans("Ref").''; - print $form->showrefnav($product,'ref','',1,'ref'); - print '
'.$langs->trans("Label").''.$product->libelle.'
'; + + // Reference + print ''; + print ''; + print ''; + + // Libelle + print ''; + print ''; + // Status (to sell) - print ''; - + // Status (to buy) - print ''; + + show_stats_for_company($product, $socid); + + print "
' . $langs->trans("Ref") . ''; + print $form->showrefnav($product, 'ref', '', 1, 'ref'); + print '
' . $langs->trans("Label") . '' . $product->libelle . '
'.$langs->trans("Status").' ('.$langs->trans("Sell").')'; - print $product->getLibStatut(2,0); + print '
' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ')'; + print $product->getLibStatut(2, 0); print '
'.$langs->trans("Status").' ('.$langs->trans("Buy").')'; - print $product->getLibStatut(2,1); + print '
' . $langs->trans("Status") . ' (' . $langs->trans("Buy") . ')'; + print $product->getLibStatut(2, 1); print '
"; + + print ''; + + if ($user->rights->fournisseur->facture->lire) + { + $sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client, f.ref, d.total_ht as total_ht,"; + $sql .= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, d.qty"; + if (! $user->rights->societe->client->voir && ! $socid) + $sql .= ", sc.fk_soc, sc.fk_user "; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; + $sql .= ", " . MAIN_DB_PREFIX . "facture_fourn as f"; + $sql .= ", " . MAIN_DB_PREFIX . "facture_fourn_det as d"; + if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; + $sql .= " WHERE f.fk_soc = s.rowid"; + $sql .= " AND f.entity = " . $conf->entity; + $sql .= " AND d.fk_facture_fourn = f.rowid"; + $sql .= " AND d.fk_product =" . $product->id; + if (! empty($search_month)) + $sql .= ' AND MONTH(f.datef) IN (' . $search_month . ')'; + if (! empty($search_year)) + $sql .= ' AND YEAR(f.datef) IN (' . $search_year . ')'; + if (! $user->rights->societe->client->voir && ! $socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; + if ($socid) $sql .= " AND f.fk_soc = " . $socid; + $sql .= " ORDER BY $sortfield $sortorder "; + + // Calcul total qty and amount for global if full scan list + $total_ht = 0; + $total_qty = 0; + $totalrecords = 0; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $result = $db->query($sql); + if ($result) { + $totalrecords = $db->num_rows($result); + while ( $objp = $db->fetch_object($result) ) { + $total_ht += $objp->total_ht; + $total_qty += $objp->qty; + } + } + } + + $sql .= $db->plimit($conf->liste_limit + 1, $offset); + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + + if (! empty($id)) + $option .= '&id=' . $product->id; + if (! empty($search_month)) + $option .= '&search_month=' . $search_month; + if (! empty($search_year)) + $option .= '&search_year=' . $search_year; + + print '
' . "\n"; + if (! empty($sortfield)) + print ''; + if (! empty($sortorder)) + print ''; + if (! empty($page)) { + print ''; + $option .= '&page=' . $page; + } - show_stats_for_company($product,$socid); - - print ""; - - print ''; - - - $sql = "SELECT distinct s.nom as name, s.rowid as socid, s.code_client, f.ref, f.total_ht as total_ht,"; - $sql.= " f.datef, f.paye, f.fk_statut as statut, f.rowid as facid, d.qty"; - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user "; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= ", ".MAIN_DB_PREFIX."facture_fourn as f"; - $sql.= ", ".MAIN_DB_PREFIX."facture_fourn_det as d"; - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE f.fk_soc = s.rowid"; - $sql.= " AND f.entity = ".$conf->entity; - $sql.= " AND d.fk_facture_fourn = f.rowid"; - $sql.= " AND d.fk_product =".$product->id; - if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if ($socid) $sql.= " AND f.fk_soc = ".$socid; - $sql.= " ORDER BY $sortfield $sortorder "; - $sql.= $db->plimit($conf->liste_limit +1, $offset); - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - - print_barre_liste($langs->trans("SuppliersInvoices"),$page,$_SERVER["PHP_SELF"],"&id=$product->id",$sortfield,$sortorder,'',$num,0,''); - - $i = 0; - print ""; - - print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("SupplierCode"),$_SERVER["PHP_SELF"],"s.code_client","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DateInvoice"),$_SERVER["PHP_SELF"],"f.datef","","&id=".$product->id,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$product->id,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total_ht","","&id=".$product->id,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"f.paye,f.fk_statut","","&id=".$product->id,'align="right"',$sortfield,$sortorder); - print "\n"; - - if ($num > 0) - { - $var=True; - while ($i < $num && $conf->liste_limit) - { - $objp = $db->fetch_object($result); - $var=!$var; - - print ""; - print '\n"; - print ''; - print "\n"; - print ""; - print "\n"; - print "\n"; - print ''; - print "\n"; - $i++; - } - } - } - else - { - dol_print_error($db); - } - print "
'; - $supplierinvoicestatic->id=$objp->facid; - $supplierinvoicestatic->ref=$objp->facnumber; - print $supplierinvoicestatic->getNomUrl(1); - print "'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).'".$objp->code_client.""; - print dol_print_date($db->jdate($objp->datef))."".$objp->qty."".price($objp->total_ht)."'.$supplierinvoicestatic->LibStatut($objp->paye,$objp->statut,5).'
"; - print '
'; - $db->free($result); - } + print_barre_liste($langs->trans("SuppliersInvoices"), $page, $_SERVER["PHP_SELF"], "&id=$product->id", $sortfield, $sortorder, '', $num, $totalrecords, ''); + print '
'; + print $langs->trans('Period') . '(' . $langs->trans("DateInvoice") . ') '; + print $langs->trans('Month') . ': '; + print $langs->trans('Year') . ':' . $formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + print ''; + print ''; + print '
'; + + $i = 0; + print ''; + print ''; + print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "s.rowid", "", $option, '', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("SupplierCode"), $_SERVER["PHP_SELF"], "s.code_client", "", $option, '', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("DateInvoice"), $_SERVER["PHP_SELF"], "f.datef", "", $option, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Qty"), $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("AmountHT"), $_SERVER["PHP_SELF"], "f.total_ht", "", $option, 'align="right"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "f.paye,f.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder); + print "\n"; + + if ($num > 0) + { + $var = True; + while ($i < $num && $i < $conf->liste_limit) + { + $objp = $db->fetch_object($result); + $var = ! $var; + + print ''; + print '\n"; + $societestatic->fetch($objp->socid); + print ''; + print "\n"; + print '"; + print '\n"; + print '\n"; + print ''; + print "\n"; + $i ++; + + if (! empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $total_ht += $objp->total_ht; + $total_qty += $objp->qty; + } + } + } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "
'; + $supplierinvoicestatic->id = $objp->facid; + $supplierinvoicestatic->ref = $objp->facnumber; + print $supplierinvoicestatic->getNomUrl(1); + print "' . $societestatic->getNomUrl(1) . '" . $objp->code_client . "'; + print dol_print_date($db->jdate($objp->datef)) . "' . $objp->qty . "' . price($objp->total_ht) . "' . $supplierinvoicestatic->LibStatut($objp->paye, $objp->statut, 5) . '
' . $langs->trans('Total') . '' . $total_qty . '' . price($total_ht) . '
"; + print '
'; + print '
'; + } else { + dol_print_error($db); + } + $db->free($result); + } + } +} else { + dol_print_error(); } -else -{ - dol_print_error(); -} - llxFooter(); $db->close(); diff --git a/htdocs/product/stats/propal.php b/htdocs/product/stats/propal.php index 566961d9c5f..50d7c952b6d 100644 --- a/htdocs/product/stats/propal.php +++ b/htdocs/product/stats/propal.php @@ -2,6 +2,7 @@ /* Copyright (C) 2004-2007 Rodolphe Quiedeville * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014 Florian Henry * * 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,16 +19,16 @@ */ /** - * \file htdocs/product/stats/propal.php - * \ingroup product service propal - * \brief Page des stats des propals pour un produit + * \file htdocs/product/stats/propal.php + * \ingroup product service propal + * \brief Page des stats des propals pour un produit */ - require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/comm/propal/class/propal.class.php'; +require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; $langs->load("products"); $langs->load("companies"); @@ -38,154 +39,226 @@ $ref = GETPOST('ref', 'alpha'); // Security check $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); -if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype); +$socid=''; +if (! empty($user->societe_id)) $socid=$user->societe_id; +$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array -$hookmanager->initHooks(array('productstatspropal')); +$hookmanager->initHooks(array ('productstatspropal')); $mesg = ''; -$sortfield = GETPOST("sortfield",'alpha'); -$sortorder = GETPOST("sortorder",'alpha'); -$page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOST("page", 'int'); +if ($page == - 1) { $page = 0;} $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (! $sortorder) $sortorder="DESC"; -if (! $sortfield) $sortfield="p.datep"; +if (! $sortorder) $sortorder = "DESC"; +if (! $sortfield) $sortfield = "p.datep"; +$search_month = GETPOST('search_month', 'aplha'); +$search_year = GETPOST('search_year', 'int'); + +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) { + $search_month = ''; + $search_year = ''; +} /* * View */ + +$propalstatic = new Propal($db); +$societestatic=new Societe($db); + $form = new Form($db); +$formother = new FormOther($db); if ($id > 0 || ! empty($ref)) { $product = new Product($db); $result = $product->fetch($id, $ref); - - $parameters=array('id'=>$id); - $reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action); // Note that $action and $object may have been modified by some hooks + + $parameters = array ('id' => $id); + $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - - llxHeader("","",$langs->trans("CardProduct".$product->type)); - + + llxHeader("", "", $langs->trans("CardProduct" . $product->type)); + if ($result > 0) { - $head=product_prepare_head($product, $user); - $titre=$langs->trans("CardProduct".$product->type); - $picto=($product->type==1?'service':'product'); - dol_fiche_head($head, 'referers', $titre,0,$picto); - - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action); // Note that $action and $object may have been modified by hook + $head = product_prepare_head($product, $user); + $titre = $langs->trans("CardProduct" . $product->type); + $picto = ($product->type == 1 ? 'service' : 'product'); + dol_fiche_head($head, 'referers', $titre, 0, $picto); + + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - + print ''; - + // Reference print ''; - print ''; print ''; - + // Libelle - print ''; + print ''; print ''; - + // Status (to sell) - print ''; - + // Status (to buy) - print ''; - - show_stats_for_company($product,$socid); - + + show_stats_for_company($product, $socid); + print "
'.$langs->trans("Ref").''; - print $form->showrefnav($product,'ref','',1,'ref'); + print '' . $langs->trans("Ref") . ''; + print $form->showrefnav($product, 'ref', '', 1, 'ref'); print '
'.$langs->trans("Label").''.$product->libelle.'
' . $langs->trans("Label") . '' . $product->libelle . '
'.$langs->trans("Status").' ('.$langs->trans("Sell").')'; - print $product->getLibStatut(2,0); + print '
' . $langs->trans("Status") . ' (' . $langs->trans("Sell") . ')'; + print $product->getLibStatut(2, 0); print '
'.$langs->trans("Status").' ('.$langs->trans("Buy").')'; - print $product->getLibStatut(2,1); + print '
' . $langs->trans("Status") . ' (' . $langs->trans("Buy") . ')'; + print $product->getLibStatut(2, 1); print '
"; - + print ''; - - - $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, p.rowid as propalid, p.ref, p.total_ht as amount,"; - $sql.= "p.datep, p.fk_statut as statut, d.qty"; - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user "; - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; - $sql.= ",".MAIN_DB_PREFIX."propal as p"; - $sql.= ", ".MAIN_DB_PREFIX."propaldet as d"; - if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE p.fk_soc = s.rowid"; - $sql.= " AND p.entity = ".$conf->entity; - $sql.= " AND d.fk_propal = p.rowid"; - $sql.= " AND d.fk_product =".$product->id; - if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if ($socid) $sql.= " AND p.fk_soc = ".$socid; - $sql.= " ORDER BY $sortfield $sortorder "; - $sql.= $db->plimit($conf->liste_limit +1, $offset); - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - - print_barre_liste($langs->trans("Proposals"),$page,$_SERVER["PHP_SELF"],"&id=$product->id",$sortfield,$sortorder,'',$num,0,''); - - $i = 0; - print ''; - print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"p.rowid","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","&id=".$product->id,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DatePropal"),$_SERVER["PHP_SELF"],"p.datep","","&id=".$product->id,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Qty"),$_SERVER["PHP_SELF"],"d.qty","","&id=".$product->id,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"p.total","","&id=".$product->id,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"p.fk_statut","","&id=".$product->id,'align="right"',$sortfield,$sortorder); - print "\n"; - - $propalstatic=new Propal($db); - - if ($num > 0) - { - $var=True; - while ($i < $num && $i < $conf->liste_limit) - { - $objp = $db->fetch_object($result); - $var=!$var; - - print ''; - print ''."\n"; - print ''; - print '"; - print "\n"; - print ''."\n"; - print ''; - print ''."\n"; - $i++; + + if ($user->rights->propale->lire) { + $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, p.rowid as propalid, p.ref, d.total_ht as amount,"; + $sql .= " p.ref_client,"; + $sql .= "p.datep, p.fk_statut as statut, d.qty"; + if (! $user->rights->societe->client->voir && ! $socid) + $sql .= ", sc.fk_soc, sc.fk_user "; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; + $sql .= "," . MAIN_DB_PREFIX . "propal as p"; + $sql .= ", " . MAIN_DB_PREFIX . "propaldet as d"; + if (! $user->rights->societe->client->voir && ! $socid) + $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; + $sql .= " WHERE p.fk_soc = s.rowid"; + $sql .= " AND p.entity = " . $conf->entity; + $sql .= " AND d.fk_propal = p.rowid"; + $sql .= " AND d.fk_product =" . $product->id; + if (! empty($search_month)) + $sql .= ' AND MONTH(p.datep) IN (' . $search_month . ')'; + if (! empty($search_year)) + $sql .= ' AND YEAR(p.datep) IN (' . $search_year . ')'; + if (! $user->rights->societe->client->voir && ! $socid) + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; + if ($socid) + $sql .= " AND p.fk_soc = " . $socid; + $sql .= " ORDER BY $sortfield $sortorder "; + + // Calcul total qty and amount for global if full scan list + $total_ht = 0; + $total_qty = 0; + $totalrecords = 0; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $result = $db->query($sql); + if ($result) { + $totalrecords = $db->num_rows($result); + while ( $objp = $db->fetch_object($result) ) { + $total_ht += $objp->amount; + $total_qty += $objp->qty; + } } } - } - else - { + + $sql .= $db->plimit($conf->liste_limit + 1, $offset); + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + + if (! empty($id)) + $option .= '&id=' . $product->id; + if (! empty($search_month)) + $option .= '&search_month=' . $search_month; + if (! empty($search_year)) + $option .= '&search_year=' . $search_year; + + print '' . "\n"; + if (! empty($sortfield)) + print ''; + if (! empty($sortorder)) + print ''; + if (! empty($page)) { + print ''; + $option .= '&page=' . $page; + } + + print_barre_liste($langs->trans("Proposals"), $page, $_SERVER["PHP_SELF"], "&id=$product->id", $sortfield, $sortorder, '', $num, $totalrecords, ''); + print '
'; + print $langs->trans('Period') . '(' . $langs->trans("DateInvoice") . ') '; + print $langs->trans('Month') . ': '; + print $langs->trans('Year') . ':' . $formother->selectyear($search_year ? $search_year : - 1, 'search_year', 1, 20, 5); + print ''; + print ''; + print '
'; + + $i = 0; + print '
'.img_object($langs->trans("ShowPropal"),"propal").' '; - print $objp->ref; - print ''.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($objp->name,44).''; - print dol_print_date($db->jdate($objp->datep))."".$objp->qty."'.price($objp->amount).''.$propalstatic->LibStatut($objp->statut,5).'
'; + print ''; + print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "p.rowid", "", $option, '', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom", "", $option, '', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("DatePropal"), $_SERVER["PHP_SELF"], "p.datep", "", $option, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Qty"), $_SERVER["PHP_SELF"], "d.qty", "", $option, 'align="center"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("AmountHT"), $_SERVER["PHP_SELF"], "p.total", "", $option, 'align="right"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "p.fk_statut", "", $option, 'align="right"', $sortfield, $sortorder); + print "\n"; + + if ($num > 0) + { + $var = True; + while ($i < $num && $i < $conf->liste_limit) + { + $objp = $db->fetch_object($result); + $var = ! $var; + + print ''; + print '\n"; + $societestatic->fetch($objp->socid); + print ''; + print '"; + print "\n"; + print '' . "\n"; + print ''; + print "\n"; + $i ++; + + if (! empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $total_ht += $objp->total_ht; + $total_qty += $objp->qty; + } + } + } + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "
'; + $propalstatic->id=$objp->propalid; + $propalstatic->ref=$objp->ref; + $propalstatic->ref_client=$objp->ref_client; + print $propalstatic->getNomUrl(1); + print "'.$societestatic->getNomUrl(1).''; + print dol_print_date($db->jdate($objp->datep)) . "" . $objp->qty . "' . price($objp->amount) . '' . $propalstatic->LibStatut($objp->statut, 5) . '
' . $langs->trans('Total') . '' . $total_qty . '' . price($total_ht) . '
"; + print ''; + print '
'; + } else { dol_print_error($db); } - print ""; - print '
'; $db->free($result); + } } -} -else -{ +} else { dol_print_error(); } - llxFooter(); $db->close();