list.php 82 KB

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