/htdocs/projet/element.php

https://bitbucket.org/speedealing/speedealing · PHP · 299 lines · 206 code · 48 blank · 45 comment · 62 complexity · adcbc1a7571a2110112fb7f260b48ae8 MD5 · raw file

  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/projet/element.php
  22. * \ingroup projet facture
  23. * \brief Page of project referrers
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  28. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  29. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  30. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
  31. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  32. if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  33. if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  34. if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  35. if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  36. if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  37. if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  38. $langs->load("projects");
  39. $langs->load("companies");
  40. $langs->load("suppliers");
  41. if (! empty($conf->facture->enabled)) $langs->load("bills");
  42. if (! empty($conf->commande->enabled)) $langs->load("orders");
  43. if (! empty($conf->propal->enabled)) $langs->load("propal");
  44. if (! empty($conf->ficheinter->enabled)) $langs->load("interventions");
  45. $projectid=GETPOST('id');
  46. $ref=GETPOST('ref');
  47. if ($projectid == '' && $ref == '')
  48. {
  49. dol_print_error('','Bad parameter');
  50. exit;
  51. }
  52. $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
  53. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  54. $project = new Project($db);
  55. if ($ref)
  56. {
  57. $project->fetch(0,$ref);
  58. $projectid=$project->id;
  59. }
  60. // Security check
  61. $socid=0;
  62. if ($user->societe_id > 0) $socid=$user->societe_id;
  63. $result = restrictedArea($user, 'projet', $projectid);
  64. /*
  65. * View
  66. */
  67. llxHeader("",$langs->trans("Referers"));
  68. $form = new Form($db);
  69. $userstatic=new User($db);
  70. $project = new Project($db);
  71. $project->fetch($_GET["id"],$_GET["ref"]);
  72. $project->societe->fetch($project->societe->id);
  73. // To verify role of users
  74. $userAccess = $project->restrictedProjectArea($user);
  75. $head=project_prepare_head($project);
  76. dol_fiche_head($head, 'element', $langs->trans("Project"),0,($project->public?'projectpub':'project'));
  77. print '<table class="border" width="100%">';
  78. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/liste.php">'.$langs->trans("BackToList").'</a>';
  79. print '<tr><td width="30%">'.$langs->trans("Ref").'</td><td>';
  80. // Define a complementary filter for search of next/prev ref.
  81. if (! $user->rights->projet->all->lire)
  82. {
  83. $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,0);
  84. $project->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
  85. }
  86. print $form->showrefnav($project, 'ref', $linkback, 1, 'ref', 'ref');
  87. print '</td></tr>';
  88. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$project->title.'</td></tr>';
  89. print '<tr><td>'.$langs->trans("Company").'</td><td>';
  90. if (! empty($project->societe->id)) print $project->societe->getNomUrl(1);
  91. else print '&nbsp;';
  92. print '</td></tr>';
  93. // Visibility
  94. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  95. if ($project->public) print $langs->trans('SharedProject');
  96. else print $langs->trans('PrivateProject');
  97. print '</td></tr>';
  98. // Statut
  99. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$project->getLibStatut(4).'</td></tr>';
  100. print '</table>';
  101. print '</div>';
  102. /*
  103. * Referers types
  104. */
  105. $listofreferent=array(
  106. 'propal'=>array(
  107. 'title'=>"ListProposalsAssociatedProject",
  108. 'class'=>'Propal',
  109. 'test'=>$conf->propal->enabled),
  110. 'order'=>array(
  111. 'title'=>"ListOrdersAssociatedProject",
  112. 'class'=>'Commande',
  113. 'test'=>$conf->commande->enabled),
  114. 'invoice'=>array(
  115. 'title'=>"ListInvoicesAssociatedProject",
  116. 'class'=>'Facture',
  117. 'test'=>$conf->facture->enabled),
  118. 'invoice_predefined'=>array(
  119. 'title'=>"ListPredefinedInvoicesAssociatedProject",
  120. 'class'=>'FactureRec',
  121. 'test'=>$conf->facture->enabled),
  122. 'order_supplier'=>array(
  123. 'title'=>"ListSupplierOrdersAssociatedProject",
  124. 'class'=>'CommandeFournisseur',
  125. 'test'=>$conf->fournisseur->enabled),
  126. 'invoice_supplier'=>array(
  127. 'title'=>"ListSupplierInvoicesAssociatedProject",
  128. 'class'=>'FactureFournisseur',
  129. 'test'=>$conf->fournisseur->enabled),
  130. 'contract'=>array(
  131. 'title'=>"ListContractAssociatedProject",
  132. 'class'=>'Contrat',
  133. 'test'=>$conf->contrat->enabled),
  134. 'intervention'=>array(
  135. 'title'=>"ListFichinterAssociatedProject",
  136. 'class'=>'Fichinter',
  137. 'disableamount'=>1,
  138. 'test'=>$conf->ficheinter->enabled),
  139. 'trip'=>array(
  140. 'title'=>"ListTripAssociatedProject",
  141. 'class'=>'Deplacement',
  142. 'disableamount'=>1,
  143. 'test'=>$conf->deplacement->enabled),
  144. 'agenda'=>array(
  145. 'title'=>"ListActionsAssociatedProject",
  146. 'class'=>'ActionComm',
  147. 'disableamount'=>1,
  148. 'test'=>$conf->agenda->enabled)
  149. );
  150. foreach ($listofreferent as $key => $value)
  151. {
  152. $title=$value['title'];
  153. $classname=$value['class'];
  154. $qualified=$value['test'];
  155. if ($qualified)
  156. {
  157. print '<br>';
  158. print_titre($langs->trans($title));
  159. print '<table class="noborder" width="100%">';
  160. print '<tr class="liste_titre">';
  161. print '<td width="100">'.$langs->trans("Ref").'</td>';
  162. print '<td width="100" align="center">'.$langs->trans("Date").'</td>';
  163. print '<td>'.$langs->trans("ThirdParty").'</td>';
  164. if (empty($value['disableamount'])) print '<td align="right" width="120">'.$langs->trans("AmountHT").'</td>';
  165. if (empty($value['disableamount'])) print '<td align="right" width="120">'.$langs->trans("AmountTTC").'</td>';
  166. print '<td align="right" width="200">'.$langs->trans("Status").'</td>';
  167. print '</tr>';
  168. $elementarray = $project->get_element_list($key);
  169. if (count($elementarray)>0 && is_array($elementarray))
  170. {
  171. $var=true;
  172. $total_ht = 0;
  173. $total_ttc = 0;
  174. $num=count($elementarray);
  175. for ($i = 0; $i < $num; $i++)
  176. {
  177. $element = new $classname($db);
  178. $element->fetch($elementarray[$i]);
  179. $element->fetch_thirdparty();
  180. //print $classname;
  181. $var=!$var;
  182. print "<tr $bc[$var]>";
  183. // Ref
  184. print '<td align="left">';
  185. print $element->getNomUrl(1);
  186. print "</td>\n";
  187. // Date
  188. $date=$element->date;
  189. if (empty($date)) $date=$element->datep;
  190. if (empty($date)) $date=$element->date_contrat;
  191. print '<td align="center">'.dol_print_date($date,'day').'</td>';
  192. // Third party
  193. print '<td align="left">';
  194. if (is_object($element->client)) print $element->client->getNomUrl(1,'',48);
  195. print '</td>';
  196. // Amount
  197. if (empty($value['disableamount'])) print '<td align="right">'.(isset($element->total_ht)?price($element->total_ht):'&nbsp;').'</td>';
  198. // Amount
  199. if (empty($value['disableamount'])) print '<td align="right">'.(isset($element->total_ttc)?price($element->total_ttc):'&nbsp;').'</td>';
  200. // Status
  201. print '<td align="right">'.$element->getLibStatut(5).'</td>';
  202. print '</tr>';
  203. $total_ht = $total_ht + $element->total_ht;
  204. $total_ttc = $total_ttc + $element->total_ttc;
  205. }
  206. print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Number").': '.$i.'</td>';
  207. if (empty($value['disableamount'])) print '<td align="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
  208. if (empty($value['disableamount'])) print '<td align="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_ttc).'</td>';
  209. print '<td>&nbsp;</td>';
  210. print '</tr>';
  211. }
  212. print "</table>";
  213. /*
  214. * Barre d'action
  215. */
  216. print '<div class="tabsAction">';
  217. if ($project->statut > 0)
  218. {
  219. if ($project->societe->prospect || $project->societe->client)
  220. {
  221. if ($key == 'propal' && ! empty($conf->propal->enabled) && $user->rights->propale->creer)
  222. {
  223. print '<a class="butAction" href="'.DOL_URL_ROOT.'/comm/addpropal.php?socid='.$project->societe->id.'&amp;action=create&amp;origin='.$project->element.'&amp;originid='.$project->id.'">'.$langs->trans("AddProp").'</a>';
  224. }
  225. if ($key == 'order' && ! empty($conf->commande->enabled) && $user->rights->commande->creer)
  226. {
  227. print '<a class="butAction" href="'.DOL_URL_ROOT.'/commande/fiche.php?socid='.$project->societe->id.'&amp;action=create&amp;origin='.$project->element.'&amp;originid='.$project->id.'">'.$langs->trans("AddCustomerOrder").'</a>';
  228. }
  229. if ($key == 'invoice' && ! empty($conf->facture->enabled) && $user->rights->facture->creer)
  230. {
  231. print '<a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$project->societe->id.'&amp;action=create&amp;origin='.$project->element.'&amp;originid='.$project->id.'">'.$langs->trans("AddCustomerInvoice").'</a>';
  232. }
  233. }
  234. if ($project->societe->fournisseur)
  235. {
  236. if ($key == 'order_supplier' && ! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande->creer)
  237. {
  238. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?socid='.$project->societe->id.'&amp;action=create&amp;origin='.$project->element.'&amp;originid='.$project->id.'">'.$langs->trans("AddSupplierInvoice").'</a>';
  239. }
  240. if ($key == 'invoice_supplier' && ! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->creer)
  241. {
  242. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/commande/fiche.php?socid='.$project->societe->id.'&amp;action=create&amp;origin='.$project->element.'&amp;originid='.$project->id.'">'.$langs->trans("AddSupplierOrder").'</a>';
  243. }
  244. }
  245. }
  246. print '</div>';
  247. }
  248. }
  249. llxFooter();
  250. $db->close();
  251. ?>