list.php 97 KB

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