NEW: add 2 new element types on thirdparty consumption page (#29794)

* NEW: add 2 new element types (shipments and receptions) on thirdparty consumption page

* Update consumption.php

---------

Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
jyhere 2024-06-01 00:54:22 +02:00 committed by GitHub
parent effc7e606b
commit 2a93d8e48a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -179,6 +179,9 @@ if ($object->client) {
if (isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
$elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices');
}
if (isModEnabled('shipping') && $user->hasRight('expedition', 'lire')) {
$elementTypeArray['shipment'] = $langs->transnoentitiesnoconv('Shipments');
}
if (isModEnabled('contract') && $user->hasRight('contrat', 'lire')) {
$elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts');
}
@ -213,6 +216,10 @@ if ($object->fournisseur) {
if ((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'commande', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire'))) {
$elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders');
}
if (isModEnabled('reception') && $user->hasRight('reception', 'lire')) {
$langs->load('receptions');
$elementTypeArray['reception'] = $langs->transnoentitiesnoconv('Receptions');
}
if (isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire')) {
$elementTypeArray['supplier_proposal'] = $langs->transnoentitiesnoconv('SupplierProposals');
}
@ -288,6 +295,20 @@ if ($type_element == 'order') {
$doc_number = 'c.ref';
$thirdTypeSelect = 'customer';
}
if ($type_element == 'shipment') {
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
$langs->load('sendings');
$documentstatic = new Expedition($db);
$sql_select = 'SELECT e.rowid as doc_id, e.ref as doc_number, \'1\' as doc_type, e.date_creation as dateprint, e.fk_statut as status, NULL as paid, e.date_delivery as delivery_planned_date,';
$tables_from = MAIN_DB_PREFIX."expedition as e,".MAIN_DB_PREFIX."expeditiondet as ed,".MAIN_DB_PREFIX."commandedet as d";
$where = " WHERE e.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
$where .= " AND ed.fk_expedition = e.rowid";
$where .= " AND ed.element_type = 'commande' AND ed.fk_elementdet = d.rowid";
$where .= " AND e.entity = ".$conf->entity;
$dateprint = 'e.date_creation';
$doc_number = 'e.ref';
$thirdTypeSelect = 'customer';
}
if ($type_element == 'supplier_invoice') { // Supplier : Show products from invoices.
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
$documentstatic = new FactureFournisseur($db);
@ -325,6 +346,20 @@ if ($type_element == 'supplier_order') { // Supplier : Show products from order
$doc_number = 'c.ref';
$thirdTypeSelect = 'supplier';
}
if ($type_element == 'reception') { // Supplier : Show products from orders.
require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php';
$langs->loadLangs(['sendings', 'receptions']); // delivery planned date
$documentstatic = new Reception($db);
$sql_select = 'SELECT r.rowid as doc_id, r.ref as doc_number, \'1\' as doc_type, r.date_creation as dateprint, r.fk_statut as status, NULL as paid, r.date_delivery as delivery_planned_date, ';
$tables_from = MAIN_DB_PREFIX."reception as r,".MAIN_DB_PREFIX."receptiondet_batch as rd,".MAIN_DB_PREFIX."commande_fournisseurdet as d";
$where = " WHERE r.fk_soc = s.rowid AND s.rowid = ".((int) $socid);
$where .= " AND rd.fk_reception = r.rowid";
$where .= " AND rd.fk_elementdet = d.rowid AND rd.element_type = 'supplier_order'";
$where .= " AND r.entity = ".$conf->entity;
$dateprint = 'r.date_creation';
$doc_number = 'r.ref';
$thirdTypeSelect = 'supplier';
}
if ($type_element == 'contract') { // Order
require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
$documentstatic = new Contrat($db);
@ -345,7 +380,7 @@ $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // N
if (!empty($sql_select)) {
$sql = $sql_select;
$sql .= ' d.description as description,';
if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') {
if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal' && $type_element != 'shipment' && $type_element != 'reception') {
$sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
}
if ($type_element == 'supplier_proposal') {
@ -354,6 +389,12 @@ if (!empty($sql_select)) {
if ($type_element == 'contract') {
$sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, ';
}
if ($type_element == 'shipment') {
$sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, ed.qty, ed.qty as prod_qty, ed.qty * d.subprice * (100 - d.remise_percent) / 100 as total_ht, ';
}
if ($type_element == 'reception') {
$sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, rd.qty, rd.qty as prod_qty, rd.qty * d.subprice * (100 - d.remise_percent) / 100 as total_ht, ';
}
if ($type_element != 'fichinter') {
$sql .= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity, ';
}
@ -450,7 +491,7 @@ if ($sql_select) {
print $formother->selectyear($year ? $year : -1, 'year', 1, 20, 1, 0, 0, '', 'valignmiddle maxwidth75imp marginleftonly');
print '</td>';
// delivery planned date
if ($type_element == 'order' || $type_element == 'supplier_order') {
if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
print '<td class="liste_titre center"></td>';
}
print '<td class="liste_titre center">';
@ -473,7 +514,7 @@ if ($sql_select) {
print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, '', $sortfield, $sortorder, 'left ');
print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, '', $sortfield, $sortorder, 'center ');
// delivery planned date
if ($type_element == 'order' || $type_element == 'supplier_order') {
if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
print_liste_field_titre('DateDeliveryPlanned', $_SERVER['PHP_SELF'], 'delivery_planned_date', '', $param, '', $sortfield, $sortorder, 'center ');
}
print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, '', $sortfield, $sortorder, 'center ');
@ -506,7 +547,7 @@ if ($sql_select) {
print '</td>';
print '<td class="center" width="80">'.dol_print_date($db->jdate($objp->dateprint), 'day').'</td>';
// delivery planned date
if ($type_element == 'order' || $type_element == 'supplier_order') {
if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
print '<td class="center">'.dol_print_date($db->jdate($objp->delivery_planned_date), 'day').'</td>';
}
@ -692,7 +733,7 @@ if ($sql_select) {
print '<td>'.$langs->trans('Total').'</td>';
print '<td colspan="3"></td>';
// delivery planned date
if ($type_element == 'order' || $type_element == 'supplier_order') {
if ($type_element == 'order' || $type_element == 'supplier_order' || $type_element == 'shipment') {
print '<td></td>';
}
print '<td class="right">'.$total_qty.'</td>';