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-2020 Charlene Benke <charlie@patas-monkey.com> 11 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com> 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of the GNU General Public License as published by 15 * the Free Software Foundation; either version 3 of the License, or 16 * (at your option) any later version. 17 * 18 * This program is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program. If not, see <https://www.gnu.org/licenses/>. 25 */ 26 27/** 28 * \file htdocs/fourn/commande/list.php 29 * \ingroup fournisseur 30 * \brief List of purchase orders 31 */ 32 33require '../../main.inc.php'; 34require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; 35require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; 36require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; 37require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; 38require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; 39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; 40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php'; 41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; 42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 43require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; 44require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; 45 46$langs->loadLangs(array("orders", "sendings", 'deliveries', 'companies', 'compta', 'bills', 'projects', 'suppliers', 'products')); 47 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 55$search_orderyear = GETPOST("search_orderyear", "int"); 56$search_ordermonth = GETPOST("search_ordermonth", "int"); 57$search_orderday = GETPOST("search_orderday", "int"); 58$search_deliveryyear = GETPOST("search_deliveryyear", "int"); 59$search_deliverymonth = GETPOST("search_deliverymonth", "int"); 60$search_deliveryday = GETPOST("search_deliveryday", "int"); 61 62$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); 63 64$search_product_category = GETPOST('search_product_category', 'int'); 65$search_ref = GETPOST('search_ref', 'alpha'); 66$search_refsupp = GETPOST('search_refsupp', 'alpha'); 67$search_company = GETPOST('search_company', 'alpha'); 68$search_town = GETPOST('search_town', 'alpha'); 69$search_zip = GETPOST('search_zip', 'alpha'); 70$search_state = GETPOST("search_state", 'alpha'); 71$search_country = GETPOST("search_country", 'int'); 72$search_type_thirdparty = GETPOST("search_type_thirdparty", 'int'); 73$search_user = GETPOST('search_user', 'int'); 74$search_request_author = GETPOST('search_request_author', 'alpha'); 75$search_ht = GETPOST('search_ht', 'alpha'); 76$search_ttc = GETPOST('search_ttc', 'alpha'); 77$optioncss = GETPOST('optioncss', 'alpha'); 78$socid = GETPOST('socid', 'int'); 79$search_sale = GETPOST('search_sale', 'int'); 80$search_total_ht = GETPOST('search_total_ht', 'alpha'); 81$search_total_tva = GETPOST('search_total_tva', 'alpha'); 82$search_total_ttc = GETPOST('search_total_ttc', 'alpha'); 83$search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha'); 84$search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha'); 85$search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha'); 86$search_multicurrency_montant_tva = GETPOST('search_multicurrency_montant_tva', 'alpha'); 87$search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha'); 88$optioncss = GETPOST('optioncss', 'alpha'); 89$search_billed = GETPOST('search_billed', 'int'); 90$search_project_ref = GETPOST('search_project_ref', 'alpha'); 91$search_btn = GETPOST('button_search', 'alpha'); 92$search_remove_btn = GETPOST('button_removefilter', 'alpha'); 93 94if (is_array(GETPOST('search_status', 'none'))) { // 'none' because we want to know type before sanitizing 95 $search_status = join(',', GETPOST('search_status', 'array:intcomma')); 96} else { 97 $search_status = (GETPOST('search_status', 'intcomma') != '' ? GETPOST('search_status', 'intcomma') : GETPOST('statut', 'intcomma')); 98} 99 100// Security check 101$orderid = GETPOST('orderid', 'int'); 102if ($user->socid) { 103 $socid = $user->socid; 104} 105$result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande'); 106 107$diroutputmassaction = $conf->fournisseur->commande->dir_output.'/temp/massgeneration/'.$user->id; 108 109$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; 110$sortfield = GETPOST("sortfield", 'alpha'); 111$sortorder = GETPOST("sortorder", 'alpha'); 112$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); 113if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) { 114 $page = 0; 115} // If $page is not defined, or '' or -1 116$offset = $limit * $page; 117$pageprev = $page - 1; 118$pagenext = $page + 1; 119if (!$sortfield) { 120 $sortfield = 'cf.ref'; 121} 122if (!$sortorder) { 123 $sortorder = 'DESC'; 124} 125 126if ($search_status == '') { 127 $search_status = -1; 128} 129 130// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context 131$object = new CommandeFournisseur($db); 132$hookmanager->initHooks(array('supplierorderlist')); 133$extrafields = new ExtraFields($db); 134 135// fetch optionals attributes and labels 136$extrafields->fetch_name_optionals_label($object->table_element); 137 138$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); 139 140// List of fields to search into when doing a "search in all" 141$fieldstosearchall = array( 142 'cf.ref'=>'Ref', 143 'cf.ref_supplier'=>'RefOrderSupplier', 144 'pd.description'=>'Description', 145 's.nom'=>"ThirdParty", 146 's.name_alias'=>"AliasNameShort", 147 's.zip'=>"Zip", 148 's.town'=>"Town", 149 'cf.note_public'=>'NotePublic', 150); 151if (empty($user->socid)) { 152 $fieldstosearchall["cf.note_private"] = "NotePrivate"; 153} 154 155$checkedtypetiers = 0; 156$arrayfields = array( 157 'cf.ref'=>array('label'=>"Ref", 'checked'=>1), 158 'cf.ref_supplier'=>array('label'=>"RefOrderSupplierShort", 'checked'=>1, 'enabled'=>1), 159 'p.project_ref'=>array('label'=>"ProjectRef", 'checked'=>0, 'enabled'=>1), 160 'u.login'=>array('label'=>"AuthorRequest", 'checked'=>1), 161 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1), 162 's.town'=>array('label'=>"Town", 'checked'=>1), 163 's.zip'=>array('label'=>"Zip", 'checked'=>1), 164 'state.nom'=>array('label'=>"StateShort", 'checked'=>0), 165 'country.code_iso'=>array('label'=>"Country", 'checked'=>0), 166 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers), 167 'cf.date_commande'=>array('label'=>"OrderDateShort", 'checked'=>1), 168 'cf.date_livraison'=>array('label'=>"DateDeliveryPlanned", 'checked'=>1, 'enabled'=>empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)), 169 'cf.total_ht'=>array('label'=>"AmountHT", 'checked'=>1), 170 'cf.total_tva'=>array('label'=>"AmountVAT", 'checked'=>0), 171 'cf.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0), 172 'cf.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 173 'cf.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 174 'cf.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 175 'cf.multicurrency_total_tva'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 176 'cf.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)), 177 'cf.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500), 178 'cf.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500), 179 'cf.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000), 180 'cf.billed'=>array('label'=>"Billed", 'checked'=>1, 'position'=>1000, 'enabled'=>1) 181); 182// Extra fields 183include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php'; 184 185$object->fields = dol_sort_array($object->fields, 'position'); 186$arrayfields = dol_sort_array($arrayfields, 'position'); 187 188$error = 0; 189 190 191/* 192 * Actions 193 */ 194 195if (GETPOST('cancel', 'alpha')) { 196 $action = 'list'; $massaction = ''; 197} 198if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createsupplierbills') { 199 $massaction = ''; 200} 201 202$parameters = array('socid'=>$socid); 203$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks 204if ($reshook < 0) { 205 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); 206} 207 208if (empty($reshook)) { 209 // Selection of new fields 210 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; 211 212 // Purge search criteria 213 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 214 $search_categ = ''; 215 $search_user = ''; 216 $search_sale = ''; 217 $search_product_category = ''; 218 $search_ref = ''; 219 $search_refsupp = ''; 220 $search_company = ''; 221 $search_town = ''; 222 $search_zip = ""; 223 $search_state = ""; 224 $search_type = ''; 225 $search_country = ''; 226 $search_type_thirdparty = ''; 227 $search_request_author = ''; 228 $search_total_ht = ''; 229 $search_total_tva = ''; 230 $search_total_ttc = ''; 231 $search_multicurrency_code = ''; 232 $search_multicurrency_tx = ''; 233 $search_multicurrency_montant_ht = ''; 234 $search_multicurrency_montant_tva = ''; 235 $search_multicurrency_montant_ttc = ''; 236 $search_project_ref = ''; 237 $search_status = -1; 238 $search_orderyear = ''; 239 $search_ordermonth = ''; 240 $search_orderday = ''; 241 $search_deliveryday = ''; 242 $search_deliverymonth = ''; 243 $search_deliveryyear = ''; 244 $billed = ''; 245 $search_billed = ''; 246 $toselect = ''; 247 $search_array_options = array(); 248 } 249 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') 250 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { 251 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation 252 } 253 254 // Mass actions 255 $objectclass = 'CommandeFournisseur'; 256 $objectlabel = 'SupplierOrders'; 257 $permissiontoread = $user->rights->fournisseur->commande->lire; 258 $permissiontodelete = $user->rights->fournisseur->commande->supprimer; 259 $uploaddir = $conf->fournisseur->commande->dir_output; 260 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; 261 262 // Mass action to generate vendor bills 263 if ($massaction == 'confirm_createsupplierbills') { 264 $orders = GETPOST('toselect', 'array'); 265 $createbills_onebythird = GETPOST('createbills_onebythird', 'int'); 266 $validate_invoices = GETPOST('validate_invoices', 'int'); 267 268 $TFact = array(); 269 $TFactThird = array(); 270 271 $nb_bills_created = 0; 272 $lastid = 0; 273 $lastref = ''; 274 275 $db->begin(); 276 277 foreach ($orders as $id_order) { 278 $cmd = new CommandeFournisseur($db); 279 if ($cmd->fetch($id_order) <= 0) { 280 continue; 281 } 282 283 $objecttmp = new FactureFournisseur($db); 284 if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) { 285 $objecttmp = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. 286 } else { 287 $objecttmp->socid = $cmd->socid; 288 $objecttmp->type = $objecttmp::TYPE_STANDARD; 289 $objecttmp->cond_reglement_id = $cmd->cond_reglement_id; 290 $objecttmp->mode_reglement_id = $cmd->mode_reglement_id; 291 $objecttmp->fk_project = $cmd->fk_project; 292 $objecttmp->multicurrency_code = $cmd->multicurrency_code; 293 if (empty($createbills_onebythird)) { 294 $objecttmp->ref_client = $cmd->ref_client; 295 } 296 297 $datefacture = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); 298 if (empty($datefacture)) { 299 $datefacture = dol_now(); 300 } 301 302 $objecttmp->date = $datefacture; 303 $objecttmp->origin = 'order_supplier'; 304 $objecttmp->origin_id = $id_order; 305 306 $res = $objecttmp->create($user); 307 308 if ($res > 0) { 309 $nb_bills_created++; 310 $lastref = $objecttmp->ref; 311 $lastid = $objecttmp->id; 312 } 313 } 314 315 if ($objecttmp->id > 0) { 316 $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; 317 $sql .= "fk_source"; 318 $sql .= ", sourcetype"; 319 $sql .= ", fk_target"; 320 $sql .= ", targettype"; 321 $sql .= ") VALUES ("; 322 $sql .= $id_order; 323 $sql .= ", '".$db->escape($objecttmp->origin)."'"; 324 $sql .= ", ".$objecttmp->id; 325 $sql .= ", '".$db->escape($objecttmp->element)."'"; 326 $sql .= ")"; 327 328 if (!$db->query($sql)) { 329 $erorr++; 330 } 331 332 if (!$error) { 333 $lines = $cmd->lines; 334 if (empty($lines) && method_exists($cmd, 'fetch_lines')) { 335 $cmd->fetch_lines(); 336 $lines = $cmd->lines; 337 } 338 339 $fk_parent_line = 0; 340 $num = count($lines); 341 342 for ($i = 0; $i < $num; $i++) { 343 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle); 344 if ($lines[$i]->subprice < 0) { 345 // Negative line, we create a discount line 346 $discount = new DiscountAbsolute($db); 347 $discount->fk_soc = $objecttmp->socid; 348 $discount->amount_ht = abs($lines[$i]->total_ht); 349 $discount->amount_tva = abs($lines[$i]->total_tva); 350 $discount->amount_ttc = abs($lines[$i]->total_ttc); 351 $discount->tva_tx = $lines[$i]->tva_tx; 352 $discount->fk_user = $user->id; 353 $discount->description = $desc; 354 $discountid = $discount->create($user); 355 if ($discountid > 0) { 356 $result = $objecttmp->insert_discount($discountid); 357 //$result=$discount->link_to_invoice($lineid,$id); 358 } else { 359 setEventMessages($discount->error, $discount->errors, 'errors'); 360 $error++; 361 break; 362 } 363 } else { 364 // Positive line 365 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0); 366 // Date start 367 $date_start = false; 368 if ($lines[$i]->date_debut_prevue) { 369 $date_start = $lines[$i]->date_debut_prevue; 370 } 371 if ($lines[$i]->date_debut_reel) { 372 $date_start = $lines[$i]->date_debut_reel; 373 } 374 if ($lines[$i]->date_start) { 375 $date_start = $lines[$i]->date_start; 376 } 377 //Date end 378 $date_end = false; 379 if ($lines[$i]->date_fin_prevue) { 380 $date_end = $lines[$i]->date_fin_prevue; 381 } 382 if ($lines[$i]->date_fin_reel) { 383 $date_end = $lines[$i]->date_fin_reel; 384 } 385 if ($lines[$i]->date_end) { 386 $date_end = $lines[$i]->date_end; 387 } 388 // Reset fk_parent_line for no child products and special product 389 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) { 390 $fk_parent_line = 0; 391 } 392 $result = $objecttmp->addline( 393 $desc, 394 $lines[$i]->subprice, 395 $lines[$i]->tva_tx, 396 $lines[$i]->localtax1_tx, 397 $lines[$i]->localtax2_tx, 398 $lines[$i]->qty, 399 $lines[$i]->fk_product, 400 $lines[$i]->remise_percent, 401 $date_start, 402 $date_end, 403 0, 404 $lines[$i]->info_bits, 405 'HT', 406 $product_type, 407 $lines[$i]->rang, 408 false, 409 $lines[$i]->array_options, 410 $lines[$i]->fk_unit, 411 $objecttmp->origin_id, 412 $lines[$i]->pa_ht, 413 $lines[$i]->ref_supplier, 414 $lines[$i]->special_code, 415 $fk_parent_line 416 ); 417 if ($result > 0) { 418 $lineid = $result; 419 } else { 420 $lineid = 0; 421 $error++; 422 break; 423 } 424 // Defined the new fk_parent_line 425 if ($result > 0 && $lines[$i]->product_type == 9) { 426 $fk_parent_line = $result; 427 } 428 } 429 } 430 } 431 } 432 433 $cmd->classifyBilled($user); // TODO Move this in workflow like done for customer orders 434 435 if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) { 436 $TFactThird[$cmd->socid] = $objecttmp; 437 } else { 438 $TFact[$objecttmp->id] = $objecttmp; 439 } 440 } 441 442 // Build doc with all invoices 443 $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird; 444 $toselect = array(); 445 446 if (!$error && $validate_invoices) { 447 $massaction = $action = 'builddoc'; 448 449 foreach ($TAllFact as &$objecttmp) { 450 $objecttmp->validate($user); 451 if ($result <= 0) { 452 $error++; 453 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); 454 break; 455 } 456 457 $id = $objecttmp->id; // For builddoc action 458 459 // Fac builddoc 460 $donotredirect = 1; 461 $upload_dir = $conf->fournisseur->facture->dir_output; 462 $permissiontoadd = ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer); 463 //include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; 464 } 465 466 $massaction = $action = 'confirm_createsupplierbills'; 467 } 468 469 if (!$error) { 470 $db->commit(); 471 472 if ($nb_bills_created == 1) { 473 $texttoshow = $langs->trans('BillXCreated', '{s1}'); 474 $texttoshow = str_replace('{s1}', '<a href="'.DOL_URL_ROOT.'/fourn/facture/card.php?id='.urlencode($lastid).'">'.$lastref.'</a>', $texttoshow); 475 setEventMessages($texttoshow, null, 'mesgs'); 476 } else { 477 setEventMessages($langs->trans('BillCreated', $nb_bills_created), null, 'mesgs'); 478 } 479 480 // Make a redirect to avoid to bill twice if we make a refresh or back 481 $param = ''; 482 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { 483 $param .= '&contextpage='.urlencode($contextpage); 484 } 485 if ($limit > 0 && $limit != $conf->liste_limit) { 486 $param .= '&limit='.urlencode($limit); 487 } 488 if ($sall) { 489 $param .= '&sall='.urlencode($sall); 490 } 491 if ($socid > 0) { 492 $param .= '&socid='.urlencode($socid); 493 } 494 if ($search_status != '') { 495 $param .= '&search_status='.urlencode($search_status); 496 } 497 if ($search_orderday) { 498 $param .= '&search_orderday='.urlencode($search_orderday); 499 } 500 if ($search_ordermonth) { 501 $param .= '&search_ordermonth='.urlencode($search_ordermonth); 502 } 503 if ($search_orderyear) { 504 $param .= '&search_orderyear='.urlencode($search_orderyear); 505 } 506 if ($search_deliveryday) { 507 $param .= '&search_deliveryday='.urlencode($search_deliveryday); 508 } 509 if ($search_deliverymonth) { 510 $param .= '&search_deliverymonth='.urlencode($search_deliverymonth); 511 } 512 if ($search_deliveryyear) { 513 $param .= '&search_deliveryyear='.urlencode($search_deliveryyear); 514 } 515 if ($search_ref) { 516 $param .= '&search_ref='.urlencode($search_ref); 517 } 518 if ($search_company) { 519 $param .= '&search_company='.urlencode($search_company); 520 } 521 //if ($search_ref_customer) $param .= '&search_ref_customer='.urlencode($search_ref_customer); 522 if ($search_user > 0) { 523 $param .= '&search_user='.urlencode($search_user); 524 } 525 if ($search_sale > 0) { 526 $param .= '&search_sale='.urlencode($search_sale); 527 } 528 if ($search_total_ht != '') { 529 $param .= '&search_total_ht='.urlencode($search_total_ht); 530 } 531 if ($search_total_tva != '') { 532 $param .= '&search_total_tva='.urlencode($search_total_tva); 533 } 534 if ($search_total_ttc != '') { 535 $param .= '&search_total_ttc='.urlencode($search_total_ttc); 536 } 537 if ($search_project_ref >= 0) { 538 $param .= "&search_project_ref=".urlencode($search_project_ref); 539 } 540 if ($show_files) { 541 $param .= '&show_files='.urlencode($show_files); 542 } 543 if ($optioncss != '') { 544 $param .= '&optioncss='.urlencode($optioncss); 545 } 546 if ($billed != '') { 547 $param .= '&billed='.urlencode($billed); 548 } 549 550 header("Location: ".$_SERVER['PHP_SELF'].'?'.$param); 551 exit; 552 } else { 553 $db->rollback(); 554 $action = 'create'; 555 $_GET["origin"] = $_POST["origin"]; 556 $_GET["originid"] = $_POST["originid"]; 557 setEventMessages("Error", null, 'errors'); 558 $error++; 559 } 560 } 561} 562 563 564/* 565 * View 566 */ 567 568$now = dol_now(); 569 570$form = new Form($db); 571$thirdpartytmp = new Fournisseur($db); 572$commandestatic = new CommandeFournisseur($db); 573$formfile = new FormFile($db); 574$formorder = new FormOrder($db); 575$formother = new FormOther($db); 576$formcompany = new FormCompany($db); 577 578$title = $langs->trans("ListOfSupplierOrders"); 579if ($socid > 0) { 580 $fourn = new Fournisseur($db); 581 $fourn->fetch($socid); 582 $title .= ' - '.$fourn->name; 583} 584 585/*if ($search_status) 586{ 587 if ($search_status == '1,2') $title .= ' - '.$langs->trans("SuppliersOrdersToProcess"); 588 elseif ($search_status == '3,4') $title .= ' - '.$langs->trans("SuppliersOrdersAwaitingReception"); 589 elseif ($search_status == '1,2,3') $title .= ' - '.$langs->trans("StatusOrderToProcessShort"); 590 elseif ($search_status == '6,7') $title .= ' - '.$langs->trans("StatusOrderCanceled"); 591 elseif (is_numeric($search_status) && $search_status >= 0) $title .= ' - '.$commandestatic->LibStatut($search_status); 592}*/ 593if ($search_billed > 0) { 594 $title .= ' - '.$langs->trans("Billed"); 595} 596 597//$help_url="EN:Module_Customers_Orders|FR:Module_Commandes_Clients|ES:Módulo_Pedidos_de_clientes"; 598$help_url = ''; 599// llxHeader('',$title,$help_url); 600 601$sql = 'SELECT'; 602if ($sall || $search_product_category > 0 || $search_user > 0) { 603 $sql = 'SELECT DISTINCT'; 604} 605$sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, s.email,'; 606$sql .= " typent.code as typent_code,"; 607$sql .= " state.code_departement as state_code, state.nom as state_name,"; 608$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,"; 609$sql .= ' cf.fk_multicurrency, cf.multicurrency_code, cf.multicurrency_tx, cf.multicurrency_total_ht, cf.multicurrency_total_tva, cf.multicurrency_total_ttc,'; 610$sql .= ' cf.date_creation as date_creation, cf.tms as date_update,'; 611$sql .= ' cf.note_public, cf.note_private,'; 612$sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_title,"; 613$sql .= " u.firstname, u.lastname, u.photo, u.login, u.email as user_email, u.statut as user_status"; 614// Add fields from extrafields 615if (!empty($extrafields->attributes[$object->table_element]['label'])) { 616 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { 617 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); 618 } 619} 620// Add fields from hooks 621$parameters = array(); 622$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook 623$sql .= $hookmanager->resPrint; 624$sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; 625$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)"; 626$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)"; 627$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)"; 628$sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf"; 629if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { 630 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (cf.rowid = ef.fk_object)"; 631} 632if ($sall || $search_product_category > 0) { 633 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet as pd ON cf.rowid=pd.fk_commande'; 634} 635if ($search_product_category > 0) { 636 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; 637} 638$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON cf.fk_user_author = u.rowid"; 639$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = cf.fk_projet"; 640// We'll need this table joined to the select in order to filter by sale 641if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) { 642 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; 643} 644if ($search_user > 0) { 645 $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; 646 $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc"; 647} 648$parameters = array(); 649$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook 650$sql .= $hookmanager->resPrint; 651$sql .= ' WHERE cf.fk_soc = s.rowid'; 652$sql .= ' AND cf.entity IN ('.getEntity('supplier_order').')'; 653if ($socid > 0) { 654 $sql .= " AND s.rowid = ".((int) $socid); 655} 656if (!$user->rights->societe->client->voir && !$socid) { 657 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id); 658} 659if ($search_ref) { 660 $sql .= natural_search('cf.ref', $search_ref); 661} 662if ($search_refsupp) { 663 $sql .= natural_search("cf.ref_supplier", $search_refsupp); 664} 665if ($sall) { 666 $sql .= natural_search(array_keys($fieldstosearchall), $sall); 667} 668if ($search_company) { 669 $sql .= natural_search('s.nom', $search_company); 670} 671if ($search_request_author) { 672 $sql .= natural_search(array('u.lastname', 'u.firstname', 'u.login'), $search_request_author); 673} 674if ($search_billed != '' && $search_billed >= 0) { 675 $sql .= " AND cf.billed = ".((int) $search_billed); 676} 677if ($search_product_category > 0) { 678 $sql .= " AND cp.fk_categorie = ".((int) $search_product_category); 679} 680//Required triple check because statut=0 means draft filter 681if (GETPOST('statut', 'intcomma') !== '') { 682 $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($db->escape(GETPOST('statut', 'intcomma')))).")"; 683} 684if ($search_status != '' && $search_status != '-1') { 685 $sql .= " AND cf.fk_statut IN (".$db->sanitize($db->escape($search_status)).")"; 686} 687$sql .= dolSqlDateFilter("cf.date_commande", $search_orderday, $search_ordermonth, $search_orderyear); 688$sql .= dolSqlDateFilter("cf.date_livraison", $search_deliveryday, $search_deliverymonth, $search_deliveryyear); 689if ($search_town) { 690 $sql .= natural_search('s.town', $search_town); 691} 692if ($search_zip) { 693 $sql .= natural_search("s.zip", $search_zip); 694} 695if ($search_state) { 696 $sql .= natural_search("state.nom", $search_state); 697} 698if ($search_country) { 699 $sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')'; 700} 701if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) { 702 $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')'; 703} 704if ($search_company) { 705 $sql .= natural_search('s.nom', $search_company); 706} 707if ($search_sale > 0) { 708 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale); 709} 710if ($search_user > 0) { 711 $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='supplier_order' AND tc.source='internal' AND ec.element_id = cf.rowid AND ec.fk_socpeople = ".((int) $search_user); 712} 713if ($search_total_ht != '') { 714 $sql .= natural_search('cf.total_ht', $search_total_ht, 1); 715} 716if ($search_total_tva != '') { 717 $sql .= natural_search('cf.total_tva', $search_total_tva, 1); 718} 719if ($search_total_ttc != '') { 720 $sql .= natural_search('cf.total_ttc', $search_total_ttc, 1); 721} 722if ($search_multicurrency_code != '') { 723 $sql .= ' AND cf.multicurrency_code = "'.$db->escape($search_multicurrency_code).'"'; 724} 725if ($search_multicurrency_tx != '') { 726 $sql .= natural_search('cf.multicurrency_tx', $search_multicurrency_tx, 1); 727} 728if ($search_multicurrency_montant_ht != '') { 729 $sql .= natural_search('cf.multicurrency_total_ht', $search_multicurrency_montant_ht, 1); 730} 731if ($search_multicurrency_montant_tva != '') { 732 $sql .= natural_search('cf.multicurrency_total_tva', $search_multicurrency_montant_tva, 1); 733} 734if ($search_multicurrency_montant_ttc != '') { 735 $sql .= natural_search('cf.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1); 736} 737if ($search_project_ref != '') { 738 $sql .= natural_search("p.ref", $search_project_ref); 739} 740// Add where from extra fields 741include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; 742// Add where from hooks 743$parameters = array(); 744$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook 745$sql .= $hookmanager->resPrint; 746 747$sql .= $db->order($sortfield, $sortorder); 748 749// Count total nb of records 750$nbtotalofrecords = ''; 751if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { 752 $result = $db->query($sql); 753 $nbtotalofrecords = $db->num_rows($result); 754 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 755 $page = 0; 756 $offset = 0; 757 } 758} 759 760$sql .= $db->plimit($limit + 1, $offset); 761//print $sql; 762 763$resql = $db->query($sql); 764if ($resql) { 765 $num = $db->num_rows($resql); 766 767 $arrayofselected = is_array($toselect) ? $toselect : array(); 768 769 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) { 770 $obj = $db->fetch_object($resql); 771 $id = $obj->rowid; 772 header("Location: ".DOL_URL_ROOT.'/fourn/commande/card.php?id='.$id); 773 exit; 774 } 775 776 llxHeader('', $title, $help_url); 777 778 $param = ''; 779 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { 780 $param .= '&contextpage='.urlencode($contextpage); 781 } 782 if ($limit > 0 && $limit != $conf->liste_limit) { 783 $param .= '&limit='.urlencode($limit); 784 } 785 if ($sall) { 786 $param .= '&sall='.urlencode($sall); 787 } 788 if ($socid > 0) { 789 $param .= '&socid='.urlencode($socid); 790 } 791 if ($sall) { 792 $param .= "&search_all=".urlencode($sall); 793 } 794 if ($search_orderday) { 795 $param .= '&search_orderday='.urlencode($search_orderday); 796 } 797 if ($search_ordermonth) { 798 $param .= '&search_ordermonth='.urlencode($search_ordermonth); 799 } 800 if ($search_orderyear) { 801 $param .= '&search_orderyear='.urlencode($search_orderyear); 802 } 803 if ($search_deliveryday) { 804 $param .= '&search_deliveryday='.urlencode($search_deliveryday); 805 } 806 if ($search_deliverymonth) { 807 $param .= '&search_deliverymonth='.urlencode($search_deliverymonth); 808 } 809 if ($search_deliveryyear) { 810 $param .= '&search_deliveryyear='.urlencode($search_deliveryyear); 811 } 812 if ($search_ref) { 813 $param .= '&search_ref='.urlencode($search_ref); 814 } 815 if ($search_company) { 816 $param .= '&search_company='.urlencode($search_company); 817 } 818 if ($search_user > 0) { 819 $param .= '&search_user='.urlencode($search_user); 820 } 821 if ($search_request_author) { 822 $param .= '&search_request_author='.urlencode($search_request_author); 823 } 824 if ($search_sale > 0) { 825 $param .= '&search_sale='.urlencode($search_sale); 826 } 827 if ($search_total_ht != '') { 828 $param .= '&search_total_ht='.urlencode($search_total_ht); 829 } 830 if ($search_total_ttc != '') { 831 $param .= "&search_total_ttc=".urlencode($search_total_ttc); 832 } 833 if ($search_multicurrency_code != '') { 834 $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code); 835 } 836 if ($search_multicurrency_tx != '') { 837 $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx); 838 } 839 if ($search_multicurrency_montant_ht != '') { 840 $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht); 841 } 842 if ($search_multicurrency_montant_tva != '') { 843 $param .= '&search_multicurrency_montant_tva='.urlencode($search_multicurrency_montant_tva); 844 } 845 if ($search_multicurrency_montant_ttc != '') { 846 $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc); 847 } 848 if ($search_refsupp) { 849 $param .= "&search_refsupp=".urlencode($search_refsupp); 850 } 851 if ($search_status != '' && $search_status != '-1') { 852 $param .= "&search_status=".urlencode($search_status); 853 } 854 if ($search_project_ref >= 0) { 855 $param .= "&search_project_ref=".urlencode($search_project_ref); 856 } 857 if ($search_billed != '') { 858 $param .= "&search_billed=".urlencode($search_billed); 859 } 860 if ($show_files) { 861 $param .= '&show_files='.urlencode($show_files); 862 } 863 if ($optioncss != '') { 864 $param .= '&optioncss='.urlencode($optioncss); 865 } 866 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) { 867 $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty); 868 } 869 870 // Add $param from extra fields 871 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; 872 873 $parameters = array(); 874 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook 875 $param .= $hookmanager->resPrint; 876 877 // List of mass actions available 878 $arrayofmassactions = array( 879 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"), 880 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"), 881 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"), 882 ); 883 if ($user->rights->fournisseur->facture->creer || $user->rights->supplier_invoice->creer) { 884 $arrayofmassactions['createbills'] = img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("CreateInvoiceForThisSupplier"); 885 } 886 if ($user->rights->fournisseur->commande->supprimer) { 887 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete"); 888 } 889 if (in_array($massaction, array('presend', 'predelete', 'createbills'))) { 890 $arrayofmassactions = array(); 891 } 892 $massactionbutton = $form->selectMassAction('', $arrayofmassactions); 893 894 $url = DOL_URL_ROOT.'/fourn/commande/card.php?action=create'; 895 if ($socid > 0) { 896 $url .= '&socid='.((int) $socid); 897 $url .= '&backtopage='.urlencode(DOL_URL_ROOT.'/fourn/commande/list.php?socid='.((int) $socid)); 898 } 899 $newcardbutton = dolGetButtonTitle($langs->trans('NewSupplierOrderShort'), '', 'fa fa-plus-circle', $url, '', ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer)); 900 901 // Lines of title fields 902 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'; 903 if ($optioncss != '') { 904 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; 905 } 906 print '<input type="hidden" name="token" value="'.newToken().'">'; 907 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; 908 print '<input type="hidden" name="action" value="list">'; 909 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">'; 910 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">'; 911 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">'; 912 print '<input type="hidden" name="socid" value="'.$socid.'">'; 913 914 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_order', 0, $newcardbutton, '', $limit, 0, 0, 1); 915 916 $topicmail = "SendOrderRef"; 917 $modelmail = "order_supplier_send"; 918 $objecttmp = new CommandeFournisseur($db); 919 $trackid = 'sord'.$object->id; 920 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; 921 922 if ($massaction == 'createbills') { 923 //var_dump($_REQUEST); 924 print '<input type="hidden" name="massaction" value="confirm_createsupplierbills">'; 925 926 print '<table class="noborder" width="100%" >'; 927 print '<tr>'; 928 print '<td class="titlefield">'; 929 print $langs->trans('DateInvoice'); 930 print '</td>'; 931 print '<td>'; 932 print $form->selectDate('', '', '', '', '', '', 1, 1); 933 print '</td>'; 934 print '</tr>'; 935 print '<tr>'; 936 print '<td>'; 937 print $langs->trans('CreateOneBillByThird'); 938 print '</td>'; 939 print '<td>'; 940 print $form->selectyesno('createbills_onebythird', '', 1); 941 print '</td>'; 942 print '</tr>'; 943 print '<tr>'; 944 print '<td>'; 945 print $langs->trans('ValidateInvoices'); 946 print '</td>'; 947 print '<td>'; 948 print $form->selectyesno('validate_invoices', 1, 1); 949 print '</td>'; 950 print '</tr>'; 951 print '</table>'; 952 953 print '<br>'; 954 print '<div class="center">'; 955 print '<input type="submit" class="button" id="createbills" name="createbills" value="'.$langs->trans('CreateInvoiceForThisCustomer').'"> '; 956 print '<input type="submit" class="button button-cancel" id="cancel" name="cancel" value="'.$langs->trans("Cancel").'">'; 957 print '</div>'; 958 print '<br>'; 959 } 960 961 if ($sall) { 962 foreach ($fieldstosearchall as $key => $val) { 963 $fieldstosearchall[$key] = $langs->trans($val); 964 } 965 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>'; 966 } 967 968 $moreforfilter = ''; 969 970 // If the user can view prospects other than his' 971 if ($user->rights->societe->client->voir || $socid) { 972 $langs->load("commercial"); 973 $moreforfilter .= '<div class="divsearchfield">'; 974 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative'); 975 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250'); 976 $moreforfilter .= '</div>'; 977 } 978 // If the user can view other users 979 if ($user->rights->user->user->lire) { 980 $moreforfilter .= '<div class="divsearchfield">'; 981 $tmptitle = $langs->trans('LinkedToSpecificUsers'); 982 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250'); 983 $moreforfilter .= '</div>'; 984 } 985 // If the user can view prospects other than his' 986 if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) { 987 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; 988 $moreforfilter .= '<div class="divsearchfield">'; 989 $tmptitle = $langs->trans('IncludingProductWithTag'); 990 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); 991 $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', 1); 992 $moreforfilter .= '</div>'; 993 } 994 $parameters = array(); 995 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook 996 if (empty($reshook)) { 997 $moreforfilter .= $hookmanager->resPrint; 998 } else { 999 $moreforfilter = $hookmanager->resPrint; 1000 } 1001 1002 if (!empty($moreforfilter)) { 1003 print '<div class="liste_titre liste_titre_bydiv centpercent">'; 1004 print $moreforfilter; 1005 print '</div>'; 1006 } 1007 1008 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; 1009 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields 1010 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); 1011 1012 if (GETPOST('autoselectall', 'int')) { 1013 $selectedfields .= '<script>'; 1014 $selectedfields .= ' $(document).ready(function() {'; 1015 $selectedfields .= ' console.log("Autoclick on checkforselects");'; 1016 $selectedfields .= ' $("#checkforselects").click();'; 1017 $selectedfields .= ' $("#massaction").val("createbills").change();'; 1018 $selectedfields .= ' });'; 1019 $selectedfields .= '</script>'; 1020 } 1021 1022 print '<div class="div-table-responsive">'; 1023 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n"; 1024 1025 print '<tr class="liste_titre_filter">'; 1026 // Ref 1027 if (!empty($arrayfields['cf.ref']['checked'])) { 1028 print '<td class="liste_titre"><input size="8" type="text" class="flat maxwidth75" name="search_ref" value="'.$search_ref.'"></td>'; 1029 } 1030 // Ref customer 1031 if (!empty($arrayfields['cf.ref_supplier']['checked'])) { 1032 print '<td class="liste_titre"><input type="text" class="flat maxwidth75" name="search_refsupp" value="'.$search_refsupp.'"></td>'; 1033 } 1034 // Project ref 1035 if (!empty($arrayfields['p.project_ref']['checked'])) { 1036 print '<td class="liste_titre"><input type="text" class="flat maxwidth100" name="search_project_ref" value="'.$search_project_ref.'"></td>'; 1037 } 1038 // Request author 1039 if (!empty($arrayfields['u.login']['checked'])) { 1040 print '<td class="liste_titre">'; 1041 print '<input type="text" class="flat" size="6" name="search_request_author" value="'.$search_request_author.'">'; 1042 print '</td>'; 1043 } 1044 // Thirpdarty 1045 if (!empty($arrayfields['s.nom']['checked'])) { 1046 print '<td class="liste_titre"><input type="text" size="6" class="flat" name="search_company" value="'.$search_company.'"></td>'; 1047 } 1048 // Town 1049 if (!empty($arrayfields['s.town']['checked'])) { 1050 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.$search_town.'"></td>'; 1051 } 1052 // Zip 1053 if (!empty($arrayfields['s.zip']['checked'])) { 1054 print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.$search_zip.'"></td>'; 1055 } 1056 // State 1057 if (!empty($arrayfields['state.nom']['checked'])) { 1058 print '<td class="liste_titre">'; 1059 print '<input class="flat maxwidth50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">'; 1060 print '</td>'; 1061 } 1062 // Country 1063 if (!empty($arrayfields['country.code_iso']['checked'])) { 1064 print '<td class="liste_titre center">'; 1065 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100'); 1066 print '</td>'; 1067 } 1068 // Company type 1069 if (!empty($arrayfields['typent.code']['checked'])) { 1070 print '<td class="liste_titre maxwidthonsmartphone center">'; 1071 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); 1072 print '</td>'; 1073 } 1074 // Date order 1075 if (!empty($arrayfields['cf.date_commande']['checked'])) { 1076 print '<td class="liste_titre nowraponall center">'; 1077 if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { 1078 print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_orderday" value="'.$search_orderday.'">'; 1079 } 1080 print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_ordermonth" value="'.$search_ordermonth.'">'; 1081 $formother->select_year($search_orderyear ? $search_orderyear : -1, 'search_orderyear', 1, 20, 5); 1082 print '</td>'; 1083 } 1084 // Date delivery 1085 if (!empty($arrayfields['cf.date_livraison']['checked'])) { 1086 print '<td class="liste_titre nowraponall center">'; 1087 if (!empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) { 1088 print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_deliveryday" value="'.$search_deliveryday.'">'; 1089 } 1090 print '<input class="flat width25 valignmiddle" type="text" maxlength="2" name="search_deliverymonth" value="'.$search_deliverymonth.'">'; 1091 $formother->select_year($search_deliveryyear ? $search_deliveryyear : -1, 'search_deliveryyear', 1, 20, 5); 1092 print '</td>'; 1093 } 1094 if (!empty($arrayfields['cf.total_ht']['checked'])) { 1095 // Amount 1096 print '<td class="liste_titre right">'; 1097 print '<input class="flat" type="text" size="5" name="search_total_ht" value="'.$search_total_ht.'">'; 1098 print '</td>'; 1099 } 1100 if (!empty($arrayfields['cf.total_tva']['checked'])) { 1101 // Amount 1102 print '<td class="liste_titre right">'; 1103 print '<input class="flat" type="text" size="5" name="search_total_tva" value="'.$search_total_tva.'">'; 1104 print '</td>'; 1105 } 1106 if (!empty($arrayfields['cf.total_ttc']['checked'])) { 1107 // Amount 1108 print '<td class="liste_titre right">'; 1109 print '<input class="flat" type="text" size="5" name="search_total_ttc" value="'.$search_total_ttc.'">'; 1110 print '</td>'; 1111 } 1112 if (!empty($arrayfields['cf.multicurrency_code']['checked'])) { 1113 // Currency 1114 print '<td class="liste_titre">'; 1115 print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1); 1116 print '</td>'; 1117 } 1118 if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) { 1119 // Currency rate 1120 print '<td class="liste_titre">'; 1121 print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">'; 1122 print '</td>'; 1123 } 1124 if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) { 1125 // Amount 1126 print '<td class="liste_titre right">'; 1127 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">'; 1128 print '</td>'; 1129 } 1130 if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) { 1131 // Amount 1132 print '<td class="liste_titre right">'; 1133 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_tva" value="'.dol_escape_htmltag($search_multicurrency_montant_tva).'">'; 1134 print '</td>'; 1135 } 1136 if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) { 1137 // Amount 1138 print '<td class="liste_titre right">'; 1139 print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">'; 1140 print '</td>'; 1141 } 1142 // Extra fields 1143 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php'; 1144 1145 // Fields from hook 1146 $parameters = array('arrayfields'=>$arrayfields); 1147 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook 1148 print $hookmanager->resPrint; 1149 // Date creation 1150 if (!empty($arrayfields['cf.datec']['checked'])) { 1151 print '<td class="liste_titre">'; 1152 print '</td>'; 1153 } 1154 // Date modification 1155 if (!empty($arrayfields['cf.tms']['checked'])) { 1156 print '<td class="liste_titre">'; 1157 print '</td>'; 1158 } 1159 // Status 1160 if (!empty($arrayfields['cf.fk_statut']['checked'])) { 1161 print '<td class="liste_titre right">'; 1162 $formorder->selectSupplierOrderStatus($search_status, 1, 'search_status'); 1163 print '</td>'; 1164 } 1165 // Status billed 1166 if (!empty($arrayfields['cf.billed']['checked'])) { 1167 print '<td class="liste_titre center">'; 1168 print $form->selectyesno('search_billed', $search_billed, 1, 0, 1, 1); 1169 print '</td>'; 1170 } 1171 // Action column 1172 print '<td class="liste_titre middle">'; 1173 $searchpicto = $form->showFilterButtons(); 1174 print $searchpicto; 1175 print '</td>'; 1176 1177 print "</tr>\n"; 1178 1179 // Fields title 1180 print '<tr class="liste_titre">'; 1181 if (!empty($arrayfields['cf.ref']['checked'])) { 1182 print_liste_field_titre($arrayfields['cf.ref']['label'], $_SERVER["PHP_SELF"], "cf.ref", "", $param, '', $sortfield, $sortorder); 1183 } 1184 if (!empty($arrayfields['cf.ref_supplier']['checked'])) { 1185 print_liste_field_titre($arrayfields['cf.ref_supplier']['label'], $_SERVER["PHP_SELF"], "cf.ref_supplier", "", $param, '', $sortfield, $sortorder, 'tdoverflowmax100imp '); 1186 } 1187 if (!empty($arrayfields['p.project_ref']['checked'])) { 1188 print_liste_field_titre($arrayfields['p.project_ref']['label'], $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder); 1189 } 1190 if (!empty($arrayfields['u.login']['checked'])) { 1191 print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], "u.login", "", $param, '', $sortfield, $sortorder); 1192 } 1193 if (!empty($arrayfields['s.nom']['checked'])) { 1194 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder); 1195 } 1196 if (!empty($arrayfields['s.town']['checked'])) { 1197 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder); 1198 } 1199 if (!empty($arrayfields['s.zip']['checked'])) { 1200 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder); 1201 } 1202 if (!empty($arrayfields['state.nom']['checked'])) { 1203 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder); 1204 } 1205 if (!empty($arrayfields['country.code_iso']['checked'])) { 1206 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center '); 1207 } 1208 if (!empty($arrayfields['typent.code']['checked'])) { 1209 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center '); 1210 } 1211 if (!empty($arrayfields['cf.fk_author']['checked'])) { 1212 print_liste_field_titre($arrayfields['cf.fk_author']['label'], $_SERVER["PHP_SELF"], "cf.fk_author", "", $param, '', $sortfield, $sortorder); 1213 } 1214 if (!empty($arrayfields['cf.date_commande']['checked'])) { 1215 print_liste_field_titre($arrayfields['cf.date_commande']['label'], $_SERVER["PHP_SELF"], "cf.date_commande", "", $param, '', $sortfield, $sortorder, 'center '); 1216 } 1217 if (!empty($arrayfields['cf.date_livraison']['checked'])) { 1218 print_liste_field_titre($arrayfields['cf.date_livraison']['label'], $_SERVER["PHP_SELF"], 'cf.date_livraison', '', $param, '', $sortfield, $sortorder, 'center '); 1219 } 1220 if (!empty($arrayfields['cf.total_ht']['checked'])) { 1221 print_liste_field_titre($arrayfields['cf.total_ht']['label'], $_SERVER["PHP_SELF"], "cf.total_ht", "", $param, '', $sortfield, $sortorder, 'right '); 1222 } 1223 if (!empty($arrayfields['cf.total_tva']['checked'])) { 1224 print_liste_field_titre($arrayfields['cf.total_tva']['label'], $_SERVER["PHP_SELF"], "cf.total_tva", "", $param, '', $sortfield, $sortorder, 'right '); 1225 } 1226 if (!empty($arrayfields['cf.total_ttc']['checked'])) { 1227 print_liste_field_titre($arrayfields['cf.total_ttc']['label'], $_SERVER["PHP_SELF"], "cf.total_ttc", "", $param, '', $sortfield, $sortorder, 'right '); 1228 } 1229 if (!empty($arrayfields['cf.multicurrency_code']['checked'])) { 1230 print_liste_field_titre($arrayfields['cf.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_code', '', $param, '', $sortfield, $sortorder); 1231 } 1232 if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) { 1233 print_liste_field_titre($arrayfields['cf.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_tx', '', $param, '', $sortfield, $sortorder); 1234 } 1235 if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) { 1236 print_liste_field_titre($arrayfields['cf.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder); 1237 } 1238 if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) { 1239 print_liste_field_titre($arrayfields['cf.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder); 1240 } 1241 if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) { 1242 print_liste_field_titre($arrayfields['cf.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'cf.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder); 1243 } 1244 // Extra fields 1245 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; 1246 // Hook fields 1247 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); 1248 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook 1249 print $hookmanager->resPrint; 1250 if (!empty($arrayfields['cf.datec']['checked'])) { 1251 print_liste_field_titre($arrayfields['cf.datec']['label'], $_SERVER["PHP_SELF"], "cf.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap '); 1252 } 1253 if (!empty($arrayfields['cf.tms']['checked'])) { 1254 print_liste_field_titre($arrayfields['cf.tms']['label'], $_SERVER["PHP_SELF"], "cf.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); 1255 } 1256 if (!empty($arrayfields['cf.fk_statut']['checked'])) { 1257 print_liste_field_titre($arrayfields['cf.fk_statut']['label'], $_SERVER["PHP_SELF"], "cf.fk_statut", "", $param, '', $sortfield, $sortorder, 'right '); 1258 } 1259 if (!empty($arrayfields['cf.billed']['checked'])) { 1260 print_liste_field_titre($arrayfields['cf.billed']['label'], $_SERVER["PHP_SELF"], 'cf.billed', '', $param, '', $sortfield, $sortorder, 'center '); 1261 } 1262 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); 1263 print "</tr>\n"; 1264 1265 1266 $total = 0; 1267 $subtotal = 0; 1268 $productstat_cache = array(); 1269 1270 $userstatic = new User($db); 1271 $objectstatic = new CommandeFournisseur($db); 1272 $projectstatic = new Project($db); 1273 1274 $i = 0; 1275 $totalarray = array(); 1276 $totalarray['nbfield'] = 0; 1277 $totalarray['val'] = array(); 1278 $totalarray['val']['cf.total_ht'] = 0; 1279 $totalarray['val']['cf.total_ttc'] = 0; 1280 while ($i < min($num, $limit)) { 1281 $obj = $db->fetch_object($resql); 1282 1283 $notshippable = 0; 1284 $warning = 0; 1285 $text_info = ''; 1286 $text_warning = ''; 1287 $nbprod = 0; 1288 1289 $objectstatic->id = $obj->rowid; 1290 $objectstatic->ref = $obj->ref; 1291 $objectstatic->socid = $obj->socid; 1292 $objectstatic->ref_supplier = $obj->ref_supplier; 1293 $objectstatic->socid = $obj->socid; 1294 $objectstatic->total_ht = $obj->total_ht; 1295 $objectstatic->total_tva = $obj->total_tva; 1296 $objectstatic->total_ttc = $obj->total_ttc; 1297 $objectstatic->date_commande = $db->jdate($obj->date_commande); 1298 $objectstatic->delivery_date = $db->jdate($obj->date_livraison); 1299 $objectstatic->note_public = $obj->note_public; 1300 $objectstatic->note_private = $obj->note_private; 1301 $objectstatic->statut = $obj->fk_statut; 1302 1303 print '<tr class="oddeven">'; 1304 1305 // Ref 1306 if (!empty($arrayfields['cf.ref']['checked'])) { 1307 print '<td class="nowrap">'; 1308 1309 // Picto + Ref 1310 print $objectstatic->getNomUrl(1, '', 0, -1, 1); 1311 // Other picto tool 1312 $filename = dol_sanitizeFileName($obj->ref); 1313 $filedir = $conf->fournisseur->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref); 1314 print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir); 1315 1316 print '</td>'."\n"; 1317 if (!$i) { 1318 $totalarray['nbfield']++; 1319 } 1320 } 1321 // Ref Supplier 1322 if (!empty($arrayfields['cf.ref_supplier']['checked'])) { 1323 print '<td>'.$obj->ref_supplier.'</td>'."\n"; 1324 if (!$i) { 1325 $totalarray['nbfield']++; 1326 } 1327 } 1328 // Project 1329 if (!empty($arrayfields['p.project_ref']['checked'])) { 1330 $projectstatic->id = $obj->project_id; 1331 $projectstatic->ref = $obj->project_ref; 1332 $projectstatic->title = $obj->project_title; 1333 print '<td>'; 1334 if ($obj->project_id > 0) { 1335 print $projectstatic->getNomUrl(1); 1336 } 1337 print '</td>'; 1338 if (!$i) { 1339 $totalarray['nbfield']++; 1340 } 1341 } 1342 // Author 1343 $userstatic->id = $obj->fk_user_author; 1344 $userstatic->lastname = $obj->lastname; 1345 $userstatic->firstname = $obj->firstname; 1346 $userstatic->login = $obj->login; 1347 $userstatic->photo = $obj->photo; 1348 $userstatic->email = $obj->user_email; 1349 $userstatic->statut = $obj->user_status; 1350 if (!empty($arrayfields['u.login']['checked'])) { 1351 print '<td class="tdoverflowmax150">'; 1352 if ($userstatic->id) { 1353 print $userstatic->getNomUrl(1); 1354 } 1355 print "</td>"; 1356 if (!$i) { 1357 $totalarray['nbfield']++; 1358 } 1359 } 1360 // Thirdparty 1361 if (!empty($arrayfields['s.nom']['checked'])) { 1362 print '<td class="tdoverflowmax150">'; 1363 $thirdpartytmp->id = $obj->socid; 1364 $thirdpartytmp->name = $obj->name; 1365 $thirdpartytmp->email = $obj->email; 1366 print $thirdpartytmp->getNomUrl(1, 'supplier'); 1367 print '</td>'."\n"; 1368 if (!$i) { 1369 $totalarray['nbfield']++; 1370 } 1371 } 1372 // Town 1373 if (!empty($arrayfields['s.town']['checked'])) { 1374 print '<td>'; 1375 print $obj->town; 1376 print '</td>'; 1377 if (!$i) { 1378 $totalarray['nbfield']++; 1379 } 1380 } 1381 // Zip 1382 if (!empty($arrayfields['s.zip']['checked'])) { 1383 print '<td>'; 1384 print $obj->zip; 1385 print '</td>'; 1386 if (!$i) { 1387 $totalarray['nbfield']++; 1388 } 1389 } 1390 // State 1391 if (!empty($arrayfields['state.nom']['checked'])) { 1392 print "<td>".$obj->state_name."</td>\n"; 1393 if (!$i) { 1394 $totalarray['nbfield']++; 1395 } 1396 } 1397 // Country 1398 if (!empty($arrayfields['country.code_iso']['checked'])) { 1399 print '<td class="center">'; 1400 $tmparray = getCountry($obj->fk_pays, 'all'); 1401 print $tmparray['label']; 1402 print '</td>'; 1403 if (!$i) { 1404 $totalarray['nbfield']++; 1405 } 1406 } 1407 // Type ent 1408 if (!empty($arrayfields['typent.code']['checked'])) { 1409 print '<td class="center">'; 1410 if (empty($typenArray)) { 1411 $typenArray = $formcompany->typent_array(1); 1412 } 1413 print $typenArray[$obj->typent_code]; 1414 print '</td>'; 1415 if (!$i) { 1416 $totalarray['nbfield']++; 1417 } 1418 } 1419 1420 // Order date 1421 if (!empty($arrayfields['cf.date_commande']['checked'])) { 1422 print '<td class="center">'; 1423 print dol_print_date($db->jdate($obj->date_commande), 'day'); 1424 if ($objectstatic->statut != $objectstatic::STATUS_ORDERSENT && $objectstatic->statut != $objectstatic::STATUS_RECEIVED_PARTIALLY) { 1425 if ($objectstatic->hasDelay()) { 1426 print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning"); 1427 } 1428 } 1429 print '</td>'; 1430 if (!$i) { 1431 $totalarray['nbfield']++; 1432 } 1433 } 1434 // Plannned date of delivery 1435 if (!empty($arrayfields['cf.date_livraison']['checked'])) { 1436 print '<td class="center">'; 1437 print dol_print_date($db->jdate($obj->date_livraison), 'day'); 1438 if ($objectstatic->statut == $objectstatic::STATUS_ORDERSENT || $objectstatic->statut == $objectstatic::STATUS_RECEIVED_PARTIALLY) { 1439 if ($objectstatic->hasDelay()) { 1440 print ' '.img_picto($langs->trans("Late").' : '.$objectstatic->showDelay(), "warning"); 1441 } 1442 } 1443 print '</td>'; 1444 if (!$i) { 1445 $totalarray['nbfield']++; 1446 } 1447 } 1448 // Amount HT 1449 if (!empty($arrayfields['cf.total_ht']['checked'])) { 1450 print '<td class="right"><span class="amount">'.price($obj->total_ht)."</span></td>\n"; 1451 if (!$i) { 1452 $totalarray['nbfield']++; 1453 } 1454 if (!$i) { 1455 $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ht'; 1456 } 1457 $totalarray['val']['cf.total_ht'] += $obj->total_ht; 1458 } 1459 // Amount VAT 1460 if (!empty($arrayfields['cf.total_tva']['checked'])) { 1461 print '<td class="right"><span class="amount">'.price($obj->total_tva)."</span></td>\n"; 1462 if (!$i) { 1463 $totalarray['nbfield']++; 1464 } 1465 if (!$i) { 1466 $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_tva'; 1467 } 1468 $totalarray['val']['cf.total_tva'] += $obj->total_tva; 1469 } 1470 // Amount TTC 1471 if (!empty($arrayfields['cf.total_ttc']['checked'])) { 1472 print '<td class="right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n"; 1473 if (!$i) { 1474 $totalarray['nbfield']++; 1475 } 1476 if (!$i) { 1477 $totalarray['pos'][$totalarray['nbfield']] = 'cf.total_ttc'; 1478 } 1479 $totalarray['val']['cf.total_ttc'] += $obj->total_ttc; 1480 } 1481 1482 // Currency 1483 if (!empty($arrayfields['cf.multicurrency_code']['checked'])) { 1484 print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n"; 1485 if (!$i) { 1486 $totalarray['nbfield']++; 1487 } 1488 } 1489 1490 // Currency rate 1491 if (!empty($arrayfields['cf.multicurrency_tx']['checked'])) { 1492 print '<td class="nowrap">'; 1493 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code); 1494 print "</td>\n"; 1495 if (!$i) { 1496 $totalarray['nbfield']++; 1497 } 1498 } 1499 // Amount HT 1500 if (!empty($arrayfields['cf.multicurrency_total_ht']['checked'])) { 1501 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n"; 1502 if (!$i) { 1503 $totalarray['nbfield']++; 1504 } 1505 } 1506 // Amount VAT 1507 if (!empty($arrayfields['cf.multicurrency_total_tva']['checked'])) { 1508 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n"; 1509 if (!$i) { 1510 $totalarray['nbfield']++; 1511 } 1512 } 1513 // Amount TTC 1514 if (!empty($arrayfields['cf.multicurrency_total_ttc']['checked'])) { 1515 print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n"; 1516 if (!$i) { 1517 $totalarray['nbfield']++; 1518 } 1519 } 1520 1521 // Extra fields 1522 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; 1523 // Fields from hook 1524 $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray); 1525 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook 1526 print $hookmanager->resPrint; 1527 // Date creation 1528 if (!empty($arrayfields['cf.datec']['checked'])) { 1529 print '<td class="center nowrap">'; 1530 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser'); 1531 print '</td>'; 1532 if (!$i) { 1533 $totalarray['nbfield']++; 1534 } 1535 } 1536 // Date modification 1537 if (!empty($arrayfields['cf.tms']['checked'])) { 1538 print '<td class="center nowrap">'; 1539 print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser'); 1540 print '</td>'; 1541 if (!$i) { 1542 $totalarray['nbfield']++; 1543 } 1544 } 1545 // Status 1546 if (!empty($arrayfields['cf.fk_statut']['checked'])) { 1547 print '<td class="right nowrap">'.$objectstatic->LibStatut($obj->fk_statut, 5, $obj->billed).'</td>'; 1548 if (!$i) { 1549 $totalarray['nbfield']++; 1550 } 1551 } 1552 // Billed 1553 if (!empty($arrayfields['cf.billed']['checked'])) { 1554 print '<td class="center">'.yn($obj->billed).'</td>'; 1555 if (!$i) { 1556 $totalarray['nbfield']++; 1557 } 1558 } 1559 1560 // Action column 1561 print '<td class="nowrap center">'; 1562 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined 1563 $selected = 0; 1564 if (in_array($obj->rowid, $arrayofselected)) { 1565 $selected = 1; 1566 } 1567 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>'; 1568 } 1569 print '</td>'; 1570 if (!$i) { 1571 $totalarray['nbfield']++; 1572 } 1573 1574 print "</tr>\n"; 1575 1576 $total += $obj->total_ht; 1577 $subtotal += $obj->total_ht; 1578 $i++; 1579 } 1580 1581 // Show total line 1582 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php'; 1583 1584 $db->free($resql); 1585 1586 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql); 1587 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook 1588 print $hookmanager->resPrint; 1589 1590 print '</table>'."\n"; 1591 print '</div>'; 1592 1593 print '</form>'."\n"; 1594 1595 $hidegeneratedfilelistifempty = 1; 1596 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { 1597 $hidegeneratedfilelistifempty = 0; 1598 } 1599 1600 // Show list of available documents 1601 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; 1602 $urlsource .= str_replace('&', '&', $param); 1603 1604 $filedir = $diroutputmassaction; 1605 $genallowed = ($user->rights->fournisseur->commande->lire || $user->rights->supplier_order->lire); 1606 $delallowed = ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer); 1607 1608 print $formfile->showdocuments('massfilesarea_supplier_order', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty); 1609} else { 1610 dol_print_error($db); 1611} 1612 1613// End of page 1614llxFooter(); 1615$db->close(); 1616