propal.lib.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /* Copyright (C) 2006-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. * or see https://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/lib/propal.lib.php
  21. * \brief Ensemble de fonctions de base pour le module propal
  22. * \ingroup propal
  23. */
  24. /**
  25. * Prepare array with list of tabs
  26. *
  27. * @param object $object Object related to tabs
  28. * @return array Array of tabs to show
  29. */
  30. function propal_prepare_head($object)
  31. {
  32. global $db, $langs, $conf, $user;
  33. $langs->loadLangs(array('propal', 'compta', 'companies'));
  34. $h = 0;
  35. $head = array();
  36. $head[$h][0] = DOL_URL_ROOT.'/comm/propal/card.php?id='.$object->id;
  37. $head[$h][1] = $langs->trans('Proposal');
  38. $head[$h][2] = 'comm';
  39. $h++;
  40. if ((empty($conf->commande->enabled) && ((!empty($conf->expedition->enabled) && !empty($conf->expedition_bon->enabled) && $user->rights->expedition->lire)
  41. || (!empty($conf->expedition->enabled) && !empty($conf->delivery_note->enabled) && $user->rights->expedition->delivery->lire)))) {
  42. $langs->load("sendings");
  43. $text = '';
  44. $head[$h][0] = DOL_URL_ROOT.'/expedition/propal.php?id='.$object->id;
  45. if ($conf->expedition_bon->enabled) {
  46. $text = $langs->trans("Shipment");
  47. }
  48. if ($conf->delivery_note->enabled) {
  49. $text .= '/'.$langs->trans("Receivings");
  50. }
  51. $head[$h][1] = $text;
  52. $head[$h][2] = 'shipping';
  53. $h++;
  54. }
  55. if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  56. $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
  57. $head[$h][0] = DOL_URL_ROOT.'/comm/propal/contact.php?id='.$object->id;
  58. $head[$h][1] = $langs->trans('ContactsAddresses');
  59. if ($nbContact > 0) {
  60. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
  61. }
  62. $head[$h][2] = 'contact';
  63. $h++;
  64. }
  65. // Show more tabs from modules
  66. // Entries must be declared in modules descriptor with line
  67. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  68. // $this->tabs = array('entity:-tabname); to remove a tab
  69. complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal');
  70. if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  71. $nbNote = 0;
  72. if (!empty($object->note_private)) {
  73. $nbNote++;
  74. }
  75. if (!empty($object->note_public)) {
  76. $nbNote++;
  77. }
  78. $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?id='.$object->id;
  79. $head[$h][1] = $langs->trans('Notes');
  80. if ($nbNote > 0) {
  81. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
  82. }
  83. $head[$h][2] = 'note';
  84. $h++;
  85. }
  86. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  87. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  88. $upload_dir = $conf->propal->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
  89. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  90. $nbLinks = Link::count($db, $object->element, $object->id);
  91. $head[$h][0] = DOL_URL_ROOT.'/comm/propal/document.php?id='.$object->id;
  92. $head[$h][1] = $langs->trans('Documents');
  93. if (($nbFiles + $nbLinks) > 0) {
  94. $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>';
  95. }
  96. $head[$h][2] = 'document';
  97. $h++;
  98. $head[$h][0] = DOL_URL_ROOT.'/comm/propal/info.php?id='.$object->id;
  99. $head[$h][1] = $langs->trans('Info');
  100. $head[$h][2] = 'info';
  101. $h++;
  102. complete_head_from_modules($conf, $langs, $object, $head, $h, 'propal', 'remove');
  103. return $head;
  104. }
  105. /**
  106. * Return array head with list of tabs to view object informations.
  107. *
  108. * @return array head array with tabs
  109. */
  110. function propal_admin_prepare_head()
  111. {
  112. global $langs, $conf, $user;
  113. $h = 0;
  114. $head = array();
  115. $head[$h][0] = DOL_URL_ROOT.'/admin/propal.php';
  116. $head[$h][1] = $langs->trans("Miscellaneous");
  117. $head[$h][2] = 'general';
  118. $h++;
  119. // Show more tabs from modules
  120. // Entries must be declared in modules descriptor with line
  121. // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
  122. // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
  123. complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin');
  124. $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propal_extrafields.php';
  125. $head[$h][1] = $langs->trans("ExtraFields");
  126. $head[$h][2] = 'attributes';
  127. $h++;
  128. $head[$h][0] = DOL_URL_ROOT.'/comm/admin/propaldet_extrafields.php';
  129. $head[$h][1] = $langs->trans("ExtraFieldsLines");
  130. $head[$h][2] = 'attributeslines';
  131. $h++;
  132. complete_head_from_modules($conf, $langs, null, $head, $h, 'propal_admin', 'remove');
  133. return $head;
  134. }
  135. /**
  136. * Return a HTML table that contains a pie chart of customer proposals
  137. *
  138. * @param int $socid (Optional) Show only results from the customer with this id
  139. * @return string A HTML table that contains a pie chart of customer invoices
  140. */
  141. function getCustomerProposalPieChart($socid = 0)
  142. {
  143. global $conf, $db, $langs, $user;
  144. $result= '';
  145. if (empty($conf->propal->enabled) || empty($user->rights->propal->lire)) {
  146. return '';
  147. }
  148. $listofstatus = array(Propal::STATUS_DRAFT, Propal::STATUS_VALIDATED, Propal::STATUS_SIGNED, Propal::STATUS_NOTSIGNED, Propal::STATUS_BILLED);
  149. $propalstatic = new Propal($db);
  150. $sql = "SELECT count(p.rowid) as nb, p.fk_statut as status";
  151. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  152. $sql .= ", ".MAIN_DB_PREFIX."propal as p";
  153. if (empty($user->rights->societe->client->voir) && !$socid) {
  154. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  155. }
  156. $sql .= " WHERE p.entity IN (".getEntity($propalstatic->element).")";
  157. $sql .= " AND p.fk_soc = s.rowid";
  158. if ($user->socid) {
  159. $sql .= ' AND p.fk_soc = '.((int) $user->socid);
  160. }
  161. if (empty($user->rights->societe->client->voir) && !$socid) {
  162. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  163. }
  164. $sql .= " AND p.fk_statut IN (".$db->sanitize(implode(" ,", $listofstatus)).")";
  165. $sql .= " GROUP BY p.fk_statut";
  166. $resql = $db->query($sql);
  167. if ($resql) {
  168. $num = $db->num_rows($resql);
  169. $i = 0;
  170. $total = 0;
  171. $totalinprocess = 0;
  172. $dataseries = array();
  173. $colorseries = array();
  174. $vals = array();
  175. while ($i < $num) {
  176. $obj = $db->fetch_object($resql);
  177. if ($obj) {
  178. $vals[$obj->status] = $obj->nb;
  179. $totalinprocess += $obj->nb;
  180. $total += $obj->nb;
  181. }
  182. $i++;
  183. }
  184. $db->free($resql);
  185. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  186. $result = '<div class="div-table-responsive-no-min">';
  187. $result .= '<table class="noborder nohover centpercent">';
  188. $result .= '<tr class="liste_titre">';
  189. $result .= '<td colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Proposals").'</td>';
  190. $result .= '</tr>';
  191. foreach ($listofstatus as $status) {
  192. $dataseries[] = array($propalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
  193. if ($status == Propal::STATUS_DRAFT) {
  194. $colorseries[$status] = '-'.$badgeStatus0;
  195. }
  196. if ($status == Propal::STATUS_VALIDATED) {
  197. $colorseries[$status] = $badgeStatus1;
  198. }
  199. if ($status == Propal::STATUS_SIGNED) {
  200. $colorseries[$status] = $badgeStatus4;
  201. }
  202. if ($status == Propal::STATUS_NOTSIGNED) {
  203. $colorseries[$status] = $badgeStatus9;
  204. }
  205. if ($status == Propal::STATUS_BILLED) {
  206. $colorseries[$status] = $badgeStatus6;
  207. }
  208. if (empty($conf->use_javascript_ajax)) {
  209. $result .= '<tr class="oddeven">';
  210. $result .= '<td>'.$propalstatic->LibStatut($status, 0).'</td>';
  211. $result .= '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
  212. $result .= "</tr>\n";
  213. }
  214. }
  215. if ($conf->use_javascript_ajax) {
  216. $result .= '<tr>';
  217. $result .= '<td align="center" colspan="2">';
  218. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  219. $dolgraph = new DolGraph();
  220. $dolgraph->SetData($dataseries);
  221. $dolgraph->SetDataColor(array_values($colorseries));
  222. $dolgraph->setShowLegend(2);
  223. $dolgraph->setShowPercent(1);
  224. $dolgraph->SetType(array('pie'));
  225. $dolgraph->setHeight('150');
  226. $dolgraph->setWidth('300');
  227. $dolgraph->draw('idgraphthirdparties');
  228. $result .= $dolgraph->show($total ? 0 : 1);
  229. $result .= '</td>';
  230. $result .= '</tr>';
  231. }
  232. //if ($totalinprocess != $total)
  233. //{
  234. // print '<tr class="liste_total">';
  235. // print '<td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td>';
  236. // print '<td class="right">'.$totalinprocess.'</td>';
  237. // print '</tr>';
  238. //}
  239. $result .= '<tr class="liste_total">';
  240. $result .= '<td>'.$langs->trans("Total").'</td>';
  241. $result .= '<td class="right">'.$total.'</td>';
  242. $result .= '</tr>';
  243. $result .= '</table>';
  244. $result .= '</div>';
  245. $result .= '<br>';
  246. } else {
  247. dol_print_error($db);
  248. }
  249. return $result;
  250. }