list.php 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  6. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  9. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  10. * Copyright (C) 2018-2022 Charlene Benke <charlene@patas-monkey.com>
  11. * Copyright (C) 2019 Nicolas Zabouri <info@inovea-conseil.com>
  12. * Copyright (C) 2021-2023 Alexandre Spangaro <aspangaro@open-dsi.fr>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/fourn/commande/list.php
  29. * \ingroup fournisseur
  30. * \brief List of purchase orders
  31. */
  32. // Load Dolibarr environment
  33. require '../../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  45. // Load translation files required by the page
  46. $langs->loadLangs(array("orders", "sendings", 'deliveries', 'companies', 'compta', 'bills', 'projects', 'suppliers', 'products'));
  47. // Get Parameters
  48. $action = GETPOST('action', 'aZ09');
  49. $massaction = GETPOST('massaction', 'alpha');
  50. $show_files = GETPOST('show_files', 'int');
  51. $confirm = GETPOST('confirm', 'alpha');
  52. $toselect = GETPOST('toselect', 'array');
  53. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'supplierorderlist';
  54. $mode = GETPOST('mode', 'alpha');
  55. // Search Criteria
  56. $search_date_order_startday = GETPOST('search_date_order_startday', 'int');
  57. $search_date_order_startmonth = GETPOST('search_date_order_startmonth', 'int');
  58. $search_date_order_startyear = GETPOST('search_date_order_startyear', 'int');
  59. $search_date_order_endday = GETPOST('search_date_order_endday', 'int');
  60. $search_date_order_endmonth = GETPOST('search_date_order_endmonth', 'int');
  61. $search_date_order_endyear = GETPOST('search_date_order_endyear', 'int');
  62. $search_date_order_start = dol_mktime(0, 0, 0, $search_date_order_startmonth, $search_date_order_startday, $search_date_order_startyear); // Use tzserver
  63. $search_date_order_end = dol_mktime(23, 59, 59, $search_date_order_endmonth, $search_date_order_endday, $search_date_order_endyear);
  64. $search_date_delivery_startday = GETPOST('search_date_delivery_startday', 'int');
  65. $search_date_delivery_startmonth = GETPOST('search_date_delivery_startmonth', 'int');
  66. $search_date_delivery_startyear = GETPOST('search_date_delivery_startyear', 'int');
  67. $search_date_delivery_endday = GETPOST('search_date_delivery_endday', 'int');
  68. $search_date_delivery_endmonth = GETPOST('search_date_delivery_endmonth', 'int');
  69. $search_date_delivery_endyear = GETPOST('search_date_delivery_endyear', 'int');
  70. $search_date_delivery_start = dol_mktime(0, 0, 0, $search_date_delivery_startmonth, $search_date_delivery_startday, $search_date_delivery_startyear); // Use tzserver
  71. $search_date_delivery_end = dol_mktime(23, 59, 59, $search_date_delivery_endmonth, $search_date_delivery_endday, $search_date_delivery_endyear);
  72. $search_date_valid_startday = GETPOST('search_date_valid_startday', 'int');
  73. $search_date_valid_startmonth = GETPOST('search_date_valid_startmonth', 'int');
  74. $search_date_valid_startyear = GETPOST('search_date_valid_startyear', 'int');
  75. $search_date_valid_endday = GETPOST('search_date_valid_endday', 'int');
  76. $search_date_valid_endmonth = GETPOST('search_date_valid_endmonth', 'int');
  77. $search_date_valid_endyear = GETPOST('search_date_valid_endyear', 'int');
  78. $search_date_valid_start = dol_mktime(0, 0, 0, $search_date_valid_startmonth, $search_date_valid_startday, $search_date_valid_startyear); // Use tzserver
  79. $search_date_valid_end = dol_mktime(23, 59, 59, $search_date_valid_endmonth, $search_date_valid_endday, $search_date_valid_endyear);
  80. $search_date_approve_startday = GETPOST('search_date_approve_startday', 'int');
  81. $search_date_approve_startmonth = GETPOST('search_date_approve_startmonth', 'int');
  82. $search_date_approve_startyear = GETPOST('search_date_approve_startyear', 'int');
  83. $search_date_approve_endday = GETPOST('search_date_approve_endday', 'int');
  84. $search_date_approve_endmonth = GETPOST('search_date_approve_endmonth', 'int');
  85. $search_date_approve_endyear = GETPOST('search_date_approve_endyear', 'int');
  86. $search_date_approve_start = dol_mktime(0, 0, 0, $search_date_approve_startmonth, $search_date_approve_startday, $search_date_approve_startyear); // Use tzserver
  87. $search_date_approve_end = dol_mktime(23, 59, 59, $search_date_approve_endmonth, $search_date_approve_endday, $search_date_approve_endyear);
  88. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  89. $search_product_category = GETPOST('search_product_category', 'int');
  90. $search_ref = GETPOST('search_ref', 'alpha');
  91. $search_refsupp = GETPOST('search_refsupp', 'alpha');
  92. $search_company = GETPOST('search_company', 'alpha');
  93. $search_company_alias = GETPOST('search_company_alias', 'alpha');
  94. $search_town = GETPOST('search_town', 'alpha');
  95. $search_zip = GETPOST('search_zip', 'alpha');
  96. $search_state = GETPOST("search_state", 'alpha');
  97. $search_country = GETPOST("search_country", 'int');
  98. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  99. $search_user = GETPOST('search_user', 'int');
  100. $search_request_author = GETPOST('search_request_author', 'alpha');
  101. $search_ht = GETPOST('search_ht', 'alpha');
  102. $search_ttc = GETPOST('search_ttc', 'alpha');
  103. $optioncss = GETPOST('optioncss', 'alpha');
  104. $socid = GETPOST('socid', 'int');
  105. $search_sale = GETPOST('search_sale', 'int');
  106. $search_total_ht = GETPOST('search_total_ht', 'alpha');
  107. $search_total_tva = GETPOST('search_total_tva', 'alpha');
  108. $search_total_ttc = GETPOST('search_total_ttc', 'alpha');
  109. $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
  110. $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
  111. $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
  112. $search_multicurrency_montant_tva = GETPOST('search_multicurrency_montant_tva', 'alpha');
  113. $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
  114. $optioncss = GETPOST('optioncss', 'alpha');
  115. $search_billed = GETPOST('search_billed', 'int');
  116. $search_project_ref = GETPOST('search_project_ref', 'alpha');
  117. $search_btn = GETPOST('button_search', 'alpha');
  118. $search_remove_btn = GETPOST('button_removefilter', 'alpha');
  119. if (GETPOSTISARRAY('search_status')) {
  120. $search_status = join(',', GETPOST('search_status', 'array:intcomma'));
  121. } else {
  122. $search_status = (GETPOST('search_status', 'intcomma') != '' ? GETPOST('search_status', 'intcomma') : GETPOST('statut', 'intcomma'));
  123. }
  124. $diroutputmassaction = $conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id;
  125. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  126. $sortfield = GETPOST('sortfield', 'aZ09comma');
  127. $sortorder = GETPOST('sortorder', 'aZ09comma');
  128. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  129. if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
  130. $page = 0;
  131. } // If $page is not defined, or '' or -1
  132. $offset = $limit * $page;
  133. $pageprev = $page - 1;
  134. $pagenext = $page + 1;
  135. if (!$sortfield) {
  136. $sortfield = 'cf.ref';
  137. }
  138. if (!$sortorder) {
  139. $sortorder = 'DESC';
  140. }
  141. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  142. $object = new CommandeFournisseur($db);
  143. $hookmanager->initHooks(array('supplierorderlist'));
  144. $extrafields = new ExtraFields($db);
  145. // fetch optionals attributes and labels
  146. $extrafields->fetch_name_optionals_label($object->table_element);
  147. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  148. // List of fields to search into when doing a "search in all"
  149. $fieldstosearchall = array();
  150. foreach ($object->fields as $key => $val) {
  151. if (!empty($val['searchall'])) {
  152. $fieldstosearchall['cf.'.$key] = $val['label'];
  153. }
  154. }
  155. $fieldstosearchall['pd.description'] = 'Description';
  156. $fieldstosearchall['s.nom'] = "ThirdParty";
  157. $fieldstosearchall['s.name_alias'] = "AliasNameShort";
  158. $fieldstosearchall['s.zip'] = "Zip";
  159. $fieldstosearchall['s.town'] = "Town";
  160. if (empty($user->socid)) {
  161. $fieldstosearchall["cf.note_private"] = "NotePrivate";
  162. }
  163. $checkedtypetiers = 0;
  164. // Definition of array of fields for columns
  165. $arrayfields = array(
  166. 'u.login'=>array('label'=>"AuthorRequest", 'enabled'=>1, 'position'=>41),
  167. 's.name_alias'=>array('label'=>"AliasNameShort", 'position'=>51, 'checked'=>0),
  168. 's.town'=>array('label'=>"Town", 'enabled'=>1, 'position'=>55, 'checked'=>1),
  169. 's.zip'=>array('label'=>"Zip", 'enabled'=>1, 'position'=>56, 'checked'=>1),
  170. 'state.nom'=>array('label'=>"StateShort", 'enabled'=>1, 'position'=>57),
  171. 'country.code_iso'=>array('label'=>"Country", 'enabled'=>1, 'position'=>58),
  172. 'typent.code'=>array('label'=>"ThirdPartyType", 'enabled'=>$checkedtypetiers, 'position'=>59),
  173. 'cf.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>($mysoc->localtax1_assuj == "1"), 'position'=>140),
  174. 'cf.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>($mysoc->localtax2_assuj == "1"), 'position'=>145),
  175. 'cf.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'enabled'=>(!getDolGlobalInt('MAIN_LIST_HIDE_PUBLIC_NOTES')), 'position'=>750),
  176. 'cf.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'enabled'=>(!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES')), 'position'=>760),
  177. );
  178. foreach ($object->fields as $key => $val) {
  179. // If $val['visible']==0, then we never show the field
  180. if (!empty($val['visible'])) {
  181. $visible = (int) dol_eval($val['visible'], 1);
  182. $arrayfields['cf.'.$key] = array(
  183. 'label'=>$val['label'],
  184. 'checked'=>(($visible < 0) ? 0 : 1),
  185. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  186. 'position'=>$val['position'],
  187. 'help'=> isset($val['help']) ? $val['help'] : ''
  188. );
  189. }
  190. }
  191. // Extra fields
  192. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  193. $object->fields = dol_sort_array($object->fields, 'position');
  194. $arrayfields = dol_sort_array($arrayfields, 'position');
  195. $error = 0;
  196. if (!$user->hasRight('societe', 'client', 'voir')) {
  197. $search_sale = $user->id;
  198. }
  199. // Security check
  200. $orderid = GETPOST('orderid', 'int');
  201. if ($user->socid) {
  202. $socid = $user->socid;
  203. }
  204. $result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande');
  205. $permissiontoread = ($user->hasRight("fournisseur", "commande", "lire") || $user->hasRight("supplier_order", "lire"));
  206. $permissiontoadd = ($user->hasRight("fournisseur", "commande", "creer") || $user->hasRight("supplier_order", "creer"));
  207. $permissiontodelete = ($user->hasRight("fournisseur", "commande", "supprimer") || $user->hasRight("supplier_order", "supprimer"));
  208. $permissiontovalidate = $permissiontoadd;
  209. $permissiontoapprove = ($user->hasRight("fournisseur", "commande", "approuver") || $user->hasRight("supplier_order", "approuver"));
  210. /*
  211. * Actions
  212. */
  213. if (GETPOST('cancel', 'alpha')) {
  214. $action = 'list';
  215. $massaction = '';
  216. }
  217. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createsupplierbills') {
  218. $massaction = '';
  219. }
  220. $parameters = array('socid'=>$socid, 'arrayfields'=>&$arrayfields);
  221. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  222. if ($reshook < 0) {
  223. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  224. }
  225. if (empty($reshook)) {
  226. // Selection of new fields
  227. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  228. // Purge search criteria
  229. 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
  230. $search_categ = '';
  231. $search_user = '';
  232. $search_sale = '';
  233. $search_product_category = '';
  234. $search_ref = '';
  235. $search_refsupp = '';
  236. $search_company = '';
  237. $search_company_alias = '';
  238. $search_town = '';
  239. $search_zip = "";
  240. $search_state = "";
  241. $search_type = '';
  242. $search_country = '';
  243. $search_type_thirdparty = '';
  244. $search_request_author = '';
  245. $search_total_ht = '';
  246. $search_total_tva = '';
  247. $search_total_ttc = '';
  248. $search_multicurrency_code = '';
  249. $search_multicurrency_tx = '';
  250. $search_multicurrency_montant_ht = '';
  251. $search_multicurrency_montant_tva = '';
  252. $search_multicurrency_montant_ttc = '';
  253. $search_project_ref = '';
  254. $search_status = '';
  255. $search_date_order_startday = '';
  256. $search_date_order_startmonth = '';
  257. $search_date_order_startyear = '';
  258. $search_date_order_endday = '';
  259. $search_date_order_endmonth = '';
  260. $search_date_order_endyear = '';
  261. $search_date_order_start = '';
  262. $search_date_order_end = '';
  263. $search_date_delivery_startday = '';
  264. $search_date_delivery_startmonth = '';
  265. $search_date_delivery_startyear = '';
  266. $search_date_delivery_endday = '';
  267. $search_date_delivery_endmonth = '';
  268. $search_date_delivery_endyear = '';
  269. $search_date_delivery_start = '';
  270. $search_date_delivery_end = '';
  271. $search_date_valid_startday = '';
  272. $search_date_valid_startmonth = '';
  273. $search_date_valid_startyear = '';
  274. $search_date_valid_endday = '';
  275. $search_date_valid_endmonth = '';
  276. $search_date_valid_endyear = '';
  277. $search_date_valid_start = '';
  278. $search_date_valid_end = '';
  279. $search_date_approve_startday = '';
  280. $search_date_approve_startmonth = '';
  281. $search_date_approve_startyear = '';
  282. $search_date_approve_endday = '';
  283. $search_date_approve_endmonth = '';
  284. $search_date_approve_endyear = '';
  285. $search_date_approve_start = '';
  286. $search_date_approve_end = '';
  287. $billed = '';
  288. $search_billed = '';
  289. $toselect = array();
  290. $search_array_options = array();
  291. }
  292. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  293. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  294. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  295. }
  296. // Mass actions
  297. $objectclass = 'CommandeFournisseur';
  298. $objectlabel = 'SupplierOrders';
  299. $uploaddir = $conf->fournisseur->commande->dir_output;
  300. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  301. if ($action == 'validate' && $permissiontovalidate) {
  302. if (GETPOST('confirm') == 'yes') {
  303. $objecttmp = new CommandeFournisseur($db);
  304. $db->begin();
  305. $error = 0;
  306. foreach ($toselect as $checked) {
  307. if ($objecttmp->fetch($checked)) {
  308. if ($objecttmp->statut == 0) {
  309. $objecttmp->date_commande = dol_now();
  310. $result = $objecttmp->valid($user);
  311. if ($result >= 0) {
  312. // If we have permission, and if we don't need to provide the idwarehouse, we go directly on approved step
  313. if (!getDolGlobalString('SUPPLIER_ORDER_NO_DIRECT_APPROVE') && $permissiontoapprove && !(getDolGlobalString('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') && $objecttmp->hasProductsOrServices(1))) {
  314. $result = $objecttmp->approve($user);
  315. setEventMessages($langs->trans("SupplierOrderValidatedAndApproved"), array($objecttmp->ref));
  316. } else {
  317. setEventMessages($langs->trans("SupplierOrderValidated"), array($objecttmp->ref));
  318. }
  319. } else {
  320. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  321. $error++;
  322. }
  323. }
  324. }
  325. }
  326. if (!$error) {
  327. $db->commit();
  328. } else {
  329. $db->rollback();
  330. }
  331. }
  332. }
  333. // Mass action to generate vendor bills
  334. if ($massaction == 'confirm_createsupplierbills') {
  335. $orders = GETPOST('toselect', 'array');
  336. $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
  337. $validate_invoices = GETPOST('validate_invoices', 'int');
  338. $TFact = array();
  339. /** @var FactureFournisseur[] $TFactThird */
  340. $TFactThird = array();
  341. $nb_bills_created = 0;
  342. $lastid = 0;
  343. $lastref = '';
  344. $db->begin();
  345. $default_ref_supplier=dol_print_date(dol_now(), '%Y%m%d%H%M%S');
  346. foreach ($orders as $id_order) {
  347. $cmd = new CommandeFournisseur($db);
  348. if ($cmd->fetch($id_order) <= 0) {
  349. continue;
  350. }
  351. $objecttmp = new FactureFournisseur($db);
  352. if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) {
  353. $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created supplier invoice.
  354. } else {
  355. // Search if the VAT reverse-charge is activated by default in supplier card to resume the information
  356. if (!empty($cmd->socid) > 0) {
  357. $societe = new Societe($db);
  358. $societe->fetch($cmd->socid);
  359. $objecttmp->vat_reverse_charge = $societe->vat_reverse_charge;
  360. }
  361. $objecttmp->socid = $cmd->socid;
  362. $objecttmp->type = $objecttmp::TYPE_STANDARD;
  363. $objecttmp->cond_reglement_id = $cmd->cond_reglement_id;
  364. $objecttmp->mode_reglement_id = $cmd->mode_reglement_id;
  365. $objecttmp->fk_project = $cmd->fk_project;
  366. $objecttmp->multicurrency_code = $cmd->multicurrency_code;
  367. $objecttmp->ref_supplier = !empty($cmd->ref_supplier) ? $cmd->ref_supplier : $default_ref_supplier;
  368. $default_ref_supplier+=1;
  369. $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
  370. if (empty($datefacture)) {
  371. $datefacture = dol_now();
  372. }
  373. $objecttmp->date = $datefacture;
  374. $objecttmp->origin = 'order_supplier';
  375. $objecttmp->origin_id = $id_order;
  376. $res = $objecttmp->create($user);
  377. if ($res > 0) {
  378. $nb_bills_created++;
  379. $lastref = $objecttmp->ref;
  380. $lastid = $objecttmp->id;
  381. }
  382. }
  383. if ($objecttmp->id > 0) {
  384. $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
  385. $sql .= "fk_source";
  386. $sql .= ", sourcetype";
  387. $sql .= ", fk_target";
  388. $sql .= ", targettype";
  389. $sql .= ") VALUES (";
  390. $sql .= $id_order;
  391. $sql .= ", '".$db->escape($objecttmp->origin)."'";
  392. $sql .= ", ".((int) $objecttmp->id);
  393. $sql .= ", '".$db->escape($objecttmp->element)."'";
  394. $sql .= ")";
  395. if (!$db->query($sql)) {
  396. $erorr++;
  397. }
  398. if (!$error) {
  399. $lines = $cmd->lines;
  400. if (empty($lines) && method_exists($cmd, 'fetch_lines')) {
  401. $cmd->fetch_lines();
  402. $lines = $cmd->lines;
  403. }
  404. $fk_parent_line = 0;
  405. $num = count($lines);
  406. for ($i = 0; $i < $num; $i++) {
  407. $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
  408. if ($lines[$i]->subprice < 0) {
  409. // Negative line, we create a discount line
  410. $discount = new DiscountAbsolute($db);
  411. $discount->fk_soc = $objecttmp->socid;
  412. $discount->amount_ht = abs($lines[$i]->total_ht);
  413. $discount->amount_tva = abs($lines[$i]->total_tva);
  414. $discount->amount_ttc = abs($lines[$i]->total_ttc);
  415. $discount->tva_tx = $lines[$i]->tva_tx;
  416. $discount->fk_user = $user->id;
  417. $discount->description = $desc;
  418. $discountid = $discount->create($user);
  419. if ($discountid > 0) {
  420. $result = $objecttmp->insert_discount($discountid);
  421. //$result=$discount->link_to_invoice($lineid,$id);
  422. } else {
  423. setEventMessages($discount->error, $discount->errors, 'errors');
  424. $error++;
  425. break;
  426. }
  427. } else {
  428. // Positive line
  429. $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
  430. // Date start
  431. $date_start = false;
  432. if ($lines[$i]->date_debut_prevue) {
  433. $date_start = $lines[$i]->date_debut_prevue;
  434. }
  435. if ($lines[$i]->date_debut_reel) {
  436. $date_start = $lines[$i]->date_debut_reel;
  437. }
  438. if ($lines[$i]->date_start) {
  439. $date_start = $lines[$i]->date_start;
  440. }
  441. //Date end
  442. $date_end = false;
  443. if ($lines[$i]->date_fin_prevue) {
  444. $date_end = $lines[$i]->date_fin_prevue;
  445. }
  446. if ($lines[$i]->date_fin_reel) {
  447. $date_end = $lines[$i]->date_fin_reel;
  448. }
  449. if ($lines[$i]->date_end) {
  450. $date_end = $lines[$i]->date_end;
  451. }
  452. // Reset fk_parent_line for no child products and special product
  453. if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
  454. $fk_parent_line = 0;
  455. }
  456. $result = $objecttmp->addline(
  457. $desc,
  458. $lines[$i]->subprice,
  459. $lines[$i]->tva_tx,
  460. $lines[$i]->localtax1_tx,
  461. $lines[$i]->localtax2_tx,
  462. $lines[$i]->qty,
  463. $lines[$i]->fk_product,
  464. $lines[$i]->remise_percent,
  465. $date_start,
  466. $date_end,
  467. 0,
  468. $lines[$i]->info_bits,
  469. 'HT',
  470. $product_type,
  471. // we dont use the rank from orderline because we may have lines from several orders
  472. -1,
  473. false,
  474. $lines[$i]->array_options,
  475. $lines[$i]->fk_unit,
  476. // we use the id of each order, not the id of the first one stored in $objecttmp->origin_id
  477. $lines[$i]->fk_commande,
  478. $lines[$i]->pa_ht,
  479. $lines[$i]->ref_supplier,
  480. $lines[$i]->special_code,
  481. $fk_parent_line
  482. );
  483. if ($result > 0) {
  484. $lineid = $result;
  485. } else {
  486. $lineid = 0;
  487. $error++;
  488. break;
  489. }
  490. // Defined the new fk_parent_line
  491. if ($result > 0 && $lines[$i]->product_type == 9) {
  492. $fk_parent_line = $result;
  493. }
  494. }
  495. }
  496. }
  497. }
  498. $cmd->classifyBilled($user); // TODO Move this in workflow like done for sales orders
  499. if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) {
  500. $TFactThird[$cmd->socid] = $objecttmp;
  501. } else {
  502. $TFact[$objecttmp->id] = $objecttmp;
  503. }
  504. }
  505. // Build doc with all invoices
  506. $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
  507. $toselect = array();
  508. if (!$error && $validate_invoices) {
  509. $massaction = $action = 'builddoc';
  510. foreach ($TAllFact as &$objecttmp) {
  511. $objecttmp->validate($user);
  512. if ($result <= 0) {
  513. $error++;
  514. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  515. break;
  516. }
  517. $id = $objecttmp->id; // For builddoc action
  518. // Fac builddoc
  519. $donotredirect = 1;
  520. $upload_dir = $conf->fournisseur->facture->dir_output;
  521. $permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
  522. //include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  523. }
  524. $massaction = $action = 'confirm_createsupplierbills';
  525. }
  526. if (!$error) {
  527. $db->commit();
  528. if ($nb_bills_created == 1) {
  529. $texttoshow = $langs->trans('BillXCreated', '{s1}');
  530. $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow);
  531. setEventMessages($texttoshow, null, 'mesgs');
  532. } else {
  533. setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs');
  534. }
  535. // Make a redirect to avoid to bill twice if we make a refresh or back
  536. $param = '';
  537. if (!empty($mode)) {
  538. $param .= '&mode='.urlencode($mode);
  539. }
  540. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  541. $param .= '&contextpage='.urlencode($contextpage);
  542. }
  543. if ($limit > 0 && $limit != $conf->liste_limit) {
  544. $param .= '&limit='.((int) $limit);
  545. }
  546. if ($sall) {
  547. $param .= '&sall='.urlencode($sall);
  548. }
  549. if ($socid > 0) {
  550. $param .= '&socid='.urlencode($socid);
  551. }
  552. if ($search_status != '') {
  553. $param .= '&search_status='.urlencode($search_status);
  554. }
  555. if ($search_date_order_startday) {
  556. $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
  557. }
  558. if ($search_date_order_startmonth) {
  559. $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
  560. }
  561. if ($search_date_order_startyear) {
  562. $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
  563. }
  564. if ($search_date_order_endday) {
  565. $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
  566. }
  567. if ($search_date_order_endmonth) {
  568. $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
  569. }
  570. if ($search_date_order_endyear) {
  571. $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
  572. }
  573. if ($search_date_delivery_startday) {
  574. $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
  575. }
  576. if ($search_date_delivery_startmonth) {
  577. $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
  578. }
  579. if ($search_date_delivery_startyear) {
  580. $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
  581. }
  582. if ($search_date_delivery_endday) {
  583. $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
  584. }
  585. if ($search_date_delivery_endmonth) {
  586. $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
  587. }
  588. if ($search_date_delivery_endyear) {
  589. $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
  590. }
  591. if ($search_date_valid_startday) {
  592. $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
  593. }
  594. if ($search_date_valid_startmonth) {
  595. $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
  596. }
  597. if ($search_date_valid_startyear) {
  598. $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
  599. }
  600. if ($search_date_valid_endday) {
  601. $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
  602. }
  603. if ($search_date_valid_endmonth) {
  604. $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
  605. }
  606. if ($search_date_valid_endyear) {
  607. $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
  608. }
  609. if ($search_date_approve_startday) {
  610. $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
  611. }
  612. if ($search_date_approve_startmonth) {
  613. $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
  614. }
  615. if ($search_date_approve_startyear) {
  616. $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
  617. }
  618. if ($search_date_approve_endday) {
  619. $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
  620. }
  621. if ($search_date_approve_endmonth) {
  622. $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
  623. }
  624. if ($search_date_approve_endyear) {
  625. $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
  626. }
  627. if ($search_ref) {
  628. $param .= '&search_ref='.urlencode($search_ref);
  629. }
  630. if ($search_company) {
  631. $param .= '&search_company='.urlencode($search_company);
  632. }
  633. if ($search_company_alias) {
  634. $param .= '&search_company_alias='.urlencode($search_company_alias);
  635. }
  636. //if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer);
  637. if ($search_user > 0) {
  638. $param .= '&search_user='.urlencode($search_user);
  639. }
  640. if ($search_sale > 0) {
  641. $param .= '&search_sale='.urlencode($search_sale);
  642. }
  643. if ($search_total_ht != '') {
  644. $param .= '&search_total_ht='.urlencode($search_total_ht);
  645. }
  646. if ($search_total_tva != '') {
  647. $param .= '&search_total_tva='.urlencode($search_total_tva);
  648. }
  649. if ($search_total_ttc != '') {
  650. $param .= '&search_total_ttc='.urlencode($search_total_ttc);
  651. }
  652. if ($search_project_ref >= 0) {
  653. $param .= "&search_project_ref=".urlencode($search_project_ref);
  654. }
  655. if ($show_files) {
  656. $param .= '&show_files='.urlencode($show_files);
  657. }
  658. if ($optioncss != '') {
  659. $param .= '&optioncss='.urlencode($optioncss);
  660. }
  661. if ($billed != '') {
  662. $param .= '&billed='.urlencode($billed);
  663. }
  664. header("Location: ".$_SERVER['PHP_SELF'].'?'.$param);
  665. exit;
  666. } else {
  667. $db->rollback();
  668. $action = 'create';
  669. $_GET["origin"] = $_POST["origin"];
  670. $_GET["originid"] = $_POST["originid"];
  671. setEventMessages("Error", null, 'errors');
  672. $error++;
  673. }
  674. }
  675. }
  676. /*
  677. * View
  678. */
  679. $now = dol_now();
  680. $form = new Form($db);
  681. $thirdpartytmp = new Fournisseur($db);
  682. $commandestatic = new CommandeFournisseur($db);
  683. $formfile = new FormFile($db);
  684. $formorder = new FormOrder($db);
  685. $formother = new FormOther($db);
  686. $formcompany = new FormCompany($db);
  687. $title = $langs->trans("SuppliersOrders");
  688. if ($socid > 0) {
  689. $fourn = new Fournisseur($db);
  690. $fourn->fetch($socid);
  691. $title .= ' - '.$fourn->name;
  692. }
  693. /*if ($search_status)
  694. {
  695. if ($search_status == '1,2') $title .= ' - '.$langs->trans("SuppliersOrdersToProcess");
  696. elseif ($search_status == '3,4') $title .= ' - '.$langs->trans("SuppliersOrdersAwaitingReception");
  697. elseif ($search_status == '1,2,3') $title .= ' - '.$langs->trans("StatusOrderToProcessShort");
  698. elseif ($search_status == '6,7') $title .= ' - '.$langs->trans("StatusOrderCanceled");
  699. elseif (is_numeric($search_status) && $search_status >= 0) $title .= ' - '.$commandestatic->LibStatut($search_status);
  700. }*/
  701. if ($search_billed > 0) {
  702. $title .= ' - '.$langs->trans("Billed");
  703. }
  704. //$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
  705. $help_url = '';
  706. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  707. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  708. $sql = 'SELECT';
  709. if ($sall) {
  710. $sql = 'SELECT DISTINCT';
  711. }
  712. $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.email,';
  713. $sql .= " typent.code as typent_code,";
  714. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  715. $sql .= " cf.rowid, cf.ref, cf.ref_supplier, cf.fk_statut, cf.billed, cf.total_ht, cf.total_tva, cf.total_ttc, cf.fk_user_author, cf.date_commande as date_commande, cf.date_livraison as delivery_date, cf.date_valid, cf.date_approve,";
  716. $sql .= ' cf.localtax1 as total_localtax1, cf.localtax2 as total_localtax2,';
  717. $sql .= ' cf.fk_multicurrency, cf.multicurrency_code, cf.multicurrency_tx, cf.multicurrency_total_ht, cf.multicurrency_total_tva, cf.multicurrency_total_ttc,';
  718. $sql .= ' cf.date_creation as date_creation, cf.tms as date_update,';
  719. $sql .= ' cf.note_public, cf.note_private,';
  720. $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_title,";
  721. $sql .= " u.firstname, u.lastname, u.photo, u.login, u.email as user_email, u.statut as user_status";
  722. // Add fields from extrafields
  723. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  724. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  725. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  726. }
  727. }
  728. // Add fields from hooks
  729. $parameters = array();
  730. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  731. $sql .= $hookmanager->resPrint;
  732. $sqlfields = $sql; // $sql fields to remove for count total
  733. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  734. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  735. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  736. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  737. $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
  738. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  739. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cf.rowid = ef.fk_object)";
  740. }
  741. if ($sall) {
  742. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet as pd ON cf.rowid=pd.fk_commande';
  743. }
  744. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid";
  745. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cf.fk_projet";
  746. $parameters = array();
  747. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  748. $sql .= $hookmanager->resPrint;
  749. $sql .= ' WHERE cf.fk_soc = s.rowid';
  750. $sql .= ' AND cf.entity IN ('.getEntity('supplier_order').')';
  751. if ($socid > 0) {
  752. $sql .= " AND s.rowid = ".((int) $socid);
  753. }
  754. if ($search_ref) {
  755. $sql .= natural_search('cf.ref', $search_ref);
  756. }
  757. if ($search_refsupp) {
  758. $sql .= natural_search("cf.ref_supplier", $search_refsupp);
  759. }
  760. if ($sall) {
  761. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  762. }
  763. if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
  764. $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
  765. } else {
  766. if ($search_company) {
  767. $sql .= natural_search('s.nom', $search_company);
  768. }
  769. if ($search_company_alias) {
  770. $sql .= natural_search('s.name_alias', $search_company_alias);
  771. }
  772. }
  773. if ($search_request_author) {
  774. $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_request_author);
  775. }
  776. if ($search_billed != '' && $search_billed >= 0) {
  777. $sql .= " AND cf.billed = ".((int) $search_billed);
  778. }
  779. //Required triple check because statut=0 means draft filter
  780. if (GETPOST('statut', 'intcomma') !== '') {
  781. $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($db->escape(GETPOST('statut', 'intcomma')))).")";
  782. }
  783. if ($search_status != '' && $search_status != '-1') {
  784. $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($search_status)).")";
  785. }
  786. if ($search_date_order_start) {
  787. $sql .= " AND cf.date_commande >= '".$db->idate($search_date_order_start)."'";
  788. }
  789. if ($search_date_order_end) {
  790. $sql .= " AND cf.date_commande <= '".$db->idate($search_date_order_end)."'";
  791. }
  792. if ($search_date_delivery_start) {
  793. $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_delivery_start)."'";
  794. }
  795. if ($search_date_delivery_end) {
  796. $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_delivery_end)."'";
  797. }
  798. if ($search_date_valid_start) {
  799. $sql .= " AND cf.date_commande >= '".$db->idate($search_date_valid_start)."'";
  800. }
  801. if ($search_date_valid_end) {
  802. $sql .= " AND cf.date_commande <= '".$db->idate($search_date_valid_end)."'";
  803. }
  804. if ($search_date_approve_start) {
  805. $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_approve_start)."'";
  806. }
  807. if ($search_date_approve_end) {
  808. $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_approve_end)."'";
  809. }
  810. if ($search_town) {
  811. $sql .= natural_search('s.town', $search_town);
  812. }
  813. if ($search_zip) {
  814. $sql .= natural_search("s.zip", $search_zip);
  815. }
  816. if ($search_state) {
  817. $sql .= natural_search("state.nom", $search_state);
  818. }
  819. if ($search_country) {
  820. $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
  821. }
  822. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  823. $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
  824. }
  825. /*if ($search_sale > 0) {
  826. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
  827. }*/
  828. if ($search_user > 0) {
  829. $sql .= " AND EXISTS (";
  830. $sql .= " SELECT ec.rowid ";
  831. $sql .= " FROM " . MAIN_DB_PREFIX . "element_contact as ec";
  832. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_type_contact as tc ON tc.rowid = ec.fk_c_type_contact";
  833. $sql .= " WHERE ec.element_id = cf.rowid AND ec.fk_socpeople = " . ((int) $search_user);
  834. $sql .= " AND tc.element = 'order_supplier' AND tc.source = 'internal'";
  835. $sql .= ")";
  836. }
  837. if ($search_total_ht != '') {
  838. $sql .= natural_search('cf.total_ht', $search_total_ht, 1);
  839. }
  840. if ($search_total_tva != '') {
  841. $sql .= natural_search('cf.total_tva', $search_total_tva, 1);
  842. }
  843. if ($search_total_ttc != '') {
  844. $sql .= natural_search('cf.total_ttc', $search_total_ttc, 1);
  845. }
  846. if ($search_multicurrency_code != '') {
  847. $sql .= " AND cf.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
  848. }
  849. if ($search_multicurrency_tx != '') {
  850. $sql .= natural_search('cf.multicurrency_tx', $search_multicurrency_tx, 1);
  851. }
  852. if ($search_multicurrency_montant_ht != '') {
  853. $sql .= natural_search('cf.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
  854. }
  855. if ($search_multicurrency_montant_tva != '') {
  856. $sql .= natural_search('cf.multicurrency_total_tva', $search_multicurrency_montant_tva, 1);
  857. }
  858. if ($search_multicurrency_montant_ttc != '') {
  859. $sql .= natural_search('cf.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
  860. }
  861. if ($search_project_ref != '') {
  862. $sql .= natural_search("p.ref", $search_project_ref);
  863. }
  864. // Search on sale representative
  865. if ($search_sale && $search_sale != '-1') {
  866. if ($search_sale == -2) {
  867. $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = cf.fk_soc)";
  868. } elseif ($search_sale > 0) {
  869. $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = cf.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
  870. }
  871. }
  872. // Search for tag/category ($searchCategoryProductList is an array of ID)
  873. $searchCategoryProductOperator = -1;
  874. $searchCategoryProductList = array($search_product_category);
  875. if (!empty($searchCategoryProductList)) {
  876. $searchCategoryProductSqlList = array();
  877. $listofcategoryid = '';
  878. foreach ($searchCategoryProductList as $searchCategoryProduct) {
  879. if (intval($searchCategoryProduct) == -2) {
  880. $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commande_fournisseurdet as cd WHERE cd.fk_commande = cf.rowid AND cd.fk_product = ck.fk_product)";
  881. } elseif (intval($searchCategoryProduct) > 0) {
  882. if ($searchCategoryProductOperator == 0) {
  883. $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commande_fournisseurdet as cd WHERE cd.fk_commande = cf.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
  884. } else {
  885. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
  886. }
  887. }
  888. }
  889. if ($listofcategoryid) {
  890. $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."commande_fournisseurdet as cd WHERE cd.fk_commande = cf.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  891. }
  892. if ($searchCategoryProductOperator == 1) {
  893. if (!empty($searchCategoryProductSqlList)) {
  894. $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
  895. }
  896. } else {
  897. if (!empty($searchCategoryProductSqlList)) {
  898. $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
  899. }
  900. }
  901. }
  902. // Add where from extra fields
  903. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  904. // Add where from hooks
  905. $parameters = array();
  906. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  907. $sql .= $hookmanager->resPrint;
  908. // Count total nb of records
  909. $nbtotalofrecords = '';
  910. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  911. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  912. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  913. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  914. $resql = $db->query($sqlforcount);
  915. if ($resql) {
  916. $objforcount = $db->fetch_object($resql);
  917. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  918. } else {
  919. dol_print_error($db);
  920. }
  921. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  922. $page = 0;
  923. $offset = 0;
  924. }
  925. $db->free($resql);
  926. }
  927. $sql .= $db->order($sortfield, $sortorder);
  928. if ($limit) {
  929. $sql .= $db->plimit($limit + 1, $offset);
  930. }
  931. //print $sql;
  932. $resql = $db->query($sql);
  933. if ($resql) {
  934. $num = $db->num_rows($resql);
  935. $arrayofselected = is_array($toselect) ? $toselect : array();
  936. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $sall) {
  937. $obj = $db->fetch_object($resql);
  938. $id = $obj->rowid;
  939. header("Location: ".DOL_URL_ROOT.'/fourn/commande/card.php?id='.$id);
  940. exit;
  941. }
  942. llxHeader('', $title, $help_url);
  943. $param = '';
  944. if (!empty($mode)) {
  945. $param .= '&mode='.urlencode($mode);
  946. }
  947. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  948. $param .= '&contextpage='.urlencode($contextpage);
  949. }
  950. if ($limit > 0 && $limit != $conf->liste_limit) {
  951. $param .= '&limit='.((int) $limit);
  952. }
  953. if ($sall) {
  954. $param .= '&sall='.urlencode($sall);
  955. }
  956. if ($socid > 0) {
  957. $param .= '&socid='.urlencode($socid);
  958. }
  959. if ($sall) {
  960. $param .= "&search_all=".urlencode($sall);
  961. }
  962. if ($search_date_order_startday) {
  963. $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
  964. }
  965. if ($search_date_order_startmonth) {
  966. $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
  967. }
  968. if ($search_date_order_startyear) {
  969. $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
  970. }
  971. if ($search_date_order_endday) {
  972. $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
  973. }
  974. if ($search_date_order_endmonth) {
  975. $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
  976. }
  977. if ($search_date_order_endyear) {
  978. $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
  979. }
  980. if ($search_date_delivery_startday) {
  981. $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
  982. }
  983. if ($search_date_delivery_startmonth) {
  984. $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
  985. }
  986. if ($search_date_delivery_startyear) {
  987. $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
  988. }
  989. if ($search_date_delivery_endday) {
  990. $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
  991. }
  992. if ($search_date_delivery_endmonth) {
  993. $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
  994. }
  995. if ($search_date_delivery_endyear) {
  996. $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
  997. }
  998. if ($search_date_valid_startday) {
  999. $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
  1000. }
  1001. if ($search_date_valid_startmonth) {
  1002. $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
  1003. }
  1004. if ($search_date_valid_startyear) {
  1005. $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
  1006. }
  1007. if ($search_date_valid_endday) {
  1008. $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
  1009. }
  1010. if ($search_date_valid_endmonth) {
  1011. $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
  1012. }
  1013. if ($search_date_valid_endyear) {
  1014. $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
  1015. }
  1016. if ($search_date_approve_startday) {
  1017. $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
  1018. }
  1019. if ($search_date_approve_startmonth) {
  1020. $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
  1021. }
  1022. if ($search_date_approve_startyear) {
  1023. $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
  1024. }
  1025. if ($search_date_approve_endday) {
  1026. $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
  1027. }
  1028. if ($search_date_approve_endmonth) {
  1029. $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
  1030. }
  1031. if ($search_date_approve_endyear) {
  1032. $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
  1033. }
  1034. if ($search_ref) {
  1035. $param .= '&search_ref='.urlencode($search_ref);
  1036. }
  1037. if ($search_company) {
  1038. $param .= '&search_company='.urlencode($search_company);
  1039. }
  1040. if ($search_company_alias) {
  1041. $param .= '&search_company_alias='.urlencode($search_company_alias);
  1042. }
  1043. if ($search_user > 0) {
  1044. $param .= '&search_user='.urlencode($search_user);
  1045. }
  1046. if ($search_request_author) {
  1047. $param .= '&search_request_author='.urlencode($search_request_author);
  1048. }
  1049. if ($search_sale > 0) {
  1050. $param .= '&search_sale='.urlencode($search_sale);
  1051. }
  1052. if ($search_total_ht != '') {
  1053. $param .= '&search_total_ht='.urlencode($search_total_ht);
  1054. }
  1055. if ($search_total_ttc != '') {
  1056. $param .= "&search_total_ttc=".urlencode($search_total_ttc);
  1057. }
  1058. if ($search_multicurrency_code != '') {
  1059. $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
  1060. }
  1061. if ($search_multicurrency_tx != '') {
  1062. $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
  1063. }
  1064. if ($search_multicurrency_montant_ht != '') {
  1065. $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
  1066. }
  1067. if ($search_multicurrency_montant_tva != '') {
  1068. $param .= '&search_multicurrency_montant_tva='.urlencode($search_multicurrency_montant_tva);
  1069. }
  1070. if ($search_multicurrency_montant_ttc != '') {
  1071. $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
  1072. }
  1073. if ($search_refsupp) {
  1074. $param .= "&search_refsupp=".urlencode($search_refsupp);
  1075. }
  1076. if ($search_status != '' && $search_status != '-1') {
  1077. $param .= "&search_status=".urlencode($search_status);
  1078. }
  1079. if ($search_project_ref >= 0) {
  1080. $param .= "&search_project_ref=".urlencode($search_project_ref);
  1081. }
  1082. if ($search_billed != '') {
  1083. $param .= "&search_billed=".urlencode($search_billed);
  1084. }
  1085. if ($show_files) {
  1086. $param .= '&show_files='.urlencode($show_files);
  1087. }
  1088. if ($optioncss != '') {
  1089. $param .= '&optioncss='.urlencode($optioncss);
  1090. }
  1091. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  1092. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  1093. }
  1094. // Add $param from extra fields
  1095. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  1096. $parameters = array();
  1097. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  1098. $param .= $hookmanager->resPrint;
  1099. // List of mass actions available
  1100. $arrayofmassactions = array(
  1101. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  1102. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  1103. 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  1104. );
  1105. if ($permissiontovalidate) {
  1106. if ($permissiontoapprove && !getDolGlobalString('SUPPLIER_ORDER_NO_DIRECT_APPROVE')) {
  1107. $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ValidateAndApprove");
  1108. } else {
  1109. $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
  1110. }
  1111. }
  1112. if ($user->hasRight('fournisseur', 'facture', 'creer') || $user->hasRight("supplier_invoice", "creer")) {
  1113. $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisSupplier");
  1114. }
  1115. if ($permissiontodelete) {
  1116. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  1117. }
  1118. if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
  1119. $arrayofmassactions = array();
  1120. }
  1121. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  1122. $url = DOL_URL_ROOT.'/fourn/commande/card.php?action=create';
  1123. if ($socid > 0) {
  1124. $url .= '&socid='.((int) $socid);
  1125. $url .= '&backtopage='.urlencode(DOL_URL_ROOT.'/fourn/commande/list.php?socid='.((int) $socid));
  1126. }
  1127. $newcardbutton = '';
  1128. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  1129. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  1130. $newcardbutton .= dolGetButtonTitleSeparator();
  1131. $newcardbutton .= dolGetButtonTitle($langs->trans('NewSupplierOrderShort'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
  1132. // Lines of title fields
  1133. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  1134. if ($optioncss != '') {
  1135. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  1136. }
  1137. print '<input type="hidden" name="token" value="'.newToken().'">';
  1138. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  1139. print '<input type="hidden" name="action" value="list">';
  1140. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  1141. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  1142. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  1143. print '<input type="hidden" name="socid" value="'.$socid.'">';
  1144. print '<input type="hidden" name="mode" value="'.$mode.'">';
  1145. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_order', 0, $newcardbutton, '', $limit, 0, 0, 1);
  1146. $topicmail = "SendOrderRef";
  1147. $modelmail = "order_supplier_send";
  1148. $objecttmp = new CommandeFournisseur($db); // in case $object is not the good object
  1149. $trackid = 'sord'.$object->id;
  1150. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  1151. if ($massaction == 'prevalidate') {
  1152. print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
  1153. }
  1154. if ($massaction == 'createbills') {
  1155. //var_dump($_REQUEST);
  1156. print '<input type="hidden" name="massaction" value="confirm_createsupplierbills">';
  1157. print '<table class="noborder centpercent">';
  1158. print '<tr>';
  1159. print '<td class="titlefield">';
  1160. print $langs->trans('DateInvoice');
  1161. print '</td>';
  1162. print '<td>';
  1163. print $form->selectDate('', '', '', '', '', '', 1, 1);
  1164. print '</td>';
  1165. print '</tr>';
  1166. print '<tr>';
  1167. print '<td>';
  1168. print $langs->trans('CreateOneBillByThird');
  1169. print '</td>';
  1170. print '<td>';
  1171. print $form->selectyesno('createbills_onebythird', '', 1);
  1172. print '</td>';
  1173. print '</tr>';
  1174. print '<tr>';
  1175. print '<td>';
  1176. print $langs->trans('ValidateInvoices');
  1177. print '</td>';
  1178. print '<td>';
  1179. print $form->selectyesno('validate_invoices', 1, 1);
  1180. print '</td>';
  1181. print '</tr>';
  1182. print '</table>';
  1183. print '<div class="center">';
  1184. print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
  1185. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1186. print '</div>';
  1187. print '<br>';
  1188. print '<br>';
  1189. }
  1190. if ($sall) {
  1191. foreach ($fieldstosearchall as $key => $val) {
  1192. $fieldstosearchall[$key] = $langs->trans($val);
  1193. }
  1194. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  1195. }
  1196. $moreforfilter = '';
  1197. // If the user can view prospects other than his'
  1198. if ($user->hasRight("user", "user", "lire")) {
  1199. $langs->load("commercial");
  1200. $moreforfilter .= '<div class="divsearchfield">';
  1201. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  1202. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
  1203. $moreforfilter .= '</div>';
  1204. }
  1205. // If the user can view other users
  1206. if ($user->hasRight("user", "user", "lire")) {
  1207. $moreforfilter .= '<div class="divsearchfield">';
  1208. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  1209. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
  1210. $moreforfilter .= '</div>';
  1211. }
  1212. // If the user can view prospects other than his'
  1213. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
  1214. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1215. $moreforfilter .= '<div class="divsearchfield">';
  1216. $tmptitle = $langs->trans('IncludingProductWithTag');
  1217. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  1218. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1);
  1219. $moreforfilter .= '</div>';
  1220. }
  1221. $parameters = array();
  1222. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1223. if (empty($reshook)) {
  1224. $moreforfilter .= $hookmanager->resPrint;
  1225. } else {
  1226. $moreforfilter = $hookmanager->resPrint;
  1227. }
  1228. if (!empty($moreforfilter)) {
  1229. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1230. print $moreforfilter;
  1231. print '</div>';
  1232. }
  1233. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  1234. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  1235. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  1236. if (GETPOST('autoselectall', 'int')) {
  1237. $selectedfields .= '<script>';
  1238. $selectedfields .= ' $(document).ready(function() {';
  1239. $selectedfields .= ' console.log("Autoclick on checkforselects");';
  1240. $selectedfields .= ' $("#checkforselects").click();';
  1241. $selectedfields .= ' $("#massaction").val("createbills").change();';
  1242. $selectedfields .= ' });';
  1243. $selectedfields .= '</script>';
  1244. }
  1245. print '<div class="div-table-responsive">';
  1246. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  1247. print '<tr class="liste_titre_filter">';
  1248. // Action column
  1249. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1250. print '<td class="liste_titre middle">';
  1251. $searchpicto = $form->showFilterButtons('left');
  1252. print $searchpicto;
  1253. print '</td>';
  1254. }
  1255. // Ref
  1256. if (!empty($arrayfields['cf.ref']['checked'])) {
  1257. print '<td class="liste_titre"><input size="8" type="text" class="flat maxwidth75" name="search_ref" value="'.$search_ref.'"></td>';
  1258. }
  1259. // Ref customer
  1260. if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
  1261. print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_refsupp" value="'.$search_refsupp.'"></td>';
  1262. }
  1263. // Project ref
  1264. if (!empty($arrayfields['cf.fk_projet']['checked'])) {
  1265. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_project_ref" value="'.$search_project_ref.'"></td>';
  1266. }
  1267. // Request author
  1268. if (!empty($arrayfields['u.login']['checked'])) {
  1269. print '<td class="liste_titre">';
  1270. print '<input type="text" class="flat" size="6" name="search_request_author" value="'.$search_request_author.'">';
  1271. print '</td>';
  1272. }
  1273. // Thirpdarty
  1274. if (!empty($arrayfields['cf.fk_soc']['checked'])) {
  1275. print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company" value="'.$search_company.'"></td>';
  1276. }
  1277. // Alias
  1278. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1279. print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company_alias" value="'.$search_company_alias.'"></td>';
  1280. }
  1281. // Town
  1282. if (!empty($arrayfields['s.town']['checked'])) {
  1283. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.$search_town.'"></td>';
  1284. }
  1285. // Zip
  1286. if (!empty($arrayfields['s.zip']['checked'])) {
  1287. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.$search_zip.'"></td>';
  1288. }
  1289. // State
  1290. if (!empty($arrayfields['state.nom']['checked'])) {
  1291. print '<td class="liste_titre">';
  1292. print '<input class="flat maxwidth50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  1293. print '</td>';
  1294. }
  1295. // Country
  1296. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1297. print '<td class="liste_titre center">';
  1298. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  1299. print '</td>';
  1300. }
  1301. // Company type
  1302. if (!empty($arrayfields['typent.code']['checked'])) {
  1303. print '<td class="liste_titre maxwidthonsmartphone center">';
  1304. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
  1305. print '</td>';
  1306. }
  1307. // Date order
  1308. if (!empty($arrayfields['cf.date_commande']['checked'])) {
  1309. print '<td class="liste_titre center">';
  1310. print '<div class="nowrapfordate">';
  1311. print $form->selectDate($search_date_order_start ? $search_date_order_start : -1, 'search_date_order_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1312. print '</div>';
  1313. print '<div class="nowrapfordate">';
  1314. print $form->selectDate($search_date_order_end ? $search_date_order_end : -1, 'search_date_order_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1315. print '</div>';
  1316. print '</td>';
  1317. }
  1318. // Date delivery
  1319. if (!empty($arrayfields['cf.date_livraison']['checked'])) {
  1320. print '<td class="liste_titre center">';
  1321. print '<div class="nowrapfordate">';
  1322. 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'));
  1323. print '</div>';
  1324. print '<div class="nowrapfordate">';
  1325. 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('to'));
  1326. print '</div>';
  1327. print '</td>';
  1328. }
  1329. if (!empty($arrayfields['cf.total_ht']['checked'])) {
  1330. // Amount
  1331. print '<td class="liste_titre right">';
  1332. print '<input class="flat" type="text" size="5" name="search_total_ht" value="'.$search_total_ht.'">';
  1333. print '</td>';
  1334. }
  1335. if (!empty($arrayfields['cf.total_tva']['checked'])) {
  1336. // Amount
  1337. print '<td class="liste_titre right">';
  1338. print '<input class="flat" type="text" size="5" name="search_total_tva" value="'.$search_total_tva.'">';
  1339. print '</td>';
  1340. }
  1341. if (!empty($arrayfields['cf.total_ttc']['checked'])) {
  1342. // Amount
  1343. print '<td class="liste_titre right">';
  1344. print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
  1345. print '</td>';
  1346. }
  1347. if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
  1348. // Currency
  1349. print '<td class="liste_titre">';
  1350. print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
  1351. print '</td>';
  1352. }
  1353. if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
  1354. // Currency rate
  1355. print '<td class="liste_titre">';
  1356. print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
  1357. print '</td>';
  1358. }
  1359. if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
  1360. // Amount
  1361. print '<td class="liste_titre right">';
  1362. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
  1363. print '</td>';
  1364. }
  1365. if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
  1366. // Amount
  1367. print '<td class="liste_titre right">';
  1368. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_tva" value="'.dol_escape_htmltag($search_multicurrency_montant_tva).'">';
  1369. print '</td>';
  1370. }
  1371. if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
  1372. // Amount
  1373. print '<td class="liste_titre right">';
  1374. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
  1375. print '</td>';
  1376. }
  1377. // Extra fields
  1378. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1379. // Fields from hook
  1380. $parameters = array('arrayfields'=>$arrayfields);
  1381. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  1382. print $hookmanager->resPrint;
  1383. // Date creation
  1384. if (!empty($arrayfields['cf.date_creation']['checked'])) {
  1385. print '<td class="liste_titre">';
  1386. print '</td>';
  1387. }
  1388. // Date modification
  1389. if (!empty($arrayfields['cf.tms']['checked'])) {
  1390. print '<td class="liste_titre">';
  1391. print '</td>';
  1392. }
  1393. // Billed
  1394. if (!empty($arrayfields['cf.billed']['checked'])) {
  1395. print '<td class="liste_titre center parentonrightofpage">';
  1396. print $form->selectyesno('search_billed', $search_billed, 1, false, 1, 1, 'search_status width100 onrightofpage');
  1397. print '</td>';
  1398. }
  1399. // Status
  1400. if (!empty($arrayfields['cf.fk_statut']['checked'])) {
  1401. print '<td class="liste_titre center parentonrightofpage">';
  1402. $formorder->selectSupplierOrderStatus($search_status, 1, 'search_status', 'search_status width100 onrightofpage');
  1403. print '</td>';
  1404. }
  1405. // Date valid
  1406. if (!empty($arrayfields['cf.date_valid']['checked'])) {
  1407. print '<td class="liste_titre center">';
  1408. print '<div class="nowrapfordate">';
  1409. print $form->selectDate($search_date_valid_start ? $search_date_valid_start : -1, 'search_date_valid_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1410. print '</div>';
  1411. print '<div class="nowrapfordate">';
  1412. print $form->selectDate($search_date_valid_end ? $search_date_valid_end : -1, 'search_date_valid_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1413. print '</div>';
  1414. print '</td>';
  1415. }
  1416. // Date approve
  1417. if (!empty($arrayfields['cf.date_approve']['checked'])) {
  1418. print '<td class="liste_titre center">';
  1419. print '<div class="nowrapfordate">';
  1420. print $form->selectDate($search_date_approve_start ? $search_date_approve_start : -1, 'search_date_approve_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1421. print '</div>';
  1422. print '<div class="nowrapfordate">';
  1423. print $form->selectDate($search_date_approve_end ? $search_date_approve_end : -1, 'search_date_approve_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1424. print '</div>';
  1425. print '</td>';
  1426. }
  1427. // Note public
  1428. if (!empty($arrayfields['cf.note_public']['checked'])) {
  1429. print '<td class="liste_titre">';
  1430. print '</td>';
  1431. }
  1432. // Note private
  1433. if (!empty($arrayfields['cf.note_private']['checked'])) {
  1434. print '<td class="liste_titre">';
  1435. print '</td>';
  1436. }
  1437. // Action column
  1438. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1439. print '<td class="liste_titre center">';
  1440. $searchpicto = $form->showFilterButtons();
  1441. print $searchpicto;
  1442. print '</td>';
  1443. }
  1444. print "</tr>\n";
  1445. $totalarray = array();
  1446. $totalarray['nbfield'] = 0;
  1447. // Fields title
  1448. print '<tr class="liste_titre">';
  1449. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1450. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  1451. $totalarray['nbfield']++;
  1452. }
  1453. if (!empty($arrayfields['cf.ref']['checked'])) {
  1454. print_liste_field_titre($arrayfields['cf.ref']['label'], $_SERVER["PHP_SELF"], "cf.ref", "", $param, '', $sortfield, $sortorder);
  1455. $totalarray['nbfield']++;
  1456. }
  1457. if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
  1458. print_liste_field_titre($arrayfields['cf.ref_supplier']['label'], $_SERVER["PHP_SELF"], "cf.ref_supplier", "", $param, '', $sortfield, $sortorder, 'tdoverflowmax100imp ');
  1459. $totalarray['nbfield']++;
  1460. }
  1461. if (!empty($arrayfields['cf.fk_projet']['checked'])) {
  1462. print_liste_field_titre($arrayfields['cf.fk_projet']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  1463. $totalarray['nbfield']++;
  1464. }
  1465. if (!empty($arrayfields['u.login']['checked'])) {
  1466. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], "u.login", "", $param, '', $sortfield, $sortorder);
  1467. $totalarray['nbfield']++;
  1468. }
  1469. if (!empty($arrayfields['cf.fk_soc']['checked'])) {
  1470. print_liste_field_titre($arrayfields['cf.fk_soc']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
  1471. $totalarray['nbfield']++;
  1472. }
  1473. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1474. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", "", $param, '', $sortfield, $sortorder);
  1475. $totalarray['nbfield']++;
  1476. }
  1477. if (!empty($arrayfields['s.town']['checked'])) {
  1478. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  1479. $totalarray['nbfield']++;
  1480. }
  1481. if (!empty($arrayfields['s.zip']['checked'])) {
  1482. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  1483. $totalarray['nbfield']++;
  1484. }
  1485. if (!empty($arrayfields['state.nom']['checked'])) {
  1486. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  1487. $totalarray['nbfield']++;
  1488. }
  1489. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1490. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  1491. $totalarray['nbfield']++;
  1492. }
  1493. if (!empty($arrayfields['typent.code']['checked'])) {
  1494. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  1495. $totalarray['nbfield']++;
  1496. }
  1497. if (!empty($arrayfields['cf.fk_author']['checked'])) {
  1498. print_liste_field_titre($arrayfields['cf.fk_author']['label'], $_SERVER["PHP_SELF"], "cf.fk_author", "", $param, '', $sortfield, $sortorder);
  1499. $totalarray['nbfield']++;
  1500. }
  1501. if (!empty($arrayfields['cf.date_commande']['checked'])) {
  1502. print_liste_field_titre($arrayfields['cf.date_commande']['label'], $_SERVER["PHP_SELF"], "cf.date_commande", "", $param, '', $sortfield, $sortorder, 'center ');
  1503. $totalarray['nbfield']++;
  1504. }
  1505. if (!empty($arrayfields['cf.date_livraison']['checked'])) {
  1506. print_liste_field_titre($arrayfields['cf.date_livraison']['label'], $_SERVER["PHP_SELF"], 'cf.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
  1507. $totalarray['nbfield']++;
  1508. }
  1509. if (!empty($arrayfields['cf.total_ht']['checked'])) {
  1510. print_liste_field_titre($arrayfields['cf.total_ht']['label'], $_SERVER["PHP_SELF"], "cf.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
  1511. $totalarray['nbfield']++;
  1512. }
  1513. if (!empty($arrayfields['cf.total_tva']['checked'])) {
  1514. print_liste_field_titre($arrayfields['cf.total_tva']['label'], $_SERVER["PHP_SELF"], "cf.total_tva", "", $param, '', $sortfield, $sortorder, 'right ');
  1515. $totalarray['nbfield']++;
  1516. }
  1517. if (!empty($arrayfields['cf.total_ttc']['checked'])) {
  1518. print_liste_field_titre($arrayfields['cf.total_ttc']['label'], $_SERVER["PHP_SELF"], "cf.total_ttc", "", $param, '', $sortfield, $sortorder, 'right ');
  1519. $totalarray['nbfield']++;
  1520. }
  1521. if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
  1522. print_liste_field_titre($arrayfields['cf.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_code', '', $param, '', $sortfield, $sortorder);
  1523. $totalarray['nbfield']++;
  1524. }
  1525. if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
  1526. print_liste_field_titre($arrayfields['cf.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
  1527. $totalarray['nbfield']++;
  1528. }
  1529. if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
  1530. print_liste_field_titre($arrayfields['cf.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
  1531. $totalarray['nbfield']++;
  1532. }
  1533. if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
  1534. print_liste_field_titre($arrayfields['cf.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
  1535. $totalarray['nbfield']++;
  1536. }
  1537. if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
  1538. print_liste_field_titre($arrayfields['cf.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
  1539. $totalarray['nbfield']++;
  1540. }
  1541. // Extra fields
  1542. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1543. // Hook fields
  1544. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1545. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1546. print $hookmanager->resPrint;
  1547. if (!empty($arrayfields['cf.date_creation']['checked'])) {
  1548. print_liste_field_titre($arrayfields['cf.date_creation']['label'], $_SERVER["PHP_SELF"], "cf.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowraponall ');
  1549. $totalarray['nbfield']++;
  1550. }
  1551. if (!empty($arrayfields['cf.tms']['checked'])) {
  1552. print_liste_field_titre($arrayfields['cf.tms']['label'], $_SERVER["PHP_SELF"], "cf.tms", "", $param, '', $sortfield, $sortorder, 'center nowraponall ');
  1553. $totalarray['nbfield']++;
  1554. }
  1555. if (!empty($arrayfields['cf.billed']['checked'])) {
  1556. print_liste_field_titre($arrayfields['cf.billed']['label'], $_SERVER["PHP_SELF"], 'cf.billed', '', $param, '', $sortfield, $sortorder, 'center ');
  1557. $totalarray['nbfield']++;
  1558. }
  1559. if (!empty($arrayfields['cf.fk_statut']['checked'])) {
  1560. print_liste_field_titre($arrayfields['cf.fk_statut']['label'], $_SERVER["PHP_SELF"], "cf.fk_statut", "", $param, '', $sortfield, $sortorder, 'center ');
  1561. $totalarray['nbfield']++;
  1562. }
  1563. if (!empty($arrayfields['cf.date_valid']['checked'])) {
  1564. print_liste_field_titre($arrayfields['cf.date_valid']['label'], $_SERVER["PHP_SELF"], "cf.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
  1565. $totalarray['nbfield']++;
  1566. }
  1567. if (!empty($arrayfields['cf.date_approve']['checked'])) {
  1568. print_liste_field_titre($arrayfields['cf.date_approve']['label'], $_SERVER["PHP_SELF"], 'cf.date_approve', '', $param, '', $sortfield, $sortorder, 'center ');
  1569. $totalarray['nbfield']++;
  1570. }
  1571. if (!empty($arrayfields['cf.note_public']['checked'])) {
  1572. print_liste_field_titre($arrayfields['cf.note_public']['label'], $_SERVER["PHP_SELF"], "cf.note_public", "", $param, '', $sortfield, $sortorder, 'center ');
  1573. $totalarray['nbfield']++;
  1574. }
  1575. if (!empty($arrayfields['cf.note_private']['checked'])) {
  1576. print_liste_field_titre($arrayfields['cf.note_private']['label'], $_SERVER["PHP_SELF"], "cf.note_private", "", $param, '', $sortfield, $sortorder, 'center ');
  1577. $totalarray['nbfield']++;
  1578. }
  1579. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1580. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  1581. $totalarray['nbfield']++;
  1582. }
  1583. print "</tr>\n";
  1584. $total = 0;
  1585. $subtotal = 0;
  1586. $productstat_cache = array();
  1587. $userstatic = new User($db);
  1588. $objectstatic = new CommandeFournisseur($db);
  1589. $projectstatic = new Project($db);
  1590. $i = 0;
  1591. $savnbfield = $totalarray['nbfield'];
  1592. $totalarray = array('nbfield' => 0, 'val' => array(), 'pos' => array());
  1593. $totalarray['val']['cf.total_ht'] = 0;
  1594. $totalarray['val']['cf.total_ttc'] = 0;
  1595. $totalarray['val']['cf.total_tva'] = 0;
  1596. $imaxinloop = ($limit ? min($num, $limit) : $num);
  1597. while ($i < $imaxinloop) {
  1598. $obj = $db->fetch_object($resql);
  1599. $notshippable = 0;
  1600. $warning = 0;
  1601. $text_info = '';
  1602. $text_warning = '';
  1603. $nbprod = 0;
  1604. $objectstatic->id = $obj->rowid;
  1605. $objectstatic->ref = $obj->ref;
  1606. $objectstatic->ref_supplier = $obj->ref_supplier;
  1607. $objectstatic->socid = $obj->socid;
  1608. $objectstatic->total_ht = $obj->total_ht;
  1609. $objectstatic->total_tva = $obj->total_tva;
  1610. $objectstatic->total_ttc = $obj->total_ttc;
  1611. $objectstatic->date_commande = $db->jdate($obj->date_commande);
  1612. $objectstatic->delivery_date = $db->jdate($obj->delivery_date);
  1613. $objectstatic->note_public = $obj->note_public;
  1614. $objectstatic->note_private = $obj->note_private;
  1615. $objectstatic->statut = $obj->fk_statut;
  1616. if ($mode == 'kanban') {
  1617. if ($i == 0) {
  1618. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  1619. print '<div class="box-flex-container kanban">';
  1620. }
  1621. $thirdpartytmp->id = $obj->socid;
  1622. $thirdpartytmp->name = $obj->name;
  1623. $thirdpartytmp->email = $obj->email;
  1624. $thirdpartytmp->name_alias = $obj->alias;
  1625. $thirdpartytmp->client = $obj->client;
  1626. $thirdpartytmp->fournisseur = $obj->fournisseur;
  1627. // Output Kanban
  1628. print $objectstatic->getKanbanView('', array('thirdparty'=>$thirdpartytmp->getNomUrl('supplier', 0, 0, -1), 'selected' => in_array($objectstatic->id, $arrayofselected)));
  1629. if ($i == ($imaxinloop - 1)) {
  1630. print '</div>';
  1631. print '</td></tr>';
  1632. }
  1633. } else {
  1634. print '<tr class="oddeven">';
  1635. // Action column
  1636. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1637. print '<td class="nowrap center">';
  1638. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1639. $selected = 0;
  1640. if (in_array($obj->rowid, $arrayofselected)) {
  1641. $selected = 1;
  1642. }
  1643. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1644. }
  1645. print '</td>';
  1646. }
  1647. // Ref
  1648. if (!empty($arrayfields['cf.ref']['checked'])) {
  1649. print '<td class="nowrap">';
  1650. // Picto + Ref
  1651. print $objectstatic->getNomUrl(1, '', 0, -1, 1);
  1652. // Other picto tool
  1653. $filename = dol_sanitizeFileName($obj->ref);
  1654. $filedir = $conf->fournisseur->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  1655. print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  1656. print '</td>'."\n";
  1657. if (!$i) {
  1658. $totalarray['nbfield']++;
  1659. }
  1660. }
  1661. // Ref Supplier
  1662. if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
  1663. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>'."\n";
  1664. if (!$i) {
  1665. $totalarray['nbfield']++;
  1666. }
  1667. }
  1668. // Project
  1669. if (!empty($arrayfields['cf.fk_projet']['checked'])) {
  1670. $projectstatic->id = $obj->project_id;
  1671. $projectstatic->ref = $obj->project_ref;
  1672. $projectstatic->title = $obj->project_title;
  1673. print '<td>';
  1674. if ($obj->project_id > 0) {
  1675. print $projectstatic->getNomUrl(1);
  1676. }
  1677. print '</td>';
  1678. if (!$i) {
  1679. $totalarray['nbfield']++;
  1680. }
  1681. }
  1682. // Author
  1683. $userstatic->id = $obj->fk_user_author;
  1684. $userstatic->lastname = $obj->lastname;
  1685. $userstatic->firstname = $obj->firstname;
  1686. $userstatic->login = $obj->login;
  1687. $userstatic->photo = $obj->photo;
  1688. $userstatic->email = $obj->user_email;
  1689. $userstatic->statut = $obj->user_status;
  1690. if (!empty($arrayfields['u.login']['checked'])) {
  1691. print '<td class="tdoverflowmax150">';
  1692. if ($userstatic->id) {
  1693. print $userstatic->getNomUrl(1);
  1694. }
  1695. print "</td>";
  1696. if (!$i) {
  1697. $totalarray['nbfield']++;
  1698. }
  1699. }
  1700. // Thirdparty
  1701. if (!empty($arrayfields['cf.fk_soc']['checked'])) {
  1702. print '<td class="tdoverflowmax150">';
  1703. $thirdpartytmp->id = $obj->socid;
  1704. $thirdpartytmp->name = $obj->name;
  1705. $thirdpartytmp->email = $obj->email;
  1706. $thirdpartytmp->name_alias = $obj->alias;
  1707. $thirdpartytmp->client = $obj->client;
  1708. $thirdpartytmp->fournisseur = $obj->fournisseur;
  1709. print $thirdpartytmp->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
  1710. print '</td>'."\n";
  1711. if (!$i) {
  1712. $totalarray['nbfield']++;
  1713. }
  1714. }
  1715. // Alias
  1716. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1717. print '<td class="tdoverflowmax150">';
  1718. print $obj->alias;
  1719. print '</td>'."\n";
  1720. if (!$i) {
  1721. $totalarray['nbfield']++;
  1722. }
  1723. }
  1724. // Town
  1725. if (!empty($arrayfields['s.town']['checked'])) {
  1726. print '<td>';
  1727. print $obj->town;
  1728. print '</td>';
  1729. if (!$i) {
  1730. $totalarray['nbfield']++;
  1731. }
  1732. }
  1733. // Zip
  1734. if (!empty($arrayfields['s.zip']['checked'])) {
  1735. print '<td>';
  1736. print $obj->zip;
  1737. print '</td>';
  1738. if (!$i) {
  1739. $totalarray['nbfield']++;
  1740. }
  1741. }
  1742. // State
  1743. if (!empty($arrayfields['state.nom']['checked'])) {
  1744. print "<td>".$obj->state_name."</td>\n";
  1745. if (!$i) {
  1746. $totalarray['nbfield']++;
  1747. }
  1748. }
  1749. // Country
  1750. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1751. print '<td class="center">';
  1752. $tmparray = getCountry($obj->fk_pays, 'all');
  1753. print $tmparray['label'];
  1754. print '</td>';
  1755. if (!$i) {
  1756. $totalarray['nbfield']++;
  1757. }
  1758. }
  1759. // Type ent
  1760. if (!empty($arrayfields['typent.code']['checked'])) {
  1761. print '<td class="center">';
  1762. if (empty($typenArray)) {
  1763. $typenArray = $formcompany->typent_array(1);
  1764. }
  1765. print $typenArray[$obj->typent_code];
  1766. print '</td>';
  1767. if (!$i) {
  1768. $totalarray['nbfield']++;
  1769. }
  1770. }
  1771. // Order date
  1772. if (!empty($arrayfields['cf.date_commande']['checked'])) {
  1773. print '<td class="center">';
  1774. print dol_print_date($db->jdate($obj->date_commande), 'day');
  1775. if ($objectstatic->statut != $objectstatic::STATUS_ORDERSENT && $objectstatic->statut != $objectstatic::STATUS_RECEIVED_PARTIALLY) {
  1776. if ($objectstatic->hasDelay()) {
  1777. print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
  1778. }
  1779. }
  1780. print '</td>';
  1781. if (!$i) {
  1782. $totalarray['nbfield']++;
  1783. }
  1784. }
  1785. // Plannned date of delivery
  1786. if (!empty($arrayfields['cf.date_livraison']['checked'])) {
  1787. print '<td class="center">';
  1788. print dol_print_date($db->jdate($obj->delivery_date), 'day');
  1789. if ($objectstatic->statut == $objectstatic::STATUS_ORDERSENT || $objectstatic->statut == $objectstatic::STATUS_RECEIVED_PARTIALLY) {
  1790. if ($objectstatic->hasDelay()) {
  1791. print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
  1792. }
  1793. }
  1794. print '</td>';
  1795. if (!$i) {
  1796. $totalarray['nbfield']++;
  1797. }
  1798. }
  1799. // Amount HT
  1800. if (!empty($arrayfields['cf.total_ht']['checked'])) {
  1801. print '<td class="right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
  1802. if (!$i) {
  1803. $totalarray['nbfield']++;
  1804. }
  1805. if (!$i) {
  1806. $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ht';
  1807. }
  1808. $totalarray['val']['cf.total_ht'] += $obj->total_ht;
  1809. }
  1810. // Amount VAT
  1811. if (!empty($arrayfields['cf.total_tva']['checked'])) {
  1812. print '<td class="right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
  1813. if (!$i) {
  1814. $totalarray['nbfield']++;
  1815. }
  1816. if (!$i) {
  1817. $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_tva';
  1818. }
  1819. $totalarray['val']['cf.total_tva'] += $obj->total_tva;
  1820. }
  1821. // Amount TTC
  1822. if (!empty($arrayfields['cf.total_ttc']['checked'])) {
  1823. print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
  1824. if (!$i) {
  1825. $totalarray['nbfield']++;
  1826. }
  1827. if (!$i) {
  1828. $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ttc';
  1829. }
  1830. $totalarray['val']['cf.total_ttc'] += $obj->total_ttc;
  1831. }
  1832. // Currency
  1833. if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
  1834. print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
  1835. if (!$i) {
  1836. $totalarray['nbfield']++;
  1837. }
  1838. }
  1839. // Currency rate
  1840. if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
  1841. print '<td class="nowrap">';
  1842. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
  1843. print "</td>\n";
  1844. if (!$i) {
  1845. $totalarray['nbfield']++;
  1846. }
  1847. }
  1848. // Amount HT
  1849. if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
  1850. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
  1851. if (!$i) {
  1852. $totalarray['nbfield']++;
  1853. }
  1854. }
  1855. // Amount VAT
  1856. if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
  1857. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n";
  1858. if (!$i) {
  1859. $totalarray['nbfield']++;
  1860. }
  1861. }
  1862. // Amount TTC
  1863. if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
  1864. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
  1865. if (!$i) {
  1866. $totalarray['nbfield']++;
  1867. }
  1868. }
  1869. // Extra fields
  1870. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1871. // Fields from hook
  1872. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1873. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1874. print $hookmanager->resPrint;
  1875. // Date creation
  1876. if (!empty($arrayfields['cf.date_creation']['checked'])) {
  1877. print '<td class="center nowraponall">';
  1878. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1879. print '</td>';
  1880. if (!$i) {
  1881. $totalarray['nbfield']++;
  1882. }
  1883. }
  1884. // Date modification
  1885. if (!empty($arrayfields['cf.tms']['checked'])) {
  1886. print '<td class="center nowraponall">';
  1887. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1888. print '</td>';
  1889. if (!$i) {
  1890. $totalarray['nbfield']++;
  1891. }
  1892. }
  1893. // Billed
  1894. if (!empty($arrayfields['cf.billed']['checked'])) {
  1895. print '<td class="center">'.yn($obj->billed).'</td>';
  1896. if (!$i) {
  1897. $totalarray['nbfield']++;
  1898. }
  1899. }
  1900. // Status
  1901. if (!empty($arrayfields['cf.fk_statut']['checked'])) {
  1902. print '<td class="center nowrap">'.$objectstatic->LibStatut($obj->fk_statut, 5, $obj->billed).'</td>';
  1903. if (!$i) {
  1904. $totalarray['nbfield']++;
  1905. }
  1906. }
  1907. // valid date
  1908. if (!empty($arrayfields['cf.date_valid']['checked'])) {
  1909. print '<td class="center">';
  1910. print dol_print_date($db->jdate($obj->date_valid), 'day');
  1911. print '</td>';
  1912. if (!$i) {
  1913. $totalarray['nbfield']++;
  1914. }
  1915. }
  1916. // approve date
  1917. if (!empty($arrayfields['cf.date_approve']['checked'])) {
  1918. print '<td class="center">';
  1919. print dol_print_date($db->jdate($obj->date_approve), 'day');
  1920. print '</td>';
  1921. if (!$i) {
  1922. $totalarray['nbfield']++;
  1923. }
  1924. }
  1925. // Note public
  1926. if (!empty($arrayfields['cf.note_public']['checked'])) {
  1927. print '<td class="center">';
  1928. print dol_string_nohtmltag($obj->note_public);
  1929. print '</td>';
  1930. if (!$i) {
  1931. $totalarray['nbfield']++;
  1932. }
  1933. }
  1934. // Note private
  1935. if (!empty($arrayfields['cf.note_private']['checked'])) {
  1936. print '<td class="center">';
  1937. print dol_string_nohtmltag($obj->note_private);
  1938. print '</td>';
  1939. if (!$i) {
  1940. $totalarray['nbfield']++;
  1941. }
  1942. }
  1943. // Action column
  1944. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1945. print '<td class="nowrap center">';
  1946. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1947. $selected = 0;
  1948. if (in_array($obj->rowid, $arrayofselected)) {
  1949. $selected = 1;
  1950. }
  1951. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1952. }
  1953. print '</td>';
  1954. }
  1955. if (!$i) {
  1956. $totalarray['nbfield']++;
  1957. }
  1958. print "</tr>\n";
  1959. $total += $obj->total_ht;
  1960. $subtotal += $obj->total_ht;
  1961. }
  1962. $i++;
  1963. }
  1964. // Show total line
  1965. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1966. // If no record found
  1967. if ($num == 0) {
  1968. $colspan = 1;
  1969. foreach ($arrayfields as $key => $val) {
  1970. if (!empty($val['checked'])) {
  1971. $colspan++;
  1972. }
  1973. }
  1974. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1975. }
  1976. $db->free($resql);
  1977. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1978. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1979. print $hookmanager->resPrint;
  1980. print '</table>'."\n";
  1981. print '</div>';
  1982. print '</form>'."\n";
  1983. $hidegeneratedfilelistifempty = 1;
  1984. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1985. $hidegeneratedfilelistifempty = 0;
  1986. }
  1987. // Show list of available documents
  1988. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1989. $urlsource .= str_replace('&amp;', '&', $param);
  1990. $filedir = $diroutputmassaction;
  1991. $genallowed = $permissiontoread;
  1992. $delallowed = $permissiontoadd;
  1993. print $formfile->showdocuments('massfilesarea_supplier_order', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1994. } else {
  1995. dol_print_error($db);
  1996. }
  1997. // End of page
  1998. llxFooter();
  1999. $db->close();