Debug v20 - Fix getMultidirOutput

This commit is contained in:
Laurent Destailleur
2024-06-17 13:06:43 +02:00
parent 61bf5b0f96
commit d636114540
5 changed files with 72 additions and 34 deletions

View File

@@ -513,7 +513,7 @@ if (empty($reshook)) {
} }
} }
// others mass actions // mass actions on lettering
if (!$error && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->hasRight('accounting', 'mouvements', 'creer')) { if (!$error && getDolGlobalInt('ACCOUNTING_ENABLE_LETTERING') && $user->hasRight('accounting', 'mouvements', 'creer')) {
if ($massaction == 'letteringauto') { if ($massaction == 'letteringauto') {
$lettering = new Lettering($db); $lettering = new Lettering($db);
@@ -1135,9 +1135,15 @@ while ($i < min($num, $limit)) {
// Journal code // Journal code
if (!empty($arrayfields['t.code_journal']['checked'])) { if (!empty($arrayfields['t.code_journal']['checked'])) {
$accountingjournal = new AccountingJournal($db); if (empty($conf->cache['accountingjournal'][$line->code_journal])) {
$result = $accountingjournal->fetch('', $line->code_journal); $accountingjournal = new AccountingJournal($db);
$journaltoshow = (($result > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal); $accountingjournal->fetch(0, $line->code_journal);
$conf->cache['accountingjournal'][$line->code_journal] = $accountingjournal;
} else {
$accountingjournal = $conf->cache['accountingjournal'][$line->code_journal];
}
$journaltoshow = (($accountingjournal->id > 0) ? $accountingjournal->getNomUrl(0, 0, 0, '', 0) : $line->code_journal);
print '<td class="center tdoverflowmax150">'.$journaltoshow.'</td>'; print '<td class="center tdoverflowmax150">'.$journaltoshow.'</td>';
if (!$i) { if (!$i) {
$totalarray['nbfield']++; $totalarray['nbfield']++;
@@ -1176,9 +1182,18 @@ while ($i < min($num, $limit)) {
$modulepart = 'invoice_supplier'; $modulepart = 'invoice_supplier';
$filename = dol_sanitizeFileName($line->doc_ref); $filename = dol_sanitizeFileName($line->doc_ref);
$filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
$subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref); //$filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($line->fk_doc, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
$documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir); //$subdir = get_exdir($objectstatic->id, 2, 0, 0, $objectstatic, $modulepart).dol_sanitizeFileName($line->doc_ref);
$filedir = getMultidirOutput($objectstatic, '', 1).dol_sanitizeFileName($line->doc_ref);
$subdir = getMultidirOutput($objectstatic, '', 1, 'outputrel').dol_sanitizeFileName($line->doc_ref);
//var_dump($filedir); var_dump($subdir);
if ($objectstatic->id > 0) {
$documentlink = $formfile->getDocumentsLink($objectstatic->element, $subdir, $filedir);
} else {
$documentlink = $line->doc_ref;
}
} elseif ($line->doc_type == 'expense_report') { } elseif ($line->doc_type == 'expense_report') {
$langs->loadLangs(array('trips')); $langs->loadLangs(array('trips'));
@@ -1201,6 +1216,7 @@ while ($i < min($num, $limit)) {
$labeltoshow = ''; $labeltoshow = '';
$labeltoshowalt = ''; $labeltoshowalt = '';
$classforlabel = '';
if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') { if ($line->doc_type == 'customer_invoice' || $line->doc_type == 'supplier_invoice' || $line->doc_type == 'expense_report') {
$labeltoshow .= $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1); $labeltoshow .= $objectstatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
$labeltoshow .= $documentlink; $labeltoshow .= $documentlink;
@@ -1214,9 +1230,10 @@ while ($i < min($num, $limit)) {
} else { } else {
$labeltoshow .= $line->doc_ref; $labeltoshow .= $line->doc_ref;
$labeltoshowalt .= $line->doc_ref; $labeltoshowalt .= $line->doc_ref;
$classforlabel = 'tdoverflowmax250';
} }
print '<td class="nowraponall tdoverflowmax250" title="'.dol_escape_htmltag($labeltoshowalt).'">'; print '<td class="nowraponall'.($classforlabel ? ' '.$classforlabel : '').'" title="'.dol_escape_htmltag($labeltoshowalt).'">';
print $labeltoshow; print $labeltoshow;
print "</td>\n"; print "</td>\n";
if (!$i) { if (!$i) {

View File

@@ -445,8 +445,8 @@ if ($result) {
} }
$arrayofmassactions = array( $arrayofmassactions = array(
'set_default_account' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount"),
'ventil' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Ventilate") 'ventil' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Ventilate")
,'set_default_account' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount")
//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
); );

View File

@@ -418,12 +418,11 @@ if ($action == 'writebookkeeping' && !$error) {
$companystatic = new Societe($db); $companystatic = new Societe($db);
$invoicestatic = new Facture($db); $invoicestatic = new Facture($db);
$accountingaccountcustomer = new AccountingAccount($db);
$accountingaccountcustomer = new AccountingAccount($db);
$accountingaccountcustomer->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true); $accountingaccountcustomer->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER'), true);
$accountingaccountcustomerwarranty = new AccountingAccount($db); $accountingaccountcustomerwarranty = new AccountingAccount($db);
$accountingaccountcustomerwarranty->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'), true); $accountingaccountcustomerwarranty->fetch(null, getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY'), true);
foreach ($tabfac as $key => $val) { // Loop on each invoice foreach ($tabfac as $key => $val) { // Loop on each invoice

View File

@@ -452,8 +452,8 @@ if ($result) {
} }
$arrayofmassactions = array( $arrayofmassactions = array(
'ventil' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Ventilate"), 'set_default_account' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount"),
'set_default_account' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ConfirmPreselectAccount") 'ventil' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Ventilate")
//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
//'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
); );

View File

@@ -126,8 +126,8 @@ if (!function_exists('str_contains')) {
* @param CommonObject $object Dolibarr common object * @param CommonObject $object Dolibarr common object
* @param string $module Override object element, for example to use 'mycompany' instead of 'societe' * @param string $module Override object element, for example to use 'mycompany' instead of 'societe'
* @param int $forobject Return the more complete path for the given object instead of for the module only. * @param int $forobject Return the more complete path for the given object instead of for the module only.
* @param string $mode 'output' or 'temp' or 'version' * @param string $mode 'output' (full main dir) or 'outputrel' (relative dir) or 'temp' (for temporary files) or 'version' (dir for archived files)
* @return string|null The path of the relative directory of the module * @return string|null The path of the relative directory of the module, ending with /
* @since Dolibarr V18 * @since Dolibarr V18
*/ */
function getMultidirOutput($object, $module = '', $forobject = 0, $mode = 'output') function getMultidirOutput($object, $module = '', $forobject = 0, $mode = 'output')
@@ -144,14 +144,21 @@ function getMultidirOutput($object, $module = '', $forobject = 0, $mode = 'outpu
// Special case for backward compatibility // Special case for backward compatibility
if ($module == 'fichinter') { if ($module == 'fichinter') {
$module = 'ficheinter'; $module = 'ficheinter';
} elseif ($module == 'invoice_supplier') {
$module = 'supplier_invoice';
} elseif ($module == 'order_supplier') {
$module = 'supplier_order';
} }
// Get the relative path of directory // Get the relative path of directory
if ($mode == 'output' || $mode == 'version') { if ($mode == 'output' || $mode == 'outputrel' || $mode == 'version') {
if (isset($conf->$module) && property_exists($conf->$module, 'multidir_output')) { if (isset($conf->$module) && property_exists($conf->$module, 'multidir_output')) {
$s = $conf->$module->multidir_output[(empty($object->entity) ? $conf->entity : $object->entity)]; $s = '';
if ($mode != 'outputrel') {
$s = $conf->$module->multidir_output[(empty($object->entity) ? $conf->entity : $object->entity)];
}
if ($forobject && $object->id > 0) { if ($forobject && $object->id > 0) {
$s .= '/'.get_exdir(0, 0, 0, 0, $object); $s .= ($mode != 'outputrel' ? '/' : '').get_exdir(0, 0, 0, 0, $object);
} }
return $s; return $s;
} else { } else {
@@ -7568,34 +7575,49 @@ function yn($yesno, $case = 1, $color = 0)
/** /**
* Return a path to have a the directory according to object where files are stored. * Return a path to have a the directory according to object where files are stored.
* New usage: $conf->module->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, '').'/' * This function is called by getMultidirOutput
* or: $conf->module->dir_output.'/'.get_exdir(0, 0, 0, 0, $object, '') if multidir_output not defined. * New usage: $conf->module->multidir_output[$object->entity].'/'.get_exdir(0, 0, 0, 1, $object, '').'/'
* Example out with new usage: $object is invoice -> 'INYYMM-ABCD' * or: $conf->module->dir_output.'/'.get_exdir(0, 0, 0, 0, $object, '')
* Example out with old usage: '015' with level 3->"0/1/5/", '015' with level 1->"5/", 'ABC-1' with level 3 ->"0/0/1/"
* *
* @param string|int $num Id of object (deprecated, $object will be used in future) * Example of output with new usage: $object is invoice -> 'INYYMM-ABCD'
* @param int $level Level of subdirs to return (1, 2 or 3 levels). (deprecated, global option will be used in future) * Example of output with old usage: '015' with level 3->"0/1/5/", '015' with level 1->"5/", 'ABC-1' with level 3 ->"0/0/1/"
* @param int $alpha 0=Keep number only to forge path, 1=Use alpha part after the - (By default, use 0). (deprecated, global option will be used in future) *
* @param int $withoutslash 0=With slash at end (except if '/', we return ''), 1=without slash at end * @param string|int $num Id of object (deprecated, $object->id will be used in future)
* @param ?CommonObject $object Object to use to get ref to forge the path. * @param int $level Level of subdirs to return (1, 2 or 3 levels). (deprecated, global setup will be used in future)
* @param string $modulepart Type of object ('invoice_supplier, 'donation', 'invoice', ...'). Use '' for autodetect from $object. * @param int $alpha 0=Keep number only to forge path, 1=Use alpha part after the - (By default, use 0). (deprecated, global option will be used in future)
* @return string Dir to use ending. Example '' or '1/' or '1/2/' * @param int $withoutslash 0=With slash at end (except if '/', we return ''), 1=without slash at end
* @param ?CommonObject $object Object to use to get ref to forge the path.
* @param string $modulepart Type of object ('invoice_supplier, 'donation', 'invoice', ...'). Use '' for autodetect from $object.
* @return string Dir to use ending. Example '' or '1/' or '1/2/'
* @see getMultidirOutput() * @see getMultidirOutput()
*/ */
function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart = '') function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart = '')
{ {
if (empty($modulepart) && !empty($object->module)) { if (empty($modulepart) && is_object($object)) {
$modulepart = $object->module; if (!empty($object->module)) {
$modulepart = $object->module;
} elseif (!empty($object->element)) {
$modulepart = $object->element;
}
} }
$path = ''; $path = '';
$arrayforoldpath = array('cheque', 'category', 'holiday', 'supplier_invoice', 'invoice_supplier', 'mailing', 'supplier_payment'); // Define $arrayforoldpath that is module path using a hierarchy on more than 1 level.
$arrayforoldpath = array('cheque' => 2, 'category' => 2, 'holiday' => 2, 'supplier_invoice' => 2, 'invoice_supplier' => 2, 'mailing' => 2, 'supplier_payment' => 2);
if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) { if (getDolGlobalInt('PRODUCT_USE_OLD_PATH_FOR_PHOTO')) {
$arrayforoldpath[] = 'product'; $arrayforoldpath['product'] = 2;
} }
if (!empty($level) && in_array($modulepart, $arrayforoldpath)) {
if (empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
$level = $arrayforoldpath[$modulepart];
}
if (!empty($level) && array_key_exists($modulepart, $arrayforoldpath)) {
// This part should be removed once all code is using "get_exdir" to forge path, with parameter $object and $modulepart provided. // This part should be removed once all code is using "get_exdir" to forge path, with parameter $object and $modulepart provided.
if (empty($num) && is_object($object)) {
$num = $object->id;
}
if (empty($alpha)) { if (empty($alpha)) {
$num = preg_replace('/([^0-9])/i', '', $num); $num = preg_replace('/([^0-9])/i', '', $num);
} else { } else {