list.php 87 KB

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