Merge pull request #4963 from altatof/add_filter_type_on_turnover_report

NEW: add product type filter on turnover report
This commit is contained in:
Laurent Destailleur 2016-04-19 19:15:04 +02:00
commit 005751f330

View File

@ -55,6 +55,9 @@ $subcat = false;
if (GETPOST('subcat', 'alpha') === 'yes') {
$subcat = true;
}
// product/service
$selected_type = GETPOST('search_type', 'int');
if ($selected_type =='') $selected_type = -1;
// Date range
$year=GETPOST("year");
@ -124,6 +127,7 @@ $headerparams['q'] = $q;
$tableparams = array();
$tableparams['search_categ'] = $selected_cat;
$tableparams['search_type'] = $selected_type;
$tableparams['subcat'] = ($subcat === true)?'yes':'';
// Adding common parameters
@ -180,7 +184,7 @@ $catotal=0;
if ($modecompta == 'CREANCES-DETTES')
{
$sql = "SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label,";
$sql = "SELECT DISTINCT p.rowid as rowid, p.ref as ref, p.label as label, p.fk_product_type as product_type,";
$sql.= " SUM(l.total_ht) as amount, SUM(l.total_ttc) as amount_ttc,";
$sql.= " SUM(CASE WHEN f.type = 2 THEN -l.qty ELSE l.qty END) as qty";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as l, ".MAIN_DB_PREFIX."product as p";
@ -203,6 +207,10 @@ if ($modecompta == 'CREANCES-DETTES')
if ($date_start && $date_end) {
$sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
}
if ($selected_type >=0)
{
$sql.= " AND l.product_type = ".$selected_type;
}
if ($selected_cat === -2) // Without any category
{
$sql.=" AND cp.fk_product is null";
@ -214,7 +222,7 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= " AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid";
}
$sql.= " AND f.entity = ".$conf->entity;
$sql.= " GROUP BY p.rowid, p.ref, p.label";
$sql.= " GROUP BY p.rowid, p.ref, p.label, p.fk_product_type";
$sql.= $db->order($sortfield,$sortorder);
dol_syslog("cabyprodserv", LOG_DEBUG);
@ -228,6 +236,7 @@ if ($modecompta == 'CREANCES-DETTES')
$amount[$obj->rowid] = $obj->amount_ttc;
$qty[$obj->rowid] = $obj->qty;
$name[$obj->rowid] = $obj->ref . '&nbsp;-&nbsp;' . $obj->label;
$type[$obj->rowid] = $obj->product_type;
$catotal_ht+=$obj->amount;
$catotal+=$obj->amount_ttc;
$qtytotal+=$obj->qty;
@ -257,8 +266,14 @@ if ($modecompta == 'CREANCES-DETTES')
if ($subcat) {
print ' checked';
}
print '></td>';
print '<td colspan="5" align="right">';
print '>';
// type filter (produit/service)
print ' ';
print $langs->trans("Type"). ': ';
$form->select_type_of_lines(isset($selected_type)?$selected_type:-1,'search_type',1,1,1);
print '</td>';
print '<td colspan="5" align="right">';
print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
print '</td></tr>';
@ -337,7 +352,7 @@ if ($modecompta == 'CREANCES-DETTES')
// Product
$fullname=$name[$key];
if ($key >= 0) {
$linkname='<a href="'.DOL_URL_ROOT.'/product/card.php?id='.$key.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$fullname.'</a>';
$linkname='<a href="'.DOL_URL_ROOT.'/product/card.php?id='.$key.'">'.img_object($langs->trans("ShowProduct"),$type[$key]==0?'product':'service').' '.$fullname.'</a>';
} else {
$linkname=$langs->trans("PaymentsNotLinkedToProduct");
}