dolibarr/htdocs/core/lib/sendings.lib.php

578 lines
20 KiB
PHP
Raw Permalink Normal View History

<?php
2012-10-31 08:50:20 +00:00
/* Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
2018-10-27 12:43:12 +00:00
* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 19:55:30 +00:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
2011-10-24 10:59:44 +00:00
* \file htdocs/core/lib/sendings.lib.php
* \ingroup expedition
* \brief Library for expedition module
*/
require_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php';
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
2012-02-04 09:48:47 +00:00
/**
* Prepare array with list of tabs
*
* @param Expedition $object Object related to tabs
* @return array<array{0:string,1:string,2:string}> Array of tabs to show
2012-02-04 09:48:47 +00:00
*/
function shipping_prepare_head($object)
{
2016-10-24 18:52:21 +00:00
global $db, $langs, $conf, $user;
2010-05-08 16:45:47 +00:00
2018-09-11 15:30:43 +00:00
// Load translation files required by the page
$langs->loadLangs(array("sendings"));
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT . "/expedition/card.php?id=" . $object->id;
$head[$h][1] = $langs->trans("SendingCard");
$head[$h][2] = 'shipping';
$h++;
if ($object->status == Expedition::STATUS_DRAFT) {
$head[$h][0] = DOL_URL_ROOT . "/expedition/dispatch.php?id=" . $object->id;
2023-05-22 13:59:48 +00:00
$head[$h][1] = $langs->trans("ShipmentDistribution");
2023-05-09 09:04:53 +00:00
$head[$h][2] = 'dispatch';
$h++;
}
2023-10-15 13:32:35 +00:00
if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY') && $user->hasRight('expedition', 'delivery', 'lire')) {
2012-07-02 17:30:37 +00:00
// delivery link
$object->fetchObjectLinked($object->id, $object->element);
if (isset($object->linkedObjectsIds['delivery']) && is_array($object->linkedObjectsIds['delivery']) && count($object->linkedObjectsIds['delivery']) > 0) { // If there is a delivery
2024-03-12 20:59:29 +00:00
// Take first element of array
$tmp = reset($object->linkedObjectsIds['delivery']);
$head[$h][0] = DOL_URL_ROOT . "/delivery/card.php?id=" . ((int) $tmp);
2012-07-02 17:30:37 +00:00
$head[$h][1] = $langs->trans("DeliveryCard");
$head[$h][2] = 'delivery';
2012-07-02 15:07:37 +00:00
$h++;
}
}
2023-11-27 10:39:32 +00:00
if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
$objectsrc = $object;
if (!getDolGlobalInt('SHIPPING_USE_ITS_OWN_CONTACTS') && $object->origin_type == 'commande' && $object->origin_id > 0) {
$objectsrc = new Commande($db);
$objectsrc->fetch($object->origin_id);
}
$nbContact = count($objectsrc->liste_contact(-1, 'internal')) + count($objectsrc->liste_contact(-1, 'external'));
$head[$h][0] = DOL_URL_ROOT . "/expedition/contact.php?id=" . ((int) $object->id);
$head[$h][1] = $langs->trans("ContactsAddresses");
2021-02-23 21:03:23 +00:00
if ($nbContact > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbContact . '</span>';
2021-02-23 21:03:23 +00:00
}
$head[$h][2] = 'contact';
$h++;
2016-06-06 10:29:15 +00:00
}
2025-08-14 13:26:13 +00:00
// Files
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
$upload_dir = $conf->expedition->dir_output . "/sending/" . dol_sanitizeFileName($object->ref);
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
$nbLinks = Link::count($db, $object->element, $object->id);
$head[$h][0] = DOL_URL_ROOT . '/expedition/document.php?id=' . $object->id;
$head[$h][1] = $langs->trans('Documents');
2021-02-23 21:03:23 +00:00
if (($nbFiles + $nbLinks) > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($nbFiles + $nbLinks) . '</span>';
2021-02-23 21:03:23 +00:00
}
$head[$h][2] = 'documents';
$h++;
2025-08-14 13:26:13 +00:00
// Notes
$nbNote = 0;
2021-02-23 21:03:23 +00:00
if (!empty($object->note_private)) {
$nbNote++;
}
if (!empty($object->note_public)) {
$nbNote++;
}
$head[$h][0] = DOL_URL_ROOT . "/expedition/note.php?id=" . $object->id;
2013-04-09 15:18:07 +00:00
$head[$h][1] = $langs->trans("Notes");
2021-02-23 21:03:23 +00:00
if ($nbNote > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>';
2021-02-23 21:03:23 +00:00
}
2013-04-09 15:18:07 +00:00
$head[$h][2] = 'note';
$h++;
2025-08-14 13:26:13 +00:00
// Events
$head[$h][0] = DOL_URL_ROOT . '/expedition/agenda.php?id=' . $object->id;
$head[$h][1] = $langs->trans("Events");
if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
$nbEvent = 0;
// Enable caching of thirdparty count actioncomm
require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
$cachekey = 'count_events_expedition_' . $object->id;
$dataretrieved = dol_getcache($cachekey);
if (!is_null($dataretrieved)) {
$nbEvent = $dataretrieved;
} else {
$sql = "SELECT COUNT(id) as nb";
$sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm";
$sql .= " WHERE fk_element = " . ((int) $object->id);
$sql .= " AND elementtype = 'shipping'";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
$nbEvent = $obj->nb;
} else {
dol_syslog('Failed to count actioncomm ' . $db->lasterror(), LOG_ERR);
}
dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
}
$head[$h][1] .= '/';
$head[$h][1] .= $langs->trans("Agenda");
if ($nbEvent > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbEvent . '</span>';
}
}
$head[$h][2] = 'agenda';
$h++;
2012-02-04 09:48:47 +00:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery');
complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery', 'remove');
2012-02-04 09:48:47 +00:00
return $head;
}
2011-01-24 23:35:21 +00:00
2012-02-04 09:48:47 +00:00
/**
* Prepare array with list of tabs
*
* @param Delivery $object Object related to tabs
* @return array<array{0:string,1:string,2:string}> Array of tabs to show
2012-02-04 09:48:47 +00:00
*/
function delivery_prepare_head($object)
{
2020-01-28 01:21:39 +00:00
global $langs, $db, $conf, $user;
2010-05-08 16:45:47 +00:00
2018-09-11 15:30:43 +00:00
// Load translation files required by the page
$langs->loadLangs(array("sendings"));
$h = 0;
$head = array();
2023-10-15 13:32:35 +00:00
if (getDolGlobalInt('MAIN_SUBMODULE_EXPEDITION') && $user->hasRight('expedition', 'lire')) {
$head[$h][0] = DOL_URL_ROOT . "/expedition/card.php?id=" . $object->origin_id;
$head[$h][1] = $langs->trans("SendingCard");
$head[$h][2] = 'shipping';
$h++;
}
$head[$h][0] = DOL_URL_ROOT . "/delivery/card.php?id=" . $object->id;
$head[$h][1] = $langs->trans("DeliveryCard");
$head[$h][2] = 'delivery';
$h++;
2020-01-28 01:21:39 +00:00
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
// complete_head_from_modules use $object->id for this link so we temporary change it
$savObjectId = $object->id;
// Get parent object
$tmpobject = null;
if ($object->origin_type) {
2020-01-28 01:21:39 +00:00
$tmpobject = new Expedition($db);
$tmpobject->fetch($object->origin_id);
} else {
$tmpobject = $object;
}
2023-11-27 10:39:32 +00:00
if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
2020-10-25 16:19:15 +00:00
$objectsrc = $tmpobject;
if ($tmpobject->origin_type == 'commande' && $tmpobject->origin_id > 0) {
2020-10-25 16:19:15 +00:00
$objectsrc = new Commande($db);
$objectsrc->fetch($tmpobject->origin_id);
}
$nbContact = count($objectsrc->liste_contact(-1, 'internal')) + count($objectsrc->liste_contact(-1, 'external'));
$head[$h][0] = DOL_URL_ROOT . "/expedition/contact.php?id=" . $tmpobject->id;
2020-10-25 16:19:15 +00:00
$head[$h][1] = $langs->trans("ContactsAddresses");
2021-02-23 21:03:23 +00:00
if ($nbContact > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbContact . '</span>';
2021-02-23 21:03:23 +00:00
}
2020-10-25 16:19:15 +00:00
$head[$h][2] = 'contact';
$h++;
}
2020-01-28 01:21:39 +00:00
2025-08-14 13:26:13 +00:00
// Files
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/link.class.php';
$upload_dir = $conf->expedition->dir_output . "/sending/" . dol_sanitizeFileName($tmpobject->ref);
2020-01-28 01:21:39 +00:00
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
$nbLinks = Link::count($db, $tmpobject->element, $tmpobject->id);
$head[$h][0] = DOL_URL_ROOT . '/expedition/document.php?id=' . $tmpobject->id;
2020-01-28 01:21:39 +00:00
$head[$h][1] = $langs->trans('Documents');
2021-02-23 21:03:23 +00:00
if (($nbFiles + $nbLinks) > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . ($nbFiles + $nbLinks) . '</span>';
2021-02-23 21:03:23 +00:00
}
2020-01-28 01:21:39 +00:00
$head[$h][2] = 'documents';
$h++;
2025-08-14 13:26:13 +00:00
// Notes
2020-01-28 01:21:39 +00:00
$nbNote = 0;
2021-02-23 21:03:23 +00:00
if (!empty($tmpobject->note_private)) {
$nbNote++;
}
if (!empty($tmpobject->note_public)) {
$nbNote++;
}
$head[$h][0] = DOL_URL_ROOT . "/expedition/note.php?id=" . $tmpobject->id;
$head[$h][1] = $langs->trans("Notes");
2021-02-23 21:03:23 +00:00
if ($nbNote > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbNote . '</span>';
2021-02-23 21:03:23 +00:00
}
$head[$h][2] = 'note';
$h++;
2025-08-14 13:26:13 +00:00
// Events
$head[$h][0] = DOL_URL_ROOT . '/expedition/agenda.php?id=' . $tmpobject->id;
$head[$h][1] = $langs->trans("Events");
if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
$nbEvent = 0;
// Enable caching of thirdparty count actioncomm
require_once DOL_DOCUMENT_ROOT . '/core/lib/memory.lib.php';
$cachekey = 'count_events_expedition_' . $tmpobject->id;
$dataretrieved = dol_getcache($cachekey);
if (!is_null($dataretrieved)) {
$nbEvent = $dataretrieved;
} else {
$sql = "SELECT COUNT(id) as nb";
$sql .= " FROM " . MAIN_DB_PREFIX . "actioncomm";
$sql .= " WHERE fk_element = " . ((int) $tmpobject->id);
$sql .= " AND elementtype = 'shipping'";
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
$nbEvent = $obj->nb;
} else {
dol_syslog('Failed to count actioncomm ' . $db->lasterror(), LOG_ERR);
}
dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
}
$head[$h][1] .= '/';
$head[$h][1] .= $langs->trans("Agenda");
if ($nbEvent > 0) {
$head[$h][1] .= '<span class="badge marginleftonlyshort">' . $nbEvent . '</span>';
}
}
$head[$h][2] = 'agenda';
$h++;
2020-01-28 01:21:39 +00:00
$object->id = $tmpobject->id;
complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery');
complete_head_from_modules($conf, $langs, $object, $head, $h, 'delivery', 'remove');
2020-01-28 01:21:39 +00:00
$object->id = $savObjectId;
2012-02-04 09:48:47 +00:00
return $head;
}
/**
* List sendings and receive receipts
*
2012-02-04 13:39:47 +00:00
* @param string $origin Origin ('commande', ...)
2011-09-12 17:08:02 +00:00
* @param int $origin_id Origin id
2023-12-02 15:46:37 +00:00
* @param string $filter Filter (Do not use a string from a user input)
2023-12-01 18:51:32 +00:00
* @return int Return integer <0 if KO, >0 if OK
*/
function show_list_sending_receive($origin, $origin_id, $filter = '')
{
global $db, $conf, $langs;
global $form;
$product_static = new Product($db);
$expedition = new Expedition($db);
$warehousestatic = new Entrepot($db);
NEW Subtotal module (#33502) * Changes to follow mvc logic * Reworked admin page and form to add lines * Reworked adding line logic * Adding options when editing subtotal lines * Fix translations * Fixed errors/displays and started pdf * Color for subtotals pdf lines * FIX display of subtotal totht * Added pdf azur for propal * Fix duplicate translation * Added subtotal support for facture pdf * Added subtotal support for commande pdf * Improve UI/translations * Restored old pdf * Info to warn user for unsupported pdf * Added title lines VAT rate and discount support This is meant for future feature wich is block mass changing vat rate and discount percentage * Working on block apply vat and discount * Added buttons for block actions * Handle editing vat and discount for subtotal lines * Editing vat and discount for subtotal lines bloc working * Added possibility to move by block * Updated adding and updating a subtotal line * Improved vat and discount block update * Improvement for block vat/discount and line edition Editing a title line edits the corresponding subtotal line * Improvement for moving by block * Bad tile or st line placement managing * Improved bad title or st line placement managing * Adding subtotal line improved Adding a subtotal line adds it right under its corresponding title * Improved deleting subtotal line Added possibility to choose if you want to delete the corresponding subtotal line when deleting a title line * Preventing too high level titles to be created * Create and update line errors managing * Improved bad title or st line placement managing * Improved st line creation * improve headers * fix bad block placement managing * fix adding st line not working if duplicates titles * fix translations * Fix block update * FIX special chars bug If special char like " ' " was used in title it could be converted to special char entity. * Prepare for pdf options Pdf options like page break befor title should be shown as a picto if activated on a subtotal line on a document * Added option managing * Improved subtotal options and PDF integration * Code refactor * Action name/Error managment/PDF refreshing When adding or updating a subtotal line * Reformat * Reworked subtotal options database managment * Changed access to special code * Remove unecessary call to php trait * Changed definition of subtotals special code constant * Reworked align on PDF * Removed unecessary function and improved error managment * Typo fix and removed treated todos * Post typo changed for to better match subtotals names * Disabled edit if status is not draft * Changed way subtotals options are stored * Added view managing when creating a document form an other * Improved creating document from an other Can check subtotals lines with table head checkbox and removed highlight class for better UI. * Make include of subtotals tpl more clear * Manage centered or justified case If user chose to center or justify, we don't change nothing * Improved pdf * Removed unecessary code block * optimisation * Code sniffer fix * Code sniffer fix * Code sniffer fix * Code sniffer fix * Code sniffer fix and added missing translation * Fix php code sniffer * Reload page when setup saved on subtotals admin page * Fix php code sniffer * pjan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * php warning fix * php warning fix * php phan fix * php phan fix * php phan fix * Fix bug admin page not loading because of const not defined * php phan fix * php phan fix * FIX subtotals admin page display * php phan fix * FIX php phan * Fix bugs and langs * Fix bug pdf align * Replace include by require * Add headers to avoid refreshing and adding unwanted lines * Fix phan * Add GETPOST check for security * Fix phan * Fix phan * Fix phan * Subtotal option when creating a document from another * Fix phan * Add field subtotal options for subtotal lines * Fix phan * Fix phan * Fix phan * Update to follow mvc * Fix php phan * Fix php phan * Fix phpstan/phan * Fix phpstan * Fix phpstan * Fix phpstan * Fix phpstan * Fix phpstan * Update to switch to extraparams * Update to switch to extraparams * Retrieve extraparams from db to objectline * Modified last things to switch to extraparams * Cleaning unnecessary code lines * Fix php-stan * Section subtotal in extraparams to differentiate if needed for further devs * Fix phan * Keep extraparams when creating from another object * Change default value to false when creating a subtotal line * Fix clone would not keep extraparams in new object * Fix dark subtotal line background color Fix when a subtotal background color is too dark and edit pencil or delete trash could not be seen * Fix typo * Fix typo * Added subtotals for facturerec * Fix precommit * Added extraparams when creating rec from fac and other way * Fix phan * Fix objectline null * Desactivating block vat / discount update for facturerec * reformating code * Added expeditions for subtotal * Save extraparams for shipping lines * Display of subtotals lines in shipments * Display when creating facture from shipments * Improve display of lines and invoice creation from shipments * Fix error if missing line rang * Deleted duplicate * Added deletion of subtotal line in shipping documents * Not including subtotal lines if there is no product line in between * Update get subtotal lines in shipment docs to disable * Delete possibility to edit subtotal lines in shipments * Handle pdf for shipment * Handle conf stock or shipment supporting services * Fix precommit * Fix duplicate name creating bug * Fix bug where id could be changed by the line id and would create bug * Deleted subtotal lines when STOCK_SUPPORTS_SERVICES is enabled and block would only have service lines * Disable shipments in admin modules Shimpements subtotals lines are only created from commands * Fixing phan and stan * Deleted unused template and phan fix * Fix phan * Fix phan * Fix phan * FIX: phan * Fix template bug If document was not in subtotal scope and would use a template used by subtotal it would create an error. * Fix php-stan * Fix bad display when modules and confs were activated * Fix php codesniffer * Excluding subtotal lines when mass updating * Fix shipments service lines exluded + showing subtotal line with specific configs * Fix line display with situation invoices + bug block line update * Added ODT managment This works with invoices but has not been tested with other documents * Fix bug when editing VAT/discount by block * Fix error raised when subtotal line added Subtotal line had no fk_product and raised the error but we want this line to have no fk product * Fix precommit * Added ODT template for documents that uses subtotals This template can be usefull to understand how to create an odt template using subtotals module * Fix phan * Fix phan * fix: buttons showing in bad document status * clean: unwanted commited files * add: table examples to use with subtotals on ODT templates * fix: Unwanted print of value when creating a document from another * feat: renaming for better understanding * feat: Improved templates for documents related to subtotals --------- Co-authored-by: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-05-10 00:44:31 +00:00
$sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end, obj.special_code,";
$sql .= " ed.rowid as edrowid, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_elementdet, ed.fk_entrepot as warehouse_id,";
$sql .= " e.rowid as sendingid, e.ref as exp_ref, e.date_creation, e.date_delivery, e.date_expedition, e.billed, e.fk_statut as status, e.signed_status,";
$sql .= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid, p.tobatch as product_tobatch,';
$sql .= ' p.description as product_desc';
$sql .= " FROM " . MAIN_DB_PREFIX . "expeditiondet as ed,";
$sql .= " " . MAIN_DB_PREFIX . "expedition as e,";
2026-04-14 17:23:50 +00:00
$sql .= " " . MAIN_DB_PREFIX . $db->sanitize($origin) . "det as obj"; // for example llx_commandedet
$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON obj.fk_product = p.rowid";
//TODO Add link to expeditiondet_batch
$sql .= " WHERE e.entity IN (" . getEntity('expedition') . ")";
2026-04-14 17:23:50 +00:00
$sql .= " AND obj.fk_" . $db->sanitize($origin) . " = " . ((int) $origin_id);
$sql .= " AND obj.rowid = ed.fk_elementdet";
NEW Subtotal module (#33502) * Changes to follow mvc logic * Reworked admin page and form to add lines * Reworked adding line logic * Adding options when editing subtotal lines * Fix translations * Fixed errors/displays and started pdf * Color for subtotals pdf lines * FIX display of subtotal totht * Added pdf azur for propal * Fix duplicate translation * Added subtotal support for facture pdf * Added subtotal support for commande pdf * Improve UI/translations * Restored old pdf * Info to warn user for unsupported pdf * Added title lines VAT rate and discount support This is meant for future feature wich is block mass changing vat rate and discount percentage * Working on block apply vat and discount * Added buttons for block actions * Handle editing vat and discount for subtotal lines * Editing vat and discount for subtotal lines bloc working * Added possibility to move by block * Updated adding and updating a subtotal line * Improved vat and discount block update * Improvement for block vat/discount and line edition Editing a title line edits the corresponding subtotal line * Improvement for moving by block * Bad tile or st line placement managing * Improved bad title or st line placement managing * Adding subtotal line improved Adding a subtotal line adds it right under its corresponding title * Improved deleting subtotal line Added possibility to choose if you want to delete the corresponding subtotal line when deleting a title line * Preventing too high level titles to be created * Create and update line errors managing * Improved bad title or st line placement managing * Improved st line creation * improve headers * fix bad block placement managing * fix adding st line not working if duplicates titles * fix translations * Fix block update * FIX special chars bug If special char like " ' " was used in title it could be converted to special char entity. * Prepare for pdf options Pdf options like page break befor title should be shown as a picto if activated on a subtotal line on a document * Added option managing * Improved subtotal options and PDF integration * Code refactor * Action name/Error managment/PDF refreshing When adding or updating a subtotal line * Reformat * Reworked subtotal options database managment * Changed access to special code * Remove unecessary call to php trait * Changed definition of subtotals special code constant * Reworked align on PDF * Removed unecessary function and improved error managment * Typo fix and removed treated todos * Post typo changed for to better match subtotals names * Disabled edit if status is not draft * Changed way subtotals options are stored * Added view managing when creating a document form an other * Improved creating document from an other Can check subtotals lines with table head checkbox and removed highlight class for better UI. * Make include of subtotals tpl more clear * Manage centered or justified case If user chose to center or justify, we don't change nothing * Improved pdf * Removed unecessary code block * optimisation * Code sniffer fix * Code sniffer fix * Code sniffer fix * Code sniffer fix * Code sniffer fix and added missing translation * Fix php code sniffer * Reload page when setup saved on subtotals admin page * Fix php code sniffer * pjan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * php warning fix * php warning fix * php phan fix * php phan fix * php phan fix * Fix bug admin page not loading because of const not defined * php phan fix * php phan fix * FIX subtotals admin page display * php phan fix * FIX php phan * Fix bugs and langs * Fix bug pdf align * Replace include by require * Add headers to avoid refreshing and adding unwanted lines * Fix phan * Add GETPOST check for security * Fix phan * Fix phan * Fix phan * Subtotal option when creating a document from another * Fix phan * Add field subtotal options for subtotal lines * Fix phan * Fix phan * Fix phan * Update to follow mvc * Fix php phan * Fix php phan * Fix phpstan/phan * Fix phpstan * Fix phpstan * Fix phpstan * Fix phpstan * Fix phpstan * Update to switch to extraparams * Update to switch to extraparams * Retrieve extraparams from db to objectline * Modified last things to switch to extraparams * Cleaning unnecessary code lines * Fix php-stan * Section subtotal in extraparams to differentiate if needed for further devs * Fix phan * Keep extraparams when creating from another object * Change default value to false when creating a subtotal line * Fix clone would not keep extraparams in new object * Fix dark subtotal line background color Fix when a subtotal background color is too dark and edit pencil or delete trash could not be seen * Fix typo * Fix typo * Added subtotals for facturerec * Fix precommit * Added extraparams when creating rec from fac and other way * Fix phan * Fix objectline null * Desactivating block vat / discount update for facturerec * reformating code * Added expeditions for subtotal * Save extraparams for shipping lines * Display of subtotals lines in shipments * Display when creating facture from shipments * Improve display of lines and invoice creation from shipments * Fix error if missing line rang * Deleted duplicate * Added deletion of subtotal line in shipping documents * Not including subtotal lines if there is no product line in between * Update get subtotal lines in shipment docs to disable * Delete possibility to edit subtotal lines in shipments * Handle pdf for shipment * Handle conf stock or shipment supporting services * Fix precommit * Fix duplicate name creating bug * Fix bug where id could be changed by the line id and would create bug * Deleted subtotal lines when STOCK_SUPPORTS_SERVICES is enabled and block would only have service lines * Disable shipments in admin modules Shimpements subtotals lines are only created from commands * Fixing phan and stan * Deleted unused template and phan fix * Fix phan * Fix phan * Fix phan * FIX: phan * Fix template bug If document was not in subtotal scope and would use a template used by subtotal it would create an error. * Fix php-stan * Fix bad display when modules and confs were activated * Fix php codesniffer * Excluding subtotal lines when mass updating * Fix shipments service lines exluded + showing subtotal line with specific configs * Fix line display with situation invoices + bug block line update * Added ODT managment This works with invoices but has not been tested with other documents * Fix bug when editing VAT/discount by block * Fix error raised when subtotal line added Subtotal line had no fk_product and raised the error but we want this line to have no fk product * Fix precommit * Added ODT template for documents that uses subtotals This template can be usefull to understand how to create an odt template using subtotals module * Fix phan * Fix phan * fix: buttons showing in bad document status * clean: unwanted commited files * add: table examples to use with subtotals on ODT templates * fix: Unwanted print of value when creating a document from another * feat: renaming for better understanding * feat: Improved templates for documents related to subtotals --------- Co-authored-by: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-05-10 00:44:31 +00:00
if (isModEnabled('subtotals')) {
$sql .= " AND obj.special_code <> " . SUBTOTALS_SPECIAL_CODE;
NEW Subtotal module (#33502) * Changes to follow mvc logic * Reworked admin page and form to add lines * Reworked adding line logic * Adding options when editing subtotal lines * Fix translations * Fixed errors/displays and started pdf * Color for subtotals pdf lines * FIX display of subtotal totht * Added pdf azur for propal * Fix duplicate translation * Added subtotal support for facture pdf * Added subtotal support for commande pdf * Improve UI/translations * Restored old pdf * Info to warn user for unsupported pdf * Added title lines VAT rate and discount support This is meant for future feature wich is block mass changing vat rate and discount percentage * Working on block apply vat and discount * Added buttons for block actions * Handle editing vat and discount for subtotal lines * Editing vat and discount for subtotal lines bloc working * Added possibility to move by block * Updated adding and updating a subtotal line * Improved vat and discount block update * Improvement for block vat/discount and line edition Editing a title line edits the corresponding subtotal line * Improvement for moving by block * Bad tile or st line placement managing * Improved bad title or st line placement managing * Adding subtotal line improved Adding a subtotal line adds it right under its corresponding title * Improved deleting subtotal line Added possibility to choose if you want to delete the corresponding subtotal line when deleting a title line * Preventing too high level titles to be created * Create and update line errors managing * Improved bad title or st line placement managing * Improved st line creation * improve headers * fix bad block placement managing * fix adding st line not working if duplicates titles * fix translations * Fix block update * FIX special chars bug If special char like " ' " was used in title it could be converted to special char entity. * Prepare for pdf options Pdf options like page break befor title should be shown as a picto if activated on a subtotal line on a document * Added option managing * Improved subtotal options and PDF integration * Code refactor * Action name/Error managment/PDF refreshing When adding or updating a subtotal line * Reformat * Reworked subtotal options database managment * Changed access to special code * Remove unecessary call to php trait * Changed definition of subtotals special code constant * Reworked align on PDF * Removed unecessary function and improved error managment * Typo fix and removed treated todos * Post typo changed for to better match subtotals names * Disabled edit if status is not draft * Changed way subtotals options are stored * Added view managing when creating a document form an other * Improved creating document from an other Can check subtotals lines with table head checkbox and removed highlight class for better UI. * Make include of subtotals tpl more clear * Manage centered or justified case If user chose to center or justify, we don't change nothing * Improved pdf * Removed unecessary code block * optimisation * Code sniffer fix * Code sniffer fix * Code sniffer fix * Code sniffer fix * Code sniffer fix and added missing translation * Fix php code sniffer * Reload page when setup saved on subtotals admin page * Fix php code sniffer * pjan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * phan fix * php warning fix * php warning fix * php phan fix * php phan fix * php phan fix * Fix bug admin page not loading because of const not defined * php phan fix * php phan fix * FIX subtotals admin page display * php phan fix * FIX php phan * Fix bugs and langs * Fix bug pdf align * Replace include by require * Add headers to avoid refreshing and adding unwanted lines * Fix phan * Add GETPOST check for security * Fix phan * Fix phan * Fix phan * Subtotal option when creating a document from another * Fix phan * Add field subtotal options for subtotal lines * Fix phan * Fix phan * Fix phan * Update to follow mvc * Fix php phan * Fix php phan * Fix phpstan/phan * Fix phpstan * Fix phpstan * Fix phpstan * Fix phpstan * Fix phpstan * Update to switch to extraparams * Update to switch to extraparams * Retrieve extraparams from db to objectline * Modified last things to switch to extraparams * Cleaning unnecessary code lines * Fix php-stan * Section subtotal in extraparams to differentiate if needed for further devs * Fix phan * Keep extraparams when creating from another object * Change default value to false when creating a subtotal line * Fix clone would not keep extraparams in new object * Fix dark subtotal line background color Fix when a subtotal background color is too dark and edit pencil or delete trash could not be seen * Fix typo * Fix typo * Added subtotals for facturerec * Fix precommit * Added extraparams when creating rec from fac and other way * Fix phan * Fix objectline null * Desactivating block vat / discount update for facturerec * reformating code * Added expeditions for subtotal * Save extraparams for shipping lines * Display of subtotals lines in shipments * Display when creating facture from shipments * Improve display of lines and invoice creation from shipments * Fix error if missing line rang * Deleted duplicate * Added deletion of subtotal line in shipping documents * Not including subtotal lines if there is no product line in between * Update get subtotal lines in shipment docs to disable * Delete possibility to edit subtotal lines in shipments * Handle pdf for shipment * Handle conf stock or shipment supporting services * Fix precommit * Fix duplicate name creating bug * Fix bug where id could be changed by the line id and would create bug * Deleted subtotal lines when STOCK_SUPPORTS_SERVICES is enabled and block would only have service lines * Disable shipments in admin modules Shimpements subtotals lines are only created from commands * Fixing phan and stan * Deleted unused template and phan fix * Fix phan * Fix phan * Fix phan * FIX: phan * Fix template bug If document was not in subtotal scope and would use a template used by subtotal it would create an error. * Fix php-stan * Fix bad display when modules and confs were activated * Fix php codesniffer * Excluding subtotal lines when mass updating * Fix shipments service lines exluded + showing subtotal line with specific configs * Fix line display with situation invoices + bug block line update * Added ODT managment This works with invoices but has not been tested with other documents * Fix bug when editing VAT/discount by block * Fix error raised when subtotal line added Subtotal line had no fk_product and raised the error but we want this line to have no fk product * Fix precommit * Added ODT template for documents that uses subtotals This template can be usefull to understand how to create an odt template using subtotals module * Fix phan * Fix phan * fix: buttons showing in bad document status * clean: unwanted commited files * add: table examples to use with subtotals on ODT templates * fix: Unwanted print of value when creating a document from another * feat: renaming for better understanding * feat: Improved templates for documents related to subtotals --------- Co-authored-by: Marc de Lima Lucio <68746600+marc-dll@users.noreply.github.com> Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-05-10 00:44:31 +00:00
}
$sql .= " AND ed.fk_expedition = e.rowid";
2021-02-23 21:03:23 +00:00
if ($filter) {
$sql .= $filter; // @phan-suppress-current-line SqlInjection
2021-02-23 21:03:23 +00:00
}
2023-12-02 15:46:37 +00:00
$sql .= " ORDER BY obj.rowid, obj.fk_product";
2014-06-12 09:31:53 +00:00
dol_syslog("show_list_sending_receive", LOG_DEBUG);
$resql = $db->query($sql);
2021-02-23 21:03:23 +00:00
if ($resql) {
$num = $db->num_rows($resql);
$i = 0;
2021-02-23 21:03:23 +00:00
if ($num) {
if ($filter) {
print load_fiche_titre($langs->trans("OtherSendingsForSameOrder"));
} else {
print load_fiche_titre($langs->trans("SendingsAndReceivingForSameOrder"));
}
2025-03-20 12:39:25 +00:00
print '<div class="div-table-responsive-no-min">';
2019-11-05 20:24:41 +00:00
print '<table class="liste centpercent">';
print '<tr class="liste_titre">';
2019-01-19 11:40:17 +00:00
//print '<td class="left">'.$langs->trans("QtyOrdered").'</td>';
print '<td>' . $langs->trans("SendingSheet") . '</td>';
print '<td>' . $langs->trans("Description") . '</td>';
print '<td class="center">' . $langs->trans("DateCreation") . '</td>';
print '<td class="center">' . $langs->trans("DateDeliveryPlanned") . '</td>';
print '<td class="center">' . $langs->trans("QtyPreparedOrShipped") . '</td>';
2022-09-25 04:02:37 +00:00
if (isModEnabled('stock')) {
print '<td>' . $langs->trans("Warehouse") . '</td>';
2016-10-29 14:18:39 +00:00
}
/*TODO Add link to expeditiondet_batch
if (isModEnabled('productbatch'))
{
2021-02-23 21:03:23 +00:00
print '<td>';
print '</td>';
}*/
2023-04-18 12:04:27 +00:00
if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
print '<td>' . $langs->trans("DeliveryOrder") . '</td>';
2019-03-14 13:20:32 +00:00
//print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
print '<td class="right">' . $langs->trans("DeliveryDate") . '</td>';
2012-02-04 09:48:47 +00:00
}
print "</tr>\n";
2021-02-23 21:03:23 +00:00
while ($i < $num) {
$objp = $db->fetch_object($resql);
2018-04-22 17:27:37 +00:00
2023-09-19 18:29:24 +00:00
$expedition->id = $objp->expedition_id;
$expedition->ref = $objp->exp_ref;
$expedition->billed = $objp->billed;
$expedition->statut = $objp->status;
$expedition->status = $objp->status;
$expedition->signed_status = $objp->signed_status;
2023-09-19 18:29:24 +00:00
print '<tr class="oddeven">';
2010-05-17 14:13:03 +00:00
// Sending id
2025-03-20 12:39:25 +00:00
print '<td class="tdoverflowmax125">';
2023-09-19 18:29:24 +00:00
print $expedition->getNomUrl(1);
//print '<a href="'.DOL_URL_ROOT.'/expedition/card.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"), 'sending').' '.$objp->exp_ref.'<a>';
print '</td>';
2010-05-17 14:13:03 +00:00
// Description
2021-02-23 21:03:23 +00:00
if ($objp->fk_product > 0) {
2012-02-04 09:48:47 +00:00
// Define output language
2023-11-27 10:39:32 +00:00
if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
2012-02-04 09:48:47 +00:00
$object = new $origin($db);
'@phan-var-force CommonObject $object';
2012-02-04 09:48:47 +00:00
$object->fetch($origin_id);
$object->fetch_thirdparty();
2014-03-12 00:21:18 +00:00
$prod = new Product($db);
$prod->id = $objp->fk_product;
2014-03-12 00:21:18 +00:00
$prod->getMultiLangs();
2012-02-04 09:48:47 +00:00
$outputlangs = $langs;
$newlang = '';
2021-05-17 05:27:02 +00:00
if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
$newlang = GETPOST('lang_id', 'aZ09');
2021-02-23 21:03:23 +00:00
}
if (empty($newlang)) {
$newlang = $object->thirdparty->default_lang;
}
if (!empty($newlang)) {
$outputlangs = new Translate("", $conf);
2012-02-04 09:48:47 +00:00
$outputlangs->setDefaultLang($newlang);
}
$label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label;
2020-05-21 13:05:19 +00:00
} else {
$label = (!empty($objp->label) ? $objp->label : $objp->product_label);
2012-02-04 09:48:47 +00:00
}
print '<td>';
// Show product and description
$product_static->type = $objp->fk_product_type;
$product_static->id = $objp->fk_product;
$product_static->ref = $objp->ref;
$product_static->status_batch = $objp->product_tobatch;
2023-09-19 18:29:24 +00:00
$text = $product_static->getNomUrl(1);
$text .= ' - ' . $label;
$description = (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE') ? '' : dol_htmlentitiesbr($objp->description));
print $form->textwithtooltip($text, $description, 3, 0, '', (string) $i);
// Show range
print_date_range($objp->date_start, $objp->date_end);
// Add description in form
if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
print(!empty($objp->description) ? ((empty($objp->product) || $objp->description != $objp->product) ? '<br>' . dol_htmlentitiesbr($objp->description) : '') : '');
}
print '</td>';
2020-05-21 13:05:19 +00:00
} else {
print "<td>";
2021-02-23 21:03:23 +00:00
if ($objp->fk_product_type == 1) {
$text = img_object($langs->trans('Service'), 'service');
} else {
$text = img_object($langs->trans('Product'), 'product');
}
2012-08-25 13:21:34 +00:00
if (!empty($objp->label)) {
$text .= ' <strong>' . $objp->label . '</strong>';
print $form->textwithtooltip($text, $objp->description, 3, 0, '', (string) $i);
2012-08-25 13:21:34 +00:00
} else {
print $text . ' ' . nl2br($objp->description);
2012-08-25 13:21:34 +00:00
}
// Show range
print_date_range($objp->date_start, $objp->date_end);
print "</td>\n";
}
2019-03-14 13:20:32 +00:00
//print '<td class="center">'.$objp->qty_asked.'</td>';
// Date creation
print '<td class="nowrap center">' . dol_print_date($db->jdate($objp->date_creation), 'day') . '</td>';
// Date shipping creation
print '<td class="nowrap center">' . dol_print_date($db->jdate($objp->date_delivery), 'day') . '</td>';
2010-05-12 23:03:33 +00:00
// Qty shipped
print '<td class="center">' . $objp->qty_shipped . '</td>';
2010-05-12 23:03:33 +00:00
2016-10-29 14:18:39 +00:00
// Warehouse
2022-09-25 04:02:37 +00:00
if (isModEnabled('stock')) {
2025-03-20 12:39:25 +00:00
print '<td class="tdoverflowmax125">';
2021-02-23 21:03:23 +00:00
if ($objp->warehouse_id > 0) {
$warehousestatic->fetch($objp->warehouse_id);
print $warehousestatic->getNomUrl(1);
}
print '</td>';
2016-10-29 14:18:39 +00:00
}
// Batch number management
/*TODO Add link to expeditiondet_batch
if (isModEnabled('productbatch'))
{
//var_dump($objp->edrowid);
2021-02-23 21:03:23 +00:00
$lines[$i]->detail_batch
if (isset($lines[$i]->detail_batch))
{
print '<td>';
if ($lines[$i]->product_tobatch)
{
$detail = '';
foreach ($lines[$i]->detail_batch as $dbatch)
{
$detail.= $langs->trans("Batch").': '.$dbatch->batch;
$detail.= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby,"day");
2017-12-02 10:34:56 +00:00
$detail.= ' - '.$langs->trans("EatByDate").': '.dol_print_date($dbatch->eatby,"day");
$detail.= ' - '.$langs->trans("Qty").': '.$dbatch->qty;
$detail.= '<br>';
2021-02-23 21:03:23 +00:00
}
print $form->textwithtooltip(img_picto('', 'object_barcode').' '.$langs->trans("DetailBatchNumber"),$detail);
}
else
{
print $langs->trans("NA");
}
print '</td>';
} else {
print '<td></td>';
}
}*/
// Information on receipt
2023-04-18 12:04:27 +00:00
if (getDolGlobalInt('MAIN_SUBMODULE_DELIVERY')) {
include_once DOL_DOCUMENT_ROOT . '/delivery/class/delivery.class.php';
$expedition->fetchObjectLinked($expedition->id, $expedition->element, null, 'delivery');
2011-05-06 18:27:18 +00:00
//var_dump($expedition->linkedObjects);
$receiving = '';
2021-02-23 21:03:23 +00:00
if (!empty($expedition->linkedObjects['delivery'])) {
$receiving = reset($expedition->linkedObjects['delivery']); // Take first link
}
2021-02-23 21:03:23 +00:00
if (!empty($receiving)) {
/** @var Delivery $receiving */
'@phan-var-force Delivery $receiving';
// $expedition->fk_elementdet = id of det line of order
// $receiving->fk_origin_line = id of det line of order
// $receiving->origin may be 'shipping'
// $receiving->origin_id may be id of shipping
2010-05-12 23:03:33 +00:00
// Ref
print '<td>';
print $receiving->getNomUrl(1);
2020-10-05 13:32:29 +00:00
//print '<a href="'.DOL_URL_ROOT.'/delivery/card.php?id='.$livraison_id.'">'.img_object($langs->trans("ShowReceiving"),'sending').' '.$objp->livraison_ref.'<a>';
print '</td>';
2010-05-12 23:03:33 +00:00
// Qty received
2019-03-14 13:20:32 +00:00
//print '<td class="center">';
// TODO No solution for the moment to link a line det of receipt with a line det of shipping,
// so no way to know the qty received for this line of shipping.
//print $langs->trans("FeatureNotYetAvailable");
//print '</td>';
2010-05-12 23:03:33 +00:00
// Date shipping real
2019-03-14 13:20:32 +00:00
print '<td class="right">';
print dol_print_date($receiving->date_delivery, 'day');
print '</td>';
2020-05-21 13:05:19 +00:00
} else {
2010-07-22 22:51:00 +00:00
//print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
}
}
print '</tr>';
$i++;
}
print '</table>';
2025-03-20 12:39:25 +00:00
print '</div>';
}
$db->free($resql);
2020-05-21 13:05:19 +00:00
} else {
dol_print_error($db);
}
return 1;
}