Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW Add order tags #22849

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions htdocs/categories/class/api_categories.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ class Categories extends DolibarrApi
);

public static $TYPES = array(
0 => 'product',
1 => 'supplier',
2 => 'customer',
3 => 'member',
4 => 'contact',
5 => 'account',
6 => 'project',
7 => 'user',
8 => 'bank_line',
9 => 'warehouse',
0 => 'product',
1 => 'supplier',
2 => 'customer',
3 => 'member',
4 => 'contact',
5 => 'account',
6 => 'project',
7 => 'user',
8 => 'bank_line',
9 => 'warehouse',
10 => 'actioncomm',
11 => 'website_page',
12 => 'ticket',
13 => 'knowledgemanagement'
13 => 'knowledgemanagement',
16 => 'order'
);

/**
Expand Down
161 changes: 84 additions & 77 deletions htdocs/categories/class/categorie.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,21 @@
class Categorie extends CommonObject
{
// Categories types (we use string because we want to accept any modules/types in a future)
const TYPE_PRODUCT = 'product';
const TYPE_SUPPLIER = 'supplier';
const TYPE_CUSTOMER = 'customer';
const TYPE_MEMBER = 'member';
const TYPE_CONTACT = 'contact';
const TYPE_USER = 'user';
const TYPE_PROJECT = 'project';
const TYPE_ACCOUNT = 'bank_account';
const TYPE_BANK_LINE = 'bank_line';
const TYPE_WAREHOUSE = 'warehouse';
const TYPE_ACTIONCOMM = 'actioncomm';
const TYPE_WEBSITE_PAGE = 'website_page';
const TYPE_TICKET = 'ticket';
const TYPE_PRODUCT = 'product';
const TYPE_SUPPLIER = 'supplier';
const TYPE_CUSTOMER = 'customer';
const TYPE_MEMBER = 'member';
const TYPE_CONTACT = 'contact';
const TYPE_USER = 'user';
const TYPE_PROJECT = 'project';
const TYPE_ACCOUNT = 'bank_account';
const TYPE_BANK_LINE = 'bank_line';
const TYPE_WAREHOUSE = 'warehouse';
const TYPE_ACTIONCOMM = 'actioncomm';
const TYPE_WEBSITE_PAGE = 'website_page';
const TYPE_TICKET = 'ticket';
const TYPE_KNOWLEDGEMANAGEMENT = 'knowledgemanagement';
const TYPE_ORDER = 'order';

/**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
Expand All @@ -73,20 +74,21 @@ class Categorie extends CommonObject
* @var array Table of mapping between type string and ID used for field 'type' in table llx_categories
*/
protected $MAP_ID = array(
'product' => 0,
'supplier' => 1,
'customer' => 2,
'member' => 3,
'contact' => 4,
'bank_account' => 5,
'project' => 6,
'user' => 7,
'bank_line' => 8,
'warehouse' => 9,
'actioncomm' => 10,
'website_page' => 11,
'ticket' => 12,
'knowledgemanagement' => 13
'product' => 0,
'supplier' => 1,
'customer' => 2,
'member' => 3,
'contact' => 4,
'bank_account' => 5,
'project' => 6,
'user' => 7,
'bank_line' => 8,
'warehouse' => 9,
'actioncomm' => 10,
'website_page' => 11,
'ticket' => 12,
'knowledgemanagement' => 13,
'order' => 16
);

/**
Expand All @@ -95,20 +97,21 @@ class Categorie extends CommonObject
* @note This array should be removed in future, once previous constants are moved to the string value. Deprecated
*/
public static $MAP_ID_TO_CODE = array(
0 => 'product',
1 => 'supplier',
2 => 'customer',
3 => 'member',
4 => 'contact',
5 => 'bank_account',
6 => 'project',
7 => 'user',
8 => 'bank_line',
9 => 'warehouse',
0 => 'product',
1 => 'supplier',
2 => 'customer',
3 => 'member',
4 => 'contact',
5 => 'bank_account',
6 => 'project',
7 => 'user',
8 => 'bank_line',
9 => 'warehouse',
10 => 'actioncomm',
11 => 'website_page',
12 => 'ticket',
13 => 'knowledgemanagement'
13 => 'knowledgemanagement',
16 => 'order'
);

/**
Expand All @@ -117,9 +120,9 @@ class Categorie extends CommonObject
* @todo Move to const array when PHP 5.6 will be our minimum target
*/
public $MAP_CAT_FK = array(
'customer' => 'soc',
'supplier' => 'soc',
'contact' => 'socpeople',
'customer' => 'soc',
'supplier' => 'soc',
'contact' => 'socpeople',
'bank_account' => 'account',
);

Expand All @@ -129,8 +132,8 @@ class Categorie extends CommonObject
* @note Move to const array when PHP 5.6 will be our minimum target
*/
public $MAP_CAT_TABLE = array(
'customer' => 'societe',
'supplier' => 'fournisseur',
'customer' => 'societe',
'supplier' => 'fournisseur',
'bank_account' => 'account',
);

Expand All @@ -140,20 +143,21 @@ class Categorie extends CommonObject
* @note Move to const array when PHP 5.6 will be our minimum target
*/
public $MAP_OBJ_CLASS = array(
'product' => 'Product',
'customer' => 'Societe',
'supplier' => 'Fournisseur',
'member' => 'Adherent',
'contact' => 'Contact',
'user' => 'User',
'account' => 'Account', // old for bank account
'bank_account' => 'Account',
'project' => 'Project',
'warehouse' => 'Entrepot',
'actioncomm' => 'ActionComm',
'website_page' => 'WebsitePage',
'ticket' => 'Ticket',
'knowledgemanagement' => 'KnowledgeRecord'
'product' => 'Product',
'customer' => 'Societe',
'supplier' => 'Fournisseur',
'member' => 'Adherent',
'contact' => 'Contact',
'user' => 'User',
'account' => 'Account', // old for bank account
'bank_account' => 'Account',
'project' => 'Project',
'warehouse' => 'Entrepot',
'actioncomm' => 'ActionComm',
'website_page' => 'WebsitePage',
'ticket' => 'Ticket',
'knowledgemanagement' => 'KnowledgeRecord',
'order' => 'Commande'
);

/**
Expand All @@ -162,33 +166,35 @@ class Categorie extends CommonObject
* @note Move to const array when PHP 5.6 will be our minimum target
*/
public static $MAP_TYPE_TITLE_AREA = array(
'product' => 'ProductsCategoriesArea',
'customer' => 'CustomersCategoriesArea',
'supplier' => 'SuppliersCategoriesArea',
'member' => 'MembersCategoriesArea',
'contact' => 'ContactsCategoriesArea',
'user' => 'UsersCategoriesArea',
'account' => 'AccountsCategoriesArea', // old for bank account
'bank_account' => 'AccountsCategoriesArea',
'project' => 'ProjectsCategoriesArea',
'warehouse' => 'StocksCategoriesArea',
'actioncomm' => 'ActioncommCategoriesArea',
'website_page' => 'WebsitePageCategoriesArea'
'product' => 'ProductsCategoriesArea',
'customer' => 'CustomersCategoriesArea',
'supplier' => 'SuppliersCategoriesArea',
'member' => 'MembersCategoriesArea',
'contact' => 'ContactsCategoriesArea',
'user' => 'UsersCategoriesArea',
'account' => 'AccountsCategoriesArea', // old for bank account
'bank_account' => 'AccountsCategoriesArea',
'project' => 'ProjectsCategoriesArea',
'warehouse' => 'StocksCategoriesArea',
'actioncomm' => 'ActioncommCategoriesArea',
'website_page' => 'WebsitePageCategoriesArea',
'order' => 'OrderCategoriesArea'
);

/**
* @var array Object table mapping from type string (table llx_...) when value of key does not match table name.
* This array may be completed by external modules with hook "constructCategory"
*/
public $MAP_OBJ_TABLE = array(
'customer' => 'societe',
'supplier' => 'societe',
'member' => 'adherent',
'contact' => 'socpeople',
'account' => 'bank_account', // old for bank account
'project' => 'projet',
'warehouse' => 'entrepot',
'knowledgemanagement' => 'knowledgemanagement_knowledgerecord'
'customer' => 'societe',
'supplier' => 'societe',
'member' => 'adherent',
'contact' => 'socpeople',
'account' => 'bank_account', // old for bank account
'project' => 'projet',
'warehouse' => 'entrepot',
'knowledgemanagement' => 'knowledgemanagement_knowledgerecord',
'order' => 'commande'
);

/**
Expand Down Expand Up @@ -252,6 +258,7 @@ class Categorie extends CommonObject
* @see Categorie::TYPE_ACTIONCOMM
* @see Categorie::TYPE_WEBSITE_PAGE
* @see Categorie::TYPE_TICKET
* @see Categorie::TYPE_ORDER
*/
public $type;

Expand Down
90 changes: 89 additions & 1 deletion htdocs/categories/viewcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@
$tmpobject = new Ticket($db);
$result = $tmpobject->fetch($removeelem);
$elementtype = 'ticket';
} elseif ($type == Categorie::TYPE_ORDER && $user->rights->commande->creer) {
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
$tmpobject = new Commande($db);
$result = $tmpobject->fetch($removeelem);
$elementtype = 'order';
}

$result = $object->del_type($tmpobject, $elementtype);
Expand Down Expand Up @@ -184,7 +189,8 @@
($type == Categorie::TYPE_MEMBER && $user->hasRight('adherent', 'creer')) ||
($type == Categorie::TYPE_CONTACT && $user->hasRight('societe', 'creer')) ||
($type == Categorie::TYPE_USER && $user->hasRight('user', 'user', 'creer')) ||
($type == Categorie::TYPE_ACCOUNT && $user->hasRight('banque', 'configurer'))
($type == Categorie::TYPE_ACCOUNT && $user->hasRight('banque', 'configurer')) ||
($type == Categorie::TYPE_ORDER && $user->hasRight('commande', 'creer'))
)) {
if ($type == Categorie::TYPE_PRODUCT) {
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
Expand Down Expand Up @@ -222,6 +228,10 @@
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$newobject = new Account($db);
$elementtype = 'bank_account';
} elseif ($type == Categorie::TYPE_ORDER) {
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
$newobject = new Commande($db);
$elementtype = 'order';
} else {
dol_print_error(null, "Not supported value of type = ".$type);
}
Expand Down Expand Up @@ -1370,6 +1380,84 @@
}
}

// List of Orders
if ($type == Categorie::TYPE_ORDER) {
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';

$permission = $user->rights->commande->creer;

$objects = $object->getObjectsInCateg($type, 0, $limit, $offset);
if ($objects < 0) {
dol_print_error($db, $object->error, $object->errors);
} else {
// Form to add record into a category
$showclassifyform = 1;
if ($showclassifyform) {
print '<br>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
print '<input type="hidden" name="type" value="'.$typeid.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="action" value="addintocategory">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td>';
print $langs->trans("AddOrderIntoCategory").' &nbsp;';
$form->selectOrder('', 'elemid');
print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
print '</tr>';
print '</table>';
print '</form>';
}

print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
print '<input type="hidden" name="type" value="'.$typeid.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="action" value="list">';

print '<br>';
$param = '&limit='.$limit.'&id='.$id.'&type='.$type; $num = count($objects); $nbtotalofrecords = ''; $newcardbutton = '';

// @phan-suppress-next-line PhanPluginSuspiciousParamOrder
print_barre_liste($langs->trans("Orders"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bill', 0, $newcardbutton, '', $limit);

print "<table class='noborder' width='100%'>\n";
print '<tr class="liste_titre"><td colspan="4">'.$langs->trans("Ref").'</td></tr>'."\n";

if (count($objects) > 0) {
$i = 0;
foreach ($objects as $key => $order) {
$i++;
if ($i > $limit) {
break;
}

print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">';
print $order->getNomUrl(1);
print "</td>\n";
print '<td class="tdtop">'.$order->ref."</td>\n";
// Link to delete from category
print '<td class="right">';
if ($permission) {
print "<a href= '".$_SERVER['PHP_SELF']."?".(empty($socid) ? 'id' : 'socid')."=".$object->id."&amp;type=".$typeid."&amp;removeelem=".$order->id."'>";
print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', false, 0, 0, '', 'paddingleft');
print "</a>";
}
print "</tr>\n";
}
} else {
print '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("ThisCategoryHasNoItems").'</td></tr>';
}
print "</table>\n";

print '</form>'."\n";
}
}

// Note that $action and $object may have been modified by some hooks
$parameters = array('type' => $type, 'id' => $id, 'label' => $label);
$reshook = $hookmanager->executeHooks('addMoreCategoriesList', $parameters, $object, $action);
Expand Down
Loading
Loading