list.php 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. <?php
  2. /* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  4. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  6. * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
  7. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  8. * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  10. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  11. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  12. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  13. * Copyright (C) 2015-2016 Ferran Marcet <fmarcet@2byte.es>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. */
  28. /**
  29. * \file htdocs/compta/facture/list.php
  30. * \ingroup facture
  31. * \brief List of customer invoices
  32. */
  33. require '../../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  38. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  45. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  46. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  47. if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  48. $langs->load('bills');
  49. $langs->load('companies');
  50. $langs->load('products');
  51. $sall=trim(GETPOST('sall'));
  52. $projectid=(GETPOST('projectid')?GETPOST('projectid','int'):0);
  53. $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
  54. $ref=GETPOST('ref','alpha');
  55. $socid=GETPOST('socid','int');
  56. $action=GETPOST('action','alpha');
  57. $massaction=GETPOST('massaction','alpha');
  58. $show_files=GETPOST('show_files','int');
  59. $confirm=GETPOST('confirm','alpha');
  60. $toselect = GETPOST('toselect', 'array');
  61. $lineid=GETPOST('lineid','int');
  62. $userid=GETPOST('userid','int');
  63. $search_product_category=GETPOST('search_product_category','int');
  64. $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
  65. $search_refcustomer=GETPOST('search_refcustomer','alpha');
  66. $search_societe=GETPOST('search_societe','alpha');
  67. $search_montant_ht=GETPOST('search_montant_ht','alpha');
  68. $search_montant_vat=GETPOST('search_montant_vat','alpha');
  69. $search_montant_ttc=GETPOST('search_montant_ttc','alpha');
  70. $search_status=GETPOST('search_status','int');
  71. $search_paymentmode=GETPOST('search_paymentmode','int');
  72. $search_town=GETPOST('search_town','alpha');
  73. $search_zip=GETPOST('search_zip','alpha');
  74. $search_state=trim(GETPOST("search_state"));
  75. $search_country=GETPOST("search_country",'int');
  76. $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
  77. $search_user = GETPOST('search_user','int');
  78. $search_sale = GETPOST('search_sale','int');
  79. $day = GETPOST('day','int');
  80. $month = GETPOST('month','int');
  81. $year = GETPOST('year','int');
  82. $day_lim = GETPOST('day_lim','int');
  83. $month_lim = GETPOST('month_lim','int');
  84. $year_lim = GETPOST('year_lim','int');
  85. $option = GETPOST('option');
  86. if ($option == 'late') $filter = 'paye:0';
  87. $filtre = GETPOST('filtre');
  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. if (! $sortorder && ! empty($conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER) && $search_status == 1) $sortorder=$conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER;
  95. if (! $sortorder) $sortorder='DESC';
  96. if (! $sortfield) $sortfield='f.datef';
  97. $pageprev = $page - 1;
  98. $pagenext = $page + 1;
  99. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  100. $contextpage='invoicelist';
  101. // Security check
  102. $fieldid = (! empty($ref)?'facnumber':'rowid');
  103. if (! empty($user->societe_id)) $socid=$user->societe_id;
  104. $result = restrictedArea($user, 'facture', $id,'','','fk_soc',$fieldid);
  105. $diroutputmassaction=$conf->facture->dir_output . '/temp/massgeneration/'.$user->id;
  106. $object=new Facture($db);
  107. $now=dol_now();
  108. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  109. $hookmanager->initHooks(array('invoicelist'));
  110. $extrafields = new ExtraFields($db);
  111. // fetch optionals attributes and labels
  112. $extralabels = $extrafields->fetch_name_optionals_label('facture');
  113. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  114. // List of fields to search into when doing a "search in all"
  115. $fieldstosearchall = array(
  116. 'f.facnumber'=>'Ref',
  117. 'f.ref_client'=>'RefCustomer',
  118. 'fd.description'=>'Description',
  119. 's.nom'=>"ThirdParty",
  120. 'f.note_public'=>'NotePublic',
  121. );
  122. if (empty($user->socid)) $fieldstosearchall["f.note_private"]="NotePrivate";
  123. $checkedtypetiers=0;
  124. $arrayfields=array(
  125. 'f.facnumber'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  126. 'f.ref_client'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
  127. 'f.date'=>array('label'=>$langs->trans("DateInvoice"), 'checked'=>1),
  128. 'f.date_lim_reglement'=>array('label'=>$langs->trans("DateDue"), 'checked'=>1),
  129. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
  130. 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
  131. 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
  132. 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
  133. 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
  134. 'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
  135. 'f.fk_mode_reglement'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>1),
  136. 'f.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
  137. 'f.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0),
  138. 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0),
  139. 'am'=>array('label'=>$langs->trans("Received"), 'checked'=>0),
  140. 'rtp'=>array('label'=>$langs->trans("Rest"), 'checked'=>0),
  141. 'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  142. 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  143. 'f.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  144. );
  145. // Extra fields
  146. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  147. {
  148. foreach($extrafields->attribute_label as $key => $val)
  149. {
  150. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  151. }
  152. }
  153. /*
  154. * Actions
  155. */
  156. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  157. if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  158. $parameters=array('socid'=>$socid);
  159. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  160. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  161. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  162. // Do we click on purge search criteria ?
  163. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter") || GETPOST("button_removefilter.x")) // Both test are required to be compatible with all browsers
  164. {
  165. $search_user='';
  166. $search_sale='';
  167. $search_product_category='';
  168. $search_ref='';
  169. $search_refcustomer='';
  170. $search_project='';
  171. $search_societe='';
  172. $search_montant_ht='';
  173. $search_montant_vat='';
  174. $search_montant_ttc='';
  175. $search_status='';
  176. $search_paymentmode='';
  177. $search_town='';
  178. $search_zip="";
  179. $search_state="";
  180. $search_type='';
  181. $search_country='';
  182. $search_type_thirdparty='';
  183. $day='';
  184. $year='';
  185. $month='';
  186. $option='';
  187. $filter='';
  188. $day_lim='';
  189. $year_lim='';
  190. $month_lim='';
  191. $toselect='';
  192. $search_array_options=array();
  193. }
  194. if (empty($reshook))
  195. {
  196. $objectclass='Facture';
  197. $permtoread = $user->rights->facture->lire;
  198. $permtodelete = $user->rights->facture->supprimer;
  199. $uploaddir = $conf->facture->dir_output;
  200. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  201. }
  202. /*
  203. * View
  204. */
  205. $form = new Form($db);
  206. $formother = new FormOther($db);
  207. $formfile = new FormFile($db);
  208. $bankaccountstatic=new Account($db);
  209. $facturestatic=new Facture($db);
  210. $formcompany=new FormCompany($db);
  211. llxHeader('',$langs->trans('CustomersInvoices'),'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
  212. $sql = 'SELECT';
  213. if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
  214. $sql.= ' f.rowid as facid, f.facnumber, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,';
  215. $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,';
  216. $sql.= ' f.paye as paye, f.fk_statut,';
  217. $sql.= ' f.datec as date_creation, f.tms as date_update,';
  218. $sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
  219. $sql.= " typent.code as typent_code,";
  220. $sql.= " state.code_departement as state_code, state.nom as state_name";
  221. if (! $sall) $sql.= ', SUM(pf.amount) as am'; // To be able to sort on status
  222. // Add fields from extrafields
  223. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  224. // Add fields from hooks
  225. $parameters=array();
  226. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  227. $sql.=$hookmanager->resPrint;
  228. $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  229. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  230. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  231. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  232. $sql.= ', '.MAIN_DB_PREFIX.'facture as f';
  233. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture_extrafields as ef on (f.rowid = ef.fk_object)";
  234. if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
  235. else $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid';
  236. if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture';
  237. if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  238. // We'll need this table joined to the select in order to filter by sale
  239. if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  240. if ($search_user > 0)
  241. {
  242. $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
  243. $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
  244. }
  245. $sql.= ' WHERE f.fk_soc = s.rowid';
  246. $sql.= " AND f.entity = ".$conf->entity;
  247. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  248. if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
  249. if ($socid > 0) $sql.= ' AND s.rowid = '.$socid;
  250. if ($userid)
  251. {
  252. if ($userid == -1) $sql.=' AND f.fk_user_author IS NULL';
  253. else $sql.=' AND f.fk_user_author = '.$userid;
  254. }
  255. if ($filtre)
  256. {
  257. $aFilter = explode(',', $filtre);
  258. foreach ($aFilter as $filter)
  259. {
  260. $filt = explode(':', $filter);
  261. $sql .= ' AND ' . trim($filt[0]) . ' = ' . trim($filt[1]);
  262. }
  263. }
  264. if ($search_ref) $sql .= natural_search('f.facnumber', $search_ref);
  265. if ($search_refcustomer) $sql .= natural_search('f.ref_client', $search_refcustomer);
  266. if ($search_project) $sql .= natural_search('p.ref', $search_project);
  267. if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
  268. if ($search_town) $sql.= natural_search('s.town', $search_town);
  269. if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
  270. if ($search_state) $sql.= natural_search("state.nom",$search_state);
  271. if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
  272. if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
  273. if ($search_company) $sql .= natural_search('s.nom', $search_company);
  274. if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1);
  275. if ($search_montant_vat != '') $sql.= natural_search('f.total_vat', $search_montant_vat, 1);
  276. if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1);
  277. if ($search_status != '' && $search_status >= 0)
  278. {
  279. if ($search_status == '0') $sql.=" AND f.fk_statut = 0"; // draft
  280. if ($search_status == '1') $sql.=" AND f.fk_statut = 1"; // unpayed
  281. if ($search_status == '2') $sql.=" AND f.fk_statut = 2"; // payed Not that some correupted data may contains f.fk_statut = 1 AND f.paye = 1 (it means payed too but should not happend. If yes, reopen and reclassify billed)
  282. if ($search_status == '3') $sql.=" AND f.fk_statut = 3"; // abandonned
  283. }
  284. if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$search_paymentmode."";
  285. if ($month > 0)
  286. {
  287. if ($year > 0 && empty($day))
  288. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  289. else if ($year > 0 && ! empty($day))
  290. $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))."'";
  291. else
  292. $sql.= " AND date_format(f.datef, '%m') = '".$month."'";
  293. }
  294. else if ($year > 0)
  295. {
  296. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  297. }
  298. if ($month_lim > 0)
  299. {
  300. if ($year_lim > 0 && empty($day_lim))
  301. $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))."'";
  302. else if ($year_lim > 0 && ! empty($day_lim))
  303. $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))."'";
  304. else
  305. $sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$month_lim."'";
  306. }
  307. else if ($year_lim > 0)
  308. {
  309. $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))."'";
  310. }
  311. if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->client->warning_delay)."'";
  312. if ($filter == 'paye:0') $sql.= " AND f.fk_statut = 1";
  313. if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
  314. if ($search_user > 0)
  315. {
  316. $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='facture' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".$search_user;
  317. }
  318. // Add where from extra fields
  319. foreach ($search_array_options as $key => $val)
  320. {
  321. $crit=$val;
  322. $tmpkey=preg_replace('/search_options_/','',$key);
  323. $typ=$extrafields->attribute_type[$tmpkey];
  324. $mode=0;
  325. if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
  326. if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
  327. {
  328. $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
  329. }
  330. }
  331. // Add where from hooks
  332. $parameters=array();
  333. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  334. $sql.=$hookmanager->resPrint;
  335. if (! $sall)
  336. {
  337. $sql.= ' GROUP BY f.rowid, f.facnumber, ref_client, f.type, f.note_private, f.note_public, f.increment, f.total, f.tva, f.total_ttc,';
  338. $sql.= ' f.datef, f.date_lim_reglement,';
  339. $sql.= ' f.paye, f.fk_statut,';
  340. $sql.= ' f.datec, f.tms,';
  341. $sql.= ' s.rowid, s.nom, s.town, s.zip, s.fk_pays, s.code_client, s.client, typent.code';
  342. $sql.= ' ,state.code_departement, state.nom';
  343. }
  344. else
  345. {
  346. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  347. }
  348. $sql.= ' ORDER BY ';
  349. $listfield=explode(',',$sortfield);
  350. foreach ($listfield as $key => $value) $sql.= $listfield[$key].' '.$sortorder.',';
  351. $sql.= ' f.rowid DESC ';
  352. $nbtotalofrecords = 0;
  353. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  354. {
  355. $result = $db->query($sql);
  356. $nbtotalofrecords = $db->num_rows($result);
  357. }
  358. $sql.= $db->plimit($limit+1,$offset);
  359. //print $sql;
  360. $resql = $db->query($sql);
  361. if ($resql)
  362. {
  363. $num = $db->num_rows($resql);
  364. $arrayofselected=is_array($toselect)?$toselect:array();
  365. if ($socid)
  366. {
  367. $soc = new Societe($db);
  368. $soc->fetch($socid);
  369. }
  370. $param='&socid='.$socid;
  371. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  372. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  373. if ($day) $param.='&day='.urlencode($day);
  374. if ($month) $param.='&month='.urlencode($month);
  375. if ($year) $param.='&year=' .urlencode($year);
  376. if ($day_lim) $param.='&day_lim='.urlencode($day_lim);
  377. if ($month_lim) $param.='&month_lim='.urlencode($month_lim);
  378. if ($year_lim) $param.='&year_lim=' .urlencode($year_lim);
  379. if ($search_ref) $param.='&search_ref=' .urlencode($search_ref);
  380. if ($search_refcustomer) $param.='&search_refcustomer=' .urlencode($search_refcustomer);
  381. if ($search_societe) $param.='&search_societe=' .urlencode($search_societe);
  382. if ($search_sale > 0) $param.='&search_sale=' .urlencode($search_sale);
  383. if ($search_user > 0) $param.='&search_user=' .urlencode($search_user);
  384. if ($search_product_category > 0) $param.='$search_product_category=' .urlencode($search_product_category);
  385. if ($search_montant_ht != '') $param.='&search_montant_ht='.urlencode($search_montant_ht);
  386. if ($search_montant_vat != '') $param.='&search_montant_vat='.urlencode($search_montant_vat);
  387. if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc);
  388. if ($search_status != '') $param.='&search_status='.urlencode($search_status);
  389. if ($search_paymentmode > 0) $param.='search_paymentmode='.urlencode($search_paymentmode);
  390. if ($show_files) $param.='&show_files=' .$show_files;
  391. if ($option) $param.="&option=".$option;
  392. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  393. // Add $param from extra fields
  394. foreach ($search_array_options as $key => $val)
  395. {
  396. $crit=$val;
  397. $tmpkey=preg_replace('/search_options_/','',$key);
  398. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  399. }
  400. $arrayofmassactions=array(
  401. 'presend'=>$langs->trans("SendByMail"),
  402. 'builddoc'=>$langs->trans("PDFMerge")
  403. );
  404. if ($user->rights->facture->supprimer)
  405. {
  406. //if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED))
  407. if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED))
  408. {
  409. // mass deletion never possible on invoices on such situation
  410. }
  411. else
  412. {
  413. $arrayofmassactions['delete']=$langs->trans("Delete");
  414. }
  415. }
  416. if ($massaction == 'presend') $arrayofmassactions=array();
  417. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  418. $i = 0;
  419. print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  420. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  421. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  422. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  423. print '<input type="hidden" name="action" value="list">';
  424. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  425. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  426. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  427. print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->name:''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit);
  428. if ($massaction == 'presend')
  429. {
  430. $langs->load("mails");
  431. if (! GETPOST('cancel'))
  432. {
  433. $objecttmp=new Facture($db);
  434. $listofselectedid=array();
  435. $listofselectedthirdparties=array();
  436. $listofselectedref=array();
  437. foreach($arrayofselected as $toselectid)
  438. {
  439. $result=$objecttmp->fetch($toselectid);
  440. if ($result > 0)
  441. {
  442. $listofselectedid[$toselectid]=$toselectid;
  443. $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
  444. $listofselectedthirdparties[$thirdpartyid]=$thirdpartyid;
  445. $listofselectedref[$thirdpartyid][$toselectid]=$objecttmp->ref;
  446. }
  447. }
  448. }
  449. print '<input type="hidden" name="massaction" value="confirm_presend">';
  450. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  451. $formmail = new FormMail($db);
  452. dol_fiche_head(null, '', '');
  453. $topicmail="SendBillRef";
  454. $modelmail="facture_send";
  455. // Cree l'objet formulaire mail
  456. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  457. $formmail = new FormMail($db);
  458. $formmail->withform=-1;
  459. $formmail->fromtype = 'user';
  460. $formmail->fromid = $user->id;
  461. $formmail->fromname = $user->getFullName($langs);
  462. $formmail->frommail = $user->email;
  463. if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 1)) // If bit 1 is set
  464. {
  465. $formmail->trackid='inv'.$object->id;
  466. }
  467. if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
  468. {
  469. include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  470. $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'inv'.$object->id);
  471. }
  472. $formmail->withfrom=1;
  473. $liste=$langs->trans("AllRecipientSelected");
  474. if (count($listofselectedthirdparties) == 1)
  475. {
  476. $liste=array();
  477. $thirdpartyid=array_shift($listofselectedthirdparties);
  478. $soc=new Societe($db);
  479. $soc->fetch($thirdpartyid);
  480. foreach ($soc->thirdparty_and_contact_email_array(1) as $key=>$value)
  481. {
  482. $liste[$key]=$value;
  483. }
  484. $formmail->withtoreadonly=0;
  485. }
  486. else
  487. {
  488. $formmail->withtoreadonly=1;
  489. }
  490. $formmail->withto=$liste;
  491. $formmail->withtofree=0;
  492. $formmail->withtocc=1;
  493. $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
  494. $formmail->withtopic=$langs->transnoentities($topicmail, '__REF__', '__REFCLIENT__');
  495. $formmail->withfile=$langs->trans("OnlyPDFattachmentSupported");
  496. $formmail->withbody=1;
  497. $formmail->withdeliveryreceipt=1;
  498. $formmail->withcancel=1;
  499. // Tableau des substitutions
  500. $formmail->substit['__REF__']='__REF__'; // We want to keep the tag
  501. $formmail->substit['__SIGNATURE__']=$user->signature;
  502. $formmail->substit['__REFCLIENT__']='__REFCLIENT__'; // We want to keep the tag
  503. $formmail->substit['__PERSONALIZED__']='';
  504. $formmail->substit['__CONTACTCIVNAME__']='';
  505. // Tableau des parametres complementaires du post
  506. $formmail->param['action']=$action;
  507. $formmail->param['models']=$modelmail;
  508. $formmail->param['models_id']=GETPOST('modelmailselected','int');
  509. $formmail->param['facid']=join(',',$arrayofselected);
  510. // TODO We should use $formmail->param['id']=join(',',$arrayofselected);
  511. //$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  512. print $formmail->get_form();
  513. dol_fiche_end();
  514. }
  515. if ($sall)
  516. {
  517. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  518. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  519. }
  520. // If the user can view prospects other than his'
  521. $moreforfilter='';
  522. if ($user->rights->societe->client->voir || $socid)
  523. {
  524. $langs->load("commercial");
  525. $moreforfilter.='<div class="divsearchfield">';
  526. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  527. $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300');
  528. $moreforfilter.='</div>';
  529. }
  530. // If the user can view prospects other than his'
  531. if ($user->rights->societe->client->voir || $socid)
  532. {
  533. $moreforfilter.='<div class="divsearchfield">';
  534. $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
  535. $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  536. $moreforfilter.='</div>';
  537. }
  538. // If the user can view prospects other than his'
  539. if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
  540. {
  541. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  542. $moreforfilter.='<div class="divsearchfield">';
  543. $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
  544. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  545. $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1);
  546. $moreforfilter.='</div>';
  547. }
  548. $parameters=array();
  549. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  550. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  551. else $moreforfilter = $hookmanager->resPrint;
  552. if ($moreforfilter)
  553. {
  554. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  555. print $moreforfilter;
  556. print '</div>';
  557. }
  558. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  559. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  560. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  561. print '<tr class="liste_titre">';
  562. if (! empty($arrayfields['f.facnumber']['checked'])) print_liste_field_titre($arrayfields['f.facnumber']['label'],$_SERVER['PHP_SELF'],'f.facnumber','',$param,'',$sortfield,$sortorder);
  563. if (! empty($arrayfields['f.ref_client']['checked'])) print_liste_field_titre($arrayfields['f.ref_client']['label'],$_SERVER["PHP_SELF"],'f.ref_client','',$param,'',$sortfield,$sortorder);
  564. if (! empty($arrayfields['f.date']['checked'])) print_liste_field_titre($arrayfields['f.date']['label'],$_SERVER['PHP_SELF'],'f.datef','',$param,'align="center"',$sortfield,$sortorder);
  565. 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);
  566. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER['PHP_SELF'],'s.nom','',$param,'',$sortfield,$sortorder);
  567. if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
  568. if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
  569. if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  570. 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);
  571. if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
  572. 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);
  573. 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);
  574. 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);
  575. 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);
  576. if (! empty($arrayfields['am']['checked'])) print_liste_field_titre($arrayfields['am']['label'],$_SERVER['PHP_SELF'],'am','',$param,'align="right"',$sortfield,$sortorder);
  577. if (! empty($arrayfields['rtp']['checked'])) print_liste_field_titre($arrayfields['rtp']['label'],$_SERVER['PHP_SELF'],'rtp','',$param,'align="right"',$sortfield,$sortorder);
  578. // Extra fields
  579. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  580. {
  581. foreach($extrafields->attribute_label as $key => $val)
  582. {
  583. if (! empty($arrayfields["ef.".$key]['checked']))
  584. {
  585. $align=$extrafields->getAlignFlag($key);
  586. print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  587. }
  588. }
  589. }
  590. // Hook fields
  591. $parameters=array('arrayfields'=>$arrayfields);
  592. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  593. print $hookmanager->resPrint;
  594. 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);
  595. 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);
  596. if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye,am","",$param,'align="right"',$sortfield,$sortorder);
  597. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
  598. print "</tr>\n";
  599. // Filters lines
  600. print '<tr class="liste_titre">';
  601. // Ref
  602. if (! empty($arrayfields['f.facnumber']['checked']))
  603. {
  604. print '<td class="liste_titre" align="left">';
  605. print '<input class="flat" size="6" type="text" name="search_ref" value="'.$search_ref.'">';
  606. print '</td>';
  607. }
  608. // Ref customer
  609. if (! empty($arrayfields['f.ref_client']['checked']))
  610. {
  611. print '<td class="liste_titre">';
  612. print '<input class="flat" size="6" type="text" name="search_refcustomer" value="'.$search_refcustomer.'">';
  613. print '</td>';
  614. }
  615. // Date invoice
  616. if (! empty($arrayfields['f.date']['checked']))
  617. {
  618. print '<td class="liste_titre" align="center">';
  619. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  620. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  621. $formother->select_year($year?$year:-1,'year',1, 20, 5);
  622. print '</td>';
  623. }
  624. // Date due
  625. if (! empty($arrayfields['f.date_lim_reglement']['checked']))
  626. {
  627. print '<td class="liste_titre" align="center">';
  628. 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.'">';
  629. print '<input class="flat" type="text" size="1" maxlength="2" name="month_lim" value="'.$month_lim.'">';
  630. $formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5);
  631. print '<br><input type="checkbox" name="option" value="late"'.($option == 'late'?' checked':'').'> '.$langs->trans("Late");
  632. print '</td>';
  633. }
  634. // Thirpdarty
  635. if (! empty($arrayfields['s.nom']['checked']))
  636. {
  637. print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_societe" value="'.$search_societe.'"></td>';
  638. }
  639. // Town
  640. 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>';
  641. // Zip
  642. 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>';
  643. // State
  644. if (! empty($arrayfields['state.nom']['checked']))
  645. {
  646. print '<td class="liste_titre">';
  647. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  648. print '</td>';
  649. }
  650. // Country
  651. if (! empty($arrayfields['country.code_iso']['checked']))
  652. {
  653. print '<td class="liste_titre" align="center">';
  654. print $form->select_country($search_country,'search_country','',0,'maxwidth100');
  655. print '</td>';
  656. }
  657. // Company type
  658. if (! empty($arrayfields['typent.code']['checked']))
  659. {
  660. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  661. 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));
  662. print '</td>';
  663. }
  664. // Payment mode
  665. if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
  666. {
  667. print '<td class="liste_titre" align="left">';
  668. $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 0, 1, 10);
  669. print '</td>';
  670. }
  671. if (! empty($arrayfields['f.total_ht']['checked']))
  672. {
  673. // Amount
  674. print '<td class="liste_titre" align="right">';
  675. print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.$search_montant_ht.'">';
  676. print '</td>';
  677. }
  678. if (! empty($arrayfields['f.total_vat']['checked']))
  679. {
  680. // Amount
  681. print '<td class="liste_titre" align="right">';
  682. print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.$search_montant_vat.'">';
  683. print '</td>';
  684. }
  685. if (! empty($arrayfields['f.total_ttc']['checked']))
  686. {
  687. // Amount
  688. print '<td class="liste_titre" align="right">';
  689. print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.$search_montant_ttc.'">';
  690. print '</td>';
  691. }
  692. if (! empty($arrayfields['am']['checked']))
  693. {
  694. print '<td class="liste_titre" align="right">';
  695. print '</td>';
  696. }
  697. if (! empty($arrayfields['rtp']['checked']))
  698. {
  699. print '<td class="liste_titre" align="right">';
  700. print '</td>';
  701. }
  702. // Extra fields
  703. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  704. {
  705. foreach($extrafields->attribute_label as $key => $val)
  706. {
  707. if (! empty($arrayfields["ef.".$key]['checked']))
  708. {
  709. $align=$extrafields->getAlignFlag($key);
  710. $typeofextrafield=$extrafields->attribute_type[$key];
  711. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  712. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  713. {
  714. $crit=$val;
  715. $tmpkey=preg_replace('/search_options_/','',$key);
  716. $searchclass='';
  717. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  718. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  719. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  720. }
  721. print '</td>';
  722. }
  723. }
  724. }
  725. // Fields from hook
  726. $parameters=array('arrayfields'=>$arrayfields);
  727. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  728. print $hookmanager->resPrint;
  729. // Date creation
  730. if (! empty($arrayfields['f.datec']['checked']))
  731. {
  732. print '<td class="liste_titre">';
  733. print '</td>';
  734. }
  735. // Date modification
  736. if (! empty($arrayfields['f.tms']['checked']))
  737. {
  738. print '<td class="liste_titre">';
  739. print '</td>';
  740. }
  741. // Status
  742. if (! empty($arrayfields['f.fk_statut']['checked']))
  743. {
  744. print '<td class="liste_titre maxwidthonsmartphone" align="right">';
  745. $liststatus=array('0'=>$langs->trans("BillShortStatusDraft"), '1'=>$langs->trans("BillShortStatusNotPaid"), '2'=>$langs->trans("BillShortStatusPaid"), '3'=>$langs->trans("BillShortStatusCanceled"));
  746. print $form->selectarray('search_status', $liststatus, $search_status, 1);
  747. print '</td>';
  748. }
  749. // Action column
  750. print '<td class="liste_titre" align="middle">';
  751. $searchpitco=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1);
  752. print $searchpitco;
  753. print '</td>';
  754. print "</tr>\n";
  755. if ($num > 0)
  756. {
  757. $i=0;
  758. $var=true;
  759. $totalarray=array();
  760. while ($i < min($num,$limit))
  761. {
  762. $obj = $db->fetch_object($resql);
  763. $var=!$var;
  764. $datelimit=$db->jdate($obj->datelimite);
  765. $facturestatic->id=$obj->facid;
  766. $facturestatic->ref=$obj->facnumber;
  767. $facturestatic->type=$obj->type;
  768. $facturestatic->statut=$obj->fk_statut;
  769. $facturestatic->date_lim_reglement=$db->jdate($obj->datelimite);
  770. print '<tr '.$bc[$var].'>';
  771. if (! empty($arrayfields['f.facnumber']['checked']))
  772. {
  773. print '<td class="nowrap">';
  774. $notetoshow=dol_string_nohtmltag(($user->societe_id>0?$obj->note_public:$obj->note_private),1);
  775. $paiement = $facturestatic->getSommePaiement();
  776. $remaintopay = $obj->total_ttc - $paiement;
  777. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  778. print '<td class="nobordernopadding nowrap">';
  779. print $facturestatic->getNomUrl(1,'',200,0,$notetoshow);
  780. print $obj->increment;
  781. print '</td>';
  782. print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
  783. if (! empty($obj->note_private))
  784. {
  785. print ' <span class="note">';
  786. print '<a href="'.DOL_URL_ROOT.'/compta/facture/note.php?id='.$obj->facid.'">'.img_picto($langs->trans("ViewPrivateNote"),'object_generic').'</a>';
  787. print '</span>';
  788. }
  789. $filename=dol_sanitizeFileName($obj->facnumber);
  790. $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->facnumber);
  791. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->facid;
  792. print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
  793. print '</td>';
  794. print '</tr>';
  795. print '</table>';
  796. print "</td>\n";
  797. if (! $i) $totalarray['nbfield']++;
  798. }
  799. // Customer ref
  800. if (! empty($arrayfields['f.ref_client']['checked']))
  801. {
  802. print '<td class="nowrap">';
  803. print $obj->ref_client;
  804. print '</td>';
  805. if (! $i) $totalarray['nbfield']++;
  806. }
  807. // Date
  808. if (! empty($arrayfields['f.date']['checked']))
  809. {
  810. print '<td align="center" class="nowrap">';
  811. print dol_print_date($db->jdate($obj->df),'day');
  812. print '</td>';
  813. if (! $i) $totalarray['nbfield']++;
  814. }
  815. // Date limit
  816. if (! empty($arrayfields['f.date_lim_reglement']['checked']))
  817. {
  818. print '<td align="center" class="nowrap">'.dol_print_date($datelimit,'day');
  819. if ($facturestatic->hasDelay())
  820. {
  821. print img_warning($langs->trans('Late'));
  822. }
  823. print '</td>';
  824. if (! $i) $totalarray['nbfield']++;
  825. }
  826. // Third party
  827. if (! empty($arrayfields['s.nom']['checked']))
  828. {
  829. print '<td>';
  830. $thirdparty=new Societe($db);
  831. $thirdparty->id=$obj->socid;
  832. $thirdparty->name=$obj->name;
  833. $thirdparty->client=$obj->client;
  834. $thirdparty->code_client=$obj->code_client;
  835. print $thirdparty->getNomUrl(1,'customer');
  836. print '</td>';
  837. if (! $i) $totalarray['nbfield']++;
  838. }
  839. // Town
  840. if (! empty($arrayfields['s.town']['checked']))
  841. {
  842. print '<td class="nocellnopadd">';
  843. print $obj->town;
  844. print '</td>';
  845. if (! $i) $totalarray['nbfield']++;
  846. }
  847. // Zip
  848. if (! empty($arrayfields['s.zip']['checked']))
  849. {
  850. print '<td class="nocellnopadd">';
  851. print $obj->zip;
  852. print '</td>';
  853. if (! $i) $totalarray['nbfield']++;
  854. }
  855. // State
  856. if (! empty($arrayfields['state.nom']['checked']))
  857. {
  858. print "<td>".$obj->state_name."</td>\n";
  859. if (! $i) $totalarray['nbfield']++;
  860. }
  861. // Country
  862. if (! empty($arrayfields['country.code_iso']['checked']))
  863. {
  864. print '<td align="center">';
  865. $tmparray=getCountry($obj->fk_pays,'all');
  866. print $tmparray['label'];
  867. print '</td>';
  868. if (! $i) $totalarray['nbfield']++;
  869. }
  870. // Type ent
  871. if (! empty($arrayfields['typent.code']['checked']))
  872. {
  873. print '<td align="center">';
  874. if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
  875. print $typenArray[$obj->typent_code];
  876. print '</td>';
  877. if (! $i) $totalarray['nbfield']++;
  878. }
  879. // Payment mode
  880. if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
  881. {
  882. print '<td>';
  883. $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
  884. print '</td>';
  885. if (! $i) $totalarray['nbfield']++;
  886. }
  887. // Amount HT
  888. if (! empty($arrayfields['f.total_ht']['checked']))
  889. {
  890. print '<td align="right">'.price($obj->total_ht)."</td>\n";
  891. if (! $i) $totalarray['nbfield']++;
  892. if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
  893. $totalarray['totalht'] += $obj->total_ht;
  894. }
  895. // Amount VAT
  896. if (! empty($arrayfields['f.total_vat']['checked']))
  897. {
  898. print '<td align="right">'.price($obj->total_vat)."</td>\n";
  899. if (! $i) $totalarray['nbfield']++;
  900. if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
  901. $totalarray['totalvat'] += $obj->total_vat;
  902. }
  903. // Amount TTC
  904. if (! empty($arrayfields['f.total_ttc']['checked']))
  905. {
  906. print '<td align="right">'.price($obj->total_ttc)."</td>\n";
  907. if (! $i) $totalarray['nbfield']++;
  908. if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
  909. $totalarray['totalttc'] += $obj->total_ttc;
  910. }
  911. if (! empty($arrayfields['am']['checked']))
  912. {
  913. print '<td align="right">'.(! empty($paiement)?price($paiement,0,$langs):'&nbsp;').'</td>';
  914. if (! $i) $totalarray['nbfield']++;
  915. if (! $i) $totalarray['totalamfield']=$totalarray['nbfield'];
  916. $totalarray['totalam'] += $paiement;
  917. }
  918. if (! empty($arrayfields['rtp']['checked']))
  919. {
  920. print '<td align="right">'.(! empty($remaintopay)?price($remaintopay,0,$langs):'&nbsp;').'</td>';
  921. if (! $i) $totalarray['nbfield']++;
  922. if (! $i) $totalarray['totalrtpfield']=$totalarray['nbfield'];
  923. $totalarray['totalrtp'] += $remaintopay;
  924. }
  925. // Extra fields
  926. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  927. {
  928. foreach($extrafields->attribute_label as $key => $val)
  929. {
  930. if (! empty($arrayfields["ef.".$key]['checked']))
  931. {
  932. print '<td';
  933. $align=$extrafields->getAlignFlag($key);
  934. if ($align) print ' align="'.$align.'"';
  935. print '>';
  936. $tmpkey='options_'.$key;
  937. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  938. print '</td>';
  939. if (! $i) $totalarray['nbfield']++;
  940. }
  941. }
  942. }
  943. // Fields from hook
  944. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  945. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  946. print $hookmanager->resPrint;
  947. // Date creation
  948. if (! empty($arrayfields['f.datec']['checked']))
  949. {
  950. print '<td align="center" class="nowrap">';
  951. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  952. print '</td>';
  953. if (! $i) $totalarray['nbfield']++;
  954. }
  955. // Date modification
  956. if (! empty($arrayfields['f.tms']['checked']))
  957. {
  958. print '<td align="center" class="nowrap">';
  959. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  960. print '</td>';
  961. if (! $i) $totalarray['nbfield']++;
  962. }
  963. // Status
  964. if (! empty($arrayfields['f.fk_statut']['checked']))
  965. {
  966. print '<td align="right" class="nowrap">';
  967. print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$paiement,$obj->type);
  968. print "</td>";
  969. if (! $i) $totalarray['nbfield']++;
  970. }
  971. // Action column
  972. print '<td class="nowrap" align="center">';
  973. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  974. {
  975. $selected=0;
  976. if (in_array($obj->facid, $arrayofselected)) $selected=1;
  977. print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected?' checked="checked"':'').'>';
  978. }
  979. print '</td>' ;
  980. if (! $i) $totalarray['nbfield']++;
  981. print "</tr>\n";
  982. $i++;
  983. }
  984. // Show total line
  985. if (isset($totalarray['totalhtfield']))
  986. {
  987. print '<tr class="liste_total">';
  988. $i=0;
  989. while ($i < $totalarray['nbfield'])
  990. {
  991. $i++;
  992. if ($i == 1)
  993. {
  994. if ($num < $limit) print '<td align="left">'.$langs->trans("Total").'</td>';
  995. else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
  996. }
  997. elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
  998. elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
  999. elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
  1000. elseif ($totalarray['totalamfield'] == $i) print '<td align="right">'.price($totalarray['totalam']).'</td>';
  1001. elseif ($totalarray['totalrtpfield'] == $i) print '<td align="right">'.price($totalarray['totalrtp']).'</td>';
  1002. else print '<td></td>';
  1003. }
  1004. print '</tr>';
  1005. }
  1006. }
  1007. $db->free($resql);
  1008. $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1009. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  1010. print $hookmanager->resPrint;
  1011. print "</table>\n";
  1012. print "</form>\n";
  1013. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
  1014. {
  1015. /*
  1016. * Show list of available documents
  1017. */
  1018. $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1019. $urlsource.=str_replace('&amp;','&',$param);
  1020. $filedir=$diroutputmassaction;
  1021. $genallowed=$user->rights->facture->lire;
  1022. $delallowed=$user->rights->facture->lire;
  1023. print '<br><a name="show_files"></a>';
  1024. $paramwithoutshowfiles=preg_replace('/show_files=1&?/','',$param);
  1025. $title=$langs->trans("MassFilesArea").' <a href="'.$_SERVER["PHP_SELF"].'?'.$paramwithoutshowfiles.'">('.$langs->trans("Hide").')</a>';
  1026. print $formfile->showdocuments('massfilesarea_invoices','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
  1027. }
  1028. else
  1029. {
  1030. print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
  1031. }
  1032. }
  1033. else
  1034. {
  1035. dol_print_error($db);
  1036. }
  1037. llxFooter();
  1038. $db->close();