element.php 34 KB

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