This commit is contained in:
arnaud 2016-06-30 14:57:23 +02:00
parent b6700c70d6
commit 97fe75f198

View File

@ -280,17 +280,18 @@ if ($type_element == 'contract')
$thirdTypeSelect='customer'; $thirdTypeSelect='customer';
} }
$sql = $sql_select; if(!empty($sql_select)) {
$sql.= ' d.description as description,'; $sql = $sql_select;
if ($type_element != 'fichinter' && $type_element != 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty,'; $sql.= ' d.description as description,';
if ($type_element == 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty,'; if ($type_element != 'fichinter' && $type_element != 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty,';
if ($type_element != 'fichinter') $sql.= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity,'; if ($type_element == 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty,';
$sql.= " s.rowid as socid "; if ($type_element != 'fichinter') $sql.= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity,';
if ($type_element != 'fichinter') $sql.= ", p.ref as prod_ref, p.label as product_label"; $sql.= " s.rowid as socid ";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from; if ($type_element != 'fichinter') $sql.= ", p.ref as prod_ref, p.label as product_label";
if ($type_element != 'fichinter') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid '; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from;
$sql.= $where; if ($type_element != 'fichinter') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid ';
if ($month > 0) { $sql.= $where;
if ($month > 0) {
if ($year > 0) { if ($year > 0) {
$start = dol_mktime(0, 0, 0, $month, 1, $year); $start = dol_mktime(0, 0, 0, $month, 1, $year);
$end = dol_time_plus_duree($start,1,'m') - 1; $end = dol_time_plus_duree($start,1,'m') - 1;
@ -298,25 +299,26 @@ if ($month > 0) {
} else { } else {
$sql.= " AND date_format(".$dateprint.", '%m') = '".sprintf('%02d',$month)."'"; $sql.= " AND date_format(".$dateprint.", '%m') = '".sprintf('%02d',$month)."'";
} }
} else if ($year > 0) { } else if ($year > 0) {
$start = dol_mktime(0, 0, 0, 1, 1, $year); $start = dol_mktime(0, 0, 0, 1, 1, $year);
$end = dol_time_plus_duree($start,1,'y') - 1; $end = dol_time_plus_duree($start,1,'y') - 1;
$sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'";
} }
if ($sref) $sql.= " AND ".$doc_number." LIKE '%".$sref."%'"; if ($sref) $sql.= " AND ".$doc_number." LIKE '%".$sref."%'";
if ($sprod_fulldescr) if ($sprod_fulldescr)
{ {
$sql.= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'"; $sql.= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'";
if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'"; if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'";
if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'"; if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'";
$sql.=")"; $sql.=")";
}
$sql.= $db->order($sortfield,$sortorder);
$resql=$db->query($sql);
$totalnboflines = $db->num_rows($resql);
$sql.= $db->plimit($limit + 1, $offset);
} }
$sql.= $db->order($sortfield,$sortorder);
$resql=$db->query($sql);
$totalnboflines = $db->num_rows($resql);
$sql.= $db->plimit($limit + 1, $offset);
//print $sql; //print $sql;
// Define type of elements // Define type of elements