diff --git a/htdocs/adherents/subscription/card.php b/htdocs/adherents/subscription/card.php index 215635757c2..83f1a01441c 100644 --- a/htdocs/adherents/subscription/card.php +++ b/htdocs/adherents/subscription/card.php @@ -288,7 +288,7 @@ if ($rowid && $action != 'edit') { print '
'; - print ''; + print '
'; // Member $adh->ref = $adh->getFullName($langs); @@ -320,7 +320,7 @@ if ($rowid && $action != 'edit') { print ''; // Amount - print ''; + print ''; // Label print ''; diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 648fc6e18c4..e99c4a29663 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -131,7 +131,6 @@ $permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown // Security check if (!empty($user->socid)) { $socid = $user->socid; - $object->id = $user->socid; } restrictedArea($user, 'propal', $object->id); @@ -2004,8 +2003,8 @@ if ($action == 'create') { $i = 0; while ($i < $num) { $row = $db->fetch_row($resql); - $propalRefAndSocName = $row [1]." - ".$row [2]; - $liste_propal [$row [0]] = $propalRefAndSocName; + $propalRefAndSocName = $row[1]." - ".$row[2]; + $liste_propal[$row[0]] = $propalRefAndSocName; $i++; } print $form->selectarray("copie_propal", $liste_propal, 0); diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index 8b057a6c702..f1b5c29bae2 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -552,7 +552,7 @@ $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos' llxHeader('', $title, $help_url); $sql = 'SELECT'; -if ($sall || $search_product_category > 0 || $search_user > 0) { +if ($sall || $search_user > 0) { $sql = 'SELECT DISTINCT'; } $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax , s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, '; @@ -596,12 +596,9 @@ $sql .= ', '.MAIN_DB_PREFIX.'propal as p'; if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)"; } -if ($sall || $search_product_category > 0) { +if ($sall) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid=pd.fk_propal'; } -if ($search_product_category > 0) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; -} $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON p.fk_user_author = u.rowid'; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON pr.rowid = p.fk_projet"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_availability as ava on (ava.rowid = p.fk_availability)"; @@ -714,10 +711,6 @@ if ($search_fk_input_reason > 0) { if ($search_fk_mode_reglement > 0) { $sql .= " AND p.fk_mode_reglement = ".((int) $search_fk_mode_reglement); } - -if ($search_product_category > 0) { - $sql .= " AND cp.fk_categorie = ".((int) $search_product_category); -} if ($socid > 0) { $sql .= ' AND s.rowid = '.((int) $socid); } @@ -754,6 +747,36 @@ if ($search_date_signature_start) { if ($search_date_signature_end) { $sql .= " AND p.date_signature <= '".$db->idate($search_date_signature_end)."'"; } +// Search for tag/category ($searchCategoryProductList is an array of ID) +$searchCategoryProductOperator = -1; +$searchCategoryProductList = array($search_product_category); +if (!empty($searchCategoryProductList)) { + $searchCategoryProductSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryProductList as $searchCategoryProduct) { + if (intval($searchCategoryProduct) == -2) { + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."propaldet as pd WHERE pd.fk_propal = p.rowid AND pd.fk_product = ck.fk_product)"; + } elseif (intval($searchCategoryProduct) > 0) { + if ($searchCategoryProductOperator == 0) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."propaldet as pd WHERE pd.fk_propal = p.rowid AND pd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; + } else { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); + } + } + } + if ($listofcategoryid) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."propaldet as pd WHERE pd.fk_propal = p.rowid AND pd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryProductOperator == 1) { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")"; + } + } else { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; + } + } +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 455420ce90a..79bbf69e31c 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -793,7 +793,7 @@ $title = $langs->trans("Orders"); $help_url = "EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes"; $sql = 'SELECT'; -if ($sall || $search_product_category > 0 || $search_user > 0) { +if ($sall || $search_user > 0) { $sql = 'SELECT DISTINCT'; } $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax, s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client,'; @@ -837,12 +837,9 @@ $sql .= ', '.MAIN_DB_PREFIX.'commande as c'; if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande_extrafields as ef on (c.rowid = ef.fk_object)"; } -if ($sall || $search_product_category > 0) { +if ($sall) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON c.rowid=pd.fk_commande'; } -if ($search_product_category > 0) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; -} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = c.fk_projet"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON c.fk_user_author = u.rowid'; @@ -862,9 +859,6 @@ $sql .= $hookmanager->resPrint; $sql .= ' WHERE c.fk_soc = s.rowid'; $sql .= ' AND c.entity IN ('.getEntity('commande').')'; -if ($search_product_category > 0) { - $sql .= " AND cp.fk_categorie = ".((int) $search_product_category); -} if ($socid > 0) { $sql .= ' AND s.rowid = '.((int) $socid); } @@ -1007,7 +1001,36 @@ if ($search_fk_mode_reglement > 0) { if ($search_fk_input_reason > 0) { $sql .= " AND c.fk_input_reason = ".((int) $search_fk_input_reason); } - +// Search for tag/category ($searchCategoryProductList is an array of ID) +$searchCategoryProductOperator = -1; +$searchCategoryProductList = array($search_product_category); +if (!empty($searchCategoryProductList)) { + $searchCategoryProductSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryProductList as $searchCategoryProduct) { + if (intval($searchCategoryProduct) == -2) { + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commandedet as cd WHERE cd.fk_commande = c.rowid AND cd.fk_product = ck.fk_product)"; + } elseif (intval($searchCategoryProduct) > 0) { + if ($searchCategoryProductOperator == 0) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commandedet as cd WHERE cd.fk_commande = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; + } else { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); + } + } + } + if ($listofcategoryid) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commandedet as cd WHERE cd.fk_commande = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryProductOperator == 1) { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")"; + } + } else { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; + } + } +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index fb7616e8ab3..46cf6b73ac4 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -559,7 +559,7 @@ $companyparent = new Societe($db); $company_url_list = array(); $sql = 'SELECT'; -if ($sall || $search_product_category > 0 || $search_user > 0) { +if ($sall || $search_user > 0) { $sql = 'SELECT DISTINCT'; } $sql .= ' f.rowid as id, f.ref, f.ref_client, f.fk_soc, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total_ht, f.total_tva, f.total_ttc,'; @@ -616,7 +616,7 @@ if (!$sall) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; } */ -if ($sall || $search_product_category > 0) { +if ($sall) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture'; } if (!empty($search_fac_rec_source_title)) { @@ -811,17 +811,17 @@ if (!empty($searchCategoryProductList)) { $listofcategoryid = ''; foreach ($searchCategoryProductList as $searchCategoryProduct) { if (intval($searchCategoryProduct) == -2) { - $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product)"; + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facturedet as fd WHERE fd.fk_facture = f.rowid AND fd.fk_product = ck.fk_product)"; } elseif (intval($searchCategoryProduct) > 0) { if ($searchCategoryProductOperator == 0) { - $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facturedet as fd WHERE fd.fk_facture = f.rowid AND fd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; } else { $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); } } } if ($listofcategoryid) { - $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facturedet as fd WHERE fd.fk_facture = f.rowid AND fd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; } if ($searchCategoryProductOperator == 1) { if (!empty($searchCategoryProductSqlList)) { @@ -918,7 +918,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords = $db->num_rows($result); */ /* The fast and low memory method to get and count full list converts the sql into a sql count */ - if ($sall || $search_product_category > 0 || $search_user > 0) { + if ($sall || $search_user > 0) { $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords FROM', $sql); } else { $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(f.rowid) as nbtotalofrecords FROM', $sql); diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index c1b97e65e98..65bb4fa8b08 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -265,9 +265,6 @@ if (!empty($extrafields->attributes[$object->table_element]['label']) && is_arra $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (c.rowid = ef.fk_object)"; } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat"; -if ($search_product_category > 0) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product'; -} if ($search_user > 0) { $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc"; @@ -277,9 +274,6 @@ $sql .= ' AND c.entity IN ('.getEntity('contract').')'; if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) { $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')'; } -if ($search_product_category > 0) { - $sql .= " AND cp.fk_categorie = ".((int) $search_product_category); -} if ($socid) { $sql .= " AND s.rowid = ".((int) $socid); } @@ -325,6 +319,36 @@ if ($sall) { if ($search_user > 0) { $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".((int) $search_user); } +// Search for tag/category ($searchCategoryProductList is an array of ID) +$searchCategoryProductOperator = -1; +$searchCategoryProductList = array($search_product_category); +if (!empty($searchCategoryProductList)) { + $searchCategoryProductSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryProductList as $searchCategoryProduct) { + if (intval($searchCategoryProduct) == -2) { + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product)"; + } elseif (intval($searchCategoryProduct) > 0) { + if ($searchCategoryProductOperator == 0) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; + } else { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); + } + } + } + if ($listofcategoryid) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryProductOperator == 1) { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")"; + } + } else { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; + } + } +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks @@ -378,8 +402,6 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { } else { $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql); $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as cd ON c.rowid = cd.fk_contrat/', '', $sqlforcount); - $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product/', '', $sqlforcount); - $sqlforcount = preg_replace('/AND cp.fk_categorie = '.((int) $search_product_category).'/', '', $sqlforcount); $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount); $resql = $db->query($sqlforcount); diff --git a/htdocs/expedition/list.php b/htdocs/expedition/list.php index 81e0adb15aa..3b06f005787 100644 --- a/htdocs/expedition/list.php +++ b/htdocs/expedition/list.php @@ -258,7 +258,7 @@ $helpurl = 'EN:Module_Shipments|FR:Module_Expéditions|ES:Módulo_Ex llxHeader('', $langs->trans('ListOfSendings'), $helpurl); $sql = 'SELECT'; -if ($sall || $search_product_category > 0 || $search_user > 0) { +if ($sall || $search_user > 0) { $sql = 'SELECT DISTINCT'; } $sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_delivery as delivery_date, e.fk_statut, e.billed, e.tracking_number, e.fk_shipping_method,"; @@ -288,13 +288,10 @@ $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e"; if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)"; } -if ($sall || $search_product_category > 0) { +if ($sall) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'expeditiondet as ed ON e.rowid=ed.fk_expedition'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON pd.rowid=ed.fk_origin_line'; } -if ($search_product_category > 0) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; -} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; if (($search_categ_cus > 0) || ($search_categ_cus == -2)) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ @@ -326,9 +323,7 @@ $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object $sql .= $hookmanager->resPrint; $sql .= " WHERE e.entity IN (".getEntity('expedition').")"; -if ($search_product_category > 0) { - $sql .= " AND cp.fk_categorie = ".((int) $search_product_category); -} + if ($socid > 0) { $sql .= " AND s.rowid = ".((int) $socid); } @@ -408,7 +403,36 @@ if ($search_categ_cus > 0) { if ($search_categ_cus == -2) { $sql .= " AND cc.fk_categorie IS NULL"; } - +// Search for tag/category ($searchCategoryProductList is an array of ID) +$searchCategoryProductOperator = -1; +$searchCategoryProductList = array($search_product_category); +if (!empty($searchCategoryProductList)) { + $searchCategoryProductSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryProductList as $searchCategoryProduct) { + if (intval($searchCategoryProduct) == -2) { + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product)"; + } elseif (intval($searchCategoryProduct) > 0) { + if ($searchCategoryProductOperator == 0) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; + } else { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); + } + } + } + if ($listofcategoryid) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."commandedet as cd WHERE ed.fk_expedition = e.rowid AND ed.fk_origin_line = cd.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryProductOperator == 1) { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")"; + } + } else { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; + } + } +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; @@ -593,7 +617,7 @@ if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->right $moreforfilter .= img_picto($tmptitle, 'category'); //$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); //$moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1); - $moreforfilter .= $formother->select_categories(Categorie::TYPE_PRODUCT, $search_product_category, 'parent', 1, $tmptitle); + $moreforfilter .= $formother->select_categories(Categorie::TYPE_PRODUCT, $search_product_category, 'search_product_category', 1, $tmptitle); $moreforfilter .= ''; } diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index e0434378573..8eac9943c3a 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -752,7 +752,7 @@ if ($search_billed > 0) { $help_url = ''; $sql = 'SELECT'; -if ($sall || $search_product_category > 0) { +if ($sall) { $sql = 'SELECT DISTINCT'; } $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.email,'; @@ -782,12 +782,9 @@ $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf"; if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cf.rowid = ef.fk_object)"; } -if ($sall || $search_product_category > 0) { +if ($sall) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet as pd ON cf.rowid=pd.fk_commande'; } -if ($search_product_category > 0) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; -} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cf.fk_projet"; // We'll need this table joined to the select in order to filter by sale @@ -826,9 +823,6 @@ if ($search_request_author) { if ($search_billed != '' && $search_billed >= 0) { $sql .= " AND cf.billed = ".((int) $search_billed); } -if ($search_product_category > 0) { - $sql .= " AND cp.fk_categorie = ".((int) $search_product_category); -} //Required triple check because statut=0 means draft filter if (GETPOST('statut', 'intcomma') !== '') { $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($db->escape(GETPOST('statut', 'intcomma')))).")"; @@ -920,6 +914,36 @@ if ($search_multicurrency_montant_ttc != '') { if ($search_project_ref != '') { $sql .= natural_search("p.ref", $search_project_ref); } +// Search for tag/category ($searchCategoryProductList is an array of ID) +$searchCategoryProductOperator = -1; +$searchCategoryProductList = array($search_product_category); +if (!empty($searchCategoryProductList)) { + $searchCategoryProductSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryProductList as $searchCategoryProduct) { + if (intval($searchCategoryProduct) == -2) { + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commande_fournisseurdet as cd WHERE cd.fk_commande = cf.rowid AND cd.fk_product = ck.fk_product)"; + } elseif (intval($searchCategoryProduct) > 0) { + if ($searchCategoryProductOperator == 0) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commande_fournisseurdet as cd WHERE cd.fk_commande = cf.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; + } else { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); + } + } + } + if ($listofcategoryid) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commande_fournisseurdet as cd WHERE cd.fk_commande = cf.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryProductOperator == 1) { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")"; + } + } else { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; + } + } +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index 709204793e9..9f06c56b9e1 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -405,7 +405,7 @@ $formcompany = new FormCompany($db); $thirdparty = new Societe($db); $sql = "SELECT"; -if ($search_all || $search_product_category > 0) { +if ($search_all) { $sql = 'SELECT DISTINCT'; } $sql .= " f.rowid as facid, f.ref, f.ref_supplier, f.type, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement, f.fk_cond_reglement,"; @@ -446,7 +446,7 @@ if (isset($extrafields->attributes[$object->table_element]['label']) && is_array if (!$search_all) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid'; } -if ($search_all || $search_product_category > 0) { +if ($search_all) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn'; } $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid'; @@ -622,17 +622,17 @@ if (!empty($searchCategoryProductList)) { $listofcategoryid = ''; foreach ($searchCategoryProductList as $searchCategoryProduct) { if (intval($searchCategoryProduct) == -2) { - $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product)"; + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facture_fourn_det as fd WHERE fd.fk_facture_fourn = f.rowid AND p.rowid = ck.fk_product)"; } elseif (intval($searchCategoryProduct) > 0) { if ($searchCategoryProductOperator == 0) { - $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facture_fourn_det as fd WHERE fd.fk_facture_fourn = f.rowid AND p.rowid = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; } else { $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); } } } if ($listofcategoryid) { - $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facture_fourn_det as fd WHERE fd.fk_facture_fourn = f.rowid AND p.rowid = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; } if ($searchCategoryProductOperator == 1) { if (!empty($searchCategoryProductSqlList)) { diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index 37853d1488a..66f69a25ff9 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -52,7 +52,7 @@ if (!empty($conf->project->enabled)) { // Load translation files required by the page $langs->loadLangs(array('companies', 'supplier_proposal', 'compta', 'bills', 'propal', 'orders', 'products', 'deliveries', 'sendings')); -if (!empty($conf->margin->enabled)) { +if (isModEnabled('margin')) { $langs->load('margins'); } @@ -62,13 +62,13 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); $socid = GETPOST('socid', 'int'); $action = GETPOST('action', 'aZ09'); -$cancel = GETPOST('cancel'); +$cancel = GETPOST('cancel', 'alpha'); $origin = GETPOST('origin', 'alpha'); $originid = GETPOST('originid', 'int'); $confirm = GETPOST('confirm', 'alpha'); -$projectid = GETPOST('projectid', 'int'); $lineid = GETPOST('lineid', 'int'); $contactid = GETPOST('contactid', 'int'); +$projectid = GETPOST('projectid', 'int'); $rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1; // PDF @@ -79,12 +79,6 @@ $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($con // Nombre de ligne pour choix de produit/service predefinis $NBLINES = 4; -// Security check -if (!empty($user->socid)) { - $socid = $user->socid; -} -$result = restrictedArea($user, 'supplier_proposal', $id); - // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('supplier_proposalcard', 'globalcard')); @@ -100,8 +94,9 @@ if ($id > 0 || !empty($ref)) { if ($ret > 0) { $ret = $object->fetch_thirdparty(); } - if ($ret < 0) { - dol_print_error('', $object->error); + if ($ret <= 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $action = ''; } } @@ -124,6 +119,12 @@ $permissiondellink = $usercancreate; // Used by the include of actions_dellink.i $permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php $permissiontoadd = $usercancreate; +// Security check +if (!empty($user->socid)) { + $socid = $user->socid; +} +$result = restrictedArea($user, 'supplier_proposal', $object->id); + /* * Actions @@ -166,7 +167,7 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once // Action clone object - if ($action == 'confirm_clone' && $confirm == 'yes') { + if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) { if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { @@ -195,8 +196,11 @@ if (empty($reshook)) { // Remove line $result = $object->deleteline($lineid); // reorder lines - if ($result) { + if ($result > 0) { $object->line_order(true); + } else { + $langs->load("errors"); + setEventMessages($object->error, $object->errors, 'errors'); } if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { @@ -208,6 +212,9 @@ if (empty($reshook)) { $outputlangs->setDefaultLang($newlang); } $ret = $object->fetch($id); // Reload to get new records + if ($ret > 0) { + $object->fetch_thirdparty(); + } $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } @@ -218,25 +225,25 @@ if (empty($reshook)) { $result = $object->valid($user); if ($result >= 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { - $outputlangs = $langs; - $newlang = ''; - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { - $newlang = GETPOST('lang_id', 'aZ09'); - } - if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { - $newlang = $object->thirdparty->default_lang; - } - if (!empty($newlang)) { - $outputlangs = new Translate("", $conf); - $outputlangs->setDefaultLang($newlang); - } - $model = $object->model_pdf; - $ret = $object->fetch($id); // Reload to get new records - - $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + $outputlangs = $langs; + $newlang = ''; + if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); } + if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } + if (!empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model = $object->model_pdf; + $ret = $object->fetch($id); // Reload to get new records + if ($ret > 0) { + $object->fetch_thirdparty(); + } + + $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); } } else { $langs->load("errors"); @@ -322,6 +329,7 @@ if (empty($reshook)) { if (!$error) { if ($origin && $originid) { + // Parse element/subelement (ex: project_task) $element = $subelement = $origin; if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) { $element = $regs[1]; @@ -336,6 +344,15 @@ if (empty($reshook)) { $element = 'comm/propal'; $subelement = 'propal'; } + if ($element == 'contract') { + $element = $subelement = 'contrat'; + } + if ($element == 'inter') { + $element = $subelement = 'ficheinter'; + } + if ($element == 'shipping') { + $element = $subelement = 'expedition'; + } $object->origin = $origin; $object->origin_id = $originid; @@ -533,6 +550,9 @@ if (empty($reshook)) { $outputlangs->setDefaultLang($newlang); } $ret = $object->fetch($id); // Reload to get new records + if ($ret > 0) { + $object->fetch_thirdparty(); + } $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } } elseif ($action == "setabsolutediscount" && $usercancreate) { @@ -568,11 +588,13 @@ if (empty($reshook)) { $ref_supplier = GETPOST('fourn_ref', 'alpha'); - $prod_entry_mode = GETPOST('prod_entry_mode'); - if ($prod_entry_mode == 'free') { + $prod_entry_mode = GETPOST('prod_entry_mode', 'aZ09'); + if ($prod_entry_mode == 'free') { $idprod = 0; + $tva_tx = (GETPOST('tva_tx', 'alpha') ? price2num(preg_replace('/\s*\(.*\)/', '', GETPOST('tva_tx', 'alpha'))) : 0); } else { $idprod = GETPOST('idprod', 'int'); + $tva_tx = ''; } $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)' @@ -581,7 +603,8 @@ if (empty($reshook)) { $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2); $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2); $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2); - $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS'); + + $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2); $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0); if (empty($remise_percent)) { @@ -864,6 +887,9 @@ if (empty($reshook)) { } $model = $object->model_pdf; $ret = $object->fetch($id); // Reload to get new records + if ($ret > 0) { + $object->fetch_thirdparty(); + } $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); if ($result < 0) { @@ -917,7 +943,7 @@ if (empty($reshook)) { } } } elseif ($action == 'updateline' && $usercancreate && GETPOST('save') == $langs->trans("Save")) { - // Mise a jour d'une ligne dans la demande de prix + // Update a line within proposal $vat_rate = (GETPOST('tva_tx') ?GETPOST('tva_tx') : 0); // Define info_bits @@ -1403,7 +1429,7 @@ if ($action == 'create') { /* - * Combobox pour la fonction de copie + * Combobox for copy function */ if (empty($conf->global->SUPPLIER_PROPOSAL_CLONE_ON_CREATE_PAGE)) { @@ -1425,7 +1451,7 @@ if ($action == 'create') { $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal p"; $sql .= ", ".MAIN_DB_PREFIX."societe s"; $sql .= " WHERE s.rowid = p.fk_soc"; - $sql .= " AND p.entity = ".$conf->entity; + $sql .= " AND p.entityy IN (".getEntity('supplier_proposal').")"; $sql .= " AND p.fk_statut <> ".SupplierProposal::STATUS_DRAFT; $sql .= " ORDER BY Id"; @@ -1435,8 +1461,8 @@ if ($action == 'create') { $i = 0; while ($i < $num) { $row = $db->fetch_row($resql); - $askPriceSupplierRefAndSocName = $row [1]." - ".$row [2]; - $liste_ask [$row [0]] = $askPriceSupplierRefAndSocName; + $askPriceSupplierRefAndSocName = $row[1]." - ".$row[2]; + $liste_ask[$row[0]] = $askPriceSupplierRefAndSocName; $i++; } print $form->selectarray("copie_supplier_proposal", $liste_ask, 0); @@ -1564,39 +1590,28 @@ if ($action == 'create') { //$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', 0, 1); //$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreateorder, 'string', '', null, null, '', 1); // Thirdparty - $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1, 'supplier'); + $morehtmlref .= $object->thirdparty->getNomUrl(1, 'supplier'); if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) { $morehtmlref .= ' ('.$langs->trans("OtherProposals").')'; } // Project - if (!empty($conf->project->enabled)) { + if (isModEnabled('project')) { $langs->load("projects"); - $morehtmlref .= '
'.$langs->trans('Project').' '; + $morehtmlref .= '
'; if ($usercancreate) { + $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); if ($action != 'classify') { - $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; - } - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref .= ''; - $morehtmlref .= ''; - } else { - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; } + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, ($action == 'classify' ? 1 : 0), 0, 1, ''); } else { if (!empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); - $morehtmlref .= ' : '.$proj->getNomUrl(1); + $morehtmlref .= $proj->getNomUrl(1); if ($proj->title) { - $morehtmlref .= ' - '.$proj->title; + $morehtmlref .= ' - '.dol_escape_htmltag($proj->title).''; } - } else { - $morehtmlref .= ''; } } } @@ -1610,7 +1625,7 @@ if ($action == 'create') { print '
'; print '
'; - print '
'.$langs->trans("Amount").''.price($object->amount).'
'.$langs->trans("Amount").''.price($object->amount).'
'.$langs->trans("Label").''.$object->note.'
'; + print '
'; // Relative and absolute discounts if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) { diff --git a/htdocs/supplier_proposal/contact.php b/htdocs/supplier_proposal/contact.php index 1fa344cbb5e..8db19cfb2a7 100644 --- a/htdocs/supplier_proposal/contact.php +++ b/htdocs/supplier_proposal/contact.php @@ -132,15 +132,15 @@ if ($id > 0 || !empty($ref)) { $morehtmlref = '
'; // Ref supplier - $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); - $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); + //$morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', 0, 1); + //$morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, 0, 'string', '', null, null, '', 1); // Thirdparty - $morehtmlref .= '
'.$object->thirdparty->getNomUrl(1); + $morehtmlref .= $object->thirdparty->getNomUrl(1); // Project if (!empty($conf->project->enabled)) { $langs->load("projects"); $morehtmlref .= '
'; - if ($permissiontoedit) { + if (0) { $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); if ($action != 'classify') { $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; diff --git a/htdocs/supplier_proposal/document.php b/htdocs/supplier_proposal/document.php index 7aacfb8f8b2..c1829fd61d6 100644 --- a/htdocs/supplier_proposal/document.php +++ b/htdocs/supplier_proposal/document.php @@ -77,6 +77,7 @@ if ($object->id > 0) { } $permissiontoadd = $user->rights->supplier_proposal->creer; +$usercancreate = $permissiontoadd; /* * Actions @@ -120,37 +121,25 @@ if ($object->id > 0) { //$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', 0, 1); //$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', null, null, '', 1); // Thirdparty - $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); + $morehtmlref .= $object->thirdparty->getNomUrl(1); // Project if (!empty($conf->project->enabled)) { $langs->load("projects"); - $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($user->rights->supplier_proposal->creer) { + $morehtmlref .= '
'; + if (0) { + $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); if ($action != 'classify') { - //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - $morehtmlref .= ' : '; - } - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref .= '
'; - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref .= ''; - $morehtmlref .= ''; - } else { - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; } + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, ($action == 'classify' ? 1 : 0), 0, 1, ''); } else { if (!empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); - $morehtmlref .= ' : '.$proj->getNomUrl(1); + $morehtmlref .= $proj->getNomUrl(1); if ($proj->title) { $morehtmlref .= ' - '.$proj->title; } - } else { - $morehtmlref .= ''; } } } diff --git a/htdocs/supplier_proposal/info.php b/htdocs/supplier_proposal/info.php index d1f0daad639..0b2af861163 100644 --- a/htdocs/supplier_proposal/info.php +++ b/htdocs/supplier_proposal/info.php @@ -72,32 +72,22 @@ $morehtmlref = '
'; //$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', 0, 1); //$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', null, null, '', 1); // Thirdparty -$morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); +$morehtmlref .= $object->thirdparty->getNomUrl(1); // Project if (!empty($conf->project->enabled)) { $langs->load("projects"); - $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($user->rights->supplier_proposal->creer) { + $morehtmlref .= '
'; + if (0) { + $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); if ($action != 'classify') { - //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - $morehtmlref .= ' : '; - } - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref .= '
'; - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref .= ''; - $morehtmlref .= ''; - } else { - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; } + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, ($action == 'classify' ? 1 : 0), 0, 1, ''); } else { if (!empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); - $morehtmlref .= ' : '.$proj->getNomUrl(1); + $morehtmlref .= $proj->getNomUrl(1); if ($proj->title) { $morehtmlref .= ' - '.$proj->title; } diff --git a/htdocs/supplier_proposal/list.php b/htdocs/supplier_proposal/list.php index 5cb7cf69ef8..fd71dc26204 100644 --- a/htdocs/supplier_proposal/list.php +++ b/htdocs/supplier_proposal/list.php @@ -94,6 +94,7 @@ $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'a $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha'); $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha'); $search_status = GETPOST('search_status', 'int'); +$search_product_category = GETPOST('search_product_category', 'int'); $object_statut = $db->escape(GETPOST('supplier_proposal_statut')); $search_btn = GETPOST('button_search', 'alpha'); @@ -216,8 +217,6 @@ if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } -$search_product_category = 0; - include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Do we click on purge search criteria ? @@ -295,7 +294,7 @@ $help_url = 'EN:Ask_Price_Supplier|FR:Demande_de_prix_fournisseur'; llxHeader('', $title, $help_url); $sql = 'SELECT'; -if ($sall || $search_product_category > 0 || $search_user > 0) { +if ($sall || $search_user > 0) { $sql = 'SELECT DISTINCT'; } $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.town, s.zip, s.fk_pays, s.client, s.code_client,'; @@ -327,12 +326,9 @@ $sql .= ', '.MAIN_DB_PREFIX.'supplier_proposal as sp'; if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (sp.rowid = ef.fk_object)"; } -if ($sall || $search_product_category > 0) { +if ($sall) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'supplier_proposaldet as pd ON sp.rowid=pd.fk_supplier_proposal'; } -if ($search_product_category > 0) { - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; -} $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON sp.fk_user_author = u.rowid'; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = sp.fk_projet"; // We'll need this table joined to the select in order to filter by sale @@ -426,6 +422,36 @@ if ($search_sale > 0) { if ($search_user > 0) { $sql .= " AND c.fk_c_type_contact = tc.rowid AND tc.element='supplier_proposal' AND tc.source='internal' AND c.element_id = sp.rowid AND c.fk_socpeople = ".((int) $search_user); } +// Search for tag/category ($searchCategoryProductList is an array of ID) +$searchCategoryProductOperator = -1; +$searchCategoryProductList = array($search_product_category); +if (!empty($searchCategoryProductList)) { + $searchCategoryProductSqlList = array(); + $listofcategoryid = ''; + foreach ($searchCategoryProductList as $searchCategoryProduct) { + if (intval($searchCategoryProduct) == -2) { + $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."supplier_proposaldet as sd WHERE sd.fk_supplier_proposal = sp.rowid AND sd.fk_product = ck.fk_product)"; + } elseif (intval($searchCategoryProduct) > 0) { + if ($searchCategoryProductOperator == 0) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."supplier_proposaldet as sd WHERE sd.fk_supplier_proposal = sp.rowid AND sd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")"; + } else { + $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct); + } + } + } + if ($listofcategoryid) { + $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."supplier_proposaldet as sd WHERE sd.fk_supplier_proposal = sp.rowid AND sd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))"; + } + if ($searchCategoryProductOperator == 1) { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")"; + } + } else { + if (!empty($searchCategoryProductSqlList)) { + $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")"; + } + } +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; // Add where from hooks @@ -1121,7 +1147,7 @@ if ($resql) { $userstatic->id = $obj->fk_user_author; $userstatic->login = $obj->login; - $userstatic->status = $obj->status; + $userstatic->status = $obj->ustatus; $userstatic->lastname = $obj->name; $userstatic->firstname = $obj->firstname; $userstatic->photo = $obj->photo; @@ -1201,6 +1227,17 @@ if ($resql) { // Show total line include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; + // If no record found + if ($num == 0) { + $colspan = 1; + foreach ($arrayfields as $key => $val) { + if (!empty($val['checked'])) { + $colspan++; + } + } + print '
'; + } + $db->free($resql); $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql); diff --git a/htdocs/supplier_proposal/note.php b/htdocs/supplier_proposal/note.php index 118855cecf3..aa0ccc5276a 100644 --- a/htdocs/supplier_proposal/note.php +++ b/htdocs/supplier_proposal/note.php @@ -21,9 +21,9 @@ */ /** - * \file htdocs/comm/propal/note.php + * \file htdocs/supplier_proposal/note.php * \ingroup propal - * \brief Fiche d'information sur une proposition commerciale + * \brief Page to show notes of a supplier proposal request */ // Load Dolibarr environment @@ -53,6 +53,8 @@ $result = restrictedArea($user, 'supplier_proposal', $id, 'supplier_proposal'); $object = new SupplierProposal($db); +$usercancreate = $user->hasRight("supplier_propal", "write"); + /* @@ -104,37 +106,25 @@ if ($id > 0 || !empty($ref)) { //$morehtmlref.=$form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', 0, 1); //$morehtmlref.=$form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->fournisseur->commande->creer, 'string', '', null, null, '', 1); // Thirdparty - $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1); + $morehtmlref .= $object->thirdparty->getNomUrl(1); // Project if (!empty($conf->project->enabled)) { $langs->load("projects"); - $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($user->rights->supplier_proposal->creer) { + $morehtmlref .= '
'; + if ($usercancreate) { + $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"'); if ($action != 'classify') { - //$morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; - $morehtmlref .= ' : '; - } - if ($action == 'classify') { - //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1); - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= ''; - $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1); - $morehtmlref .= ''; - $morehtmlref .= ''; - } else { - $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); + $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' '; } + $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, ($action == 'classify' ? 1 : 0), 0, 1, ''); } else { if (!empty($object->fk_project)) { $proj = new Project($db); $proj->fetch($object->fk_project); - $morehtmlref .= ' : '.$proj->getNomUrl(1); + $morehtmlref .= $proj->getNomUrl(1); if ($proj->title) { $morehtmlref .= ' - '.$proj->title; } - } else { - $morehtmlref .= ''; } } } diff --git a/htdocs/user/list.php b/htdocs/user/list.php index dacf572d175..c5681326817 100644 --- a/htdocs/user/list.php +++ b/htdocs/user/list.php @@ -436,7 +436,6 @@ if ($search_statut != '' && $search_statut >= 0) { if ($sall) { $sql .= natural_search(array_keys($fieldstosearchall), $sall); } - // Search for tag/category ($searchCategoryUserList is an array of ID) $searchCategoryUserList = array($search_categ); if (!empty($searchCategoryUserList)) {
'.$langs->trans("NoRecordFound").'