list.php 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  6. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  8. * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2010-2022 Philippe Grand <philippe.grand@atoo-net.com>
  10. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  11. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  12. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  13. * Copyright (C) 2016-2021 Ferran Marcet <fmarcet@2byte.es>
  14. * Copyright (C) 2017-2018 Charlene Benke <charlie@patas-monkey.com>
  15. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
  16. * Copyright (C) 2019-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  17. * Copyright (C) 2021 Anthony Berton <anthony.berton@bb2a.fr>
  18. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  19. * Copyright (C) 2022 Josep Lluís Amador <joseplluis@lliuretic.cat>
  20. *
  21. * This program is free software; you can redistribute it and/or modify
  22. * it under the terms of the GNU General Public License as published by
  23. * the Free Software Foundation; either version 3 of the License, or
  24. * (at your option) any later version.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU General Public License
  32. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  33. */
  34. /**
  35. * \file htdocs/comm/propal/list.php
  36. * \ingroup propal
  37. * \brief Page of commercial proposals card and list
  38. */
  39. // Load Dolibarr environment
  40. require '../../main.inc.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  45. if (isModEnabled('margin')) {
  46. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
  47. }
  48. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  49. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  50. require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  51. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  52. if (isModEnabled('categorie')) {
  53. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  54. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
  55. }
  56. // Load translation files required by the page
  57. $langs->loadLangs(array('companies', 'propal', 'compta', 'bills', 'orders', 'products', 'deliveries', 'categories'));
  58. if (isModEnabled("expedition")) {
  59. $langs->loadLangs(array('sendings'));
  60. }
  61. // Get Parameters
  62. $socid = GETPOST('socid', 'int');
  63. $action = GETPOST('action', 'aZ09');
  64. $massaction = GETPOST('massaction', 'alpha');
  65. $show_files = GETPOST('show_files', 'int');
  66. $confirm = GETPOST('confirm', 'alpha');
  67. $cancel = GETPOST('cancel', 'alpha');
  68. $toselect = GETPOST('toselect', 'array');
  69. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'proposallist';
  70. $mode = GETPOST('mode', 'alpha');
  71. // Search Fields
  72. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  73. $search_user = GETPOST('search_user', 'int');
  74. $search_sale = GETPOST('search_sale', 'int');
  75. $search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
  76. $search_refcustomer = GETPOST('search_refcustomer', 'alpha');
  77. $search_refproject = GETPOST('search_refproject', 'alpha');
  78. $search_project = GETPOST('search_project', 'alpha');
  79. $search_societe = GETPOST('search_societe', 'alpha');
  80. $search_societe_alias = GETPOST('search_societe_alias', 'alpha');
  81. $search_montant_ht = GETPOST('search_montant_ht', 'alpha');
  82. $search_montant_vat = GETPOST('search_montant_vat', 'alpha');
  83. $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
  84. $search_warehouse = GETPOST('search_warehouse', 'alpha');
  85. $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
  86. $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
  87. $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
  88. $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
  89. $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
  90. $search_login = GETPOST('search_login', 'alpha');
  91. $search_product_category = GETPOST('search_product_category', 'int');
  92. $search_town = GETPOST('search_town', 'alpha');
  93. $search_zip = GETPOST('search_zip', 'alpha');
  94. $search_state = GETPOST("search_state");
  95. $search_country = GETPOST("search_country", 'int');
  96. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  97. $search_date_startday = GETPOST('search_date_startday', 'int');
  98. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  99. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  100. $search_date_endday = GETPOST('search_date_endday', 'int');
  101. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  102. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  103. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  104. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  105. $search_date_end_startday = GETPOST('search_date_end_startday', 'int');
  106. $search_date_end_startmonth = GETPOST('search_date_end_startmonth', 'int');
  107. $search_date_end_startyear = GETPOST('search_date_end_startyear', 'int');
  108. $search_date_end_endday = GETPOST('search_date_end_endday', 'int');
  109. $search_date_end_endmonth = GETPOST('search_date_end_endmonth', 'int');
  110. $search_date_end_endyear = GETPOST('search_date_end_endyear', 'int');
  111. $search_date_end_start = dol_mktime(0, 0, 0, $search_date_end_startmonth, $search_date_end_startday, $search_date_end_startyear); // Use tzserver
  112. $search_date_end_end = dol_mktime(23, 59, 59, $search_date_end_endmonth, $search_date_end_endday, $search_date_end_endyear);
  113. $search_date_delivery_startday = GETPOST('search_date_delivery_startday', 'int');
  114. $search_date_delivery_startmonth = GETPOST('search_date_delivery_startmonth', 'int');
  115. $search_date_delivery_startyear = GETPOST('search_date_delivery_startyear', 'int');
  116. $search_date_delivery_endday = GETPOST('search_date_delivery_endday', 'int');
  117. $search_date_delivery_endmonth = GETPOST('search_date_delivery_endmonth', 'int');
  118. $search_date_delivery_endyear = GETPOST('search_date_delivery_endyear', 'int');
  119. $search_date_delivery_start = dol_mktime(0, 0, 0, $search_date_delivery_startmonth, $search_date_delivery_startday, $search_date_delivery_startyear);
  120. $search_date_delivery_end = dol_mktime(23, 59, 59, $search_date_delivery_endmonth, $search_date_delivery_endday, $search_date_delivery_endyear);
  121. $search_availability = GETPOST('search_availability', 'int');
  122. $search_categ_cus = GETPOST("search_categ_cus", 'int');
  123. $search_fk_cond_reglement = GETPOST("search_fk_cond_reglement", 'int');
  124. $search_fk_shipping_method = GETPOST("search_fk_shipping_method", 'int');
  125. $search_fk_input_reason = GETPOST("search_fk_input_reason", 'int');
  126. $search_fk_mode_reglement = GETPOST("search_fk_mode_reglement", 'int');
  127. $search_date_signature_startday = GETPOST('search_date_signature_startday', 'int');
  128. $search_date_signature_startmonth = GETPOST('search_date_signature_startmonth', 'int');
  129. $search_date_signature_startyear = GETPOST('search_date_signature_startyear', 'int');
  130. $search_date_signature_endday = GETPOST('search_date_signature_endday', 'int');
  131. $search_date_signature_endmonth = GETPOST('search_date_signature_endmonth', 'int');
  132. $search_date_signature_endyear = GETPOST('search_date_signature_endyear', 'int');
  133. $search_date_signature_start = dol_mktime(0, 0, 0, $search_date_signature_startmonth, $search_date_signature_startday, $search_date_signature_startyear);
  134. $search_date_signature_end = dol_mktime(23, 59, 59, $search_date_signature_endmonth, $search_date_signature_endday, $search_date_signature_endyear);
  135. $search_status = GETPOST('search_status', 'alpha');
  136. $optioncss = GETPOST('optioncss', 'alpha');
  137. $object_statut = GETPOST('search_statut', 'alpha');
  138. // Pagination
  139. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  140. $sortfield = GETPOST('sortfield', 'aZ09comma');
  141. $sortorder = GETPOST('sortorder', 'aZ09comma');
  142. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  143. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  144. // If $page is not defined, or '' or -1 or if we click on clear filters
  145. $page = 0;
  146. }
  147. $offset = $limit * $page;
  148. $pageprev = $page - 1;
  149. $pagenext = $page + 1;
  150. if (!$sortfield) {
  151. $sortfield = 'p.ref';
  152. }
  153. if (!$sortorder) {
  154. $sortorder = 'DESC';
  155. }
  156. // Security check
  157. $module = 'propal';
  158. $dbtable = '';
  159. $objectid = '';
  160. if (!empty($user->socid)) {
  161. $socid = $user->socid;
  162. }
  163. if (!empty($socid)) {
  164. $objectid = $socid;
  165. $module = 'societe';
  166. $dbtable = '&societe';
  167. }
  168. $result = restrictedArea($user, $module, $objectid, $dbtable);
  169. $diroutputmassaction = $conf->propal->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id;
  170. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  171. $object = new Propal($db);
  172. $hookmanager->initHooks(array('propallist'));
  173. $extrafields = new ExtraFields($db);
  174. // fetch optionals attributes and labels
  175. $extrafields->fetch_name_optionals_label($object->table_element);
  176. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  177. // List of fields to search into when doing a "search in all"
  178. $fieldstosearchall = array(
  179. 'p.ref'=>'Ref',
  180. 'p.ref_client'=>'RefCustomer',
  181. 'pd.description'=>'Description',
  182. 's.nom'=>"ThirdParty",
  183. 's.name_alias'=>"AliasNameShort",
  184. 's.zip'=>"Zip",
  185. 's.town'=>"Town",
  186. 'p.note_public'=>'NotePublic',
  187. );
  188. if (empty($user->socid)) {
  189. $fieldstosearchall["p.note_private"] = "NotePrivate";
  190. }
  191. $checkedtypetiers = 0;
  192. $arrayfields = array(
  193. 'p.ref'=>array('label'=>"Ref", 'checked'=>1),
  194. 'p.ref_client'=>array('label'=>"RefCustomer", 'checked'=>-1),
  195. 'pr.ref'=>array('label'=>"ProjectRef", 'checked'=>1, 'enabled'=>(isModEnabled('project') ? 1 : 0)),
  196. 'pr.title'=>array('label'=>"ProjectLabel", 'checked'=>0, 'enabled'=>(isModEnabled('project') ? 1 : 0)),
  197. 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1),
  198. 's.name_alias'=>array('label'=>"AliasNameShort", 'checked'=>-1),
  199. 's.town'=>array('label'=>"Town", 'checked'=>-1),
  200. 's.zip'=>array('label'=>"Zip", 'checked'=>-1),
  201. 'state.nom'=>array('label'=>"StateShort", 'checked'=>0),
  202. 'country.code_iso'=>array('label'=>"Country", 'checked'=>0),
  203. 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers),
  204. 'p.date'=>array('label'=>"DatePropal", 'checked'=>1),
  205. 'p.fin_validite'=>array('label'=>"DateEnd", 'checked'=>1),
  206. 'p.date_livraison'=>array('label'=>"DeliveryDate", 'checked'=>0),
  207. 'p.date_signature'=>array('label'=>"DateSigning", 'checked'=>0),
  208. 'ava.rowid'=>array('label'=>"AvailabilityPeriod", 'checked'=>0),
  209. 'p.fk_shipping_method'=>array('label'=>"SendingMethod", 'checked'=>0, 'enabled'=>isModEnabled("expedition")),
  210. 'p.fk_input_reason'=>array('label'=>"Origin", 'checked'=>0, 'enabled'=>1),
  211. 'p.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>0),
  212. 'p.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>0),
  213. 'p.total_ht'=>array('label'=>"AmountHT", 'checked'=>1),
  214. 'p.total_tva'=>array('label'=>"AmountVAT", 'checked'=>0),
  215. 'p.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0),
  216. 'p.total_ht_invoiced'=>array('label'=>"AmountInvoicedHT", 'checked'=>0, 'enabled'=>getDolGlobalString('PROPOSAL_SHOW_INVOICED_AMOUNT')),
  217. 'p.total_invoiced'=>array('label'=>"AmountInvoicedTTC", 'checked'=>0, 'enabled'=>getDolGlobalString('PROPOSAL_SHOW_INVOICED_AMOUNT')),
  218. 'p.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  219. 'p.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  220. 'p.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  221. 'p.multicurrency_total_tva'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  222. 'p.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  223. 'p.multicurrency_total_ht_invoiced'=>array('label'=>'MulticurrencyAmountInvoicedHT', 'checked'=>0, 'enabled'=>isModEnabled("multicurrency") && getDolGlobalString('PROPOSAL_SHOW_INVOICED_AMOUNT')),
  224. 'p.multicurrency_total_invoiced'=>array('label'=>'MulticurrencyAmountInvoicedTTC', 'checked'=>0, 'enabled'=>isModEnabled("multicurrency") && getDolGlobalString('PROPOSAL_SHOW_INVOICED_AMOUNT')),
  225. 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>10),
  226. 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>-1),
  227. 'total_pa' => array('label' => (getDolGlobalString('MARGIN_TYPE') == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (!isModEnabled('margin') || !$user->hasRight('margins', 'liretous') ? 0 : 1)),
  228. 'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (!isModEnabled('margin') || !$user->hasRight('margins', 'liretous') ? 0 : 1)),
  229. 'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (!isModEnabled('margin') || !$user->hasRight('margins', 'liretous') || !getDolGlobalString('DISPLAY_MARGIN_RATES') ? 0 : 1)),
  230. 'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (!isModEnabled('margin') || !$user->hasRight('margins', 'liretous') || !getDolGlobalString('DISPLAY_MARK_RATES') ? 0 : 1)),
  231. 'p.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  232. 'p.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
  233. 'p.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>500),
  234. 'p.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(!getDolGlobalInt('MAIN_LIST_HIDE_PUBLIC_NOTES'))),
  235. 'p.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES'))),
  236. 'p.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
  237. );
  238. // List of fields to search into when doing a "search in all"
  239. /*$fieldstosearchall = array();
  240. foreach ($object->fields as $key => $val) {
  241. if (!empty($val['searchall'])) {
  242. $fieldstosearchall['t.'.$key] = $val['label'];
  243. }
  244. }*/
  245. // Definition of array of fields for columns
  246. /*$arrayfields = array();
  247. foreach ($object->fields as $key => $val) {
  248. // If $val['visible']==0, then we never show the field
  249. if (!empty($val['visible'])) {
  250. $visible = (int) dol_eval($val['visible'], 1);
  251. $arrayfields['t.'.$key] = array(
  252. 'label'=>$val['label'],
  253. 'checked'=>(($visible < 0) ? 0 : 1),
  254. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  255. 'position'=>$val['position'],
  256. 'help'=> isset($val['help']) ? $val['help'] : ''
  257. );
  258. }
  259. }*/
  260. if (!$user->hasRight('societe', 'client', 'voir')) {
  261. $search_sale = $user->id;
  262. }
  263. // Extra fields
  264. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  265. // Permissions
  266. $permissiontoread = $user->hasRight('propal', 'lire');
  267. $permissiontoadd = $user->hasRight('propal', 'creer');
  268. $permissiontodelete = $user->hasRight('propal', 'supprimer');
  269. if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) {
  270. $permissiontovalidate = $user->hasRight('propal', 'propal_advance', 'validate');
  271. $permissiontoclose = $user->hasRight('propal', 'propal_advance', 'close');
  272. $permissiontosendbymail = $user->hasRight('propal', 'propal_advance', 'send');
  273. } else {
  274. $permissiontovalidate = $user->hasRight('propal', 'creer');
  275. $permissiontoclose = $user->hasRight('propal', 'creer');
  276. $permissiontosendbymail = $user->hasRight('propal', 'lire');
  277. }
  278. /*
  279. * Actions
  280. */
  281. if (GETPOST('cancel', 'alpha')) {
  282. $action = 'list';
  283. $massaction = '';
  284. }
  285. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  286. $massaction = '';
  287. }
  288. $parameters = array('socid'=>$socid, 'arrayfields'=>&$arrayfields);
  289. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  290. if ($reshook < 0) {
  291. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  292. }
  293. if (empty($reshook)) {
  294. // Selection of new fields
  295. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  296. // Purge search criteria
  297. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  298. $search_user = '';
  299. $search_sale = '';
  300. $search_ref = '';
  301. $search_refcustomer = '';
  302. $search_refproject = '';
  303. $search_project = '';
  304. $search_societe = '';
  305. $search_societe_alias = '';
  306. $search_montant_ht = '';
  307. $search_montant_vat = '';
  308. $search_montant_ttc = '';
  309. $search_warehouse = '';
  310. $search_multicurrency_code = '';
  311. $search_multicurrency_tx = '';
  312. $search_multicurrency_montant_ht = '';
  313. $search_multicurrency_montant_vat = '';
  314. $search_multicurrency_montant_ttc = '';
  315. $search_login = '';
  316. $search_product_category = '';
  317. $search_town = '';
  318. $search_zip = "";
  319. $search_state = "";
  320. $search_type = '';
  321. $search_country = '';
  322. $search_type_thirdparty = '';
  323. $search_date_startday = '';
  324. $search_date_startmonth = '';
  325. $search_date_startyear = '';
  326. $search_date_endday = '';
  327. $search_date_endmonth = '';
  328. $search_date_endyear = '';
  329. $search_date_start = '';
  330. $search_date_end = '';
  331. $search_date_end_startday = '';
  332. $search_date_end_startmonth = '';
  333. $search_date_end_startyear = '';
  334. $search_date_end_endday = '';
  335. $search_date_end_endmonth = '';
  336. $search_date_end_endyear = '';
  337. $search_date_end_start = '';
  338. $search_date_end_end = '';
  339. $search_date_delivery_startday = '';
  340. $search_date_delivery_startmonth = '';
  341. $search_date_delivery_startyear = '';
  342. $search_date_delivery_endday = '';
  343. $search_date_delivery_endmonth = '';
  344. $search_date_delivery_endyear = '';
  345. $search_date_delivery_start = '';
  346. $search_date_delivery_end = '';
  347. $search_availability = '';
  348. $search_status = '';
  349. $object_statut = '';
  350. $search_categ_cus = 0;
  351. $search_fk_cond_reglement = '';
  352. $search_fk_shipping_method = '';
  353. $search_fk_input_reason = '';
  354. $search_fk_mode_reglement = '';
  355. $search_date_signature_startday = '';
  356. $search_date_signature_startmonth = '';
  357. $search_date_signature_startyear = '';
  358. $search_date_signature_endday = '';
  359. $search_date_signature_endmonth = '';
  360. $search_date_signature_endyear = '';
  361. $search_date_signature_start = '';
  362. $search_date_signature_end = '';
  363. $toselect = array();
  364. $search_array_options = array();
  365. }
  366. if ($object_statut != '') {
  367. $search_status = $object_statut;
  368. }
  369. // Mass actions
  370. $objectclass = 'Propal';
  371. $objectlabel = 'Proposals';
  372. $uploaddir = $conf->propal->multidir_output[$conf->entity];
  373. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  374. }
  375. if ($action == 'validate' && $permissiontovalidate) {
  376. if (GETPOST('confirm') == 'yes') {
  377. $tmpproposal = new Propal($db);
  378. $db->begin();
  379. $error = 0;
  380. foreach ($toselect as $checked) {
  381. if ($tmpproposal->fetch($checked) > 0) {
  382. if ($tmpproposal->statut == $tmpproposal::STATUS_DRAFT) {
  383. if ($tmpproposal->valid($user) > 0) {
  384. setEventMessages($langs->trans('hasBeenValidated', $tmpproposal->ref), null, 'mesgs');
  385. } else {
  386. setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
  387. $error++;
  388. }
  389. } else {
  390. $langs->load("errors");
  391. setEventMessages($langs->trans('ErrorIsNotADraft', $tmpproposal->ref), null, 'errors');
  392. $error++;
  393. }
  394. } else {
  395. setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
  396. $error++;
  397. }
  398. }
  399. if ($error) {
  400. $db->rollback();
  401. } else {
  402. $db->commit();
  403. }
  404. }
  405. }
  406. if ($action == "sign" && $permissiontoclose) {
  407. if (GETPOST('confirm') == 'yes') {
  408. $tmpproposal = new Propal($db);
  409. $db->begin();
  410. $error = 0;
  411. foreach ($toselect as $checked) {
  412. if ($tmpproposal->fetch($checked) > 0) {
  413. if ($tmpproposal->statut == $tmpproposal::STATUS_VALIDATED) {
  414. $tmpproposal->statut = $tmpproposal::STATUS_SIGNED;
  415. if ($tmpproposal->closeProposal($user, $tmpproposal::STATUS_SIGNED) >= 0) {
  416. setEventMessages($tmpproposal->ref." ".$langs->trans('Signed'), null, 'mesgs');
  417. } else {
  418. setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
  419. $error++;
  420. }
  421. } else {
  422. setEventMessage($langs->trans('MustBeValidatedToBeSigned', $tmpproposal->ref), 'errors');
  423. $error++;
  424. }
  425. } else {
  426. setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
  427. $error++;
  428. }
  429. }
  430. if ($error) {
  431. $db->rollback();
  432. } else {
  433. $db->commit();
  434. }
  435. }
  436. }
  437. if ($action == "nosign" && $permissiontoclose) {
  438. if (GETPOST('confirm') == 'yes') {
  439. $tmpproposal = new Propal($db);
  440. $db->begin();
  441. $error = 0;
  442. foreach ($toselect as $checked) {
  443. if ($tmpproposal->fetch($checked) > 0) {
  444. if ($tmpproposal->statut == $tmpproposal::STATUS_VALIDATED || (getDolGlobalString('PROPAL_SKIP_ACCEPT_REFUSE') && $tmpproposal->statut == $tmpproposal::STATUS_DRAFT)) {
  445. $tmpproposal->statut = $tmpproposal::STATUS_NOTSIGNED;
  446. if ($tmpproposal->closeProposal($user, $tmpproposal::STATUS_NOTSIGNED) > 0) {
  447. setEventMessage($tmpproposal->ref." ".$langs->trans('NoSigned'), 'mesgs');
  448. } else {
  449. setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
  450. $error++;
  451. }
  452. } else {
  453. setEventMessage($tmpproposal->ref." ".$langs->trans('CantBeNoSign'), 'errors');
  454. $error++;
  455. }
  456. } else {
  457. setEventMessages($tmpproposal->error, $tmpproposal->errors, 'errors');
  458. $error++;
  459. }
  460. }
  461. if ($error) {
  462. $db->rollback();
  463. } else {
  464. $db->commit();
  465. }
  466. }
  467. }
  468. // Closed records
  469. if (!$error && $massaction === 'setbilled' && $permissiontoclose) {
  470. $db->begin();
  471. $objecttmp = new $objectclass($db);
  472. $nbok = 0;
  473. foreach ($toselect as $toselectid) {
  474. $result = $objecttmp->fetch($toselectid);
  475. if ($result > 0) {
  476. $result = $objecttmp->classifyBilled($user, 0);
  477. if ($result <= 0) {
  478. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  479. $error++;
  480. break;
  481. } else {
  482. $nbok++;
  483. }
  484. } else {
  485. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  486. $error++;
  487. break;
  488. }
  489. }
  490. if (!$error) {
  491. if ($nbok > 1) {
  492. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  493. } else {
  494. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  495. }
  496. $db->commit();
  497. } else {
  498. $db->rollback();
  499. }
  500. }
  501. /*
  502. * View
  503. */
  504. $now = dol_now();
  505. $form = new Form($db);
  506. $formother = new FormOther($db);
  507. $formfile = new FormFile($db);
  508. $formpropal = new FormPropal($db);
  509. $formmargin = null;
  510. if (isModEnabled('margin')) {
  511. $formmargin = new FormMargin($db);
  512. }
  513. $companystatic = new Societe($db);
  514. $projectstatic = new Project($db);
  515. $formcompany = new FormCompany($db);
  516. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  517. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  518. $sql = 'SELECT';
  519. if ($search_all || $search_user > 0) {
  520. $sql = 'SELECT DISTINCT';
  521. }
  522. $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax , s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client,';
  523. $sql .= " typent.code as typent_code,";
  524. $sql .= " ava.rowid as availability,";
  525. $sql .= " country.code as country_code,";
  526. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  527. $sql .= ' p.rowid, p.entity as propal_entity, p.note_private, p.total_ht, p.total_tva, p.total_ttc, p.localtax1, p.localtax2, p.ref, p.ref_client, p.fk_statut as status, p.fk_user_author, p.datep as dp, p.fin_validite as dfv, p.date_livraison as ddelivery,';
  528. $sql .= ' p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc,';
  529. $sql .= ' p.datec as date_creation, p.tms as date_update, p.date_cloture as date_cloture,';
  530. $sql .= ' p.date_signature as dsignature,';
  531. $sql .= ' p.note_public, p.note_private,';
  532. $sql .= ' p.fk_cond_reglement,p.deposit_percent,p.fk_mode_reglement,p.fk_shipping_method,p.fk_input_reason,';
  533. $sql .= " pr.rowid as project_id, pr.ref as project_ref, pr.title as project_label,";
  534. $sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity as user_entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender';
  535. // Add fields from extrafields
  536. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  537. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  538. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  539. }
  540. }
  541. // Add fields from hooks
  542. $parameters = array();
  543. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  544. $sql .= $hookmanager->resPrint;
  545. $sql = preg_replace('/, $/', '', $sql);
  546. $sqlfields = $sql; // $sql fields to remove for count total
  547. $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  548. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  549. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  550. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  551. $sql .= ', '.MAIN_DB_PREFIX.'propal as p';
  552. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  553. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
  554. }
  555. if ($search_all) {
  556. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid = pd.fk_propal';
  557. }
  558. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON p.fk_user_author = u.rowid';
  559. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON pr.rowid = p.fk_projet";
  560. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_availability as ava on (ava.rowid = p.fk_availability)";
  561. if ($search_user > 0) {
  562. $sql .= ", ".MAIN_DB_PREFIX."element_contact as c";
  563. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
  564. }
  565. // Add table from hooks
  566. $parameters = array();
  567. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  568. $sql .= $hookmanager->resPrint;
  569. $sql .= ' WHERE p.fk_soc = s.rowid';
  570. $sql .= ' AND p.entity IN ('.getEntity('propal').')';
  571. if ($search_town) {
  572. $sql .= natural_search('s.town', $search_town);
  573. }
  574. if ($search_zip) {
  575. $sql .= natural_search("s.zip", $search_zip);
  576. }
  577. if ($search_state) {
  578. $sql .= natural_search("state.nom", $search_state);
  579. }
  580. if ($search_country) {
  581. $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
  582. }
  583. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  584. $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
  585. }
  586. if ($search_ref) {
  587. $sql .= natural_search('p.ref', $search_ref);
  588. }
  589. if ($search_refcustomer) {
  590. $sql .= natural_search('p.ref_client', $search_refcustomer);
  591. }
  592. if ($search_refproject) {
  593. $sql .= natural_search('pr.ref', $search_refproject);
  594. }
  595. if ($search_project) {
  596. $sql .= natural_search('pr.title', $search_project);
  597. }
  598. if ($search_availability) {
  599. $sql .= " AND p.fk_availability IN (".$db->sanitize($db->escape($search_availability)).')';
  600. }
  601. if (empty($arrayfields['s.name_alias']['checked']) && $search_societe) {
  602. $sql .= natural_search(array("s.nom", "s.name_alias"), $search_societe);
  603. } else {
  604. if ($search_societe) {
  605. $sql .= natural_search('s.nom', $search_societe);
  606. }
  607. if ($search_societe_alias) {
  608. $sql .= natural_search('s.name_alias', $search_societe_alias);
  609. }
  610. }
  611. if ($search_login) {
  612. $sql .= natural_search(array("u.login", "u.firstname", "u.lastname"), $search_login);
  613. }
  614. if ($search_montant_ht != '') {
  615. $sql .= natural_search("p.total_ht", $search_montant_ht, 1);
  616. }
  617. if ($search_montant_vat != '') {
  618. $sql .= natural_search("p.total_tva", $search_montant_vat, 1);
  619. }
  620. if ($search_montant_ttc != '') {
  621. $sql .= natural_search("p.total_ttc", $search_montant_ttc, 1);
  622. }
  623. if ($search_warehouse != '' && $search_warehouse > 0) {
  624. $sql .= natural_search("p.fk_warehouse", $search_warehouse, 1);
  625. }
  626. if ($search_multicurrency_code != '') {
  627. $sql .= " AND p.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
  628. }
  629. if ($search_multicurrency_tx != '') {
  630. $sql .= natural_search('p.multicurrency_tx', $search_multicurrency_tx, 1);
  631. }
  632. if ($search_multicurrency_montant_ht != '') {
  633. $sql .= natural_search('p.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
  634. }
  635. if ($search_multicurrency_montant_vat != '') {
  636. $sql .= natural_search('p.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
  637. }
  638. if ($search_multicurrency_montant_ttc != '') {
  639. $sql .= natural_search('p.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
  640. }
  641. if ($search_all) {
  642. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  643. }
  644. if ($search_fk_cond_reglement > 0) {
  645. $sql .= " AND p.fk_cond_reglement = ".((int) $search_fk_cond_reglement);
  646. }
  647. if ($search_fk_shipping_method > 0) {
  648. $sql .= " AND p.fk_shipping_method = ".((int) $search_fk_shipping_method);
  649. }
  650. if ($search_fk_input_reason > 0) {
  651. $sql .= " AND p.fk_input_reason = ".((int) $search_fk_input_reason);
  652. }
  653. if ($search_fk_mode_reglement > 0) {
  654. $sql .= " AND p.fk_mode_reglement = ".((int) $search_fk_mode_reglement);
  655. }
  656. if ($socid > 0) {
  657. $sql .= ' AND s.rowid = '.((int) $socid);
  658. }
  659. if ($search_status != '' && $search_status != '-1') {
  660. $sql .= ' AND p.fk_statut IN ('.$db->sanitize($search_status).')';
  661. }
  662. if ($search_date_start) {
  663. $sql .= " AND p.datep >= '".$db->idate($search_date_start)."'";
  664. }
  665. if ($search_date_end) {
  666. $sql .= " AND p.datep <= '".$db->idate($search_date_end)."'";
  667. }
  668. if ($search_date_end_start) {
  669. $sql .= " AND p.fin_validite >= '".$db->idate($search_date_end_start)."'";
  670. }
  671. if ($search_date_end_end) {
  672. $sql .= " AND p.fin_validite <= '".$db->idate($search_date_end_end)."'";
  673. }
  674. if ($search_date_delivery_start) {
  675. $sql .= " AND p.date_livraison >= '".$db->idate($search_date_delivery_start)."'";
  676. }
  677. if ($search_date_delivery_end) {
  678. $sql .= " AND p.date_livraison <= '".$db->idate($search_date_delivery_end)."'";
  679. }
  680. if ($search_user > 0) {
  681. $sql .= " AND c.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal' AND c.element_id = p.rowid AND c.fk_socpeople = ".((int) $search_user);
  682. }
  683. if ($search_date_signature_start) {
  684. $sql .= " AND p.date_signature >= '".$db->idate($search_date_signature_start)."'";
  685. }
  686. if ($search_date_signature_end) {
  687. $sql .= " AND p.date_signature <= '".$db->idate($search_date_signature_end)."'";
  688. }
  689. // Search on sale representative
  690. if ($search_sale && $search_sale != '-1') {
  691. if ($search_sale == -2) {
  692. $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
  693. } elseif ($search_sale > 0) {
  694. $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
  695. }
  696. }
  697. // Search for tag/category ($searchCategoryCustomerList is an array of ID)
  698. $searchCategoryCustomerOperator = -1;
  699. $searchCategoryCustomerList = array($search_categ_cus);
  700. if (!empty($searchCategoryCustomerList)) {
  701. $searchCategoryCustomerSqlList = array();
  702. $listofcategoryid = '';
  703. foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
  704. if (intval($searchCategoryCustomer) == -2) {
  705. $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc)";
  706. } elseif (intval($searchCategoryCustomer) > 0) {
  707. if ($searchCategoryCustomerOperator == 0) {
  708. $searchCategoryCustomerSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc AND cs.fk_categorie = ".((int) $searchCategoryCustomer).")";
  709. } else {
  710. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
  711. }
  712. }
  713. }
  714. if ($listofcategoryid) {
  715. $searchCategoryCustomerSqlList[] = " EXISTS (SELECT cs.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as cs WHERE s.rowid = cs.fk_soc AND cs.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  716. }
  717. if ($searchCategoryCustomerOperator == 1) {
  718. if (!empty($searchCategoryCustomerSqlList)) {
  719. $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
  720. }
  721. } else {
  722. if (!empty($searchCategoryCustomerSqlList)) {
  723. $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
  724. }
  725. }
  726. }
  727. // Search for tag/category ($searchCategoryProductList is an array of ID)
  728. $searchCategoryProductOperator = -1;
  729. $searchCategoryProductList = array($search_product_category);
  730. if (!empty($searchCategoryProductList)) {
  731. $searchCategoryProductSqlList = array();
  732. $listofcategoryid = '';
  733. foreach ($searchCategoryProductList as $searchCategoryProduct) {
  734. if (intval($searchCategoryProduct) == -2) {
  735. $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."propaldet as pd WHERE pd.fk_propal = p.rowid AND pd.fk_product = ck.fk_product)";
  736. } elseif (intval($searchCategoryProduct) > 0) {
  737. if ($searchCategoryProductOperator == 0) {
  738. $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."propaldet as pd WHERE pd.fk_propal = p.rowid AND pd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
  739. } else {
  740. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
  741. }
  742. }
  743. }
  744. if ($listofcategoryid) {
  745. $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."propaldet as pd WHERE pd.fk_propal = p.rowid AND pd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  746. }
  747. if ($searchCategoryProductOperator == 1) {
  748. if (!empty($searchCategoryProductSqlList)) {
  749. $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
  750. }
  751. } else {
  752. if (!empty($searchCategoryProductSqlList)) {
  753. $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
  754. }
  755. }
  756. }
  757. // Add where from extra fields
  758. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  759. //print $sql;
  760. // Add where from hooks
  761. $parameters = array();
  762. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  763. $sql .= $hookmanager->resPrint;
  764. // Add HAVING from hooks
  765. $parameters = array();
  766. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  767. $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
  768. // Count total nb of records
  769. $nbtotalofrecords = '';
  770. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  771. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  772. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  773. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  774. $resql = $db->query($sqlforcount);
  775. if ($resql) {
  776. $objforcount = $db->fetch_object($resql);
  777. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  778. } else {
  779. dol_print_error($db);
  780. }
  781. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  782. $page = 0;
  783. $offset = 0;
  784. }
  785. $db->free($resql);
  786. }
  787. // Complete request and execute it with limit
  788. $sql .= $db->order($sortfield, $sortorder);
  789. $sql .= ', p.ref DESC';
  790. if ($limit) {
  791. $sql .= $db->plimit($limit + 1, $offset);
  792. }
  793. $resql = $db->query($sql);
  794. if (!$resql) {
  795. dol_print_error($db);
  796. exit;
  797. }
  798. $objectstatic = new Propal($db);
  799. $userstatic = new User($db);
  800. if ($socid > 0) {
  801. $soc = new Societe($db);
  802. $soc->fetch($socid);
  803. $title = $langs->trans('Proposals').' - '.$soc->name;
  804. if (empty($search_societe)) {
  805. $search_societe = $soc->name;
  806. }
  807. } else {
  808. $title = $langs->trans('Proposals');
  809. }
  810. $num = $db->num_rows($resql);
  811. $arrayofselected = is_array($toselect) ? $toselect : array();
  812. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all) {
  813. $obj = $db->fetch_object($resql);
  814. $id = $obj->rowid;
  815. header("Location: ".DOL_URL_ROOT.'/comm/propal/card.php?id='.$id);
  816. exit;
  817. }
  818. $help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos';
  819. llxHeader('', $title, $help_url);
  820. $param = '&search_status='.urlencode($search_status);
  821. if (!empty($mode)) {
  822. $param .= '&mode='.urlencode($mode);
  823. }
  824. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  825. $param .= '&contextpage='.urlencode($contextpage);
  826. }
  827. if ($limit > 0 && $limit != $conf->liste_limit) {
  828. $param .= '&limit='.((int) $limit);
  829. }
  830. if ($search_all) {
  831. $param .= '&search_all='.urlencode($search_all);
  832. }
  833. if ($search_date_startday) {
  834. $param .= '&search_date_startday='.urlencode($search_date_startday);
  835. }
  836. if ($search_date_startmonth) {
  837. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  838. }
  839. if ($search_date_startyear) {
  840. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  841. }
  842. if ($search_date_endday) {
  843. $param .= '&search_date_endday='.urlencode($search_date_endday);
  844. }
  845. if ($search_date_endmonth) {
  846. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  847. }
  848. if ($search_date_endyear) {
  849. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  850. }
  851. if ($search_date_end_startday) {
  852. $param .= '&search_date_end_startday='.urlencode($search_date_end_startday);
  853. }
  854. if ($search_date_end_startmonth) {
  855. $param .= '&search_date_end_startmonth='.urlencode($search_date_end_startmonth);
  856. }
  857. if ($search_date_end_startyear) {
  858. $param .= '&search_date_end_startyear='.urlencode($search_date_end_startyear);
  859. }
  860. if ($search_date_end_endday) {
  861. $param .= '&search_date_end_endday='.urlencode($search_date_end_endday);
  862. }
  863. if ($search_date_end_endmonth) {
  864. $param .= '&search_date_end_endmonth='.urlencode($search_date_end_endmonth);
  865. }
  866. if ($search_date_end_endyear) {
  867. $param .= '&search_date_end_endyear='.urlencode($search_date_end_endyear);
  868. }
  869. if ($search_date_delivery_startday) {
  870. $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
  871. }
  872. if ($search_date_delivery_startmonth) {
  873. $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
  874. }
  875. if ($search_date_delivery_startyear) {
  876. $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
  877. }
  878. if ($search_date_delivery_endday) {
  879. $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
  880. }
  881. if ($search_date_delivery_endmonth) {
  882. $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
  883. }
  884. if ($search_date_delivery_endyear) {
  885. $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
  886. }
  887. if ($search_ref) {
  888. $param .= '&search_ref='.urlencode($search_ref);
  889. }
  890. if ($search_refcustomer) {
  891. $param .= '&search_refcustomer='.urlencode($search_refcustomer);
  892. }
  893. if ($search_refproject) {
  894. $param .= '&search_refproject='.urlencode($search_refproject);
  895. }
  896. if ($search_societe) {
  897. $param .= '&search_societe='.urlencode($search_societe);
  898. }
  899. if ($search_societe_alias) {
  900. $param .= '&search_societe_alias='.urlencode($search_societe_alias);
  901. }
  902. if ($search_user > 0) {
  903. $param .= '&search_user='.urlencode($search_user);
  904. }
  905. if ($search_sale > 0) {
  906. $param .= '&search_sale='.urlencode($search_sale);
  907. }
  908. if ($search_montant_ht) {
  909. $param .= '&search_montant_ht='.urlencode($search_montant_ht);
  910. }
  911. if ($search_multicurrency_code != '') {
  912. $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
  913. }
  914. if ($search_multicurrency_tx != '') {
  915. $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
  916. }
  917. if ($search_multicurrency_montant_ht != '') {
  918. $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
  919. }
  920. if ($search_multicurrency_montant_vat != '') {
  921. $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
  922. }
  923. if ($search_multicurrency_montant_ttc != '') {
  924. $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
  925. }
  926. if ($search_login) {
  927. $param .= '&search_login='.urlencode($search_login);
  928. }
  929. if ($search_town) {
  930. $param .= '&search_town='.urlencode($search_town);
  931. }
  932. if ($search_zip) {
  933. $param .= '&search_zip='.urlencode($search_zip);
  934. }
  935. if ($socid > 0) {
  936. $param .= '&socid='.urlencode($socid);
  937. }
  938. if ($optioncss != '') {
  939. $param .= '&optioncss='.urlencode($optioncss);
  940. }
  941. if ($search_categ_cus > 0) {
  942. $param .= '&search_categ_cus='.urlencode($search_categ_cus);
  943. }
  944. if ($search_product_category != '') {
  945. $param .= '&search_product_category='.urlencode($search_product_category);
  946. }
  947. if ($search_fk_cond_reglement > 0) {
  948. $param .= '&search_fk_cond_reglement='.urlencode($search_fk_cond_reglement);
  949. }
  950. if ($search_fk_shipping_method > 0) {
  951. $param .= '&search_fk_shipping_method='.urlencode($search_fk_shipping_method);
  952. }
  953. if ($search_fk_input_reason > 0) {
  954. $param .= '&search_fk_input_reason='.urlencode($search_fk_input_reason);
  955. }
  956. if ($search_fk_mode_reglement > 0) {
  957. $param .= '&search_fk_mode_reglement='.urlencode($search_fk_mode_reglement);
  958. }
  959. if ($search_type_thirdparty > 0) {
  960. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  961. }
  962. if ($search_town) {
  963. $param .= '&search_town='.urlencode($search_town);
  964. }
  965. if ($search_zip) {
  966. $param .= '&search_zip='.urlencode($search_zip);
  967. }
  968. if ($search_state) {
  969. $param .= '&search_state='.urlencode($search_state);
  970. }
  971. if ($search_town) {
  972. $param .= '&search_town='.urlencode($search_town);
  973. }
  974. if ($search_country) {
  975. $param .= '&search_country='.urlencode($search_country);
  976. }
  977. if ($search_date_signature_startday) {
  978. $param .= '&search_date_signature_startday='.urlencode($search_date_signature_startday);
  979. }
  980. if ($search_date_signature_startmonth) {
  981. $param .= '&search_date_signature_startmonth='.urlencode($search_date_signature_startmonth);
  982. }
  983. if ($search_date_signature_startyear) {
  984. $param .= '&search_date_signature_startyear='.urlencode($search_date_signature_startyear);
  985. }
  986. if ($search_date_signature_endday) {
  987. $param .= '&search_date_signature_endday='.urlencode($search_date_signature_endday);
  988. }
  989. if ($search_date_signature_endmonth) {
  990. $param .= '&search_date_signature_endmonth='.urlencode($search_date_signature_endmonth);
  991. }
  992. if ($search_date_signature_endyear) {
  993. $param .= '&search_date_signature_endyear='.urlencode($search_date_signature_endyear);
  994. }
  995. // Add $param from extra fields
  996. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  997. // Add $param from hooks
  998. $parameters = array();
  999. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1000. $param .= $hookmanager->resPrint;
  1001. // List of mass actions available
  1002. $arrayofmassactions = array(
  1003. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  1004. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  1005. );
  1006. if ($permissiontosendbymail) {
  1007. $arrayofmassactions['presend']=img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail");
  1008. }
  1009. if ($permissiontovalidate) {
  1010. $arrayofmassactions['prevalidate']=img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
  1011. }
  1012. if ($permissiontoclose) {
  1013. $arrayofmassactions['presign']=img_picto('', 'propal', 'class="pictofixedwidth"').$langs->trans("Sign");
  1014. $arrayofmassactions['nopresign']=img_picto('', 'propal', 'class="pictofixedwidth"').$langs->trans("NoSign");
  1015. $arrayofmassactions['setbilled'] =img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("ClassifyBilled");
  1016. }
  1017. if ($permissiontodelete) {
  1018. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  1019. }
  1020. if (in_array($massaction, array('presend', 'predelete', 'closed'))) {
  1021. $arrayofmassactions = array();
  1022. }
  1023. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  1024. $url = DOL_URL_ROOT.'/comm/propal/card.php?action=create';
  1025. if (!empty($socid)) {
  1026. $url .= '&socid='.$socid;
  1027. }
  1028. $newcardbutton = '';
  1029. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  1030. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  1031. $newcardbutton .= dolGetButtonTitleSeparator();
  1032. $newcardbutton .= dolGetButtonTitle($langs->trans('NewPropal'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('propal', 'creer'));
  1033. // Fields title search
  1034. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  1035. if ($optioncss != '') {
  1036. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  1037. }
  1038. print '<input type="hidden" name="token" value="'.newToken().'">';
  1039. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  1040. print '<input type="hidden" name="action" value="list">';
  1041. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  1042. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  1043. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  1044. print '<input type="hidden" name="mode"value="'.$mode.'">';
  1045. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'propal', 0, $newcardbutton, '', $limit, 0, 0, 1);
  1046. $topicmail = "SendPropalRef";
  1047. $modelmail = "propal_send";
  1048. $objecttmp = new Propal($db);
  1049. $trackid = 'pro'.$object->id;
  1050. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  1051. if ($massaction == 'prevalidate') {
  1052. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
  1053. }
  1054. if ($massaction == 'presign') {
  1055. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassSignature"), $langs->trans("ConfirmMassSignatureQuestion"), "sign", null, '', 0, 200, 500, 1);
  1056. }
  1057. if ($massaction == 'nopresign') {
  1058. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassNoSignature"), $langs->trans("ConfirmMassNoSignatureQuestion"), "nosign", null, '', 0, 200, 500, 1);
  1059. }
  1060. if ($search_all) {
  1061. foreach ($fieldstosearchall as $key => $val) {
  1062. $fieldstosearchall[$key] = $langs->trans($val);
  1063. }
  1064. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  1065. }
  1066. $i = 0;
  1067. $moreforfilter = '';
  1068. // If the user can view prospects other than his'
  1069. if ($user->hasRight('user', 'user', 'lire')) {
  1070. $langs->load("commercial");
  1071. $moreforfilter .= '<div class="divsearchfield">';
  1072. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  1073. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx', 1);
  1074. $moreforfilter .= '</div>';
  1075. }
  1076. // If the user can view prospects other than his'
  1077. if ($user->hasRight('user', 'user', 'lire')) {
  1078. $moreforfilter .= '<div class="divsearchfield">';
  1079. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  1080. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
  1081. $moreforfilter .= '</div>';
  1082. }
  1083. // If the user can view products
  1084. if (isModEnabled('categorie') && $user->hasRight('categorie', 'read') && ($user->hasRight('product', 'read') || $user->hasRight('service', 'read'))) {
  1085. $searchCategoryProductOperator = -1;
  1086. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1087. $tmptitle = $langs->trans('IncludingProductWithTag');
  1088. $formcategory = new FormCategory($db);
  1089. $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PRODUCT, array($search_product_category), 'maxwidth300', $searchCategoryProductOperator, 0, 0, $tmptitle);
  1090. }
  1091. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  1092. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1093. $moreforfilter .= '<div class="divsearchfield">';
  1094. $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
  1095. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle, (empty($conf->dol_optimize_smallscreen) ? 'maxwidth300 widthcentpercentminusx' : 'maxwidth250 widthcentpercentminusx'));
  1096. $moreforfilter .= '</div>';
  1097. }
  1098. if (isModEnabled('stock') && getDolGlobalString('WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL')) {
  1099. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  1100. $formproduct = new FormProduct($db);
  1101. $moreforfilter .= '<div class="divsearchfield">';
  1102. $tmptitle = $langs->trans('Warehouse');
  1103. $moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', $tmptitle, 0, 0, $tmptitle);
  1104. $moreforfilter .= '</div>';
  1105. }
  1106. $parameters = array();
  1107. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1108. if (empty($reshook)) {
  1109. $moreforfilter .= $hookmanager->resPrint;
  1110. } else {
  1111. $moreforfilter = $hookmanager->resPrint;
  1112. }
  1113. if (!empty($moreforfilter)) {
  1114. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1115. print $moreforfilter;
  1116. print '</div>';
  1117. }
  1118. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  1119. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  1120. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  1121. print '<div class="div-table-responsive">';
  1122. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  1123. print '<tr class="liste_titre_filter">';
  1124. // Action column
  1125. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1126. print '<td class="liste_titre" align="middle">';
  1127. $searchpicto = $form->showFilterButtons('left');
  1128. print $searchpicto;
  1129. print '</td>';
  1130. }
  1131. if (!empty($arrayfields['p.ref']['checked'])) {
  1132. print '<td class="liste_titre">';
  1133. print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  1134. print '</td>';
  1135. }
  1136. if (!empty($arrayfields['p.ref_client']['checked'])) {
  1137. print '<td class="liste_titre">';
  1138. print '<input class="flat maxwidth50" type="text" name="search_refcustomer" value="'.dol_escape_htmltag($search_refcustomer).'">';
  1139. print '</td>';
  1140. }
  1141. if (!empty($arrayfields['pr.ref']['checked'])) {
  1142. print '<td class="liste_titre">';
  1143. print '<input class="flat maxwidth50" type="text" name="search_refproject" value="'.dol_escape_htmltag($search_refproject).'">';
  1144. print '</td>';
  1145. }
  1146. if (!empty($arrayfields['pr.title']['checked'])) {
  1147. print '<td class="liste_titre">';
  1148. print '<input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'">';
  1149. print '</td>';
  1150. }
  1151. if (!empty($arrayfields['s.nom']['checked'])) {
  1152. print '<td class="liste_titre" align="left">';
  1153. print '<input class="flat maxwidth100" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
  1154. print '</td>';
  1155. }
  1156. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1157. print '<td class="liste_titre" align="left">';
  1158. print '<input class="flat maxwidth100" type="text" name="search_societe_alias" value="'.dol_escape_htmltag($search_societe_alias).'">';
  1159. print '</td>';
  1160. }
  1161. if (!empty($arrayfields['s.town']['checked'])) {
  1162. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.$search_town.'"></td>';
  1163. }
  1164. if (!empty($arrayfields['s.zip']['checked'])) {
  1165. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.$search_zip.'"></td>';
  1166. }
  1167. // State
  1168. if (!empty($arrayfields['state.nom']['checked'])) {
  1169. print '<td class="liste_titre">';
  1170. print '<input class="flat maxwidth50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  1171. print '</td>';
  1172. }
  1173. // Country
  1174. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1175. print '<td class="liste_titre" align="center">';
  1176. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  1177. print '</td>';
  1178. }
  1179. // Company type
  1180. if (!empty($arrayfields['typent.code']['checked'])) {
  1181. print '<td class="liste_titre maxwidth100onsmartphone" align="center">';
  1182. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
  1183. print ajax_combobox('search_type_thirdparty');
  1184. print '</td>';
  1185. }
  1186. // Date
  1187. if (!empty($arrayfields['p.date']['checked'])) {
  1188. print '<td class="liste_titre center">';
  1189. print '<div class="nowrapfordate">';
  1190. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1191. print '</div>';
  1192. print '<div class="nowrapfordate">';
  1193. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1194. print '</div>';
  1195. print '</td>';
  1196. }
  1197. // Date end
  1198. if (!empty($arrayfields['p.fin_validite']['checked'])) {
  1199. print '<td class="liste_titre center">';
  1200. print '<div class="nowrapfordate">';
  1201. print $form->selectDate($search_date_end_start ? $search_date_end_start : -1, 'search_date_end_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1202. print '</div>';
  1203. print '<div class="nowrapfordate">';
  1204. print $form->selectDate($search_date_end_end ? $search_date_end_end : -1, 'search_date_end_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1205. print '</div>';
  1206. print '</td>';
  1207. }
  1208. // Date delivery
  1209. if (!empty($arrayfields['p.date_livraison']['checked'])) {
  1210. print '<td class="liste_titre center">';
  1211. print '<div class="nowrapfordate">';
  1212. print $form->selectDate($search_date_delivery_start ? $search_date_delivery_start : -1, 'search_date_delivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1213. print '</div>';
  1214. print '<div class="nowrapfordate">';
  1215. print $form->selectDate($search_date_delivery_end ? $search_date_delivery_end : -1, 'search_date_delivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1216. print '</div>';
  1217. print '</td>';
  1218. }
  1219. // Date Signature
  1220. if (!empty($arrayfields['p.date_signature']['checked'])) {
  1221. print '<td class="liste_titre center">';
  1222. print '<div class="nowrapfordate">';
  1223. print $form->selectDate($search_date_signature_start ? $search_date_signature_start : -1, 'search_date_signature_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1224. print '</div>';
  1225. print '<div class="nowrapfordate">';
  1226. print $form->selectDate($search_date_signature_end ? $search_date_signature_end : -1, 'search_date_signature_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1227. print '</div>';
  1228. print '</td>';
  1229. }
  1230. // Availability
  1231. if (!empty($arrayfields['ava.rowid']['checked'])) {
  1232. print '<td class="liste_titre maxwidth100onsmartphone center">';
  1233. $form->selectAvailabilityDelay($search_availability, 'search_availability', '', 1);
  1234. print ajax_combobox('search_availability');
  1235. print '</td>';
  1236. }
  1237. // Shipping Method
  1238. if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
  1239. print '<td class="liste_titre">';
  1240. $form->selectShippingMethod($search_fk_shipping_method, 'search_fk_shipping_method', '', 1, '', 1);
  1241. print '</td>';
  1242. }
  1243. // Source - Input reason
  1244. if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
  1245. print '<td class="liste_titre">';
  1246. $form->selectInputReason($search_fk_input_reason, 'search_fk_input_reason', '', 1, 'maxwidth125', 1);
  1247. print '</td>';
  1248. }
  1249. // Payment term
  1250. if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
  1251. print '<td class="liste_titre">';
  1252. print $form->getSelectConditionsPaiements($search_fk_cond_reglement, 'search_fk_cond_reglement', 1, 1, 1);
  1253. print '</td>';
  1254. }
  1255. // Payment mode
  1256. if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
  1257. print '<td class="liste_titre">';
  1258. print $form->select_types_paiements($search_fk_mode_reglement, 'search_fk_mode_reglement', '', 0, 1, 1, 0, -1, '', 1);
  1259. print '</td>';
  1260. }
  1261. if (!empty($arrayfields['p.total_ht']['checked'])) {
  1262. // Amount
  1263. print '<td class="liste_titre right">';
  1264. print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
  1265. print '</td>';
  1266. }
  1267. if (!empty($arrayfields['p.total_tva']['checked'])) {
  1268. // Amount
  1269. print '<td class="liste_titre right">';
  1270. print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
  1271. print '</td>';
  1272. }
  1273. if (!empty($arrayfields['p.total_ttc']['checked'])) {
  1274. // Amount
  1275. print '<td class="liste_titre right">';
  1276. print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
  1277. print '</td>';
  1278. }
  1279. if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
  1280. // Amount invoiced
  1281. print '<td class="liste_titre right">';
  1282. print '</td>';
  1283. }
  1284. if (!empty($arrayfields['p.total_invoiced']['checked'])) {
  1285. // Amount invoiced
  1286. print '<td class="liste_titre right">';
  1287. print '</td>';
  1288. }
  1289. if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
  1290. // Currency
  1291. print '<td class="liste_titre">';
  1292. print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
  1293. print '</td>';
  1294. }
  1295. if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
  1296. // Currency rate
  1297. print '<td class="liste_titre">';
  1298. print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
  1299. print '</td>';
  1300. }
  1301. if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
  1302. // Amount
  1303. print '<td class="liste_titre right">';
  1304. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
  1305. print '</td>';
  1306. }
  1307. if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
  1308. // Amount
  1309. print '<td class="liste_titre right">';
  1310. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
  1311. print '</td>';
  1312. }
  1313. if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
  1314. // Amount
  1315. print '<td class="liste_titre right">';
  1316. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
  1317. print '</td>';
  1318. }
  1319. if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
  1320. // Amount invoiced
  1321. print '<td class="liste_titre right">';
  1322. print '</td>';
  1323. }
  1324. if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
  1325. // Amount invoiced
  1326. print '<td class="liste_titre right">';
  1327. print '</td>';
  1328. }
  1329. if (!empty($arrayfields['u.login']['checked'])) {
  1330. // Author
  1331. print '<td class="liste_titre">';
  1332. print '<input class="flat maxwidth75" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
  1333. print '</td>';
  1334. }
  1335. if (!empty($arrayfields['sale_representative']['checked'])) {
  1336. print '<td class="liste_titre"></td>';
  1337. }
  1338. if (!empty($arrayfields['total_pa']['checked'])) {
  1339. print '<td class="liste_titre right">';
  1340. print '</td>';
  1341. }
  1342. if (!empty($arrayfields['total_margin']['checked'])) {
  1343. print '<td class="liste_titre right">';
  1344. print '</td>';
  1345. }
  1346. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  1347. print '<td class="liste_titre right">';
  1348. print '</td>';
  1349. }
  1350. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  1351. print '<td class="liste_titre right">';
  1352. print '</td>';
  1353. }
  1354. // Extra fields
  1355. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1356. // Fields from hook
  1357. $parameters = array('arrayfields'=>$arrayfields);
  1358. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1359. print $hookmanager->resPrint;
  1360. // Date creation
  1361. if (!empty($arrayfields['p.datec']['checked'])) {
  1362. print '<td class="liste_titre">';
  1363. print '</td>';
  1364. }
  1365. // Date modification
  1366. if (!empty($arrayfields['p.tms']['checked'])) {
  1367. print '<td class="liste_titre">';
  1368. print '</td>';
  1369. }
  1370. // Date cloture
  1371. if (!empty($arrayfields['p.date_cloture']['checked'])) {
  1372. print '<td class="liste_titre">';
  1373. print '</td>';
  1374. }
  1375. if (!empty($arrayfields['p.note_public']['checked'])) {
  1376. // Note public
  1377. print '<td class="liste_titre">';
  1378. print '</td>';
  1379. }
  1380. if (!empty($arrayfields['p.note_private']['checked'])) {
  1381. // Note private
  1382. print '<td class="liste_titre">';
  1383. print '</td>';
  1384. }
  1385. // Status
  1386. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  1387. print '<td class="liste_titre center parentonrightofpage">';
  1388. $formpropal->selectProposalStatus($search_status, 1, 0, 1, 'customer', 'search_statut', 'search_status width100 onrightofpage');
  1389. print '</td>';
  1390. }
  1391. // Action column
  1392. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1393. print '<td class="liste_titre" align="middle">';
  1394. $searchpicto = $form->showFilterButtons();
  1395. print $searchpicto;
  1396. print '</td>';
  1397. }
  1398. print "</tr>\n";
  1399. $totalarray = array(
  1400. 'nbfield' => 0,
  1401. 'val' => array(
  1402. 'p.total_ht' => 0,
  1403. 'p.total_tva' => 0,
  1404. 'p.total_ttc' => 0,
  1405. ),
  1406. );
  1407. // Fields title
  1408. print '<tr class="liste_titre">';
  1409. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1410. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  1411. $totalarray['nbfield']++;
  1412. }
  1413. if (!empty($arrayfields['p.ref']['checked'])) {
  1414. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
  1415. $totalarray['nbfield']++;
  1416. }
  1417. if (!empty($arrayfields['p.ref_client']['checked'])) {
  1418. print_liste_field_titre($arrayfields['p.ref_client']['label'], $_SERVER["PHP_SELF"], 'p.ref_client', '', $param, '', $sortfield, $sortorder);
  1419. $totalarray['nbfield']++;
  1420. }
  1421. if (!empty($arrayfields['pr.ref']['checked'])) {
  1422. print_liste_field_titre($arrayfields['pr.ref']['label'], $_SERVER["PHP_SELF"], 'pr.ref', '', $param, '', $sortfield, $sortorder);
  1423. $totalarray['nbfield']++;
  1424. }
  1425. if (!empty($arrayfields['pr.title']['checked'])) {
  1426. print_liste_field_titre($arrayfields['pr.title']['label'], $_SERVER["PHP_SELF"], 'pr.title', '', $param, '', $sortfield, $sortorder);
  1427. $totalarray['nbfield']++;
  1428. }
  1429. if (!empty($arrayfields['s.nom']['checked'])) {
  1430. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
  1431. $totalarray['nbfield']++;
  1432. }
  1433. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1434. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder);
  1435. $totalarray['nbfield']++;
  1436. }
  1437. if (!empty($arrayfields['s.town']['checked'])) {
  1438. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  1439. $totalarray['nbfield']++;
  1440. }
  1441. if (!empty($arrayfields['s.zip']['checked'])) {
  1442. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  1443. $totalarray['nbfield']++;
  1444. }
  1445. if (!empty($arrayfields['state.nom']['checked'])) {
  1446. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  1447. $totalarray['nbfield']++;
  1448. }
  1449. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1450. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'class="center"', $sortfield, $sortorder);
  1451. $totalarray['nbfield']++;
  1452. }
  1453. if (!empty($arrayfields['typent.code']['checked'])) {
  1454. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'class="center"', $sortfield, $sortorder);
  1455. $totalarray['nbfield']++;
  1456. }
  1457. if (!empty($arrayfields['p.date']['checked'])) {
  1458. print_liste_field_titre($arrayfields['p.date']['label'], $_SERVER["PHP_SELF"], 'p.datep', '', $param, 'class="center"', $sortfield, $sortorder);
  1459. $totalarray['nbfield']++;
  1460. }
  1461. if (!empty($arrayfields['p.fin_validite']['checked'])) {
  1462. print_liste_field_titre($arrayfields['p.fin_validite']['label'], $_SERVER["PHP_SELF"], 'dfv', '', $param, 'class="center"', $sortfield, $sortorder);
  1463. $totalarray['nbfield']++;
  1464. }
  1465. if (!empty($arrayfields['p.date_livraison']['checked'])) {
  1466. print_liste_field_titre($arrayfields['p.date_livraison']['label'], $_SERVER["PHP_SELF"], 'p.date_livraison', '', $param, 'class="center"', $sortfield, $sortorder);
  1467. $totalarray['nbfield']++;
  1468. }
  1469. if (!empty($arrayfields['p.date_signature']['checked'])) {
  1470. print_liste_field_titre($arrayfields['p.date_signature']['label'], $_SERVER["PHP_SELF"], 'p.date_signature', '', $param, 'class="center"', $sortfield, $sortorder);
  1471. $totalarray['nbfield']++;
  1472. }
  1473. if (!empty($arrayfields['ava.rowid']['checked'])) {
  1474. print_liste_field_titre($arrayfields['ava.rowid']['label'], $_SERVER["PHP_SELF"], 'availability', '', $param, '', $sortfield, $sortorder);
  1475. $totalarray['nbfield']++;
  1476. }
  1477. if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
  1478. print_liste_field_titre($arrayfields['p.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "p.fk_shipping_method", "", $param, '', $sortfield, $sortorder);
  1479. $totalarray['nbfield']++;
  1480. }
  1481. if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
  1482. print_liste_field_titre($arrayfields['p.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "p.fk_input_reason", "", $param, '', $sortfield, $sortorder);
  1483. $totalarray['nbfield']++;
  1484. }
  1485. if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
  1486. print_liste_field_titre($arrayfields['p.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
  1487. $totalarray['nbfield']++;
  1488. }
  1489. if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
  1490. print_liste_field_titre($arrayfields['p.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
  1491. $totalarray['nbfield']++;
  1492. }
  1493. if (!empty($arrayfields['p.total_ht']['checked'])) {
  1494. print_liste_field_titre($arrayfields['p.total_ht']['label'], $_SERVER["PHP_SELF"], 'p.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
  1495. $totalarray['nbfield']++;
  1496. }
  1497. if (!empty($arrayfields['p.total_tva']['checked'])) {
  1498. print_liste_field_titre($arrayfields['p.total_tva']['label'], $_SERVER["PHP_SELF"], 'p.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
  1499. $totalarray['nbfield']++;
  1500. }
  1501. if (!empty($arrayfields['p.total_ttc']['checked'])) {
  1502. print_liste_field_titre($arrayfields['p.total_ttc']['label'], $_SERVER["PHP_SELF"], 'p.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
  1503. $totalarray['nbfield']++;
  1504. }
  1505. if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
  1506. print_liste_field_titre($arrayfields['p.total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1507. $totalarray['nbfield']++;
  1508. }
  1509. if (!empty($arrayfields['p.total_invoiced']['checked'])) {
  1510. print_liste_field_titre($arrayfields['p.total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1511. $totalarray['nbfield']++;
  1512. }
  1513. if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
  1514. print_liste_field_titre($arrayfields['p.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_code', '', $param, '', $sortfield, $sortorder);
  1515. $totalarray['nbfield']++;
  1516. }
  1517. if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
  1518. print_liste_field_titre($arrayfields['p.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
  1519. $totalarray['nbfield']++;
  1520. }
  1521. if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
  1522. print_liste_field_titre($arrayfields['p.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
  1523. $totalarray['nbfield']++;
  1524. }
  1525. if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
  1526. print_liste_field_titre($arrayfields['p.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
  1527. $totalarray['nbfield']++;
  1528. }
  1529. if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
  1530. print_liste_field_titre($arrayfields['p.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
  1531. $totalarray['nbfield']++;
  1532. }
  1533. if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
  1534. print_liste_field_titre($arrayfields['p.multicurrency_total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1535. $totalarray['nbfield']++;
  1536. }
  1537. if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
  1538. print_liste_field_titre($arrayfields['p.multicurrency_total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1539. $totalarray['nbfield']++;
  1540. }
  1541. if (!empty($arrayfields['u.login']['checked'])) {
  1542. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder, 'center ');
  1543. $totalarray['nbfield']++;
  1544. }
  1545. if (!empty($arrayfields['sale_representative']['checked'])) {
  1546. print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
  1547. $totalarray['nbfield']++;
  1548. }
  1549. if (!empty($arrayfields['total_pa']['checked'])) {
  1550. print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1551. $totalarray['nbfield']++;
  1552. }
  1553. if (!empty($arrayfields['total_margin']['checked'])) {
  1554. print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1555. $totalarray['nbfield']++;
  1556. }
  1557. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  1558. print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1559. $totalarray['nbfield']++;
  1560. }
  1561. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  1562. print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1563. $totalarray['nbfield']++;
  1564. }
  1565. // Extra fields
  1566. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1567. // Hook fields
  1568. $parameters = array(
  1569. 'arrayfields' => $arrayfields,
  1570. 'param' => $param,
  1571. 'sortfield' => $sortfield,
  1572. 'sortorder' => $sortorder,
  1573. 'totalarray' => &$totalarray,
  1574. );
  1575. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1576. print $hookmanager->resPrint;
  1577. if (!empty($arrayfields['p.datec']['checked'])) {
  1578. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowraponall ');
  1579. $totalarray['nbfield']++;
  1580. }
  1581. if (!empty($arrayfields['p.tms']['checked'])) {
  1582. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowraponall ');
  1583. $totalarray['nbfield']++;
  1584. }
  1585. if (!empty($arrayfields['p.date_cloture']['checked'])) {
  1586. print_liste_field_titre($arrayfields['p.date_cloture']['label'], $_SERVER["PHP_SELF"], "p.date_cloture", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  1587. $totalarray['nbfield']++;
  1588. }
  1589. if (!empty($arrayfields['p.note_public']['checked'])) {
  1590. print_liste_field_titre($arrayfields['p.note_public']['label'], $_SERVER["PHP_SELF"], "p.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1591. $totalarray['nbfield']++;
  1592. }
  1593. if (!empty($arrayfields['p.note_private']['checked'])) {
  1594. print_liste_field_titre($arrayfields['p.note_private']['label'], $_SERVER["PHP_SELF"], "p.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1595. $totalarray['nbfield']++;
  1596. }
  1597. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  1598. print_liste_field_titre($arrayfields['p.fk_statut']['label'], $_SERVER["PHP_SELF"], "p.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
  1599. $totalarray['nbfield']++;
  1600. }
  1601. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1602. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  1603. $totalarray['nbfield']++;
  1604. }
  1605. print '</tr>'."\n";
  1606. // Loop on record
  1607. // --------------------------------------------------------------------
  1608. $typenArray = null;
  1609. $now = dol_now();
  1610. $with_margin_info = false;
  1611. if (isModEnabled('margin') && (
  1612. !empty($arrayfields['total_pa']['checked'])
  1613. || !empty($arrayfields['total_margin']['checked'])
  1614. || !empty($arrayfields['total_margin_rate']['checked'])
  1615. || !empty($arrayfields['total_mark_rate']['checked'])
  1616. )
  1617. ) {
  1618. $with_margin_info = true;
  1619. }
  1620. $total_ht = 0;
  1621. $total_margin = 0;
  1622. $i = 0;
  1623. $savnbfield = $totalarray['nbfield'];
  1624. $totalarray = array();
  1625. $totalarray['nbfield'] = 0;
  1626. $imaxinloop = ($limit ? min($num, $limit) : $num);
  1627. while ($i < $imaxinloop) {
  1628. $obj = $db->fetch_object($resql);
  1629. if (empty($obj)) {
  1630. break; // Should not happen
  1631. }
  1632. $objectstatic->id = $obj->rowid;
  1633. $objectstatic->ref = $obj->ref;
  1634. $objectstatic->ref_client = $obj->ref_client;
  1635. $objectstatic->note_public = $obj->note_public;
  1636. $objectstatic->note_private = $obj->note_private;
  1637. $objectstatic->statut = $obj->status;
  1638. $objectstatic->status = $obj->status;
  1639. $companystatic->id = $obj->socid;
  1640. $companystatic->name = $obj->name;
  1641. $companystatic->name_alias = $obj->alias;
  1642. $companystatic->client = $obj->client;
  1643. $companystatic->fournisseur = $obj->fournisseur;
  1644. $companystatic->code_client = $obj->code_client;
  1645. $companystatic->email = $obj->email;
  1646. $companystatic->phone = $obj->phone;
  1647. $companystatic->address = $obj->address;
  1648. $companystatic->zip = $obj->zip;
  1649. $companystatic->town = $obj->town;
  1650. $companystatic->country_code = $obj->country_code;
  1651. $projectstatic->id = $obj->project_id;
  1652. $projectstatic->ref = $obj->project_ref;
  1653. $projectstatic->title = $obj->project_label;
  1654. $totalInvoicedHT = 0;
  1655. $totalInvoicedTTC = 0;
  1656. $multicurrency_totalInvoicedHT = 0;
  1657. $multicurrency_totalInvoicedTTC = 0;
  1658. $TInvoiceData = $objectstatic->InvoiceArrayList($obj->rowid);
  1659. if (!empty($TInvoiceData)) {
  1660. foreach ($TInvoiceData as $invoiceData) {
  1661. $invoice = new Facture($db);
  1662. $invoice->fetch($invoiceData->facid);
  1663. if (getDolGlobalString('FACTURE_DEPOSITS_ARE_JUST_PAYMENTS') && $invoice->type == Facture::TYPE_DEPOSIT) {
  1664. continue;
  1665. }
  1666. $totalInvoicedHT += $invoice->total_ht;
  1667. $totalInvoicedTTC += $invoice->total_ttc;
  1668. $multicurrency_totalInvoicedHT += $invoice->multicurrency_total_ht;
  1669. $multicurrency_totalInvoicedTTC += $invoice->multicurrency_total_ttc;
  1670. }
  1671. }
  1672. $marginInfo = array();
  1673. if ($with_margin_info === true) {
  1674. $objectstatic->fetch_lines();
  1675. $marginInfo = $formmargin->getMarginInfosArray($objectstatic);
  1676. $total_ht += $obj->total_ht;
  1677. $total_margin += $marginInfo['total_margin'];
  1678. }
  1679. if ($mode == 'kanban') {
  1680. if ($i == 0) {
  1681. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  1682. print '<div class="box-flex-container kanban">';
  1683. }
  1684. // Output Kanban
  1685. $userstatic->fetch($obj->fk_user_author);
  1686. $arrayofparams = array('selected' => in_array($object->id, $arrayofselected), 'authorlink' => $userstatic->getNomUrl(-2), 'projectlink' => $projectstatic->getNomUrl(2));
  1687. print $objectstatic->getKanbanView('', $arrayofparams);
  1688. if ($i == ($imaxinloop - 1)) {
  1689. print '</div>';
  1690. print '</td></tr>';
  1691. }
  1692. } else {
  1693. print '<tr class="oddeven">';
  1694. // Action column
  1695. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1696. print '<td class="nowrap" align="center">';
  1697. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1698. $selected = 0;
  1699. if (in_array($obj->rowid, $arrayofselected)) {
  1700. $selected = 1;
  1701. }
  1702. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1703. }
  1704. print '</td>';
  1705. if (!$i) {
  1706. $totalarray['nbfield']++;
  1707. }
  1708. }
  1709. if (!empty($arrayfields['p.ref']['checked'])) {
  1710. print '<td class="nowraponall">';
  1711. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  1712. // Picto + Ref
  1713. print '<td class="nobordernopadding nowraponall">';
  1714. print $objectstatic->getNomUrl(1, '', '', 0, 1, (isset($conf->global->PROPAL_LIST_SHOW_NOTES) ? $conf->global->PROPAL_LIST_SHOW_NOTES : 1));
  1715. print '</td>';
  1716. // Warning
  1717. $warnornote = '';
  1718. if ($obj->status == Propal::STATUS_VALIDATED && $db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) {
  1719. $warnornote .= img_warning($langs->trans("Late"));
  1720. }
  1721. if ($warnornote) {
  1722. print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
  1723. print $warnornote;
  1724. print '</td>';
  1725. }
  1726. // Other picto tool
  1727. print '<td width="16" class="nobordernopadding right">';
  1728. $filename = dol_sanitizeFileName($obj->ref);
  1729. $filedir = $conf->propal->multidir_output[$obj->propal_entity].'/'.dol_sanitizeFileName($obj->ref);
  1730. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  1731. print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  1732. print '</td></tr></table>';
  1733. print "</td>\n";
  1734. if (!$i) {
  1735. $totalarray['nbfield']++;
  1736. }
  1737. }
  1738. if (!empty($arrayfields['p.ref_client']['checked'])) {
  1739. // Customer ref
  1740. print '<td class="nowrap tdoverflowmax200">';
  1741. print dol_escape_htmltag($obj->ref_client);
  1742. print '</td>';
  1743. if (!$i) {
  1744. $totalarray['nbfield']++;
  1745. }
  1746. }
  1747. if (!empty($arrayfields['pr.ref']['checked'])) {
  1748. // Project ref
  1749. print '<td class="nowraponall">';
  1750. if ($obj->project_id > 0) {
  1751. print $projectstatic->getNomUrl(1);
  1752. }
  1753. print '</td>';
  1754. if (!$i) {
  1755. $totalarray['nbfield']++;
  1756. }
  1757. }
  1758. if (!empty($arrayfields['pr.title']['checked'])) {
  1759. // Project label
  1760. print '<td class="nowrap">';
  1761. if ($obj->project_id > 0) {
  1762. print dol_escape_htmltag($projectstatic->title);
  1763. }
  1764. print '</td>';
  1765. if (!$i) {
  1766. $totalarray['nbfield']++;
  1767. }
  1768. }
  1769. // Thirdparty
  1770. if (!empty($arrayfields['s.nom']['checked'])) {
  1771. print '<td class="tdoverflowmax150">';
  1772. print $companystatic->getNomUrl(1, 'customer', 0, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
  1773. print '</td>';
  1774. if (!$i) {
  1775. $totalarray['nbfield']++;
  1776. }
  1777. }
  1778. // Alias
  1779. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1780. print '<td class="tdoverflowmax200">';
  1781. print $obj->alias;
  1782. print '</td>';
  1783. if (!$i) {
  1784. $totalarray['nbfield']++;
  1785. }
  1786. }
  1787. // Town
  1788. if (!empty($arrayfields['s.town']['checked'])) {
  1789. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
  1790. print dol_escape_htmltag($obj->town);
  1791. print '</td>';
  1792. if (!$i) {
  1793. $totalarray['nbfield']++;
  1794. }
  1795. }
  1796. // Zip
  1797. if (!empty($arrayfields['s.zip']['checked'])) {
  1798. print '<td class="nocellnopadd">';
  1799. print $obj->zip;
  1800. print '</td>';
  1801. if (!$i) {
  1802. $totalarray['nbfield']++;
  1803. }
  1804. }
  1805. // State
  1806. if (!empty($arrayfields['state.nom']['checked'])) {
  1807. print "<td>".$obj->state_name."</td>\n";
  1808. if (!$i) {
  1809. $totalarray['nbfield']++;
  1810. }
  1811. }
  1812. // Country
  1813. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1814. print '<td class="center">';
  1815. $tmparray = getCountry($obj->fk_pays, 'all');
  1816. print $tmparray['label'];
  1817. print '</td>';
  1818. if (!$i) {
  1819. $totalarray['nbfield']++;
  1820. }
  1821. }
  1822. // Type ent
  1823. if (!empty($arrayfields['typent.code']['checked'])) {
  1824. if (!is_array($typenArray) || empty($typenArray)) {
  1825. $typenArray = $formcompany->typent_array(1);
  1826. }
  1827. print '<td class="center">';
  1828. print $typenArray[$obj->typent_code];
  1829. print '</td>';
  1830. if (!$i) {
  1831. $totalarray['nbfield']++;
  1832. }
  1833. }
  1834. // Date proposal
  1835. if (!empty($arrayfields['p.date']['checked'])) {
  1836. print '<td class="center">';
  1837. print dol_print_date($db->jdate($obj->dp), 'day');
  1838. print "</td>\n";
  1839. if (!$i) {
  1840. $totalarray['nbfield']++;
  1841. }
  1842. }
  1843. // Date end validity
  1844. if (!empty($arrayfields['p.fin_validite']['checked'])) {
  1845. if ($obj->dfv) {
  1846. print '<td class="center">'.dol_print_date($db->jdate($obj->dfv), 'day');
  1847. print '</td>';
  1848. } else {
  1849. print '<td>&nbsp;</td>';
  1850. }
  1851. if (!$i) {
  1852. $totalarray['nbfield']++;
  1853. }
  1854. }
  1855. // Date delivery
  1856. if (!empty($arrayfields['p.date_livraison']['checked'])) {
  1857. if ($obj->ddelivery) {
  1858. print '<td class="center">'.dol_print_date($db->jdate($obj->ddelivery), 'day');
  1859. print '</td>';
  1860. } else {
  1861. print '<td>&nbsp;</td>';
  1862. }
  1863. if (!$i) {
  1864. $totalarray['nbfield']++;
  1865. }
  1866. }
  1867. // Date Signature
  1868. if (!empty($arrayfields['p.date_signature']['checked'])) {
  1869. if ($obj->dsignature) {
  1870. print '<td class="center">'.dol_print_date($db->jdate($obj->dsignature), 'day');
  1871. print '</td>';
  1872. } else {
  1873. print '<td>&nbsp;</td>';
  1874. }
  1875. if (!$i) {
  1876. $totalarray['nbfield']++;
  1877. }
  1878. }
  1879. // Availability
  1880. if (!empty($arrayfields['ava.rowid']['checked'])) {
  1881. print '<td class="center">';
  1882. $form->form_availability('', $obj->availability, 'none', 1);
  1883. print '</td>';
  1884. if (!$i) {
  1885. $totalarray['nbfield']++;
  1886. }
  1887. }
  1888. // Shipping Method
  1889. if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
  1890. print '<td>';
  1891. $form->formSelectShippingMethod('', $obj->fk_shipping_method, 'none', 1);
  1892. print '</td>';
  1893. if (!$i) {
  1894. $totalarray['nbfield']++;
  1895. }
  1896. }
  1897. // Source - input reason
  1898. if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
  1899. print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($form->cache_demand_reason[$obj->fk_input_reason]['label']).'">';
  1900. if ($obj->fk_input_reason > 0) {
  1901. print $form->cache_demand_reason[$obj->fk_input_reason]['label'];
  1902. }
  1903. print '</td>';
  1904. if (!$i) {
  1905. $totalarray['nbfield']++;
  1906. }
  1907. }
  1908. // Payment terms
  1909. if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
  1910. print '<td>';
  1911. $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 0, '', 1, $obj->deposit_percent);
  1912. print '</td>';
  1913. if (!$i) {
  1914. $totalarray['nbfield']++;
  1915. }
  1916. }
  1917. // Payment mode
  1918. if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
  1919. print '<td>';
  1920. $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
  1921. print '</td>';
  1922. if (!$i) {
  1923. $totalarray['nbfield']++;
  1924. }
  1925. }
  1926. // Amount HT
  1927. if (!empty($arrayfields['p.total_ht']['checked'])) {
  1928. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
  1929. if (!$i) {
  1930. $totalarray['nbfield']++;
  1931. }
  1932. if (!$i) {
  1933. $totalarray['pos'][$totalarray['nbfield']] = 'p.total_ht';
  1934. }
  1935. if (empty($totalarray['val']['p.total_ht'])) {
  1936. $totalarray['val']['p.total_ht'] = $obj->total_ht;
  1937. } else {
  1938. $totalarray['val']['p.total_ht'] += $obj->total_ht;
  1939. }
  1940. }
  1941. // Amount VAT
  1942. if (!empty($arrayfields['p.total_tva']['checked'])) {
  1943. print '<td class="nowrap right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
  1944. if (!$i) {
  1945. $totalarray['nbfield']++;
  1946. }
  1947. if (!$i) {
  1948. $totalarray['pos'][$totalarray['nbfield']] = 'p.total_tva';
  1949. }
  1950. if (empty($totalarray['val']['p.total_tva'])) {
  1951. $totalarray['val']['p.total_tva'] = $obj->total_tva;
  1952. } else {
  1953. $totalarray['val']['p.total_tva'] += $obj->total_tva;
  1954. }
  1955. }
  1956. // Amount TTC
  1957. if (!empty($arrayfields['p.total_ttc']['checked'])) {
  1958. print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
  1959. if (!$i) {
  1960. $totalarray['nbfield']++;
  1961. }
  1962. if (!$i) {
  1963. $totalarray['pos'][$totalarray['nbfield']] = 'p.total_ttc';
  1964. }
  1965. if (empty($totalarray['val']['p.total_ttc'])) {
  1966. $totalarray['val']['p.total_ttc'] = $obj->total_ttc;
  1967. } else {
  1968. $totalarray['val']['p.total_ttc'] += $obj->total_ttc;
  1969. }
  1970. }
  1971. // Amount invoiced HT
  1972. if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
  1973. print '<td class="nowrap right"><span class="amount">'.price($totalInvoicedHT)."</span></td>\n";
  1974. if (!$i) {
  1975. $totalarray['nbfield']++;
  1976. }
  1977. if (!$i) {
  1978. $totalarray['pos'][$totalarray['nbfield']] = 'p.total_ht_invoiced';
  1979. }
  1980. if (empty($totalarray['val']['p.total_ht_invoiced'])) {
  1981. $totalarray['val']['p.total_ht_invoiced'] = $totalInvoicedHT;
  1982. } else {
  1983. $totalarray['val']['p.total_ht_invoiced'] += $totalInvoicedHT;
  1984. }
  1985. }
  1986. // Amount invoiced TTC
  1987. if (!empty($arrayfields['p.total_invoiced']['checked'])) {
  1988. print '<td class="nowrap right"><span class="amount">'.price($totalInvoicedTTC)."</span></td>\n";
  1989. if (!$i) {
  1990. $totalarray['nbfield']++;
  1991. }
  1992. if (!$i) {
  1993. $totalarray['pos'][$totalarray['nbfield']] = 'p.total_invoiced';
  1994. }
  1995. if (empty($totalarray['val']['p.total_invoiced'])) {
  1996. $totalarray['val']['p.total_invoiced'] = $totalInvoicedTTC;
  1997. } else {
  1998. $totalarray['val']['p.total_invoiced'] += $totalInvoicedTTC;
  1999. }
  2000. }
  2001. // Currency
  2002. if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
  2003. print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
  2004. if (!$i) {
  2005. $totalarray['nbfield']++;
  2006. }
  2007. }
  2008. // Currency rate
  2009. if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
  2010. print '<td class="nowrap">';
  2011. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
  2012. print "</td>\n";
  2013. if (!$i) {
  2014. $totalarray['nbfield']++;
  2015. }
  2016. }
  2017. // Amount HT
  2018. if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
  2019. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
  2020. if (!$i) {
  2021. $totalarray['nbfield']++;
  2022. }
  2023. }
  2024. // Amount VAT
  2025. if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
  2026. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n";
  2027. if (!$i) {
  2028. $totalarray['nbfield']++;
  2029. }
  2030. }
  2031. // Amount TTC
  2032. if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
  2033. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
  2034. if (!$i) {
  2035. $totalarray['nbfield']++;
  2036. }
  2037. }
  2038. // Amount invoiced
  2039. if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
  2040. print '<td class="nowrap right"><span class="amount">'.price($multicurrency_totalInvoicedHT)."</span></td>\n";
  2041. if (!$i) {
  2042. $totalarray['nbfield']++;
  2043. }
  2044. }
  2045. // Amount invoiced
  2046. if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
  2047. print '<td class="nowrap right"><span class="amount">'.price($multicurrency_totalInvoicedTTC)."</span></td>\n";
  2048. if (!$i) {
  2049. $totalarray['nbfield']++;
  2050. }
  2051. }
  2052. $userstatic->id = $obj->fk_user_author;
  2053. $userstatic->login = $obj->login;
  2054. $userstatic->lastname = $obj->lastname;
  2055. $userstatic->firstname = $obj->firstname;
  2056. $userstatic->email = $obj->user_email;
  2057. $userstatic->statut = $obj->user_statut;
  2058. $userstatic->entity = $obj->user_entity;
  2059. $userstatic->photo = $obj->photo;
  2060. $userstatic->office_phone = $obj->office_phone;
  2061. $userstatic->office_fax = $obj->office_fax;
  2062. $userstatic->user_mobile = $obj->user_mobile;
  2063. $userstatic->job = $obj->job;
  2064. $userstatic->gender = $obj->gender;
  2065. // Author
  2066. if (!empty($arrayfields['u.login']['checked'])) {
  2067. print '<td class="tdoverflowmax150">';
  2068. if ($userstatic->id) {
  2069. print $userstatic->getNomUrl(-1);
  2070. }
  2071. print "</td>\n";
  2072. if (!$i) {
  2073. $totalarray['nbfield']++;
  2074. }
  2075. }
  2076. if (!empty($arrayfields['sale_representative']['checked'])) {
  2077. // Sales representatives
  2078. print '<td class="tdoverflowmax125">';
  2079. if ($obj->socid > 0) {
  2080. $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
  2081. if ($listsalesrepresentatives < 0) {
  2082. dol_print_error($db);
  2083. }
  2084. $nbofsalesrepresentative = count($listsalesrepresentatives);
  2085. if ($nbofsalesrepresentative > 6) {
  2086. // We print only number
  2087. print $nbofsalesrepresentative;
  2088. } elseif ($nbofsalesrepresentative > 0) {
  2089. $userstatic = new User($db);
  2090. $j = 0;
  2091. foreach ($listsalesrepresentatives as $val) {
  2092. $userstatic->id = $val['id'];
  2093. $userstatic->lastname = $val['lastname'];
  2094. $userstatic->firstname = $val['firstname'];
  2095. $userstatic->email = $val['email'];
  2096. $userstatic->statut = $val['statut'];
  2097. $userstatic->entity = $val['entity'];
  2098. $userstatic->photo = $val['photo'];
  2099. $userstatic->login = $val['login'];
  2100. $userstatic->office_phone = $val['office_phone'];
  2101. $userstatic->office_fax = $val['office_fax'];
  2102. $userstatic->user_mobile = $val['user_mobile'];
  2103. $userstatic->job = $val['job'];
  2104. $userstatic->gender = $val['gender'];
  2105. //print '<div class="float">':
  2106. print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
  2107. $j++;
  2108. if ($j < $nbofsalesrepresentative) {
  2109. print ' ';
  2110. }
  2111. //print '</div>';
  2112. }
  2113. }
  2114. //else print $langs->trans("NoSalesRepresentativeAffected");
  2115. } else {
  2116. print '&nbsp;';
  2117. }
  2118. print '</td>';
  2119. if (!$i) {
  2120. $totalarray['nbfield']++;
  2121. }
  2122. }
  2123. // Total buying or cost price
  2124. if (!empty($arrayfields['total_pa']['checked'])) {
  2125. print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
  2126. if (!$i) {
  2127. $totalarray['nbfield']++;
  2128. }
  2129. }
  2130. // Total margin
  2131. if (!empty($arrayfields['total_margin']['checked'])) {
  2132. print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
  2133. if (!$i) {
  2134. $totalarray['nbfield']++;
  2135. }
  2136. if (!$i) {
  2137. $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
  2138. }
  2139. $totalarray['val']['total_margin'] = $total_margin;
  2140. }
  2141. // Total margin rate
  2142. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  2143. print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
  2144. if (!$i) {
  2145. $totalarray['nbfield']++;
  2146. }
  2147. }
  2148. // Total mark rate
  2149. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  2150. print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
  2151. if (!$i) {
  2152. $totalarray['nbfield']++;
  2153. }
  2154. if (!$i) {
  2155. $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
  2156. }
  2157. if ($i >= $imaxinloop - 1) {
  2158. if (!empty($total_ht)) {
  2159. $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
  2160. } else {
  2161. $totalarray['val']['total_mark_rate'] = '';
  2162. }
  2163. }
  2164. }
  2165. // Extra fields
  2166. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  2167. // Fields from hook
  2168. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  2169. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2170. print $hookmanager->resPrint;
  2171. // Date creation
  2172. if (!empty($arrayfields['p.datec']['checked'])) {
  2173. print '<td align="center" class="nowrap">';
  2174. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  2175. print '</td>';
  2176. if (!$i) {
  2177. $totalarray['nbfield']++;
  2178. }
  2179. }
  2180. // Date modification
  2181. if (!empty($arrayfields['p.tms']['checked'])) {
  2182. print '<td align="center" class="nowrap">';
  2183. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  2184. print '</td>';
  2185. if (!$i) {
  2186. $totalarray['nbfield']++;
  2187. }
  2188. }
  2189. // Date cloture
  2190. if (!empty($arrayfields['p.date_cloture']['checked'])) {
  2191. print '<td align="center" class="nowrap">';
  2192. print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
  2193. print '</td>';
  2194. if (!$i) {
  2195. $totalarray['nbfield']++;
  2196. }
  2197. }
  2198. // Note public
  2199. if (!empty($arrayfields['p.note_public']['checked'])) {
  2200. print '<td class="center">';
  2201. print dol_string_nohtmltag($obj->note_public);
  2202. print '</td>';
  2203. if (!$i) {
  2204. $totalarray['nbfield']++;
  2205. }
  2206. }
  2207. // Note private
  2208. if (!empty($arrayfields['p.note_private']['checked'])) {
  2209. print '<td class="center">';
  2210. print dol_string_nohtmltag($obj->note_private);
  2211. print '</td>';
  2212. if (!$i) {
  2213. $totalarray['nbfield']++;
  2214. }
  2215. }
  2216. // Status
  2217. if (!empty($arrayfields['p.fk_statut']['checked'])) {
  2218. print '<td class="nowrap center">'.$objectstatic->getLibStatut(5).'</td>';
  2219. if (!$i) {
  2220. $totalarray['nbfield']++;
  2221. }
  2222. }
  2223. // Action column
  2224. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  2225. print '<td class="nowrap" align="center">';
  2226. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  2227. $selected = 0;
  2228. if (in_array($obj->rowid, $arrayofselected)) {
  2229. $selected = 1;
  2230. }
  2231. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  2232. }
  2233. print '</td>';
  2234. if (!$i) {
  2235. $totalarray['nbfield']++;
  2236. }
  2237. }
  2238. print '</tr>'."\n";
  2239. }
  2240. $i++;
  2241. }
  2242. // Show total line
  2243. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  2244. // If no record found
  2245. if ($num == 0) {
  2246. $colspan = 1;
  2247. foreach ($arrayfields as $key => $val) {
  2248. if (!empty($val['checked'])) {
  2249. $colspan++;
  2250. }
  2251. }
  2252. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  2253. }
  2254. $db->free($resql);
  2255. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  2256. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2257. print $hookmanager->resPrint;
  2258. print '</table>'."\n";
  2259. print '</div>'."\n";
  2260. print '</form>'."\n";
  2261. if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  2262. $hidegeneratedfilelistifempty = 1;
  2263. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  2264. $hidegeneratedfilelistifempty = 0;
  2265. }
  2266. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  2267. $formfile = new FormFile($db);
  2268. // Show list of available documents
  2269. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  2270. $urlsource .= str_replace('&amp;', '&', $param);
  2271. $filedir = $diroutputmassaction;
  2272. $genallowed = $permissiontoread;
  2273. $delallowed = $permissiontoadd;
  2274. print $formfile->showdocuments('massfilesarea_proposals', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  2275. }
  2276. // End of page
  2277. llxFooter();
  2278. $db->close();