list.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  1. <?php
  2. /* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
  6. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  7. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2015 juanjo Menent <jmenent@2byte.es>
  10. * Copyright (C) 2015 Abbes Bahfir <bafbes@gmail.com>
  11. * Copyright (C) 2015-2016 Ferran Marcet <fmarcet@2byte.es>
  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 <http://www.gnu.org/licenses/>.
  25. */
  26. /**
  27. * \file htdocs/fourn/facture/list.php
  28. * \ingroup fournisseur,facture
  29. * \brief List of suppliers invoices
  30. */
  31. require '../../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  41. if (!$user->rights->fournisseur->facture->lire) accessforbidden();
  42. $langs->load("bills");
  43. $langs->load("companies");
  44. $langs->load('products');
  45. $socid = GETPOST('socid','int');
  46. // Security check
  47. if ($user->societe_id > 0)
  48. {
  49. $action='';
  50. $_GET["action"] = '';
  51. $socid = $user->societe_id;
  52. }
  53. $mode=GETPOST("mode");
  54. $modesearch=GETPOST("mode_search");
  55. $search_product_category=GETPOST('search_product_category','int');
  56. $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
  57. $search_refsupplier=GETPOST('search_refsupplier','alpha');
  58. $search_project=GETPOST('search_project','alpha');
  59. $search_societe=GETPOST('search_societe','alpha');
  60. $search_montant_ht=GETPOST('search_montant_ht','alpha');
  61. $search_montant_vat=GETPOST('search_montant_vat','alpha');
  62. $search_montant_ttc=GETPOST('search_montant_ttc','alpha');
  63. $search_status=GETPOST('search_status','int');
  64. $search_paymentmode=GETPOST('search_paymentmode','int');
  65. $search_town=GETPOST('search_town','alpha');
  66. $search_zip=GETPOST('search_zip','alpha');
  67. $search_state=trim(GETPOST("search_state"));
  68. $search_country=GETPOST("search_country",'int');
  69. $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
  70. $search_user = GETPOST('search_user','int');
  71. $search_sale = GETPOST('search_sale','int');
  72. $day = GETPOST('day','int');
  73. $month = GETPOST('month','int');
  74. $year = GETPOST('year','int');
  75. $day_lim = GETPOST('day_lim','int');
  76. $month_lim = GETPOST('month_lim','int');
  77. $year_lim = GETPOST('year_lim','int');
  78. $toselect = GETPOST('toselect', 'array');
  79. $option = GETPOST('option');
  80. if ($option == 'late') $filter = 'paye:0';
  81. $search_all = GETPOST('sall');
  82. $search_label = GETPOST("search_label","alpha");
  83. $search_company = GETPOST("search_company","alpha");
  84. $search_amount_no_tax = GETPOST("search_amount_no_tax","alpha");
  85. $search_amount_all_tax = GETPOST("search_amount_all_tax","alpha");
  86. $search_status=GETPOST('search_status','alpha');
  87. $optioncss = GETPOST('optioncss','alpha');
  88. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  89. $sortfield = GETPOST("sortfield",'alpha');
  90. $sortorder = GETPOST("sortorder",'alpha');
  91. $page=GETPOST("page",'int');
  92. if ($page == -1) { $page = 0 ; }
  93. $offset = $limit * $page ;
  94. $pageprev = $page - 1;
  95. $pagenext = $page + 1;
  96. if (! $sortorder) $sortorder="DESC";
  97. if (! $sortfield) $sortfield="f.datef,f.rowid";
  98. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  99. $contextpage='supplierinvoicelist';
  100. $diroutputmassaction=$conf->facture->dir_output . '/temp/massgeneration/'.$user->id;
  101. $object=new FactureFournisseur($db);
  102. $now=dol_now();
  103. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  104. $hookmanager->initHooks(array('supplierinvoicelist'));
  105. $extrafields = new ExtraFields($db);
  106. // fetch optionals attributes and labels
  107. $extralabels = $extrafields->fetch_name_optionals_label('facture_fourn');
  108. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  109. // List of fields to search into when doing a "search in all"
  110. $fieldstosearchall = array(
  111. 'f.ref'=>'Ref',
  112. 'f.ref_supplier'=>'RefSupplier',
  113. //'fd.description'=>'Description',
  114. 's.nom'=>"ThirdParty",
  115. 'f.note_public'=>'NotePublic',
  116. );
  117. if (empty($user->socid)) $fieldstosearchall["f.note_private"]="NotePrivate";
  118. $checkedtypetiers=0;
  119. $arrayfields=array(
  120. 'f.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  121. 'f.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
  122. 'f.label'=>array('label'=>$langs->trans("Label"), 'checked'=>0),
  123. 'f.datef'=>array('label'=>$langs->trans("DateInvoice"), 'checked'=>1),
  124. 'f.date_lim_reglement'=>array('label'=>$langs->trans("DateDue"), 'checked'=>1),
  125. 'p.ref'=>array('label'=>$langs->trans("Project"), 'checked'=>0),
  126. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
  127. 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
  128. 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
  129. 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
  130. 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
  131. 'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
  132. 'f.fk_mode_reglement'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>1),
  133. 'f.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
  134. 'f.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0),
  135. 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0),
  136. 'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  137. 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  138. 'f.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  139. );
  140. // Extra fields
  141. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  142. {
  143. foreach($extrafields->attribute_label as $key => $val)
  144. {
  145. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  146. }
  147. }
  148. /*
  149. * Actions
  150. */
  151. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  152. if (! GETPOST('confirmmassaction')) { $massaction=''; }
  153. $parameters=array('socid'=>$socid);
  154. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  155. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  156. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  157. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter") || GETPOST("button_removefilter.x")) // All test must be present to be compatible with all browsers
  158. {
  159. $search_all="";
  160. $search_user='';
  161. $search_sale='';
  162. $search_product_category='';
  163. $search_ref="";
  164. $search_refsupplier="";
  165. $search_label="";
  166. $search_project='';
  167. $search_societe="";
  168. $search_company="";
  169. $search_amount_no_tax="";
  170. $search_amount_all_tax="";
  171. $search_montant_ht='';
  172. $search_montant_vat='';
  173. $search_montant_ttc='';
  174. $search_status='';
  175. $search_paymentmode='';
  176. $search_town='';
  177. $search_zip="";
  178. $search_state="";
  179. $search_type='';
  180. $search_country='';
  181. $search_type_thirdparty='';
  182. $year="";
  183. $month="";
  184. $day="";
  185. $year_lim="";
  186. $month_lim="";
  187. $day_lim="";
  188. $search_array_options=array();
  189. $filter='';
  190. $option='';
  191. }
  192. if ($mode == 'search')
  193. {
  194. if ($modesearch == 'soc')
  195. {
  196. $sql = "SELECT s.rowid FROM ".MAIN_DB_PREFIX."societe as s ";
  197. $sql.= " WHERE s.nom LIKE '%".$db->escape($socname)."%'";
  198. $sql.= " AND s.entity IN (".getEntity('societe', 1).")";
  199. }
  200. $resql=$db->query($sql);
  201. if ($resql)
  202. {
  203. if ( $db->num_rows($resql) == 1)
  204. {
  205. $obj = $db->fetch_object($resql);
  206. $socid = $obj->rowid;
  207. }
  208. $db->free($resql);
  209. }
  210. }
  211. if (empty($reshook))
  212. {
  213. // Mass actions. Controls on number of lines checked
  214. $maxformassaction=1000;
  215. if (! empty($massaction) && count($toselect) < 1)
  216. {
  217. $error++;
  218. setEventMessages($langs->trans("NoLineChecked"), null, "warnings");
  219. }
  220. if (! $error && count($toselect) > $maxformassaction)
  221. {
  222. setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors');
  223. $error++;
  224. }
  225. }
  226. /*
  227. * View
  228. */
  229. $form=new Form($db);
  230. $formother=new FormOther($db);
  231. $formfile = new FormFile($db);
  232. $bankaccountstatic=new Account($db);
  233. $facturestatic=new FactureFournisseur($db);
  234. $formcompany=new FormCompany($db);
  235. llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
  236. $sql = "SELECT";
  237. if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
  238. $sql.= " f.rowid as facid, f.ref, f.ref_supplier, f.datef, f.date_lim_reglement as datelimite,";
  239. $sql.= " f.total_ht, f.total_ttc, f.paye as paye, f.fk_statut as fk_statut, f.libelle as label,";
  240. $sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
  241. $sql.= " typent.code as typent_code,";
  242. $sql.= " state.code_departement as state_code, state.nom as state_name,";
  243. $sql.= " p.rowid as project_id, p.ref as project_ref";
  244. if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
  245. // Add fields from extrafields
  246. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  247. // Add fields from hooks
  248. $parameters=array();
  249. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  250. $sql.=$hookmanager->resPrint;
  251. $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  252. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  253. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  254. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  255. $sql.= ', '.MAIN_DB_PREFIX.'facture_fourn as f';
  256. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn_extrafields as ef on (f.rowid = ef.fk_object)";
  257. else $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as fd ON fd.fk_facture_fourn = f.rowid';
  258. if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn';
  259. if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  260. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
  261. // We'll need this table joined to the select in order to filter by sale
  262. if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  263. if ($search_user > 0)
  264. {
  265. $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
  266. $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
  267. }
  268. $sql.= ' WHERE f.fk_soc = s.rowid';
  269. $sql.= " AND f.entity = ".$conf->entity;
  270. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  271. if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
  272. if ($socid > 0) $sql .= ' AND s.rowid = '.$socid;
  273. if ($search_all)
  274. {
  275. $sql.= natural_search(array_keys($fieldstosearchall), $search_all);
  276. }
  277. if ($search_ref)
  278. {
  279. if (is_numeric($search_ref)) $sql .= natural_search(array('f.ref'), $search_ref);
  280. else $sql .= natural_search('f.ref', $search_ref);
  281. }
  282. if ($search_ref) $sql .= natural_search('f.ref', $search_ref);
  283. if ($search_ref_supplier) $sql .= natural_search('f.ref_supplier', $search_ref_supplier);
  284. if ($search_project) $sql .= natural_search('p.ref', $search_project);
  285. if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
  286. if ($search_town) $sql.= natural_search('s.town', $search_town);
  287. if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
  288. if ($search_state) $sql.= natural_search("state.nom",$search_state);
  289. if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
  290. if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
  291. if ($search_company) $sql .= natural_search('s.nom', $search_company);
  292. if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1);
  293. if ($search_montant_vat != '') $sql.= natural_search('f.total_tva', $search_montant_vat, 1);
  294. if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1);
  295. if ($search_status != '' && $search_status >= 0) $sql.= " AND f.fk_statut = ".$db->escape($search_status);
  296. if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$search_paymentmode."";
  297. if ($month > 0)
  298. {
  299. if ($year > 0 && empty($day))
  300. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  301. else if ($year > 0 && ! empty($day))
  302. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
  303. else
  304. $sql.= " AND date_format(f.datef, '%m') = '".$month."'";
  305. }
  306. else if ($year > 0)
  307. {
  308. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  309. }
  310. if ($month_lim > 0)
  311. {
  312. if ($year_lim > 0 && empty($day_lim))
  313. $sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($year_lim,$month_lim,false))."' AND '".$db->idate(dol_get_last_day($year_lim,$month_lim,false))."'";
  314. else if ($year_lim > 0 && ! empty($day_lim))
  315. $sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_lim, $day_lim, $year_lim))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_lim, $day_lim, $year_lim))."'";
  316. else
  317. $sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$month_lim."'";
  318. }
  319. else if ($year_lim > 0)
  320. {
  321. $sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($year_lim,1,false))."' AND '".$db->idate(dol_get_last_day($year_lim,12,false))."'";
  322. }
  323. if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'";
  324. if ($filter == 'paye:0') $sql.= " AND f.fk_statut = 1";
  325. if ($search_label) $sql .= natural_search('f.libelle', $search_label);
  326. if ($search_status != '' && $search_status >= 0)
  327. {
  328. $sql.= " AND f.fk_statut = ".$search_status;
  329. }
  330. if ($filter && $filter != -1)
  331. {
  332. $aFilter = explode(',', $filter);
  333. foreach ($aFilter as $fil)
  334. {
  335. $filt = explode(':', $fil);
  336. $sql .= ' AND ' . trim($filt[0]) . ' = ' . trim($filt[1]);
  337. }
  338. }
  339. if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
  340. if ($search_user > 0)
  341. {
  342. $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='invoice_supplier' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".$search_user;
  343. }
  344. // Add where from extra fields
  345. foreach ($search_array_options as $key => $val)
  346. {
  347. $crit=$val;
  348. $tmpkey=preg_replace('/search_options_/','',$key);
  349. $typ=$extrafields->attribute_type[$tmpkey];
  350. $mode=0;
  351. if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
  352. if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
  353. {
  354. $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
  355. }
  356. }
  357. // Add where from hooks
  358. $parameters=array();
  359. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  360. $sql.=$hookmanager->resPrint;
  361. $sql.= $db->order($sortfield,$sortorder);
  362. $nbtotalofrecords = 0;
  363. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  364. {
  365. $result = $db->query($sql);
  366. $nbtotalofrecords = $db->num_rows($result);
  367. }
  368. $sql.= $db->plimit($limit+1, $offset);
  369. //print $sql;
  370. $resql = $db->query($sql);
  371. if ($resql)
  372. {
  373. $num = $db->num_rows($resql);
  374. $arrayofselected=is_array($toselect)?$toselect:array();
  375. if ($socid)
  376. {
  377. $soc = new Societe($db);
  378. $soc->fetch($socid);
  379. }
  380. $param='&socid='.$socid;
  381. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  382. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  383. if ($day) $param.='&day='.urlencode($day);
  384. if ($month) $param.='&month='.urlencode($month);
  385. if ($year) $param.='&year=' .urlencode($year);
  386. if ($day_lim) $param.='&day_lim='.urlencode($day_lim);
  387. if ($month_lim) $param.='&month_lim='.urlencode($month_lim);
  388. if ($year_lim) $param.='&year_lim=' .urlencode($year_lim);
  389. if ($search_ref) $param.='&search_ref='.urlencode($search_ref);
  390. if ($search_refsupplier) $param.='&search_refsupplier'.urlencode($search_refsupplier);
  391. if ($search_label) $param.='&search_label='.urlencode($search_label);
  392. if ($search_company) $param.='&search_company='.urlencode($search_company);
  393. if ($search_montant_ht != '') $param.='&search_montant_ht='.urlencode($search_montant_ht);
  394. if ($search_montant_vat != '') $param.='&search_montant_vat='.urlencode($search_montant_vat);
  395. if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc);
  396. if ($search_amount_no_tax) $param.='&search_amount_no_tax='.urlencode($search_amount_no_tax);
  397. if ($search_amount_all_tax) $param.='&search_amount_all_tax='.urlencode($search_amount_all_tax);
  398. if ($search_status >= 0) $param.="&search_status=".urlencode($search_status);
  399. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  400. // Add $param from extra fields
  401. foreach ($search_array_options as $key => $val)
  402. {
  403. $crit=$val;
  404. $tmpkey=preg_replace('/search_options_/','',$key);
  405. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  406. }
  407. $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
  408. $i = 0;
  409. print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  410. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  411. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  412. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  413. print '<input type="hidden" name="action" value="list">';
  414. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  415. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  416. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  417. print_barre_liste($langs->trans("BillsSuppliers").($socid?" $soc->name.":""),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'title_accountancy',0,'','',$limit);
  418. if ($search_all)
  419. {
  420. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  421. print $langs->trans("FilterOnInto", $search_all) . join(', ',$fieldstosearchall);
  422. }
  423. // If the user can view prospects other than his'
  424. $moreforfilter='';
  425. if ($user->rights->societe->client->voir || $socid)
  426. {
  427. $langs->load("commercial");
  428. $moreforfilter.='<div class="divsearchfield">';
  429. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  430. $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300');
  431. $moreforfilter.='</div>';
  432. }
  433. // If the user can view prospects other than his'
  434. if ($user->rights->societe->client->voir || $socid)
  435. {
  436. $moreforfilter.='<div class="divsearchfield">';
  437. $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
  438. $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  439. $moreforfilter.='</div>';
  440. }
  441. // If the user can view prospects other than his'
  442. if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
  443. {
  444. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  445. $moreforfilter.='<div class="divsearchfield">';
  446. $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
  447. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  448. $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1);
  449. $moreforfilter.='</div>';
  450. }
  451. $parameters=array();
  452. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  453. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  454. else $moreforfilter = $hookmanager->resPrint;
  455. if ($moreforfilter)
  456. {
  457. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  458. print $moreforfilter;
  459. print '</div>';
  460. }
  461. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  462. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  463. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  464. print '<tr class="liste_titre">';
  465. if (! empty($arrayfields['f.ref']['checked'])) print_liste_field_titre($arrayfields['f.ref']['label'],$_SERVER['PHP_SELF'],'f.ref,f.rowid','',$param,'',$sortfield,$sortorder);
  466. if (! empty($arrayfields['f.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['f.ref_supplier']['label'],$_SERVER["PHP_SELF"],'f.ref_supplier','',$param,'',$sortfield,$sortorder);
  467. if (! empty($arrayfields['f.label']['checked'])) print_liste_field_titre($arrayfields['f.label']['label'],$_SERVER['PHP_SELF'],"f.libelle,f.rowid",'',$param,'',$sortfield,$sortorder);
  468. if (! empty($arrayfields['f.datef']['checked'])) print_liste_field_titre($arrayfields['f.datef']['label'],$_SERVER['PHP_SELF'],'f.datef','',$param,'align="center"',$sortfield,$sortorder);
  469. if (! empty($arrayfields['f.date_lim_reglement']['checked'])) print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'],$_SERVER['PHP_SELF'],"f.date_lim_reglement",'',$param,'align="center"',$sortfield,$sortorder);
  470. if (! empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'],$_SERVER['PHP_SELF'],"p.ref",'',$param,'align="center"',$sortfield,$sortorder);
  471. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER['PHP_SELF'],'s.nom','',$param,'',$sortfield,$sortorder);
  472. if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
  473. if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
  474. if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  475. 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);
  476. if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
  477. if (! empty($arrayfields['f.fk_mode_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'],$_SERVER["PHP_SELF"],"f.fk_mode_reglement","",$param,"",$sortfield,$sortorder);
  478. if (! empty($arrayfields['f.total_ht']['checked'])) print_liste_field_titre($arrayfields['f.total_ht']['label'],$_SERVER['PHP_SELF'],'f.total','',$param,'align="right"',$sortfield,$sortorder);
  479. if (! empty($arrayfields['f.total_vat']['checked'])) print_liste_field_titre($arrayfields['f.total_vat']['label'],$_SERVER['PHP_SELF'],'f.tva','',$param,'align="right"',$sortfield,$sortorder);
  480. if (! empty($arrayfields['f.total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.total_ttc']['label'],$_SERVER['PHP_SELF'],'f.total_ttc','',$param,'align="right"',$sortfield,$sortorder);
  481. // Extra fields
  482. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  483. {
  484. foreach($extrafields->attribute_label as $key => $val)
  485. {
  486. if (! empty($arrayfields["ef.".$key]['checked']))
  487. {
  488. $align=$extrafields->getAlignFlag($key);
  489. print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  490. }
  491. }
  492. }
  493. // Hook fields
  494. $parameters=array('arrayfields'=>$arrayfields);
  495. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  496. print $hookmanager->resPrint;
  497. if (! empty($arrayfields['f.datec']['checked'])) print_liste_field_titre($arrayfields['f.datec']['label'],$_SERVER["PHP_SELF"],"f.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  498. if (! empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'],$_SERVER["PHP_SELF"],"f.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  499. if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye","",$param,'align="right"',$sortfield,$sortorder);
  500. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
  501. /*
  502. print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"f.ref,f.rowid","",$param,"",$sortfield,$sortorder);
  503. if (empty($conf->global->SUPPLIER_INVOICE_HIDE_REF_SUPPLIER)) print_liste_field_titre($langs->trans("RefSupplier"),$_SERVER["PHP_SELF"],"ref_supplier","",$param,"",$sortfield,$sortorder);
  504. print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"f.datef,f.rowid","",$param,'align="center"',$sortfield,$sortorder);
  505. print_liste_field_titre($langs->trans("DateDue"),$_SERVER["PHP_SELF"],"f.date_lim_reglement","",$param,'align="center"',$sortfield,$sortorder);
  506. print_liste_field_titre($langs->trans("Label"),$_SERVER["PHP_SELF"],"f.libelle","",$param,"",$sortfield,$sortorder);
  507. print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
  508. if (! empty($conf->global->PROJECT_SHOW_REF_INTO_LISTS)) print_liste_field_titre($langs->trans("Project"),$_SERVER["PHP_SELF"],"p.ref","",$param,'',$sortfield,$sortorder);
  509. print_liste_field_titre($langs->trans("AmountHT"),$_SERVER["PHP_SELF"],"f.total_ht","",$param,'align="right"',$sortfield,$sortorder);
  510. print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
  511. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"fk_statut,paye","",$param,'align="right"',$sortfield,$sortorder);
  512. print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
  513. */ print "</tr>\n";
  514. // Line for filters
  515. print '<tr class="liste_titre">';
  516. // Ref
  517. if (! empty($arrayfields['f.ref']['checked']))
  518. {
  519. print '<td class="liste_titre" align="left">';
  520. print '<input class="flat" size="6" type="text" name="search_ref" value="'.$search_ref.'">';
  521. print '</td>';
  522. }
  523. // Ref supplier
  524. if (! empty($arrayfields['f.ref_supplier']['checked']))
  525. {
  526. print '<td class="liste_titre">';
  527. print '<input class="flat" size="6" type="text" name="search_refsupplier" value="'.$search_refsupplier.'">';
  528. print '</td>';
  529. }
  530. // Label
  531. if (! empty($arrayfields['f.label']['checked']))
  532. {
  533. print '<td class="liste_titre">';
  534. print '<input class="flat" size="6" type="text" name="search_label" value="'.$search_label.'">';
  535. print '</td>';
  536. }
  537. // Date invoice
  538. if (! empty($arrayfields['f.datef']['checked']))
  539. {
  540. print '<td class="liste_titre" align="center">';
  541. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  542. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  543. $formother->select_year($year?$year:-1,'year',1, 20, 5);
  544. print '</td>';
  545. }
  546. // Date due
  547. if (! empty($arrayfields['f.date_lim_reglement']['checked']))
  548. {
  549. print '<td class="liste_titre" align="center">';
  550. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day_lim" value="'.$day_lim.'">';
  551. print '<input class="flat" type="text" size="1" maxlength="2" name="month_lim" value="'.$month_lim.'">';
  552. $formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5);
  553. print '<br><input type="checkbox" name="option" value="late"'.($option == 'late'?' checked':'').'> '.$langs->trans("Late");
  554. print '</td>';
  555. }
  556. // Project
  557. if (! empty($arrayfields['p.ref']['checked']))
  558. {
  559. print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_project" value="'.$search_project.'"></td>';
  560. }
  561. // Thirpdarty
  562. if (! empty($arrayfields['s.nom']['checked']))
  563. {
  564. print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_societe" value="'.$search_societe.'"></td>';
  565. }
  566. // Town
  567. if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
  568. // Zip
  569. 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>';
  570. // State
  571. if (! empty($arrayfields['state.nom']['checked']))
  572. {
  573. print '<td class="liste_titre">';
  574. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  575. print '</td>';
  576. }
  577. // Country
  578. if (! empty($arrayfields['country.code_iso']['checked']))
  579. {
  580. print '<td class="liste_titre" align="center">';
  581. print $form->select_country($search_country,'search_country','',0,'maxwidth100');
  582. print '</td>';
  583. }
  584. // Company type
  585. if (! empty($arrayfields['typent.code']['checked']))
  586. {
  587. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  588. 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));
  589. print '</td>';
  590. }
  591. // Payment mode
  592. if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
  593. {
  594. print '<td class="liste_titre" align="left">';
  595. $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 0, 1, 10);
  596. print '</td>';
  597. }
  598. if (! empty($arrayfields['f.total_ht']['checked']))
  599. {
  600. // Amount
  601. print '<td class="liste_titre" align="right">';
  602. print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.$search_montant_ht.'">';
  603. print '</td>';
  604. }
  605. if (! empty($arrayfields['f.total_vat']['checked']))
  606. {
  607. // Amount
  608. print '<td class="liste_titre" align="right">';
  609. print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.$search_montant_vat.'">';
  610. print '</td>';
  611. }
  612. if (! empty($arrayfields['f.total_ttc']['checked']))
  613. {
  614. // Amount
  615. print '<td class="liste_titre" align="right">';
  616. print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.$search_montant_ttc.'">';
  617. print '</td>';
  618. }
  619. // Extra fields
  620. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  621. {
  622. foreach($extrafields->attribute_label as $key => $val)
  623. {
  624. if (! empty($arrayfields["ef.".$key]['checked']))
  625. {
  626. $align=$extrafields->getAlignFlag($key);
  627. $typeofextrafield=$extrafields->attribute_type[$key];
  628. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  629. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  630. {
  631. $crit=$val;
  632. $tmpkey=preg_replace('/search_options_/','',$key);
  633. $searchclass='';
  634. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  635. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  636. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  637. }
  638. print '</td>';
  639. }
  640. }
  641. }
  642. // Fields from hook
  643. $parameters=array('arrayfields'=>$arrayfields);
  644. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  645. print $hookmanager->resPrint;
  646. // Date creation
  647. if (! empty($arrayfields['f.datec']['checked']))
  648. {
  649. print '<td class="liste_titre">';
  650. print '</td>';
  651. }
  652. // Date modification
  653. if (! empty($arrayfields['f.tms']['checked']))
  654. {
  655. print '<td class="liste_titre">';
  656. print '</td>';
  657. }
  658. // Status
  659. if (! empty($arrayfields['f.fk_statut']['checked']))
  660. {
  661. print '<td class="liste_titre maxwidthonsmartphone" align="right">';
  662. $liststatus=array('0'=>$langs->trans("Draft"),'1'=>$langs->trans("Unpaid"), '2'=>$langs->trans("Paid"));
  663. print $form->selectarray('search_status', $liststatus, $search_status, 1);
  664. print '</td>';
  665. }
  666. // Action column
  667. print '<td class="liste_titre" align="middle">';
  668. $searchpitco=$form->showFilterAndCheckAddButtons(0, 'checkforselect', 0);
  669. print $searchpitco;
  670. print '</td>';
  671. print "</tr>\n";
  672. $facturestatic=new FactureFournisseur($db);
  673. $supplierstatic=new Fournisseur($db);
  674. $projectstatic=new Project($db);
  675. if ($num > 0)
  676. {
  677. $i=0;
  678. $var=true;
  679. $totalarray=array();
  680. while ($i < min($num,$limit))
  681. {
  682. $obj = $db->fetch_object($resql);
  683. $var=!$var;
  684. $datelimit=$db->jdate($obj->datelimite);
  685. $facturestatic->id=$obj->facid;
  686. $facturestatic->ref=$obj->ref;
  687. $facturestatic->ref_supplier=$obj->ref_supplier;
  688. $facturestatic->date_echeance = $db->jdate($obj->datelimite);
  689. $facturestatic->statut = $obj->fk_statut;
  690. print '<tr '.$bc[$var].'>';
  691. if (! empty($arrayfields['f.ref']['checked']))
  692. {
  693. print '<td class="nowrap">';
  694. print $facturestatic->getNomUrl(1);
  695. $filename=dol_sanitizeFileName($obj->ref);
  696. $filedir=$conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid,2,0,0,$facturestatic,'invoice_supplier').dol_sanitizeFileName($obj->ref);
  697. print $formfile->getDocumentsLink('facture_fournisseur', $filename, $filedir);
  698. print "</td>\n";
  699. if (! $i) $totalarray['nbfield']++;
  700. }
  701. // Customer ref
  702. if (! empty($arrayfields['f.ref_supplier']['checked']))
  703. {
  704. print '<td class="nowrap">';
  705. print $obj->ref_supplier;
  706. print '</td>';
  707. if (! $i) $totalarray['nbfield']++;
  708. }
  709. // Label
  710. if (! empty($arrayfields['f.label']['checked']))
  711. {
  712. print '<td class="nowrap">';
  713. print $obj->label;
  714. print '</td>';
  715. if (! $i) $totalarray['nbfield']++;
  716. }
  717. // Date
  718. if (! empty($arrayfields['f.datef']['checked']))
  719. {
  720. print '<td align="center" class="nowrap">';
  721. print dol_print_date($db->jdate($obj->datef),'day');
  722. print '</td>';
  723. if (! $i) $totalarray['nbfield']++;
  724. }
  725. // Date limit
  726. if (! empty($arrayfields['f.date_lim_reglement']['checked']))
  727. {
  728. print '<td align="center" class="nowrap">'.dol_print_date($datelimit,'day');
  729. if ($facturestatic->hasDelay())
  730. {
  731. print img_warning($langs->trans('Late'));
  732. }
  733. print '</td>';
  734. if (! $i) $totalarray['nbfield']++;
  735. }
  736. // Project
  737. if (! empty($arrayfields['p.ref']['checked']))
  738. {
  739. print '<td class="nowrap">';
  740. if ($obj->project_id > 0)
  741. {
  742. $projectstatic->id=$obj->project_id;
  743. $projectstatic->ref=$obj->project_ref;
  744. print $projectstatic->getNomUrl(1);
  745. }
  746. print '</td>';
  747. if (! $i) $totalarray['nbfield']++;
  748. }
  749. // Third party
  750. if (! empty($arrayfields['s.nom']['checked']))
  751. {
  752. print '<td>';
  753. $thirdparty=new Societe($db);
  754. $thirdparty->id=$obj->socid;
  755. $thirdparty->name=$obj->name;
  756. $thirdparty->client=$obj->client;
  757. $thirdparty->code_client=$obj->code_client;
  758. print $thirdparty->getNomUrl(1,'customer');
  759. print '</td>';
  760. if (! $i) $totalarray['nbfield']++;
  761. }
  762. // Town
  763. if (! empty($arrayfields['s.town']['checked']))
  764. {
  765. print '<td class="nocellnopadd">';
  766. print $obj->town;
  767. print '</td>';
  768. if (! $i) $totalarray['nbfield']++;
  769. }
  770. // Zip
  771. if (! empty($arrayfields['s.zip']['checked']))
  772. {
  773. print '<td class="nocellnopadd">';
  774. print $obj->zip;
  775. print '</td>';
  776. if (! $i) $totalarray['nbfield']++;
  777. }
  778. // State
  779. if (! empty($arrayfields['state.nom']['checked']))
  780. {
  781. print "<td>".$obj->state_name."</td>\n";
  782. if (! $i) $totalarray['nbfield']++;
  783. }
  784. // Country
  785. if (! empty($arrayfields['country.code_iso']['checked']))
  786. {
  787. print '<td align="center">';
  788. $tmparray=getCountry($obj->fk_pays,'all');
  789. print $tmparray['label'];
  790. print '</td>';
  791. if (! $i) $totalarray['nbfield']++;
  792. }
  793. // Type ent
  794. if (! empty($arrayfields['typent.code']['checked']))
  795. {
  796. print '<td align="center">';
  797. if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
  798. print $typenArray[$obj->typent_code];
  799. print '</td>';
  800. if (! $i) $totalarray['nbfield']++;
  801. }
  802. // Payment mode
  803. if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
  804. {
  805. print '<td>';
  806. $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
  807. print '</td>';
  808. if (! $i) $totalarray['nbfield']++;
  809. }
  810. // Amount HT
  811. if (! empty($arrayfields['f.total_ht']['checked']))
  812. {
  813. print '<td align="right">'.price($obj->total_ht)."</td>\n";
  814. if (! $i) $totalarray['nbfield']++;
  815. if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
  816. $totalarray['totalht'] += $obj->total_ht;
  817. }
  818. // Amount VAT
  819. if (! empty($arrayfields['f.total_vat']['checked']))
  820. {
  821. print '<td align="right">'.price($obj->total_vat)."</td>\n";
  822. if (! $i) $totalarray['nbfield']++;
  823. if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
  824. $totalarray['totalvat'] += $obj->total_vat;
  825. }
  826. // Amount TTC
  827. if (! empty($arrayfields['f.total_ttc']['checked']))
  828. {
  829. print '<td align="right">'.price($obj->total_ttc)."</td>\n";
  830. if (! $i) $totalarray['nbfield']++;
  831. if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
  832. $totalarray['totalttc'] += $obj->total_ttc;
  833. }
  834. if (! empty($arrayfields['am']['checked']))
  835. {
  836. print '<td align="right">'.(! empty($paiement)?price($paiement,0,$langs):'&nbsp;').'</td>';
  837. if (! $i) $totalarray['nbfield']++;
  838. if (! $i) $totalarray['totalamfield']=$totalarray['nbfield'];
  839. $totalarray['totalam'] += $paiement;
  840. }
  841. if (! empty($arrayfields['rtp']['checked']))
  842. {
  843. print '<td align="right">'.(! empty($remaintopay)?price($remaintopay,0,$langs):'&nbsp;').'</td>';
  844. if (! $i) $totalarray['nbfield']++;
  845. if (! $i) $totalarray['totalrtpfield']=$totalarray['nbfield'];
  846. $totalarray['totalrtp'] += $remaintopay;
  847. }
  848. // Extra fields
  849. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  850. {
  851. foreach($extrafields->attribute_label as $key => $val)
  852. {
  853. if (! empty($arrayfields["ef.".$key]['checked']))
  854. {
  855. print '<td';
  856. $align=$extrafields->getAlignFlag($key);
  857. if ($align) print ' align="'.$align.'"';
  858. print '>';
  859. $tmpkey='options_'.$key;
  860. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  861. print '</td>';
  862. if (! $i) $totalarray['nbfield']++;
  863. }
  864. }
  865. }
  866. // Fields from hook
  867. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  868. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  869. print $hookmanager->resPrint;
  870. // Date creation
  871. if (! empty($arrayfields['f.datec']['checked']))
  872. {
  873. print '<td align="center" class="nowrap">';
  874. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  875. print '</td>';
  876. if (! $i) $totalarray['nbfield']++;
  877. }
  878. // Date modification
  879. if (! empty($arrayfields['f.tms']['checked']))
  880. {
  881. print '<td align="center" class="nowrap">';
  882. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  883. print '</td>';
  884. if (! $i) $totalarray['nbfield']++;
  885. }
  886. // Status
  887. if (! empty($arrayfields['f.fk_statut']['checked']))
  888. {
  889. print '<td align="right" class="nowrap">';
  890. // TODO $paiement is not yet defined
  891. print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$paiement,$obj->type);
  892. print "</td>";
  893. if (! $i) $totalarray['nbfield']++;
  894. }
  895. // Action column
  896. print '<td class="nowrap" align="center">';
  897. $selected=0;
  898. if (in_array($obj->facid, $arrayofselected)) $selected=1;
  899. //print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected?' checked="checked"':'').'>';
  900. print '</td>' ;
  901. if (! $i) $totalarray['nbfield']++;
  902. print "</tr>\n";
  903. $i++;
  904. }
  905. // Show total line
  906. if (isset($totalarray['totalhtfield']))
  907. {
  908. print '<tr class="liste_total">';
  909. $i=0;
  910. while ($i < $totalarray['nbfield'])
  911. {
  912. $i++;
  913. if ($i == 1)
  914. {
  915. if ($num < $limit) print '<td align="left">'.$langs->trans("Total").'</td>';
  916. else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
  917. }
  918. elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
  919. elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
  920. elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
  921. elseif ($totalarray['totalamfield'] == $i) print '<td align="right">'.price($totalarray['totalam']).'</td>';
  922. elseif ($totalarray['totalrtpfield'] == $i) print '<td align="right">'.price($totalarray['totalrtp']).'</td>';
  923. else print '<td></td>';
  924. }
  925. print '</tr>';
  926. }
  927. }
  928. $db->free($resql);
  929. $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  930. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  931. print $hookmanager->resPrint;
  932. print "</table>\n";
  933. print "</form>\n";
  934. }
  935. else
  936. {
  937. dol_print_error($db);
  938. }
  939. llxFooter();
  940. $db->close();