list.php 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983
  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'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES)), 'position'=>100),
  179. 'cf.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_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 customer 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. $sql = 'SELECT';
  685. if ($sall || $search_product_category > 0) {
  686. $sql = 'SELECT DISTINCT';
  687. }
  688. $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,';
  689. $sql .= " typent.code as typent_code,";
  690. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  691. $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,";
  692. $sql .= ' cf.fk_multicurrency, cf.multicurrency_code, cf.multicurrency_tx, cf.multicurrency_total_ht, cf.multicurrency_total_tva, cf.multicurrency_total_ttc,';
  693. $sql .= ' cf.date_creation as date_creation, cf.tms as date_update,';
  694. $sql .= ' cf.note_public, cf.note_private,';
  695. $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_title,";
  696. $sql .= " u.firstname, u.lastname, u.photo, u.login, u.email as user_email, u.statut as user_status";
  697. // Add fields from extrafields
  698. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  699. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  700. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  701. }
  702. }
  703. // Add fields from hooks
  704. $parameters = array();
  705. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  706. $sql .= $hookmanager->resPrint;
  707. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  708. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  709. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  710. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  711. $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
  712. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  713. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cf.rowid = ef.fk_object)";
  714. }
  715. if ($sall || $search_product_category > 0) {
  716. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet as pd ON cf.rowid=pd.fk_commande';
  717. }
  718. if ($search_product_category > 0) {
  719. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  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 ($search_company) {
  748. $sql .= natural_search('s.nom', $search_company);
  749. }
  750. if ($search_company_alias) {
  751. $sql .= natural_search('s.name_alias', $search_company_alias);
  752. }
  753. if ($search_request_author) {
  754. $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_request_author);
  755. }
  756. if ($search_billed != '' && $search_billed >= 0) {
  757. $sql .= " AND cf.billed = ".((int) $search_billed);
  758. }
  759. if ($search_product_category > 0) {
  760. $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
  761. }
  762. //Required triple check because statut=0 means draft filter
  763. if (GETPOST('statut', 'intcomma') !== '') {
  764. $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($db->escape(GETPOST('statut', 'intcomma')))).")";
  765. }
  766. if ($search_status != '' && $search_status != '-1') {
  767. $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($search_status)).")";
  768. }
  769. if ($search_date_order_start) {
  770. $sql .= " AND cf.date_commande >= '".$db->idate($search_date_order_start)."'";
  771. }
  772. if ($search_date_order_end) {
  773. $sql .= " AND cf.date_commande <= '".$db->idate($search_date_order_end)."'";
  774. }
  775. if ($search_date_delivery_start) {
  776. $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_delivery_start)."'";
  777. }
  778. if ($search_date_delivery_end) {
  779. $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_delivery_end)."'";
  780. }
  781. if ($search_date_valid_start) {
  782. $sql .= " AND cf.date_commande >= '".$db->idate($search_date_valid_start)."'";
  783. }
  784. if ($search_date_valid_end) {
  785. $sql .= " AND cf.date_commande <= '".$db->idate($search_date_valid_end)."'";
  786. }
  787. if ($search_date_approve_start) {
  788. $sql .= " AND cf.date_livraison >= '".$db->idate($search_date_approve_start)."'";
  789. }
  790. if ($search_date_approve_end) {
  791. $sql .= " AND cf.date_livraison <= '".$db->idate($search_date_approve_end)."'";
  792. }
  793. if ($search_town) {
  794. $sql .= natural_search('s.town', $search_town);
  795. }
  796. if ($search_zip) {
  797. $sql .= natural_search("s.zip", $search_zip);
  798. }
  799. if ($search_state) {
  800. $sql .= natural_search("state.nom", $search_state);
  801. }
  802. if ($search_country) {
  803. $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
  804. }
  805. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  806. $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
  807. }
  808. if ($search_company) {
  809. $sql .= natural_search('s.nom', $search_company);
  810. }
  811. if ($search_company_alias) {
  812. $sql .= natural_search('s.name_alias', $search_company_alias);
  813. }
  814. if ($search_sale > 0) {
  815. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
  816. }
  817. if ($search_user > 0) {
  818. $sql .= " AND EXISTS (";
  819. $sql .= " SELECT ec.rowid ";
  820. $sql .= " FROM " . MAIN_DB_PREFIX . "element_contact as ec";
  821. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "c_type_contact as tc ON tc.rowid = ec.fk_c_type_contact";
  822. $sql .= " WHERE ec.element_id = cf.rowid AND ec.fk_socpeople = " . ((int) $search_user);
  823. $sql .= " AND tc.element = 'order_supplier' AND tc.source = 'internal'";
  824. $sql .= ")";
  825. }
  826. if ($search_total_ht != '') {
  827. $sql .= natural_search('cf.total_ht', $search_total_ht, 1);
  828. }
  829. if ($search_total_tva != '') {
  830. $sql .= natural_search('cf.total_tva', $search_total_tva, 1);
  831. }
  832. if ($search_total_ttc != '') {
  833. $sql .= natural_search('cf.total_ttc', $search_total_ttc, 1);
  834. }
  835. if ($search_multicurrency_code != '') {
  836. $sql .= " AND cf.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
  837. }
  838. if ($search_multicurrency_tx != '') {
  839. $sql .= natural_search('cf.multicurrency_tx', $search_multicurrency_tx, 1);
  840. }
  841. if ($search_multicurrency_montant_ht != '') {
  842. $sql .= natural_search('cf.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
  843. }
  844. if ($search_multicurrency_montant_tva != '') {
  845. $sql .= natural_search('cf.multicurrency_total_tva', $search_multicurrency_montant_tva, 1);
  846. }
  847. if ($search_multicurrency_montant_ttc != '') {
  848. $sql .= natural_search('cf.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
  849. }
  850. if ($search_project_ref != '') {
  851. $sql .= natural_search("p.ref", $search_project_ref);
  852. }
  853. // Add where from extra fields
  854. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  855. // Add where from hooks
  856. $parameters = array();
  857. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  858. $sql .= $hookmanager->resPrint;
  859. $sql .= $db->order($sortfield, $sortorder);
  860. // Count total nb of records
  861. $nbtotalofrecords = '';
  862. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  863. $result = $db->query($sql);
  864. $nbtotalofrecords = $db->num_rows($result);
  865. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  866. $page = 0;
  867. $offset = 0;
  868. }
  869. }
  870. $sql .= $db->plimit($limit + 1, $offset);
  871. //print $sql;
  872. $resql = $db->query($sql);
  873. if ($resql) {
  874. $num = $db->num_rows($resql);
  875. $arrayofselected = is_array($toselect) ? $toselect : array();
  876. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
  877. $obj = $db->fetch_object($resql);
  878. $id = $obj->rowid;
  879. header("Location: ".DOL_URL_ROOT.'/fourn/commande/card.php?id='.$id);
  880. exit;
  881. }
  882. llxHeader('', $title, $help_url);
  883. $param = '';
  884. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  885. $param .= '&contextpage='.urlencode($contextpage);
  886. }
  887. if ($limit > 0 && $limit != $conf->liste_limit) {
  888. $param .= '&limit='.urlencode($limit);
  889. }
  890. if ($sall) {
  891. $param .= '&sall='.urlencode($sall);
  892. }
  893. if ($socid > 0) {
  894. $param .= '&socid='.urlencode($socid);
  895. }
  896. if ($sall) {
  897. $param .= "&search_all=".urlencode($sall);
  898. }
  899. if ($search_date_order_startday) {
  900. $param .= '&search_date_order_startday='.urlencode($search_date_order_startday);
  901. }
  902. if ($search_date_order_startmonth) {
  903. $param .= '&search_date_order_startmonth='.urlencode($search_date_order_startmonth);
  904. }
  905. if ($search_date_order_startyear) {
  906. $param .= '&search_date_order_startyear='.urlencode($search_date_order_startyear);
  907. }
  908. if ($search_date_order_endday) {
  909. $param .= '&search_date_order_endday='.urlencode($search_date_order_endday);
  910. }
  911. if ($search_date_order_endmonth) {
  912. $param .= '&search_date_order_endmonth='.urlencode($search_date_order_endmonth);
  913. }
  914. if ($search_date_order_endyear) {
  915. $param .= '&search_date_order_endyear='.urlencode($search_date_order_endyear);
  916. }
  917. if ($search_date_delivery_startday) {
  918. $param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
  919. }
  920. if ($search_date_delivery_startmonth) {
  921. $param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
  922. }
  923. if ($search_date_delivery_startyear) {
  924. $param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
  925. }
  926. if ($search_date_delivery_endday) {
  927. $param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
  928. }
  929. if ($search_date_delivery_endmonth) {
  930. $param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
  931. }
  932. if ($search_date_delivery_endyear) {
  933. $param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
  934. }
  935. if ($search_date_valid_startday) {
  936. $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
  937. }
  938. if ($search_date_valid_startmonth) {
  939. $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
  940. }
  941. if ($search_date_valid_startyear) {
  942. $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
  943. }
  944. if ($search_date_valid_endday) {
  945. $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
  946. }
  947. if ($search_date_valid_endmonth) {
  948. $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
  949. }
  950. if ($search_date_valid_endyear) {
  951. $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
  952. }
  953. if ($search_date_approve_startday) {
  954. $param .= '&search_date_approve_startday='.urlencode($search_date_approve_startday);
  955. }
  956. if ($search_date_approve_startmonth) {
  957. $param .= '&search_date_approve_startmonth='.urlencode($search_date_approve_startmonth);
  958. }
  959. if ($search_date_approve_startyear) {
  960. $param .= '&search_date_approve_startyear='.urlencode($search_date_approve_startyear);
  961. }
  962. if ($search_date_approve_endday) {
  963. $param .= '&search_date_approve_endday='.urlencode($search_date_approve_endday);
  964. }
  965. if ($search_date_approve_endmonth) {
  966. $param .= '&search_date_approve_endmonth='.urlencode($search_date_approve_endmonth);
  967. }
  968. if ($search_date_approve_endyear) {
  969. $param .= '&search_date_approve_endyear='.urlencode($search_date_approve_endyear);
  970. }
  971. if ($search_ref) {
  972. $param .= '&search_ref='.urlencode($search_ref);
  973. }
  974. if ($search_company) {
  975. $param .= '&search_company='.urlencode($search_company);
  976. }
  977. if ($search_company_alias) {
  978. $param .= '&search_company_alias='.urlencode($search_company_alias);
  979. }
  980. if ($search_user > 0) {
  981. $param .= '&search_user='.urlencode($search_user);
  982. }
  983. if ($search_request_author) {
  984. $param .= '&search_request_author='.urlencode($search_request_author);
  985. }
  986. if ($search_sale > 0) {
  987. $param .= '&search_sale='.urlencode($search_sale);
  988. }
  989. if ($search_total_ht != '') {
  990. $param .= '&search_total_ht='.urlencode($search_total_ht);
  991. }
  992. if ($search_total_ttc != '') {
  993. $param .= "&search_total_ttc=".urlencode($search_total_ttc);
  994. }
  995. if ($search_multicurrency_code != '') {
  996. $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
  997. }
  998. if ($search_multicurrency_tx != '') {
  999. $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
  1000. }
  1001. if ($search_multicurrency_montant_ht != '') {
  1002. $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
  1003. }
  1004. if ($search_multicurrency_montant_tva != '') {
  1005. $param .= '&search_multicurrency_montant_tva='.urlencode($search_multicurrency_montant_tva);
  1006. }
  1007. if ($search_multicurrency_montant_ttc != '') {
  1008. $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
  1009. }
  1010. if ($search_refsupp) {
  1011. $param .= "&search_refsupp=".urlencode($search_refsupp);
  1012. }
  1013. if ($search_status != '' && $search_status != '-1') {
  1014. $param .= "&search_status=".urlencode($search_status);
  1015. }
  1016. if ($search_project_ref >= 0) {
  1017. $param .= "&search_project_ref=".urlencode($search_project_ref);
  1018. }
  1019. if ($search_billed != '') {
  1020. $param .= "&search_billed=".urlencode($search_billed);
  1021. }
  1022. if ($show_files) {
  1023. $param .= '&show_files='.urlencode($show_files);
  1024. }
  1025. if ($optioncss != '') {
  1026. $param .= '&optioncss='.urlencode($optioncss);
  1027. }
  1028. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  1029. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  1030. }
  1031. // Add $param from extra fields
  1032. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  1033. $parameters = array();
  1034. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  1035. $param .= $hookmanager->resPrint;
  1036. // List of mass actions available
  1037. $arrayofmassactions = array(
  1038. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  1039. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  1040. 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  1041. );
  1042. if ($permissiontovalidate) {
  1043. if ($permissiontoapprove && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE)) {
  1044. $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ValidateAndApprove");
  1045. } else {
  1046. $arrayofmassactions['prevalidate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
  1047. }
  1048. }
  1049. if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) {
  1050. $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisSupplier");
  1051. }
  1052. if ($permissiontodelete) {
  1053. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  1054. }
  1055. if (in_array($massaction, array('presend', 'predelete', 'createbills'))) {
  1056. $arrayofmassactions = array();
  1057. }
  1058. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  1059. $url = DOL_URL_ROOT.'/fourn/commande/card.php?action=create';
  1060. if ($socid > 0) {
  1061. $url .= '&socid='.((int) $socid);
  1062. $url .= '&backtopage='.urlencode(DOL_URL_ROOT.'/fourn/commande/list.php?socid='.((int) $socid));
  1063. }
  1064. $newcardbutton = dolGetButtonTitle($langs->trans('NewSupplierOrderShort'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
  1065. // Lines of title fields
  1066. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  1067. if ($optioncss != '') {
  1068. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  1069. }
  1070. print '<input type="hidden" name="token" value="'.newToken().'">';
  1071. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  1072. print '<input type="hidden" name="action" value="list">';
  1073. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  1074. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  1075. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  1076. print '<input type="hidden" name="socid" value="'.$socid.'">';
  1077. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_order', 0, $newcardbutton, '', $limit, 0, 0, 1);
  1078. $topicmail = "SendOrderRef";
  1079. $modelmail = "order_supplier_send";
  1080. $objecttmp = new CommandeFournisseur($db);
  1081. $trackid = 'sord'.$object->id;
  1082. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  1083. if ($massaction == 'prevalidate') {
  1084. print $form->formconfirm($_SERVER["PHP_SELF"].$fieldstosearchall, $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
  1085. }
  1086. if ($massaction == 'createbills') {
  1087. //var_dump($_REQUEST);
  1088. print '<input type="hidden" name="massaction" value="confirm_createsupplierbills">';
  1089. print '<table class="noborder" width="100%" >';
  1090. print '<tr>';
  1091. print '<td class="titlefield">';
  1092. print $langs->trans('DateInvoice');
  1093. print '</td>';
  1094. print '<td>';
  1095. print $form->selectDate('', '', '', '', '', '', 1, 1);
  1096. print '</td>';
  1097. print '</tr>';
  1098. print '<tr>';
  1099. print '<td>';
  1100. print $langs->trans('CreateOneBillByThird');
  1101. print '</td>';
  1102. print '<td>';
  1103. print $form->selectyesno('createbills_onebythird', '', 1);
  1104. print '</td>';
  1105. print '</tr>';
  1106. print '<tr>';
  1107. print '<td>';
  1108. print $langs->trans('ValidateInvoices');
  1109. print '</td>';
  1110. print '<td>';
  1111. print $form->selectyesno('validate_invoices', 1, 1);
  1112. print '</td>';
  1113. print '</tr>';
  1114. print '</table>';
  1115. print '<br>';
  1116. print '<div class="center">';
  1117. print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
  1118. print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
  1119. print '</div>';
  1120. print '<br>';
  1121. }
  1122. if ($sall) {
  1123. foreach ($fieldstosearchall as $key => $val) {
  1124. $fieldstosearchall[$key] = $langs->trans($val);
  1125. }
  1126. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  1127. }
  1128. $moreforfilter = '';
  1129. // If the user can view prospects other than his'
  1130. if ($user->rights->user->user->lire) {
  1131. $langs->load("commercial");
  1132. $moreforfilter .= '<div class="divsearchfield">';
  1133. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  1134. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx');
  1135. $moreforfilter .= '</div>';
  1136. }
  1137. // If the user can view other users
  1138. if ($user->rights->user->user->lire) {
  1139. $moreforfilter .= '<div class="divsearchfield">';
  1140. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  1141. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250 widthcentpercentminusx');
  1142. $moreforfilter .= '</div>';
  1143. }
  1144. // If the user can view prospects other than his'
  1145. if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
  1146. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1147. $moreforfilter .= '<div class="divsearchfield">';
  1148. $tmptitle = $langs->trans('IncludingProductWithTag');
  1149. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  1150. $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);
  1151. $moreforfilter .= '</div>';
  1152. }
  1153. $parameters = array();
  1154. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1155. if (empty($reshook)) {
  1156. $moreforfilter .= $hookmanager->resPrint;
  1157. } else {
  1158. $moreforfilter = $hookmanager->resPrint;
  1159. }
  1160. if (!empty($moreforfilter)) {
  1161. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1162. print $moreforfilter;
  1163. print '</div>';
  1164. }
  1165. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  1166. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  1167. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  1168. if (GETPOST('autoselectall', 'int')) {
  1169. $selectedfields .= '<script>';
  1170. $selectedfields .= ' $(document).ready(function() {';
  1171. $selectedfields .= ' console.log("Autoclick on checkforselects");';
  1172. $selectedfields .= ' $("#checkforselects").click();';
  1173. $selectedfields .= ' $("#massaction").val("createbills").change();';
  1174. $selectedfields .= ' });';
  1175. $selectedfields .= '</script>';
  1176. }
  1177. print '<div class="div-table-responsive">';
  1178. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  1179. print '<tr class="liste_titre_filter">';
  1180. // Ref
  1181. if (!empty($arrayfields['cf.ref']['checked'])) {
  1182. print '<td class="liste_titre"><input size="8" type="text" class="flat maxwidth75" name="search_ref" value="'.$search_ref.'"></td>';
  1183. }
  1184. // Ref customer
  1185. if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
  1186. print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_refsupp" value="'.$search_refsupp.'"></td>';
  1187. }
  1188. // Project ref
  1189. if (!empty($arrayfields['cf.fk_projet']['checked'])) {
  1190. print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_project_ref" value="'.$search_project_ref.'"></td>';
  1191. }
  1192. // Request author
  1193. if (!empty($arrayfields['u.login']['checked'])) {
  1194. print '<td class="liste_titre">';
  1195. print '<input type="text" class="flat" size="6" name="search_request_author" value="'.$search_request_author.'">';
  1196. print '</td>';
  1197. }
  1198. // Thirpdarty
  1199. if (!empty($arrayfields['cf.fk_soc']['checked'])) {
  1200. print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company" value="'.$search_company.'"></td>';
  1201. }
  1202. // Alias
  1203. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1204. print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company_alias" value="'.$search_company_alias.'"></td>';
  1205. }
  1206. // Town
  1207. if (!empty($arrayfields['s.town']['checked'])) {
  1208. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.$search_town.'"></td>';
  1209. }
  1210. // Zip
  1211. if (!empty($arrayfields['s.zip']['checked'])) {
  1212. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.$search_zip.'"></td>';
  1213. }
  1214. // State
  1215. if (!empty($arrayfields['state.nom']['checked'])) {
  1216. print '<td class="liste_titre">';
  1217. print '<input class="flat maxwidth50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  1218. print '</td>';
  1219. }
  1220. // Country
  1221. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1222. print '<td class="liste_titre center">';
  1223. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  1224. print '</td>';
  1225. }
  1226. // Company type
  1227. if (!empty($arrayfields['typent.code']['checked'])) {
  1228. print '<td class="liste_titre maxwidthonsmartphone center">';
  1229. 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);
  1230. print '</td>';
  1231. }
  1232. // Date order
  1233. if (!empty($arrayfields['cf.date_commande']['checked'])) {
  1234. print '<td class="liste_titre center">';
  1235. print '<div class="nowrap">';
  1236. 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'));
  1237. print '</div>';
  1238. print '<div class="nowrap">';
  1239. 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'));
  1240. print '</div>';
  1241. print '</td>';
  1242. }
  1243. // Date delivery
  1244. if (!empty($arrayfields['cf.date_livraison']['checked'])) {
  1245. print '<td class="liste_titre center">';
  1246. print '<div class="nowrap">';
  1247. 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'));
  1248. print '</div>';
  1249. print '<div class="nowrap">';
  1250. 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'));
  1251. print '</div>';
  1252. print '</td>';
  1253. }
  1254. if (!empty($arrayfields['cf.total_ht']['checked'])) {
  1255. // Amount
  1256. print '<td class="liste_titre right">';
  1257. print '<input class="flat" type="text" size="5" name="search_total_ht" value="'.$search_total_ht.'">';
  1258. print '</td>';
  1259. }
  1260. if (!empty($arrayfields['cf.total_tva']['checked'])) {
  1261. // Amount
  1262. print '<td class="liste_titre right">';
  1263. print '<input class="flat" type="text" size="5" name="search_total_tva" value="'.$search_total_tva.'">';
  1264. print '</td>';
  1265. }
  1266. if (!empty($arrayfields['cf.total_ttc']['checked'])) {
  1267. // Amount
  1268. print '<td class="liste_titre right">';
  1269. print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
  1270. print '</td>';
  1271. }
  1272. if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
  1273. // Currency
  1274. print '<td class="liste_titre">';
  1275. print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
  1276. print '</td>';
  1277. }
  1278. if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
  1279. // Currency rate
  1280. print '<td class="liste_titre">';
  1281. print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
  1282. print '</td>';
  1283. }
  1284. if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
  1285. // Amount
  1286. print '<td class="liste_titre right">';
  1287. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
  1288. print '</td>';
  1289. }
  1290. if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
  1291. // Amount
  1292. print '<td class="liste_titre right">';
  1293. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_tva" value="'.dol_escape_htmltag($search_multicurrency_montant_tva).'">';
  1294. print '</td>';
  1295. }
  1296. if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
  1297. // Amount
  1298. print '<td class="liste_titre right">';
  1299. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
  1300. print '</td>';
  1301. }
  1302. // Extra fields
  1303. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1304. // Fields from hook
  1305. $parameters = array('arrayfields'=>$arrayfields);
  1306. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  1307. print $hookmanager->resPrint;
  1308. // Date creation
  1309. if (!empty($arrayfields['cf.date_creation']['checked'])) {
  1310. print '<td class="liste_titre">';
  1311. print '</td>';
  1312. }
  1313. // Date modification
  1314. if (!empty($arrayfields['cf.tms']['checked'])) {
  1315. print '<td class="liste_titre">';
  1316. print '</td>';
  1317. }
  1318. // Status
  1319. if (!empty($arrayfields['cf.fk_statut']['checked'])) {
  1320. print '<td class="liste_titre right">';
  1321. $formorder->selectSupplierOrderStatus($search_status, 1, 'search_status');
  1322. print '</td>';
  1323. }
  1324. // Status billed
  1325. if (!empty($arrayfields['cf.billed']['checked'])) {
  1326. print '<td class="liste_titre center">';
  1327. print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1);
  1328. print '</td>';
  1329. }
  1330. // Date valid
  1331. if (!empty($arrayfields['cf.date_valid']['checked'])) {
  1332. print '<td class="liste_titre center">';
  1333. print '<div class="nowrap">';
  1334. 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'));
  1335. print '</div>';
  1336. print '<div class="nowrap">';
  1337. 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'));
  1338. print '</div>';
  1339. print '</td>';
  1340. }
  1341. // Date approve
  1342. if (!empty($arrayfields['cf.date_approve']['checked'])) {
  1343. print '<td class="liste_titre center">';
  1344. print '<div class="nowrap">';
  1345. 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'));
  1346. print '</div>';
  1347. print '<div class="nowrap">';
  1348. 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'));
  1349. print '</div>';
  1350. print '</td>';
  1351. }
  1352. // Note public
  1353. if (!empty($arrayfields['cf.note_public']['checked'])) {
  1354. print '<td class="liste_titre">';
  1355. print '</td>';
  1356. }
  1357. // Note private
  1358. if (!empty($arrayfields['cf.note_private']['checked'])) {
  1359. print '<td class="liste_titre">';
  1360. print '</td>';
  1361. }
  1362. // Action column
  1363. print '<td class="liste_titre middle">';
  1364. $searchpicto = $form->showFilterButtons();
  1365. print $searchpicto;
  1366. print '</td>';
  1367. print "</tr>\n";
  1368. // Fields title
  1369. print '<tr class="liste_titre">';
  1370. if (!empty($arrayfields['cf.ref']['checked'])) {
  1371. print_liste_field_titre($arrayfields['cf.ref']['label'], $_SERVER["PHP_SELF"], "cf.ref", "", $param, '', $sortfield, $sortorder);
  1372. }
  1373. if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
  1374. print_liste_field_titre($arrayfields['cf.ref_supplier']['label'], $_SERVER["PHP_SELF"], "cf.ref_supplier", "", $param, '', $sortfield, $sortorder, 'tdoverflowmax100imp ');
  1375. }
  1376. if (!empty($arrayfields['cf.fk_projet']['checked'])) {
  1377. print_liste_field_titre($arrayfields['cf.fk_projet']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder);
  1378. }
  1379. if (!empty($arrayfields['u.login']['checked'])) {
  1380. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], "u.login", "", $param, '', $sortfield, $sortorder);
  1381. }
  1382. if (!empty($arrayfields['cf.fk_soc']['checked'])) {
  1383. print_liste_field_titre($arrayfields['cf.fk_soc']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
  1384. }
  1385. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1386. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", "", $param, '', $sortfield, $sortorder);
  1387. }
  1388. if (!empty($arrayfields['s.town']['checked'])) {
  1389. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  1390. }
  1391. if (!empty($arrayfields['s.zip']['checked'])) {
  1392. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  1393. }
  1394. if (!empty($arrayfields['state.nom']['checked'])) {
  1395. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  1396. }
  1397. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1398. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  1399. }
  1400. if (!empty($arrayfields['typent.code']['checked'])) {
  1401. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  1402. }
  1403. if (!empty($arrayfields['cf.fk_author']['checked'])) {
  1404. print_liste_field_titre($arrayfields['cf.fk_author']['label'], $_SERVER["PHP_SELF"], "cf.fk_author", "", $param, '', $sortfield, $sortorder);
  1405. }
  1406. if (!empty($arrayfields['cf.date_commande']['checked'])) {
  1407. print_liste_field_titre($arrayfields['cf.date_commande']['label'], $_SERVER["PHP_SELF"], "cf.date_commande", "", $param, '', $sortfield, $sortorder, 'center ');
  1408. }
  1409. if (!empty($arrayfields['cf.date_livraison']['checked'])) {
  1410. print_liste_field_titre($arrayfields['cf.date_livraison']['label'], $_SERVER["PHP_SELF"], 'cf.date_livraison', '', $param, '', $sortfield, $sortorder, 'center ');
  1411. }
  1412. if (!empty($arrayfields['cf.total_ht']['checked'])) {
  1413. print_liste_field_titre($arrayfields['cf.total_ht']['label'], $_SERVER["PHP_SELF"], "cf.total_ht", "", $param, '', $sortfield, $sortorder, 'right ');
  1414. }
  1415. if (!empty($arrayfields['cf.total_tva']['checked'])) {
  1416. print_liste_field_titre($arrayfields['cf.total_tva']['label'], $_SERVER["PHP_SELF"], "cf.total_tva", "", $param, '', $sortfield, $sortorder, 'right ');
  1417. }
  1418. if (!empty($arrayfields['cf.total_ttc']['checked'])) {
  1419. print_liste_field_titre($arrayfields['cf.total_ttc']['label'], $_SERVER["PHP_SELF"], "cf.total_ttc", "", $param, '', $sortfield, $sortorder, 'right ');
  1420. }
  1421. if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
  1422. print_liste_field_titre($arrayfields['cf.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_code', '', $param, '', $sortfield, $sortorder);
  1423. }
  1424. if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
  1425. print_liste_field_titre($arrayfields['cf.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
  1426. }
  1427. if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
  1428. print_liste_field_titre($arrayfields['cf.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
  1429. }
  1430. if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
  1431. print_liste_field_titre($arrayfields['cf.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
  1432. }
  1433. if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
  1434. print_liste_field_titre($arrayfields['cf.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
  1435. }
  1436. // Extra fields
  1437. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1438. // Hook fields
  1439. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1440. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1441. print $hookmanager->resPrint;
  1442. if (!empty($arrayfields['cf.date_creation']['checked'])) {
  1443. print_liste_field_titre($arrayfields['cf.date_creation']['label'], $_SERVER["PHP_SELF"], "cf.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1444. }
  1445. if (!empty($arrayfields['cf.tms']['checked'])) {
  1446. print_liste_field_titre($arrayfields['cf.tms']['label'], $_SERVER["PHP_SELF"], "cf.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1447. }
  1448. if (!empty($arrayfields['cf.fk_statut']['checked'])) {
  1449. print_liste_field_titre($arrayfields['cf.fk_statut']['label'], $_SERVER["PHP_SELF"], "cf.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
  1450. }
  1451. if (!empty($arrayfields['cf.billed']['checked'])) {
  1452. print_liste_field_titre($arrayfields['cf.billed']['label'], $_SERVER["PHP_SELF"], 'cf.billed', '', $param, '', $sortfield, $sortorder, 'center ');
  1453. }
  1454. if (!empty($arrayfields['cf.date_valid']['checked'])) {
  1455. print_liste_field_titre($arrayfields['cf.date_valid']['label'], $_SERVER["PHP_SELF"], "cf.date_valid", "", $param, '', $sortfield, $sortorder, 'center ');
  1456. }
  1457. if (!empty($arrayfields['cf.date_approve']['checked'])) {
  1458. print_liste_field_titre($arrayfields['cf.date_approve']['label'], $_SERVER["PHP_SELF"], 'cf.date_approve', '', $param, '', $sortfield, $sortorder, 'center ');
  1459. }
  1460. if (!empty($arrayfields['cf.note_public']['checked'])) {
  1461. print_liste_field_titre($arrayfields['cf.note_public']['label'], $_SERVER["PHP_SELF"], "cf.note_public", "", $param, '', $sortfield, $sortorder, 'center ');
  1462. }
  1463. if (!empty($arrayfields['cf.note_private']['checked'])) {
  1464. print_liste_field_titre($arrayfields['cf.note_private']['label'], $_SERVER["PHP_SELF"], "cf.note_private", "", $param, '', $sortfield, $sortorder, 'center ');
  1465. }
  1466. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  1467. print "</tr>\n";
  1468. $total = 0;
  1469. $subtotal = 0;
  1470. $productstat_cache = array();
  1471. $userstatic = new User($db);
  1472. $objectstatic = new CommandeFournisseur($db);
  1473. $projectstatic = new Project($db);
  1474. $i = 0;
  1475. $totalarray = array('nbfield' => 0, 'val' => array(), 'pos' => array());
  1476. $totalarray['val']['cf.total_ht'] = 0;
  1477. $totalarray['val']['cf.total_ttc'] = 0;
  1478. $totalarray['val']['cf.total_tva'] = 0;
  1479. $imaxinloop = ($limit ? min($num, $limit) : $num);
  1480. while ($i < $imaxinloop) {
  1481. $obj = $db->fetch_object($resql);
  1482. $notshippable = 0;
  1483. $warning = 0;
  1484. $text_info = '';
  1485. $text_warning = '';
  1486. $nbprod = 0;
  1487. $objectstatic->id = $obj->rowid;
  1488. $objectstatic->ref = $obj->ref;
  1489. $objectstatic->socid = $obj->socid;
  1490. $objectstatic->ref_supplier = $obj->ref_supplier;
  1491. $objectstatic->socid = $obj->socid;
  1492. $objectstatic->total_ht = $obj->total_ht;
  1493. $objectstatic->total_tva = $obj->total_tva;
  1494. $objectstatic->total_ttc = $obj->total_ttc;
  1495. $objectstatic->date_commande = $db->jdate($obj->date_commande);
  1496. $objectstatic->delivery_date = $db->jdate($obj->date_livraison);
  1497. $objectstatic->note_public = $obj->note_public;
  1498. $objectstatic->note_private = $obj->note_private;
  1499. $objectstatic->statut = $obj->fk_statut;
  1500. print '<tr class="oddeven">';
  1501. // Ref
  1502. if (!empty($arrayfields['cf.ref']['checked'])) {
  1503. print '<td class="nowrap">';
  1504. // Picto + Ref
  1505. print $objectstatic->getNomUrl(1, '', 0, -1, 1);
  1506. // Other picto tool
  1507. $filename = dol_sanitizeFileName($obj->ref);
  1508. $filedir = $conf->fournisseur->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  1509. print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  1510. print '</td>'."\n";
  1511. if (!$i) {
  1512. $totalarray['nbfield']++;
  1513. }
  1514. }
  1515. // Ref Supplier
  1516. if (!empty($arrayfields['cf.ref_supplier']['checked'])) {
  1517. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>'."\n";
  1518. if (!$i) {
  1519. $totalarray['nbfield']++;
  1520. }
  1521. }
  1522. // Project
  1523. if (!empty($arrayfields['cf.fk_projet']['checked'])) {
  1524. $projectstatic->id = $obj->project_id;
  1525. $projectstatic->ref = $obj->project_ref;
  1526. $projectstatic->title = $obj->project_title;
  1527. print '<td>';
  1528. if ($obj->project_id > 0) {
  1529. print $projectstatic->getNomUrl(1);
  1530. }
  1531. print '</td>';
  1532. if (!$i) {
  1533. $totalarray['nbfield']++;
  1534. }
  1535. }
  1536. // Author
  1537. $userstatic->id = $obj->fk_user_author;
  1538. $userstatic->lastname = $obj->lastname;
  1539. $userstatic->firstname = $obj->firstname;
  1540. $userstatic->login = $obj->login;
  1541. $userstatic->photo = $obj->photo;
  1542. $userstatic->email = $obj->user_email;
  1543. $userstatic->statut = $obj->user_status;
  1544. if (!empty($arrayfields['u.login']['checked'])) {
  1545. print '<td class="tdoverflowmax150">';
  1546. if ($userstatic->id) {
  1547. print $userstatic->getNomUrl(1);
  1548. }
  1549. print "</td>";
  1550. if (!$i) {
  1551. $totalarray['nbfield']++;
  1552. }
  1553. }
  1554. // Thirdparty
  1555. if (!empty($arrayfields['cf.fk_soc']['checked'])) {
  1556. print '<td class="tdoverflowmax150">';
  1557. $thirdpartytmp->id = $obj->socid;
  1558. $thirdpartytmp->name = $obj->name;
  1559. $thirdpartytmp->email = $obj->email;
  1560. $thirdpartytmp->name_alias = $obj->alias;
  1561. $thirdpartytmp->client = $obj->client;
  1562. $thirdpartytmp->fournisseur = $obj->fournisseur;
  1563. print $thirdpartytmp->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
  1564. print '</td>'."\n";
  1565. if (!$i) {
  1566. $totalarray['nbfield']++;
  1567. }
  1568. }
  1569. //alias
  1570. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1571. print '<td class="tdoverflowmax150">';
  1572. print $obj->alias;
  1573. print '</td>'."\n";
  1574. if (!$i) {
  1575. $totalarray['nbfield']++;
  1576. }
  1577. }
  1578. // Town
  1579. if (!empty($arrayfields['s.town']['checked'])) {
  1580. print '<td>';
  1581. print $obj->town;
  1582. print '</td>';
  1583. if (!$i) {
  1584. $totalarray['nbfield']++;
  1585. }
  1586. }
  1587. // Zip
  1588. if (!empty($arrayfields['s.zip']['checked'])) {
  1589. print '<td>';
  1590. print $obj->zip;
  1591. print '</td>';
  1592. if (!$i) {
  1593. $totalarray['nbfield']++;
  1594. }
  1595. }
  1596. // State
  1597. if (!empty($arrayfields['state.nom']['checked'])) {
  1598. print "<td>".$obj->state_name."</td>\n";
  1599. if (!$i) {
  1600. $totalarray['nbfield']++;
  1601. }
  1602. }
  1603. // Country
  1604. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1605. print '<td class="center">';
  1606. $tmparray = getCountry($obj->fk_pays, 'all');
  1607. print $tmparray['label'];
  1608. print '</td>';
  1609. if (!$i) {
  1610. $totalarray['nbfield']++;
  1611. }
  1612. }
  1613. // Type ent
  1614. if (!empty($arrayfields['typent.code']['checked'])) {
  1615. print '<td class="center">';
  1616. if (empty($typenArray)) {
  1617. $typenArray = $formcompany->typent_array(1);
  1618. }
  1619. print $typenArray[$obj->typent_code];
  1620. print '</td>';
  1621. if (!$i) {
  1622. $totalarray['nbfield']++;
  1623. }
  1624. }
  1625. // Order date
  1626. if (!empty($arrayfields['cf.date_commande']['checked'])) {
  1627. print '<td class="center">';
  1628. print dol_print_date($db->jdate($obj->date_commande), 'day');
  1629. if ($objectstatic->statut != $objectstatic::STATUS_ORDERSENT && $objectstatic->statut != $objectstatic::STATUS_RECEIVED_PARTIALLY) {
  1630. if ($objectstatic->hasDelay()) {
  1631. print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
  1632. }
  1633. }
  1634. print '</td>';
  1635. if (!$i) {
  1636. $totalarray['nbfield']++;
  1637. }
  1638. }
  1639. // Plannned date of delivery
  1640. if (!empty($arrayfields['cf.date_livraison']['checked'])) {
  1641. print '<td class="center">';
  1642. print dol_print_date($db->jdate($obj->date_livraison), 'day');
  1643. if ($objectstatic->statut == $objectstatic::STATUS_ORDERSENT || $objectstatic->statut == $objectstatic::STATUS_RECEIVED_PARTIALLY) {
  1644. if ($objectstatic->hasDelay()) {
  1645. print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning");
  1646. }
  1647. }
  1648. print '</td>';
  1649. if (!$i) {
  1650. $totalarray['nbfield']++;
  1651. }
  1652. }
  1653. // Amount HT
  1654. if (!empty($arrayfields['cf.total_ht']['checked'])) {
  1655. print '<td class="right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
  1656. if (!$i) {
  1657. $totalarray['nbfield']++;
  1658. }
  1659. if (!$i) {
  1660. $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ht';
  1661. }
  1662. $totalarray['val']['cf.total_ht'] += $obj->total_ht;
  1663. }
  1664. // Amount VAT
  1665. if (!empty($arrayfields['cf.total_tva']['checked'])) {
  1666. print '<td class="right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
  1667. if (!$i) {
  1668. $totalarray['nbfield']++;
  1669. }
  1670. if (!$i) {
  1671. $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_tva';
  1672. }
  1673. $totalarray['val']['cf.total_tva'] += $obj->total_tva;
  1674. }
  1675. // Amount TTC
  1676. if (!empty($arrayfields['cf.total_ttc']['checked'])) {
  1677. print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
  1678. if (!$i) {
  1679. $totalarray['nbfield']++;
  1680. }
  1681. if (!$i) {
  1682. $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ttc';
  1683. }
  1684. $totalarray['val']['cf.total_ttc'] += $obj->total_ttc;
  1685. }
  1686. // Currency
  1687. if (!empty($arrayfields['cf.multicurrency_code']['checked'])) {
  1688. print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
  1689. if (!$i) {
  1690. $totalarray['nbfield']++;
  1691. }
  1692. }
  1693. // Currency rate
  1694. if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) {
  1695. print '<td class="nowrap">';
  1696. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
  1697. print "</td>\n";
  1698. if (!$i) {
  1699. $totalarray['nbfield']++;
  1700. }
  1701. }
  1702. // Amount HT
  1703. if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) {
  1704. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
  1705. if (!$i) {
  1706. $totalarray['nbfield']++;
  1707. }
  1708. }
  1709. // Amount VAT
  1710. if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) {
  1711. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n";
  1712. if (!$i) {
  1713. $totalarray['nbfield']++;
  1714. }
  1715. }
  1716. // Amount TTC
  1717. if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) {
  1718. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
  1719. if (!$i) {
  1720. $totalarray['nbfield']++;
  1721. }
  1722. }
  1723. // Extra fields
  1724. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1725. // Fields from hook
  1726. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1727. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1728. print $hookmanager->resPrint;
  1729. // Date creation
  1730. if (!empty($arrayfields['cf.date_creation']['checked'])) {
  1731. print '<td class="center nowrap">';
  1732. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1733. print '</td>';
  1734. if (!$i) {
  1735. $totalarray['nbfield']++;
  1736. }
  1737. }
  1738. // Date modification
  1739. if (!empty($arrayfields['cf.tms']['checked'])) {
  1740. print '<td class="center nowrap">';
  1741. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1742. print '</td>';
  1743. if (!$i) {
  1744. $totalarray['nbfield']++;
  1745. }
  1746. }
  1747. // Status
  1748. if (!empty($arrayfields['cf.fk_statut']['checked'])) {
  1749. print '<td class="right nowrap">'.$objectstatic->LibStatut($obj->fk_statut, 5, $obj->billed).'</td>';
  1750. if (!$i) {
  1751. $totalarray['nbfield']++;
  1752. }
  1753. }
  1754. // Billed
  1755. if (!empty($arrayfields['cf.billed']['checked'])) {
  1756. print '<td class="center">'.yn($obj->billed).'</td>';
  1757. if (!$i) {
  1758. $totalarray['nbfield']++;
  1759. }
  1760. }
  1761. // valid date
  1762. if (!empty($arrayfields['cf.date_valid']['checked'])) {
  1763. print '<td class="center">';
  1764. print dol_print_date($db->jdate($obj->date_valid), 'day');
  1765. print '</td>';
  1766. if (!$i) {
  1767. $totalarray['nbfield']++;
  1768. }
  1769. }
  1770. // approve date
  1771. if (!empty($arrayfields['cf.date_approve']['checked'])) {
  1772. print '<td class="center">';
  1773. print dol_print_date($db->jdate($obj->date_approve), 'day');
  1774. print '</td>';
  1775. if (!$i) {
  1776. $totalarray['nbfield']++;
  1777. }
  1778. }
  1779. // Note public
  1780. if (!empty($arrayfields['cf.note_public']['checked'])) {
  1781. print '<td class="center">';
  1782. print dol_string_nohtmltag($obj->note_public);
  1783. print '</td>';
  1784. if (!$i) {
  1785. $totalarray['nbfield']++;
  1786. }
  1787. }
  1788. // Note private
  1789. if (!empty($arrayfields['cf.note_private']['checked'])) {
  1790. print '<td class="center">';
  1791. print dol_string_nohtmltag($obj->note_private);
  1792. print '</td>';
  1793. if (!$i) {
  1794. $totalarray['nbfield']++;
  1795. }
  1796. }
  1797. // Action column
  1798. print '<td class="nowrap center">';
  1799. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1800. $selected = 0;
  1801. if (in_array($obj->rowid, $arrayofselected)) {
  1802. $selected = 1;
  1803. }
  1804. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1805. }
  1806. print '</td>';
  1807. if (!$i) {
  1808. $totalarray['nbfield']++;
  1809. }
  1810. print "</tr>\n";
  1811. $total += $obj->total_ht;
  1812. $subtotal += $obj->total_ht;
  1813. $i++;
  1814. }
  1815. // Show total line
  1816. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1817. // If no record found
  1818. if ($num == 0) {
  1819. $colspan = 1;
  1820. foreach ($arrayfields as $key => $val) {
  1821. if (!empty($val['checked'])) {
  1822. $colspan++;
  1823. }
  1824. }
  1825. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1826. }
  1827. $db->free($resql);
  1828. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1829. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1830. print $hookmanager->resPrint;
  1831. print '</table>'."\n";
  1832. print '</div>';
  1833. print '</form>'."\n";
  1834. $hidegeneratedfilelistifempty = 1;
  1835. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1836. $hidegeneratedfilelistifempty = 0;
  1837. }
  1838. // Show list of available documents
  1839. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1840. $urlsource .= str_replace('&amp;', '&', $param);
  1841. $filedir = $diroutputmassaction;
  1842. $genallowed = $permissiontoread;
  1843. $delallowed = $permissiontoadd;
  1844. print $formfile->showdocuments('massfilesarea_supplier_order', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1845. } else {
  1846. dol_print_error($db);
  1847. }
  1848. // End of page
  1849. llxFooter();
  1850. $db->close();