NEW Can choose the root category to show for TakePOS module

This commit is contained in:
Laurent Destailleur 2019-03-15 01:28:54 +01:00
parent 0ef6fd36f9
commit 86c5dc20e3
14 changed files with 110 additions and 59 deletions

View File

@ -31,7 +31,7 @@ if (!$user->admin)
accessforbidden(); accessforbidden();
// Load translation files required by the page // Load translation files required by the page
$langs->load("categories"); $langs->loadLangs(array("categories","admin"));
$action=GETPOST('action', 'aZ09'); $action=GETPOST('action', 'aZ09');

View File

@ -909,7 +909,7 @@ class Categorie extends CommonObject
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* Return direct childs of a category * Return direct childs id of a category into an array
* *
* @return array|int <0 KO, array ok * @return array|int <0 KO, array ok
*/ */
@ -947,8 +947,6 @@ class Categorie extends CommonObject
protected function load_motherof() protected function load_motherof()
{ {
// phpcs:enable // phpcs:enable
global $conf;
$this->motherof=array(); $this->motherof=array();
// Load array[child]=parent // Load array[child]=parent
@ -987,10 +985,10 @@ class Categorie extends CommonObject
* *
* @param string $type Type of categories ('customer', 'supplier', 'contact', 'product', 'member') or (0, 1, 2, ...). * @param string $type Type of categories ('customer', 'supplier', 'contact', 'product', 'member') or (0, 1, 2, ...).
* @param int $markafterid Removed all categories including the leaf $markafterid in category tree. * @param int $markafterid Removed all categories including the leaf $markafterid in category tree.
* * @param int $keeponlyifinleafid Keep only of category is inside the leaf starting with this id.
* @return array|int Array of categories. this->cats and this->motherof are set, -1 on error * @return array|int Array of categories. this->cats and this->motherof are set, -1 on error
*/ */
public function get_full_arbo($type, $markafterid = 0) public function get_full_arbo($type, $markafterid = 0, $keeponlyifinleafid = 0)
{ {
// phpcs:enable // phpcs:enable
global $conf, $langs; global $conf, $langs;
@ -1059,6 +1057,27 @@ class Categorie extends CommonObject
} }
} }
} }
// Exclude leaf including $markafterid from tree
if ($keeponlyifinleafid)
{
//print "Look to discard category ".$keeponlyifinleafid."\n";
$keyfilter1='^'.$keeponlyifinleafid.'$';
$keyfilter2='_'.$keeponlyifinleafid.'$';
$keyfilter3='^'.$keeponlyifinleafid.'_';
$keyfilter4='_'.$keeponlyifinleafid.'_';
foreach($this->cats as $key => $val)
{
if (preg_match('/'.$keyfilter1.'/', $val['fullpath']) || preg_match('/'.$keyfilter2.'/', $val['fullpath'])
|| preg_match('/'.$keyfilter3.'/', $val['fullpath']) || preg_match('/'.$keyfilter4.'/', $val['fullpath']))
{
// We keep
}
else
{
unset($this->cats[$key]);
}
}
}
dol_syslog(get_class($this)."::get_full_arbo dol_sort_array", LOG_DEBUG); dol_syslog(get_class($this)."::get_full_arbo dol_sort_array", LOG_DEBUG);
$this->cats=dol_sort_array($this->cats, 'fulllabel', 'asc', true, false); $this->cats=dol_sort_array($this->cats, 'fulllabel', 'asc', true, false);
@ -1070,7 +1089,8 @@ class Categorie extends CommonObject
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* For category id_categ and its childs available in this->cats, define property fullpath and fulllabel * For category id_categ and its childs available in this->cats, define property fullpath and fulllabel.
* This function is a memory scan only from $this->cats and $this->motherof, no database access must be done here.
* *
* @param int $id_categ id_categ entry to update * @param int $id_categ id_categ entry to update
* @param int $protection Deep counter to avoid infinite loop * @param int $protection Deep counter to avoid infinite loop
@ -1174,6 +1194,19 @@ class Categorie extends CommonObject
} }
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Returns the top level categories (which are not child)
*
* @param int $type Type of category (0, 1, ...)
* @return array
*/
public function get_main_categories($type = null)
{
// phpcs:enable
return $this->get_all_categories($type, true);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* Check if no category with same label already exists for this cat's parent or root and for this cat's type * Check if no category with same label already exists for this cat's parent or root and for this cat's type
@ -1225,18 +1258,6 @@ class Categorie extends CommonObject
} }
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Returns the top level categories (which are not girls)
*
* @param int $type Type of category (0, 1, ...)
* @return array
*/
public function get_main_categories($type = null)
{
// phpcs:enable
return $this->get_all_categories($type, true);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**

View File

@ -3805,7 +3805,7 @@ class Form
* @param int $excludeafterid Exclude all categories after this leaf in category tree. * @param int $excludeafterid Exclude all categories after this leaf in category tree.
* @param int $outputmode 0=HTML select string, 1=Array * @param int $outputmode 0=HTML select string, 1=Array
* @return string * @return string
* @see select_categories * @see select_categories()
*/ */
public function select_all_categories($type, $selected = '', $htmlname = "parent", $maxlength = 64, $excludeafterid = 0, $outputmode = 0) public function select_all_categories($type, $selected = '', $htmlname = "parent", $maxlength = 64, $excludeafterid = 0, $outputmode = 0)
{ {

View File

@ -375,8 +375,7 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
{ {
global $conf; global $conf;
// select2 disabled for smartphones with standard browser. // select2 can be disabled for smartphones
// TODO With select2 v4, it seems ok, except that responsive style on table become crazy when scrolling at end of array)
if (! empty($conf->browser->layout) && $conf->browser->layout == 'phone' && ! empty($conf->global->MAIN_DISALLOW_SELECT2_WITH_SMARTPHONE)) return ''; if (! empty($conf->browser->layout) && $conf->browser->layout == 'phone' && ! empty($conf->global->MAIN_DISALLOW_SELECT2_WITH_SMARTPHONE)) return '';
if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return ''; if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return '';

View File

@ -784,7 +784,8 @@ if (empty($reshook))
$stockLocation="entl".$detail_entrepot->line_id; $stockLocation="entl".$detail_entrepot->line_id;
$qty = "qtyl".$detail_entrepot->line_id; $qty = "qtyl".$detail_entrepot->line_id;
$warehouse = GETPOST($stockLocation, 'int'); $warehouse = GETPOST($stockLocation, 'int');
if (!empty($warehouse)) { if (!empty($warehouse))
{
$line->id = $detail_entrepot->line_id; $line->id = $detail_entrepot->line_id;
$line->entrepot_id = $warehouse; $line->entrepot_id = $warehouse;
$line->qty = GETPOST($qty, 'int'); $line->qty = GETPOST($qty, 'int');

View File

@ -1860,3 +1860,5 @@ MAIN_OPTIMIZEFORTEXTBROWSERDesc=Enable this option if you are a blind person, or
ThisValueCanOverwrittenOnUserLevel=This value can be overwritten by each user from its user page - tab '%s' ThisValueCanOverwrittenOnUserLevel=This value can be overwritten by each user from its user page - tab '%s'
DefaultCustomerType=Default thirdparty type for "New customer" creation form DefaultCustomerType=Default thirdparty type for "New customer" creation form
ABankAccountMustBeDefinedOnPaymentModeSetup=Note: The bank account must be defined on the module of each payment mode (Paypal, Stripe, ...) to have this feature working. ABankAccountMustBeDefinedOnPaymentModeSetup=Note: The bank account must be defined on the module of each payment mode (Paypal, Stripe, ...) to have this feature working.
RootCategoryForProductsToSell=Root category of products to sell
RootCategoryForProductsToSellDesc=If defined, only products inside this category or childs of this category will be available in the Point Of Sale

View File

@ -83,7 +83,7 @@ DeleteFromCat=Remove from tags/category
ExtraFieldsCategories=Complementary attributes ExtraFieldsCategories=Complementary attributes
CategoriesSetup=Tags/categories setup CategoriesSetup=Tags/categories setup
CategorieRecursiv=Link with parent tag/category automatically CategorieRecursiv=Link with parent tag/category automatically
CategorieRecursivHelp=If activated, product will also linked to parent category when adding into a subcategory CategorieRecursivHelp=If option is on, when you add a product into a subcategory, product will also be added into the parent category.
AddProductServiceIntoCategory=Add the following product/service AddProductServiceIntoCategory=Add the following product/service
ShowCategory=Show tag/category ShowCategory=Show tag/category
ByDefaultInList=By default in list ByDefaultInList=By default in list

View File

@ -1496,7 +1496,7 @@ else
// Tags-Categories // Tags-Categories
if ($conf->categorie->enabled) if ($conf->categorie->enabled)
{ {
print '<tr><td class="tdtop">'.$langs->trans("Categories").'</td><td colspan="3">'; print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1); $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 1);
$c = new Categorie($db); $c = new Categorie($db);
$cats = $c->containing($object->id, Categorie::TYPE_PRODUCT); $cats = $c->containing($object->id, Categorie::TYPE_PRODUCT);

View File

@ -799,10 +799,10 @@ SCRIPT;
print_liste_field_titre("NbDaysToDelivery", $_SERVER["PHP_SELF"], "pfp.delivery_time_days", "", $param, '', $sortfield, $sortorder, 'right '); print_liste_field_titre("NbDaysToDelivery", $_SERVER["PHP_SELF"], "pfp.delivery_time_days", "", $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre("ReputationForThisProduct", $_SERVER["PHP_SELF"], "pfp.supplier_reputation", "", $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre("ReputationForThisProduct", $_SERVER["PHP_SELF"], "pfp.supplier_reputation", "", $param, '', $sortfield, $sortorder, 'center ');
if ($conf->barcode->enabled) { if ($conf->barcode->enabled) {
print_liste_field_titre("BarcodeValue", $_SERVER["PHP_SELF"], "pfp.barcode", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre("BarcodeValue", $_SERVER["PHP_SELF"], "pfp.barcode", "", $param, '', $sortfield, $sortorder, 'center ');
print_liste_field_titre("BarcodeType", $_SERVER["PHP_SELF"], "pfp.fk_barcode_type", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre("BarcodeType", $_SERVER["PHP_SELF"], "pfp.fk_barcode_type", "", $param, '', $sortfield, $sortorder, 'center ');
} }
print_liste_field_titre("DateModification",$_SERVER["PHP_SELF"],"pfp.tms","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre("DateModification", $_SERVER["PHP_SELF"], "pfp.tms", "", $param, '', $sortfield, $sortorder, 'right ');
print_liste_field_titre(''); print_liste_field_titre('');
print "</tr>\n"; print "</tr>\n";

View File

@ -26,6 +26,7 @@ require '../../main.inc.php'; // Load $user and permissions
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
// If socid provided by ajax company selector // If socid provided by ajax company selector
if (! empty($_REQUEST['CASHDESK_ID_THIRDPARTY_id'])) if (! empty($_REQUEST['CASHDESK_ID_THIRDPARTY_id']))
@ -56,6 +57,8 @@ if (GETPOST('action', 'alpha') == 'set')
$res = dolibarr_set_const($db, "CASHDESK_ID_WAREHOUSE", (GETPOST('CASHDESK_ID_WAREHOUSE', 'alpha') > 0 ? GETPOST('CASHDESK_ID_WAREHOUSE', 'alpha') : ''), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "CASHDESK_ID_WAREHOUSE", (GETPOST('CASHDESK_ID_WAREHOUSE', 'alpha') > 0 ? GETPOST('CASHDESK_ID_WAREHOUSE', 'alpha') : ''), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "CASHDESK_NO_DECREASE_STOCK", GETPOST('CASHDESK_NO_DECREASE_STOCK', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "CASHDESK_NO_DECREASE_STOCK", GETPOST('CASHDESK_NO_DECREASE_STOCK', 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "CASHDESK_SERVICES", GETPOST('CASHDESK_SERVICES', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "CASHDESK_SERVICES", GETPOST('CASHDESK_SERVICES', 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOS_ROOT_CATEGORY_ID", GETPOST('TAKEPOS_ROOT_CATEGORY_ID', 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOSCONNECTOR", GETPOST('TAKEPOSCONNECTOR', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOSCONNECTOR", GETPOST('TAKEPOSCONNECTOR', 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOS_BAR_RESTAURANT", GETPOST('TAKEPOS_BAR_RESTAURANT', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_BAR_RESTAURANT", GETPOST('TAKEPOS_BAR_RESTAURANT', 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOS_PRINT_SERVER", GETPOST('TAKEPOS_PRINT_SERVER', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_PRINT_SERVER", GETPOST('TAKEPOS_PRINT_SERVER', 'alpha'), 'chaine', 0, '', $conf->entity);
@ -121,6 +124,13 @@ if (! empty($conf->service->enabled))
print "</td></tr>\n"; print "</td></tr>\n";
} }
print '<tr class="oddeven"><td>';
print $form->textwithpicto($langs->trans("RootCategoryForProductsToSell"), $langs->trans("RootCategoryForProductsToSellDesc"));
print '<td colspan="2">';
print $form->select_all_categories(Categorie::TYPE_PRODUCT, $conf->global->TAKEPOS_ROOT_CATEGORY_ID, 'TAKEPOS_ROOT_CATEGORY_ID', 64, 0, 0);
print ajax_combobox('TAKEPOS_ROOT_CATEGORY_ID');
print "</td></tr>\n";
// Use Takepos printing // Use Takepos printing
print '<tr class="oddeven"><td>'; print '<tr class="oddeven"><td>';
print $langs->trans("DolibarrReceiptPrinter").' (<a href="http://en.takepos.com/connector">'.$langs->trans("TakeposConnectorNecesary").'</a>)'; print $langs->trans("DolibarrReceiptPrinter").' (<a href="http://en.takepos.com/connector">'.$langs->trans("TakeposConnectorNecesary").'</a>)';

View File

@ -83,7 +83,7 @@ div.wrapper2{
width:12.5%; width:12.5%;
height:25%; height:25%;
margin:0; margin:0;
padding:1px; /* padding:1px; */
border: 0.1em solid; border: 0.1em solid;
box-shadow: 2px 2px 1px #888; box-shadow: 2px 2px 1px #888;
text-align: center; text-align: center;

View File

@ -40,6 +40,11 @@ $action = GETPOST('action', 'alpha');
$langs->loadLangs(array("bills","orders","commercial","cashdesk","receiptprinter")); $langs->loadLangs(array("bills","orders","commercial","cashdesk","receiptprinter"));
$categorie = new Categorie($db);
$MAXCATEG = 16;
$MAXPRODUCT = 32;
/* /*
* View * View
@ -61,14 +66,30 @@ top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss);
<script type="text/javascript" src="js/jquery.colorbox-min.js"></script> <script type="text/javascript" src="js/jquery.colorbox-min.js"></script>
<script language="javascript"> <script language="javascript">
<?php <?php
$categorie = new Categorie($db); $categories = $categorie->get_full_arbo('product', 0, (($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0)?$conf->global->TAKEPOS_ROOT_CATEGORY_ID:0));
$categories = $categorie->get_full_arbo('product');
//$conf->global->TAKEPOS_ROOT_CATEGORY_ID=0;
// Search root category to know its level
$levelofrootcategory=0;
if ($conf->global->TAKEPOS_ROOT_CATEGORY_ID > 0)
{
foreach($categories as $key => $categorycursor)
{
if ($categorycursor['id'] == $conf->global->TAKEPOS_ROOT_CATEGORY_ID)
{
$levelofrootcategory = $categorycursor['level'];
break;
}
}
}
$levelofmaincategories = $levelofrootcategory + 1;
$maincategories = array(); $maincategories = array();
$subcategories = array(); $subcategories = array();
foreach($categories as $key => $categorycursor) foreach($categories as $key => $categorycursor)
{ {
if ($categorycursor['level'] == 1) if ($categorycursor['level'] == $levelofmaincategories)
{ {
$maincategories[$key] = $categorycursor; $maincategories[$key] = $categorycursor;
} }
@ -487,9 +508,6 @@ if (!empty($reshook)) {
<div class="div3"> <div class="div3">
<?php <?php
$MAXCATEG = 16;
$MAXPRODUCT = 32;
$i = 0; $i = 0;
foreach($menus as $menu) { foreach($menus as $menu) {
$i++; $i++;