fourn.lib.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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-2023 Frédéric France <frederic.france@netlogic.fr>
  7. * Copyright (C) 2023 Nick Fragoulis
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. * or see https://www.gnu.org/
  22. */
  23. /**
  24. * \file htdocs/core/lib/fourn.lib.php
  25. * \brief Functions used by supplier invoice module
  26. * \ingroup supplier
  27. */
  28. /**
  29. * Prepare array with list of tabs
  30. *
  31. * @param FactureFournisseur $object Object related to tabs
  32. * @return array Array of tabs to show
  33. */
  34. function facturefourn_prepare_head(FactureFournisseur $object)
  35. {
  36. global $db, $langs, $conf;
  37. $h = 0;
  38. $head = array();
  39. $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$object->id;
  40. $head[$h][1] = $langs->trans('SupplierInvoice');
  41. $head[$h][2] = 'card';
  42. $h++;
  43. if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
  44. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  45. $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/contact.php?facid='.$object->id;
  46. $head[$h][1] = $langs->trans('ContactsAddresses');
  47. if ($nbContact > 0) {
  48. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  49. }
  50. $head[$h][2] = 'contact';
  51. $h++;
  52. }
  53. //if ($fac->mode_reglement_code == 'PRE')
  54. if (isModEnabled('paymentbybanktransfer')) {
  55. $nbStandingOrders = 0;
  56. $sql = "SELECT COUNT(pfd.rowid) as nb";
  57. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
  58. $sql .= " WHERE pfd.fk_facture_fourn = ".((int) $object->id);
  59. $sql .= " AND type = 'ban'";
  60. $resql = $db->query($sql);
  61. if ($resql) {
  62. $obj = $db->fetch_object($resql);
  63. if ($obj) {
  64. $nbStandingOrders = $obj->nb;
  65. }
  66. } else {
  67. dol_print_error($db);
  68. }
  69. $langs->load("banks");
  70. $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$object->id.'&type=bank-transfer';
  71. $head[$h][1] = $langs->trans('BankTransfer');
  72. if ($nbStandingOrders > 0) {
  73. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbStandingOrders.'</span>';
  74. }
  75. $head[$h][2] = 'standingorders';
  76. $h++;
  77. }
  78. // Show more tabs from modules
  79. // Entries must be declared in modules descriptor with line
  80. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  81. // $this->tabs = array('entity:-tabname); to remove a tab
  82. complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'add', 'core');
  83. if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
  84. $nbNote = 0;
  85. if (!empty($object->note_private)) {
  86. $nbNote++;
  87. }
  88. if (!empty($object->note_public)) {
  89. $nbNote++;
  90. }
  91. $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/note.php?facid='.$object->id;
  92. $head[$h][1] = $langs->trans('Notes');
  93. if ($nbNote > 0) {
  94. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  95. }
  96. $head[$h][2] = 'note';
  97. $h++;
  98. }
  99. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  100. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  101. $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$object->ref;
  102. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  103. $nbLinks = Link::count($db, $object->element, $object->id);
  104. $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$object->id;
  105. $head[$h][1] = $langs->trans('Documents');
  106. if (($nbFiles + $nbLinks) > 0) {
  107. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  108. }
  109. $head[$h][2] = 'documents';
  110. $h++;
  111. $head[$h][0] = DOL_URL_ROOT.'/fourn/facture/info.php?facid='.$object->id;
  112. $head[$h][1] = $langs->trans('Info');
  113. $head[$h][2] = 'info';
  114. $h++;
  115. complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'add', 'external');
  116. complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_invoice', 'remove');
  117. return $head;
  118. }
  119. /**
  120. * Prepare array with list of tabs
  121. *
  122. * @param CommandeFournisseur $object Object related to tabs
  123. * @return array Array of tabs to show
  124. */
  125. function ordersupplier_prepare_head(CommandeFournisseur $object)
  126. {
  127. global $db, $langs, $conf, $user;
  128. $h = 0;
  129. $head = array();
  130. $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$object->id;
  131. $head[$h][1] = $langs->trans("SupplierOrder");
  132. $head[$h][2] = 'card';
  133. $h++;
  134. if (!getDolGlobalString('MAIN_DISABLE_CONTACTS_TAB')) {
  135. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  136. $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/contact.php?id='.$object->id;
  137. $head[$h][1] = $langs->trans('ContactsAddresses');
  138. if ($nbContact > 0) {
  139. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  140. }
  141. $head[$h][2] = 'contact';
  142. $h++;
  143. }
  144. if (isModEnabled('stock') && (getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION') || getDolGlobalString('STOCK_CALCULATE_ON_RECEPTION_CLOSE'))) {
  145. $langs->load("stocks");
  146. $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/dispatch.php?id='.$object->id;
  147. $head[$h][1] = $langs->trans("OrderDispatch");
  148. //If dispach process running we add the number of item to dispatch into the head
  149. if (in_array($object->statut, array($object::STATUS_ORDERSENT, $object::STATUS_RECEIVED_PARTIALLY, $object::STATUS_RECEIVED_COMPLETELY))) {
  150. $sumQtyAllreadyDispatched = 0;
  151. $sumQtyOrdered = 0;
  152. if (empty($object->lines)) {
  153. $object->fetch_lines();
  154. }
  155. $nbLinesOrdered = count($object->lines);
  156. $dispachedLines = $object->getDispachedLines(1);
  157. $nbDispachedLines = count($dispachedLines);
  158. for ($line = 0 ; $line < $nbDispachedLines; $line++) {
  159. $sumQtyAllreadyDispatched = $sumQtyAllreadyDispatched + $dispachedLines[$line]['qty'];
  160. }
  161. for ($line = 0 ; $line < $nbLinesOrdered; $line++) {
  162. //If line is a product of conf to manage stocks for services
  163. if ($object->lines[$line]->product_type == 0 || getDolGlobalString('STOCK_SUPPORTS_SERVICES')) {
  164. $sumQtyOrdered = $sumQtyOrdered + $object->lines[$line]->qty;
  165. }
  166. }
  167. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.price2num($sumQtyAllreadyDispatched, 'MS').' / '.price2num($sumQtyOrdered, 'MS').'</span>';
  168. }
  169. $head[$h][2] = 'dispatch';
  170. $h++;
  171. }
  172. // Show more tabs from modules
  173. // Entries must be declared in modules descriptor with line
  174. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  175. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  176. complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'add', 'core');
  177. if (!getDolGlobalString('MAIN_DISABLE_NOTES_TAB')) {
  178. $nbNote = 0;
  179. if (!empty($object->note_private)) {
  180. $nbNote++;
  181. }
  182. if (!empty($object->note_public)) {
  183. $nbNote++;
  184. }
  185. $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/note.php?id='.$object->id;
  186. $head[$h][1] = $langs->trans("Notes");
  187. if ($nbNote > 0) {
  188. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  189. }
  190. $head[$h][2] = 'note';
  191. $h++;
  192. }
  193. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  194. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  195. $upload_dir = $conf->fournisseur->dir_output."/commande/".dol_sanitizeFileName($object->ref);
  196. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  197. $nbLinks = Link::count($db, $object->element, $object->id);
  198. $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/document.php?id='.$object->id;
  199. $head[$h][1] = $langs->trans('Documents');
  200. if (($nbFiles + $nbLinks) > 0) {
  201. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  202. }
  203. $head[$h][2] = 'documents';
  204. $h++;
  205. $head[$h][0] = DOL_URL_ROOT.'/fourn/commande/info.php?id='.$object->id;
  206. $head[$h][1] = $langs->trans("Events");
  207. if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) {
  208. $head[$h][1] .= '/';
  209. $head[$h][1] .= $langs->trans("Agenda");
  210. }
  211. $head[$h][2] = 'info';
  212. $h++;
  213. complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'add', 'external');
  214. complete_head_from_modules($conf, $langs, $object, $head, $h, 'supplier_order', 'remove');
  215. return $head;
  216. }
  217. /**
  218. * Return array head with list of tabs to view object informations.
  219. *
  220. * @return array head array with tabs
  221. */
  222. function supplierorder_admin_prepare_head()
  223. {
  224. global $langs, $conf, $user, $db;
  225. $extrafields = new ExtraFields($db);
  226. $extrafields->fetch_name_optionals_label('commande_fournisseur');
  227. $extrafields->fetch_name_optionals_label('commande_fournisseurdet');
  228. $extrafields->fetch_name_optionals_label('facture_fourn');
  229. $extrafields->fetch_name_optionals_label('facture_fourn_det');
  230. $extrafields->fetch_name_optionals_label('facture_fourn_rec');
  231. $extrafields->fetch_name_optionals_label('facture_fourn_det_rec');
  232. $h = 0;
  233. $head = array();
  234. $head[$h][0] = DOL_URL_ROOT."/admin/supplier_order.php";
  235. $head[$h][1] = $langs->trans("SupplierOrder");
  236. $head[$h][2] = 'order';
  237. $h++;
  238. $head[$h][0] = DOL_URL_ROOT."/admin/supplier_invoice.php";
  239. $head[$h][1] = $langs->trans("SuppliersInvoice");
  240. $head[$h][2] = 'invoice';
  241. $h++;
  242. $head[$h][0] = DOL_URL_ROOT."/admin/supplier_payment.php";
  243. $head[$h][1] = $langs->trans("SuppliersPayment");
  244. $head[$h][2] = 'supplierpayment';
  245. $h++;
  246. complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin');
  247. $head[$h][0] = DOL_URL_ROOT.'/admin/supplierorder_extrafields.php';
  248. $head[$h][1] = $langs->trans("ExtraFieldsSupplierOrders");
  249. $nbExtrafields = $extrafields->attributes['commande_fournisseur']['count'];
  250. if ($nbExtrafields > 0) {
  251. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  252. }
  253. $head[$h][2] = 'supplierorder';
  254. $h++;
  255. $head[$h][0] = DOL_URL_ROOT.'/admin/supplierorderdet_extrafields.php';
  256. $head[$h][1] = $langs->trans("ExtraFieldsSupplierOrdersLines");
  257. $nbExtrafields = $extrafields->attributes['commande_fournisseurdet']['count'];
  258. if ($nbExtrafields > 0) {
  259. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  260. }
  261. $head[$h][2] = 'supplierorderdet';
  262. $h++;
  263. $head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoice_extrafields.php';
  264. $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoices");
  265. $nbExtrafields = $extrafields->attributes['facture_fourn']['count'];
  266. if ($nbExtrafields > 0) {
  267. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  268. }
  269. $head[$h][2] = 'supplierinvoice';
  270. $h++;
  271. $head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoicedet_extrafields.php';
  272. $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesLines");
  273. $nbExtrafields = $extrafields->attributes['facture_fourn_det']['count'];
  274. if ($nbExtrafields > 0) {
  275. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  276. }
  277. $head[$h][2] = 'supplierinvoicedet';
  278. $h++;
  279. $head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoice_rec_extrafields.php';
  280. $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesRec");
  281. $nbExtrafields = $extrafields->attributes['facture_fourn_rec']['count'];
  282. if ($nbExtrafields > 0) {
  283. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  284. }
  285. $head[$h][2] = 'attributesrec';
  286. $h++;
  287. $head[$h][0] = DOL_URL_ROOT.'/admin/supplierinvoicedet_rec_extrafields.php';
  288. $head[$h][1] = $langs->trans("ExtraFieldsSupplierInvoicesLinesRec");
  289. $nbExtrafields = $extrafields->attributes['facture_fourn_det_rec']['count'];
  290. if ($nbExtrafields > 0) {
  291. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
  292. }
  293. $head[$h][2] = 'attributeslinesrec';
  294. $h++;
  295. complete_head_from_modules($conf, $langs, null, $head, $h, 'supplierorder_admin', 'remove');
  296. return $head;
  297. }