element.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  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@inodbox.com>
  5. * Copyright (C) 2012-2016 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2015-2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  8. * Copyright (C) 2016 Josep Lluís Amador <joseplluis@lliuretic.cat>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/projet/element.php
  25. * \ingroup projet
  26. * \brief Page of project referrers
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  36. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  37. if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
  38. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  39. if (! empty($conf->supplier_proposal->enabled)) require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php';
  40. if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  41. if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  42. if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  43. if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  44. if (! empty($conf->expedition->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
  45. if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php';
  46. if (! empty($conf->expensereport->enabled)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  47. if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  48. if (! empty($conf->don->enabled)) require_once DOL_DOCUMENT_ROOT.'/don/class/don.class.php';
  49. if (! empty($conf->loan->enabled)) require_once DOL_DOCUMENT_ROOT.'/loan/class/loan.class.php';
  50. if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
  51. if (! empty($conf->tax->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php';
  52. if (! empty($conf->banque->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/paymentvarious.class.php';
  53. if (! empty($conf->salaries->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php';
  54. // Load translation files required by the page
  55. $langs->loadLangs(array('projects', 'companies', 'suppliers', 'compta'));
  56. if (! empty($conf->facture->enabled)) $langs->load("bills");
  57. if (! empty($conf->commande->enabled)) $langs->load("orders");
  58. if (! empty($conf->propal->enabled)) $langs->load("propal");
  59. if (! empty($conf->ficheinter->enabled)) $langs->load("interventions");
  60. if (! empty($conf->deplacement->enabled)) $langs->load("trips");
  61. if (! empty($conf->expensereport->enabled)) $langs->load("trips");
  62. if (! empty($conf->don->enabled)) $langs->load("donations");
  63. if (! empty($conf->loan->enabled)) $langs->load("loan");
  64. if (! empty($conf->salaries->enabled)) $langs->load("salaries");
  65. $id=GETPOST('id','int');
  66. $ref=GETPOST('ref','alpha');
  67. $action=GETPOST('action','alpha');
  68. $datesrfc=GETPOST('datesrfc');
  69. $dateerfc=GETPOST('dateerfc');
  70. $dates=dol_mktime(0, 0, 0, GETPOST('datesmonth'), GETPOST('datesday'), GETPOST('datesyear'));
  71. $datee=dol_mktime(23, 59, 59, GETPOST('dateemonth'), GETPOST('dateeday'), GETPOST('dateeyear'));
  72. if (empty($dates) && ! empty($datesrfc)) $dates=dol_stringtotime($datesrfc);
  73. if (empty($datee) && ! empty($dateerfc)) $datee=dol_stringtotime($dateerfc);
  74. if (! isset($_POST['datesrfc']) && ! isset($_POST['datesday']) && ! empty($conf->global->PROJECT_LINKED_ELEMENT_DEFAULT_FILTER_YEAR))
  75. {
  76. $new=dol_now();
  77. $tmp=dol_getdate($new);
  78. //$datee=$now
  79. //$dates=dol_time_plus_duree($datee, -1, 'y');
  80. $dates=dol_get_first_day($tmp['year'],1);
  81. }
  82. if ($id == '' && $projectid == '' && $ref == '')
  83. {
  84. dol_print_error('','Bad parameter');
  85. exit;
  86. }
  87. $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
  88. //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
  89. $projectid=$id; // For backward compatibility
  90. $object = new Project($db);
  91. include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once
  92. if(! empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT) && method_exists($object, 'fetchComments') && empty($object->comments)) $object->fetchComments();
  93. // Security check
  94. $socid=$object->socid;
  95. //if ($user->societe_id > 0) $socid = $user->societe_id; // For external user, no check is done on company because readability is managed by public status of project and assignement.
  96. $result = restrictedArea($user, 'projet', $projectid, 'projet&project');
  97. $hookmanager->initHooks(array('projectOverview'));
  98. /*
  99. * View
  100. */
  101. $title=$langs->trans("ProjectReferers").' - '.$object->ref.' '.$object->name;
  102. 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");
  103. $help_url="EN:Module_Projects|FR:Module_Projets|ES:M&oacute;dulo_Proyectos";
  104. llxHeader("",$langs->trans("Referers"),$help_url);
  105. $form = new Form($db);
  106. $formproject=new FormProjets($db);
  107. $formfile = new FormFile($db);
  108. $userstatic=new User($db);
  109. // To verify role of users
  110. $userAccess = $object->restrictedProjectArea($user);
  111. $head=project_prepare_head($object);
  112. dol_fiche_head($head, 'element', $langs->trans("Project"), -1, ($object->public?'projectpub':'project'));
  113. // Project card
  114. $linkback = '<a href="'.DOL_URL_ROOT.'/projet/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  115. $morehtmlref='<div class="refidno">';
  116. // Title
  117. $morehtmlref.=$object->title;
  118. // Thirdparty
  119. if ($object->thirdparty->id > 0)
  120. {
  121. $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1, 'project');
  122. }
  123. $morehtmlref.='</div>';
  124. // Define a complementary filter for search of next/prev ref.
  125. if (! $user->rights->projet->all->lire)
  126. {
  127. $objectsListId = $object->getProjectsAuthorizedForUser($user,0,0);
  128. $object->next_prev_filter=" te.rowid in (".(count($objectsListId)?join(',',array_keys($objectsListId)):'0').")";
  129. }
  130. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  131. print '<div class="fichecenter">';
  132. print '<div class="fichehalfleft">';
  133. print '<div class="underbanner clearboth"></div>';
  134. print '<table class="border" width="100%">';
  135. // Visibility
  136. print '<tr><td class="titlefield">'.$langs->trans("Visibility").'</td><td>';
  137. if ($object->public) print $langs->trans('SharedProject');
  138. else print $langs->trans('PrivateProject');
  139. print '</td></tr>';
  140. if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
  141. {
  142. // Opportunity status
  143. print '<tr><td>'.$langs->trans("OpportunityStatus").'</td><td>';
  144. $code = dol_getIdFromCode($db, $object->opp_status, 'c_lead_status', 'rowid', 'code');
  145. if ($code) print $langs->trans("OppStatus".$code);
  146. print '</td></tr>';
  147. // Opportunity percent
  148. print '<tr><td>'.$langs->trans("OpportunityProbability").'</td><td>';
  149. if (strcmp($object->opp_percent,'')) print price($object->opp_percent,'',$langs,1,0).' %';
  150. print '</td></tr>';
  151. // Opportunity Amount
  152. print '<tr><td>'.$langs->trans("OpportunityAmount").'</td><td>';
  153. if (strcmp($object->opp_amount,'')) print price($object->opp_amount,'',$langs,1,0,0,$conf->currency);
  154. print '</td></tr>';
  155. }
  156. // Date start - end
  157. print '<tr><td>'.$langs->trans("DateStart").' - '.$langs->trans("DateEnd").'</td><td>';
  158. $start = dol_print_date($object->date_start,'day');
  159. print ($start?$start:'?');
  160. $end = dol_print_date($object->date_end,'day');
  161. print ' - ';
  162. print ($end?$end:'?');
  163. if ($object->hasDelay()) print img_warning("Late");
  164. print '</td></tr>';
  165. // Budget
  166. print '<tr><td>'.$langs->trans("Budget").'</td><td>';
  167. if (strcmp($object->budget_amount, '')) print price($object->budget_amount,'',$langs,1,0,0,$conf->currency);
  168. print '</td></tr>';
  169. // Other attributes
  170. $cols = 2;
  171. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
  172. print '</table>';
  173. print '</div>';
  174. print '<div class="fichehalfright">';
  175. print '<div class="ficheaddleft">';
  176. print '<div class="underbanner clearboth"></div>';
  177. print '<table class="border" width="100%">';
  178. // Description
  179. print '<td class="titlefield tdtop">'.$langs->trans("Description").'</td><td>';
  180. print nl2br($object->description);
  181. print '</td></tr>';
  182. // Bill time
  183. if (empty($conf->global->PROJECT_HIDE_TASKS) && ! empty($conf->global->PROJECT_BILL_TIME_SPENT))
  184. {
  185. print '<tr><td>'.$langs->trans("BillTime").'</td><td>';
  186. print yn($object->bill_time);
  187. print '</td></tr>';
  188. }
  189. // Categories
  190. if($conf->categorie->enabled) {
  191. print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td>';
  192. print $form->showCategories($object->id,'project',1);
  193. print "</td></tr>";
  194. }
  195. print '</table>';
  196. print '</div>';
  197. print '</div>';
  198. print '</div>';
  199. print '<div class="clearboth"></div>';
  200. dol_fiche_end();
  201. print '<br>';
  202. /*
  203. * Referers types
  204. */
  205. $listofreferent=array(
  206. 'propal'=>array(
  207. 'name'=>"Proposals",
  208. 'title'=>"ListProposalsAssociatedProject",
  209. 'class'=>'Propal',
  210. 'table'=>'propal',
  211. 'datefieldname'=>'datep',
  212. 'urlnew'=>DOL_URL_ROOT.'/comm/propal/card.php?action=create&origin=project&originid='.$id.'&socid='.$socid,
  213. 'lang'=>'propal',
  214. 'buttonnew'=>'AddProp',
  215. 'testnew'=>$user->rights->propal->creer,
  216. 'test'=>$conf->propal->enabled && $user->rights->propale->lire),
  217. 'order'=>array(
  218. 'name'=>"CustomersOrders",
  219. 'title'=>"ListOrdersAssociatedProject",
  220. 'class'=>'Commande',
  221. 'table'=>'commande',
  222. 'datefieldname'=>'date_commande',
  223. 'urlnew'=>DOL_URL_ROOT.'/commande/card.php?action=create&projectid='.$id.'&socid='.$socid,
  224. 'lang'=>'orders',
  225. 'buttonnew'=>'CreateOrder',
  226. 'testnew'=>$user->rights->commande->creer,
  227. 'test'=>$conf->commande->enabled && $user->rights->commande->lire),
  228. 'invoice'=>array(
  229. 'name'=>"CustomersInvoices",
  230. 'title'=>"ListInvoicesAssociatedProject",
  231. 'class'=>'Facture',
  232. 'margin'=>'add',
  233. 'table'=>'facture',
  234. 'datefieldname'=>'datef',
  235. 'urlnew'=>DOL_URL_ROOT.'/compta/facture/card.php?action=create&projectid='.$id.'&socid='.$socid,
  236. 'lang'=>'bills',
  237. 'buttonnew'=>'CreateBill',
  238. 'testnew'=>$user->rights->facture->creer,
  239. 'test'=>$conf->facture->enabled && $user->rights->facture->lire),
  240. 'invoice_predefined'=>array(
  241. 'name'=>"PredefinedInvoices",
  242. 'title'=>"ListPredefinedInvoicesAssociatedProject",
  243. 'class'=>'FactureRec',
  244. 'table'=>'facture_rec',
  245. 'datefieldname'=>'datec',
  246. 'urlnew'=>DOL_URL_ROOT.'/compta/facture/card.php?action=create&projectid='.$id.'&socid='.$socid,
  247. 'lang'=>'bills',
  248. 'buttonnew'=>'CreateBill',
  249. 'testnew'=>$user->rights->facture->creer,
  250. 'test'=>$conf->facture->enabled && $user->rights->facture->lire),
  251. 'proposal_supplier'=>array(
  252. 'name'=>"SuppliersProposals",
  253. 'title'=>"ListSupplierProposalsAssociatedProject",
  254. 'class'=>'SupplierProposal',
  255. 'table'=>'supplier_proposal',
  256. 'datefieldname'=>'date_valid',
  257. 'urlnew'=>DOL_URL_ROOT.'/supplier_proposal/card.php?action=create&projectid='.$id, // No socid parameter here, the socid is often the customer and we create a supplier object
  258. 'lang'=>'supplier_proposal',
  259. 'buttonnew'=>'AddSupplierProposal',
  260. 'testnew'=>$user->rights->supplier_proposal->creer,
  261. 'test'=>$conf->supplier_proposal->enabled && $user->rights->supplier_proposal->lire),
  262. 'order_supplier'=>array(
  263. 'name'=>"SuppliersOrders",
  264. 'title'=>"ListSupplierOrdersAssociatedProject",
  265. 'class'=>'CommandeFournisseur',
  266. 'table'=>'commande_fournisseur',
  267. 'datefieldname'=>'date_commande',
  268. 'urlnew'=>DOL_URL_ROOT.'/fourn/commande/card.php?action=create&projectid='.$id, // No socid parameter here, the socid is often the customer and we create a supplier object
  269. 'lang'=>'suppliers',
  270. 'buttonnew'=>'AddSupplierOrder',
  271. 'testnew'=>$user->rights->fournisseur->commande->creer,
  272. 'test'=>$conf->supplier_order->enabled && $user->rights->fournisseur->commande->lire),
  273. 'invoice_supplier'=>array(
  274. 'name'=>"BillsSuppliers",
  275. 'title'=>"ListSupplierInvoicesAssociatedProject",
  276. 'class'=>'FactureFournisseur',
  277. 'margin'=>'minus',
  278. 'table'=>'facture_fourn',
  279. 'datefieldname'=>'datef',
  280. 'urlnew'=>DOL_URL_ROOT.'/fourn/facture/card.php?action=create&projectid='.$id, // No socid parameter here, the socid is often the customer and we create a supplier object
  281. 'lang'=>'suppliers',
  282. 'buttonnew'=>'AddSupplierInvoice',
  283. 'testnew'=>$user->rights->fournisseur->facture->creer,
  284. 'test'=>$conf->supplier_invoice->enabled && $user->rights->fournisseur->facture->lire),
  285. 'contract'=>array(
  286. 'name'=>"Contracts",
  287. 'title'=>"ListContractAssociatedProject",
  288. 'class'=>'Contrat',
  289. 'table'=>'contrat',
  290. 'datefieldname'=>'date_contrat',
  291. 'urlnew'=>DOL_URL_ROOT.'/contrat/card.php?action=create&projectid='.$id.'&socid='.$socid,
  292. 'lang'=>'contracts',
  293. 'buttonnew'=>'AddContract',
  294. 'testnew'=>$user->rights->contrat->creer,
  295. 'test'=>$conf->contrat->enabled && $user->rights->contrat->lire),
  296. 'intervention'=>array(
  297. 'name'=>"Interventions",
  298. 'title'=>"ListFichinterAssociatedProject",
  299. 'class'=>'Fichinter',
  300. 'table'=>'fichinter',
  301. 'datefieldname'=>'date_valid',
  302. 'disableamount'=>0,
  303. 'margin'=>'minus',
  304. 'urlnew'=>DOL_URL_ROOT.'/fichinter/card.php?action=create&origin=project&originid='.$id.'&socid='.$socid,
  305. 'lang'=>'interventions',
  306. 'buttonnew'=>'AddIntervention',
  307. 'testnew'=>$user->rights->ficheinter->creer,
  308. 'test'=>$conf->ficheinter->enabled && $user->rights->ficheinter->lire),
  309. 'shipping'=>array(
  310. 'name'=>"Shippings",
  311. 'title'=>"ListShippingAssociatedProject",
  312. 'class'=>'Expedition',
  313. 'table'=>'expedition',
  314. 'datefieldname'=>'date_valid',
  315. 'urlnew'=>DOL_URL_ROOT.'/expedition/card.php?action=create&origin=project&originid='.$id.'&socid='.$socid,
  316. 'lang'=>'sendings',
  317. 'buttonnew'=>'CreateShipment',
  318. 'testnew'=>0,
  319. 'test'=>$conf->expedition->enabled && $user->rights->expedition->lire),
  320. 'trip'=>array(
  321. 'name'=>"TripsAndExpenses",
  322. 'title'=>"ListExpenseReportsAssociatedProject",
  323. 'class'=>'Deplacement',
  324. 'table'=>'deplacement',
  325. 'datefieldname'=>'dated',
  326. 'margin'=>'minus',
  327. 'disableamount'=>1,
  328. 'urlnew'=>DOL_URL_ROOT.'/deplacement/card.php?action=create&projectid='.$id.'&socid='.$socid,
  329. 'lang'=>'trips',
  330. 'buttonnew'=>'AddTrip',
  331. 'testnew'=>$user->rights->deplacement->creer,
  332. 'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire),
  333. 'expensereport'=>array(
  334. 'name'=>"ExpenseReports",
  335. 'title'=>"ListExpenseReportsAssociatedProject",
  336. 'class'=>'ExpenseReportLine',
  337. 'table'=>'expensereport_det',
  338. 'datefieldname'=>'date',
  339. 'margin'=>'minus',
  340. 'disableamount'=>0,
  341. 'urlnew'=>DOL_URL_ROOT.'/expensereport/card.php?action=create&projectid='.$id.'&socid='.$socid,
  342. 'lang'=>'trips',
  343. 'buttonnew'=>'AddTrip',
  344. 'testnew'=>$user->rights->expensereport->creer,
  345. 'test'=>$conf->expensereport->enabled && $user->rights->expensereport->lire),
  346. 'donation'=>array(
  347. 'name'=>"Donation",
  348. 'title'=>"ListDonationsAssociatedProject",
  349. 'class'=>'Don',
  350. 'margin'=>'add',
  351. 'table'=>'don',
  352. 'datefieldname'=>'datedon',
  353. 'disableamount'=>0,
  354. 'urlnew'=>DOL_URL_ROOT.'/don/card.php?action=create&projectid='.$id.'&socid='.$socid,
  355. 'lang'=>'donations',
  356. 'buttonnew'=>'AddDonation',
  357. 'testnew'=>$user->rights->don->creer,
  358. 'test'=>$conf->don->enabled && $user->rights->don->lire),
  359. 'loan'=>array(
  360. 'name'=>"Loan",
  361. 'title'=>"ListLoanAssociatedProject",
  362. 'class'=>'Loan',
  363. 'margin'=>'add',
  364. 'table'=>'loan',
  365. 'datefieldname'=>'datestart',
  366. 'disableamount'=>0,
  367. 'urlnew'=>DOL_URL_ROOT.'/loan/card.php?action=create&projectid='.$id.'&socid='.$socid,
  368. 'lang'=>'loan',
  369. 'buttonnew'=>'AddLoan',
  370. 'testnew'=>$user->rights->loan->write,
  371. 'test'=>$conf->loan->enabled && $user->rights->loan->read),
  372. 'chargesociales'=>array(
  373. 'name'=>"SocialContribution",
  374. 'title'=>"ListSocialContributionAssociatedProject",
  375. 'class'=>'ChargeSociales',
  376. 'margin'=>'add',
  377. 'table'=>'chargesociales',
  378. 'datefieldname'=>'date_ech',
  379. 'disableamount'=>0,
  380. 'urlnew'=>DOL_URL_ROOT.'/compta/sociales/card.php?action=create&projectid='.$id,
  381. 'lang'=>'compta',
  382. 'buttonnew'=>'AddSocialContribution',
  383. 'testnew'=>$user->rights->tax->charges->lire,
  384. 'test'=>$conf->tax->enabled && $user->rights->tax->charges->lire),
  385. 'project_task'=>array(
  386. 'name'=>"TaskTimeSpent",
  387. 'title'=>"ListTaskTimeUserProject",
  388. 'class'=>'Task',
  389. 'margin'=>'minus',
  390. 'table'=>'projet_task',
  391. 'datefieldname'=>'task_date',
  392. 'disableamount'=>0,
  393. 'urlnew'=>DOL_URL_ROOT.'/projet/tasks.php?id='.$id,
  394. 'buttonnew'=>'AddTimeSpent',
  395. 'testnew'=>$user->rights->projet->creer,
  396. 'test'=>($conf->projet->enabled && $user->rights->projet->lire && empty($conf->global->PROJECT_HIDE_TASKS))),
  397. 'stock_mouvement'=>array(
  398. 'name'=>"MouvementStockAssociated",
  399. 'title'=>"ListMouvementStockProject",
  400. 'class'=>'MouvementStock',
  401. 'margin'=>'minus',
  402. 'table'=>'stock_mouvement',
  403. 'datefieldname'=>'datem',
  404. 'disableamount'=>0,
  405. 'test'=>($conf->stock->enabled && $user->rights->stock->mouvement->lire && ! empty($conf->global->STOCK_MOVEMENT_INTO_PROJECT_OVERVIEW))),
  406. 'salaries'=>array(
  407. 'name'=>"Salaries",
  408. 'title'=>"ListSalariesAssociatedProject",
  409. 'class'=>'PaymentSalary',
  410. 'table'=>'payment_salary',
  411. 'datefieldname'=>'datev',
  412. 'margin'=>'minus',
  413. 'disableamount'=>0,
  414. 'urlnew'=>DOL_URL_ROOT.'/compta/salaries/card.php?action=create&projectid='.$id,
  415. 'lang'=>'salaries',
  416. 'buttonnew'=>'AddSalaryPayment',
  417. 'testnew'=>$user->rights->salaries->write,
  418. 'test'=>$conf->salaries->enabled && $user->rights->salaries->read),
  419. 'variouspayment'=>array(
  420. 'name'=>"VariousPayments",
  421. 'title'=>"ListVariousPaymentsAssociatedProject",
  422. 'class'=>'PaymentVarious',
  423. 'table'=>'payment_various',
  424. 'datefieldname'=>'datev',
  425. 'margin'=>'minus',
  426. 'disableamount'=>0,
  427. 'urlnew'=>DOL_URL_ROOT.'/compta/bank/various_payment/card.php?action=create&projectid='.$id.'&socid='.$socid,
  428. 'lang'=>'banks',
  429. 'buttonnew'=>'AddVariousPayment',
  430. 'testnew'=>$user->rights->banque->modifier,
  431. 'test'=>$conf->banque->enabled && $user->rights->banque->lire),
  432. /* No need for this, available on dedicated tab "Agenda/Events"
  433. 'agenda'=>array(
  434. 'name'=>"Agenda",
  435. 'title'=>"ListActionsAssociatedProject",
  436. 'class'=>'ActionComm',
  437. 'table'=>'actioncomm',
  438. 'datefieldname'=>'datep',
  439. 'disableamount'=>1,
  440. 'urlnew'=>DOL_URL_ROOT.'/comm/action/card.php?action=create&projectid='.$id.'&socid='.$socid,
  441. 'lang'=>'agenda',
  442. 'buttonnew'=>'AddEvent',
  443. 'testnew'=>$user->rights->agenda->myactions->create,
  444. 'test'=>$conf->agenda->enabled && $user->rights->agenda->myactions->read),
  445. */
  446. );
  447. $parameters=array('listofreferent'=>$listofreferent);
  448. $resHook = $hookmanager->executeHooks('completeListOfReferent', $parameters, $object, $action);
  449. if(!empty($hookmanager->resArray)) {
  450. $listofreferent = array_merge($listofreferent, $hookmanager->resArray);
  451. }
  452. if ($action=="addelement")
  453. {
  454. $tablename = GETPOST("tablename");
  455. $elementselectid = GETPOST("elementselect");
  456. $result=$object->update_element($tablename, $elementselectid);
  457. if ($result<0)
  458. {
  459. setEventMessages($object->error, $object->errors, 'errors');
  460. }
  461. }
  462. elseif ($action == "unlink")
  463. {
  464. $tablename = GETPOST("tablename");
  465. $elementselectid = GETPOST("elementselect");
  466. $result = $object->remove_element($tablename, $elementselectid);
  467. if ($result < 0)
  468. {
  469. setEventMessages($object->error, $object->errors, 'errors');
  470. }
  471. }
  472. $elementuser = new User($db);
  473. $showdatefilter=0;
  474. // Show the filter on date on top of element list
  475. if (! $showdatefilter)
  476. {
  477. print '<div class="center centpercent">';
  478. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$projectid.'" method="post">';
  479. print '<input type="hidden" name="tablename" value="'.$tablename.'">';
  480. print '<input type="hidden" name="action" value="view">';
  481. print '<table class="center"><tr>';
  482. print '<td>'.$langs->trans("From").' ';
  483. print $form->selectDate($dates, 'dates', 0, 0, 1, '', 1, 0);
  484. print '</td>';
  485. print '<td>'.$langs->trans("to").' ';
  486. print $form->selectDate($datee, 'datee', 0, 0, 1, '', 1, 0);
  487. print '</td>';
  488. print '<td>';
  489. print '<input type="submit" name="refresh" value="'.$langs->trans("Refresh").'" class="button">';
  490. print '</td>';
  491. print '</tr></table>';
  492. print '</form>';
  493. print '</div>';
  494. $showdatefilter++;
  495. }
  496. // Show balance for whole project
  497. $langs->loadLangs(array("suppliers", "bills", "orders", "proposals", "margins"));
  498. if (!empty($conf->stock->enabled)) $langs->load('stocks');
  499. print load_fiche_titre($langs->trans("Profit"), '', 'title_accountancy');
  500. print '<table class="noborder" width="100%">';
  501. print '<tr class="liste_titre">';
  502. print '<td align="left" width="200">'.$langs->trans("Element").'</td>';
  503. print '<td align="right" width="100">'.$langs->trans("Number").'</td>';
  504. print '<td align="right" width="100">'.$langs->trans("AmountHT").'</td>';
  505. print '<td align="right" width="100">'.$langs->trans("AmountTTC").'</td>';
  506. print '</tr>';
  507. foreach ($listofreferent as $key => $value)
  508. {
  509. $name=$langs->trans($value['name']);
  510. $title=$value['title'];
  511. $classname=$value['class'];
  512. $tablename=$value['table'];
  513. $datefieldname=$value['datefieldname'];
  514. $qualified=$value['test'];
  515. $margin = $value['margin'];
  516. $project_field = $value['project_field'];
  517. if ($qualified && isset($margin)) // If this element must be included into profit calculation ($margin is 'minus' or 'plus')
  518. {
  519. $element = new $classname($db);
  520. $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee, !empty($project_field)?$project_field:'fk_projet');
  521. if (count($elementarray)>0 && is_array($elementarray))
  522. {
  523. $total_ht = 0;
  524. $total_ttc = 0;
  525. $num=count($elementarray);
  526. for ($i = 0; $i < $num; $i++)
  527. {
  528. $tmp=explode('_',$elementarray[$i]);
  529. $idofelement=$tmp[0];
  530. $idofelementuser=$tmp[1];
  531. $element->fetch($idofelement);
  532. if ($idofelementuser) $elementuser->fetch($idofelementuser);
  533. // Special cases
  534. if ($tablename != 'expensereport_det' && method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty();
  535. if ($tablename == 'don' || $tablename == 'chargesociales') $total_ht_by_line=$element->amount;
  536. elseif ($tablename == 'stock_mouvement') $total_ht_by_line=$element->price*abs($element->qty);
  537. elseif($tablename == 'fichinter') $total_ht_by_line=$element->getAmount();
  538. elseif ($tablename == 'projet_task')
  539. {
  540. if ($idofelementuser)
  541. {
  542. $tmp = $element->getSumOfAmount($elementuser, $dates, $datee);
  543. $total_ht_by_line = price2num($tmp['amount'],'MT');
  544. }
  545. else
  546. {
  547. $tmp = $element->getSumOfAmount('', $dates, $datee);
  548. $total_ht_by_line = price2num($tmp['amount'],'MT');
  549. }
  550. }
  551. else $total_ht_by_line=$element->total_ht;
  552. $qualifiedfortotal=true;
  553. if ($key == 'invoice')
  554. {
  555. if (! empty($element->close_code) && $element->close_code == 'replaced') $qualifiedfortotal=false; // Replacement invoice, do not include into total
  556. }
  557. if ($key == 'propal')
  558. {
  559. if ($element->statut == Propal::STATUS_NOTSIGNED) $qualifiedfortotal=false; // Refused proposal must not be included in total
  560. }
  561. if ($qualifiedfortotal) $total_ht = $total_ht + $total_ht_by_line;
  562. if ($tablename == 'don' || $tablename == 'chargesociales') $total_ttc_by_line=$element->amount;
  563. elseif($tablename == 'fichinter') $total_ttc_by_line=$element->getAmount();
  564. elseif ($tablename == 'stock_mouvement') $total_ttc_by_line=$element->price*abs($element->qty);
  565. elseif ($tablename == 'projet_task')
  566. {
  567. $defaultvat = get_default_tva($mysoc, $mysoc);
  568. $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)),'MT');
  569. }
  570. else $total_ttc_by_line=$element->total_ttc;
  571. if ($qualifiedfortotal) $total_ttc = $total_ttc + $total_ttc_by_line;
  572. }
  573. // Each element with at least one line is output
  574. $qualifiedforfinalprofit=true;
  575. if ($key == 'intervention' && empty($conf->global->PROJECT_INCLUDE_INTERVENTION_AMOUNT_IN_PROFIT)) $qualifiedforfinalprofit=false;
  576. //var_dump($key);
  577. // Calculate margin
  578. if ($qualifiedforfinalprofit)
  579. {
  580. if ($margin=="add")
  581. {
  582. $balance_ht+= $total_ht;
  583. $balance_ttc+= $total_ttc;
  584. }
  585. else
  586. {
  587. $balance_ht-= $total_ht;
  588. $balance_ttc-= $total_ttc;
  589. }
  590. // Show $total_ht & $total_ttc -- add a minus when necessary
  591. if ($margin!="add")
  592. {
  593. $total_ht = -$total_ht;
  594. $total_ttc = -$total_ttc;
  595. }
  596. }
  597. print '<tr class="oddeven">';
  598. // Module
  599. print '<td class="left">'.$name.'</td>';
  600. // Nb
  601. print '<td align="right">'.$i.'</td>';
  602. // Amount HT
  603. print '<td align="right">';
  604. if (! $qualifiedforfinalprofit) print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>';
  605. else print price($total_ht);
  606. print '</td>';
  607. // Amount TTC
  608. print '<td align="right">';
  609. if (! $qualifiedforfinalprofit) print '<span class="opacitymedium">'.$form->textwithpicto($langs->trans("NA"), $langs->trans("AmountOfInteventionNotIncludedByDefault")).'</span>';
  610. else print price($total_ttc);
  611. print '</td>';
  612. print '</tr>';
  613. }
  614. }
  615. }
  616. // and the final balance
  617. print '<tr class="liste_total">';
  618. print '<td align="right" colspan=2 >'.$langs->trans("Profit").'</td>';
  619. print '<td align="right" >'.price(price2num($balance_ht, 'MT')).'</td>';
  620. print '<td align="right" >'.price(price2num($balance_ttc, 'MT')).'</td>';
  621. print '</tr>';
  622. print "</table>";
  623. print '<br><br>';
  624. print '<br>';
  625. // Detail
  626. foreach ($listofreferent as $key => $value)
  627. {
  628. $title=$value['title'];
  629. $classname=$value['class'];
  630. $tablename=$value['table'];
  631. $datefieldname=$value['datefieldname'];
  632. $qualified=$value['test'];
  633. $langtoload=$value['lang'];
  634. $urlnew=$value['urlnew'];
  635. $buttonnew=$value['buttonnew'];
  636. $testnew=$value['testnew'];
  637. $project_field=$value['project_field'];
  638. $exclude_select_element = array('payment_various');
  639. if (!empty($value['exclude_select_element'])) $exclude_select_element[] = $value['exclude_select_element'];
  640. if ($qualified)
  641. {
  642. // If we want the project task array to have details of users
  643. //if ($key == 'project_task') $key = 'project_task_time';
  644. if ($langtoload) $langs->load($langtoload);
  645. $element = new $classname($db);
  646. $addform='';
  647. $idtofilterthirdparty=0;
  648. $array_of_element_linkable_with_different_thirdparty = array('facture_fourn', 'commande_fournisseur');
  649. if (! in_array($tablename, $array_of_element_linkable_with_different_thirdparty))
  650. {
  651. $idtofilterthirdparty=$object->thirdparty->id;
  652. if (! empty($conf->global->PROJECT_OTHER_THIRDPARTY_ID_TO_ADD_ELEMENTS)) $idtofilterthirdparty.=','.$conf->global->PROJECT_OTHER_THIRDPARTY_ID_TO_ADD_ELEMENTS;
  653. }
  654. if (empty($conf->global->PROJECT_LINK_ON_OVERWIEW_DISABLED) && $idtofilterthirdparty && !in_array($tablename,$exclude_select_element))
  655. {
  656. $selectList=$formproject->select_element($tablename, $idtofilterthirdparty, 'minwidth300',-2,!empty($project_field)?$project_field:'fk_projet');
  657. if (! $selectList || ($selectList<0))
  658. {
  659. setEventMessages($formproject->error,$formproject->errors,'errors');
  660. }
  661. elseif($selectList)
  662. {
  663. // Define form with the combo list of elements to link
  664. $addform.='<div class="inline-block valignmiddle">';
  665. $addform.='<form action="'.$_SERVER["PHP_SELF"].'?id='.$projectid.'" method="post">';
  666. $addform.='<input type="hidden" name="tablename" value="'.$tablename.'">';
  667. $addform.='<input type="hidden" name="action" value="addelement">';
  668. $addform.='<input type="hidden" name="datesrfc" value="'.dol_print_date($dates,'dayhourrfc').'">';
  669. $addform.='<input type="hidden" name="dateerfc" value="'.dol_print_date($datee,'dayhourrfc').'">';
  670. $addform.='<table><tr><td>'.$langs->trans("SelectElement").'</td>';
  671. $addform.='<td>'.$selectList.'</td>';
  672. $addform.='<td><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("AddElement")).'"></td>';
  673. $addform.='</tr></table>';
  674. $addform.='</form>';
  675. $addform.='</div>';
  676. }
  677. }
  678. if (empty($conf->global->PROJECT_CREATE_ON_OVERVIEW_DISABLED) && $urlnew)
  679. {
  680. $addform.='<div class="inline-block valignmiddle">';
  681. if ($testnew) $addform.='<a class="buttonxxx" href="'.$urlnew.'">'.($buttonnew?$langs->trans($buttonnew):$langs->trans("Create")).' <span class="fa fa-plus-circle valignmiddle"></span></a>';
  682. elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
  683. $addform.='<a class="buttonxxx buttonRefused" disabled="disabled" href="#">'.($buttonnew?$langs->trans($buttonnew):$langs->trans("Create")).' <span class="fa fa-plus-circle valignmiddle"></span></a>';
  684. }
  685. $addform.='<div>';
  686. }
  687. print load_fiche_titre($langs->trans($title), $addform, '');
  688. print "\n".'<!-- Table for tablename = '.$tablename.' -->'."\n";
  689. print '<table class="noborder" width="100%">';
  690. print '<tr class="liste_titre">';
  691. // Remove link column
  692. print '<td style="width: 24px"></td>';
  693. // Ref
  694. print '<td'.(($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"':'').'>'.$langs->trans("Ref").'</td>';
  695. // Date
  696. print '<td'.(($tablename != 'actioncomm' && $tablename != 'projet_task') ? ' style="width: 200px"':'').' align="center">';
  697. if (in_array($tablename, array('projet_task'))) print $langs->trans("TimeSpent");
  698. if (! in_array($tablename, array('projet_task'))) print $langs->trans("Date");
  699. print '</td>';
  700. // Thirdparty or user
  701. print '<td>';
  702. if (in_array($tablename, array('projet_task')) && $key == 'project_task') print ''; // if $key == 'project_task', we don't want details per user
  703. elseif (in_array($tablename, array('payment_various'))) print ''; // if $key == 'payment_various', we don't have any thirdparty
  704. elseif (in_array($tablename, array('expensereport_det','don','projet_task','stock_mouvement','payment_salary'))) print $langs->trans("User");
  705. else print $langs->trans("ThirdParty");
  706. print '</td>';
  707. // Amount HT
  708. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td align="right" width="120">'.$langs->trans("AmountHT").'</td>';
  709. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td align="right" width="120">'.$langs->trans("Amount").'</td>';
  710. if (empty($value['disableamount'])) print '<td align="right" width="120">'.$langs->trans("AmountHT").'</td>';
  711. else print '<td width="120"></td>';
  712. // Amount TTC
  713. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td align="right" width="120">'.$langs->trans("AmountTTC").'</td>';
  714. if (empty($value['disableamount'])) print '<td align="right" width="120">'.$langs->trans("AmountTTC").'</td>';
  715. else print '<td width="120"></td>';
  716. // Status
  717. if (in_array($tablename, array('projet_task'))) print '<td align="right" width="200">'.$langs->trans("ProgressDeclared").'</td>';
  718. else print '<td align="right" width="200">'.$langs->trans("Status").'</td>';
  719. print '</tr>';
  720. $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee,!empty($project_field)?$project_field:'fk_projet');
  721. if (is_array($elementarray) && count($elementarray)>0)
  722. {
  723. $total_ht = 0;
  724. $total_ttc = 0;
  725. $total_ht_by_third = 0;
  726. $total_ttc_by_third = 0;
  727. $saved_third_id = 0;
  728. $breakline = '';
  729. if (canApplySubtotalOn($tablename))
  730. {
  731. // Sort
  732. $elementarray = sortElementsByClientName($elementarray);
  733. }
  734. $num=count($elementarray);
  735. for ($i = 0; $i < $num; $i++)
  736. {
  737. $tmp=explode('_',$elementarray[$i]);
  738. $idofelement=$tmp[0];
  739. $idofelementuser=$tmp[1];
  740. $element->fetch($idofelement);
  741. if ($idofelementuser) $elementuser->fetch($idofelementuser);
  742. // Special cases
  743. if ($tablename != 'expensereport_det')
  744. {
  745. if(method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty();
  746. }
  747. else
  748. {
  749. $expensereport=new ExpenseReport($db);
  750. $expensereport->fetch($element->fk_expensereport);
  751. }
  752. //print 'xxx'.$tablename;
  753. //print $classname;
  754. if ($breakline && $saved_third_id != $element->thirdparty->id)
  755. {
  756. print $breakline;
  757. $saved_third_id = $element->thirdparty->id;
  758. $breakline = '';
  759. $total_ht_by_third=0;
  760. $total_ttc_by_third=0;
  761. }
  762. $saved_third_id = $element->thirdparty->id;
  763. $qualifiedfortotal=true;
  764. if ($key == 'invoice')
  765. {
  766. if (! empty($element->close_code) && $element->close_code == 'replaced') $qualifiedfortotal=false; // Replacement invoice, do not include into total
  767. }
  768. print '<tr class="oddeven">';
  769. // Remove link
  770. print '<td style="width: 24px">';
  771. if ($tablename != 'projet_task' && $tablename != 'stock_mouvement')
  772. {
  773. if (empty($conf->global->PROJECT_DISABLE_UNLINK_FROM_OVERVIEW) || $user->admin) // PROJECT_DISABLE_UNLINK_FROM_OVERVIEW is empty by defaut, so this test true
  774. {
  775. print '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $projectid . '&action=unlink&tablename=' . $tablename . '&elementselect=' . $element->id . '" class="reposition">';
  776. print img_picto($langs->trans('Unlink'), 'unlink');
  777. print '</a>';
  778. }
  779. }
  780. print "</td>\n";
  781. // Ref
  782. print '<td align="left" class="nowrap">';
  783. if ($tablename == 'expensereport_det')
  784. {
  785. print $expensereport->getNomUrl(1);
  786. }
  787. else
  788. {
  789. // Show ref with link
  790. if ($element instanceof Task)
  791. {
  792. print $element->getNomUrl(1,'withproject','time');
  793. print ' - '.dol_trunc($element->label, 48);
  794. }
  795. else print $element->getNomUrl(1);
  796. $element_doc = $element->element;
  797. $filename=dol_sanitizeFileName($element->ref);
  798. $filedir=$conf->{$element_doc}->multidir_output[$element->entity] . '/' . dol_sanitizeFileName($element->ref);
  799. if ($element_doc === 'order_supplier') {
  800. $element_doc='commande_fournisseur';
  801. $filedir = $conf->fournisseur->commande->multidir_output[$element->entity].'/'.dol_sanitizeFileName($element->ref);
  802. }
  803. elseif ($element_doc === 'invoice_supplier') {
  804. $element_doc='facture_fournisseur';
  805. $filename = get_exdir($element->id,2,0,0,$element,'product').dol_sanitizeFileName($element->ref);
  806. $filedir = $conf->fournisseur->facture->multidir_output[$element->entity].'/'.get_exdir($element->id,2,0,0,$element,'invoice_supplier').dol_sanitizeFileName($element->ref);
  807. }
  808. print '<div class="inline-block valignmiddle">'.$formfile->getDocumentsLink($element_doc, $filename, $filedir).'</div>';
  809. // Show supplier ref
  810. if (! empty($element->ref_supplier)) print ' - '.$element->ref_supplier;
  811. // Show customer ref
  812. if (! empty($element->ref_customer)) print ' - '.$element->ref_customer;
  813. }
  814. print "</td>\n";
  815. // Date or TimeSpent
  816. $date=''; $total_time_by_line = null;
  817. if ($tablename == 'expensereport_det') $date = $element->date; // No draft status on lines
  818. elseif ($tablename == 'stock_mouvement') $date = $element->datem;
  819. elseif ($tablename == 'payment_salary') $date = $element->datev;
  820. elseif ($tablename == 'payment_various') $date = $element->datev;
  821. elseif ($tablename == 'chargesociales') $date = $element->date_ech;
  822. elseif (! empty($element->status) || ! empty($element->statut) || ! empty($element->fk_status))
  823. {
  824. if ($tablename == 'don') $date = $element->datedon;
  825. if ($tablename == 'commande_fournisseur' || $tablename == 'supplier_order')
  826. {
  827. $date=($element->date_commande?$element->date_commande:$element->date_valid);
  828. }
  829. elseif ($tablename == 'supplier_proposal') $date=$element->date_validation; // There is no other date for this
  830. elseif ($tablename == 'fichinter') $date=$element->datev; // There is no other date for this
  831. elseif ($tablename == 'projet_task') $date=''; // We show no date. Showing date of beginning of task make user think it is date of time consumed
  832. else
  833. {
  834. $date=$element->date; // invoice, ...
  835. if (empty($date)) $date=$element->date_contrat;
  836. if (empty($date)) $date=$element->datev;
  837. }
  838. }
  839. print '<td align="center">';
  840. if ($tablename == 'actioncomm')
  841. {
  842. print dol_print_date($element->datep,'dayhour');
  843. if ($element->datef && $element->datef > $element->datep) print " - ".dol_print_date($element->datef,'dayhour');
  844. }
  845. elseif (in_array($tablename, array('projet_task')))
  846. {
  847. $tmpprojtime = $element->getSumOfAmount($elementuser, $dates, $datee); // $element is a task. $elementuser may be empty
  848. print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$idofelement.'&withproject=1">';
  849. print convertSecondToTime($tmpprojtime['nbseconds'], 'allhourmin');
  850. print '</a>';
  851. $total_time_by_line = $tmpprojtime['nbseconds'];
  852. }
  853. else print dol_print_date($date,'day');
  854. print '</td>';
  855. // Third party or user
  856. print '<td class="left">';
  857. if (is_object($element->thirdparty)) print $element->thirdparty->getNomUrl(1,'',48);
  858. elseif ($tablename == 'expensereport_det')
  859. {
  860. $tmpuser=new User($db);
  861. $tmpuser->fetch($expensereport->fk_user_author);
  862. print $tmpuser->getNomUrl(1,'',48);
  863. }
  864. elseif ($tablename == 'payment_salary')
  865. {
  866. $tmpuser=new User($db);
  867. $tmpuser->fetch($element->fk_user);
  868. print $tmpuser->getNomUrl(1,'',48);
  869. }
  870. elseif ($tablename == 'don' || $tablename == 'stock_mouvement')
  871. {
  872. if ($element->fk_user_author > 0)
  873. {
  874. $tmpuser2=new User($db);
  875. $tmpuser2->fetch($element->fk_user_author);
  876. print $tmpuser2->getNomUrl(1,'',48);
  877. }
  878. }
  879. elseif ($tablename == 'projet_task' && $key == 'project_task_time') // if $key == 'project_task', we don't want details per user
  880. {
  881. print $elementuser->getNomUrl(1);
  882. }
  883. print '</td>';
  884. // Amount without tax
  885. $warning='';
  886. if (empty($value['disableamount']))
  887. {
  888. $total_ht_by_line=null;
  889. $othermessage='';
  890. if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'payment_salary') $total_ht_by_line=$element->amount;
  891. elseif($tablename == 'fichinter') $total_ht_by_line=$element->getAmount();
  892. elseif ($tablename == 'stock_mouvement') $total_ht_by_line=$element->price*abs($element->qty);
  893. elseif (in_array($tablename, array('projet_task')))
  894. {
  895. if (! empty($conf->salaries->enabled))
  896. {
  897. // TODO Permission to read daily rate to show value
  898. $total_ht_by_line = price2num($tmpprojtime['amount'],'MT');
  899. if ($tmpprojtime['nblinesnull'] > 0)
  900. {
  901. $langs->load("errors");
  902. $warning=$langs->trans("WarningSomeLinesWithNullHourlyRate", $conf->currency);
  903. }
  904. }
  905. else
  906. {
  907. $othermessage=$form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
  908. }
  909. }
  910. else
  911. {
  912. $total_ht_by_line=$element->total_ht;
  913. }
  914. print '<td align="right">';
  915. if ($othermessage) print $othermessage;
  916. if (isset($total_ht_by_line))
  917. {
  918. if (! $qualifiedfortotal) print '<strike>';
  919. print price($total_ht_by_line);
  920. if (! $qualifiedfortotal) print '</strike>';
  921. }
  922. if ($warning) print ' '.img_warning($warning);
  923. print '</td>';
  924. }
  925. else print '<td></td>';
  926. // Amount inc tax
  927. if (empty($value['disableamount']))
  928. {
  929. $total_ttc_by_line=null;
  930. if ($tablename == 'don' || $tablename == 'chargesociales' || $tablename == 'payment_various' || $tablename == 'payment_salary') $total_ttc_by_line=$element->amount;
  931. elseif($tablename == 'fichinter') $total_ttc_by_line=$element->getAmount();
  932. elseif ($tablename == 'stock_mouvement') $total_ttc_by_line=$element->price*abs($element->qty);
  933. elseif ($tablename == 'projet_task')
  934. {
  935. if (! empty($conf->salaries->enabled))
  936. {
  937. // TODO Permission to read daily rate
  938. $defaultvat = get_default_tva($mysoc, $mysoc);
  939. $total_ttc_by_line = price2num($total_ht_by_line * (1 + ($defaultvat / 100)),'MT');
  940. }
  941. else
  942. {
  943. $othermessage=$form->textwithpicto($langs->trans("NotAvailable"), $langs->trans("ModuleSalaryToDefineHourlyRateMustBeEnabled"));
  944. }
  945. }
  946. else
  947. {
  948. $total_ttc_by_line=$element->total_ttc;
  949. }
  950. print '<td align="right">';
  951. if ($othermessage) print $othermessage;
  952. if (isset($total_ttc_by_line))
  953. {
  954. if (! $qualifiedfortotal) print '<strike>';
  955. print price($total_ttc_by_line);
  956. if (! $qualifiedfortotal) print '</strike>';
  957. }
  958. if ($warning) print ' '.img_warning($warning);
  959. print '</td>';
  960. }
  961. else print '<td></td>';
  962. // Status
  963. print '<td align="right">';
  964. if ($tablename == 'expensereport_det')
  965. {
  966. print $expensereport->getLibStatut(5);
  967. }
  968. elseif ($element instanceof CommonInvoice)
  969. {
  970. //This applies for Facture and FactureFournisseur
  971. print $element->getLibStatut(5, $element->getSommePaiement());
  972. }
  973. elseif ($element instanceof Task)
  974. {
  975. if ($element->progress != '')
  976. {
  977. print $element->progress.' %';
  978. }
  979. }
  980. elseif ($tablename == 'stock_mouvement')
  981. {
  982. print $element->getLibStatut(3);
  983. }
  984. else
  985. {
  986. print $element->getLibStatut(5);
  987. }
  988. print '</td>';
  989. print '</tr>';
  990. if ($qualifiedfortotal)
  991. {
  992. $total_ht = $total_ht + $total_ht_by_line;
  993. $total_ttc = $total_ttc + $total_ttc_by_line;
  994. $total_ht_by_third += $total_ht_by_line;
  995. $total_ttc_by_third += $total_ttc_by_line;
  996. $total_time = $total_time + $total_time_by_line;
  997. }
  998. if (canApplySubtotalOn($tablename))
  999. {
  1000. $breakline='<tr class="liste_total liste_sub_total">';
  1001. $breakline.='<td colspan="2">';
  1002. $breakline.='</td>';
  1003. $breakline.='<td>';
  1004. $breakline.='</td>';
  1005. $breakline.='<td class="right">';
  1006. $breakline.=$langs->trans('SubTotal').' : ';
  1007. if (is_object($element->thirdparty)) $breakline.=$element->thirdparty->getNomUrl(0,'',48);
  1008. $breakline.='</td>';
  1009. $breakline.='<td align="right">'.price($total_ht_by_third).'</td>';
  1010. $breakline.='<td align="right">'.price($total_ttc_by_third).'</td>';
  1011. $breakline.='<td></td>';
  1012. $breakline.='</tr>';
  1013. }
  1014. //var_dump($element->thirdparty->name.' - '.$saved_third_id.' - '.$element->thirdparty->id);
  1015. }
  1016. if ($breakline) print $breakline;
  1017. // Total
  1018. $colspan=4;
  1019. if (in_array($tablename, array('projet_task'))) $colspan=2;
  1020. print '<tr class="liste_total"><td colspan="'.$colspan.'">'.$langs->trans("Number").': '.$i.'</td>';
  1021. if (in_array($tablename, array('projet_task')))
  1022. {
  1023. print '<td align="center">';
  1024. print convertSecondToTime($total_time, 'allhourmin');
  1025. print '</td>';
  1026. print '<td>';
  1027. print '</td>';
  1028. }
  1029. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td align="right" width="100">'.$langs->trans("TotalHT").' : '.price($total_ht).'</td>';
  1030. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td align="right" width="100">'.$langs->trans("Total").' : '.price($total_ht).'</td>';
  1031. print '<td align="right">';
  1032. if (empty($value['disableamount']))
  1033. {
  1034. if ($tablename != 'projet_task' || ! empty($conf->salaries->enabled)) print ''.$langs->trans("TotalHT").' : '.price($total_ht);
  1035. }
  1036. print '</td>';
  1037. //if (empty($value['disableamount']) && ! in_array($tablename, array('projet_task'))) print '<td align="right" width="100">'.$langs->trans("TotalTTC").' : '.price($total_ttc).'</td>';
  1038. //elseif (empty($value['disableamount']) && in_array($tablename, array('projet_task'))) print '<td align="right" width="100"></td>';
  1039. print '<td align="right">';
  1040. if (empty($value['disableamount']))
  1041. {
  1042. if ($tablename != 'projet_task' || ! empty($conf->salaries->enabled)) print $langs->trans("TotalTTC").' : '.price($total_ttc);
  1043. }
  1044. print '</td>';
  1045. print '<td>&nbsp;</td>';
  1046. print '</tr>';
  1047. }
  1048. else
  1049. {
  1050. if (! is_array($elementarray)) // error
  1051. {
  1052. print $elementarray;
  1053. }
  1054. }
  1055. print "</table>";
  1056. print "<br>\n";
  1057. }
  1058. }
  1059. // Enhance with select2
  1060. if ($conf->use_javascript_ajax)
  1061. {
  1062. include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
  1063. $comboenhancement = ajax_combobox('.elementselect');
  1064. $out.=$comboenhancement;
  1065. print $comboenhancement;
  1066. }
  1067. // End of page
  1068. llxFooter();
  1069. $db->close();
  1070. /**
  1071. * Return if we should do a group by customer with sub-total
  1072. *
  1073. * @param string $tablename Name of table
  1074. * @return boolean True to tell to make a group by sub-total
  1075. */
  1076. function canApplySubtotalOn($tablename)
  1077. {
  1078. global $conf;
  1079. if (empty($conf->global->PROJECT_ADD_SUBTOTAL_LINES)) return false;
  1080. return in_array($tablename, array('facture_fourn', 'commande_fournisseur'));
  1081. }
  1082. /**
  1083. * sortElementsByClientName
  1084. *
  1085. * @param array $elementarray Element array
  1086. * @return array Element array sorted
  1087. */
  1088. function sortElementsByClientName($elementarray)
  1089. {
  1090. global $db, $classname;
  1091. $element = new $classname($db);
  1092. $clientname = array();
  1093. foreach ($elementarray as $key => $id) // id = id of object
  1094. {
  1095. if (empty($clientname[$id]))
  1096. {
  1097. $element->fetch($id);
  1098. $element->fetch_thirdparty();
  1099. $clientname[$id] = $element->thirdparty->name;
  1100. }
  1101. }
  1102. //var_dump($clientname);
  1103. asort($clientname); // sort on name
  1104. $elementarray = array();
  1105. foreach ($clientname as $id => $name)
  1106. {
  1107. $elementarray[] = $id;
  1108. }
  1109. return $elementarray;
  1110. }