dolibarr 24.0.0-beta
supplier_order.lib.php
1<?php
2/* Copyright (C) 2005-2009 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2006 Marc Barilley <marc@ocebo.com>
5 * Copyright (C) 2011-2013 Philippe Grand <philippe.grand@atoo-net.com>
6 * Copyright (C) 2022-2026 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2023 Nick Fragoulis
8 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2026 Alexandre Spangaro <alexandre@inovea-conseil.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 * or see https://www.gnu.org/
24 */
25
38/*
39function supplierorder_prepare_head(CommandeFournisseur $object)
40{
41 global $db, $langs, $conf, $user;
42
43 $h = 0;
44 $head = array();
45
46 $head[$h][0] = DOL_URL_ROOT.'/supplier_order/card.php?id='.$object->id;
47 $head[$h][1] = $langs->trans("SupplierOrder");
48 $head[$h][2] = 'card';
49 $h++;
50
51 if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
52 $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
53 $head[$h][0] = DOL_URL_ROOT.'/supplier_order/contact.php?id='.$object->id;
54 $head[$h][1] = $langs->trans('ContactsAddresses');
55 if ($nbContact > 0) {
56 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
57 }
58 $head[$h][2] = 'contact';
59 $h++;
60 }
61
62 if (isModEnabled('stock') && (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE'))) {
63 $langs->load("stocks");
64 $head[$h][0] = DOL_URL_ROOT.'/supplier_order/dispatch.php?id='.$object->id;
65 $head[$h][1] = $langs->trans("OrderDispatch");
66
67 //If dispatch process running we add the number of item to dispatch into the head
68 if (in_array($object->status, array($object::STATUS_ORDERSENT, $object::STATUS_RECEIVED_PARTIALLY, $object::STATUS_RECEIVED_COMPLETELY))) {
69 $sumQtyAllreadyDispatched = 0;
70 $sumQtyOrdered = 0;
71
72 if (empty($object->lines)) {
73 $object->fetch_lines();
74 }
75 $nbLinesOrdered = count($object->lines);
76 $dispachedLines = $object->getDispachedLines(1);
77 $nbDispachedLines = count($dispachedLines);
78
79 for ($line = 0 ; $line < $nbDispachedLines; $line++) {
80 $sumQtyAllreadyDispatched += $dispachedLines[$line]['qty'];
81 }
82 for ($line = 0 ; $line < $nbLinesOrdered; $line++) {
83 //If line is a product of conf to manage stocks for services
84 if ($object->lines[$line]->product_type == 0 || ($object->lines[$line]->product_type == 1 && getDolGlobalString('STOCK_SUPPORTS_SERVICES'))) {
85 $sumQtyOrdered += $object->lines[$line]->qty;
86 }
87 }
88 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.price2num($sumQtyAllreadyDispatched, 'MS').' / '.price2num($sumQtyOrdered, 'MS').'</span>';
89 }
90
91 $head[$h][2] = 'dispatch';
92 $h++;
93 }
94
95 // Show more tabs from modules
96 // Entries must be declared in modules descriptor with line
97 // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
98 // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
99 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'add', 'core');
100
101 if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
102 $nbNote = 0;
103 if (!empty($object->note_private)) {
104 $nbNote++;
105 }
106 if (!empty($object->note_public)) {
107 $nbNote++;
108 }
109 $head[$h][0] = DOL_URL_ROOT.'/supplier_order/note.php?id='.$object->id;
110 $head[$h][1] = $langs->trans("Notes");
111 if ($nbNote > 0) {
112 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
113 }
114 $head[$h][2] = 'note';
115 $h++;
116 }
117
118 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
119 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
120 $upload_dir = $conf->fournisseur->dir_output."/commande/".dol_sanitizeFileName($object->ref);
121 $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
122 $nbLinks = Link::count($db, $object->element, $object->id);
123 $head[$h][0] = DOL_URL_ROOT.'/supplier_order/document.php?id='.$object->id;
124 $head[$h][1] = $langs->trans('Documents');
125 if (($nbFiles + $nbLinks) > 0) {
126 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
127 }
128 $head[$h][2] = 'documents';
129 $h++;
130
131 $head[$h][0] = DOL_URL_ROOT.'/supplier_order/info.php?id='.$object->id;
132 $head[$h][1] = $langs->trans("Events");
133 if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
134 $nbEvent = 0;
135 // Enable caching of order supplier count actioncomm
136 require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php';
137 $cachekey = 'count_events_order_'.$object->id;
138 $dataretrieved = dol_getcache($cachekey);
139 if (!is_null($dataretrieved)) {
140 $nbEvent = $dataretrieved;
141 } else {
142 $sql = "SELECT COUNT(id) as nb";
143 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
144 $sql .= " WHERE fk_element = ".((int) $object->id);
145 $sql .= " AND elementtype = 'order_supplier'";
146 $resql = $db->query($sql);
147 if ($resql) {
148 $obj = $db->fetch_object($resql);
149 $nbEvent = $obj->nb;
150 } else {
151 dol_syslog('Failed to count actioncomm '.$db->lasterror(), LOG_ERR);
152 }
153 dol_setcache($cachekey, $nbEvent, 120); // If setting cache fails, this is not a problem, so we do not test result.
154 }
155
156 $head[$h][1] .= '/';
157 $head[$h][1] .= $langs->trans("Agenda");
158 if ($nbEvent > 0) {
159 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbEvent.'</span>';
160 }
161 }
162 $head[$h][2] = 'info';
163 $h++;
164
165 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'add', 'external');
166
167 complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'remove');
168
169 return $head;
170}
171*/
172
178function supplier_order_admin_prepare_head()
179{
180 global $langs, $conf, $user, $extrafields;
181
182 $extrafields->fetch_name_optionals_label('commande_fournisseur');
183 $extrafields->fetch_name_optionals_label('commande_fournisseurdet');
184
185 $h = 0;
186 $head = array();
187
188 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT."/supplier_order/admin/supplier_order.php");
189 $head[$h][1] = $langs->trans("SupplierOrder");
190 $head[$h][2] = 'order';
191 $h++;
192
193 complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin');
194
195 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_order/admin/supplierorder_extrafields.php');
196 $head[$h][1] = $langs->trans("ExtraFieldsSupplierOrders");
197 $nbExtrafields = $extrafields->attributes['commande_fournisseur']['count'];
198 if ($nbExtrafields > 0) {
199 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
200 }
201 $head[$h][2] = 'supplierorder';
202 $h++;
203
204 $head[$h][0] = dolBuildUrl(DOL_URL_ROOT.'/supplier_order/admin/supplierorderdet_extrafields.php');
205 $head[$h][1] = $langs->trans("ExtraFieldsSupplierOrdersLines");
206 $nbExtrafields = $extrafields->attributes['commande_fournisseurdet']['count'];
207 if ($nbExtrafields > 0) {
208 $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
209 }
210 $head[$h][2] = 'supplierorderdet';
211 $h++;
212
213 complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin', 'remove');
214
215 return $head;
216}
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).