list.php 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  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. * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/compta/facture/list.php
  31. * \ingroup facture
  32. * \brief List of customer invoices
  33. */
  34. require '../../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  39. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  45. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  46. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  47. if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  48. if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  49. $langs->load('bills');
  50. $langs->load('companies');
  51. $langs->load('products');
  52. $sall=trim(GETPOST('sall', 'alphanohtml'));
  53. $projectid=(GETPOST('projectid')?GETPOST('projectid','int'):0);
  54. $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility
  55. $ref=GETPOST('ref','alpha');
  56. $socid=GETPOST('socid','int');
  57. $action=GETPOST('action','alpha');
  58. $massaction=GETPOST('massaction','alpha');
  59. $show_files=GETPOST('show_files','int');
  60. $confirm=GETPOST('confirm','alpha');
  61. $toselect = GETPOST('toselect', 'array');
  62. $lineid=GETPOST('lineid','int');
  63. $userid=GETPOST('userid','int');
  64. $search_product_category=GETPOST('search_product_category','int');
  65. $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
  66. $search_refcustomer=GETPOST('search_refcustomer','alpha');
  67. $search_type=GETPOST('search_type','int');
  68. $search_societe=GETPOST('search_societe','alpha');
  69. $search_montant_ht=GETPOST('search_montant_ht','alpha');
  70. $search_montant_vat=GETPOST('search_montant_vat','alpha');
  71. $search_montant_localtax1=GETPOST('search_montant_localtax1','alpha');
  72. $search_montant_localtax2=GETPOST('search_montant_localtax2','alpha');
  73. $search_montant_ttc=GETPOST('search_montant_ttc','alpha');
  74. $search_status=GETPOST('search_status','int');
  75. $search_paymentmode=GETPOST('search_paymentmode','int');
  76. $search_town=GETPOST('search_town','alpha');
  77. $search_zip=GETPOST('search_zip','alpha');
  78. $search_state=trim(GETPOST("search_state"));
  79. $search_country=GETPOST("search_country",'int');
  80. $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
  81. $search_user = GETPOST('search_user','int');
  82. $search_sale = GETPOST('search_sale','int');
  83. $day = GETPOST('day','int');
  84. $month = GETPOST('month','int');
  85. $year = GETPOST('year','int');
  86. $day_lim = GETPOST('day_lim','int');
  87. $month_lim = GETPOST('month_lim','int');
  88. $year_lim = GETPOST('year_lim','int');
  89. $option = GETPOST('option');
  90. if ($option == 'late') $filter = 'paye:0';
  91. $filtre = GETPOST('filtre');
  92. $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
  93. $sortfield = GETPOST("sortfield",'alpha');
  94. $sortorder = GETPOST("sortorder",'alpha');
  95. $page = GETPOST("page",'int');
  96. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  97. $offset = $limit * $page;
  98. if (! $sortorder && ! empty($conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER) && $search_status == 1) $sortorder=$conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER;
  99. if (! $sortorder) $sortorder='DESC';
  100. if (! $sortfield) $sortfield='f.datef';
  101. $pageprev = $page - 1;
  102. $pagenext = $page + 1;
  103. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  104. $contextpage='invoicelist';
  105. // Security check
  106. $fieldid = (! empty($ref)?'facnumber':'rowid');
  107. if (! empty($user->societe_id)) $socid=$user->societe_id;
  108. $result = restrictedArea($user, 'facture', $id,'','','fk_soc',$fieldid);
  109. $diroutputmassaction=$conf->facture->dir_output . '/temp/massgeneration/'.$user->id;
  110. $object=new Facture($db);
  111. $now=dol_now();
  112. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  113. $hookmanager->initHooks(array('invoicelist'));
  114. $extrafields = new ExtraFields($db);
  115. // fetch optionals attributes and labels
  116. $extralabels = $extrafields->fetch_name_optionals_label('facture');
  117. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  118. // List of fields to search into when doing a "search in all"
  119. $fieldstosearchall = array(
  120. 'f.facnumber'=>'Ref',
  121. 'f.ref_client'=>'RefCustomer',
  122. 'pd.description'=>'Description',
  123. 's.nom'=>"ThirdParty",
  124. 'f.note_public'=>'NotePublic',
  125. );
  126. if (empty($user->socid)) $fieldstosearchall["f.note_private"]="NotePrivate";
  127. $checkedtypetiers=0;
  128. $arrayfields=array(
  129. 'f.facnumber'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
  130. 'f.ref_client'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
  131. 'f.type'=>array('label'=>$langs->trans("Type"), 'checked'=>0),
  132. 'f.date'=>array('label'=>$langs->trans("DateInvoice"), 'checked'=>1),
  133. 'f.date_lim_reglement'=>array('label'=>$langs->trans("DateDue"), 'checked'=>1),
  134. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
  135. 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
  136. 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
  137. 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
  138. 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
  139. 'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
  140. 'f.fk_mode_reglement'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>1),
  141. 'f.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
  142. 'f.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0),
  143. 'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax1_assuj=="1"),
  144. 'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax2_assuj=="1"),
  145. 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0),
  146. 'dynamount_payed'=>array('label'=>$langs->trans("Received"), 'checked'=>0),
  147. 'rtp'=>array('label'=>$langs->trans("Rest"), 'checked'=>0),
  148. 'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  149. 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  150. 'f.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  151. );
  152. // Extra fields
  153. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  154. {
  155. foreach($extrafields->attribute_label as $key => $val)
  156. {
  157. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  158. }
  159. }
  160. /*
  161. * Actions
  162. */
  163. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  164. if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  165. $parameters=array('socid'=>$socid);
  166. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  167. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  168. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  169. // Do we click on purge search criteria ?
  170. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter") || GETPOST("button_removefilter.x")) // Both test are required to be compatible with all browsers
  171. {
  172. $search_user='';
  173. $search_sale='';
  174. $search_product_category='';
  175. $search_ref='';
  176. $search_refcustomer='';
  177. $search_type='';
  178. $search_project='';
  179. $search_societe='';
  180. $search_montant_ht='';
  181. $search_montant_vat='';
  182. $search_montant_localtax1='';
  183. $search_montant_localtax2='';
  184. $search_montant_ttc='';
  185. $search_status='';
  186. $search_paymentmode='';
  187. $search_town='';
  188. $search_zip="";
  189. $search_state="";
  190. $search_type='';
  191. $search_country='';
  192. $search_type_thirdparty='';
  193. $day='';
  194. $year='';
  195. $month='';
  196. $option='';
  197. $filter='';
  198. $day_lim='';
  199. $year_lim='';
  200. $month_lim='';
  201. $toselect='';
  202. $search_array_options=array();
  203. }
  204. if (empty($reshook))
  205. {
  206. $objectclass='Facture';
  207. $objectlabel='Invoices';
  208. $permtoread = $user->rights->facture->lire;
  209. $permtodelete = $user->rights->facture->supprimer;
  210. $uploaddir = $conf->facture->dir_output;
  211. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  212. }
  213. if ($massaction == 'withdrawrequest')
  214. {
  215. $langs->load("withdrawals");
  216. if (!$user->rights->prelevement->bons->creer)
  217. {
  218. $error++;
  219. setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
  220. }
  221. else
  222. {
  223. //Checking error
  224. $error = 0;
  225. $arrayofselected=is_array($toselect)?$toselect:array();
  226. $listofbills=array();
  227. foreach($arrayofselected as $toselectid)
  228. {
  229. $objecttmp=new Facture($db);
  230. $result=$objecttmp->fetch($toselectid);
  231. if ($result > 0)
  232. {
  233. $totalpaye = $objecttmp->getSommePaiement();
  234. $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
  235. $totaldeposits = $objecttmp->getSumDepositsUsed();
  236. $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
  237. $listofbills[] = $objecttmp;
  238. if($objecttmp->paye || $objecttmp->resteapayer==0){
  239. $error++;
  240. setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
  241. } else if($objecttmp->resteapayer<0){
  242. $error++;
  243. setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
  244. }
  245. if(!($objecttmp->statut > Facture::STATUS_DRAFT)){
  246. $error++;
  247. setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
  248. }
  249. $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
  250. $rsql .= " , pfd.date_traite as date_traite";
  251. $rsql .= " , pfd.amount";
  252. $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
  253. $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
  254. $rsql .= " , ".MAIN_DB_PREFIX."user as u";
  255. $rsql .= " WHERE fk_facture = ".$objecttmp->id;
  256. $rsql .= " AND pfd.fk_user_demande = u.rowid";
  257. $rsql .= " AND pfd.traite = 0";
  258. $rsql .= " ORDER BY pfd.date_demande DESC";
  259. $result_sql = $db->query($rsql);
  260. if ($result_sql)
  261. {
  262. $numprlv = $db->num_rows($result_sql);
  263. }
  264. if($numprlv>0){
  265. $error++;
  266. setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'errors');
  267. }
  268. if(!empty($objecttmp->mode_reglement_id ) && $objecttmp->mode_reglement_id != 3){
  269. $error++;
  270. setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
  271. }
  272. }
  273. }
  274. //Massive withdraw request
  275. if(!empty($listofbills) && empty($error))
  276. {
  277. $nbwithdrawrequestok=0;
  278. foreach($listofbills as $aBill)
  279. {
  280. $db->begin();
  281. $result = $aBill->demande_prelevement($user, $aBill->resteapayer);
  282. if ($result > 0)
  283. {
  284. $db->commit();
  285. $nbwithdrawrequestok++;
  286. }
  287. else
  288. {
  289. $db->rollback();
  290. setEventMessages($aBill->error, $aBill->errors, 'errors');
  291. }
  292. }
  293. if ($nbwithdrawrequestok > 0)
  294. {
  295. setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
  296. }
  297. }
  298. }
  299. }
  300. /*
  301. * View
  302. */
  303. $form = new Form($db);
  304. $formother = new FormOther($db);
  305. $formfile = new FormFile($db);
  306. $bankaccountstatic=new Account($db);
  307. $facturestatic=new Facture($db);
  308. $formcompany=new FormCompany($db);
  309. llxHeader('',$langs->trans('CustomersInvoices'),'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
  310. $sql = 'SELECT';
  311. if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
  312. $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,';
  313. $sql.= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,';
  314. $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,';
  315. $sql.= ' f.paye as paye, f.fk_statut,';
  316. $sql.= ' f.datec as date_creation, f.tms as date_update,';
  317. $sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
  318. $sql.= " typent.code as typent_code,";
  319. $sql.= " state.code_departement as state_code, state.nom as state_name";
  320. // We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0)
  321. // TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
  322. if (! $sall) $sql.= ', SUM(pf.amount) as dynamount_payed';
  323. // Add fields from extrafields
  324. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  325. // Add fields from hooks
  326. $parameters=array();
  327. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  328. $sql.=$hookmanager->resPrint;
  329. $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  330. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  331. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  332. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  333. $sql.= ', '.MAIN_DB_PREFIX.'facture as f';
  334. 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)";
  335. if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
  336. if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture';
  337. if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  338. // We'll need this table joined to the select in order to filter by sale
  339. if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  340. if ($search_user > 0)
  341. {
  342. $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
  343. $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
  344. }
  345. $sql.= ' WHERE f.fk_soc = s.rowid';
  346. $sql.= ' AND f.entity IN ('.getEntity('facture').')';
  347. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  348. if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
  349. if ($socid > 0) $sql.= ' AND s.rowid = '.$socid;
  350. if ($userid)
  351. {
  352. if ($userid == -1) $sql.=' AND f.fk_user_author IS NULL';
  353. else $sql.=' AND f.fk_user_author = '.$userid;
  354. }
  355. if ($filtre)
  356. {
  357. $aFilter = explode(',', $filtre);
  358. foreach ($aFilter as $filter)
  359. {
  360. $filt = explode(':', $filter);
  361. $sql .= ' AND ' . trim($filt[0]) . ' = ' . trim($filt[1]);
  362. }
  363. }
  364. if ($search_ref) $sql .= natural_search('f.facnumber', $search_ref);
  365. if ($search_refcustomer) $sql .= natural_search('f.ref_client', $search_refcustomer);
  366. if ($search_type != '' && $search_type >= 0)
  367. {
  368. if ($search_type == '0') $sql.=" AND f.type = 0"; // standard
  369. if ($search_type == '1') $sql.=" AND f.type = 1"; // replacement
  370. if ($search_type == '2') $sql.=" AND f.type = 2"; // credit note
  371. if ($search_type == '3') $sql.=" AND f.type = 3"; // deposit
  372. if ($search_type == '4') $sql.=" AND f.type = 4"; // proforma
  373. if ($search_type == '5') $sql.=" AND f.type = 5"; // situation
  374. }
  375. if ($search_project) $sql .= natural_search('p.ref', $search_project);
  376. if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
  377. if ($search_town) $sql.= natural_search('s.town', $search_town);
  378. if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
  379. if ($search_state) $sql.= natural_search("state.nom",$search_state);
  380. if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
  381. if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
  382. if ($search_company) $sql .= natural_search('s.nom', $search_company);
  383. if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1);
  384. if ($search_montant_vat != '') $sql.= natural_search('f.tva', $search_montant_vat, 1);
  385. if ($search_montant_localtax1 != '') $sql.= natural_search('f.localtax1', $search_montant_localtax1, 1);
  386. if ($search_montant_localtax2 != '') $sql.= natural_search('f.localtax2', $search_montant_localtax2, 1);
  387. if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1);
  388. if ($search_status != '' && $search_status >= 0)
  389. {
  390. if ($search_status == '0') $sql.=" AND f.fk_statut = 0"; // draft
  391. if ($search_status == '1') $sql.=" AND f.fk_statut = 1"; // unpayed
  392. if ($search_status == '2') $sql.=" AND f.fk_statut = 2"; // payed Not that some corrupted 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)
  393. if ($search_status == '3') $sql.=" AND f.fk_statut = 3"; // abandonned
  394. }
  395. if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$search_paymentmode;
  396. if ($month > 0)
  397. {
  398. if ($year > 0 && empty($day))
  399. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  400. else if ($year > 0 && ! empty($day))
  401. $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))."'";
  402. else
  403. $sql.= " AND date_format(f.datef, '%m') = '".$month."'";
  404. }
  405. else if ($year > 0)
  406. {
  407. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  408. }
  409. if ($month_lim > 0)
  410. {
  411. if ($year_lim > 0 && empty($day_lim))
  412. $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))."'";
  413. else if ($year_lim > 0 && ! empty($day_lim))
  414. $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))."'";
  415. else
  416. $sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$db->escape($month_lim)."'";
  417. }
  418. else if ($year_lim > 0)
  419. {
  420. $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))."'";
  421. }
  422. if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->client->warning_delay)."'";
  423. if ($filter == 'paye:0') $sql.= " AND f.fk_statut = 1";
  424. if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
  425. if ($search_user > 0)
  426. {
  427. $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;
  428. }
  429. // Add where from extra fields
  430. foreach ($search_array_options as $key => $val)
  431. {
  432. $crit=$val;
  433. $tmpkey=preg_replace('/search_options_/','',$key);
  434. $typ=$extrafields->attribute_type[$tmpkey];
  435. $mode=0;
  436. if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
  437. if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
  438. {
  439. $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
  440. }
  441. }
  442. // Add where from hooks
  443. $parameters=array();
  444. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  445. $sql.=$hookmanager->resPrint;
  446. if (! $sall)
  447. {
  448. $sql.= ' GROUP BY f.rowid, f.facnumber, ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total, f.tva, f.total_ttc,';
  449. $sql.= ' f.localtax1, f.localtax2,';
  450. $sql.= ' f.datef, f.date_lim_reglement,';
  451. $sql.= ' f.paye, f.fk_statut,';
  452. $sql.= ' f.datec, f.tms,';
  453. $sql.= ' s.rowid, s.nom, s.town, s.zip, s.fk_pays, s.code_client, s.client, typent.code,';
  454. $sql.= ' state.code_departement, state.nom';
  455. foreach ($extrafields->attribute_label as $key => $val) //prevent error with sql_mode=only_full_group_by
  456. {
  457. $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : '');
  458. }
  459. }
  460. else
  461. {
  462. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  463. }
  464. $sql.= ' ORDER BY ';
  465. $listfield=explode(',',$sortfield);
  466. foreach ($listfield as $key => $value) $sql.= $listfield[$key].' '.$sortorder.',';
  467. $sql.= ' f.rowid DESC ';
  468. $nbtotalofrecords = '';
  469. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  470. {
  471. $result = $db->query($sql);
  472. $nbtotalofrecords = $db->num_rows($result);
  473. }
  474. $sql.= $db->plimit($limit+1,$offset);
  475. //print $sql;
  476. $resql = $db->query($sql);
  477. if ($resql)
  478. {
  479. $num = $db->num_rows($resql);
  480. $arrayofselected=is_array($toselect)?$toselect:array();
  481. if ($socid)
  482. {
  483. $soc = new Societe($db);
  484. $soc->fetch($socid);
  485. }
  486. $param='&socid='.$socid;
  487. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  488. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  489. if ($sall) $param.='&sall='.urlencode($sall);
  490. if ($day) $param.='&day='.urlencode($day);
  491. if ($month) $param.='&month='.urlencode($month);
  492. if ($year) $param.='&year=' .urlencode($year);
  493. if ($day_lim) $param.='&day_lim='.urlencode($day_lim);
  494. if ($month_lim) $param.='&month_lim='.urlencode($month_lim);
  495. if ($year_lim) $param.='&year_lim=' .urlencode($year_lim);
  496. if ($search_ref) $param.='&search_ref=' .urlencode($search_ref);
  497. if ($search_refcustomer) $param.='&search_refcustomer=' .urlencode($search_refcustomer);
  498. if ($search_type != '') $param.='&search_type='.urlencode($search_type);
  499. if ($search_societe) $param.='&search_societe=' .urlencode($search_societe);
  500. if ($search_sale > 0) $param.='&search_sale=' .urlencode($search_sale);
  501. if ($search_user > 0) $param.='&search_user=' .urlencode($search_user);
  502. if ($search_product_category > 0) $param.='$search_product_category=' .urlencode($search_product_category);
  503. if ($search_montant_ht != '') $param.='&search_montant_ht='.urlencode($search_montant_ht);
  504. if ($search_montant_vat != '') $param.='&search_montant_vat='.urlencode($search_montant_vat);
  505. if ($search_montant_localtax1 != '') $param.='&search_montant_localtax1='.urlencode($search_montant_localtax1);
  506. if ($search_montant_localtax2 != '') $param.='&search_montant_localtax2='.urlencode($search_montant_localtax2);
  507. if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc);
  508. if ($search_status != '') $param.='&search_status='.urlencode($search_status);
  509. if ($search_paymentmode > 0) $param.='search_paymentmode='.urlencode($search_paymentmode);
  510. if ($show_files) $param.='&show_files=' .$show_files;
  511. if ($option) $param.="&option=".$option;
  512. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  513. // Add $param from extra fields
  514. foreach ($search_array_options as $key => $val)
  515. {
  516. $crit=$val;
  517. $tmpkey=preg_replace('/search_options_/','',$key);
  518. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  519. }
  520. $arrayofmassactions=array(
  521. 'presend'=>$langs->trans("SendByMail"),
  522. 'builddoc'=>$langs->trans("PDFMerge"),
  523. );
  524. if ($conf->prelevement->enabled)
  525. {
  526. $langs->load("withdrawals");
  527. $arrayofmassactions['withdrawrequest']=$langs->trans("MakeWithdrawRequest");
  528. }
  529. if ($user->rights->facture->supprimer)
  530. {
  531. //if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED))
  532. if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED))
  533. {
  534. // mass deletion never possible on invoices on such situation
  535. }
  536. else
  537. {
  538. $arrayofmassactions['delete']=$langs->trans("Delete");
  539. }
  540. }
  541. if ($massaction == 'presend') $arrayofmassactions=array();
  542. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  543. $i = 0;
  544. print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  545. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  546. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  547. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  548. print '<input type="hidden" name="action" value="list">';
  549. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  550. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  551. print '<input type="hidden" name="page" value="'.$page.'">';
  552. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  553. print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->name:''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit);
  554. if ($massaction == 'presend')
  555. {
  556. $langs->load("mails");
  557. if (! GETPOST('cancel'))
  558. {
  559. $objecttmp=new Facture($db);
  560. $listofselectedid=array();
  561. $listofselectedthirdparties=array();
  562. $listofselectedref=array();
  563. foreach($arrayofselected as $toselectid)
  564. {
  565. $result=$objecttmp->fetch($toselectid);
  566. if ($result > 0)
  567. {
  568. $listofselectedid[$toselectid]=$toselectid;
  569. $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
  570. $listofselectedthirdparties[$thirdpartyid]=$thirdpartyid;
  571. $listofselectedref[$thirdpartyid][$toselectid]=$objecttmp->ref;
  572. }
  573. }
  574. }
  575. print '<input type="hidden" name="massaction" value="confirm_presend">';
  576. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  577. $formmail = new FormMail($db);
  578. dol_fiche_head(null, '', '');
  579. $topicmail="SendBillRef";
  580. $modelmail="facture_send";
  581. // Cree l'objet formulaire mail
  582. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  583. $formmail = new FormMail($db);
  584. $formmail->withform=-1;
  585. $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user'));
  586. if($formmail->fromtype === 'user'){
  587. $formmail->fromid = $user->id;
  588. }
  589. if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 1)) // If bit 1 is set
  590. {
  591. $formmail->trackid='inv'.$object->id;
  592. }
  593. if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
  594. {
  595. include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  596. $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'inv'.$object->id);
  597. }
  598. $formmail->withfrom=1;
  599. $liste=$langs->trans("AllRecipientSelected");
  600. if (count($listofselectedthirdparties) == 1)
  601. {
  602. $liste=array();
  603. $thirdpartyid=array_shift($listofselectedthirdparties);
  604. $soc=new Societe($db);
  605. $soc->fetch($thirdpartyid);
  606. foreach ($soc->thirdparty_and_contact_email_array(1) as $key=>$value)
  607. {
  608. $liste[$key]=$value;
  609. }
  610. $formmail->withtoreadonly=0;
  611. }
  612. else
  613. {
  614. $formmail->withtoreadonly=1;
  615. }
  616. $formmail->withto=$liste;
  617. $formmail->withtofree=0;
  618. $formmail->withtocc=1;
  619. $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
  620. $formmail->withtopic=$langs->transnoentities($topicmail, '__REF__', '__REFCLIENT__');
  621. $formmail->withfile=$langs->trans("OnlyPDFattachmentSupported");
  622. $formmail->withbody=1;
  623. $formmail->withdeliveryreceipt=1;
  624. $formmail->withcancel=1;
  625. // Tableau des substitutions
  626. $formmail->substit['__REF__']='__REF__'; // We want to keep the tag
  627. $formmail->substit['__SIGNATURE__']=$user->signature;
  628. $formmail->substit['__REFCLIENT__']='__REFCLIENT__'; // We want to keep the tag
  629. $formmail->substit['__PERSONALIZED__']='';
  630. $formmail->substit['__CONTACTCIVNAME__']='';
  631. // Tableau des parametres complementaires du post
  632. $formmail->param['action']=$action;
  633. $formmail->param['models']=$modelmail;
  634. $formmail->param['models_id']=GETPOST('modelmailselected','int');
  635. $formmail->param['facid']=join(',',$arrayofselected);
  636. // TODO We should use $formmail->param['id']=join(',',$arrayofselected);
  637. //$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  638. print $formmail->get_form();
  639. dol_fiche_end();
  640. }
  641. if ($sall)
  642. {
  643. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  644. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  645. }
  646. // If the user can view prospects other than his'
  647. $moreforfilter='';
  648. if ($user->rights->societe->client->voir || $socid)
  649. {
  650. $langs->load("commercial");
  651. $moreforfilter.='<div class="divsearchfield">';
  652. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  653. $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300');
  654. $moreforfilter.='</div>';
  655. }
  656. // If the user can view prospects other than his'
  657. if ($user->rights->societe->client->voir || $socid)
  658. {
  659. $moreforfilter.='<div class="divsearchfield">';
  660. $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
  661. $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  662. $moreforfilter.='</div>';
  663. }
  664. // If the user can view prospects other than his'
  665. if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
  666. {
  667. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  668. $moreforfilter.='<div class="divsearchfield">';
  669. $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
  670. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  671. $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1);
  672. $moreforfilter.='</div>';
  673. }
  674. $parameters=array();
  675. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  676. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  677. else $moreforfilter = $hookmanager->resPrint;
  678. if ($moreforfilter)
  679. {
  680. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  681. print $moreforfilter;
  682. print '</div>';
  683. }
  684. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  685. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  686. if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
  687. print '<div class="div-table-responsive">';
  688. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  689. // Filters lines
  690. print '<tr class="liste_titre_filter">';
  691. // Ref
  692. if (! empty($arrayfields['f.facnumber']['checked']))
  693. {
  694. print '<td class="liste_titre" align="left">';
  695. print '<input class="flat" size="6" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  696. print '</td>';
  697. }
  698. // Ref customer
  699. if (! empty($arrayfields['f.ref_client']['checked']))
  700. {
  701. print '<td class="liste_titre">';
  702. print '<input class="flat" size="6" type="text" name="search_refcustomer" value="'.dol_escape_htmltag($search_refcustomer).'">';
  703. print '</td>';
  704. }
  705. // Type
  706. if (! empty($arrayfields['f.type']['checked']))
  707. {
  708. print '<td class="liste_titre maxwidthonsmartphone">';
  709. $listtype=array(
  710. Facture::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
  711. Facture::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
  712. Facture::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
  713. Facture::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
  714. );
  715. //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
  716. print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
  717. print '</td>';
  718. }
  719. // Date invoice
  720. if (! empty($arrayfields['f.date']['checked']))
  721. {
  722. print '<td class="liste_titre" align="center">';
  723. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.dol_escape_htmltag($day).'">';
  724. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.dol_escape_htmltag($month).'">';
  725. $formother->select_year($year?$year:-1,'year',1, 20, 5);
  726. print '</td>';
  727. }
  728. // Date due
  729. if (! empty($arrayfields['f.date_lim_reglement']['checked']))
  730. {
  731. print '<td class="liste_titre" align="center">';
  732. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day_lim" value="'.dol_escape_htmltag($day_lim).'">';
  733. print '<input class="flat" type="text" size="1" maxlength="2" name="month_lim" value="'.dol_escape_htmltag($month_lim).'">';
  734. $formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5);
  735. print '<br><input type="checkbox" name="option" value="late"'.($option == 'late'?' checked':'').'> '.$langs->trans("Late");
  736. print '</td>';
  737. }
  738. // Project
  739. if (! empty($arrayfields['p.ref']['checked']))
  740. {
  741. print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_project" value="'.$search_project.'"></td>';
  742. }
  743. // Thirpdarty
  744. if (! empty($arrayfields['s.nom']['checked']))
  745. {
  746. print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_societe" value="'.$search_societe.'"></td>';
  747. }
  748. // Town
  749. if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
  750. // Zip
  751. if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="4" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
  752. // State
  753. if (! empty($arrayfields['state.nom']['checked']))
  754. {
  755. print '<td class="liste_titre">';
  756. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  757. print '</td>';
  758. }
  759. // Country
  760. if (! empty($arrayfields['country.code_iso']['checked']))
  761. {
  762. print '<td class="liste_titre" align="center">';
  763. print $form->select_country($search_country,'search_country','',0,'maxwidth100');
  764. print '</td>';
  765. }
  766. // Company type
  767. if (! empty($arrayfields['typent.code']['checked']))
  768. {
  769. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  770. 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), 'maxwidth100');
  771. print '</td>';
  772. }
  773. // Payment mode
  774. if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
  775. {
  776. print '<td class="liste_titre" align="left">';
  777. $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 0, 1, 10);
  778. print '</td>';
  779. }
  780. if (! empty($arrayfields['f.total_ht']['checked']))
  781. {
  782. // Amount
  783. print '<td class="liste_titre" align="right">';
  784. print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
  785. print '</td>';
  786. }
  787. if (! empty($arrayfields['f.total_vat']['checked']))
  788. {
  789. // Amount
  790. print '<td class="liste_titre" align="right">';
  791. print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
  792. print '</td>';
  793. }
  794. if (! empty($arrayfields['f.total_localtax1']['checked']))
  795. {
  796. // Amount
  797. print '<td class="liste_titre" align="right">';
  798. print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.$search_montant_localtax1.'">';
  799. print '</td>';
  800. }
  801. if (! empty($arrayfields['f.total_localtax2']['checked']))
  802. {
  803. // Amount
  804. print '<td class="liste_titre" align="right">';
  805. print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.$search_montant_localtax2.'">';
  806. print '</td>';
  807. }
  808. if (! empty($arrayfields['f.total_ttc']['checked']))
  809. {
  810. // Amount
  811. print '<td class="liste_titre" align="right">';
  812. print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
  813. print '</td>';
  814. }
  815. if (! empty($arrayfields['dynamount_payed']['checked']))
  816. {
  817. print '<td class="liste_titre" align="right">';
  818. print '</td>';
  819. }
  820. if (! empty($arrayfields['rtp']['checked']))
  821. {
  822. print '<td class="liste_titre" align="right">';
  823. print '</td>';
  824. }
  825. // Extra fields
  826. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  827. {
  828. foreach($extrafields->attribute_label as $key => $val)
  829. {
  830. if (! empty($arrayfields["ef.".$key]['checked']))
  831. {
  832. $align=$extrafields->getAlignFlag($key);
  833. $typeofextrafield=$extrafields->attribute_type[$key];
  834. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  835. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  836. {
  837. $crit=$val;
  838. $tmpkey=preg_replace('/search_options_/','',$key);
  839. $searchclass='';
  840. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  841. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  842. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  843. }
  844. print '</td>';
  845. }
  846. }
  847. }
  848. // Fields from hook
  849. $parameters=array('arrayfields'=>$arrayfields);
  850. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  851. print $hookmanager->resPrint;
  852. // Date creation
  853. if (! empty($arrayfields['f.datec']['checked']))
  854. {
  855. print '<td class="liste_titre">';
  856. print '</td>';
  857. }
  858. // Date modification
  859. if (! empty($arrayfields['f.tms']['checked']))
  860. {
  861. print '<td class="liste_titre">';
  862. print '</td>';
  863. }
  864. // Status
  865. if (! empty($arrayfields['f.fk_statut']['checked']))
  866. {
  867. print '<td class="liste_titre maxwidthonsmartphone" align="right">';
  868. $liststatus=array('0'=>$langs->trans("BillShortStatusDraft"), '1'=>$langs->trans("BillShortStatusNotPaid"), '2'=>$langs->trans("BillShortStatusPaid"), '3'=>$langs->trans("BillShortStatusCanceled"));
  869. print $form->selectarray('search_status', $liststatus, $search_status, 1);
  870. print '</td>';
  871. }
  872. // Action column
  873. print '<td class="liste_titre" align="middle">';
  874. $searchpicto=$form->showFilterButtons();
  875. print $searchpicto;
  876. print '</td>';
  877. print "</tr>\n";
  878. print '<tr class="liste_titre">';
  879. if (! empty($arrayfields['f.facnumber']['checked'])) print_liste_field_titre($arrayfields['f.facnumber']['label'],$_SERVER['PHP_SELF'],'f.facnumber','',$param,'',$sortfield,$sortorder);
  880. 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);
  881. if (! empty($arrayfields['f.type']['checked'])) print_liste_field_titre($arrayfields['f.type']['label'],$_SERVER["PHP_SELF"],'f.type','',$param,'',$sortfield,$sortorder);
  882. if (! empty($arrayfields['f.date']['checked'])) print_liste_field_titre($arrayfields['f.date']['label'],$_SERVER['PHP_SELF'],'f.datef','',$param,'align="center"',$sortfield,$sortorder);
  883. 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);
  884. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER['PHP_SELF'],'s.nom','',$param,'',$sortfield,$sortorder);
  885. if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
  886. if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
  887. if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  888. 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);
  889. if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
  890. 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);
  891. 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);
  892. 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);
  893. if (! empty($arrayfields['f.total_localtax1']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax1']['label'],$_SERVER['PHP_SELF'],'f.localtax1','',$param,'align="right"',$sortfield,$sortorder);
  894. if (! empty($arrayfields['f.total_localtax2']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax2']['label'],$_SERVER['PHP_SELF'],'f.localtax2','',$param,'align="right"',$sortfield,$sortorder);
  895. 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);
  896. if (! empty($arrayfields['dynamount_payed']['checked'])) print_liste_field_titre($arrayfields['dynamount_payed']['label'],$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
  897. if (! empty($arrayfields['rtp']['checked'])) print_liste_field_titre($arrayfields['rtp']['label'],$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
  898. // Extra fields
  899. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  900. {
  901. foreach($extrafields->attribute_label as $key => $val)
  902. {
  903. if (! empty($arrayfields["ef.".$key]['checked']))
  904. {
  905. $align=$extrafields->getAlignFlag($key);
  906. print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  907. }
  908. }
  909. }
  910. // Hook fields
  911. $parameters=array('arrayfields'=>$arrayfields);
  912. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  913. print $hookmanager->resPrint;
  914. 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);
  915. 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);
  916. if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye,type,dynamount_payed","",$param,'align="right"',$sortfield,$sortorder);
  917. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  918. print "</tr>\n";
  919. if ($num > 0)
  920. {
  921. $i=0;
  922. $totalarray=array();
  923. while ($i < min($num,$limit))
  924. {
  925. $obj = $db->fetch_object($resql);
  926. $datelimit=$db->jdate($obj->datelimite);
  927. $facturestatic->id=$obj->facid;
  928. $facturestatic->ref=$obj->facnumber;
  929. $facturestatic->type=$obj->type;
  930. $facturestatic->statut=$obj->fk_statut;
  931. $facturestatic->date_lim_reglement=$db->jdate($obj->datelimite);
  932. $facturestatic->note_public=$obj->note_public;
  933. $facturestatic->note_private=$obj->note_private;
  934. $paiement = $facturestatic->getSommePaiement();
  935. $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
  936. $totaldeposits = $facturestatic->getSumDepositsUsed();
  937. $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
  938. $remaintopay = $obj->total_ttc - $totalpay;
  939. print '<tr class="oddeven">';
  940. if (! empty($arrayfields['f.facnumber']['checked']))
  941. {
  942. print '<td class="nowrap">';
  943. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  944. print '<td class="nobordernopadding nowrap">';
  945. print $facturestatic->getNomUrl(1,'',200,0,'',0,1);
  946. print empty($obj->increment)?'':' ('.$obj->increment.')';
  947. print '</td>';
  948. print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
  949. $filename=dol_sanitizeFileName($obj->facnumber);
  950. $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->facnumber);
  951. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->facid;
  952. print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
  953. print '</td>';
  954. print '</tr>';
  955. print '</table>';
  956. print "</td>\n";
  957. if (! $i) $totalarray['nbfield']++;
  958. }
  959. // Customer ref
  960. if (! empty($arrayfields['f.ref_client']['checked']))
  961. {
  962. print '<td class="nowrap">';
  963. print $obj->ref_client;
  964. print '</td>';
  965. if (! $i) $totalarray['nbfield']++;
  966. }
  967. // Type
  968. if (! empty($arrayfields['f.type']['checked']))
  969. {
  970. print '<td class="nowrap">';
  971. print $facturestatic->getLibType();
  972. print "</td>";
  973. if (! $i) $totalarray['nbfield']++;
  974. }
  975. // Date
  976. if (! empty($arrayfields['f.date']['checked']))
  977. {
  978. print '<td align="center" class="nowrap">';
  979. print dol_print_date($db->jdate($obj->df),'day');
  980. print '</td>';
  981. if (! $i) $totalarray['nbfield']++;
  982. }
  983. // Date limit
  984. if (! empty($arrayfields['f.date_lim_reglement']['checked']))
  985. {
  986. print '<td align="center" class="nowrap">'.dol_print_date($datelimit,'day');
  987. if ($facturestatic->hasDelay())
  988. {
  989. print img_warning($langs->trans('Late'));
  990. }
  991. print '</td>';
  992. if (! $i) $totalarray['nbfield']++;
  993. }
  994. // Project
  995. if (! empty($arrayfields['p.ref']['checked']))
  996. {
  997. print '<td class="nowrap">';
  998. if ($obj->project_id > 0)
  999. {
  1000. $projectstatic->id=$obj->project_id;
  1001. $projectstatic->ref=$obj->project_ref;
  1002. print $projectstatic->getNomUrl(1);
  1003. }
  1004. print '</td>';
  1005. if (! $i) $totalarray['nbfield']++;
  1006. }
  1007. // Third party
  1008. if (! empty($arrayfields['s.nom']['checked']))
  1009. {
  1010. print '<td class="tdoverflowmax200">';
  1011. $thirdparty=new Societe($db);
  1012. $thirdparty->id=$obj->socid;
  1013. $thirdparty->name=$obj->name;
  1014. $thirdparty->client=$obj->client;
  1015. $thirdparty->code_client=$obj->code_client;
  1016. print $thirdparty->getNomUrl(1,'customer');
  1017. print '</td>';
  1018. if (! $i) $totalarray['nbfield']++;
  1019. }
  1020. // Town
  1021. if (! empty($arrayfields['s.town']['checked']))
  1022. {
  1023. print '<td class="nocellnopadd">';
  1024. print $obj->town;
  1025. print '</td>';
  1026. if (! $i) $totalarray['nbfield']++;
  1027. }
  1028. // Zip
  1029. if (! empty($arrayfields['s.zip']['checked']))
  1030. {
  1031. print '<td class="nocellnopadd">';
  1032. print $obj->zip;
  1033. print '</td>';
  1034. if (! $i) $totalarray['nbfield']++;
  1035. }
  1036. // State
  1037. if (! empty($arrayfields['state.nom']['checked']))
  1038. {
  1039. print "<td>".$obj->state_name."</td>\n";
  1040. if (! $i) $totalarray['nbfield']++;
  1041. }
  1042. // Country
  1043. if (! empty($arrayfields['country.code_iso']['checked']))
  1044. {
  1045. print '<td align="center">';
  1046. $tmparray=getCountry($obj->fk_pays,'all');
  1047. print $tmparray['label'];
  1048. print '</td>';
  1049. if (! $i) $totalarray['nbfield']++;
  1050. }
  1051. // Type ent
  1052. if (! empty($arrayfields['typent.code']['checked']))
  1053. {
  1054. print '<td align="center">';
  1055. if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
  1056. print $typenArray[$obj->typent_code];
  1057. print '</td>';
  1058. if (! $i) $totalarray['nbfield']++;
  1059. }
  1060. // Payment mode
  1061. if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
  1062. {
  1063. print '<td>';
  1064. $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
  1065. print '</td>';
  1066. if (! $i) $totalarray['nbfield']++;
  1067. }
  1068. // Amount HT
  1069. if (! empty($arrayfields['f.total_ht']['checked']))
  1070. {
  1071. print '<td align="right">'.price($obj->total_ht)."</td>\n";
  1072. if (! $i) $totalarray['nbfield']++;
  1073. if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
  1074. $totalarray['totalht'] += $obj->total_ht;
  1075. }
  1076. // Amount VAT
  1077. if (! empty($arrayfields['f.total_vat']['checked']))
  1078. {
  1079. print '<td align="right">'.price($obj->total_vat)."</td>\n";
  1080. if (! $i) $totalarray['nbfield']++;
  1081. if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
  1082. $totalarray['totalvat'] += $obj->total_vat;
  1083. }
  1084. // Amount LocalTax1
  1085. if (! empty($arrayfields['f.total_localtax1']['checked']))
  1086. {
  1087. print '<td align="right">'.price($obj->total_localtax1)."</td>\n";
  1088. if (! $i) $totalarray['nbfield']++;
  1089. if (! $i) $totalarray['totallocaltax1field']=$totalarray['nbfield'];
  1090. $totalarray['totallocaltax1'] += $obj->total_localtax1;
  1091. }
  1092. // Amount LocalTax2
  1093. if (! empty($arrayfields['f.total_localtax2']['checked']))
  1094. {
  1095. print '<td align="right">'.price($obj->total_localtax2)."</td>\n";
  1096. if (! $i) $totalarray['nbfield']++;
  1097. if (! $i) $totalarray['totallocaltax2field']=$totalarray['nbfield'];
  1098. $totalarray['totallocaltax2'] += $obj->total_localtax2;
  1099. }
  1100. // Amount TTC
  1101. if (! empty($arrayfields['f.total_ttc']['checked']))
  1102. {
  1103. print '<td align="right">'.price($obj->total_ttc)."</td>\n";
  1104. if (! $i) $totalarray['nbfield']++;
  1105. if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
  1106. $totalarray['totalttc'] += $obj->total_ttc;
  1107. }
  1108. if (! empty($arrayfields['dynamount_payed']['checked']))
  1109. {
  1110. print '<td align="right">'.(! empty($totalpay)?price($totalpay,0,$langs):'&nbsp;').'</td>'; // TODO Use a denormalized field
  1111. if (! $i) $totalarray['nbfield']++;
  1112. if (! $i) $totalarray['totalamfield']=$totalarray['nbfield'];
  1113. $totalarray['totalam'] += $totalpay;
  1114. }
  1115. if (! empty($arrayfields['rtp']['checked']))
  1116. {
  1117. print '<td align="right">'.(! empty($remaintopay)?price($remaintopay,0,$langs):'&nbsp;').'</td>'; // TODO Use a denormalized field
  1118. if (! $i) $totalarray['nbfield']++;
  1119. if (! $i) $totalarray['totalrtpfield']=$totalarray['nbfield'];
  1120. $totalarray['totalrtp'] += $remaintopay;
  1121. }
  1122. // Extra fields
  1123. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  1124. {
  1125. foreach($extrafields->attribute_label as $key => $val)
  1126. {
  1127. if (! empty($arrayfields["ef.".$key]['checked']))
  1128. {
  1129. print '<td';
  1130. $align=$extrafields->getAlignFlag($key);
  1131. if ($align) print ' align="'.$align.'"';
  1132. print '>';
  1133. $tmpkey='options_'.$key;
  1134. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  1135. print '</td>';
  1136. if (! $i) $totalarray['nbfield']++;
  1137. }
  1138. }
  1139. }
  1140. // Fields from hook
  1141. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  1142. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  1143. print $hookmanager->resPrint;
  1144. // Date creation
  1145. if (! empty($arrayfields['f.datec']['checked']))
  1146. {
  1147. print '<td align="center" class="nowrap">';
  1148. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  1149. print '</td>';
  1150. if (! $i) $totalarray['nbfield']++;
  1151. }
  1152. // Date modification
  1153. if (! empty($arrayfields['f.tms']['checked']))
  1154. {
  1155. print '<td align="center" class="nowrap">';
  1156. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  1157. print '</td>';
  1158. if (! $i) $totalarray['nbfield']++;
  1159. }
  1160. // Status
  1161. if (! empty($arrayfields['f.fk_statut']['checked']))
  1162. {
  1163. print '<td align="right" class="nowrap">';
  1164. print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$paiement,$obj->type);
  1165. print "</td>";
  1166. if (! $i) $totalarray['nbfield']++;
  1167. }
  1168. // Action column
  1169. print '<td class="nowrap" align="center">';
  1170. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1171. {
  1172. $selected=0;
  1173. if (in_array($obj->facid, $arrayofselected)) $selected=1;
  1174. print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected?' checked="checked"':'').'>';
  1175. }
  1176. print '</td>' ;
  1177. if (! $i) $totalarray['nbfield']++;
  1178. print "</tr>\n";
  1179. $i++;
  1180. }
  1181. // Show total line
  1182. if (isset($totalarray['totalhtfield'])
  1183. || isset($totalarray['totalvatfield'])
  1184. || isset($totalarray['totallocaltax1field'])
  1185. || isset($totalarray['totallocaltax2field'])
  1186. || isset($totalarray['totalttcfield'])
  1187. || isset($totalarray['totalamfield'])
  1188. || isset($totalarray['totalrtpfield'])
  1189. )
  1190. {
  1191. print '<tr class="liste_total">';
  1192. $i=0;
  1193. while ($i < $totalarray['nbfield'])
  1194. {
  1195. $i++;
  1196. if ($i == 1)
  1197. {
  1198. if ($num < $limit && empty($offset)) print '<td align="left">'.$langs->trans("Total").'</td>';
  1199. else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
  1200. }
  1201. elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
  1202. elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
  1203. elseif ($totalarray['totallocaltax1field'] == $i) print '<td align="right">'.price($totalarray['totallocaltax1']).'</td>';
  1204. elseif ($totalarray['totallocaltax2field'] == $i) print '<td align="right">'.price($totalarray['totallocaltax2']).'</td>';
  1205. elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
  1206. elseif ($totalarray['totalamfield'] == $i) print '<td align="right">'.price($totalarray['totalam']).'</td>';
  1207. elseif ($totalarray['totalrtpfield'] == $i) print '<td align="right">'.price($totalarray['totalrtp']).'</td>';
  1208. else print '<td></td>';
  1209. }
  1210. print '</tr>';
  1211. }
  1212. }
  1213. $db->free($resql);
  1214. $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1215. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  1216. print $hookmanager->resPrint;
  1217. print "</table>\n";
  1218. print '</div>';
  1219. print "</form>\n";
  1220. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
  1221. {
  1222. // Show list of available documents
  1223. $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1224. $urlsource.=str_replace('&amp;','&',$param);
  1225. $filedir=$diroutputmassaction;
  1226. $genallowed=$user->rights->facture->lire;
  1227. $delallowed=$user->rights->facture->lire;
  1228. print $formfile->showdocuments('massfilesarea_invoices','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
  1229. }
  1230. else
  1231. {
  1232. print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
  1233. }
  1234. }
  1235. else
  1236. {
  1237. dol_print_error($db);
  1238. }
  1239. llxFooter();
  1240. $db->close();