fourn.lib.php 12 KB

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