diff --git a/ChangeLog b/ChangeLog index f7eedaf2369..66e4a8cfd89 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ English Dolibarr ChangeLog ***** ChangeLog for 3.4 compared to 3.3 ***** For users: +- New: Add a tab "consumption" on thirdparties to list products bought/sells. - New: Some performance enhancements. - New: Can attach files onto trip and expenses modules. - New: Add option MAIN_PDF_TITLE_BACKGROUND_COLOR. diff --git a/htdocs/compta/recap-compta.php b/htdocs/compta/recap-compta.php index 553262a3b4b..bc89cf7de7e 100644 --- a/htdocs/compta/recap-compta.php +++ b/htdocs/compta/recap-compta.php @@ -43,6 +43,8 @@ if ($user->societe_id > 0) * View */ +$userstatic=new User($db); + llxHeader(); if ($socid > 0) @@ -135,7 +137,7 @@ if ($socid > 0) $var=!$var; print ""; - print "".dol_print_date($fac->date)."\n"; + print "".dol_print_date($fac->date,'day')."\n"; print ''.img_object($langs->trans("ShowBill"),"bill")." ".$fac->ref."\n"; print ''.$fac->getLibStatut(2,$totalpaye).''; @@ -146,8 +148,12 @@ if ($socid > 0) print ' '; print ''.price($solde)."\n"; - // Auteur - print ''.img_object($langs->trans("ShowUser"),'user').' '.$objf->login.''; + // Author + $userstatic->id=$objf->userid; + $userstatic->login=$objf->login; + print ''; + print $userstatic->getLoginUrl(1); + print ''; print "\n"; @@ -172,7 +178,7 @@ if ($socid > 0) $objp = $db->fetch_object($resqlp); //$var=!$var; print ""; - print ''.dol_print_date($db->jdate($objp->dp))."\n"; + print ''.dol_print_date($db->jdate($objp->dp),'day')."\n"; print ''; print '      '; // Decalage print ''.img_object($langs->trans("ShowPayment"),"payment").' '.$langs->trans("Payment").' '.$objp->rowid.''; @@ -182,8 +188,12 @@ if ($socid > 0) $solde = $solde - $objp->amount; print ''.price($solde)."\n"; - // Auteur - print ''.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.''; + // Author + $userstatic->id=$objp->userid; + $userstatic->login=$objp->login; + print ''; + print $userstatic->getLoginUrl(1); + print ''; print ''; @@ -214,5 +224,4 @@ else llxFooter(); $db->close(); - ?> diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 8ba3a161712..f06e8027e5f 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -90,6 +90,11 @@ function societe_prepare_head($object) $head[$h][2] = 'note'; $h++; + $head[$h][0] = DOL_URL_ROOT.'/societe/consumption.php?socid='.$object->id; + $head[$h][1] = $langs->trans("Referers"); + $head[$h][2] = 'consumption'; + $h++; + // Attached files $head[$h][0] = DOL_URL_ROOT.'/societe/document.php?socid='.$object->id; $head[$h][1] = $langs->trans("Documents"); diff --git a/htdocs/langs/ar_SA/main.lang b/htdocs/langs/ar_SA/main.lang index 5befea18b77..f273f913d04 100644 --- a/htdocs/langs/ar_SA/main.lang +++ b/htdocs/langs/ar_SA/main.lang @@ -428,8 +428,6 @@ NbOfThirdParties=عدد من الأطراف الثالثة NbOfCustomers=عدد من العملاء NbOfLines=عدد الخطوط NbOfObjects=عدد الأجسام -NbOfReferers=عدد referers -Referers=Referers TotalQuantity=الكمية الإجمالية DateFromTo=ل٪ من ق ق ٪ DateFrom=من ق ٪ diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 1ce5db6ccd4..0ae15edba41 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -392,6 +392,7 @@ UniqueThirdParties=Total of unique third parties InActivity=Open ActivityCeased=Closed ActivityStateFilter=Activity status +ProductsIntoElements=List of products into # Monkey MonkeyNumRefModelDesc=Return numero with format %syymm-nnnn for customer code and %syymm-nnnn for supplier code where yy is year, mm is month and nnnn is a sequence with no break and no return to 0. diff --git a/htdocs/langs/en_US/main.lang b/htdocs/langs/en_US/main.lang index 0b82960dab2..99a60857e3d 100644 --- a/htdocs/langs/en_US/main.lang +++ b/htdocs/langs/en_US/main.lang @@ -487,7 +487,7 @@ NbOfCustomers=Number of customers NbOfLines=Number of lines NbOfObjects=Number of objects NbOfReferers=Number of referrers -Referers=Referrers +Referers=Consumption TotalQuantity=Total quantity DateFromTo=From %s to %s DateFrom=From %s diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang index 254d1e8af16..99612d8ec2d 100644 --- a/htdocs/langs/fr_FR/companies.lang +++ b/htdocs/langs/fr_FR/companies.lang @@ -394,6 +394,7 @@ UniqueThirdParties=Total de tiers uniques InActivity=En activité ActivityCeased=Clos ActivityStateFilter=Statut d'activité +ProductsIntoElements=Liste des produits dans les %s # Monkey MonkeyNumRefModelDesc=Renvoie le numéro sous la forme %syymm-nnnn pour les codes clients et %syymm-nnnn pour les codes fournisseurs où yy est l'année, mm le mois et nnnn un compteur séquentiel sans rupture et sans remise à 0. diff --git a/htdocs/langs/fr_FR/main.lang b/htdocs/langs/fr_FR/main.lang index a7093fd8b75..b31b711f3a3 100644 --- a/htdocs/langs/fr_FR/main.lang +++ b/htdocs/langs/fr_FR/main.lang @@ -490,7 +490,7 @@ NbOfCustomers=Nombre de clients NbOfLines=Nombre de lignes NbOfObjects=Nombre d'objets NbOfReferers=Nombre de références -Referers=Référents +Referers=Consommation TotalQuantity=Quantité totale DateFromTo=Du %s au %s DateFrom=A partir du %s diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php new file mode 100644 index 00000000000..733b8ee84ce --- /dev/null +++ b/htdocs/societe/consumption.php @@ -0,0 +1,318 @@ + + * Copyright (C) 2004-2012 Laurent Destailleur + * + * Version V1.1 Initial version of Philippe Berthet + * Version V2 Change to be compatible with 3.4 and enhanced to be more generic + * + * 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 3 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, see . + */ + +/** + * \file htdocs/societe/consumption.php + * \ingroup societe + * \brief Add a tab on thirpdarty view to list all products/services bought or sells by thirdparty + */ + +require("../main.inc.php"); +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; +require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; + +// Security check +$socid = GETPOST('socid','int'); +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'societe', $socid, '&societe'); +$object = new Societe($db); +if ($socid > 0) $object->fetch($socid); + +// Sort & Order fields +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if ($page == -1) { + $page = 0; +} +$offset = $conf->liste_limit * $page; +if (! $sortorder) $sortorder='DESC'; +if (! $sortfield) $sortfield='datePrint'; +$limit = $conf->liste_limit; + +// Search fields +$sref=GETPOST("sref"); +$sprod_fulldescr=GETPOST("sprod_fulldescr"); +$month = GETPOST('month','int'); +$year = GETPOST('year','int'); + +// Clean up on purge search criteria ? +if (GETPOST("button_removefilter")) +{ + $sref=''; + $sprod_fulldescr=''; + $year=''; + $month=''; +} +// Customer or supplier selected in drop box +$thirdTypeSelect = GETPOST("third_select_id"); +$type_element = GETPOST('type_element')?GETPOST('type_element'):'invoice'; + +$langs->load("bills"); +$langs->load("orders"); +$langs->load("suppliers"); + + +/* + * Actions + */ + + + +/* + * View + */ + +$form = new Form($db); +$formother = new FormOther($db); +$productstatic=new Product($db); + +$titre = $langs->trans("Referer",$object->name); +llxHeader('',$titre,''); + +if (empty($socid)) +{ + dol_print_error($db); + exit; +} + +$head = societe_prepare_head($object); +dol_fiche_head($head, 'consumption', $langs->trans("ThirdParty"),0,'company'); + +print '
'; +print ''; +print ''; + +print ''; +print ''; +print ''; + +if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field +{ + print ''; +} + +if ($object->client) +{ + print ''; + $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid; + $resql=$db->query($sql); + if (!$resql) dol_print_error($db); + + $obj = $db->fetch_object($resql); + $nbFactsClient = $obj->nb; + $thirdTypeArray['customer']=$langs->trans("customer"); + if ($conf->facture->enabled) $elementTypeArray['invoice']=$langs->trans('Invoices'); + if ($conf->commande->enabled) $elementTypeArray['order']=$langs->trans('Orders'); +} + +if ($object->fournisseur) +{ + print ''; + $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".$socid; + $resql=$db->query($sql); + if (!$resql) dol_print_error($db); + + $obj = $db->fetch_object($resql); + $nbCmdsFourn = $obj->nb; + $thirdTypeArray['supplier']=$langs->trans("supplier"); + if ($conf->fournisseur->enabled) $elementTypeArray['supplier_invoice']=$langs->trans('SuppliersInvoices'); + if ($conf->fournisseur->enabled) $elementTypeArray['supplier_order']=$langs->trans('SuppliersOrders'); +} +print '
'.$langs->trans('ThirdPartyName').''; +print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom'); +print '
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'; + print $langs->trans('CustomerCode').''; + print $object->code_client; + if ($object->check_codeclient() <> 0) print ' ('.$langs->trans("WrongCustomerCode").')'; + print '
'; + print $langs->trans('SupplierCode').''; + print $object->code_fournisseur; + if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; + print '
'; + +dol_fiche_end(); +print '
'; + + +$sql_select=''; +if ($type_element == 'invoice') +{ // Customer : show products from invoices +$documentstatic=new Facture($db); +$sql_select = 'SELECT f.rowid as doc_id, f.facnumber as doc_number, f.type as doc_type, f.datef as datePrint, '; +$tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d"; +$where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; +$where.= " AND d.fk_facture = f.rowid"; +$where.= " AND f.entity = ".$conf->entity; +$datePrint = 'f.datef'; +$doc_number='f.facnumber'; +$thirdTypeSelect='customer'; +} +if ($type_element == 'order') +{ + // TODO + +} +if ($type_element == 'supplier_order') +{ // Supplier : Show products from orders. +$documentstatic=new CommandeFournisseur($db); +$sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, "1" as doc_type, c.date_valid as datePrint, '; +$tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d"; +$where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; +$where.= " AND d.fk_commande = c.rowid"; +$datePrint = 'c.date_creation'; +$doc_number='c.ref'; +$thirdTypeSelect='supplier'; +} +if ($type_element == 'supplier_invoice') +{ + // TODO + +} + +$sql = $sql_select; +$sql.= ' d.fk_product as product_id, d.description as prod_descr, '; +$sql.= ' d.qty as prod_qty, p.rowid as prod_id, p.fk_product_type as prod_type,'; +$sql.= " s.rowid as socid, p.ref as prod_ref, p.label as prod_label"; +$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from; +$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid '; +$sql.= $where; +if ($month > 0) { + if ($year > 0) { + $start = dol_mktime(0, 0, 0, $month, 1, $year); + $end = dol_time_plus_duree($start, 1 , 'm') - 1; + $sql.= " AND ".$datePrint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; + } else { + $sql.= " AND date_format(".$datePrint.", '%m') = '".sprintf('%02d',$month)."'"; + } +} else if ($year > 0) { + $start = dol_mktime(0, 0, 0, 1, 1, $year); + $end = dol_time_plus_duree($start, 1 , 'y') - 1; + $sql.= " AND ".$datePrint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; +} +if ($sref) $sql.= " AND ".$doc_number." LIKE '%".$sref."%'"; +$sql.= $db->order($sortfield,$sortorder); +$sql.= $db->plimit($limit + 1, $offset); + + +// Define type of elements +$typeElementString = $form->selectarray("type_element",$elementTypeArray,GETPOST('type_element')); +$button = ''; +$param="&sref=".$sref."&month=".$month."&year=".$year."&sprod_fulldescr=".$sprod_fulldescr."&socid=".$socid; + +print_barre_liste($langs->trans('ProductsIntoElements', $typeElementString.' '.$button), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, '', ''); + +if ($sql_select) +{ + dol_syslog("sql=".$sql); + $resql=$db->query($sql); + if (!$resql) dol_print_error($db); +} + +print ''."\n"; +// Titles with sort buttons +print ''; +print_liste_field_titre($langs->trans('Ref'),$_SERVER['PHP_SELF'],'doc_number','',$param,'align="left"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans('Date'),$_SERVER['PHP_SELF'],'datePrint','',$param,'align="center" width="150"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans('Product'),$_SERVER['PHP_SELF'],'','',$param,'align="left"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans('Quantity'),$_SERVER['PHP_SELF'],'prod_qty','',$param,'align="right"',$sortfield,$sortorder); +// Filters +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +if ($sql_select) +{ + $var=true; + $num = $db->num_rows($resql); + $i = 0; + while (($objp = $db->fetch_object($resql)) && $i < $conf->liste_limit ) + { + $var=!$var; + print ""; + print ''; + print ''; + $prodreftxt=''; + if(!empty($objp->prod_id)) { + $productstatic->id = $objp->prod_id; + $productstatic->ref = $objp->prod_ref; + $productstatic->status = $objp->prod_type; + $prodreftxt = $productstatic->getNomUrl(0); + if(!empty($objp->prod_label)) $prodreftxt .= ' - '.$objp->prod_label; + } + if(!empty($objp->prod_descr)) { + if(!empty($prodreftxt)) { + $prodreftxt .= '
'.$objp->prod_descr; + } else { + $prodreftxt .= $objp->prod_descr; + } + } + print ''; + print ''; + print "\n"; + $i++; + } + if ($num > $conf->liste_limit) { + print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num); + } + $db->free($resql); +} +else { + print ''; +} + +print "
'; +print ''; +print ''; // date +print $formother->select_month($month?$month:-1,'month',1); +$formother->select_year($year?$year:-1,'year',1, 20, 1); +print ''; +print ''; +print ''; +print ''; +print ''; +print '
'; + $documentstatic->id=$objp->doc_id; + $documentstatic->ref=$objp->doc_number; + $documentstatic->type=$objp->type; + print $documentstatic->getNomUrl(1); + print ''.dol_print_date($db->jdate($objp->datePrint),'day').''.$prodreftxt.''.$objp->prod_qty.'
'.$langs->trans("FeatureNotYetAvailable").'
"; +print "
"; + + +/* + * Errors + */ + +dol_htmloutput_errors($warning); +dol_htmloutput_errors($error,$errors); + +llxFooter(); + +$db->close(); +?>