list.php 83 KB

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