element.php 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2010 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2012-2016 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  7. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  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 <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/projet/element.php
  24. * \ingroup projet facture
  25. * \brief Page of project referrers
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  34. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  35. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  36. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
  37. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  38. if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  39. if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  40. if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  41. if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  42. if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  43. if (! empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  44. if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  45. if (! empty($conf->don->enabled)) require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  46. $langs->load("projects");
  47. $langs->load("companies");
  48. $langs->load("suppliers");
  49. if (! empty($conf->facture->enabled)) $langs->load("bills");
  50. if (! empty($conf->commande->enabled)) $langs->load("orders");
  51. if (! empty($conf->propal->enabled)) $langs->load("propal");
  52. if (! empty($conf->ficheinter->enabled)) $langs->load("interventions");
  53. if (! empty($conf->deplacement->enabled)) $langs->load("trips");
  54. if (! empty($conf->expensereport->enabled)) $langs->load("trips");
  55. if (! empty($conf->don->enabled)) $langs->load("donations");
  56. $id=GETPOST('id','int');
  57. $ref=GETPOST('ref','alpha');
  58. $action=GETPOST('action','alpha');
  59. $datesrfc=GETPOST('datesrfc');
  60. $dateerfc=GETPOST('dateerfc');
  61. $dates=dol_mktime(0, 0, 0, GETPOST('datesmonth'), GETPOST('datesday'), GETPOST('datesyear'));
  62. $datee=dol_mktime(23, 59, 59, GETPOST('dateemonth'), GETPOST('dateeday'), GETPOST('dateeyear'));
  63. if (empty($dates) && ! empty($datesrfc)) $dates=dol_stringtotime($datesrfc);
  64. if (empty($datee) && ! empty($dateerfc)) $datee=dol_stringtotime($dateerfc);
  65. if (! isset($_POST['datesrfc']) && ! isset($_POST['datesday']) && ! empty($conf->global->PROJECT_LINKED_ELEMENT_DEFAULT_FILTER_YEAR))
  66. {
  67. $new=dol_now();
  68. $tmp=dol_getdate($new);
  69. //$datee=$now
  70. //$dates=dol_time_plus_duree($datee, -1, 'y');
  71. $dates=dol_get_first_day($tmp['year'],1);
  72. }
  73. if ($id == '' && $projectid == '' && $ref == '')
  74. {
  75. dol_print_error('','Bad parameter');
  76. exit;
  77. }
  78. $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
  79. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  80. $projectid=$id; // For backward compatibility
  81. $object = new Project($db);
  82. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  83. // Security check
  84. $socid=$object->socid;
  85. if ($user->societe_id > 0) $socid=$user->societe_id;
  86. $result = restrictedArea($user, 'projet', $projectid, 'projet&project');
  87. $hookmanager->initHooks(array('projectOverview'));
  88. /*
  89. * View
  90. */
  91. $title=$langs->trans("ProjectReferers").' - '.$object->ref.' '.$object->name;
  92. if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/projectnameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->ref.' '.$object->name.' - '.$langs->trans("ProjectReferers");
  93. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  94. llxHeader("",$langs->trans("Referers"),$help_url);
  95. $form = new Form($db);
  96. $formproject=new FormProjets($db);
  97. $formfile = new FormFile($db);
  98. $userstatic=new User($db);
  99. // To verify role of users
  100. $userAccess = $object->restrictedProjectArea($user);
  101. $head=project_prepare_head($object);
  102. dol_fiche_head($head, 'element', $langs->trans("Project"),0,($object->public?'projectpub':'project'));
  103. print '<table class="border" width="100%">';
  104. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php">'.$langs->trans("BackToList").'</a>';
  105. print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>';
  106. // Define a complementary filter for search of next/prev ref.
  107. if (! $user->rights->projet->all->lire)
  108. {
  109. $projectsListId = $object->getProjectsAuthorizedForUser($user,0,0);
  110. $object->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")";
  111. }
  112. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
  113. print '</td></tr>';
  114. print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->title.'</td></tr>';
  115. print '<tr><td>'.$langs->trans("ThirdParty").'</td><td>';
  116. if (! empty($object->thirdparty->id)) print $object->thirdparty->getNomUrl(1);
  117. else print '&nbsp;';
  118. print '</td></tr>';
  119. // Visibility
  120. print '<tr><td>'.$langs->trans("Visibility").'</td><td>';
  121. if ($object->public) print $langs->trans('SharedProject');
  122. else print $langs->trans('PrivateProject');
  123. print '</td></tr>';
  124. // Statut
  125. print '<tr><td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
  126. // Date start
  127. print '<tr><td>'.$langs->trans("DateStart").'</td><td>';
  128. print dol_print_date($object->date_start,'day');
  129. print '</td></tr>';
  130. // Date end
  131. print '<tr><td>'.$langs->trans("DateEnd").'</td><td>';
  132. print dol_print_date($object->date_end,'day');
  133. print '</td></tr>';
  134. if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
  135. {
  136. // Opportunity status
  137. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  138. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  139. if ($code) print $langs->trans("OppStatus".$code);
  140. print '</td></tr>';
  141. // Opportunity Amount
  142. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  143. if (strcmp($object->opp_amount,'')) print price($object->opp_amount,'',$langs,0,0,0,$conf->currency);
  144. print '</td></tr>';
  145. }
  146. // Budget
  147. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  148. if (strcmp($object->budget_amount, '')) print price($object->budget_amount,'',$langs,0,0,0,$conf->currency);
  149. print '</td></tr>';
  150. print '</table>';
  151. dol_fiche_end();
  152. /*
  153. * Referers types
  154. */
  155. $listofreferent=array(
  156. 'propal'=>array(
  157. 'name'=>"Proposals",
  158. 'title'=>"ListProposalsAssociatedProject",
  159. 'class'=>'Propal',
  160. 'table'=>'propal',
  161. 'datefieldname'=>'datep',
  162. 'urlnew'=>DOL_URL_ROOT.'/comm/propal/card.php?action=create&projectid='.$id.'&socid='.$socid,
  163. 'lang'=>'propal',
  164. 'buttonnew'=>'AddProp',
  165. 'testnew'=>$user->rights->propal->creer,
  166. 'test'=>$conf->propal->enabled && $user->rights->propale->lire),
  167. 'order'=>array(
  168. 'name'=>"CustomersOrders",
  169. 'title'=>"ListOrdersAssociatedProject",
  170. 'class'=>'Commande',
  171. 'table'=>'commande',
  172. 'datefieldname'=>'date_commande',
  173. 'urlnew'=>DOL_URL_ROOT.'/commande/card.php?action=create&projectid='.$id.'&socid='.$socid,
  174. 'lang'=>'orders',
  175. 'buttonnew'=>'CreateOrder',
  176. 'testnew'=>$user->rights->commande->creer,
  177. 'test'=>$conf->commande->enabled && $user->rights->commande->lire),
  178. 'invoice'=>array(
  179. 'name'=>"CustomersInvoices",
  180. 'title'=>"ListInvoicesAssociatedProject",
  181. 'class'=>'Facture',
  182. 'margin'=>'add',
  183. 'table'=>'facture',
  184. 'datefieldname'=>'datef',
  185. 'urlnew'=>DOL_URL_ROOT.'/compta/facture.php?action=create&projectid='.$id.'&socid='.$socid,
  186. 'lang'=>'bills',
  187. 'buttonnew'=>'CreateBill',
  188. 'testnew'=>$user->rights->facture->creer,
  189. 'test'=>$conf->facture->enabled && $user->rights->facture->lire),
  190. 'invoice_predefined'=>array(
  191. 'name'=>"PredefinedInvoices",
  192. 'title'=>"ListPredefinedInvoicesAssociatedProject",
  193. 'class'=>'FactureRec',
  194. 'table'=>'facture_rec',
  195. 'datefieldname'=>'datec',
  196. 'urlnew'=>DOL_URL_ROOT.'/compta/facture.php?action=create&projectid='.$id.'&socid='.$socid,
  197. 'lang'=>'bills',
  198. 'buttonnew'=>'CreateBill',
  199. 'testnew'=>$user->rights->facture->creer,
  200. 'test'=>$conf->facture->enabled && $user->rights->facture->lire),
  201. 'proposal_supplier'=>array(
  202. 'name'=>"SuppliersOrders",
  203. 'title'=>"ListSupplierOrdersAssociatedProject",
  204. 'class'=>'CommandeFournisseur',
  205. 'table'=>'commande_fournisseur',
  206. 'datefieldname'=>'date_commande',
  207. 'urlnew'=>DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&projectid='.$id.'&socid='.$socid,
  208. 'lang'=>'supplier_proposal',
  209. 'buttonnew'=>'AddSupplierProposal',
  210. 'testnew'=>$user->rights->supplier_proposal->creer,
  211. 'test'=>$conf->supplier_proposal->enabled && $user->rights->supplier_proposal->lire),
  212. 'order_supplier'=>array(
  213. 'name'=>"SuppliersOrders",
  214. 'title'=>"ListSupplierOrdersAssociatedProject",
  215. 'class'=>'CommandeFournisseur',
  216. 'table'=>'commande_fournisseur',
  217. 'datefieldname'=>'date_commande',
  218. 'urlnew'=>DOL_URL_ROOT.'/fourn/commande/card.php?action=create&projectid='.$id.'&socid='.$socid,
  219. 'lang'=>'suppliers',
  220. 'buttonnew'=>'AddSupplierOrder',
  221. 'testnew'=>$user->rights->fournisseur->commande->creer,
  222. 'test'=>$conf->supplier_order->enabled && $user->rights->fournisseur->commande->lire),
  223. 'invoice_supplier'=>array(
  224. 'name'=>"BillsSuppliers",
  225. 'title'=>"ListSupplierInvoicesAssociatedProject",
  226. 'class'=>'FactureFournisseur',
  227. 'margin'=>'minus',
  228. 'table'=>'facture_fourn',
  229. 'datefieldname'=>'datef',
  230. 'urlnew'=>DOL_URL_ROOT.'/fourn/facture/card.php?action=create&projectid='.$id.'&socid='.$socid,
  231. 'lang'=>'suppliers',
  232. 'buttonnew'=>'AddSupplierInvoice',
  233. 'testnew'=>$user->rights->fournisseur->facture->creer,
  234. 'test'=>$conf->supplier_invoice->enabled && $user->rights->fournisseur->facture->lire),
  235. 'contract'=>array(
  236. 'name'=>"Contracts",
  237. 'title'=>"ListContractAssociatedProject",
  238. 'class'=>'Contrat',
  239. 'table'=>'contrat',
  240. 'datefieldname'=>'date_contrat',
  241. 'urlnew'=>DOL_URL_ROOT.'/contrat/card.php?action=create&projectid='.$id.'&socid='.$socid,
  242. 'lang'=>'contracts',
  243. 'buttonnew'=>'AddContract',
  244. 'testnew'=>$user->rights->contrat->creer,
  245. 'test'=>$conf->contrat->enabled && $user->rights->contrat->lire),
  246. 'intervention'=>array(
  247. 'name'=>"Interventions",
  248. 'title'=>"ListFichinterAssociatedProject",
  249. 'class'=>'Fichinter',
  250. 'table'=>'fichinter',
  251. 'datefieldname'=>'date_valid',
  252. 'disableamount'=>1,
  253. 'urlnew'=>DOL_URL_ROOT.'/fichinter/card.php?action=create&projectid='.$id.'&socid='.$socid,
  254. 'lang'=>'interventions',
  255. 'buttonnew'=>'AddIntervention',
  256. 'testnew'=>$user->rights->ficheinter->creer,
  257. 'test'=>$conf->ficheinter->enabled && $user->rights->ficheinter->lire),
  258. 'trip'=>array(
  259. 'name'=>"TripsAndExpenses",
  260. 'title'=>"ListExpenseReportsAssociatedProject",
  261. 'class'=>'Deplacement',
  262. 'table'=>'deplacement',
  263. 'datefieldname'=>'dated',
  264. 'margin'=>'minus',
  265. 'disableamount'=>1,
  266. 'urlnew'=>DOL_URL_ROOT.'/deplacement/card.php?action=create&projectid='.$id.'&socid='.$socid,
  267. 'lang'=>'trips',
  268. 'buttonnew'=>'AddTrip',
  269. 'testnew'=>$user->rights->deplacement->creer,
  270. 'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire),
  271. 'expensereport'=>array(
  272. 'name'=>"ExpenseReports",
  273. 'title'=>"ListExpenseReportsAssociatedProject",
  274. 'class'=>'ExpenseReportLine',
  275. 'table'=>'expensereport_det',
  276. 'datefieldname'=>'date',
  277. 'margin'=>'minus',
  278. 'disableamount'=>0,
  279. 'urlnew'=>DOL_URL_ROOT.'/expensereport/card.php?action=create&projectid='.$id.'&socid='.$socid,
  280. 'lang'=>'trips',
  281. 'buttonnew'=>'AddTrip',
  282. 'testnew'=>$user->rights->expensereport->creer,
  283. 'test'=>$conf->expensereport->enabled && $user->rights->expensereport->lire),
  284. 'donation'=>array(
  285. 'name'=>"Donation",
  286. 'title'=>"ListDonationsAssociatedProject",
  287. 'class'=>'Don',
  288. 'margin'=>'add',
  289. 'table'=>'don',
  290. 'datefieldname'=>'datedon',
  291. 'disableamount'=>0,
  292. 'urlnew'=>DOL_URL_ROOT.'/don/card.php?action=create&projectid='.$id.'&socid='.$socid,
  293. 'lang'=>'donations',
  294. 'buttonnew'=>'AddDonation',
  295. 'testnew'=>$user->rights->don->creer,
  296. 'test'=>$conf->don->enabled && $user->rights->don->lire),
  297. 'agenda'=>array(
  298. 'name'=>"Agenda",
  299. 'title'=>"ListActionsAssociatedProject",
  300. 'class'=>'ActionComm',
  301. 'table'=>'actioncomm',
  302. 'datefieldname'=>'datep',
  303. 'disableamount'=>1,
  304. 'urlnew'=>DOL_URL_ROOT.'/comm/action/card.php?action=create&projectid='.$id.'&socid='.$socid,
  305. 'lang'=>'agenda',
  306. 'buttonnew'=>'AddEvent',
  307. 'testnew'=>$user->rights->agenda->myactions->create,
  308. 'test'=>$conf->agenda->enabled && $user->rights->agenda->myactions->read),
  309. 'project_task'=>array(
  310. 'name'=>"TaskTimeValorised",
  311. 'title'=>"ListTaskTimeUserProject",
  312. 'class'=>'Task',
  313. 'margin'=>'minus',
  314. 'table'=>'projet_task',
  315. 'datefieldname'=>'task_date',
  316. 'disableamount'=>0,
  317. 'test'=>$conf->projet->enabled && $user->rights->projet->lire && $conf->salaries->enabled && empty($conf->global->PROJECT_HIDE_TASKS)),
  318. );
  319. $parameters=array('listofreferent'=>$listofreferent);
  320. $resHook = $hookmanager->executeHooks('completeListOfReferent',$parameters,$object,$action);
  321. if(!empty($hookmanager->resArray)) {
  322. $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
  323. }
  324. if ($action=="addelement")
  325. {
  326. $tablename = GETPOST("tablename");
  327. $elementselectid = GETPOST("elementselect");
  328. $result=$object->update_element($tablename, $elementselectid);
  329. if ($result<0)
  330. {
  331. setEventMessages($object->error, $object->errors, 'errors');
  332. }
  333. }
  334. elseif ($action == "unlink")
  335. {
  336. $tablename = GETPOST("tablename");
  337. $elementselectid = GETPOST("elementselect");
  338. $result = $object->remove_element($tablename, $elementselectid);
  339. if ($result < 0)
  340. {
  341. setEventMessages($object->error, $object->errors, 'errors');
  342. }
  343. }
  344. $elementuser = new User($db);
  345. $showdatefilter=0;
  346. // Show the filter on date on top of element list
  347. if (! $showdatefilter)
  348. {
  349. print '<div class="center centpercent">';
  350. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$projectid.'" method="post">';
  351. print '<input type="hidden" name="tablename" value="'.$tablename.'">';
  352. print '<input type="hidden" name="action" value="view">';
  353. print '<table class="center"><tr>';
  354. print '<td>'.$langs->trans("From").' ';
  355. print $form->select_date($dates,'dates',0,0,1,'',1,0,1);
  356. print '</td>';
  357. print '<td>'.$langs->trans("to").' ';
  358. print $form->select_date($datee,'datee',0,0,1,'',1,0,1);
  359. print '</td>';
  360. print '<td>';
  361. print '<input type="submit" name="refresh" value="'.$langs->trans("Refresh").'" class="button">';
  362. print '</td>';
  363. print '</tr></table>';
  364. print '</form>';
  365. print '</div>';
  366. $showdatefilter++;
  367. }
  368. // Show balance for whole project
  369. $langs->load("suppliers");
  370. $langs->load("bills");
  371. $langs->load("orders");
  372. $langs->load("proposals");
  373. $langs->load("margins");
  374. print load_fiche_titre($langs->trans("Profit"), '', 'title_accountancy');
  375. print '<table class="noborder" width="100%">';
  376. print '<tr class="liste_titre">';
  377. print '<td align="left" width="200">'.$langs->trans("Element").'</td>';
  378. print '<td align="right" width="100">'.$langs->trans("Number").'</td>';
  379. print '<td align="right" width="100">'.$langs->trans("AmountHT").'</td>';
  380. print '<td align="right" width="100">'.$langs->trans("AmountTTC").'</td>';
  381. print '</tr>';
  382. $var = false;
  383. foreach ($listofreferent as $key => $value)
  384. {
  385. $name=$langs->trans($value['name']);
  386. $title=$value['title'];
  387. $classname=$value['class'];
  388. $tablename=$value['table'];
  389. $datefieldname=$value['datefieldname'];
  390. $qualified=$value['test'];
  391. $margin = $value['margin'];
  392. if ($qualified && isset($margin)) // If this element must be included into profit calculation ($margin is 'minus' or 'plus')
  393. {
  394. $element = new $classname($db);
  395. $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee);
  396. if (count($elementarray)>0 && is_array($elementarray))
  397. {
  398. $total_ht = 0;
  399. $total_ttc = 0;
  400. $num=count($elementarray);
  401. for ($i = 0; $i < $num; $i++)
  402. {
  403. $tmp=explode('_',$elementarray[$i]);
  404. $idofelement=$tmp[0];
  405. $idofelementuser=$tmp[1];
  406. $element->fetch($idofelement);
  407. if ($idofelementuser) $elementuser->fetch($idofelementuser);
  408. if ($tablename != 'expensereport_det' && method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty();
  409. if ($tablename == 'don') $total_ht_by_line=$element->amount;
  410. elseif ($tablename == 'projet_task')
  411. {
  412. if ($idofelementuser)
  413. {
  414. $tmp = $element->getSumOfAmount($elementuser, $dates, $datee);
  415. $total_ht_by_line = price2num($tmp['amount'],'MT');
  416. }
  417. else
  418. {
  419. $tmp = $element->getSumOfAmount('', $dates, $datee);
  420. $total_ht_by_line = price2num($tmp['amount'],'MT');
  421. }
  422. }
  423. else $total_ht_by_line=$element->total_ht;
  424. $total_ht = $total_ht + $total_ht_by_line;
  425. if ($tablename == 'don') $total_ttc_by_line=$element->amount;
  426. elseif ($tablename == 'projet_task')
  427. {
  428. $defaultvat = get_default_tva($mysoc, $mysoc);
  429. $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)),'MT');
  430. }
  431. else $total_ttc_by_line=$element->total_ttc;
  432. $total_ttc = $total_ttc + $total_ttc_by_line;
  433. }
  434. // Calculate margin
  435. if ($margin=="add")
  436. {
  437. $balance_ht+= $total_ht;
  438. $balance_ttc+= $total_ttc;
  439. }
  440. else
  441. {
  442. $balance_ht-= $total_ht;
  443. $balance_ttc-= $total_ttc;
  444. }
  445. // Show $total_ht & $total_ttc -- add a minus when necessary
  446. if ($margin!="add")
  447. {
  448. $total_ht = -$total_ht;
  449. $total_ttc = -$total_ttc;
  450. }
  451. switch ($classname) {
  452. case 'FactureFournisseur':
  453. $newclassname = 'SupplierInvoice';
  454. break;
  455. case 'Facture':
  456. $newclassname = 'Bill';
  457. break;
  458. case 'Propal':
  459. $newclassname = 'CommercialProposal';
  460. break;
  461. case 'Commande':
  462. $newclassname = 'Order';
  463. break;
  464. case 'Expedition':
  465. $newclassname = 'Sending';
  466. break;
  467. case 'Contrat':
  468. $newclassname = 'Contract';
  469. break;
  470. default:
  471. $newclassname = $classname;
  472. }
  473. $var = ! $var;
  474. print '<tr '.$bc[$var].'>';
  475. // Module
  476. print '<td align="left">'.$langs->trans($newclassname).'</td>';
  477. // Nb
  478. print '<td align="right">'.$i.'</td>';
  479. // Amount HT
  480. print '<td align="right">'.price($total_ht).'</td>';
  481. // Amount TTC
  482. print '<td align="right">'.price($total_ttc).'</td>';
  483. print '</tr>';
  484. }
  485. }
  486. }
  487. // and the final balance
  488. print '<tr class="liste_total">';
  489. print '<td align="right" colspan=2 >'.$langs->trans("Profit").'</td>';
  490. print '<td align="right" >'.price($balance_ht).'</td>';
  491. print '<td align="right" >'.price($balance_ttc).'</td>';
  492. print '</tr>';
  493. print "</table>";
  494. print '<br><br>';
  495. print '<br>';
  496. // Detail
  497. foreach ($listofreferent as $key => $value)
  498. {
  499. $title=$value['title'];
  500. $classname=$value['class'];
  501. $tablename=$value['table'];
  502. $datefieldname=$value['datefieldname'];
  503. $qualified=$value['test'];
  504. $langtoload=$value['lang'];
  505. $urlnew=$value['urlnew'];
  506. $buttonnew=$value['buttonnew'];
  507. $testnew=$value['testnew'];
  508. if ($qualified)
  509. {
  510. // If we want the project task array to have details of users
  511. //if ($key == 'project_task') $key = 'project_task_time';
  512. if ($langtoload) $langs->load($langtoload);
  513. $element = new $classname($db);
  514. $addform='';
  515. $idtofilterthirdparty=0;
  516. if (! in_array($tablename, array('facture_fourn', 'commande_fournisseur'))) $idtofilterthirdparty=$object->thirdparty->id;
  517. if (empty($conf->global->PROJECT_LINK_ON_OVERWIEW_DISABLED) && $idtofilterthirdparty > 0)
  518. {
  519. $selectList=$formproject->select_element($tablename, $idtofilterthirdparty, 'minwidth300');
  520. if (! $selectList || ($selectList<0))
  521. {
  522. setEventMessages($formproject->error,$formproject->errors,'errors');
  523. }
  524. elseif($selectList)
  525. {
  526. // Define form with the combo list of elements to link
  527. $addform.='<div class="inline-block valignmiddle">';
  528. $addform.='<form action="'.$_SERVER["PHP_SELF"].'?id='.$projectid.'" method="post">';
  529. $addform.='<input type="hidden" name="tablename" value="'.$tablename.'">';
  530. $addform.='<input type="hidden" name="action" value="addelement">';
  531. $addform.='<input type="hidden" name="datesrfc" value="'.dol_print_date($dates,'dayhourrfc').'">';
  532. $addform.='<input type="hidden" name="dateerfc" value="'.dol_print_date($datee,'dayhourrfc').'">';
  533. $addform.='<table><tr><td>'.$langs->trans("SelectElement").'</td>';
  534. $addform.='<td>'.$selectList.'</td>';
  535. $addform.='<td><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("AddElement")).'"></td>';
  536. $addform.='</tr></table>';
  537. $addform.='</form>';
  538. $addform.='</div>';
  539. }
  540. }
  541. if (empty($conf->global->PROJECT_CREATE_ON_OVERVIEW_DISABLED) && $urlnew)
  542. {
  543. $addform.='<div class="inline-block valignmiddle">';
  544. if ($testnew) $addform.='<a class="buttonxxx" href="'.$urlnew.'">'.($buttonnew?$langs->trans($buttonnew):$langs->trans("Create")).'</a>';
  545. else $addform.='<a class="buttonxxx buttonRefused" disabled="disabled" href="#">'.($buttonnew?$langs->trans($buttonnew):$langs->trans("Create")).'</a>';
  546. $addform.='<div>';
  547. }
  548. print load_fiche_titre($langs->trans($title), $addform, '');
  549. print '<table class="noborder" width="100%">';
  550. print '<tr class="liste_titre">';
  551. // Remove link
  552. print '<td style="width: 24px"></td>';
  553. // Ref
  554. print '<td style="width: 200px">'.$langs->trans("Ref").'</td>';
  555. // Date
  556. print '<td width="100" align="center">';
  557. if (! in_array($tablename, array('projet_task'))) print $langs->trans("Date");
  558. print '</td>';
  559. // Thirdparty or user
  560. print '<td>';
  561. if (in_array($tablename, array('projet_task')) && $key == 'project_task') print ''; // if $key == 'project_task', we don't want details per user
  562. elseif (in_array($tablename, array('expensereport_det','don','projet_task'))) print $langs->trans("User");
  563. else print $langs->trans("ThirdParty");
  564. print '</td>';
  565. // Amount HT
  566. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td align="right" width="120">'.$langs->trans("AmountHT").'</td>';
  567. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td align="right" width="120">'.$langs->trans("Amount").'</td>';
  568. if (empty($value['disableamount'])) print '<td align="right" width="120">'.$langs->trans("AmountHT").'</td>';
  569. else print '<td width="120"></td>';
  570. // Amount TTC
  571. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td align="right" width="120">'.$langs->trans("AmountTTC").'</td>';
  572. if (empty($value['disableamount'])) print '<td align="right" width="120">'.$langs->trans("AmountTTC").'</td>';
  573. else print '<td width="120"></td>';
  574. // Status
  575. if (in_array($tablename, array('projet_task'))) print '<td align="right" width="200">'.$langs->trans("ProgressDeclared").'</td>';
  576. else print '<td align="right" width="200">'.$langs->trans("Status").'</td>';
  577. print '</tr>';
  578. $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee);
  579. if (is_array($elementarray) && count($elementarray)>0)
  580. {
  581. $var=true;
  582. $total_ht = 0;
  583. $total_ttc = 0;
  584. $total_ht_by_third = 0;
  585. $total_ttc_by_third = 0;
  586. $saved_third_id = 0;
  587. $breakline = '';
  588. if (canApplySubtotalOn($tablename))
  589. {
  590. // Sort
  591. $elementarray = sortElementsByClientName($elementarray);
  592. }
  593. $num=count($elementarray);
  594. for ($i = 0; $i < $num; $i++)
  595. {
  596. $tmp=explode('_',$elementarray[$i]);
  597. $idofelement=$tmp[0];
  598. $idofelementuser=$tmp[1];
  599. $element->fetch($idofelement);
  600. if ($idofelementuser) $elementuser->fetch($idofelementuser);
  601. if ($tablename != 'expensereport_det')
  602. {
  603. if(method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty();
  604. }
  605. else
  606. {
  607. $expensereport=new ExpenseReport($db);
  608. $expensereport->fetch($element->fk_expensereport);
  609. }
  610. //print 'xxx'.$tablename;
  611. //print $classname;
  612. if ($breakline && $saved_third_id != $element->thirdparty->id)
  613. {
  614. print $breakline;
  615. $var = true;
  616. $saved_third_id = $element->thirdparty->id;
  617. $breakline = '';
  618. $total_ht_by_third=0;
  619. $total_ttc_by_third=0;
  620. }
  621. $saved_third_id = $element->thirdparty->id;
  622. $qualifiedfortotal=true;
  623. if ($key == 'invoice')
  624. {
  625. if (! empty($element->close_code) && $element->close_code == 'replaced') $qualifiedfortotal=false; // Replacement invoice, do not include into total
  626. }
  627. $var=!$var;
  628. print "<tr ".$bc[$var].">";
  629. // Remove link
  630. print '<td style="width: 24px">';
  631. if ($tablename != 'projet_task')
  632. {
  633. print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $projectid . '&action=unlink&tablename=' . $tablename . '&elementselect=' . $element->id . '">' . img_picto($langs->trans('Unlink'), 'editdelete') . '</a>';
  634. }
  635. print "</td>\n";
  636. // Ref
  637. print '<td align="left">';
  638. if ($tablename == 'expensereport_det')
  639. {
  640. print $expensereport->getNomUrl(1);
  641. }
  642. else
  643. {
  644. if ($element instanceof Task)
  645. {
  646. print $element->getNomUrl(1,'withproject','time');
  647. print ' - '.dol_trunc($element->label, 48);
  648. }
  649. else print $element->getNomUrl(1);
  650. $element_doc = $element->element;
  651. $filename=dol_sanitizeFileName($element->ref);
  652. $filedir=$conf->{$element_doc}->dir_output . '/' . dol_sanitizeFileName($element->ref);
  653. if($element_doc === 'order_supplier') {
  654. $element_doc='commande_fournisseur';
  655. $filedir = $conf->fournisseur->commande->dir_output.'/'.dol_sanitizeFileName($element->ref);
  656. }
  657. else if($element_doc === 'invoice_supplier') {
  658. $element_doc='facture_fournisseur';
  659. $filename = get_exdir($element->id,2,0,0,$this,'product').dol_sanitizeFileName($element->ref);
  660. $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($element->id,2,0,0,null,'invoice_supplier').dol_sanitizeFileName($element->ref);
  661. }
  662. print $formfile->getDocumentsLink($element_doc, $filename, $filedir);
  663. }
  664. print "</td>\n";
  665. // Date
  666. if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order') $date=$element->date_commande;
  667. elseif ($tablename == 'projet_task') $date=''; // We show no date. Showing date of beginning of task make user think it is date of time consumed
  668. else
  669. {
  670. $date=$element->date;
  671. if (empty($date)) $date=$element->datep;
  672. if (empty($date)) $date=$element->date_contrat;
  673. if (empty($date)) $date=$element->datev; //Fiche inter
  674. }
  675. print '<td align="center">'.dol_print_date($date,'day').'</td>';
  676. // Third party or user
  677. print '<td align="left">';
  678. if (is_object($element->thirdparty)) print $element->thirdparty->getNomUrl(1,'',48);
  679. else if ($tablename == 'expensereport_det')
  680. {
  681. $tmpuser=new User($db);
  682. $tmpuser->fetch($expensereport->fk_user_author);
  683. print $tmpuser->getNomUrl(1,'',48);
  684. }
  685. else if ($tablename == 'don')
  686. {
  687. if ($element->fk_user_author > 0)
  688. {
  689. $tmpuser2=new User($db);
  690. $tmpuser2->fetch($element->fk_user_author);
  691. print $tmpuser2->getNomUrl(1,'',48);
  692. }
  693. }
  694. else if ($tablename == 'projet_task' && $key == 'project_task_time') // if $key == 'project_task', we don't want details per user
  695. {
  696. print $elementuser->getNomUrl(1);
  697. }
  698. print '</td>';
  699. // Amount without tax
  700. $warning='';
  701. if (empty($value['disableamount']))
  702. {
  703. if ($tablename == 'don') $total_ht_by_line=$element->amount;
  704. elseif ($tablename == 'projet_task')
  705. {
  706. $tmp = $element->getSumOfAmount($elementuser, $dates, $datee); // $element is a task. $elementuser may be empty
  707. $total_ht_by_line = price2num($tmp['amount'],'MT');
  708. if ($tmp['nblinesnull'] > 0)
  709. {
  710. $langs->load("errors");
  711. $warning=$langs->trans("WarningSomeLinesWithNullHourlyRate", $conf->currency);
  712. }
  713. }
  714. else
  715. {
  716. $total_ht_by_line=$element->total_ht;
  717. }
  718. print '<td align="right">';
  719. if (! $qualifiedfortotal) print '<strike>';
  720. print (isset($total_ht_by_line)?price($total_ht_by_line):'&nbsp;');
  721. if (! $qualifiedfortotal) print '</strike>';
  722. if ($warning) print ' '.img_warning($warning);
  723. print '</td>';
  724. }
  725. else print '<td></td>';
  726. // Amount inc tax
  727. if (empty($value['disableamount']))
  728. {
  729. if ($tablename == 'don') $total_ttc_by_line=$element->amount;
  730. elseif ($tablename == 'projet_task')
  731. {
  732. $defaultvat = get_default_tva($mysoc, $mysoc);
  733. $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)),'MT');
  734. }
  735. else
  736. {
  737. $total_ttc_by_line=$element->total_ttc;
  738. }
  739. print '<td align="right">';
  740. if (! $qualifiedfortotal) print '<strike>';
  741. print (isset($total_ttc_by_line)?price($total_ttc_by_line):'&nbsp;');
  742. if (! $qualifiedfortotal) print '</strike>';
  743. if ($warning) print ' '.img_warning($warning);
  744. print '</td>';
  745. }
  746. else print '<td></td>';
  747. // Status
  748. print '<td align="right">';
  749. if ($tablename == 'expensereport_det')
  750. {
  751. print $expensereport->getLibStatut(5);
  752. }
  753. else if ($element instanceof CommonInvoice)
  754. {
  755. //This applies for Facture and FactureFournisseur
  756. print $element->getLibStatut(5, $element->getSommePaiement());
  757. }
  758. else if ($element instanceof Task)
  759. {
  760. if ($element->progress != '')
  761. {
  762. print $element->progress.' %';
  763. }
  764. }
  765. else
  766. {
  767. print $element->getLibStatut(5);
  768. }
  769. print '</td>';
  770. print '</tr>';
  771. if ($qualifiedfortotal)
  772. {
  773. $total_ht = $total_ht + $total_ht_by_line;
  774. $total_ttc = $total_ttc + $total_ttc_by_line;
  775. $total_ht_by_third += $total_ht_by_line;
  776. $total_ttc_by_third += $total_ttc_by_line;
  777. }
  778. if (canApplySubtotalOn($tablename))
  779. {
  780. $breakline='<tr class="liste_total">';
  781. $breakline.='<td colspan="2">';
  782. $breakline.='</td>';
  783. $breakline.='<td>';
  784. $breakline.='</td>';
  785. $breakline.='<td class="right">';
  786. $breakline.=$langs->trans('SubTotal').' : ';
  787. if (is_object($element->thirdparty)) $breakline.=$element->thirdparty->getNomUrl(0,'',48);
  788. $breakline.='</td>';
  789. $breakline.='<td align="right">'.price($total_ht_by_third).'</td>';
  790. $breakline.='<td align="right">'.price($total_ttc_by_third).'</td>';
  791. $breakline.='<td></td>';
  792. $breakline.='</tr>';
  793. }
  794. //var_dump($element->thirdparty->name.' - '.$saved_third_id.' - '.$element->thirdparty->id);
  795. }
  796. if ($breakline) print $breakline;
  797. print '<tr class="liste_total"><td colspan="4">'.$langs->trans("Number").': '.$i.'</td>';
  798. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td align="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
  799. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td align="right" width="100">'.$langs->trans("Total").' : '.price($total_ht).'</td>';
  800. if (empty($value['disableamount'])) print '<td align="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
  801. else print '<td></td>';
  802. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td align="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_ttc).'</td>';
  803. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td align="right" width="100"></td>';
  804. if (empty($value['disableamount'])) print '<td align="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_ttc).'</td>';
  805. else print '<td></td>';
  806. print '<td>&nbsp;</td>';
  807. print '</tr>';
  808. }
  809. else // error
  810. {
  811. print $elementarray;
  812. }
  813. print "</table>";
  814. print "<br>\n";
  815. }
  816. }
  817. // Enhance with select2
  818. $nodatarole='';
  819. if ($conf->use_javascript_ajax)
  820. {
  821. include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
  822. $comboenhancement = ajax_combobox('.elementselect');
  823. $out.=$comboenhancement;
  824. $nodatarole=($comboenhancement?' data-role="none"':'');
  825. print $comboenhancement;
  826. }
  827. llxFooter();
  828. $db->close();
  829. /**
  830. * Return if we should do a group by customer with sub-total
  831. *
  832. * @param string $tablename Name of table
  833. * @return boolean True to tell to make a group by sub-total
  834. */
  835. function canApplySubtotalOn($tablename)
  836. {
  837. global $conf;
  838. if (empty($conf->global->PROJECT_ADD_SUBTOTAL_LINES)) return false;
  839. return in_array($tablename, array('facture_fourn', 'commande_fournisseur'));
  840. }
  841. /**
  842. * sortElementsByClientName
  843. *
  844. * @param array $elementarray Element array
  845. * @return array Element array sorted
  846. */
  847. function sortElementsByClientName($elementarray)
  848. {
  849. global $db, $classname;
  850. $element = new $classname($db);
  851. $clientname = array();
  852. foreach ($elementarray as $key => $id) // id = id of object
  853. {
  854. if (empty($clientname[$id]))
  855. {
  856. $element->fetch($id);
  857. $element->fetch_thirdparty();
  858. $clientname[$id] = $element->thirdparty->name;
  859. }
  860. }
  861. //var_dump($clientname);
  862. asort($clientname); // sort on name
  863. $elementarray = array();
  864. foreach ($clientname as $id => $name)
  865. {
  866. $elementarray[] = $id;
  867. }
  868. return $elementarray;
  869. }