Skip to content
Snippets Groups Projects
Commit 005751f3 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Merge pull request #4963 from altatof/add_filter_type_on_turnover_report

NEW: add product type filter on turnover report
parents da329131 0dd25a7e
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,9 @@ $subcat = false; ...@@ -55,6 +55,9 @@ $subcat = false;
if (GETPOST('subcat', 'alpha') === 'yes') { if (GETPOST('subcat', 'alpha') === 'yes') {
$subcat = true; $subcat = true;
} }
// product/service
$selected_type = GETPOST('search_type', 'int');
if ($selected_type =='') $selected_type = -1;
// Date range // Date range
$year=GETPOST("year"); $year=GETPOST("year");
...@@ -124,6 +127,7 @@ $headerparams['q'] = $q; ...@@ -124,6 +127,7 @@ $headerparams['q'] = $q;
$tableparams = array(); $tableparams = array();
$tableparams['search_categ'] = $selected_cat; $tableparams['search_categ'] = $selected_cat;
$tableparams['search_type'] = $selected_type;
$tableparams['subcat'] = ($subcat === true)?'yes':''; $tableparams['subcat'] = ($subcat === true)?'yes':'';
// Adding common parameters // Adding common parameters
...@@ -180,7 +184,7 @@ $catotal=0; ...@@ -180,7 +184,7 @@ $catotal=0;
if ($modecompta == 'CREANCES-DETTES') 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(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.= " 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"; $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') ...@@ -203,6 +207,10 @@ if ($modecompta == 'CREANCES-DETTES')
if ($date_start && $date_end) { if ($date_start && $date_end) {
$sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($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 if ($selected_cat === -2) // Without any category
{ {
$sql.=" AND cp.fk_product is null"; $sql.=" AND cp.fk_product is null";
...@@ -214,7 +222,7 @@ if ($modecompta == 'CREANCES-DETTES') ...@@ -214,7 +222,7 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= " AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid"; $sql.= " AND cp.fk_categorie = c.rowid AND cp.fk_product = p.rowid";
} }
$sql.= " AND f.entity = ".$conf->entity; $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); $sql.= $db->order($sortfield,$sortorder);
dol_syslog("cabyprodserv", LOG_DEBUG); dol_syslog("cabyprodserv", LOG_DEBUG);
...@@ -228,6 +236,7 @@ if ($modecompta == 'CREANCES-DETTES') ...@@ -228,6 +236,7 @@ if ($modecompta == 'CREANCES-DETTES')
$amount[$obj->rowid] = $obj->amount_ttc; $amount[$obj->rowid] = $obj->amount_ttc;
$qty[$obj->rowid] = $obj->qty; $qty[$obj->rowid] = $obj->qty;
$name[$obj->rowid] = $obj->ref . '&nbsp;-&nbsp;' . $obj->label; $name[$obj->rowid] = $obj->ref . '&nbsp;-&nbsp;' . $obj->label;
$type[$obj->rowid] = $obj->product_type;
$catotal_ht+=$obj->amount; $catotal_ht+=$obj->amount;
$catotal+=$obj->amount_ttc; $catotal+=$obj->amount_ttc;
$qtytotal+=$obj->qty; $qtytotal+=$obj->qty;
...@@ -257,7 +266,13 @@ if ($modecompta == 'CREANCES-DETTES') ...@@ -257,7 +266,13 @@ if ($modecompta == 'CREANCES-DETTES')
if ($subcat) { if ($subcat) {
print ' checked'; print ' checked';
} }
print '></td>'; 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 '<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 '<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>'; print '</td></tr>';
...@@ -337,7 +352,7 @@ if ($modecompta == 'CREANCES-DETTES') ...@@ -337,7 +352,7 @@ if ($modecompta == 'CREANCES-DETTES')
// Product // Product
$fullname=$name[$key]; $fullname=$name[$key];
if ($key >= 0) { 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 { } else {
$linkname=$langs->trans("PaymentsNotLinkedToProduct"); $linkname=$langs->trans("PaymentsNotLinkedToProduct");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment