list.php 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495
  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. $lineid=GETPOST('lineid','int');
  61. $userid=GETPOST('userid','int');
  62. $search_product_category=GETPOST('search_product_category','int');
  63. $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
  64. $search_refcustomer=GETPOST('search_refcustomer','alpha');
  65. $search_societe=GETPOST('search_societe','alpha');
  66. $search_montant_ht=GETPOST('search_montant_ht','alpha');
  67. $search_montant_vat=GETPOST('search_montant_vat','alpha');
  68. $search_montant_ttc=GETPOST('search_montant_ttc','alpha');
  69. $search_status=GETPOST('search_status','int');
  70. $search_paymentmode=GETPOST('search_paymentmode','int');
  71. $search_town=GETPOST('search_town','alpha');
  72. $search_zip=GETPOST('search_zip','alpha');
  73. $search_state=trim(GETPOST("search_state"));
  74. $search_country=GETPOST("search_country",'int');
  75. $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
  76. $search_user = GETPOST('search_user','int');
  77. $search_sale = GETPOST('search_sale','int');
  78. $day = GETPOST('day','int');
  79. $month = GETPOST('month','int');
  80. $year = GETPOST('year','int');
  81. $day_lim = GETPOST('day_lim','int');
  82. $month_lim = GETPOST('month_lim','int');
  83. $year_lim = GETPOST('year_lim','int');
  84. $toselect = GETPOST('toselect', 'array');
  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=''; }
  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. $toselect='';
  187. $option='';
  188. $filter='';
  189. $day_lim='';
  190. $year_lim='';
  191. $month_lim='';
  192. $search_array_options=array();
  193. }
  194. if (empty($reshook))
  195. {
  196. // Mass actions. Controls on number of lines checked
  197. $maxformassaction=1000;
  198. if (! empty($massaction) && count($toselect) < 1)
  199. {
  200. $error++;
  201. setEventMessages($langs->trans("NoLineChecked"), null, "warnings");
  202. }
  203. if (! $error && count($toselect) > $maxformassaction)
  204. {
  205. setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors');
  206. $error++;
  207. }
  208. if (! $error && $massaction == 'confirm_presend')
  209. {
  210. $resaction = '';
  211. $nbsent = 0;
  212. $nbignored = 0;
  213. $langs->load("mails");
  214. include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  215. if (!$error && !isset($user->email))
  216. {
  217. $error++;
  218. setEventMessages($langs->trans("NoSenderEmailDefined"), null, 'warnings');
  219. }
  220. if (! $error)
  221. {
  222. $thirdparty=new Societe($db);
  223. $objecttmp=new Facture($db);
  224. $listofobjectid=array();
  225. $listofobjectthirdparties=array();
  226. $listofobjectref=array();
  227. foreach($toselect as $toselectid)
  228. {
  229. $objecttmp=new Facture($db); // must create new instance because instance is saved into $listofobjectref array for future use
  230. $result=$objecttmp->fetch($toselectid);
  231. if ($result > 0)
  232. {
  233. $listoinvoicesid[$toselectid]=$toselectid;
  234. $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
  235. $listofobjectthirdparties[$thirdpartyid]=$thirdpartyid;
  236. $listofobjectref[$thirdpartyid][$toselectid]=$objecttmp;
  237. }
  238. }
  239. //var_dump($listofobjectthirdparties);exit;
  240. foreach ($listofobjectthirdparties as $thirdpartyid)
  241. {
  242. $result = $thirdparty->fetch($thirdpartyid);
  243. if ($result < 0)
  244. {
  245. dol_print_error($db);
  246. exit;
  247. }
  248. // Define recipient $sendto and $sendtocc
  249. if (trim($_POST['sendto']))
  250. {
  251. // Recipient is provided into free text
  252. $sendto = trim($_POST['sendto']);
  253. $sendtoid = 0;
  254. }
  255. elseif ($_POST['receiver'] != '-1')
  256. {
  257. // Recipient was provided from combo list
  258. if ($_POST['receiver'] == 'thirdparty') // Id of third party
  259. {
  260. $sendto = $thirdparty->email;
  261. $sendtoid = 0;
  262. }
  263. else // Id du contact
  264. {
  265. $sendto = $thirdparty->contact_get_property((int) $_POST['receiver'],'email');
  266. $sendtoid = $_POST['receiver'];
  267. }
  268. }
  269. if (trim($_POST['sendtocc']))
  270. {
  271. $sendtocc = trim($_POST['sendtocc']);
  272. }
  273. elseif ($_POST['receivercc'] != '-1')
  274. {
  275. // Recipient was provided from combo list
  276. if ($_POST['receivercc'] == 'thirdparty') // Id of third party
  277. {
  278. $sendtocc = $thirdparty->email;
  279. }
  280. else // Id du contact
  281. {
  282. $sendtocc = $thirdparty->contact_get_property((int) $_POST['receivercc'],'email');
  283. }
  284. }
  285. //var_dump($listofobjectref[$thirdpartyid]); // Array of invoice for this thirdparty
  286. $attachedfiles=array('paths'=>array(), 'names'=>array(), 'mimes'=>array());
  287. $listofqualifiedinvoice=array();
  288. $listofqualifiedref=array();
  289. foreach($listofobjectref[$thirdpartyid] as $objectid => $object)
  290. {
  291. //var_dump($object);
  292. //var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut);
  293. if ($object->statut != Facture::STATUS_VALIDATED)
  294. {
  295. $nbignored++;
  296. continue; // Payment done or started or canceled
  297. }
  298. // Read document
  299. // TODO Use future field $object->fullpathdoc to know where is stored default file
  300. // TODO If not defined, use $object->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc.
  301. $filename=dol_sanitizeFileName($object->ref).'.pdf';
  302. $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
  303. $file = $filedir . '/' . $filename;
  304. $mime = dol_mimetype($file);
  305. if (dol_is_file($file))
  306. {
  307. if (empty($sendto)) // For the case, no recipient were set (multi thirdparties send)
  308. {
  309. $object->fetch_thirdparty();
  310. $sendto = $object->thirdparty->email;
  311. }
  312. if (empty($sendto))
  313. {
  314. //print "No recipient for thirdparty ".$object->thirdparty->name;
  315. $nbignored++;
  316. continue;
  317. }
  318. if (dol_strlen($sendto))
  319. {
  320. // Create form object
  321. $attachedfiles=array(
  322. 'paths'=>array_merge($attachedfiles['paths'],array($file)),
  323. 'names'=>array_merge($attachedfiles['names'],array($filename)),
  324. 'mimes'=>array_merge($attachedfiles['mimes'],array($mime))
  325. );
  326. }
  327. $listofqualifiedinvoice[$objectid]=$object;
  328. $listofqualifiedref[$objectid]=$object->ref;
  329. }
  330. else
  331. {
  332. $nbignored++;
  333. $langs->load("other");
  334. $resaction.='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
  335. dol_syslog('Failed to read file: '.$file, LOG_WARNING);
  336. continue;
  337. }
  338. //var_dump($listofqualifiedref);
  339. }
  340. if (count($listofqualifiedinvoice) > 0)
  341. {
  342. $langs->load("commercial");
  343. $from = $user->getFullName($langs) . ' <' . $user->email .'>';
  344. $replyto = $from;
  345. $subject = GETPOST('subject');
  346. $message = GETPOST('message');
  347. $sendtocc = GETPOST('sentocc');
  348. $sendtobcc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO);
  349. $substitutionarray=array(
  350. '__ID__' => join(', ',array_keys($listofqualifiedinvoice)),
  351. '__EMAIL__' => $thirdparty->email,
  352. '__CHECK_READ__' => '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$thirdparty->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>',
  353. //'__LASTNAME__' => $obj2->lastname,
  354. //'__FIRSTNAME__' => $obj2->firstname,
  355. '__FACREF__' => join(', ',$listofqualifiedref), // For backward compatibility
  356. '__REF__' => join(', ',$listofqualifiedref),
  357. '__REFCLIENT__' => $thirdparty->name
  358. );
  359. $subject=make_substitutions($subject, $substitutionarray);
  360. $message=make_substitutions($message, $substitutionarray);
  361. $filepath = $attachedfiles['paths'];
  362. $filename = $attachedfiles['names'];
  363. $mimetype = $attachedfiles['mimes'];
  364. //var_dump($filepath);
  365. // Send mail
  366. require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php');
  367. $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1);
  368. if ($mailfile->error)
  369. {
  370. $resaction.='<div class="error">'.$mailfile->error.'</div>';
  371. }
  372. else
  373. {
  374. $result=$mailfile->sendfile();
  375. if ($result)
  376. {
  377. $resaction.=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)).'<br>'; // Must not contain "
  378. $error=0;
  379. // Insert logs into agenda
  380. foreach($listofqualifiedinvoice as $invid => $object)
  381. {
  382. $actiontypecode='AC_FAC';
  383. $actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto;
  384. if ($message)
  385. {
  386. if ($sendtocc) $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('Bcc') . ": " . $sendtocc);
  387. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('MailTopic') . ": " . $subject);
  388. $actionmsg = dol_concatdesc($actionmsg, $langs->transnoentities('TextUsedInTheMessageBody') . ":");
  389. $actionmsg = dol_concatdesc($actionmsg, $message);
  390. }
  391. // Initialisation donnees
  392. $object->sendtoid = 0;
  393. $object->actiontypecode = $actiontypecode;
  394. $object->actionmsg = $actionmsg; // Long text
  395. $object->actionmsg2 = $actionmsg2; // Short text
  396. $object->fk_element = $invid;
  397. $object->elementtype = $object->element;
  398. // Appel des triggers
  399. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  400. $interface=new Interfaces($db);
  401. $result=$interface->run_triggers('BILL_SENTBYMAIL',$object,$user,$langs,$conf);
  402. if ($result < 0) { $error++; $errors=$interface->errors; }
  403. // Fin appel triggers
  404. if ($error)
  405. {
  406. setEventMessages($db->lasterror(), $errors, 'errors');
  407. dol_syslog("Error in trigger BILL_SENTBYMAIL ".$db->lasterror(), LOG_ERR);
  408. }
  409. $nbsent++;
  410. }
  411. }
  412. else
  413. {
  414. $langs->load("other");
  415. if ($mailfile->error)
  416. {
  417. $resaction.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
  418. $resaction.='<br><div class="error">'.$mailfile->error.'</div>';
  419. }
  420. else
  421. {
  422. $resaction.='<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
  423. }
  424. }
  425. }
  426. }
  427. }
  428. $resaction.=($resaction?'<br>':$resaction);
  429. $resaction.='<strong>'.$langs->trans("ResultOfMailSending").':</strong><br>'."\n";
  430. $resaction.=$langs->trans("NbSelected").': '.count($toselect)."\n<br>";
  431. $resaction.=$langs->trans("NbIgnored").': '.($nbignored?$nbignored:0)."\n<br>";
  432. $resaction.=$langs->trans("NbSent").': '.($nbsent?$nbsent:0)."\n<br>";
  433. if ($nbsent)
  434. {
  435. $action=''; // Do not show form post if there was at least one successfull sent
  436. setEventMessages($langs->trans("EMailSentToNRecipients", $nbsent.'/'.count($toselect)), null, 'mesgs');
  437. setEventMessages($resaction, null, 'mesgs');
  438. }
  439. else
  440. {
  441. //setEventMessages($langs->trans("EMailSentToNRecipients", 0), null, 'warnings'); // May be object has no generated PDF file
  442. setEventMessages($resaction, null, 'warnings');
  443. }
  444. }
  445. $action='list';
  446. $massaction='';
  447. }
  448. if (! $error && $massaction == "builddoc" && $user->rights->facture->lire && ! GETPOST('button_search'))
  449. {
  450. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  451. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  452. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  453. $objecttmp=new Facture($db);
  454. $listofobjectid=array();
  455. $listofobjectthirdparties=array();
  456. $listofobjectref=array();
  457. foreach($toselect as $toselectid)
  458. {
  459. $objecttmp=new Facture($db); // must create new instance because instance is saved into $listofobjectref array for future use
  460. $result=$objecttmp->fetch($toselectid);
  461. if ($result > 0)
  462. {
  463. $listoinvoicesid[$toselectid]=$toselectid;
  464. $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
  465. $listofobjectthirdparties[$thirdpartyid]=$thirdpartyid;
  466. $listofobjectref[$toselectid]=$objecttmp->ref;
  467. }
  468. }
  469. $arrayofinclusion=array();
  470. foreach($listofobjectref as $tmppdf) $arrayofinclusion[]=preg_quote($tmppdf.'.pdf','/');
  471. $factures = dol_dir_list($conf->facture->dir_output,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true);
  472. // liste les fichiers
  473. $files = array();
  474. foreach($listofobjectref as $basename)
  475. {
  476. foreach($factures as $facture)
  477. {
  478. if (strstr($facture["name"],$basename))
  479. {
  480. $files[] = $conf->facture->dir_output.'/'.$basename.'/'.$facture["name"];
  481. break;
  482. }
  483. }
  484. }
  485. // Define output language (Here it is not used because we do only merging existing PDF)
  486. $outputlangs = $langs;
  487. $newlang='';
  488. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
  489. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang;
  490. if (! empty($newlang))
  491. {
  492. $outputlangs = new Translate("",$conf);
  493. $outputlangs->setDefaultLang($newlang);
  494. }
  495. // Create empty PDF
  496. $pdf=pdf_getInstance();
  497. if (class_exists('TCPDF'))
  498. {
  499. $pdf->setPrintHeader(false);
  500. $pdf->setPrintFooter(false);
  501. }
  502. $pdf->SetFont(pdf_getPDFFont($outputlangs));
  503. if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false);
  504. // Add all others
  505. foreach($files as $file)
  506. {
  507. // Charge un document PDF depuis un fichier.
  508. $pagecount = $pdf->setSourceFile($file);
  509. for ($i = 1; $i <= $pagecount; $i++)
  510. {
  511. $tplidx = $pdf->importPage($i);
  512. $s = $pdf->getTemplatesize($tplidx);
  513. $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
  514. $pdf->useTemplate($tplidx);
  515. }
  516. }
  517. // Create output dir if not exists
  518. dol_mkdir($diroutputmassaction);
  519. // Save merged file
  520. $filename=strtolower(dol_sanitizeFileName($langs->transnoentities("Invoices")));
  521. if ($filter=='paye:0')
  522. {
  523. if ($option=='late') $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid"))).'_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Late")));
  524. else $filename.='_'.strtolower(dol_sanitizeFileName($langs->transnoentities("Unpaid")));
  525. }
  526. if ($year) $filename.='_'.$year;
  527. if ($month) $filename.='_'.$month;
  528. if ($pagecount)
  529. {
  530. $now=dol_now();
  531. $file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf';
  532. $pdf->Output($file,'F');
  533. if (! empty($conf->global->MAIN_UMASK))
  534. @chmod($file, octdec($conf->global->MAIN_UMASK));
  535. $langs->load("exports");
  536. setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs');
  537. }
  538. else
  539. {
  540. setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors');
  541. }
  542. }
  543. // Remove file
  544. if ($action == 'remove_file')
  545. {
  546. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  547. $langs->load("other");
  548. $upload_dir = $diroutputmassaction;
  549. $file = $upload_dir . '/' . GETPOST('file');
  550. $ret=dol_delete_file($file);
  551. if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
  552. else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
  553. $action='';
  554. }
  555. }
  556. /*
  557. * View
  558. */
  559. $form = new Form($db);
  560. $formother = new FormOther($db);
  561. $formfile = new FormFile($db);
  562. $bankaccountstatic=new Account($db);
  563. $facturestatic=new Facture($db);
  564. $formcompany=new FormCompany($db);
  565. llxHeader('',$langs->trans('CustomersInvoices'),'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
  566. $sql = 'SELECT';
  567. if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT';
  568. $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,';
  569. $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,';
  570. $sql.= ' f.paye as paye, f.fk_statut,';
  571. $sql.= ' f.datec as date_creation, f.tms as date_update,';
  572. $sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
  573. $sql.= " typent.code as typent_code,";
  574. $sql.= " state.code_departement as state_code, state.nom as state_name";
  575. if (! $sall) $sql.= ', SUM(pf.amount) as am'; // To be able to sort on status
  576. // Add fields from extrafields
  577. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  578. // Add fields from hooks
  579. $parameters=array();
  580. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  581. $sql.=$hookmanager->resPrint;
  582. $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  583. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  584. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  585. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  586. $sql.= ', '.MAIN_DB_PREFIX.'facture as f';
  587. 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)";
  588. if (! $sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
  589. else $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid';
  590. if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture';
  591. if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  592. // We'll need this table joined to the select in order to filter by sale
  593. if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  594. if ($search_user > 0)
  595. {
  596. $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
  597. $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
  598. }
  599. $sql.= ' WHERE f.fk_soc = s.rowid';
  600. $sql.= " AND f.entity = ".$conf->entity;
  601. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  602. if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
  603. if ($socid > 0) $sql.= ' AND s.rowid = '.$socid;
  604. if ($userid)
  605. {
  606. if ($userid == -1) $sql.=' AND f.fk_user_author IS NULL';
  607. else $sql.=' AND f.fk_user_author = '.$userid;
  608. }
  609. if ($filtre)
  610. {
  611. $aFilter = explode(',', $filtre);
  612. foreach ($aFilter as $filter)
  613. {
  614. $filt = explode(':', $filter);
  615. $sql .= ' AND ' . trim($filt[0]) . ' = ' . trim($filt[1]);
  616. }
  617. }
  618. if ($search_ref) $sql .= natural_search('f.facnumber', $search_ref);
  619. if ($search_refcustomer) $sql .= natural_search('f.ref_client', $search_refcustomer);
  620. if ($search_project) $sql .= natural_search('p.ref', $search_project);
  621. if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
  622. if ($search_town) $sql.= natural_search('s.town', $search_town);
  623. if ($search_zip) $sql.= natural_search("s.zip",$search_zip);
  624. if ($search_state) $sql.= natural_search("state.nom",$search_state);
  625. if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
  626. if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
  627. if ($search_company) $sql .= natural_search('s.nom', $search_company);
  628. if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1);
  629. if ($search_montant_vat != '') $sql.= natural_search('f.total_vat', $search_montant_vat, 1);
  630. if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1);
  631. if ($search_status != '' && $search_status >= 0) $sql.= " AND f.fk_statut = ".$db->escape($search_status);
  632. if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$search_paymentmode."";
  633. if ($month > 0)
  634. {
  635. if ($year > 0 && empty($day))
  636. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
  637. else if ($year > 0 && ! empty($day))
  638. $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))."'";
  639. else
  640. $sql.= " AND date_format(f.datef, '%m') = '".$month."'";
  641. }
  642. else if ($year > 0)
  643. {
  644. $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
  645. }
  646. if ($month_lim > 0)
  647. {
  648. if ($year_lim > 0 && empty($day_lim))
  649. $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))."'";
  650. else if ($year_lim > 0 && ! empty($day_lim))
  651. $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))."'";
  652. else
  653. $sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$month_lim."'";
  654. }
  655. else if ($year_lim > 0)
  656. {
  657. $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))."'";
  658. }
  659. if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->client->warning_delay)."'";
  660. if ($filter == 'paye:0') $sql.= " AND f.fk_statut = 1";
  661. if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
  662. if ($search_user > 0)
  663. {
  664. $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;
  665. }
  666. // Add where from extra fields
  667. foreach ($search_array_options as $key => $val)
  668. {
  669. $crit=$val;
  670. $tmpkey=preg_replace('/search_options_/','',$key);
  671. $typ=$extrafields->attribute_type[$tmpkey];
  672. $mode=0;
  673. if (in_array($typ, array('int','double'))) $mode=1; // Search on a numeric
  674. if ($val && ( ($crit != '' && ! in_array($typ, array('select'))) || ! empty($crit)))
  675. {
  676. $sql .= natural_search('ef.'.$tmpkey, $crit, $mode);
  677. }
  678. }
  679. // Add where from hooks
  680. $parameters=array();
  681. $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
  682. $sql.=$hookmanager->resPrint;
  683. if (! $sall)
  684. {
  685. $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,';
  686. $sql.= ' f.datef, f.date_lim_reglement,';
  687. $sql.= ' f.paye, f.fk_statut,';
  688. $sql.= ' f.datec, f.tms,';
  689. $sql.= ' s.rowid, s.nom, s.town, s.zip, s.fk_pays, s.code_client, s.client, typent.code';
  690. $sql.= ' ,state.code_departement, state.nom';
  691. }
  692. else
  693. {
  694. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  695. }
  696. $sql.= ' ORDER BY ';
  697. $listfield=explode(',',$sortfield);
  698. foreach ($listfield as $key => $value) $sql.= $listfield[$key].' '.$sortorder.',';
  699. $sql.= ' f.rowid DESC ';
  700. $nbtotalofrecords = 0;
  701. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  702. {
  703. $result = $db->query($sql);
  704. $nbtotalofrecords = $db->num_rows($result);
  705. }
  706. $sql.= $db->plimit($limit+1,$offset);
  707. //print $sql;
  708. $resql = $db->query($sql);
  709. if ($resql)
  710. {
  711. $num = $db->num_rows($resql);
  712. $arrayofselected=is_array($toselect)?$toselect:array();
  713. if ($socid)
  714. {
  715. $soc = new Societe($db);
  716. $soc->fetch($socid);
  717. }
  718. $param='&socid='.$socid;
  719. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  720. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  721. if ($day) $param.='&day='.urlencode($day);
  722. if ($month) $param.='&month='.urlencode($month);
  723. if ($year) $param.='&year=' .urlencode($year);
  724. if ($day_lim) $param.='&day_lim='.urlencode($day_lim);
  725. if ($month_lim) $param.='&month_lim='.urlencode($month_lim);
  726. if ($year_lim) $param.='&year_lim=' .urlencode($year_lim);
  727. if ($search_ref) $param.='&search_ref=' .urlencode($search_ref);
  728. if ($search_refcustomer) $param.='&search_refcustomer=' .urlencode($search_refcustomer);
  729. if ($search_societe) $param.='&search_societe=' .urlencode($search_societe);
  730. if ($search_sale > 0) $param.='&search_sale=' .urlencode($search_sale);
  731. if ($search_user > 0) $param.='&search_user=' .urlencode($search_user);
  732. if ($search_product_category > 0) $param.='$search_product_category=' .urlencode($search_product_category);
  733. if ($search_montant_ht != '') $param.='&search_montant_ht='.urlencode($search_montant_ht);
  734. if ($search_montant_vat != '') $param.='&search_montant_vat='.urlencode($search_montant_vat);
  735. if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc);
  736. if ($search_status != '') $param.='&search_status='.urlencode($search_status);
  737. if ($search_paymentmode > 0) $param.='search_paymentmode='.urlencode($search_paymentmode);
  738. if ($show_files) $param.='&show_files=' .$show_files;
  739. if ($option) $param.="&option=".$option;
  740. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  741. // Add $param from extra fields
  742. foreach ($search_array_options as $key => $val)
  743. {
  744. $crit=$val;
  745. $tmpkey=preg_replace('/search_options_/','',$key);
  746. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  747. }
  748. $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
  749. $i = 0;
  750. print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  751. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  752. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  753. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  754. print '<input type="hidden" name="action" value="list">';
  755. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  756. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  757. print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
  758. print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->name:''),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$massactionbutton,$num,$nbtotalofrecords,'title_accountancy.png',0,'','',$limit);
  759. if ($massaction == 'presend')
  760. {
  761. $langs->load("mails");
  762. if (! GETPOST('cancel'))
  763. {
  764. $objecttmp=new Facture($db);
  765. $listofselectedid=array();
  766. $listofselectedthirdparties=array();
  767. $listofselectedref=array();
  768. foreach($arrayofselected as $toselectid)
  769. {
  770. $result=$objecttmp->fetch($toselectid);
  771. if ($result > 0)
  772. {
  773. $listofselectedid[$toselectid]=$toselectid;
  774. $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid;
  775. $listofselectedthirdparties[$thirdpartyid]=$thirdpartyid;
  776. $listofselectedref[$thirdpartyid][$toselectid]=$objecttmp->ref;
  777. }
  778. }
  779. }
  780. print '<input type="hidden" name="massaction" value="confirm_presend">';
  781. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  782. $formmail = new FormMail($db);
  783. dol_fiche_head(null, '', '');
  784. $topicmail="SendBillRef";
  785. $modelmail="facture_send";
  786. // Cree l'objet formulaire mail
  787. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  788. $formmail = new FormMail($db);
  789. $formmail->withform=-1;
  790. $formmail->fromtype = 'user';
  791. $formmail->fromid = $user->id;
  792. $formmail->fromname = $user->getFullName($langs);
  793. $formmail->frommail = $user->email;
  794. if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 1)) // If bit 1 is set
  795. {
  796. $formmail->trackid='inv'.$object->id;
  797. }
  798. if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set
  799. {
  800. include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  801. $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'inv'.$object->id);
  802. }
  803. $formmail->withfrom=1;
  804. $liste=$langs->trans("AllRecipientSelected");
  805. if (count($listofselectedthirdparties) == 1)
  806. {
  807. $liste=array();
  808. $thirdpartyid=array_shift($listofselectedthirdparties);
  809. $soc=new Societe($db);
  810. $soc->fetch($thirdpartyid);
  811. foreach ($soc->thirdparty_and_contact_email_array(1) as $key=>$value)
  812. {
  813. $liste[$key]=$value;
  814. }
  815. $formmail->withtoreadonly=0;
  816. }
  817. else
  818. {
  819. $formmail->withtoreadonly=1;
  820. }
  821. $formmail->withto=$liste;
  822. $formmail->withtofree=0;
  823. $formmail->withtocc=1;
  824. $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
  825. $formmail->withtopic=$langs->transnoentities($topicmail, '__REF__', '__REFCLIENT__');
  826. $formmail->withfile=$langs->trans("OnlyPDFattachmentSupported");
  827. $formmail->withbody=1;
  828. $formmail->withdeliveryreceipt=1;
  829. $formmail->withcancel=1;
  830. // Tableau des substitutions
  831. $formmail->substit['__REF__']='__REF__'; // We want to keep the tag
  832. $formmail->substit['__SIGNATURE__']=$user->signature;
  833. $formmail->substit['__REFCLIENT__']='__REFCLIENT__'; // We want to keep the tag
  834. $formmail->substit['__PERSONALIZED__']='';
  835. $formmail->substit['__CONTACTCIVNAME__']='';
  836. // Tableau des parametres complementaires du post
  837. $formmail->param['action']=$action;
  838. $formmail->param['models']=$modelmail;
  839. $formmail->param['models_id']=GETPOST('modelmailselected','int');
  840. $formmail->param['facid']=join(',',$arrayofselected);
  841. //$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id;
  842. print $formmail->get_form();
  843. dol_fiche_end();
  844. }
  845. if ($sall)
  846. {
  847. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  848. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  849. }
  850. // If the user can view prospects other than his'
  851. $moreforfilter='';
  852. if ($user->rights->societe->client->voir || $socid)
  853. {
  854. $langs->load("commercial");
  855. $moreforfilter.='<div class="divsearchfield">';
  856. $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
  857. $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300');
  858. $moreforfilter.='</div>';
  859. }
  860. // If the user can view prospects other than his'
  861. if ($user->rights->societe->client->voir || $socid)
  862. {
  863. $moreforfilter.='<div class="divsearchfield">';
  864. $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
  865. $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
  866. $moreforfilter.='</div>';
  867. }
  868. // If the user can view prospects other than his'
  869. if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
  870. {
  871. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  872. $moreforfilter.='<div class="divsearchfield">';
  873. $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
  874. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  875. $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1);
  876. $moreforfilter.='</div>';
  877. }
  878. $parameters=array();
  879. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  880. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  881. else $moreforfilter = $hookmanager->resPrint;
  882. if ($moreforfilter)
  883. {
  884. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  885. print $moreforfilter;
  886. print '</div>';
  887. }
  888. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  889. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  890. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  891. print '<tr class="liste_titre">';
  892. if (! empty($arrayfields['f.facnumber']['checked'])) print_liste_field_titre($arrayfields['f.facnumber']['label'],$_SERVER['PHP_SELF'],'f.facnumber','',$param,'',$sortfield,$sortorder);
  893. 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);
  894. if (! empty($arrayfields['f.date']['checked'])) print_liste_field_titre($arrayfields['f.date']['label'],$_SERVER['PHP_SELF'],'f.datef','',$param,'align="center"',$sortfield,$sortorder);
  895. 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);
  896. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER['PHP_SELF'],'s.nom','',$param,'',$sortfield,$sortorder);
  897. if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
  898. if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
  899. if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  900. 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);
  901. if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
  902. 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);
  903. 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);
  904. 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);
  905. 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);
  906. if (! empty($arrayfields['am']['checked'])) print_liste_field_titre($arrayfields['am']['label'],$_SERVER['PHP_SELF'],'am','',$param,'align="right"',$sortfield,$sortorder);
  907. if (! empty($arrayfields['rtp']['checked'])) print_liste_field_titre($arrayfields['rtp']['label'],$_SERVER['PHP_SELF'],'rtp','',$param,'align="right"',$sortfield,$sortorder);
  908. // Extra fields
  909. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  910. {
  911. foreach($extrafields->attribute_label as $key => $val)
  912. {
  913. if (! empty($arrayfields["ef.".$key]['checked']))
  914. {
  915. $align=$extrafields->getAlignFlag($key);
  916. print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  917. }
  918. }
  919. }
  920. // Hook fields
  921. $parameters=array('arrayfields'=>$arrayfields);
  922. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  923. print $hookmanager->resPrint;
  924. 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);
  925. 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);
  926. 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);
  927. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
  928. print "</tr>\n";
  929. // Filters lines
  930. print '<tr class="liste_titre">';
  931. // Ref
  932. if (! empty($arrayfields['f.facnumber']['checked']))
  933. {
  934. print '<td class="liste_titre" align="left">';
  935. print '<input class="flat" size="6" type="text" name="search_ref" value="'.$search_ref.'">';
  936. print '</td>';
  937. }
  938. // Ref customer
  939. if (! empty($arrayfields['f.ref_client']['checked']))
  940. {
  941. print '<td class="liste_titre">';
  942. print '<input class="flat" size="6" type="text" name="search_refcustomer" value="'.$search_refcustomer.'">';
  943. print '</td>';
  944. }
  945. // Date invoice
  946. if (! empty($arrayfields['f.date']['checked']))
  947. {
  948. print '<td class="liste_titre" align="center">';
  949. if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
  950. print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
  951. $formother->select_year($year?$year:-1,'year',1, 20, 5);
  952. print '</td>';
  953. }
  954. // Date due
  955. if (! empty($arrayfields['f.date_lim_reglement']['checked']))
  956. {
  957. print '<td class="liste_titre" align="center">';
  958. 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.'">';
  959. print '<input class="flat" type="text" size="1" maxlength="2" name="month_lim" value="'.$month_lim.'">';
  960. $formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5);
  961. print '<br><input type="checkbox" name="option" value="late"'.($option == 'late'?' checked':'').'> '.$langs->trans("Late");
  962. print '</td>';
  963. }
  964. // Thirpdarty
  965. if (! empty($arrayfields['s.nom']['checked']))
  966. {
  967. print '<td class="liste_titre" align="left"><input class="flat" type="text" size="6" name="search_societe" value="'.$search_societe.'"></td>';
  968. }
  969. // Town
  970. 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>';
  971. // Zip
  972. 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>';
  973. // State
  974. if (! empty($arrayfields['state.nom']['checked']))
  975. {
  976. print '<td class="liste_titre">';
  977. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  978. print '</td>';
  979. }
  980. // Country
  981. if (! empty($arrayfields['country.code_iso']['checked']))
  982. {
  983. print '<td class="liste_titre" align="center">';
  984. print $form->select_country($search_country,'search_country','',0,'maxwidth100');
  985. print '</td>';
  986. }
  987. // Company type
  988. if (! empty($arrayfields['typent.code']['checked']))
  989. {
  990. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  991. 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));
  992. print '</td>';
  993. }
  994. // Payment mode
  995. if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
  996. {
  997. print '<td class="liste_titre" align="left">';
  998. $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 0, 1, 10);
  999. print '</td>';
  1000. }
  1001. if (! empty($arrayfields['f.total_ht']['checked']))
  1002. {
  1003. // Amount
  1004. print '<td class="liste_titre" align="right">';
  1005. print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.$search_montant_ht.'">';
  1006. print '</td>';
  1007. }
  1008. if (! empty($arrayfields['f.total_vat']['checked']))
  1009. {
  1010. // Amount
  1011. print '<td class="liste_titre" align="right">';
  1012. print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.$search_montant_vat.'">';
  1013. print '</td>';
  1014. }
  1015. if (! empty($arrayfields['f.total_ttc']['checked']))
  1016. {
  1017. // Amount
  1018. print '<td class="liste_titre" align="right">';
  1019. print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.$search_montant_ttc.'">';
  1020. print '</td>';
  1021. }
  1022. if (! empty($arrayfields['am']['checked']))
  1023. {
  1024. print '<td class="liste_titre" align="right">';
  1025. print '</td>';
  1026. }
  1027. if (! empty($arrayfields['rtp']['checked']))
  1028. {
  1029. print '<td class="liste_titre" align="right">';
  1030. print '</td>';
  1031. }
  1032. // Extra fields
  1033. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  1034. {
  1035. foreach($extrafields->attribute_label as $key => $val)
  1036. {
  1037. if (! empty($arrayfields["ef.".$key]['checked']))
  1038. {
  1039. $align=$extrafields->getAlignFlag($key);
  1040. $typeofextrafield=$extrafields->attribute_type[$key];
  1041. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  1042. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  1043. {
  1044. $crit=$val;
  1045. $tmpkey=preg_replace('/search_options_/','',$key);
  1046. $searchclass='';
  1047. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  1048. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  1049. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  1050. }
  1051. print '</td>';
  1052. }
  1053. }
  1054. }
  1055. // Fields from hook
  1056. $parameters=array('arrayfields'=>$arrayfields);
  1057. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  1058. print $hookmanager->resPrint;
  1059. // Date creation
  1060. if (! empty($arrayfields['f.datec']['checked']))
  1061. {
  1062. print '<td class="liste_titre">';
  1063. print '</td>';
  1064. }
  1065. // Date modification
  1066. if (! empty($arrayfields['f.tms']['checked']))
  1067. {
  1068. print '<td class="liste_titre">';
  1069. print '</td>';
  1070. }
  1071. // Status
  1072. if (! empty($arrayfields['f.fk_statut']['checked']))
  1073. {
  1074. print '<td class="liste_titre maxwidthonsmartphone" align="right">';
  1075. $liststatus=array('0'=>$langs->trans("BillShortStatusDraft"), '1'=>$langs->trans("BillShortStatusNotPaid"), '2'=>$langs->trans("BillShortStatusPaid"), '3'=>$langs->trans("BillShortStatusCanceled"));
  1076. print $form->selectarray('search_status', $liststatus, $search_status, 1);
  1077. print '</td>';
  1078. }
  1079. // Action column
  1080. print '<td class="liste_titre" align="middle">';
  1081. $searchpitco=$form->showFilterAndCheckAddButtons(1, 'checkforselect', 1);
  1082. print $searchpitco;
  1083. print '</td>';
  1084. print "</tr>\n";
  1085. if ($num > 0)
  1086. {
  1087. $i=0;
  1088. $var=true;
  1089. $totalarray=array();
  1090. while ($i < min($num,$limit))
  1091. {
  1092. $obj = $db->fetch_object($resql);
  1093. $var=!$var;
  1094. $datelimit=$db->jdate($obj->datelimite);
  1095. $facturestatic->id=$obj->facid;
  1096. $facturestatic->ref=$obj->facnumber;
  1097. $facturestatic->type=$obj->type;
  1098. $facturestatic->statut=$obj->fk_statut;
  1099. $facturestatic->date_lim_reglement=$db->jdate($obj->datelimite);
  1100. print '<tr '.$bc[$var].'>';
  1101. if (! empty($arrayfields['f.facnumber']['checked']))
  1102. {
  1103. print '<td class="nowrap">';
  1104. $notetoshow=dol_string_nohtmltag(($user->societe_id>0?$obj->note_public:$obj->note_private),1);
  1105. $paiement = $facturestatic->getSommePaiement();
  1106. $remaintopay = $obj->total_ttc - $paiement;
  1107. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  1108. print '<td class="nobordernopadding nowrap">';
  1109. print $facturestatic->getNomUrl(1,'',200,0,$notetoshow);
  1110. print $obj->increment;
  1111. print '</td>';
  1112. print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
  1113. if (! empty($obj->note_private))
  1114. {
  1115. print ' <span class="note">';
  1116. print '<a href="'.DOL_URL_ROOT.'/compta/facture/note.php?id='.$obj->facid.'">'.img_picto($langs->trans("ViewPrivateNote"),'object_generic').'</a>';
  1117. print '</span>';
  1118. }
  1119. $filename=dol_sanitizeFileName($obj->facnumber);
  1120. $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->facnumber);
  1121. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->facid;
  1122. print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
  1123. print '</td>';
  1124. print '</tr>';
  1125. print '</table>';
  1126. print "</td>\n";
  1127. if (! $i) $totalarray['nbfield']++;
  1128. }
  1129. // Customer ref
  1130. if (! empty($arrayfields['f.ref_client']['checked']))
  1131. {
  1132. print '<td class="nowrap">';
  1133. print $obj->ref_client;
  1134. print '</td>';
  1135. if (! $i) $totalarray['nbfield']++;
  1136. }
  1137. // Date
  1138. if (! empty($arrayfields['f.date']['checked']))
  1139. {
  1140. print '<td align="center" class="nowrap">';
  1141. print dol_print_date($db->jdate($obj->df),'day');
  1142. print '</td>';
  1143. if (! $i) $totalarray['nbfield']++;
  1144. }
  1145. // Date limit
  1146. if (! empty($arrayfields['f.date_lim_reglement']['checked']))
  1147. {
  1148. print '<td align="center" class="nowrap">'.dol_print_date($datelimit,'day');
  1149. if ($facturestatic->hasDelay())
  1150. {
  1151. print img_warning($langs->trans('Late'));
  1152. }
  1153. print '</td>';
  1154. if (! $i) $totalarray['nbfield']++;
  1155. }
  1156. // Third party
  1157. if (! empty($arrayfields['s.nom']['checked']))
  1158. {
  1159. print '<td>';
  1160. $thirdparty=new Societe($db);
  1161. $thirdparty->id=$obj->socid;
  1162. $thirdparty->name=$obj->name;
  1163. $thirdparty->client=$obj->client;
  1164. $thirdparty->code_client=$obj->code_client;
  1165. print $thirdparty->getNomUrl(1,'customer');
  1166. print '</td>';
  1167. if (! $i) $totalarray['nbfield']++;
  1168. }
  1169. // Town
  1170. if (! empty($arrayfields['s.town']['checked']))
  1171. {
  1172. print '<td class="nocellnopadd">';
  1173. print $obj->town;
  1174. print '</td>';
  1175. if (! $i) $totalarray['nbfield']++;
  1176. }
  1177. // Zip
  1178. if (! empty($arrayfields['s.zip']['checked']))
  1179. {
  1180. print '<td class="nocellnopadd">';
  1181. print $obj->zip;
  1182. print '</td>';
  1183. if (! $i) $totalarray['nbfield']++;
  1184. }
  1185. // State
  1186. if (! empty($arrayfields['state.nom']['checked']))
  1187. {
  1188. print "<td>".$obj->state_name."</td>\n";
  1189. if (! $i) $totalarray['nbfield']++;
  1190. }
  1191. // Country
  1192. if (! empty($arrayfields['country.code_iso']['checked']))
  1193. {
  1194. print '<td align="center">';
  1195. $tmparray=getCountry($obj->fk_pays,'all');
  1196. print $tmparray['label'];
  1197. print '</td>';
  1198. if (! $i) $totalarray['nbfield']++;
  1199. }
  1200. // Type ent
  1201. if (! empty($arrayfields['typent.code']['checked']))
  1202. {
  1203. print '<td align="center">';
  1204. if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
  1205. print $typenArray[$obj->typent_code];
  1206. print '</td>';
  1207. if (! $i) $totalarray['nbfield']++;
  1208. }
  1209. // Payment mode
  1210. if (! empty($arrayfields['f.fk_mode_reglement']['checked']))
  1211. {
  1212. print '<td>';
  1213. $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
  1214. print '</td>';
  1215. if (! $i) $totalarray['nbfield']++;
  1216. }
  1217. // Amount HT
  1218. if (! empty($arrayfields['f.total_ht']['checked']))
  1219. {
  1220. print '<td align="right">'.price($obj->total_ht)."</td>\n";
  1221. if (! $i) $totalarray['nbfield']++;
  1222. if (! $i) $totalarray['totalhtfield']=$totalarray['nbfield'];
  1223. $totalarray['totalht'] += $obj->total_ht;
  1224. }
  1225. // Amount VAT
  1226. if (! empty($arrayfields['f.total_vat']['checked']))
  1227. {
  1228. print '<td align="right">'.price($obj->total_vat)."</td>\n";
  1229. if (! $i) $totalarray['nbfield']++;
  1230. if (! $i) $totalarray['totalvatfield']=$totalarray['nbfield'];
  1231. $totalarray['totalvat'] += $obj->total_vat;
  1232. }
  1233. // Amount TTC
  1234. if (! empty($arrayfields['f.total_ttc']['checked']))
  1235. {
  1236. print '<td align="right">'.price($obj->total_ttc)."</td>\n";
  1237. if (! $i) $totalarray['nbfield']++;
  1238. if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield'];
  1239. $totalarray['totalttc'] += $obj->total_ttc;
  1240. }
  1241. if (! empty($arrayfields['am']['checked']))
  1242. {
  1243. print '<td align="right">'.(! empty($paiement)?price($paiement,0,$langs):'&nbsp;').'</td>';
  1244. if (! $i) $totalarray['nbfield']++;
  1245. if (! $i) $totalarray['totalamfield']=$totalarray['nbfield'];
  1246. $totalarray['totalam'] += $paiement;
  1247. }
  1248. if (! empty($arrayfields['rtp']['checked']))
  1249. {
  1250. print '<td align="right">'.(! empty($remaintopay)?price($remaintopay,0,$langs):'&nbsp;').'</td>';
  1251. if (! $i) $totalarray['nbfield']++;
  1252. if (! $i) $totalarray['totalrtpfield']=$totalarray['nbfield'];
  1253. $totalarray['totalrtp'] += $remaintopay;
  1254. }
  1255. // Extra fields
  1256. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  1257. {
  1258. foreach($extrafields->attribute_label as $key => $val)
  1259. {
  1260. if (! empty($arrayfields["ef.".$key]['checked']))
  1261. {
  1262. print '<td';
  1263. $align=$extrafields->getAlignFlag($key);
  1264. if ($align) print ' align="'.$align.'"';
  1265. print '>';
  1266. $tmpkey='options_'.$key;
  1267. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  1268. print '</td>';
  1269. if (! $i) $totalarray['nbfield']++;
  1270. }
  1271. }
  1272. }
  1273. // Fields from hook
  1274. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  1275. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  1276. print $hookmanager->resPrint;
  1277. // Date creation
  1278. if (! empty($arrayfields['f.datec']['checked']))
  1279. {
  1280. print '<td align="center" class="nowrap">';
  1281. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  1282. print '</td>';
  1283. if (! $i) $totalarray['nbfield']++;
  1284. }
  1285. // Date modification
  1286. if (! empty($arrayfields['f.tms']['checked']))
  1287. {
  1288. print '<td align="center" class="nowrap">';
  1289. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  1290. print '</td>';
  1291. if (! $i) $totalarray['nbfield']++;
  1292. }
  1293. // Status
  1294. if (! empty($arrayfields['f.fk_statut']['checked']))
  1295. {
  1296. print '<td align="right" class="nowrap">';
  1297. print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$paiement,$obj->type);
  1298. print "</td>";
  1299. if (! $i) $totalarray['nbfield']++;
  1300. }
  1301. // Action column
  1302. print '<td class="nowrap" align="center">';
  1303. $selected=0;
  1304. if (in_array($obj->facid, $arrayofselected)) $selected=1;
  1305. print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected?' checked="checked"':'').'>';
  1306. print '</td>' ;
  1307. if (! $i) $totalarray['nbfield']++;
  1308. print "</tr>\n";
  1309. $i++;
  1310. }
  1311. // Show total line
  1312. if (isset($totalarray['totalhtfield']))
  1313. {
  1314. print '<tr class="liste_total">';
  1315. $i=0;
  1316. while ($i < $totalarray['nbfield'])
  1317. {
  1318. $i++;
  1319. if ($i == 1)
  1320. {
  1321. if ($num < $limit) print '<td align="left">'.$langs->trans("Total").'</td>';
  1322. else print '<td align="left">'.$langs->trans("Totalforthispage").'</td>';
  1323. }
  1324. elseif ($totalarray['totalhtfield'] == $i) print '<td align="right">'.price($totalarray['totalht']).'</td>';
  1325. elseif ($totalarray['totalvatfield'] == $i) print '<td align="right">'.price($totalarray['totalvat']).'</td>';
  1326. elseif ($totalarray['totalttcfield'] == $i) print '<td align="right">'.price($totalarray['totalttc']).'</td>';
  1327. elseif ($totalarray['totalamfield'] == $i) print '<td align="right">'.price($totalarray['totalam']).'</td>';
  1328. elseif ($totalarray['totalrtpfield'] == $i) print '<td align="right">'.price($totalarray['totalrtp']).'</td>';
  1329. else print '<td></td>';
  1330. }
  1331. print '</tr>';
  1332. }
  1333. }
  1334. $db->free($resql);
  1335. $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1336. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  1337. print $hookmanager->resPrint;
  1338. print "</table>\n";
  1339. print "</form>\n";
  1340. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
  1341. {
  1342. /*
  1343. * Show list of available documents
  1344. */
  1345. $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1346. $urlsource.=str_replace('&amp;','&',$param);
  1347. $filedir=$diroutputmassaction;
  1348. $genallowed=$user->rights->facture->lire;
  1349. $delallowed=$user->rights->facture->lire;
  1350. print '<br><a name="show_files"></a>';
  1351. $paramwithoutshowfiles=preg_replace('/show_files=1&?/','',$param);
  1352. $title=$langs->trans("MassFilesArea").' <a href="'.$_SERVER["PHP_SELF"].'?'.$paramwithoutshowfiles.'">('.$langs->trans("Hide").')</a>';
  1353. print $formfile->showdocuments('massfilesarea','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
  1354. }
  1355. else
  1356. {
  1357. print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
  1358. }
  1359. }
  1360. else
  1361. {
  1362. dol_print_error($db);
  1363. }
  1364. llxFooter();
  1365. $db->close();