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 invoice tags #33250

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
36 changes: 22 additions & 14 deletions htdocs/categories/class/categorie.class.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2005 Davoleau Brice <brice.davoleau@gmail.com>
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2013-2016 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013-2018 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2016-2024 Charlene Benke <charlene@patas-monkey.com>
* Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2023-2024 Benjamin Falière <benjamin.faliere@altairis.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
/* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
* Copyright (C) 2005 Davoleau Brice <brice.davoleau@gmail.com>
* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2013-2016 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013-2018 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2016-2024 Charlene Benke <charlene@patas-monkey.com>
* Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2022-2023 Solution Libre SAS <contact@solution-libre.fr>
* Copyright (C) 2023-2024 Benjamin Falière <benjamin.faliere@altairis.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -64,6 +65,7 @@ class Categorie extends CommonObject
const TYPE_KNOWLEDGEMANAGEMENT = 'knowledgemanagement';
const TYPE_FICHINTER = 'fichinter';
const TYPE_ORDER = 'order';
const TYPE_INVOICE = 'invoice';

/**
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
Expand Down Expand Up @@ -91,6 +93,7 @@ class Categorie extends CommonObject
'knowledgemanagement' => 13,
'fichinter' => 14,
'order' => 16,
'invoice' => 17,
);

/**
Expand All @@ -115,6 +118,7 @@ class Categorie extends CommonObject
13 => 'knowledgemanagement',
14 => 'fichinter',
16 => 'order',
17 => 'invoice',
);

/**
Expand Down Expand Up @@ -162,6 +166,7 @@ class Categorie extends CommonObject
'knowledgemanagement' => 'KnowledgeRecord',
'fichinter' => 'Fichinter',
'order' => 'Commande',
'invoice' => 'Facture'
);

/**
Expand All @@ -186,6 +191,7 @@ class Categorie extends CommonObject
'knowledgemanagement' => 'KnowledgemanagementsCategoriesArea',
'fichinter' => 'FichintersCategoriesArea',
'order' => 'OrderCategoriesArea',
'invoice' => 'InvoiceCategoriesArea'
);

/**
Expand All @@ -203,6 +209,7 @@ class Categorie extends CommonObject
'knowledgemanagement' => 'knowledgemanagement_knowledgerecord',
'fichinter' => 'fichinter',
'order' => 'commande',
'invoice' => 'facture'
);

/**
Expand Down Expand Up @@ -268,6 +275,7 @@ class Categorie extends CommonObject
* @see Categorie::TYPE_TICKET
* @see Categorie::TYPE_FICHINTER
* @see Categorie::TYPE_ORDER
* @see Categorie::TYPE_INVOICE
*/
public $type;

Expand Down
88 changes: 88 additions & 0 deletions htdocs/categories/viewcat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
* Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
* Copyright (C) 2022-2023 Solution Libre SAS <contact@solution-libre.fr>
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
Expand Down Expand Up @@ -176,6 +177,11 @@
$tmpobject = new Commande($db);
$result = $tmpobject->fetch($removeelem);
$elementtype = 'order';
} elseif ($type == Categorie::TYPE_INVOICE && $user->hasRight('facture', 'creer')) {
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$tmpobject = new Facture($db);
$result = $tmpobject->fetch($removeelem);
$elementtype = 'invoice';
} else {
dol_print_error(null, "Not supported value of type = ".$type);
}
Expand Down Expand Up @@ -247,6 +253,10 @@
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
$newobject = new Commande($db);
$elementtype = 'order';
} elseif ($type == Categorie::TYPE_INVOICE && $user->hasRight('facture', 'creer')) {
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
$newobject = new Facture($db);
$elementtype = 'order';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you mean
'invoice'
here ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. It's fixed

} else {
dol_print_error(null, "Not supported value of type = ".$type);
}
Expand Down Expand Up @@ -1498,6 +1508,84 @@
}
}

// List of Invoices
if ($type == Categorie::TYPE_INVOICE) {
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';

$permission = $user->rights->facture->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 = $user->hasRight('facture', 'write');
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("AddInvoiceIntoCategory").' &nbsp;';
$form->selectInvoice(-1, '', 'elemid', 24, 0, '1', 0, 0, 0, 'maxwidth500', '', '');
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("BillsCustomers"), $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 => $invoice) {
$i++;
if ($i > $limit) {
break;
}

print "\t".'<tr class="oddeven">'."\n";
print '<td class="nowrap" valign="top">';
print $invoice->getNomUrl(1);
print "</td>\n";
print '<td class="tdtop">'.$invoice->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=".$invoice->id."'>";
print $langs->trans("DeleteFromCat");
print img_picto($langs->trans("DeleteFromCat"), 'unlink', '', 0, 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
94 changes: 73 additions & 21 deletions htdocs/compta/facture/card.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012-2023 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012-2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2013 Jean-Francois FERRY <jfefe@aternatik.fr>
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2014-2024 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2023 Nick Fragoulis
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
* Copyright (C) 2005-2015 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2010-2015 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012-2023 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2012-2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2012-2014 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2013 Jean-Francois FERRY <jfefe@aternatik.fr>
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014-2024 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2015-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2018-2025 Frédéric France <frederic.france@free.fr>
* Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2022-2023 Solution Libre SAS <contact@solution-libre.fr>
* Copyright (C) 2023 Nick Fragoulis
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -42,6 +42,7 @@

// Libraries
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
Expand Down Expand Up @@ -600,6 +601,8 @@
}
} elseif ($action == 'set_incoterms' && isModEnabled('incoterm') && $usercancreate) { // Set incoterm
$result = $object->setIncoterms(GETPOSTINT('incoterm_id'), GETPOST('location_incoterms'));
} elseif ($action == 'settags' && isModEnabled('category')) { // Set tags
$result = $object->setCategories(GETPOST('categories', 'array'));
} elseif ($action == 'setbankaccount' && $usercancreate) { // bank account
$result = $object->setBankAccount(GETPOSTINT('fk_account'));
} elseif ($action == 'setremisepercent' && $usercancreate) {
Expand Down Expand Up @@ -2109,6 +2112,13 @@

// End of object creation, we show it
if ($id > 0 && !$error) {
if (isModEnabled('category')) {
$categories = GETPOST('categories', 'array');
if (method_exists($object, 'setCategories')) {
$object->setCategories($categories);
}
}

$db->commit();

// Define output language
Expand Down Expand Up @@ -4096,6 +4106,16 @@ function setRadioForTypeOfInvoice() {
print '</td></tr>';
}

// Category
if (isModEnabled('category')) {
// Categories
print '<tr><td>'.$langs->trans("Categories").'</td><td colspan="3">';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_INVOICE, '', 'parent', 64, 0, 1);
$arrayselected = GETPOST('categories', 'array');
print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, '0');
print "</td></tr>";
}

// Other attributes
$parameters = array('objectsrc' => !empty($objectsrc) ? $objectsrc : 0, 'colspan' => ' colspan="2"', 'cols' => '2', 'socid' => $socid);
$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
Expand Down Expand Up @@ -4975,7 +4995,39 @@ function setRadioForTypeOfInvoice() {
print '</td></tr>';
}


// Categories
if (isModEnabled('category')) {
print '<tr><td>';
print '<table class="nobordernopadding centpercent"><tr><td>';
print $langs->trans("Categories");
print '<td><td class="right">';
if ($usercancreate) {
print '<a class="editfielda" href="'.DOL_URL_ROOT.'/compta/facture/card.php?facid='.$object->id.'&action=edittags&token='.newToken().'">'.img_edit().'</a>';
} else {
print '&nbsp;';
}
print '</td></tr></table>';
print '</td>';
print '<td>';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_INVOICE, '', 'parent', 64, 0, 1);
if ($action == 'edittags') {
print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'">';
print '<input type="hidden" name="action" value="settags">';
print '<input type="hidden" name="token" value="'.newToken().'">';
$c = new Categorie($db);
$cats = $c->containing($object->id, Categorie::TYPE_INVOICE);
$arrayselected=[];
foreach ($cats as $cat) {
$arrayselected[] = $cat->id;
}
print img_picto('', 'category').$form->multiselectarray('categories', $cate_arbo, $arrayselected, 0, 0, 'quatrevingtpercent widthcentpercentminusx', 0, '0');
print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
print '</form>';
} else {
print $form->showCategories($object->id, Categorie::TYPE_INVOICE, 1);
}
print "</td></tr>";
}

$displayWarranty = false;

Expand Down
31 changes: 30 additions & 1 deletion htdocs/compta/facture/class/facture.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
* Copyright (C) 2013 Cedric Gross <c.gross@kreiz-it.fr>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2016-2025 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2018-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
* Copyright (C) 2018-2025 Alexandre Spangaro <alexandre@inovea-conseil.com>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
* Copyright (C) 2022 Sylvain Legrand <contact@infras.fr>
* Copyright (C) 2022-2023 Solution Libre SAS <contact@solution-libre.fr>
* Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
* Copyright (C) 2023 Nick Fragoulis
* Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
Expand Down Expand Up @@ -2821,6 +2822,18 @@ public function delete($user, $notrigger = 0, $idwarehouse = -1)
// End call triggers
}

// Remove linked categories.
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_invoice";
$sql .= " WHERE fk_invoice = ".((int) $this->id);

$result = $this->db->query($sql);
if (!$result) {
$error++;
$this->errors[] = $this->db->lasterror();
}
}

// Removed extrafields
if (!$error) {
$result = $this->deleteExtraFields();
Expand Down Expand Up @@ -4687,6 +4700,22 @@ public function set_remise_absolue($user, $remise, $notrigger = 0)
}
*/

/**
* Sets object to given categories.
*
* Adds it to non existing supplied categories.
* Existing categories are left untouch.
*
* @param int[]|int $categories Category or categories IDs
*
* @return int Return integer <0 if KO, >0 if OK
*/
public function setCategories($categories)
{
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
return parent::setCategoriesCommon($categories, Categorie::TYPE_INVOICE);
}

/**
* Return next reference of customer invoice not already used (or last reference)
* according to numbering module defined into constant FACTURE_ADDON
Expand Down
Loading
Loading