list.php 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455
  1. <?php
  2. /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
  8. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  9. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  10. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  11. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  12. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  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 <http://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/commande/list.php
  29. * \ingroup commande
  30. * \brief Page to list orders
  31. */
  32. require '../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  42. $langs->loadLangs(array("orders",'sendings','deliveries','companies','compta','bills'));
  43. $action=GETPOST('action','alpha');
  44. $massaction=GETPOST('massaction','alpha');
  45. $show_files=GETPOST('show_files','int');
  46. $confirm=GETPOST('confirm','alpha');
  47. $toselect = GETPOST('toselect', 'array');
  48. $orderyear=GETPOST("orderyear","int");
  49. $ordermonth=GETPOST("ordermonth","int");
  50. $orderday=GETPOST("orderday","int");
  51. $deliveryyear=GETPOST("deliveryyear","int");
  52. $deliverymonth=GETPOST("deliverymonth","int");
  53. $deliveryday=GETPOST("deliveryday","int");
  54. $search_product_category=GETPOST('search_product_category','int');
  55. $search_ref=GETPOST('search_ref','alpha')!=''?GETPOST('search_ref','alpha'):GETPOST('sref','alpha');
  56. $search_ref_customer=GETPOST('search_ref_customer','alpha');
  57. $search_company=GETPOST('search_company','alpha');
  58. $search_town=GETPOST('search_town','alpha');
  59. $search_zip=GETPOST('search_zip','alpha');
  60. $search_state=trim(GETPOST("search_state"));
  61. $search_country=GETPOST("search_country",'int');
  62. $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
  63. $sall=GETPOST('sall', 'alphanohtml');
  64. $socid=GETPOST('socid','int');
  65. $search_user=GETPOST('search_user','int');
  66. $search_sale=GETPOST('search_sale','int');
  67. $search_total_ht=GETPOST('search_total_ht','alpha');
  68. $optioncss = GETPOST('optioncss','alpha');
  69. $billed = GETPOST('billed','int');
  70. $viewstatut=GETPOST('viewstatut');
  71. // Security check
  72. $id = (GETPOST('orderid')?GETPOST('orderid','int'):GETPOST('id','int'));
  73. if ($user->societe_id) $socid=$user->societe_id;
  74. $result = restrictedArea($user, 'commande', $id,'');
  75. $diroutputmassaction=$conf->commande->dir_output . '/temp/massgeneration/'.$user->id;
  76. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  77. $sortfield = GETPOST("sortfield",'alpha');
  78. $sortorder = GETPOST("sortorder",'alpha');
  79. $page = GETPOST("page",'int');
  80. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  81. $offset = $limit * $page;
  82. $pageprev = $page - 1;
  83. $pagenext = $page + 1;
  84. if (! $sortfield) $sortfield='c.ref';
  85. if (! $sortorder) $sortorder='DESC';
  86. // Initialize technical object to manage context to save list fields
  87. $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'orderlist';
  88. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  89. $hookmanager->initHooks(array($contextpage));
  90. $extrafields = new ExtraFields($db);
  91. // fetch optionals attributes and labels
  92. $extralabels = $extrafields->fetch_name_optionals_label('commande');
  93. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  94. // List of fields to search into when doing a "search in all"
  95. $fieldstosearchall = array(
  96. 'c.ref'=>'Ref',
  97. 'c.ref_client'=>'RefCustomerOrder',
  98. 'pd.description'=>'Description',
  99. 's.nom'=>"ThirdParty",
  100. 'c.note_public'=>'NotePublic',
  101. );
  102. if (empty($user->socid)) $fieldstosearchall["c.note_private"]="NotePrivate";
  103. $checkedtypetiers=0;
  104. $arrayfields=array(
  105. 'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  106. 'c.ref_client'=>array('label'=>$langs->trans("RefCustomerOrder"), 'checked'=>1),
  107. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
  108. 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
  109. 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
  110. 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
  111. 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
  112. 'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
  113. 'c.date_commande'=>array('label'=>$langs->trans("OrderDateShort"), 'checked'=>1),
  114. 'c.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1, 'enabled'=>empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)),
  115. 'c.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
  116. 'c.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0),
  117. 'c.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0),
  118. 'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  119. 'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  120. 'c.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  121. 'c.facture'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)))
  122. );
  123. // Extra fields
  124. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  125. {
  126. foreach($extrafields->attribute_label as $key => $val)
  127. {
  128. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  129. }
  130. }
  131. /*
  132. * Actions
  133. */
  134. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  135. if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction=''; }
  136. $parameters=array('socid'=>$socid);
  137. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  138. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  139. if (empty($reshook))
  140. {
  141. // Selection of new fields
  142. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  143. // Purge search criteria
  144. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers
  145. {
  146. $search_categ='';
  147. $search_user='';
  148. $search_sale='';
  149. $search_product_category='';
  150. $search_ref='';
  151. $search_ref_customer='';
  152. $search_company='';
  153. $search_town='';
  154. $search_zip="";
  155. $search_state="";
  156. $search_type='';
  157. $search_country='';
  158. $search_type_thirdparty='';
  159. $search_total_ht='';
  160. $search_total_vat='';
  161. $search_total_ttc='';
  162. $orderyear='';
  163. $ordermonth='';
  164. $orderday='';
  165. $deliveryday='';
  166. $deliverymonth='';
  167. $deliveryyear='';
  168. $viewstatut='';
  169. $billed='';
  170. $toselect='';
  171. $search_array_options=array();
  172. }
  173. // Mass actions
  174. $objectclass='Commande';
  175. $objectlabel='Orders';
  176. $permtoread = $user->rights->commande->lire;
  177. $permtodelete = $user->rights->commande->supprimer;
  178. $uploaddir = $conf->commande->dir_output;
  179. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  180. // TODO Move this into mass action include
  181. if ($massaction == 'confirm_createbills') {
  182. $orders = GETPOST('toselect');
  183. $createbills_onebythird = GETPOST('createbills_onebythird', 'int');
  184. $validate_invoices = GETPOST('valdate_invoices', 'int');
  185. $TFact = array();
  186. $TFactThird = array();
  187. $nb_bills_created = 0;
  188. $db->begin();
  189. foreach($orders as $id_order) {
  190. $cmd = new Commande($db);
  191. if($cmd->fetch($id_order) <= 0) continue;
  192. $object = new Facture($db);
  193. if(!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $object = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order.
  194. else {
  195. $object->socid = $cmd->socid;
  196. $object->type = Facture::TYPE_STANDARD;
  197. $object->cond_reglement_id = $cmd->cond_reglement_id;
  198. $object->mode_reglement_id = $cmd->mode_reglement_id;
  199. $object->fk_project = $cmd->fk_project;
  200. $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
  201. if (empty($datefacture))
  202. {
  203. $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y"));
  204. }
  205. $object->date = $datefacture;
  206. $object->origin = 'commande';
  207. $object->origin_id = $id_order;
  208. $res = $object->create($user);
  209. if($res > 0) $nb_bills_created++;
  210. }
  211. if($object->id > 0) {
  212. $db->begin();
  213. $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
  214. $sql.= "fk_source";
  215. $sql.= ", sourcetype";
  216. $sql.= ", fk_target";
  217. $sql.= ", targettype";
  218. $sql.= ") VALUES (";
  219. $sql.= $id_order;
  220. $sql.= ", '".$object->origin."'";
  221. $sql.= ", ".$object->id;
  222. $sql.= ", '".$object->element."'";
  223. $sql.= ")";
  224. if ($db->query($sql))
  225. {
  226. $db->commit();
  227. }
  228. else
  229. {
  230. $db->rollback();
  231. }
  232. $lines = $cmd->lines;
  233. if (empty($lines) && method_exists($cmd, 'fetch_lines'))
  234. {
  235. $cmd->fetch_lines();
  236. $lines = $cmd->lines;
  237. }
  238. $fk_parent_line=0;
  239. $num=count($lines);
  240. for ($i=0;$i<$num;$i++)
  241. {
  242. $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
  243. if ($lines[$i]->subprice < 0)
  244. {
  245. // Negative line, we create a discount line
  246. $discount = new DiscountAbsolute($db);
  247. $discount->fk_soc=$object->socid;
  248. $discount->amount_ht=abs($lines[$i]->total_ht);
  249. $discount->amount_tva=abs($lines[$i]->total_tva);
  250. $discount->amount_ttc=abs($lines[$i]->total_ttc);
  251. $discount->tva_tx=$lines[$i]->tva_tx;
  252. $discount->fk_user=$user->id;
  253. $discount->description=$desc;
  254. $discountid=$discount->create($user);
  255. if ($discountid > 0)
  256. {
  257. $result=$object->insert_discount($discountid);
  258. //$result=$discount->link_to_invoice($lineid,$id);
  259. }
  260. else
  261. {
  262. setEventMessages($discount->error, $discount->errors, 'errors');
  263. $error++;
  264. break;
  265. }
  266. }
  267. else
  268. {
  269. // Positive line
  270. $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
  271. // Date start
  272. $date_start=false;
  273. if ($lines[$i]->date_debut_prevue) $date_start=$lines[$i]->date_debut_prevue;
  274. if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
  275. if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
  276. //Date end
  277. $date_end=false;
  278. if ($lines[$i]->date_fin_prevue) $date_end=$lines[$i]->date_fin_prevue;
  279. if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
  280. if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
  281. // Reset fk_parent_line for no child products and special product
  282. if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
  283. {
  284. $fk_parent_line = 0;
  285. }
  286. $result = $object->addline(
  287. $desc,
  288. $lines[$i]->subprice,
  289. $lines[$i]->qty,
  290. $lines[$i]->tva_tx,
  291. $lines[$i]->localtax1_tx,
  292. $lines[$i]->localtax2_tx,
  293. $lines[$i]->fk_product,
  294. $lines[$i]->remise_percent,
  295. $date_start,
  296. $date_end,
  297. 0,
  298. $lines[$i]->info_bits,
  299. $lines[$i]->fk_remise_except,
  300. 'HT',
  301. 0,
  302. $product_type,
  303. $ii,
  304. $lines[$i]->special_code,
  305. $object->origin,
  306. $lines[$i]->rowid,
  307. $fk_parent_line,
  308. $lines[$i]->fk_fournprice,
  309. $lines[$i]->pa_ht,
  310. $lines[$i]->label
  311. );
  312. if ($result > 0)
  313. {
  314. $lineid=$result;
  315. }
  316. else
  317. {
  318. $lineid=0;
  319. $error++;
  320. break;
  321. }
  322. // Defined the new fk_parent_line
  323. if ($result > 0 && $lines[$i]->product_type == 9)
  324. {
  325. $fk_parent_line = $result;
  326. }
  327. }
  328. }
  329. }
  330. $cmd->classifyBilled($user);
  331. if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $object;
  332. else $TFact[$object->id] = $object;
  333. }
  334. // Build doc with all invoices
  335. $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
  336. $toselect = array();
  337. if(!empty($validate_invoices)) {
  338. $massaction = $action = 'builddoc';
  339. foreach($TAllFact as &$object) {
  340. $object->validate($user);
  341. $toselect[] = $object->id; // For builddoc action
  342. // Fac builddoc
  343. $upload_dir = $conf->facture->dir_output;
  344. $permissioncreate=$user->rights->facture->creer;
  345. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  346. }
  347. $objectclass='Facture';
  348. $objectlabel='Invoice';
  349. $permtoread = $user->rights->facture->lire;
  350. $permtodelete = $user->rights->facture->supprimer;
  351. $uploaddir = $conf->facture->dir_output;
  352. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  353. }
  354. if (! $error)
  355. {
  356. $db->commit();
  357. setEventMessage($langs->trans('BillCreated', $nb_bills_created));
  358. }
  359. else
  360. {
  361. $db->rollback();
  362. $action='create';
  363. $_GET["origin"]=$_POST["origin"];
  364. $_GET["originid"]=$_POST["originid"];
  365. setEventMessages($object->error, $object->errors, 'errors');
  366. $error++;
  367. }
  368. }
  369. }
  370. /*
  371. * View
  372. */
  373. $now=dol_now();
  374. $form = new Form($db);
  375. $formother = new FormOther($db);
  376. $formfile = new FormFile($db);
  377. $companystatic = new Societe($db);
  378. $formcompany=new FormCompany($db);
  379. $title=$langs->trans("Orders");
  380. $help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes";
  381. llxHeader('',$title,$help_url);
  382. $sql = 'SELECT';
  383. if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
  384. $sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
  385. $sql.= " typent.code as typent_code,";
  386. $sql.= " state.code_departement as state_code, state.nom as state_name,";
  387. $sql.= ' c.rowid, c.ref, c.total_ht, c.tva as total_tva, c.total_ttc, c.ref_client,';
  388. $sql.= ' c.date_valid, c.date_commande, c.note_private, c.date_livraison as date_delivery, c.fk_statut, c.facture as billed,';
  389. $sql.= ' c.date_creation as date_creation, c.tms as date_update';
  390. // Add fields from extrafields
  391. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  392. // Add fields from hooks
  393. $parameters=array();
  394. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  395. $sql.=$hookmanager->resPrint;
  396. $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  397. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  398. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  399. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  400. $sql.= ', '.MAIN_DB_PREFIX.'commande as c';
  401. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_extrafields as ef on (c.rowid = ef.fk_object)";
  402. if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON c.rowid=pd.fk_commande';
  403. if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  404. // We'll need this table joined to the select in order to filter by sale
  405. if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  406. if ($search_user > 0)
  407. {
  408. $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
  409. $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
  410. }
  411. $sql.= ' WHERE c.fk_soc = s.rowid';
  412. $sql.= ' AND c.entity IN ('.getEntity('commande').')';
  413. if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
  414. if ($socid > 0) $sql.= ' AND s.rowid = '.$socid;
  415. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  416. if ($search_ref) $sql .= natural_search('c.ref', $search_ref);
  417. if ($search_ref_customer) $sql.= natural_search('c.ref_client', $search_ref_customer);
  418. if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  419. if ($billed != '' && $billed >= 0) $sql.=' AND c.facture = '.$billed;
  420. if ($viewstatut <> '')
  421. {
  422. if ($viewstatut < 4 && $viewstatut > -3)
  423. {
  424. if ($viewstatut == 1 && empty($conf->expedition->enabled)) $sql.= ' AND c.fk_statut IN (1,2)'; // If module expedition disabled, we include order with status 'sending in process' into 'validated'
  425. else $sql.= ' AND c.fk_statut = '.$viewstatut; // brouillon, validee, en cours, annulee
  426. }
  427. if ($viewstatut == 4)
  428. {
  429. $sql.= ' AND c.facture = 1'; // invoice created
  430. }
  431. if ($viewstatut == -2) // To process
  432. {
  433. //$sql.= ' AND c.fk_statut IN (1,2,3) AND c.facture = 0';
  434. $sql.= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))"; // If status is 2 and facture=1, it must be selected
  435. }
  436. if ($viewstatut == -3) // To bill
  437. {
  438. //$sql.= ' AND c.fk_statut in (1,2,3)';
  439. //$sql.= ' AND c.facture = 0'; // invoice not created
  440. $sql .= ' AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))'; // validated, in process or closed but not billed
  441. }
  442. }
  443. if ($ordermonth > 0)
  444. {
  445. if ($orderyear > 0 && empty($orderday))
  446. $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_get_first_day($orderyear,$ordermonth,false))."' AND '".$db->idate(dol_get_last_day($orderyear,$ordermonth,false))."'";
  447. else if ($orderyear > 0 && ! empty($orderday))
  448. $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $ordermonth, $orderday, $orderyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $ordermonth, $orderday, $orderyear))."'";
  449. else
  450. $sql.= " AND date_format(c.date_commande, '%m') = '".$ordermonth."'";
  451. }
  452. else if ($orderyear > 0)
  453. {
  454. $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_get_first_day($orderyear,1,false))."' AND '".$db->idate(dol_get_last_day($orderyear,12,false))."'";
  455. }
  456. if ($deliverymonth > 0)
  457. {
  458. if ($deliveryyear > 0 && empty($deliveryday))
  459. $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($deliveryyear,$deliverymonth,false))."' AND '".$db->idate(dol_get_last_day($deliveryyear,$deliverymonth,false))."'";
  460. else if ($deliveryyear > 0 && ! empty($deliveryday))
  461. $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $deliverymonth, $deliveryday, $deliveryyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $deliverymonth, $deliveryday, $deliveryyear))."'";
  462. else
  463. $sql.= " AND date_format(c.date_livraison, '%m') = '".$deliverymonth."'";
  464. }
  465. else if ($deliveryyear > 0)
  466. {
  467. $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($deliveryyear,1,false))."' AND '".$db->idate(dol_get_last_day($deliveryyear,12,false))."'";
  468. }
  469. if ($search_town) $sql.= natural_search('s.town', $search_town);
  470. if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
  471. if ($search_state) $sql.= natural_search("state.nom",$search_state);
  472. if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
  473. if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
  474. if ($search_company) $sql .= natural_search('s.nom', $search_company);
  475. if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
  476. if ($search_user > 0) $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;
  477. if ($search_total_ht != '') $sql.= natural_search('c.total_ht', $search_total_ht, 1);
  478. // Add where from extra fields
  479. foreach ($search_array_options as $key => $val)
  480. {
  481. $crit=$val;
  482. $tmpkey=preg_replace('/search_options_/','',$key);
  483. $typ=$extrafields->attribute_type[$tmpkey];
  484. $mode=0;
  485. if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
  486. if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
  487. {
  488. $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
  489. }
  490. }
  491. // Add where from hooks
  492. $parameters=array();
  493. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  494. $sql.=$hookmanager->resPrint;
  495. $sql.= $db->order($sortfield,$sortorder);
  496. // Count total nb of records
  497. $nbtotalofrecords = '';
  498. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  499. {
  500. $result = $db->query($sql);
  501. $nbtotalofrecords = $db->num_rows($result);
  502. }
  503. $sql.= $db->plimit($limit + 1,$offset);
  504. //print $sql;
  505. $resql = $db->query($sql);
  506. if ($resql)
  507. {
  508. if ($socid > 0)
  509. {
  510. $soc = new Societe($db);
  511. $soc->fetch($socid);
  512. $title = $langs->trans('ListOfOrders') . ' - '.$soc->name;
  513. }
  514. else
  515. {
  516. $title = $langs->trans('ListOfOrders');
  517. }
  518. if (strval($viewstatut) == '0')
  519. $title.=' - '.$langs->trans('StatusOrderDraftShort');
  520. if ($viewstatut == 1)
  521. $title.=' - '.$langs->trans('StatusOrderValidatedShort');
  522. if ($viewstatut == 2)
  523. $title.=' - '.$langs->trans('StatusOrderSentShort');
  524. if ($viewstatut == 3)
  525. $title.=' - '.$langs->trans('StatusOrderToBillShort');
  526. if ($viewstatut == 4)
  527. $title.=' - '.$langs->trans('StatusOrderProcessedShort');
  528. if ($viewstatut == -1)
  529. $title.=' - '.$langs->trans('StatusOrderCanceledShort');
  530. if ($viewstatut == -2)
  531. $title.=' - '.$langs->trans('StatusOrderToProcessShort');
  532. if ($viewstatut == -3)
  533. $title.=' - '.$langs->trans('StatusOrderValidated').', '.(empty($conf->expedition->enabled)?'':$langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill');
  534. $num = $db->num_rows($resql);
  535. $arrayofselected=is_array($toselect)?$toselect:array();
  536. $param='';
  537. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  538. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  539. if ($sall) $param.='&sall='.$sall;
  540. if ($socid > 0) $param.='&socid='.$socid;
  541. if ($viewstatut != '') $param.='&viewstatut='.$viewstatut;
  542. if ($orderday) $param.='&orderday='.$orderday;
  543. if ($ordermonth) $param.='&ordermonth='.$ordermonth;
  544. if ($orderyear) $param.='&orderyear='.$orderyear;
  545. if ($deliveryday) $param.='&deliveryday='.$deliveryday;
  546. if ($deliverymonth) $param.='&deliverymonth='.$deliverymonth;
  547. if ($deliveryyear) $param.='&deliveryyear='.$deliveryyear;
  548. if ($search_ref) $param.='&search_ref='.$search_ref;
  549. if ($search_company) $param.='&search_company='.$search_company;
  550. if ($search_ref_customer) $param.='&search_ref_customer='.$search_ref_customer;
  551. if ($search_user > 0) $param.='&search_user='.$search_user;
  552. if ($search_sale > 0) $param.='&search_sale='.$search_sale;
  553. if ($search_total_ht != '') $param.='&search_total_ht='.$search_total_ht;
  554. if ($search_total_vat != '') $param.='&search_total_vat='.$search_total_vat;
  555. if ($search_total_ttc != '') $param.='&search_total_ttc='.$search_total_ttc;
  556. if ($show_files) $param.='&show_files=' .$show_files;
  557. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  558. if ($billed != '') $param.='&billed='.$billed;
  559. // Add $param from extra fields
  560. foreach ($search_array_options as $key => $val)
  561. {
  562. $crit=$val;
  563. $tmpkey=preg_replace('/search_options_/','',$key);
  564. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  565. }
  566. // List of mass actions available
  567. $arrayofmassactions = array(
  568. 'presend'=>$langs->trans("SendByMail"),
  569. 'builddoc'=>$langs->trans("PDFMerge"),
  570. );
  571. if($user->rights->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  572. if ($user->rights->commande->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
  573. if ($massaction == 'presend' || $massaction == 'createbills') $arrayofmassactions=array();
  574. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  575. // Lines of title fields
  576. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  577. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  578. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  579. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  580. print '<input type="hidden" name="action" value="list">';
  581. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  582. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  583. print '<input type="hidden" name="page" value="'.$page.'">';
  584. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  585. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  586. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit);
  587. // TODO Move this into an invluce
  588. if ($massaction == 'presend')
  589. {
  590. $langs->load("mails");
  591. if (! GETPOST('cancel'))
  592. {
  593. $objecttmp=new Commande($db);
  594. $listofselectedid=array();
  595. $listofselectedthirdparties=array();
  596. $listofselectedref=array();
  597. foreach($arrayofselected as $toselectid)
  598. {
  599. $result=$objecttmp->fetch($toselectid);
  600. if ($result > 0)
  601. {
  602. $listofselectedid[$toselectid]=$toselectid;
  603. $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
  604. $listofselectedthirdparties[$thirdpartyid]=$thirdpartyid;
  605. $listofselectedref[$thirdpartyid][$toselectid]=$objecttmp->ref;
  606. }
  607. }
  608. }
  609. print '<input type="hidden" name="massaction" value="confirm_presend">';
  610. dol_fiche_head(null, '', '');
  611. $topicmail="SendOrderRef";
  612. $modelmail="order_send";
  613. // Cree l'objet formulaire mail
  614. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  615. $formmail = new FormMail($db);
  616. $formmail->withform=-1;
  617. $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
  618. if($formmail->fromtype === 'user'){
  619. $formmail->fromid = $user->id;
  620. }
  621. if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 1)) // If bit 1 is set
  622. {
  623. $formmail->trackid='ord'.$object->id;
  624. }
  625. if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
  626. {
  627. include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  628. $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'ord'.$object->id);
  629. }
  630. $formmail->withfrom=1;
  631. $liste=$langs->trans("AllRecipientSelected");
  632. if (count($listofselectedthirdparties) == 1)
  633. {
  634. $liste=array();
  635. $thirdpartyid=array_shift($listofselectedthirdparties);
  636. $soc=new Societe($db);
  637. $soc->fetch($thirdpartyid);
  638. foreach ($soc->thirdparty_and_contact_email_array(1) as $key=>$value)
  639. {
  640. $liste[$key]=$value;
  641. }
  642. $formmail->withtoreadonly=0;
  643. }
  644. else
  645. {
  646. $formmail->withtoreadonly=1;
  647. }
  648. $formmail->withto=$liste;
  649. $formmail->withtofree=0;
  650. $formmail->withtocc=1;
  651. $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
  652. $formmail->withtopic=$langs->transnoentities($topicmail, '__REF__', '__REFCLIENT__');
  653. $formmail->withfile=$langs->trans("OnlyPDFattachmentSupported");
  654. $formmail->withbody=1;
  655. $formmail->withdeliveryreceipt=1;
  656. $formmail->withcancel=1;
  657. // Tableau des substitutions
  658. $formmail->substit['__REF__']='__REF__'; // We want to keep the tag
  659. $formmail->substit['__SIGNATURE__']=$user->signature;
  660. $formmail->substit['__REFCLIENT__']='__REFCLIENT__'; // We want to keep the tag
  661. $formmail->substit['__PERSONALIZED__']='';
  662. $formmail->substit['__CONTACTCIVNAME__']='';
  663. // Tableau des parametres complementaires du post
  664. $formmail->param['action']=$action;
  665. $formmail->param['models']=$modelmail;
  666. $formmail->param['models_id']=GETPOST('modelmailselected','int');
  667. $formmail->param['id']=join(',',$arrayofselected);
  668. //$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  669. print $formmail->get_form();
  670. dol_fiche_end();
  671. }
  672. elseif ($massaction == 'createbills')
  673. {
  674. //var_dump($_REQUEST);
  675. print '<input type="hidden" name="massaction" value="confirm_createbills">';
  676. print '<table class="border" width="100%" >';
  677. print '<tr>';
  678. print '<td class="titlefieldmiddle">';
  679. print $langs->trans('DateInvoice');
  680. print '</td>';
  681. print '<td>';
  682. print $form->select_date('', '', '', '', '', '', 1, 1);
  683. print '</td>';
  684. print '</tr>';
  685. print '<tr>';
  686. print '<td>';
  687. print $langs->trans('CreateOneBillByThird');
  688. print '</td>';
  689. print '<td>';
  690. print $form->selectyesno('createbills_onebythird', '', 1);
  691. print '</td>';
  692. print '</tr>';
  693. print '<tr>';
  694. print '<td>';
  695. print $langs->trans('ValidateInvoices');
  696. print '</td>';
  697. print '<td>';
  698. print $form->selectyesno('valdate_invoices', 1, 1);
  699. print '</td>';
  700. print '</tr>';
  701. print '</table>';
  702. print '<br>';
  703. print '<div class="center">';
  704. print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> ';
  705. print '<input type="submit" class="button" id="cancel" name="cancel" value="'.$langs->trans('Cancel').'">';
  706. print '</div>';
  707. print '<br>';
  708. }
  709. if ($sall)
  710. {
  711. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  712. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  713. }
  714. $moreforfilter='';
  715. // If the user can view prospects other than his'
  716. if ($user->rights->societe->client->voir || $socid)
  717. {
  718. $langs->load("commercial");
  719. $moreforfilter.='<div class="divsearchfield">';
  720. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  721. $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300');
  722. $moreforfilter.='</div>';
  723. }
  724. // If the user can view other users
  725. if ($user->rights->user->user->lire)
  726. {
  727. $moreforfilter.='<div class="divsearchfield">';
  728. $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
  729. $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  730. $moreforfilter.='</div>';
  731. }
  732. // If the user can view prospects other than his'
  733. if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
  734. {
  735. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  736. $moreforfilter.='<div class="divsearchfield">';
  737. $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
  738. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  739. $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1);
  740. $moreforfilter.='</div>';
  741. }
  742. $parameters=array();
  743. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  744. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  745. else $moreforfilter = $hookmanager->resPrint;
  746. if (! empty($moreforfilter))
  747. {
  748. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  749. print $moreforfilter;
  750. print '</div>';
  751. }
  752. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  753. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  754. if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  755. print '<div class="div-table-responsive">';
  756. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  757. print '<tr class="liste_titre_filter">';
  758. // Ref
  759. if (! empty($arrayfields['c.ref']['checked']))
  760. {
  761. print '<td class="liste_titre">';
  762. print '<input class="flat" size="6" type="text" name="search_ref" value="'.$search_ref.'">';
  763. print '</td>';
  764. }
  765. // Ref customer
  766. if (! empty($arrayfields['c.ref_client']['checked']))
  767. {
  768. print '<td class="liste_titre" align="left">';
  769. print '<input class="flat" type="text" size="6" name="search_ref_customer" value="'.$search_ref_customer.'">';
  770. print '</td>';
  771. }
  772. // Thirpdarty
  773. if (! empty($arrayfields['s.nom']['checked']))
  774. {
  775. print '<td class="liste_titre" align="left">';
  776. print '<input class="flat" type="text" name="search_company" value="'.$search_company.'">';
  777. print '</td>';
  778. }
  779. // Town
  780. if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_town" value="'.$search_town.'"></td>';
  781. // Zip
  782. if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_zip" value="'.$search_zip.'"></td>';
  783. // State
  784. if (! empty($arrayfields['state.nom']['checked']))
  785. {
  786. print '<td class="liste_titre">';
  787. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  788. print '</td>';
  789. }
  790. // Country
  791. if (! empty($arrayfields['country.code_iso']['checked']))
  792. {
  793. print '<td class="liste_titre" align="center">';
  794. print $form->select_country($search_country,'search_country','',0,'maxwidth100');
  795. print '</td>';
  796. }
  797. // Company type
  798. if (! empty($arrayfields['typent.code']['checked']))
  799. {
  800. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  801. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
  802. print '</td>';
  803. }
  804. // Date order
  805. if (! empty($arrayfields['c.date_commande']['checked']))
  806. {
  807. print '<td class="liste_titre" align="center">';
  808. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="orderday" value="'.$orderday.'">';
  809. print '<input class="flat" type="text" size="1" maxlength="2" name="ordermonth" value="'.$ordermonth.'">';
  810. $formother->select_year($orderyear?$orderyear:-1,'orderyear',1, 20, 5);
  811. print '</td>';
  812. }
  813. if (! empty($arrayfields['c.date_delivery']['checked']))
  814. {
  815. print '<td class="liste_titre" align="center">';
  816. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="deliveryday" value="'.$deliveryday.'">';
  817. print '<input class="flat" type="text" size="1" maxlength="2" name="deliverymonth" value="'.$deliverymonth.'">';
  818. $formother->select_year($deliveryyear?$deliveryyear:-1,'deliveryyear',1, 20, 5);
  819. print '</td>';
  820. }
  821. if (! empty($arrayfields['c.total_ht']['checked']))
  822. {
  823. // Amount
  824. print '<td class="liste_titre" align="right">';
  825. print '<input class="flat" type="text" size="4" name="search_total_ht" value="'.$search_total_ht.'">';
  826. print '</td>';
  827. }
  828. if (! empty($arrayfields['c.total_vat']['checked']))
  829. {
  830. // Amount
  831. print '<td class="liste_titre" align="right">';
  832. print '<input class="flat" type="text" size="4" name="search_total_vat" value="'.$search_total_vat.'">';
  833. print '</td>';
  834. }
  835. if (! empty($arrayfields['c.total_ttc']['checked']))
  836. {
  837. // Amount
  838. print '<td class="liste_titre" align="right">';
  839. print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">';
  840. print '</td>';
  841. }
  842. // Extra fields
  843. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  844. {
  845. foreach($extrafields->attribute_label as $key => $val)
  846. {
  847. if (! empty($arrayfields["ef.".$key]['checked']))
  848. {
  849. $align=$extrafields->getAlignFlag($key);
  850. $typeofextrafield=$extrafields->attribute_type[$key];
  851. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  852. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  853. {
  854. $crit=$val;
  855. $tmpkey=preg_replace('/search_options_/','',$key);
  856. $searchclass='';
  857. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  858. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  859. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  860. }
  861. print '</td>';
  862. }
  863. }
  864. }
  865. // Fields from hook
  866. $parameters=array('arrayfields'=>$arrayfields);
  867. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  868. print $hookmanager->resPrint;
  869. // Date creation
  870. if (! empty($arrayfields['c.datec']['checked']))
  871. {
  872. print '<td class="liste_titre">';
  873. print '</td>';
  874. }
  875. // Date modification
  876. if (! empty($arrayfields['c.tms']['checked']))
  877. {
  878. print '<td class="liste_titre">';
  879. print '</td>';
  880. }
  881. // Status
  882. if (! empty($arrayfields['c.fk_statut']['checked']))
  883. {
  884. print '<td class="liste_titre maxwidthonsmartphone" align="right">';
  885. $liststatus=array(
  886. Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"),
  887. Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"),
  888. Commande::STATUS_ACCEPTED=>$langs->trans("StatusOrderSentShort"),
  889. Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"),
  890. Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceledShort")
  891. );
  892. print $form->selectarray('viewstatut', $liststatus, $viewstatut, -4);
  893. print '</td>';
  894. }
  895. // Status billed
  896. if (! empty($arrayfields['c.facture']['checked']))
  897. {
  898. print '<td class="liste_titre maxwidthonsmartphone" align="right">';
  899. print $form->selectyesno('billed', $billed, 1, 0, 1);
  900. print '</td>';
  901. }
  902. // Action column
  903. print '<td class="liste_titre" align="middle">';
  904. $searchpicto=$form->showFilterButtons();
  905. print $searchpicto;
  906. print '</td>';
  907. print "</tr>\n";
  908. // Fields title
  909. print '<tr class="liste_titre">';
  910. if (! empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'],$_SERVER["PHP_SELF"],'c.ref','',$param,'',$sortfield,$sortorder);
  911. if (! empty($arrayfields['c.ref_client']['checked'])) print_liste_field_titre($arrayfields['c.ref_client']['label'],$_SERVER["PHP_SELF"],'c.ref_client','',$param,'',$sortfield,$sortorder);
  912. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER["PHP_SELF"],'s.nom','',$param,'',$sortfield,$sortorder);
  913. if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
  914. if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
  915. if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  916. if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
  917. if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
  918. if (! empty($arrayfields['c.date_commande']['checked'])) print_liste_field_titre($arrayfields['c.date_commande']['label'],$_SERVER["PHP_SELF"],'c.date_commande','',$param, 'align="center"',$sortfield,$sortorder);
  919. if (! empty($arrayfields['c.date_delivery']['checked'])) print_liste_field_titre($arrayfields['c.date_delivery']['label'],$_SERVER["PHP_SELF"],'c.date_livraison','',$param, 'align="center"',$sortfield,$sortorder);
  920. if (! empty($arrayfields['c.total_ht']['checked'])) print_liste_field_titre($arrayfields['c.total_ht']['label'],$_SERVER["PHP_SELF"],'c.total_ht','',$param, 'align="right"',$sortfield,$sortorder);
  921. if (! empty($arrayfields['c.total_vat']['checked'])) print_liste_field_titre($arrayfields['c.total_vat']['label'],$_SERVER["PHP_SELF"],'c.tva','',$param, 'align="right"',$sortfield,$sortorder);
  922. if (! empty($arrayfields['c.total_ttc']['checked'])) print_liste_field_titre($arrayfields['c.total_ttc']['label'],$_SERVER["PHP_SELF"],'c.total_ttc','',$param, 'align="right"',$sortfield,$sortorder);
  923. // Extra fields
  924. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  925. {
  926. foreach($extrafields->attribute_label as $key => $val)
  927. {
  928. if (! empty($arrayfields["ef.".$key]['checked']))
  929. {
  930. $align=$extrafields->getAlignFlag($key);
  931. print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  932. }
  933. }
  934. }
  935. // Hook fields
  936. $parameters=array('arrayfields'=>$arrayfields);
  937. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  938. print $hookmanager->resPrint;
  939. if (! empty($arrayfields['c.datec']['checked'])) print_liste_field_titre($arrayfields['c.datec']['label'],$_SERVER["PHP_SELF"],"c.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  940. if (! empty($arrayfields['c.tms']['checked'])) print_liste_field_titre($arrayfields['c.tms']['label'],$_SERVER["PHP_SELF"],"c.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  941. if (! empty($arrayfields['c.fk_statut']['checked'])) print_liste_field_titre($arrayfields['c.fk_statut']['label'],$_SERVER["PHP_SELF"],"c.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
  942. if (! empty($arrayfields['c.facture']['checked'])) print_liste_field_titre($arrayfields['c.facture']['label'],$_SERVER["PHP_SELF"],'c.facture','',$param,'align="center"',$sortfield,$sortorder,'');
  943. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  944. print '</tr>'."\n";
  945. $total=0;
  946. $subtotal=0;
  947. $productstat_cache=array();
  948. $generic_commande = new Commande($db);
  949. $generic_product = new Product($db);
  950. $i=0;
  951. $totalarray=array();
  952. while ($i < min($num,$limit))
  953. {
  954. $obj = $db->fetch_object($resql);
  955. print '<tr class="oddeven">';
  956. $notshippable=0;
  957. $warning = 0;
  958. $text_info='';
  959. $text_warning='';
  960. $nbprod=0;
  961. // Ref
  962. if (! empty($arrayfields['c.ref']['checked']))
  963. {
  964. print '<td class="nowrap">';
  965. $generic_commande->id=$obj->rowid;
  966. $generic_commande->ref=$obj->ref;
  967. $generic_commande->statut = $obj->fk_statut;
  968. $generic_commande->date_commande = $db->jdate($obj->date_commande);
  969. $generic_commande->date_livraison = $db->jdate($obj->date_delivery);
  970. $generic_commande->ref_client = $obj->ref_client;
  971. $generic_commande->total_ht = $obj->total_ht;
  972. $generic_commande->total_tva = $obj->total_tva;
  973. $generic_commande->total_ttc = $obj->total_ttc;
  974. $generic_commande->lines=array();
  975. $generic_commande->getLinesArray();
  976. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  977. print '<td class="nobordernopadding nowrap">';
  978. print $generic_commande->getNomUrl(1,($viewstatut != 2?0:$obj->fk_statut));
  979. print '</td>';
  980. // Show shippable Icon (create subloop, so may be slow)
  981. if ($conf->stock->enabled)
  982. {
  983. $langs->load("stocks");
  984. if (($obj->fk_statut > 0) && ($obj->fk_statut < 3))
  985. {
  986. $numlines = count($generic_commande->lines); // Loop on each line of order
  987. for ($lig=0; $lig < $numlines; $lig++)
  988. {
  989. if ($generic_commande->lines[$lig]->product_type == 0 && $generic_commande->lines[$lig]->fk_product > 0) // If line is a product and not a service
  990. {
  991. $nbprod++; // order contains real products
  992. $generic_product->id = $generic_commande->lines[$lig]->fk_product;
  993. // Get local and virtual stock and store it into cache
  994. if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) {
  995. $generic_product->load_stock('nobatch');
  996. //$generic_product->load_virtual_stock(); Already included into load_stock
  997. $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel;
  998. $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
  999. } else {
  1000. $generic_product->stock_reel = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'];
  1001. $generic_product->stock_theorique = $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique;
  1002. }
  1003. if (empty($conf->global->SHIPPABLE_ORDER_ICON_IN_LIST)) // Default code. Default is when this option is not set, setting it create strange result
  1004. {
  1005. $text_info .= $generic_commande->lines[$lig]->qty.' X '.$generic_commande->lines[$lig]->ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 25);
  1006. $text_info .= ' - '.$langs->trans("Stock").': '.$generic_product->stock_reel;
  1007. $text_info .= ' - '.$langs->trans("VirtualStock").': '.$generic_product->stock_theorique;
  1008. $text_info .= '<br>';
  1009. if ($generic_commande->lines[$lig]->qty > $generic_product->stock_reel)
  1010. {
  1011. $notshippable++;
  1012. }
  1013. }
  1014. else { // Detailed code, looks bugged
  1015. // stock order and stock order_supplier
  1016. $stock_order=0;
  1017. $stock_order_supplier=0;
  1018. if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) // What about other options ?
  1019. {
  1020. if (! empty($conf->commande->enabled))
  1021. {
  1022. if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'])) {
  1023. $generic_product->load_stats_commande(0,'1,2');
  1024. $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'] = $generic_product->stats_commande['qty'];
  1025. } else {
  1026. $generic_product->stats_commande['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_customer'];
  1027. }
  1028. $stock_order=$generic_product->stats_commande['qty'];
  1029. }
  1030. if (! empty($conf->fournisseur->enabled))
  1031. {
  1032. if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'])) {
  1033. $generic_product->load_stats_commande_fournisseur(0,'3');
  1034. $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'] = $generic_product->stats_commande_fournisseur['qty'];
  1035. } else {
  1036. $generic_product->stats_commande_fournisseur['qty'] = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stats_order_supplier'];
  1037. }
  1038. $stock_order_supplier=$generic_product->stats_commande_fournisseur['qty'];
  1039. }
  1040. }
  1041. $text_info .= $generic_commande->lines[$lig]->qty.' X '.$generic_commande->lines[$lig]->ref.'&nbsp;'.dol_trunc($generic_commande->lines[$lig]->product_label, 25);
  1042. $text_stock_reel = $generic_product->stock_reel.'/'.$stock_order;
  1043. if ($stock_order > $generic_product->stock_reel && ! ($generic_product->stock_reel < $generic_commande->lines[$lig]->qty)) {
  1044. $warning++;
  1045. $text_warning.='<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
  1046. }
  1047. if ($generic_product->stock_reel < $generic_commande->lines[$lig]->qty) {
  1048. $notshippable++;
  1049. $text_info.='<span class="warning">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
  1050. } else {
  1051. $text_info.='<span class="ok">'.$langs->trans('Available').'&nbsp;:&nbsp;'.$text_stock_reel.'</span>';
  1052. }
  1053. if (! empty($conf->fournisseur->enabled)) {
  1054. $text_info.= '&nbsp;'.$langs->trans('SupplierOrder').'&nbsp;:&nbsp;'.$stock_order_supplier.'<br>';
  1055. } else {
  1056. $text_info.= '<br>';
  1057. }
  1058. }
  1059. }
  1060. }
  1061. if ($notshippable==0) {
  1062. $text_icon = img_picto('', 'object_sending');
  1063. $text_info = $langs->trans('Shippable').'<br>'.$text_info;
  1064. } else {
  1065. $text_icon = img_picto('', 'error');
  1066. $text_info = $langs->trans('NonShippable').'<br>'.$text_info;
  1067. }
  1068. }
  1069. print '<td>';
  1070. if ($nbprod)
  1071. {
  1072. print $form->textwithtooltip('',$text_info,2,1,$text_icon,'',2);
  1073. }
  1074. if ($warning) { // Always false in default mode
  1075. print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'<br>'.$text_warning, 2, 1, img_picto('', 'error'),'',2);
  1076. }
  1077. print '</td>';
  1078. }
  1079. // Warning late icon and note
  1080. print '<td class="nobordernopadding nowrap">';
  1081. if ($generic_commande->hasDelay()) {
  1082. print img_picto($langs->trans("Late").' : '.$generic_commande->showDelay(), "warning");
  1083. }
  1084. if (!empty($obj->note_private) || !empty($obj->note_public))
  1085. {
  1086. print ' <span class="note">';
  1087. print '<a href="'.DOL_URL_ROOT.'/commande/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"),'object_generic').'</a>';
  1088. print '</span>';
  1089. }
  1090. print '</td>';
  1091. print '<td width="16" align="right" class="nobordernopadding hideonsmartphone">';
  1092. $filename=dol_sanitizeFileName($obj->ref);
  1093. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  1094. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  1095. print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir);
  1096. print '</td>';
  1097. print '</tr></table>';
  1098. print '</td>';
  1099. if (! $i) $totalarray['nbfield']++;
  1100. }
  1101. // Ref customer
  1102. if (! empty($arrayfields['c.ref_client']['checked']))
  1103. {
  1104. print '<td>'.$obj->ref_client.'</td>';
  1105. if (! $i) $totalarray['nbfield']++;
  1106. }
  1107. $companystatic->id=$obj->socid;
  1108. $companystatic->code_client = $obj->code_client;
  1109. $companystatic->name=$obj->name;
  1110. $companystatic->client=$obj->client;
  1111. // Third party
  1112. if (! empty($arrayfields['s.nom']['checked']))
  1113. {
  1114. print '<td class="tdoverflowmax200">';
  1115. print $companystatic->getNomUrl(1,'customer');
  1116. // If module invoices enabled and user with invoice creation permissions
  1117. if (! empty($conf->facture->enabled) && ! empty($conf->global->ORDER_BILLING_ALL_CUSTOMER))
  1118. {
  1119. if ($user->rights->facture->creer)
  1120. {
  1121. if (($obj->fk_statut > 0 && $obj->fk_statut < 3) || ($obj->fk_statut == 3 && $obj->billed == 0))
  1122. {
  1123. print '&nbsp;<a href="'.DOL_URL_ROOT.'/commande/orderstoinvoice.php?socid='.$companystatic->id.'">';
  1124. print img_picto($langs->trans("CreateInvoiceForThisCustomer").' : '.$companystatic->name, 'object_bill', 'hideonsmartphone').'</a>';
  1125. }
  1126. }
  1127. }
  1128. print '</td>';
  1129. if (! $i) $totalarray['nbfield']++;
  1130. }
  1131. // Town
  1132. if (! empty($arrayfields['s.town']['checked']))
  1133. {
  1134. print '<td class="nocellnopadd">';
  1135. print $obj->town;
  1136. print '</td>';
  1137. if (! $i) $totalarray['nbfield']++;
  1138. }
  1139. // Zip
  1140. if (! empty($arrayfields['s.zip']['checked']))
  1141. {
  1142. print '<td class="nocellnopadd">';
  1143. print $obj->zip;
  1144. print '</td>';
  1145. if (! $i) $totalarray['nbfield']++;
  1146. }
  1147. // State
  1148. if (! empty($arrayfields['state.nom']['checked']))
  1149. {
  1150. print "<td>".$obj->state_name."</td>\n";
  1151. if (! $i) $totalarray['nbfield']++;
  1152. }
  1153. // Country
  1154. if (! empty($arrayfields['country.code_iso']['checked']))
  1155. {
  1156. print '<td align="center">';
  1157. $tmparray=getCountry($obj->fk_pays,'all');
  1158. print $tmparray['label'];
  1159. print '</td>';
  1160. if (! $i) $totalarray['nbfield']++;
  1161. }
  1162. // Type ent
  1163. if (! empty($arrayfields['typent.code']['checked']))
  1164. {
  1165. print '<td align="center">';
  1166. if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
  1167. print $typenArray[$obj->typent_code];
  1168. print '</td>';
  1169. if (! $i) $totalarray['nbfield']++;
  1170. }
  1171. // Order date
  1172. if (! empty($arrayfields['c.date_commande']['checked']))
  1173. {
  1174. print '<td align="center">';
  1175. print dol_print_date($db->jdate($obj->date_commande), 'day');
  1176. print '</td>';
  1177. if (! $i) $totalarray['nbfield']++;
  1178. }
  1179. // Plannned date of delivery
  1180. if (! empty($arrayfields['c.date_delivery']['checked']))
  1181. {
  1182. print '<td align="center">';
  1183. print dol_print_date($db->jdate($obj->date_delivery), 'day');
  1184. print '</td>';
  1185. if (! $i) $totalarray['nbfield']++;
  1186. }
  1187. // Amount HT
  1188. if (! empty($arrayfields['c.total_ht']['checked']))
  1189. {
  1190. print '<td align="right">'.price($obj->total_ht)."</td>\n";
  1191. if (! $i) $totalarray['nbfield']++;
  1192. if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
  1193. $totalarray['totalht'] += $obj->total_ht;
  1194. }
  1195. // Amount VAT
  1196. if (! empty($arrayfields['c.total_vat']['checked']))
  1197. {
  1198. print '<td align="right">'.price($obj->total_tva)."</td>\n";
  1199. if (! $i) $totalarray['nbfield']++;
  1200. if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
  1201. $totalarray['totalvat'] += $obj->total_tva;
  1202. }
  1203. // Amount TTC
  1204. if (! empty($arrayfields['c.total_ttc']['checked']))
  1205. {
  1206. print '<td align="right">'.price($obj->total_ttc)."</td>\n";
  1207. if (! $i) $totalarray['nbfield']++;
  1208. if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
  1209. $totalarray['totalttc'] += $obj->total_ttc;
  1210. }
  1211. // Extra fields
  1212. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  1213. {
  1214. foreach($extrafields->attribute_label as $key => $val)
  1215. {
  1216. if (! empty($arrayfields["ef.".$key]['checked']))
  1217. {
  1218. print '<td';
  1219. $align=$extrafields->getAlignFlag($key);
  1220. if ($align) print ' align="'.$align.'"';
  1221. print '>';
  1222. $tmpkey='options_'.$key;
  1223. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  1224. print '</td>';
  1225. if (! $i) $totalarray['nbfield']++;
  1226. }
  1227. }
  1228. }
  1229. // Fields from hook
  1230. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  1231. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  1232. print $hookmanager->resPrint;
  1233. // Date creation
  1234. if (! empty($arrayfields['c.datec']['checked']))
  1235. {
  1236. print '<td align="center" class="nowrap">';
  1237. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  1238. print '</td>';
  1239. if (! $i) $totalarray['nbfield']++;
  1240. }
  1241. // Date modification
  1242. if (! empty($arrayfields['c.tms']['checked']))
  1243. {
  1244. print '<td align="center" class="nowrap">';
  1245. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  1246. print '</td>';
  1247. if (! $i) $totalarray['nbfield']++;
  1248. }
  1249. // Status
  1250. if (! empty($arrayfields['c.fk_statut']['checked']))
  1251. {
  1252. print '<td align="right" class="nowrap">'.$generic_commande->LibStatut($obj->fk_statut, $obj->billed, 5, 1).'</td>';
  1253. if (! $i) $totalarray['nbfield']++;
  1254. }
  1255. // Billed
  1256. if (! empty($arrayfields['c.facture']['checked']))
  1257. {
  1258. print '<td align="center">'.yn($obj->billed).'</td>';
  1259. if (! $i) $totalarray['nbfield']++;
  1260. }
  1261. // Action column
  1262. print '<td class="nowrap" align="center">';
  1263. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1264. {
  1265. $selected=0;
  1266. if (in_array($obj->rowid, $arrayofselected)) $selected=1;
  1267. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
  1268. }
  1269. print '</td>';
  1270. if (! $i) $totalarray['nbfield']++;
  1271. print "</tr>\n";
  1272. $total+=$obj->total_ht;
  1273. $subtotal+=$obj->total_ht;
  1274. $i++;
  1275. }
  1276. // Show total line
  1277. if (isset($totalarray['totalhtfield'])
  1278. || isset($totalarray['totalvatfield'])
  1279. || isset($totalarray['totalttcfield'])
  1280. || isset($totalarray['totalamfield'])
  1281. || isset($totalarray['totalrtpfield'])
  1282. )
  1283. {
  1284. print '<tr class="liste_total">';
  1285. $i=0;
  1286. while ($i < $totalarray['nbfield'])
  1287. {
  1288. $i++;
  1289. if ($i == 1)
  1290. {
  1291. if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
  1292. else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
  1293. }
  1294. elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
  1295. elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
  1296. elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
  1297. else print '<td></td>';
  1298. }
  1299. print '</tr>';
  1300. }
  1301. $db->free($resql);
  1302. $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1303. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  1304. print $hookmanager->resPrint;
  1305. print '</table>'."\n";
  1306. print '</div>';
  1307. print '</form>'."\n";
  1308. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
  1309. {
  1310. /*
  1311. * Show list of available documents
  1312. */
  1313. $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1314. $urlsource.=str_replace('&amp;','&',$param);
  1315. $filedir=$diroutputmassaction;
  1316. $genallowed=$user->rights->commande->lire;
  1317. $delallowed=$user->rights->commande->supprimer;
  1318. print $formfile->showdocuments('massfilesarea_orders','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
  1319. }
  1320. else
  1321. {
  1322. print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
  1323. }
  1324. }
  1325. else
  1326. {
  1327. dol_print_error($db);
  1328. }
  1329. llxFooter();
  1330. $db->close();