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 + FIX : Expédition in mass action #441

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
4 changes: 3 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ All notable changes to this project will be documented in this file.

# [Unreleased]


- FIX : Compat V20 : Document col missing for title for NC - *16/09/2024* - 3.26.1
- NEW : Add more order to invoice massaction option - *04/09/2024* - 3.26.0
Allow adding list of shipping ref to title block

# Release 3.25 - 24/07/2024

Expand Down
40 changes: 32 additions & 8 deletions class/actions_subtotal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3785,12 +3785,17 @@ function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager) {

if ((typeof id != 'undefined' && id.indexOf('row-') == 0) || $(item).hasClass('liste_titre'))
{
$(item).children('td:last-child').before('<td class="subtotal_nc"></td>');
let tableNCColSelector = 'td';
if($(item).hasClass('liste_titre') && $(item).children('th:last-child').length > 0 && $(item).children('td:last-child').length == 0){
tableNCColSelector = 'th'; // In Dolibarr V20.0 title use th instead of td
}

$(item).children(`${tableNCColSelector}:last-child`).before(`<${tableNCColSelector} class="subtotal_nc"></${tableNCColSelector}>`);

if ($(item).attr('rel') != 'subtotal' && typeof $(item).attr('id') != 'undefined')
{
var idSplit = $(item).attr('id').split('-');
$(item).children('td.subtotal_nc').append($('<input type="checkbox" id="subtotal_nc-'+idSplit[1]+'" class="subtotal_nc_chkbx" data-lineid="'+idSplit[1]+'" value="1" '+(typeof subtotal_TSubNc[idSplit[1]] != 'undefined' && subtotal_TSubNc[idSplit[1]] == 1 ? 'checked="checked"' : '')+' />'));
$(item).children(`${tableNCColSelector}.subtotal_nc`).append($('<input type="checkbox" id="subtotal_nc-'+idSplit[1]+'" class="subtotal_nc_chkbx" data-lineid="'+idSplit[1]+'" value="1" '+(typeof subtotal_TSubNc[idSplit[1]] != 'undefined' && subtotal_TSubNc[idSplit[1]] == 1 ? 'checked="checked"' : '')+' />'));
}
}
else
Expand Down Expand Up @@ -4168,20 +4173,39 @@ public function defineColumnField($parameters, &$pdfDoc, &$action, $hookmanager)
*/
private function _billOrdersAddCheckBoxForTitleBlocks()
{
global $delayedhtmlcontent, $langs;
global $delayedhtmlcontent, $langs, $conf;

ob_start();
$jsConf = array(
'langs'=> array(
'AddTitleBlocFromOrdersToInvoice' => $langs->trans('subtotal_add_title_bloc_from_orderstoinvoice'),
'AddShippingListToTile' => $langs->trans('AddShippingListToTile'),
'SubtotalOptions' => $langs->trans('SubtotalOptions'),
'UseHiddenConfToAutoCheck' => $langs->trans('UseHiddenConfToAutoCheck'),
),
'isModShippingEnable' => !empty($conf->expedition->enabled),
'SUBTOTAL_DEFAULT_CHECK_SHIPPING_LIST_FOR_TITLE_DESC' => getDolGlobalInt('SUBTOTAL_DEFAULT_CHECK_SHIPPING_LIST_FOR_TITLE_DESC')
);
?>
<script type="text/javascript">
$(function() {
var tr = $("<tr><td><?php echo $langs->trans('subtotal_add_title_bloc_from_orderstoinvoice'); ?></td><td><input type='checkbox' value='1' name='subtotal_add_title_bloc_from_orderstoinvoice' checked='checked' /></td></tr>");
var $noteTextArea = $("textarea[name=note]");
let jsConf = <?php print json_encode($jsConf); ?>;

let tr = '<tr><td>'+jsConf.langs.SubtotalOptions+'</td><td>';
tr+= '<label><input type="checkbox" value="1" name="subtotal_add_title_bloc_from_orderstoinvoice" checked="checked" /> '+jsConf.langs.AddTitleBlocFromOrdersToInvoice+'</label>';
if(jsConf.isModShippingEnable){
tr+= '<br/><label><input type="checkbox" value="1" name="subtotal_add_shipping_list_to_title_desc" /> '+jsConf.langs.AddShippingListToTile+' <i class="fa fa-question-circle" title="'+jsConf.langs.UseHiddenConfToAutoCheck+' SUBTOTAL_DEFAULT_CHECK_SHIPPING_LIST_FOR_TITLE_DESC"></label>';
}
tr+= '<td></tr>';

let $noteTextArea = $("textarea[name=note]");
if ($noteTextArea.length === 1) {
$noteTextArea.closest('tr').after(tr);
$noteTextArea.closest($('tr')).after(tr);
return;
}
var $inpCreateBills = $("#validate_invoices");
let $inpCreateBills = $("#validate_invoices");
if ($inpCreateBills.length === 1) {
$inpCreateBills.closest('tr').after(tr);
$inpCreateBills.closest($('tr')).after(tr);
}
});
</script>
Expand Down
9 changes: 5 additions & 4 deletions class/subtotal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ static function showQtyForObjectLine($line, $show_by_default = false) {
* @param string $label
* @param int $qty
* @param int $rang
* @param string $desc
* @return int
*
*/
static function addSubTotalLine(&$object, $label, $qty, $rang=-1) {
static function addSubTotalLine(&$object, $label, $qty, $rang=-1, $desc = '') {

$res = 0;

Expand All @@ -124,7 +125,6 @@ static function addSubTotalLine(&$object, $label, $qty, $rang=-1) {

}
else {
$desc = '';

$TNotElements = array ('invoice_supplier', 'order_supplier');
if ((float) DOL_VERSION < 6 || $qty==50 && !in_array($object->element, $TNotElements)) {
Expand Down Expand Up @@ -269,16 +269,17 @@ public static function addSubtotalMissing(&$object, $level_new_title)
}
}

public static function addTitle(&$object, $label, $level, $rang=-1)
public static function addTitle(&$object, $label, $level, $rang=-1, $desc = '')
/**
* @param CommonObject $object
* @param string $label
* @param int $level
* @param int $rang
* @param string $desc
* @return int
*/
{
return self::addSubTotalLine($object, $label, $level, $rang);
return self::addSubTotalLine($object, $label, $level, $rang, $desc);
}

public static function addTotal(&$object, $label, $level, $rang=-1)
Expand Down
2 changes: 1 addition & 1 deletion core/modules/modSubtotal.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct($db)
// Possible values for version are: 'development', 'experimental' or version


$this->version = '3.25.2';
$this->version = '3.26.1';


// Url to the file with your last numberversion of this module
Expand Down
95 changes: 94 additions & 1 deletion core/triggers/interface_90_modSubtotal_subtotaltrigger.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,16 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
}

$label = str_replace(array('__REFORDER__', '__REFCUSTOMER__'), array($commande->ref, $commande->ref_client), $label);
$desc = '';

if(GETPOST('subtotal_add_shipping_list_to_title_desc', 'int')){
$desc = $this->getShippingList($commande->id);
}


if(!empty($current_fk_commande)) {
$subtotal_skip = true;
TSubtotal::addTitle($facture, $label, 1, $rang);
TSubtotal::addTitle($facture, $label, 1, $rang, $desc);
$rang++;
}
}
Expand Down Expand Up @@ -1010,4 +1016,91 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf

return 0;
}




/**
* List BL ref
* @param int $orderId
* @return string
*/
private function getShippingList($orderId)
{
$refBlList = array();
$refExpList = array();

if(!function_exists('isModEnabled')){
return '';
}

if (!isModEnabled('expedition')) {
return '';
}

// LIST SHIPPING LINKED TO ORDER
$sqlShip = "SELECT fk_target FROM `".MAIN_DB_PREFIX."element_element` WHERE `targettype` = 'shipping' AND sourcetype = 'commande' AND fk_source=".intval($orderId)." ORDER BY `fk_source` ASC";

$resultShip = $this->db->query($sqlShip);
if ($resultShip)
{
while ($shipping = $this->db->fetch_object($resultShip) )
{

if (isModEnabled('delivery')) {

// SELECT LIVRAISON LINKED TO SHIPPING
$sqlBl = "SELECT liv.ref
FROM `".MAIN_DB_PREFIX."element_element` el
JOIN `".MAIN_DB_PREFIX."livraison` liv ON ( el.fk_target = liv.rowid )
WHERE el.`targettype` = 'delivery'
AND el.sourcetype = 'shipping'
AND el.fk_source=".$shipping->fk_target."
AND liv.fk_statut = 1
ORDER BY el.`fk_target` ASC";

$resultDelivery = $this->db->query($sqlBl);
if ($resultDelivery)
{
while ($delivery = $this->db->fetch_object($resultDelivery) )
{
$refBlList[] = $delivery->ref;
}
}

}


// SELECT SHIPPING REF
$sqlExp = "SELECT exp.ref
FROM `" . MAIN_DB_PREFIX . "expedition` exp
WHERE exp.`rowid` =" . $shipping->fk_target;

$resultExp = $this->db->query($sqlExp);
if ($resultExp) {
$exp = $this->db->fetch_object($resultExp);
$refExpList[] = $exp->ref;
}

}
}

global $langs;
$langs->load('subtotal@subtotal');
$refList = array_merge($refBlList,$refExpList);
$output = '';


if(!empty($refExpList)){
$objectLabel = count($refExpList)>1?$langs->trans('LinkedShippings'):$langs->trans('LinkedShipping');
$output.= (!empty($output)?'<br>':'').'<strong>'.$objectLabel.' :</strong> '.implode(', ', $refList) ;
}

if(!empty($refBlList)){
$objectLabel = count($refBlList)>1?$langs->trans('LinkedDeliveries'):$langs->trans('LinkedDelivery');
$output.= (!empty($output)?'<br>':'').'<strong>'.$objectLabel.' :</strong> '.implode(', ', $refList) ;
}

return $output;
}
}
8 changes: 8 additions & 0 deletions langs/en_US/subtotal.lang
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,11 @@ SUBTOTAL_DISABLE_SUMMARY = Disable document "quick summary menu" (appears in lef
Subtotal_HideAll=Hide all lines
Subtotal_ShowAll=Show all lines
DISPLAY_MARGIN_ON_SUBTOTALS=Displays margin on subtotals lines

LinkedShippings = Linked shipping orders
LinkedShipping = Linked shipping order
LinkedDeliveries = Linked delivery notes
LinkedDelivery = Linked delivery note
SubtotalOptions = Subtotal option
AddShippingListToTile = Add the reference list of related delivery or shipping notes to the title block description.
UseHiddenConfToAutoCheck = To pre-set the default, you can activate the settings
8 changes: 8 additions & 0 deletions langs/es_ES/subtotal.lang
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,11 @@ SubtotalExperimentalZone = Configuraciones experimentales u obsoletas
SUBTOTAL_HIDE_OPTIONS_TITLE=Ocultar opciones de título
SUBTOTAL_HIDE_OPTIONS_BREAK_PAGE_BEFORE=Ocultar la opción de salto de página
SUBTOTAL_HIDE_OPTIONS_BUILD_DOC=Ocultar las opciones de generación de documentos

LinkedShippings = Órdenes de envío vinculadas
LinkedShipping = Orden de envío vinculada
LinkedDeliveries = Albaranes vinculados
LinkedDelivery = Albarán vinculado
SubtotalOptions = Opción Subtotal
AddShippingListToTile = Añada la lista de referencia de los albaranes o notas de entrega relacionados a la descripción del bloque del título.
UseHiddenConfToAutoCheck = Para preajustar la configuración por defecto, puede activar la configuración miscelánea
7 changes: 7 additions & 0 deletions langs/fr_FR/subtotal.lang
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,11 @@ DISPLAY_MARGIN_ON_SUBTOTALS=Afficher les marges sur les lignes de sous-totaux
HideSubtitleOnFold = Cacher les lignes de titre et sous total enfant
KeepSubtitleDisplayOnFold = Afficher les lignes de titre et sous total enfant
SUBTOTAL_BLOC_FOLD_MODE = Comportement à adopter lorsque l'on cache un bloc de titre
LinkedShippings = Bons d'expéditions liés
LinkedShipping = Bon d'expédition lié
LinkedDeliveries = Bons de livraison liés
LinkedDelivery = Bon de livraison lié
SubtotalOptions = Option subtotal
AddShippingListToTile = Ajouter la liste des référence des bons d'expédition ou livraison liés dans la description du block titre
UseHiddenConfToAutoCheck = Pour précocher par défaut vous pouvez activer la configuration divers
ErrorClassXNotExists = ERREUR : la classe php %s n'est pas chargée