invoice.lib.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /* Copyright (C) 2005-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  4. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  5. * Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
  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 <http://www.gnu.org/licenses/>.
  20. * or see http://www.gnu.org/
  21. */
  22. /**
  23. * \file htdocs/core/lib/invoice.lib.php
  24. * \brief Functions used by invoice module
  25. * \ingroup invoice
  26. */
  27. /**
  28. * Initialize the array of tabs for customer invoice
  29. *
  30. * @param Facture $object Invoice object
  31. * @return array Array of head tabs
  32. */
  33. function facture_prepare_head($object)
  34. {
  35. global $db, $langs, $conf;
  36. $h = 0;
  37. $head = array();
  38. $head[$h][0] = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$object->id;
  39. $head[$h][1] = $langs->trans('Card');
  40. $head[$h][2] = 'compta';
  41. $h++;
  42. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  43. {
  44. $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
  45. $head[$h][0] = DOL_URL_ROOT.'/compta/facture/contact.php?facid='.$object->id;
  46. $head[$h][1] = $langs->trans('ContactsAddresses');
  47. if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
  48. $head[$h][2] = 'contact';
  49. $h++;
  50. }
  51. //if ($fac->mode_reglement_code == 'PRE')
  52. if (! empty($conf->prelevement->enabled))
  53. {
  54. $nbStandingOrders=0;
  55. $sql = "SELECT COUNT(pfd.rowid) as nb";
  56. $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
  57. $sql .= " WHERE pfd.fk_facture = ".$object->id;
  58. $resql=$db->query($sql);
  59. if ($resql)
  60. {
  61. $obj=$db->fetch_object($resql);
  62. if ($obj) $nbStandingOrders = $obj->nb;
  63. }
  64. else dol_print_error($db);
  65. $head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$object->id;
  66. $head[$h][1] = $langs->trans('StandingOrders');
  67. if ($nbStandingOrders > 0) $head[$h][1].= ' <span class="badge">'.$nbStandingOrders.'</span>';
  68. $head[$h][2] = 'standingorders';
  69. $h++;
  70. }
  71. // Show more tabs from modules
  72. // Entries must be declared in modules descriptor with line
  73. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  74. // $this->tabs = array('entity:-tabname); to remove a tab
  75. complete_head_from_modules($conf,$langs,$object,$head,$h,'invoice');
  76. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  77. {
  78. $nbNote = 0;
  79. if(!empty($object->note_private)) $nbNote++;
  80. if(!empty($object->note_public)) $nbNote++;
  81. $head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$object->id;
  82. $head[$h][1] = $langs->trans('Notes');
  83. if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
  84. $head[$h][2] = 'note';
  85. $h++;
  86. }
  87. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  88. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  89. $upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
  90. $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
  91. $nbLinks=Link::count($db, $object->element, $object->id);
  92. $head[$h][0] = DOL_URL_ROOT.'/compta/facture/document.php?facid='.$object->id;
  93. $head[$h][1] = $langs->trans('Documents');
  94. if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
  95. $head[$h][2] = 'documents';
  96. $h++;
  97. $head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$object->id;
  98. $head[$h][1] = $langs->trans('Info');
  99. $head[$h][2] = 'info';
  100. $h++;
  101. complete_head_from_modules($conf,$langs,$object,$head,$h,'invoice','remove');
  102. return $head;
  103. }
  104. /**
  105. * Return array head with list of tabs to view object informations.
  106. *
  107. * @return array head array with tabs
  108. */
  109. function invoice_admin_prepare_head()
  110. {
  111. global $langs, $conf, $user;
  112. $h = 0;
  113. $head = array();
  114. $head[$h][0] = DOL_URL_ROOT.'/admin/facture.php';
  115. $head[$h][1] = $langs->trans("Miscellaneous");
  116. $head[$h][2] = 'general';
  117. $h++;
  118. $head[$h][0] = DOL_URL_ROOT.'/admin/payment.php';
  119. $head[$h][1] = $langs->trans("Payments");
  120. $head[$h][2] = 'payment';
  121. $h++;
  122. // Show more tabs from modules
  123. // Entries must be declared in modules descriptor with line
  124. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  125. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  126. complete_head_from_modules($conf,$langs,null,$head,$h,'invoice_admin');
  127. $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_cust_extrafields.php';
  128. $head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoices");
  129. $head[$h][2] = 'attributes';
  130. $h++;
  131. $head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_cust_extrafields.php';
  132. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  133. $head[$h][2] = 'attributeslines';
  134. $h++;
  135. complete_head_from_modules($conf,$langs,null,$head,$h,'invoice_admin','remove');
  136. return $head;
  137. }
  138. function invoice_rec_prepare_head($object)
  139. {
  140. global $db, $langs, $conf;
  141. $h = 0;
  142. $head = array();
  143. $head[$h][0] = DOL_URL_ROOT.'/compta/facture/fiche-rec.php?id='.$object->id;
  144. $head[$h][1] = $langs->trans("CardBill");
  145. $head[$h][2] = 'card';
  146. $h++;
  147. // Show more tabs from modules
  148. // Entries must be declared in modules descriptor with line
  149. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  150. // $this->tabs = array('entity:-tabname); to remove a tab
  151. complete_head_from_modules($conf,$langs,$object,$head,$h,'invoice-rec');
  152. complete_head_from_modules($conf,$langs,$object,$head,$h,'invoice-rec','remove');
  153. return $head;
  154. }