list.php 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453
  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@inodbox.com>
  7. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  8. * Copyright (C) 2010-2020 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-2022 Ferran Marcet <fmarcet@2byte.es>
  14. * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
  15. * Copyright (C) 2018 Charlene Benke <charlie@patas-monkey.com>
  16. * Copyright (C) 2019-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 3 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  30. */
  31. /**
  32. * \file htdocs/compta/facture/list.php
  33. * \ingroup facture
  34. * \brief List of customer invoices
  35. */
  36. require '../../main.inc.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  40. if (!empty($conf->margin->enabled)) {
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php';
  42. }
  43. require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
  44. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  45. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
  46. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  48. require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  50. require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
  51. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  52. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  53. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  54. if (!empty($conf->commande->enabled)) {
  55. require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
  56. }
  57. // Load translation files required by the page
  58. $langs->loadLangs(array('bills', 'companies', 'products', 'categories'));
  59. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  60. $projectid = (GETPOST('projectid') ?GETPOST('projectid', 'int') : 0);
  61. $id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
  62. $ref = GETPOST('ref', 'alpha');
  63. $socid = GETPOST('socid', 'int');
  64. $action = GETPOST('action', 'aZ09');
  65. $massaction = GETPOST('massaction', 'alpha');
  66. $show_files = GETPOST('show_files', 'int');
  67. $confirm = GETPOST('confirm', 'alpha');
  68. $toselect = GETPOST('toselect', 'array');
  69. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'invoicelist';
  70. if ($contextpage == 'poslist') {
  71. $_GET['optioncss'] = 'print';
  72. }
  73. $lineid = GETPOST('lineid', 'int');
  74. $userid = GETPOST('userid', 'int');
  75. $search_product_category = GETPOST('search_product_category', 'int');
  76. $search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
  77. $search_refcustomer = GETPOST('search_refcustomer', 'alpha');
  78. $search_type = GETPOST('search_type', 'int');
  79. $search_project_ref = GETPOST('search_project_ref', 'alpha');
  80. $search_project = GETPOST('search_project', 'alpha');
  81. $search_company = GETPOST('search_company', 'alpha');
  82. $search_company_alias = GETPOST('search_company_alias', 'alpha');
  83. $search_montant_ht = GETPOST('search_montant_ht', 'alpha');
  84. $search_montant_vat = GETPOST('search_montant_vat', 'alpha');
  85. $search_montant_localtax1 = GETPOST('search_montant_localtax1', 'alpha');
  86. $search_montant_localtax2 = GETPOST('search_montant_localtax2', 'alpha');
  87. $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
  88. $search_login = GETPOST('search_login', 'alpha');
  89. $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
  90. $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
  91. $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
  92. $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
  93. $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
  94. $search_status = GETPOST('search_status', 'intcomma');
  95. $search_paymentmode = GETPOST('search_paymentmode', 'int');
  96. $search_paymentterms = GETPOST('search_paymentterms', 'int');
  97. $search_module_source = GETPOST('search_module_source', 'alpha');
  98. $search_pos_source = GETPOST('search_pos_source', 'alpha');
  99. $search_town = GETPOST('search_town', 'alpha');
  100. $search_zip = GETPOST('search_zip', 'alpha');
  101. $search_state = GETPOST("search_state");
  102. $search_country = GETPOST("search_country", 'alpha');
  103. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  104. $search_user = GETPOST('search_user', 'int');
  105. $search_sale = GETPOST('search_sale', 'int');
  106. $search_date_startday = GETPOST('search_date_startday', 'int');
  107. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  108. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  109. $search_date_endday = GETPOST('search_date_endday', 'int');
  110. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  111. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  112. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  113. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  114. $search_date_valid_startday = GETPOST('search_date_valid_startday', 'int');
  115. $search_date_valid_startmonth = GETPOST('search_date_valid_startmonth', 'int');
  116. $search_date_valid_startyear = GETPOST('search_date_valid_startyear', 'int');
  117. $search_date_valid_endday = GETPOST('search_date_valid_endday', 'int');
  118. $search_date_valid_endmonth = GETPOST('search_date_valid_endmonth', 'int');
  119. $search_date_valid_endyear = GETPOST('search_date_valid_endyear', 'int');
  120. $search_date_valid_start = dol_mktime(0, 0, 0, $search_date_valid_startmonth, $search_date_valid_startday, $search_date_valid_startyear); // Use tzserver
  121. $search_date_valid_end = dol_mktime(23, 59, 59, $search_date_valid_endmonth, $search_date_valid_endday, $search_date_valid_endyear);
  122. $search_datelimit_startday = GETPOST('search_datelimit_startday', 'int');
  123. $search_datelimit_startmonth = GETPOST('search_datelimit_startmonth', 'int');
  124. $search_datelimit_startyear = GETPOST('search_datelimit_startyear', 'int');
  125. $search_datelimit_endday = GETPOST('search_datelimit_endday', 'int');
  126. $search_datelimit_endmonth = GETPOST('search_datelimit_endmonth', 'int');
  127. $search_datelimit_endyear = GETPOST('search_datelimit_endyear', 'int');
  128. $search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear);
  129. $search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
  130. $search_categ_cus = GETPOST("search_categ_cus", 'int');
  131. $search_fac_rec_source_title = GETPOST("search_fac_rec_source_title", 'alpha');
  132. $search_btn = GETPOST('button_search', 'alpha');
  133. $search_remove_btn = GETPOST('button_removefilter', 'alpha');
  134. $optioncss = GETPOST('optioncss', 'alpha');
  135. $option = GETPOST('search_option');
  136. if ($option == 'late') {
  137. $search_status = '1';
  138. }
  139. $filtre = GETPOST('filtre', 'alpha');
  140. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  141. $sortfield = GETPOST('sortfield', 'aZ09comma');
  142. $sortorder = GETPOST('sortorder', 'aZ09comma');
  143. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  144. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  145. $page = 0;
  146. } // If $page is not defined, or '' or -1 or if we click on clear filters
  147. $offset = $limit * $page;
  148. if (!$sortorder && !empty($conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER) && $search_status == '1') {
  149. $sortorder = $conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER;
  150. }
  151. if (!$sortorder) {
  152. $sortorder = 'DESC';
  153. }
  154. if (!$sortfield) {
  155. $sortfield = 'f.datef';
  156. }
  157. $pageprev = $page - 1;
  158. $pagenext = $page + 1;
  159. // Security check
  160. $fieldid = (!empty($ref) ? 'ref' : 'rowid');
  161. if (!empty($user->socid)) {
  162. $socid = $user->socid;
  163. }
  164. $result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid);
  165. $diroutputmassaction = $conf->facture->dir_output.'/temp/massgeneration/'.$user->id;
  166. $object = new Facture($db);
  167. $now = dol_now();
  168. $error = 0;
  169. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  170. $object = new Facture($db);
  171. $hookmanager->initHooks(array('invoicelist'));
  172. $extrafields = new ExtraFields($db);
  173. // fetch optionals attributes and labels
  174. $extrafields->fetch_name_optionals_label($object->table_element);
  175. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  176. // List of fields to search into when doing a "search in all"
  177. $fieldstosearchall = array(
  178. 'f.ref'=>'Ref',
  179. 'f.ref_client'=>'RefCustomer',
  180. 'f.note_public'=>'NotePublic',
  181. 's.nom'=>"ThirdParty",
  182. 's.name_alias'=>"AliasNameShort",
  183. 's.zip'=>"Zip",
  184. 's.town'=>"Town",
  185. 'pd.description'=>'Description',
  186. );
  187. if (empty($user->socid)) {
  188. $fieldstosearchall["f.note_private"] = "NotePrivate";
  189. }
  190. $checkedtypetiers = 0;
  191. $arrayfields = array(
  192. 'f.ref'=>array('label'=>"Ref", 'checked'=>1, 'position'=>5),
  193. 'f.ref_client'=>array('label'=>"RefCustomer", 'checked'=>-1, 'position'=>10),
  194. 'f.type'=>array('label'=>"Type", 'checked'=>0, 'position'=>15),
  195. 'f.datef'=>array('label'=>"DateInvoice", 'checked'=>1, 'position'=>20),
  196. 'f.date_valid'=>array('label'=>"DateValidation", 'checked'=>0, 'position'=>22),
  197. 'f.date_lim_reglement'=>array('label'=>"DateDue", 'checked'=>1, 'position'=>25),
  198. 'f.date_closing'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>30),
  199. 'p.ref'=>array('label'=>"ProjectRef", 'checked'=>1, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 1), 'position'=>40),
  200. 'p.title'=>array('label'=>"ProjectLabel", 'checked'=>0, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 1), 'position'=>41),
  201. 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'position'=>50),
  202. 's.name_alias'=>array('label'=>"AliasNameShort", 'checked'=>1, 'position'=>51),
  203. 's.town'=>array('label'=>"Town", 'checked'=>-1, 'position'=>55),
  204. 's.zip'=>array('label'=>"Zip", 'checked'=>1, 'position'=>60),
  205. 'state.nom'=>array('label'=>"StateShort", 'checked'=>0, 'position'=>65),
  206. 'country.code_iso'=>array('label'=>"Country", 'checked'=>0, 'position'=>70),
  207. 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers, 'position'=>75),
  208. 'f.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>1, 'position'=>80),
  209. 'f.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>1, 'position'=>85),
  210. 'f.module_source'=>array('label'=>"POSModule", 'checked'=>($contextpage == 'poslist' ? 1 : 0), 'enabled'=>((empty($conf->cashdesk->enabled) && empty($conf->takepos->enabled) && empty($conf->global->INVOICE_SHOW_POS)) ? 0 : 1), 'position'=>90),
  211. 'f.pos_source'=>array('label'=>"POSTerminal", 'checked'=>($contextpage == 'poslist' ? 1 : 0), 'enabled'=>((empty($conf->cashdesk->enabled) && empty($conf->takepos->enabled) && empty($conf->global->INVOICE_SHOW_POS)) ? 0 : 1), 'position'=>91),
  212. 'f.total_ht'=>array('label'=>"AmountHT", 'checked'=>1, 'position'=>95),
  213. 'f.total_tva'=>array('label'=>"AmountVAT", 'checked'=>0, 'position'=>100),
  214. 'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>($mysoc->localtax1_assuj == "1"), 'position'=>110),
  215. 'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>($mysoc->localtax2_assuj == "1"), 'position'=>120),
  216. 'f.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0, 'position'=>130),
  217. 'dynamount_payed'=>array('label'=>"Received", 'checked'=>0, 'position'=>140),
  218. 'rtp'=>array('label'=>"Rest", 'checked'=>0, 'position'=>150), // Not enabled by default because slow
  219. 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>165),
  220. 'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>0, 'position'=>166),
  221. 'f.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>280),
  222. 'f.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>285),
  223. 'f.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>290),
  224. 'f.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>291),
  225. 'f.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>292),
  226. 'multicurrency_dynamount_payed'=>array('label'=>'MulticurrencyAlreadyPaid', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>295),
  227. 'multicurrency_rtp'=>array('label'=>'MulticurrencyRemainderToPay', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1), 'position'=>296), // Not enabled by default because slow
  228. 'total_pa' => array('label' => ($conf->global->MARGIN_TYPE == '1' ? 'BuyingPrice' : 'CostPrice'), 'checked' => 0, 'position' => 300, 'enabled' => (empty($conf->margin->enabled) || empty($user->rights->margins->liretous) ? 0 : 1)),
  229. 'total_margin' => array('label' => 'Margin', 'checked' => 0, 'position' => 301, 'enabled' => (empty($conf->margin->enabled) || empty($user->rights->margins->liretous) ? 0 : 1)),
  230. 'total_margin_rate' => array('label' => 'MarginRate', 'checked' => 0, 'position' => 302, 'enabled' => (empty($conf->margin->enabled) || empty($user->rights->margins->liretous) || empty($conf->global->DISPLAY_MARGIN_RATES) ? 0 : 1)),
  231. 'total_mark_rate' => array('label' => 'MarkRate', 'checked' => 0, 'position' => 303, 'enabled' => (empty($conf->margin->enabled) || empty($user->rights->margins->liretous) || empty($conf->global->DISPLAY_MARK_RATES) ? 0 : 1)),
  232. 'f.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  233. 'f.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>502),
  234. 'f.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES))),
  235. 'f.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES))),
  236. 'f.fk_fac_rec_source'=>array('label'=>'GeneratedFromTemplate', 'checked'=>0, 'position'=>520, 'enabled'=>'1'),
  237. 'f.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
  238. );
  239. if (getDolGlobalString("INVOICE_USE_SITUATION") && $conf->global->INVOICE_USE_RETAINED_WARRANTY) {
  240. $arrayfields['f.retained_warranty'] = array('label'=>$langs->trans("RetainedWarranty"), 'checked'=>0, 'position'=>86);
  241. }
  242. // Overwrite $arrayfields from columns into ->fields (transition before removal of $arrayoffields)
  243. foreach ($object->fields as $key => $val) {
  244. // If $val['visible']==0, then we never show the field
  245. if (!empty($val['visible'])) {
  246. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  247. $newkey = '';
  248. if (array_key_exists($key, $arrayfields)) { $newkey = $key; } elseif (array_key_exists('t.'.$key, $arrayfields)) { $newkey = 't.'.$key; } elseif (array_key_exists('f.'.$key, $arrayfields)) { $newkey = 'f.'.$key; } elseif (array_key_exists('s.'.$key, $arrayfields)) { $newkey = 's.'.$key; }
  249. if ($newkey) {
  250. $arrayfields[$newkey] = array(
  251. 'label'=>$val['label'],
  252. 'checked'=>(($visible < 0) ? 0 : 1),
  253. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  254. 'position'=>$val['position'],
  255. 'help' => empty($val['help']) ? '' : $val['help'],
  256. );
  257. }
  258. }
  259. }
  260. // Extra fields
  261. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  262. $object->fields = dol_sort_array($object->fields, 'position');
  263. $arrayfields = dol_sort_array($arrayfields, 'position');
  264. /*
  265. * Actions
  266. */
  267. if (GETPOST('cancel', 'alpha')) {
  268. $action = 'list';
  269. $massaction = '';
  270. }
  271. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  272. $massaction = '';
  273. }
  274. $parameters = array('socid'=>$socid);
  275. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  276. if ($reshook < 0) {
  277. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  278. }
  279. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  280. // Do we click on purge search criteria ?
  281. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha')) { // All tests are required to be compatible with all browsers
  282. $search_user = '';
  283. $search_sale = '';
  284. $search_product_category = '';
  285. $search_ref = '';
  286. $search_refcustomer = '';
  287. $search_type = '';
  288. $search_project_ref = '';
  289. $search_project = '';
  290. $search_company = '';
  291. $search_company_alias = '';
  292. $search_montant_ht = '';
  293. $search_montant_vat = '';
  294. $search_montant_localtax1 = '';
  295. $search_montant_localtax2 = '';
  296. $search_montant_ttc = '';
  297. $search_login = '';
  298. $search_multicurrency_code = '';
  299. $search_multicurrency_tx = '';
  300. $search_multicurrency_montant_ht = '';
  301. $search_multicurrency_montant_vat = '';
  302. $search_multicurrency_montant_ttc = '';
  303. $search_status = '';
  304. $search_paymentmode = '';
  305. $search_paymentterms = '';
  306. $search_module_source = '';
  307. $search_pos_source = '';
  308. $search_town = '';
  309. $search_zip = "";
  310. $search_state = "";
  311. $search_type = '';
  312. $search_country = '';
  313. $search_type_thirdparty = '';
  314. $search_date_startday = '';
  315. $search_date_startmonth = '';
  316. $search_date_startyear = '';
  317. $search_date_endday = '';
  318. $search_date_endmonth = '';
  319. $search_date_endyear = '';
  320. $search_date_start = '';
  321. $search_date_end = '';
  322. $search_date_valid_startday = '';
  323. $search_date_valid_startmonth = '';
  324. $search_date_valid_startyear = '';
  325. $search_date_valid_endday = '';
  326. $search_date_valid_endmonth = '';
  327. $search_date_valid_endyear = '';
  328. $search_date_valid_start = '';
  329. $search_date_valid_end = '';
  330. $search_datelimit_startday = '';
  331. $search_datelimit_startmonth = '';
  332. $search_datelimit_startyear = '';
  333. $search_datelimit_endday = '';
  334. $search_datelimit_endmonth = '';
  335. $search_datelimit_endyear = '';
  336. $search_datelimit_start = '';
  337. $search_datelimit_end = '';
  338. $search_fac_rec_source_title = '';
  339. $option = '';
  340. $filter = '';
  341. $toselect = array();
  342. $search_array_options = array();
  343. $search_categ_cus = 0;
  344. }
  345. if (empty($reshook)) {
  346. $objectclass = 'Facture';
  347. $objectlabel = 'Invoices';
  348. $permissiontoread = $user->rights->facture->lire;
  349. $permissiontoadd = $user->rights->facture->creer;
  350. $permissiontodelete = $user->rights->facture->supprimer;
  351. $uploaddir = $conf->facture->dir_output;
  352. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  353. }
  354. if ($action == 'makepayment_confirm' && !empty($user->rights->facture->paiement)) {
  355. require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php';
  356. $arrayofselected = is_array($toselect) ? $toselect : array();
  357. if (!empty($arrayofselected)) {
  358. $bankid = GETPOST('bankid', 'int');
  359. $paiementid = GETPOST('paiementid', 'int');
  360. $paiementdate = dol_mktime(12, 0, 0, GETPOST('datepaimentmonth', 'int'), GETPOST('datepaimentday', 'int'), GETPOST('datepaimentyear', 'year'));
  361. if (empty($paiementdate)) {
  362. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
  363. $error++;
  364. $action = 'makepayment';
  365. }
  366. if (!$error) {
  367. foreach ($arrayofselected as $toselectid) {
  368. $errorpayment = 0;
  369. $facture = new Facture($db);
  370. $result = $facture->fetch($toselectid);
  371. $db->begin();
  372. if ($result < 0) {
  373. setEventMessage($facture->error, 'errors');
  374. $errorpayment++;
  375. } else {
  376. if ($facture->type != Facture::TYPE_CREDIT_NOTE && $facture->statut == Facture::STATUS_VALIDATED && $facture->paye == 0) {
  377. $paiementAmount = $facture->getSommePaiement();
  378. $totalcreditnotes = $facture->getSumCreditNotesUsed();
  379. $totaldeposits = $facture->getSumDepositsUsed();
  380. $totalpay = $paiementAmount + $totalcreditnotes + $totaldeposits;
  381. $remaintopay = price2num($facture->total_ttc - $totalpay);
  382. if ($remaintopay != 0) {
  383. $resultBank = $facture->setBankAccount($bankid);
  384. if ($resultBank < 0) {
  385. setEventMessages($facture->error, null, 'errors');
  386. $errorpayment++;
  387. } else {
  388. $paiement = new Paiement($db);
  389. $paiement->datepaye = $paiementdate;
  390. $paiement->amounts[$facture->id] = $remaintopay; // Array with all payments dispatching with invoice id
  391. $paiement->multicurrency_amounts[$facture->id] = $remaintopay;
  392. $paiement->paiementid = $paiementid;
  393. $paiement_id = $paiement->create($user, 1, $facture->thirdparty);
  394. if ($paiement_id < 0) {
  395. $langs->load("errors");
  396. setEventMessages($facture->ref.' '.$langs->trans($paiement->error), $paiement->errors, 'errors');
  397. $errorpayment++;
  398. } else {
  399. $result = $paiement->addPaymentToBank($user, 'payment', '', $bankid, '', '');
  400. if ($result < 0) {
  401. $langs->load("errors");
  402. setEventMessages($facture->ref.' '.$langs->trans($paiement->error), $paiement->errors, 'errors');
  403. $errorpayment++;
  404. }
  405. }
  406. }
  407. } else {
  408. setEventMessage($langs->trans('NoPaymentAvailable', $facture->ref), 'warnings');
  409. $errorpayment++;
  410. }
  411. } else {
  412. setEventMessage($langs->trans('BulkPaymentNotPossibleForInvoice', $facture->ref), 'warnings');
  413. $errorpayment++;
  414. }
  415. }
  416. if (empty($errorpayment)) {
  417. setEventMessage($langs->trans('PaymentRegisteredAndInvoiceSetToPaid', $facture->ref));
  418. $db->commit();
  419. } else {
  420. $db->rollback();
  421. }
  422. }
  423. }
  424. }
  425. } elseif ($massaction == 'withdrawrequest') {
  426. $langs->load("withdrawals");
  427. if (!$user->rights->prelevement->bons->creer) {
  428. $error++;
  429. setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
  430. } else {
  431. //Checking error
  432. $error = 0;
  433. $arrayofselected = is_array($toselect) ? $toselect : array();
  434. $listofbills = array();
  435. foreach ($arrayofselected as $toselectid) {
  436. $objecttmp = new Facture($db);
  437. $result = $objecttmp->fetch($toselectid);
  438. if ($result > 0) {
  439. $totalpaye = $objecttmp->getSommePaiement();
  440. $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
  441. $totaldeposits = $objecttmp->getSumDepositsUsed();
  442. $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits, 'MT');
  443. if ($objecttmp->statut == Facture::STATUS_DRAFT) {
  444. $error++;
  445. setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
  446. } elseif ($objecttmp->paye || $objecttmp->resteapayer == 0) {
  447. $error++;
  448. setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
  449. } elseif ($objecttmp->resteapayer < 0) {
  450. $error++;
  451. setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
  452. }
  453. $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
  454. $rsql .= " , pfd.date_traite as date_traite";
  455. $rsql .= " , pfd.amount";
  456. $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
  457. $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
  458. $rsql .= " , ".MAIN_DB_PREFIX."user as u";
  459. $rsql .= " WHERE fk_facture = ".((int) $objecttmp->id);
  460. $rsql .= " AND pfd.fk_user_demande = u.rowid";
  461. $rsql .= " AND pfd.traite = 0";
  462. $rsql .= " ORDER BY pfd.date_demande DESC";
  463. $result_sql = $db->query($rsql);
  464. if ($result_sql) {
  465. $numprlv = $db->num_rows($result_sql);
  466. }
  467. if ($numprlv > 0) {
  468. $error++;
  469. setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings');
  470. } elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'PRE') {
  471. $error++;
  472. setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
  473. } else {
  474. $listofbills[] = $objecttmp; // $listofbills will only contains invoices with good payment method and no request already done
  475. }
  476. }
  477. }
  478. //Massive withdraw request for request with no errors
  479. if (!empty($listofbills)) {
  480. $nbwithdrawrequestok = 0;
  481. foreach ($listofbills as $aBill) {
  482. $db->begin();
  483. $result = $aBill->demande_prelevement($user, $aBill->resteapayer, 'direct-debit', 'facture');
  484. if ($result > 0) {
  485. $db->commit();
  486. $nbwithdrawrequestok++;
  487. } else {
  488. $db->rollback();
  489. setEventMessages($aBill->error, $aBill->errors, 'errors');
  490. }
  491. }
  492. if ($nbwithdrawrequestok > 0) {
  493. setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
  494. }
  495. }
  496. }
  497. }
  498. /*
  499. * View
  500. */
  501. $form = new Form($db);
  502. $formother = new FormOther($db);
  503. $formfile = new FormFile($db);
  504. $formmargin = null;
  505. if (!empty($conf->margin->enabled)) {
  506. $formmargin = new FormMargin($db);
  507. }
  508. $bankaccountstatic = new Account($db);
  509. $facturestatic = new Facture($db);
  510. $formcompany = new FormCompany($db);
  511. $companystatic = new Societe($db);
  512. $sql = 'SELECT';
  513. if ($sall || $search_product_category > 0 || $search_user > 0) {
  514. $sql = 'SELECT DISTINCT';
  515. }
  516. $sql .= ' f.rowid as id, f.ref, f.ref_client, f.fk_soc, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total_ht, f.total_tva, f.total_ttc,';
  517. $sql .= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,';
  518. $sql .= ' f.fk_user_author,';
  519. $sql .= ' f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva as multicurrency_total_vat, f.multicurrency_total_ttc,';
  520. $sql .= ' f.datef, f.date_valid, f.date_lim_reglement as datelimite, f.module_source, f.pos_source,';
  521. $sql .= ' f.paye as paye, f.fk_statut, f.close_code,';
  522. $sql .= ' f.datec as date_creation, f.tms as date_update, f.date_closing as date_closing,';
  523. $sql .= ' f.retained_warranty, f.retained_warranty_date_limit, f.situation_final, f.situation_cycle_ref, f.situation_counter,';
  524. $sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax, s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta as code_compta_client, s.code_compta_fournisseur,';
  525. $sql .= ' typent.code as typent_code,';
  526. $sql .= ' state.code_departement as state_code, state.nom as state_name,';
  527. $sql .= ' country.code as country_code,';
  528. $sql .= ' f.fk_fac_rec_source,';
  529. $sql .= ' p.rowid as project_id, p.ref as project_ref, p.title as project_label,';
  530. $sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender';
  531. // 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).
  532. // A Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
  533. // We disable this. It create a bug when searching with sall and sorting on status. Also it create performance troubles.
  534. /*
  535. if (!$sall) {
  536. $sql .= ', SUM(pf.amount) as dynamount_payed, SUM(pf.multicurrency_amount) as multicurrency_dynamount_payed';
  537. }
  538. */
  539. if ($search_categ_cus && $search_categ_cus != -1) {
  540. $sql .= ", cc.fk_categorie, cc.fk_soc";
  541. }
  542. // Add fields from extrafields
  543. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  544. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  545. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  546. }
  547. }
  548. // Add fields from hooks
  549. $parameters = array();
  550. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  551. $sql .= $hookmanager->resPrint;
  552. $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  553. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  554. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  555. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  556. if (!empty($search_categ_cus) && $search_categ_cus != '-1') {
  557. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ
  558. }
  559. $sql .= ', '.MAIN_DB_PREFIX.'facture as f';
  560. if ($sortfield == "f.datef") {
  561. $sql .= $db->hintindex('idx_facture_datef');
  562. }
  563. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  564. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
  565. }
  566. // We disable this. It create a bug when searching with sall and sorting on status. Also it create performance troubles.
  567. /*
  568. if (!$sall) {
  569. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid';
  570. }
  571. */
  572. if ($sall || $search_product_category > 0) {
  573. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as pd ON f.rowid=pd.fk_facture';
  574. }
  575. if ($search_product_category > 0) {
  576. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
  577. }
  578. if (!empty($search_fac_rec_source_title)) {
  579. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_rec as facrec ON f.fk_fac_rec_source=facrec.rowid';
  580. }
  581. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
  582. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid';
  583. // We'll need this table joined to the select in order to filter by sale
  584. if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
  585. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  586. }
  587. if ($search_user > 0) {
  588. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
  589. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
  590. }
  591. // Add table from hooks
  592. $parameters = array();
  593. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  594. $sql .= $hookmanager->resPrint;
  595. $sql .= ' WHERE f.fk_soc = s.rowid';
  596. $sql .= ' AND f.entity IN ('.getEntity('invoice').')';
  597. if (empty($user->rights->societe->client->voir) && !$socid) {
  598. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  599. }
  600. if ($search_product_category > 0) {
  601. $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
  602. }
  603. if ($socid > 0) {
  604. $sql .= ' AND s.rowid = '.((int) $socid);
  605. }
  606. if ($userid) {
  607. if ($userid == -1) {
  608. $sql .= ' AND f.fk_user_author IS NULL';
  609. } else {
  610. $sql .= ' AND f.fk_user_author = '.((int) $userid);
  611. }
  612. }
  613. if ($search_ref) {
  614. $sql .= natural_search('f.ref', $search_ref);
  615. }
  616. if ($search_refcustomer) {
  617. $sql .= natural_search('f.ref_client', $search_refcustomer);
  618. }
  619. if ($search_type != '' && $search_type != '-1') {
  620. $sql .= " AND f.type IN (".$db->sanitize($db->escape($search_type)).")";
  621. }
  622. if ($search_project_ref) {
  623. $sql .= natural_search('p.ref', $search_project_ref);
  624. }
  625. if ($search_project) {
  626. $sql .= natural_search('p.title', $search_project);
  627. }
  628. if ($search_company) {
  629. $sql .= natural_search('s.nom', $search_company);
  630. }
  631. if ($search_company_alias) {
  632. $sql .= natural_search('s.name_alias', $search_company_alias);
  633. }
  634. if ($search_town) {
  635. $sql .= natural_search('s.town', $search_town);
  636. }
  637. if ($search_zip) {
  638. $sql .= natural_search("s.zip", $search_zip);
  639. }
  640. if ($search_state) {
  641. $sql .= natural_search("state.nom", $search_state);
  642. }
  643. if (strlen(trim($search_country))) {
  644. $arrayofcode = getCountriesInEEC();
  645. $country_code_in_EEC = $country_code_in_EEC_without_me = '';
  646. foreach ($arrayofcode as $key => $value) {
  647. $country_code_in_EEC .= ($country_code_in_EEC ? "," : "")."'".$value."'";
  648. if ($value != $mysoc->country_code) {
  649. $country_code_in_EEC_without_me .= ($country_code_in_EEC_without_me ? "," : "")."'".$value."'";
  650. }
  651. }
  652. if ($search_country == 'special_allnotme') {
  653. $sql .= " AND country.code <> '".$db->escape($mysoc->country_code)."'";
  654. } elseif ($search_country == 'special_eec') {
  655. $sql .= " AND country.code IN (".$db->sanitize($country_code_in_EEC, 1).")";
  656. } elseif ($search_country == 'special_eecnotme') {
  657. $sql .= " AND country.code IN (".$db->sanitize($country_code_in_EEC_without_me, 1).")";
  658. } elseif ($search_country == 'special_noteec') {
  659. $sql .= " AND country.code NOT IN (".$db->sanitize($country_code_in_EEC, 1).")";
  660. } else {
  661. $sql .= natural_search("country.code", $search_country);
  662. }
  663. }
  664. if ($search_type_thirdparty != '' && $search_type_thirdparty != '-1') {
  665. $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
  666. }
  667. if ($search_montant_ht != '') {
  668. $sql .= natural_search('f.total_ht', $search_montant_ht, 1);
  669. }
  670. if ($search_montant_vat != '') {
  671. $sql .= natural_search('f.total_tva', $search_montant_vat, 1);
  672. }
  673. if ($search_montant_localtax1 != '') {
  674. $sql .= natural_search('f.localtax1', $search_montant_localtax1, 1);
  675. }
  676. if ($search_montant_localtax2 != '') {
  677. $sql .= natural_search('f.localtax2', $search_montant_localtax2, 1);
  678. }
  679. if ($search_montant_ttc != '') {
  680. $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
  681. }
  682. if ($search_multicurrency_code != '') {
  683. $sql .= " AND f.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
  684. }
  685. if ($search_multicurrency_tx != '') {
  686. $sql .= natural_search('f.multicurrency_tx', $search_multicurrency_tx, 1);
  687. }
  688. if ($search_multicurrency_montant_ht != '') {
  689. $sql .= natural_search('f.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
  690. }
  691. if ($search_multicurrency_montant_vat != '') {
  692. $sql .= natural_search('f.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
  693. }
  694. if ($search_multicurrency_montant_ttc != '') {
  695. $sql .= natural_search('f.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
  696. }
  697. if ($search_login) {
  698. $sql .= natural_search(array('u.login', 'u.firstname', 'u.lastname'), $search_login);
  699. }
  700. if ($search_categ_cus > 0) {
  701. $sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
  702. }
  703. if ($search_categ_cus == -2) {
  704. $sql .= " AND cc.fk_categorie IS NULL";
  705. }
  706. if ($search_status != '-1' && $search_status != '') {
  707. if (is_numeric($search_status) && $search_status >= 0) {
  708. if ($search_status == '0') {
  709. $sql .= " AND f.fk_statut = 0"; // draft
  710. }
  711. if ($search_status == '1') {
  712. $sql .= " AND f.fk_statut = 1"; // unpayed
  713. }
  714. if ($search_status == '2') {
  715. $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)
  716. }
  717. if ($search_status == '3') {
  718. $sql .= " AND f.fk_statut = 3"; // abandonned
  719. }
  720. } else {
  721. $sql .= " AND f.fk_statut IN (".$db->sanitize($db->escape($search_status)).")"; // When search_status is '1,2' for example
  722. }
  723. }
  724. if ($search_paymentmode > 0) {
  725. $sql .= " AND f.fk_mode_reglement = ".((int) $search_paymentmode);
  726. }
  727. if ($search_paymentterms > 0) {
  728. $sql .= " AND f.fk_cond_reglement = ".((int) $search_paymentterms);
  729. }
  730. if ($search_module_source) {
  731. $sql .= natural_search("f.module_source", $search_module_source);
  732. }
  733. if ($search_pos_source) {
  734. $sql .= natural_search("f.pos_source", $search_pos_source);
  735. }
  736. if ($search_date_start) {
  737. $sql .= " AND f.datef >= '".$db->idate($search_date_start)."'";
  738. }
  739. if ($search_date_end) {
  740. $sql .= " AND f.datef <= '".$db->idate($search_date_end)."'";
  741. }
  742. if ($search_date_valid_start) {
  743. $sql .= " AND f.date_valid >= '".$db->idate($search_date_valid_start)."'";
  744. }
  745. if ($search_date_valid_end) {
  746. $sql .= " AND f.date_valid <= '".$db->idate($search_date_valid_end)."'";
  747. }
  748. if ($search_datelimit_start) {
  749. $sql .= " AND f.date_lim_reglement >= '".$db->idate($search_datelimit_start)."'";
  750. }
  751. if ($search_datelimit_end) {
  752. $sql .= " AND f.date_lim_reglement <= '".$db->idate($search_datelimit_end)."'";
  753. }
  754. if ($option == 'late') {
  755. $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->client->warning_delay)."'";
  756. }
  757. if ($search_sale > 0) {
  758. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
  759. }
  760. if ($search_user > 0) {
  761. $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 = ".((int) $search_user);
  762. }
  763. if (!empty($search_fac_rec_source_title)) {
  764. $sql .= natural_search('facrec.titre', $search_fac_rec_source_title);
  765. }
  766. // Add where from extra fields
  767. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  768. // Add where from hooks
  769. $parameters = array();
  770. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  771. $sql .= $hookmanager->resPrint;
  772. // We disable this. It create a bug when searching with sall and sorting on status. Also it create performance troubles.
  773. /*
  774. if (!$sall) {
  775. $sql .= ' GROUP BY f.rowid, f.ref, ref_client, f.fk_soc, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total_ht, f.total_tva, f.total_ttc,';
  776. $sql .= ' f.localtax1, f.localtax2,';
  777. $sql .= ' f.datef, f.date_valid, f.date_lim_reglement, f.module_source, f.pos_source,';
  778. $sql .= ' f.paye, f.fk_statut, f.close_code,';
  779. $sql .= ' f.datec, f.tms, f.date_closing,';
  780. $sql .= ' f.retained_warranty, f.retained_warranty_date_limit, f.situation_final, f.situation_cycle_ref, f.situation_counter,';
  781. $sql .= ' f.fk_user_author, f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht,';
  782. $sql .= ' f.multicurrency_total_tva, f.multicurrency_total_ttc,';
  783. $sql .= ' s.rowid, s.nom, s.name_alias, s.email, s.phone, s.fax, s.address, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,';
  784. $sql .= ' typent.code,';
  785. $sql .= ' state.code_departement, state.nom,';
  786. $sql .= ' country.code,';
  787. $sql .= " p.rowid, p.ref, p.title,";
  788. $sql .= " u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender";
  789. if ($search_categ_cus && $search_categ_cus != -1) {
  790. $sql .= ", cc.fk_categorie, cc.fk_soc";
  791. }
  792. // Add fields from extrafields
  793. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  794. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  795. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
  796. }
  797. }
  798. // Add GroupBy from hooks
  799. $parameters = array('all' => !empty($all) ? $all : 0, 'fieldstosearchall' => $fieldstosearchall);
  800. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  801. $sql .= $hookmanager->resPrint;
  802. } else {
  803. */
  804. if ($sall) {
  805. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  806. }
  807. // Add HAVING from hooks
  808. $parameters = array();
  809. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
  810. $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
  811. $nbtotalofrecords = '';
  812. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  813. /* This old and fast method to get and count full list returns all record so use a high amount of memory.
  814. $result = $db->query($sql);
  815. $nbtotalofrecords = $db->num_rows($result);
  816. */
  817. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  818. if ($sall || $search_product_category > 0 || $search_user > 0) {
  819. $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(DISTINCT f.rowid) as nbtotalofrecords FROM', $sql);
  820. } else {
  821. $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(f.rowid) as nbtotalofrecords FROM', $sql);
  822. $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid/', '', $sqlforcount);
  823. }
  824. $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount);
  825. $resql = $db->query($sqlforcount);
  826. if ($resql) {
  827. $objforcount = $db->fetch_object($resql);
  828. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  829. } else {
  830. dol_print_error($db);
  831. }
  832. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  833. $page = 0;
  834. $offset = 0;
  835. }
  836. $db->free($resql);
  837. }
  838. // Complete request and execute it with limit
  839. $sql .= ' ORDER BY ';
  840. $listfield = explode(',', $sortfield);
  841. $listorder = explode(',', $sortorder);
  842. foreach ($listfield as $key => $value) {
  843. $sql .= $listfield[$key].' '.($listorder[$key] ? $listorder[$key] : 'DESC').',';
  844. }
  845. $sql .= ' f.rowid DESC ';
  846. if ($limit) {
  847. $sql .= $db->plimit($limit + 1, $offset);
  848. }
  849. $resql = $db->query($sql);
  850. if ($resql) {
  851. $num = $db->num_rows($resql);
  852. $arrayofselected = is_array($toselect) ? $toselect : array();
  853. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
  854. $obj = $db->fetch_object($resql);
  855. $id = $obj->id;
  856. header("Location: ".DOL_URL_ROOT.'/compta/facture/card.php?facid='.$id);
  857. exit;
  858. }
  859. llxHeader('', $langs->trans('CustomersInvoices'), 'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes');
  860. if ($socid) {
  861. $soc = new Societe($db);
  862. $soc->fetch($socid);
  863. if (empty($search_company)) {
  864. $search_company = $soc->name;
  865. }
  866. }
  867. $param = '&socid='.urlencode($socid);
  868. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  869. $param .= '&contextpage='.urlencode($contextpage);
  870. }
  871. if ($limit > 0 && $limit != $conf->liste_limit) {
  872. $param .= '&limit='.urlencode($limit);
  873. }
  874. if ($sall) {
  875. $param .= '&sall='.urlencode($sall);
  876. }
  877. if ($search_date_startday) {
  878. $param .= '&search_date_startday='.urlencode($search_date_startday);
  879. }
  880. if ($search_date_startmonth) {
  881. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  882. }
  883. if ($search_date_startyear) {
  884. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  885. }
  886. if ($search_date_endday) {
  887. $param .= '&search_date_endday='.urlencode($search_date_endday);
  888. }
  889. if ($search_date_endmonth) {
  890. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  891. }
  892. if ($search_date_endyear) {
  893. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  894. }
  895. if ($search_date_valid_startday) {
  896. $param .= '&search_date_valid_startday='.urlencode($search_date_valid_startday);
  897. }
  898. if ($search_date_valid_startmonth) {
  899. $param .= '&search_date_valid_startmonth='.urlencode($search_date_valid_startmonth);
  900. }
  901. if ($search_date_valid_startyear) {
  902. $param .= '&search_date_valid_startyear='.urlencode($search_date_valid_startyear);
  903. }
  904. if ($search_date_valid_endday) {
  905. $param .= '&search_date_valid_endday='.urlencode($search_date_valid_endday);
  906. }
  907. if ($search_date_valid_endmonth) {
  908. $param .= '&search_date_valid_endmonth='.urlencode($search_date_valid_endmonth);
  909. }
  910. if ($search_date_valid_endyear) {
  911. $param .= '&search_date_valid_endyear='.urlencode($search_date_valid_endyear);
  912. }
  913. if ($search_datelimit_startday) {
  914. $param .= '&search_datelimit_startday='.urlencode($search_datelimit_startday);
  915. }
  916. if ($search_datelimit_startmonth) {
  917. $param .= '&search_datelimit_startmonth='.urlencode($search_datelimit_startmonth);
  918. }
  919. if ($search_datelimit_startyear) {
  920. $param .= '&search_datelimit_startyear='.urlencode($search_datelimit_startyear);
  921. }
  922. if ($search_datelimit_endday) {
  923. $param .= '&search_datelimit_endday='.urlencode($search_datelimit_endday);
  924. }
  925. if ($search_datelimit_endmonth) {
  926. $param .= '&search_datelimit_endmonth='.urlencode($search_datelimit_endmonth);
  927. }
  928. if ($search_datelimit_endyear) {
  929. $param .= '&search_datelimit_endyear='.urlencode($search_datelimit_endyear);
  930. }
  931. if ($search_ref) {
  932. $param .= '&search_ref='.urlencode($search_ref);
  933. }
  934. if ($search_refcustomer) {
  935. $param .= '&search_refcustomer='.urlencode($search_refcustomer);
  936. }
  937. if ($search_project_ref) {
  938. $param .= '&search_project_ref='.urlencode($search_project_ref);
  939. }
  940. if ($search_project) {
  941. $param .= '&search_project='.urlencode($search_project);
  942. }
  943. if ($search_type != '') {
  944. $param .= '&search_type='.urlencode($search_type);
  945. }
  946. if ($search_company) {
  947. $param .= '&search_societe='.urlencode($search_company);
  948. }
  949. if ($search_company_alias) {
  950. $param .= '&search_societe_alias='.urlencode($search_company_alias);
  951. }
  952. if ($search_town) {
  953. $param .= '&search_town='.urlencode($search_town);
  954. }
  955. if ($search_zip) {
  956. $param .= '&search_zip='.urlencode($search_zip);
  957. }
  958. if ($search_country) {
  959. $param .= "&search_country=".urlencode($search_country);
  960. }
  961. if ($search_sale > 0) {
  962. $param .= '&search_sale='.urlencode($search_sale);
  963. }
  964. if ($search_user > 0) {
  965. $param .= '&search_user='.urlencode($search_user);
  966. }
  967. if ($search_login) {
  968. $param .= '&search_login='.urlencode($search_login);
  969. }
  970. if ($search_product_category > 0) {
  971. $param .= '&search_product_category='.urlencode($search_product_category);
  972. }
  973. if ($search_montant_ht != '') {
  974. $param .= '&search_montant_ht='.urlencode($search_montant_ht);
  975. }
  976. if ($search_montant_vat != '') {
  977. $param .= '&search_montant_vat='.urlencode($search_montant_vat);
  978. }
  979. if ($search_montant_localtax1 != '') {
  980. $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
  981. }
  982. if ($search_montant_localtax2 != '') {
  983. $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
  984. }
  985. if ($search_montant_ttc != '') {
  986. $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
  987. }
  988. if ($search_multicurrency_code != '') {
  989. $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
  990. }
  991. if ($search_multicurrency_tx != '') {
  992. $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
  993. }
  994. if ($search_multicurrency_montant_ht != '') {
  995. $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
  996. }
  997. if ($search_multicurrency_montant_vat != '') {
  998. $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
  999. }
  1000. if ($search_multicurrency_montant_ttc != '') {
  1001. $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
  1002. }
  1003. if ($search_status != '') {
  1004. $param .= '&search_status='.urlencode($search_status);
  1005. }
  1006. if ($search_paymentmode > 0) {
  1007. $param .= '&search_paymentmode='.urlencode($search_paymentmode);
  1008. }
  1009. if ($search_paymentterms > 0) {
  1010. $param .= '&search_paymentterms='.urlencode($search_paymentterms);
  1011. }
  1012. if ($search_module_source) {
  1013. $param .= '&search_module_source='.urlencode($search_module_source);
  1014. }
  1015. if ($search_pos_source) {
  1016. $param .= '&search_pos_source='.urlencode($search_pos_source);
  1017. }
  1018. if ($show_files) {
  1019. $param .= '&show_files='.urlencode($show_files);
  1020. }
  1021. if ($option) {
  1022. $param .= "&search_option=".urlencode($option);
  1023. }
  1024. if ($optioncss != '') {
  1025. $param .= '&optioncss='.urlencode($optioncss);
  1026. }
  1027. if ($search_categ_cus > 0) {
  1028. $param .= '&search_categ_cus='.urlencode($search_categ_cus);
  1029. }
  1030. if (!empty($search_fac_rec_source_title)) {
  1031. $param .= '&$search_fac_rec_source_title='.urlencode($search_fac_rec_source_title);
  1032. }
  1033. // Add $param from extra fields
  1034. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  1035. // Add $param from hooks
  1036. $parameters = array();
  1037. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  1038. $param .= $hookmanager->resPrint;
  1039. $arrayofmassactions = array(
  1040. 'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  1041. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  1042. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  1043. 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  1044. );
  1045. if (!empty($user->rights->facture->paiement)) {
  1046. $arrayofmassactions['makepayment'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakePaymentAndClassifyPayed");
  1047. }
  1048. if ($conf->prelevement->enabled && !empty($user->rights->prelevement->bons->creer)) {
  1049. $langs->load("withdrawals");
  1050. $arrayofmassactions['withdrawrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeWithdrawRequest");
  1051. }
  1052. if ($user->rights->facture->supprimer) {
  1053. if (!empty($conf->global->INVOICE_CAN_REMOVE_DRAFT_ONLY)) {
  1054. $arrayofmassactions['predeletedraft'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Deletedraft");
  1055. } elseif (!empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) { // mass deletion never possible on invoices on such situation
  1056. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  1057. }
  1058. }
  1059. if (in_array($massaction, array('presend', 'predelete', 'makepayment'))) {
  1060. $arrayofmassactions = array();
  1061. }
  1062. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  1063. // Show the new button only when this page is not opend from the Extended POS
  1064. if ($contextpage != 'poslist') {
  1065. $url = DOL_URL_ROOT.'/compta/facture/card.php?action=create';
  1066. if (!empty($socid)) {
  1067. $url .= '&socid='.$socid;
  1068. }
  1069. $newcardbutton = dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', $user->rights->facture->creer);
  1070. }
  1071. $i = 0;
  1072. print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  1073. if ($optioncss != '') {
  1074. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  1075. }
  1076. print '<input type="hidden" name="token" value="'.newToken().'">';
  1077. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  1078. if (!in_array($massaction, array('makepayment'))) {
  1079. print '<input type="hidden" name="action" value="list">';
  1080. }
  1081. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  1082. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  1083. print '<input type="hidden" name="search_status" value="'.$search_status.'">';
  1084. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  1085. print_barre_liste($langs->trans('BillsCustomers').' '.($socid ? ' '.$soc->name : ''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bill', 0, $newcardbutton, '', $limit, 0, 0, 1);
  1086. $topicmail = "SendBillRef";
  1087. $modelmail = "facture_send";
  1088. $objecttmp = new Facture($db);
  1089. $trackid = 'inv'.$object->id;
  1090. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  1091. if ($massaction == 'makepayment') {
  1092. $formconfirm = '';
  1093. $formquestion = array(
  1094. // 'text' => $langs->trans("ConfirmClone"),
  1095. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  1096. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  1097. array('type' => 'date', 'name' => 'datepaiment', 'label' => $langs->trans("Date"), 'datenow' => 1),
  1098. array('type' => 'other', 'name' => 'paiementid', 'label' => $langs->trans("PaymentMode"), 'value' => $form->select_types_paiements(GETPOST('search_paymentmode'), 'paiementid', '', 0, 0, 1, 0, 1, '', 1)),
  1099. array('type' => 'other', 'name' => 'bankid', 'label' => $langs->trans("BankAccount"), 'value'=>$form->select_comptes('', 'bankid', 0, '', 0, '', 0, '', 1)),
  1100. //array('type' => 'other', 'name' => 'invoicesid', 'label' => '', 'value'=>'<input type="hidden" id="invoicesid" name="invoicesid" value="'.implode('#',GETPOST('toselect','array')).'">'),
  1101. );
  1102. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('MakePaymentAndClassifyPayed'), $langs->trans('EnterPaymentReceivedFromCustomer'), 'makepayment_confirm', $formquestion, 1, 0, 200, 500, 1);
  1103. print $formconfirm;
  1104. }
  1105. if ($sall) {
  1106. foreach ($fieldstosearchall as $key => $val) {
  1107. $fieldstosearchall[$key] = $langs->trans($val);
  1108. }
  1109. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  1110. }
  1111. // If the user can view prospects other than his'
  1112. $moreforfilter = '';
  1113. if ($user->rights->user->user->lire) {
  1114. $langs->load("commercial");
  1115. $moreforfilter .= '<div class="divsearchfield">';
  1116. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  1117. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250');
  1118. $moreforfilter .= '</div>';
  1119. }
  1120. // If the user can view prospects other than his'
  1121. if ($user->rights->user->user->lire) {
  1122. $moreforfilter .= '<div class="divsearchfield">';
  1123. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  1124. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250');
  1125. $moreforfilter .= '</div>';
  1126. }
  1127. // Filter on product tags
  1128. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
  1129. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1130. $moreforfilter .= '<div class="divsearchfield">';
  1131. $tmptitle = $langs->trans('IncludingProductWithTag');
  1132. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  1133. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth250', 1);
  1134. $moreforfilter .= '</div>';
  1135. }
  1136. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
  1137. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  1138. $moreforfilter .= '<div class="divsearchfield">';
  1139. $tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
  1140. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle);
  1141. $moreforfilter .= '</div>';
  1142. }
  1143. $parameters = array();
  1144. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1145. if (empty($reshook)) {
  1146. $moreforfilter .= $hookmanager->resPrint;
  1147. } else {
  1148. $moreforfilter = $hookmanager->resPrint;
  1149. }
  1150. if ($moreforfilter) {
  1151. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1152. print $moreforfilter;
  1153. print '</div>';
  1154. }
  1155. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  1156. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  1157. // Show the massaction checkboxes only when this page is not opend from the Extended POS
  1158. if ($massactionbutton && $contextpage != 'poslist') {
  1159. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  1160. }
  1161. print '<div class="div-table-responsive">';
  1162. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  1163. // Filters lines
  1164. print '<tr class="liste_titre_filter">';
  1165. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  1166. print '<td class="liste_titre">';
  1167. print '</td>';
  1168. }
  1169. // Ref
  1170. if (!empty($arrayfields['f.ref']['checked'])) {
  1171. print '<td class="liste_titre" align="left">';
  1172. print '<input class="flat maxwidth50imp" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  1173. print '</td>';
  1174. }
  1175. // Ref customer
  1176. if (!empty($arrayfields['f.ref_client']['checked'])) {
  1177. print '<td class="liste_titre">';
  1178. print '<input class="flat maxwidth50imp" type="text" name="search_refcustomer" value="'.dol_escape_htmltag($search_refcustomer).'">';
  1179. print '</td>';
  1180. }
  1181. // Type
  1182. if (!empty($arrayfields['f.type']['checked'])) {
  1183. print '<td class="liste_titre maxwidthonsmartphone">';
  1184. $listtype = array(
  1185. Facture::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
  1186. Facture::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
  1187. Facture::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
  1188. Facture::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
  1189. );
  1190. if (!empty($conf->global->INVOICE_USE_SITUATION)) {
  1191. $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
  1192. }
  1193. //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
  1194. print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
  1195. print '</td>';
  1196. }
  1197. // Date invoice
  1198. if (!empty($arrayfields['f.datef']['checked'])) {
  1199. print '<td class="liste_titre center">';
  1200. print '<div class="nowrap">';
  1201. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1202. print '</div>';
  1203. print '<div class="nowrap">';
  1204. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1205. print '</div>';
  1206. print '</td>';
  1207. }
  1208. // Date valid
  1209. if (!empty($arrayfields['f.date_valid']['checked'])) {
  1210. print '<td class="liste_titre center">';
  1211. print '<div class="nowrap">';
  1212. print $form->selectDate($search_date_valid_start ? $search_date_valid_start : -1, 'search_date_valid_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1213. print '</div>';
  1214. print '<div class="nowrap">';
  1215. print $form->selectDate($search_date_valid_end ? $search_date_valid_end : -1, 'search_date_valid_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1216. print '</div>';
  1217. print '</td>';
  1218. }
  1219. // Date due
  1220. if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
  1221. print '<td class="liste_titre center">';
  1222. print '<div class="nowrap">';
  1223. /*
  1224. print $langs->trans('From').' ';
  1225. print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
  1226. print '</div>';
  1227. print '<div class="nowrap">';
  1228. print $langs->trans('to').' ';*/
  1229. print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
  1230. print '<br><input type="checkbox" name="search_option" value="late"'.($option == 'late' ? ' checked' : '').'> '.$langs->trans("Alert");
  1231. print '</div>';
  1232. print '</td>';
  1233. }
  1234. // Project ref
  1235. if (!empty($arrayfields['p.ref']['checked'])) {
  1236. print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project_ref" value="'.$search_project_ref.'"></td>';
  1237. }
  1238. // Project label
  1239. if (!empty($arrayfields['p.title']['checked'])) {
  1240. print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_project" value="'.$search_project.'"></td>';
  1241. }
  1242. // Thirdparty
  1243. if (!empty($arrayfields['s.nom']['checked'])) {
  1244. print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company" value="'.$search_company.'"></td>';
  1245. }
  1246. // Alias
  1247. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1248. print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_company_alias" value="'.$search_company_alias.'"></td>';
  1249. }
  1250. // Town
  1251. if (!empty($arrayfields['s.town']['checked'])) {
  1252. print '<td class="liste_titre"><input class="flat maxwidth75imp" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
  1253. }
  1254. // Zip
  1255. if (!empty($arrayfields['s.zip']['checked'])) {
  1256. print '<td class="liste_titre"><input class="flat maxwidth50imp" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
  1257. }
  1258. // State
  1259. if (!empty($arrayfields['state.nom']['checked'])) {
  1260. print '<td class="liste_titre">';
  1261. print '<input class="flat maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  1262. print '</td>';
  1263. }
  1264. // Country
  1265. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1266. print '<td class="liste_titre" align="center">';
  1267. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth150imp maxwidth150', 'code2', 1, 0, 1, null, 1);
  1268. print '</td>';
  1269. }
  1270. // Company type
  1271. if (!empty($arrayfields['typent.code']['checked'])) {
  1272. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  1273. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), 'maxwidth100', 1);
  1274. print '</td>';
  1275. }
  1276. // Payment mode
  1277. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  1278. print '<td class="liste_titre">';
  1279. $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 10);
  1280. print '</td>';
  1281. }
  1282. // Payment terms
  1283. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  1284. print '<td class="liste_titre">';
  1285. $form->select_conditions_paiements($search_paymentterms, 'search_paymentterms', -1, 1, 1);
  1286. print '</td>';
  1287. }
  1288. // Module source
  1289. if (!empty($arrayfields['f.module_source']['checked'])) {
  1290. print '<td class="liste_titre">';
  1291. print '<input class="flat maxwidth75" type="text" name="search_module_source" value="'.dol_escape_htmltag($search_module_source).'">';
  1292. print '</td>';
  1293. }
  1294. // POS Terminal
  1295. if (!empty($arrayfields['f.pos_source']['checked'])) {
  1296. print '<td class="liste_titre">';
  1297. print '<input class="flat maxwidth50" type="text" name="search_pos_source" value="'.dol_escape_htmltag($search_pos_source).'">';
  1298. print '</td>';
  1299. }
  1300. if (!empty($arrayfields['f.total_ht']['checked'])) {
  1301. // Amount
  1302. print '<td class="liste_titre right">';
  1303. print '<input class="flat" type="text" size="4" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
  1304. print '</td>';
  1305. }
  1306. if (!empty($arrayfields['f.total_tva']['checked'])) {
  1307. // Amount
  1308. print '<td class="liste_titre right">';
  1309. print '<input class="flat" type="text" size="4" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
  1310. print '</td>';
  1311. }
  1312. if (!empty($arrayfields['f.total_localtax1']['checked'])) {
  1313. // Localtax1
  1314. print '<td class="liste_titre right">';
  1315. print '<input class="flat" type="text" size="4" name="search_montant_localtax1" value="'.$search_montant_localtax1.'">';
  1316. print '</td>';
  1317. }
  1318. if (!empty($arrayfields['f.total_localtax2']['checked'])) {
  1319. // Localtax2
  1320. print '<td class="liste_titre right">';
  1321. print '<input class="flat" type="text" size="4" name="search_montant_localtax2" value="'.$search_montant_localtax2.'">';
  1322. print '</td>';
  1323. }
  1324. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  1325. // Amount
  1326. print '<td class="liste_titre right">';
  1327. print '<input class="flat" type="text" size="4" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
  1328. print '</td>';
  1329. }
  1330. if (!empty($arrayfields['u.login']['checked'])) {
  1331. // Author
  1332. print '<td class="liste_titre" align="center">';
  1333. print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
  1334. print '</td>';
  1335. }
  1336. if (!empty($arrayfields['sale_representative']['checked'])) {
  1337. print '<td class="liste_titre"></td>';
  1338. }
  1339. if (!empty($arrayfields['f.retained_warranty']['checked'])) {
  1340. print '<td class="liste_titre" align="right">';
  1341. print '</td>';
  1342. }
  1343. if (!empty($arrayfields['dynamount_payed']['checked'])) {
  1344. print '<td class="liste_titre right">';
  1345. print '</td>';
  1346. }
  1347. if (!empty($arrayfields['rtp']['checked'])) {
  1348. print '<td class="liste_titre right">';
  1349. print '</td>';
  1350. }
  1351. if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
  1352. // Currency
  1353. print '<td class="liste_titre">';
  1354. print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
  1355. print '</td>';
  1356. }
  1357. if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
  1358. // Currency rate
  1359. print '<td class="liste_titre">';
  1360. print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
  1361. print '</td>';
  1362. }
  1363. if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
  1364. // Amount
  1365. print '<td class="liste_titre right">';
  1366. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
  1367. print '</td>';
  1368. }
  1369. if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
  1370. // Amount
  1371. print '<td class="liste_titre right">';
  1372. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
  1373. print '</td>';
  1374. }
  1375. if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
  1376. // Amount
  1377. print '<td class="liste_titre right">';
  1378. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
  1379. print '</td>';
  1380. }
  1381. if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
  1382. print '<td class="liste_titre">';
  1383. print '</td>';
  1384. }
  1385. if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
  1386. print '<td class="liste_titre right">';
  1387. print '</td>';
  1388. }
  1389. if (!empty($arrayfields['total_pa']['checked'])) {
  1390. print '<td class="liste_titre right">';
  1391. print '</td>';
  1392. }
  1393. if (!empty($arrayfields['total_margin']['checked'])) {
  1394. print '<td class="liste_titre right">';
  1395. print '</td>';
  1396. }
  1397. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  1398. print '<td class="liste_titre right">';
  1399. print '</td>';
  1400. }
  1401. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  1402. print '<td class="liste_titre right">';
  1403. print '</td>';
  1404. }
  1405. // Extra fields
  1406. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1407. // Fields from hook
  1408. $parameters = array('arrayfields'=>$arrayfields);
  1409. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  1410. print $hookmanager->resPrint;
  1411. // Date creation
  1412. if (!empty($arrayfields['f.datec']['checked'])) {
  1413. print '<td class="liste_titre">';
  1414. print '</td>';
  1415. }
  1416. // Date modification
  1417. if (!empty($arrayfields['f.tms']['checked'])) {
  1418. print '<td class="liste_titre">';
  1419. print '</td>';
  1420. }
  1421. // Date closing
  1422. if (!empty($arrayfields['f.date_closing']['checked'])) {
  1423. print '<td class="liste_titre">';
  1424. print '</td>';
  1425. }
  1426. if (!empty($arrayfields['f.note_public']['checked'])) {
  1427. // Note public
  1428. print '<td class="liste_titre">';
  1429. print '</td>';
  1430. }
  1431. if (!empty($arrayfields['f.note_private']['checked'])) {
  1432. // Note private
  1433. print '<td class="liste_titre">';
  1434. print '</td>';
  1435. }
  1436. if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
  1437. // Template Invoice
  1438. print '<td class="liste_titre maxwidthonsmartphone right">';
  1439. print '<input class="flat maxwidth50imp" type="text" name="search_fac_rec_source_title" id="search_fac_rec_source_title" value="'.dol_escape_htmltag($search_fac_rec_source_title).'">';
  1440. print '</td>';
  1441. }
  1442. // Status
  1443. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  1444. print '<td class="liste_titre maxwidthonsmartphone right">';
  1445. $liststatus = array('0'=>$langs->trans("BillShortStatusDraft"), '1'=>$langs->trans("BillShortStatusNotPaid"), '0,1'=>$langs->trans("BillShortStatusDraft").'+'.$langs->trans("BillShortStatusNotPaid"), '2'=>$langs->trans("BillShortStatusPaid"), '1,2'=>$langs->trans("BillShortStatusNotPaid").'+'.$langs->trans("BillShortStatusPaid"), '3'=>$langs->trans("BillShortStatusCanceled"));
  1446. print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', '', 1);
  1447. print '</td>';
  1448. }
  1449. // Action column
  1450. print '<td class="liste_titre" align="middle">';
  1451. $searchpicto = $form->showFilterButtons();
  1452. print $searchpicto;
  1453. print '</td>';
  1454. print "</tr>\n";
  1455. print '<tr class="liste_titre">';
  1456. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  1457. print_liste_field_titre('#', $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  1458. }
  1459. if (!empty($arrayfields['f.ref']['checked'])) {
  1460. print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref', '', $param, '', $sortfield, $sortorder);
  1461. }
  1462. if (!empty($arrayfields['f.ref_client']['checked'])) {
  1463. print_liste_field_titre($arrayfields['f.ref_client']['label'], $_SERVER["PHP_SELF"], 'f.ref_client', '', $param, '', $sortfield, $sortorder);
  1464. }
  1465. if (!empty($arrayfields['f.type']['checked'])) {
  1466. print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
  1467. }
  1468. if (!empty($arrayfields['f.datef']['checked'])) {
  1469. print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef', '', $param, 'align="center"', $sortfield, $sortorder);
  1470. }
  1471. if (!empty($arrayfields['f.date_valid']['checked'])) {
  1472. print_liste_field_titre($arrayfields['f.date_valid']['label'], $_SERVER['PHP_SELF'], 'f.date_valid', '', $param, 'align="center"', $sortfield, $sortorder);
  1473. }
  1474. if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
  1475. print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, 'align="center"', $sortfield, $sortorder);
  1476. }
  1477. if (!empty($arrayfields['p.ref']['checked'])) {
  1478. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
  1479. }
  1480. if (!empty($arrayfields['p.title']['checked'])) {
  1481. print_liste_field_titre($arrayfields['p.title']['label'], $_SERVER['PHP_SELF'], "p.title", '', $param, '', $sortfield, $sortorder);
  1482. }
  1483. if (!empty($arrayfields['s.nom']['checked'])) {
  1484. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
  1485. }
  1486. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1487. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
  1488. }
  1489. if (!empty($arrayfields['s.town']['checked'])) {
  1490. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  1491. }
  1492. if (!empty($arrayfields['s.zip']['checked'])) {
  1493. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  1494. }
  1495. if (!empty($arrayfields['state.nom']['checked'])) {
  1496. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  1497. }
  1498. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1499. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'align="center"', $sortfield, $sortorder);
  1500. }
  1501. if (!empty($arrayfields['typent.code']['checked'])) {
  1502. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'align="center"', $sortfield, $sortorder);
  1503. }
  1504. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  1505. print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
  1506. }
  1507. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  1508. print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
  1509. }
  1510. if (!empty($arrayfields['f.module_source']['checked'])) {
  1511. print_liste_field_titre($arrayfields['f.module_source']['label'], $_SERVER["PHP_SELF"], "f.module_source", "", $param, "", $sortfield, $sortorder);
  1512. }
  1513. if (!empty($arrayfields['f.pos_source']['checked'])) {
  1514. print_liste_field_titre($arrayfields['f.pos_source']['label'], $_SERVER["PHP_SELF"], "f.pos_source", "", $param, "", $sortfield, $sortorder);
  1515. }
  1516. if (!empty($arrayfields['f.total_ht']['checked'])) {
  1517. print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
  1518. }
  1519. if (!empty($arrayfields['f.total_tva']['checked'])) {
  1520. print_liste_field_titre($arrayfields['f.total_tva']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
  1521. }
  1522. if (!empty($arrayfields['f.total_localtax1']['checked'])) {
  1523. print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, 'class="right"', $sortfield, $sortorder);
  1524. }
  1525. if (!empty($arrayfields['f.total_localtax2']['checked'])) {
  1526. print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, 'class="right"', $sortfield, $sortorder);
  1527. }
  1528. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  1529. print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
  1530. }
  1531. if (!empty($arrayfields['u.login']['checked'])) {
  1532. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
  1533. }
  1534. if (!empty($arrayfields['sale_representative']['checked'])) {
  1535. print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
  1536. }
  1537. if (!empty($arrayfields['f.retained_warranty']['checked'])) {
  1538. print_liste_field_titre($arrayfields['f.retained_warranty']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'align="right"', $sortfield, $sortorder);
  1539. }
  1540. if (!empty($arrayfields['dynamount_payed']['checked'])) {
  1541. print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1542. }
  1543. if (!empty($arrayfields['rtp']['checked'])) {
  1544. print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1545. }
  1546. if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
  1547. print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
  1548. }
  1549. if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
  1550. print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
  1551. }
  1552. if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
  1553. print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
  1554. }
  1555. if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
  1556. print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
  1557. }
  1558. if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
  1559. print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
  1560. }
  1561. if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
  1562. print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1563. }
  1564. if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
  1565. print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1566. }
  1567. if (!empty($arrayfields['total_pa']['checked'])) {
  1568. print_liste_field_titre($arrayfields['total_pa']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1569. }
  1570. if (!empty($arrayfields['total_margin']['checked'])) {
  1571. print_liste_field_titre($arrayfields['total_margin']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1572. }
  1573. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  1574. print_liste_field_titre($arrayfields['total_margin_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1575. }
  1576. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  1577. print_liste_field_titre($arrayfields['total_mark_rate']['label'], $_SERVER['PHP_SELF'], '', '', $param, 'class="right"', $sortfield, $sortorder);
  1578. }
  1579. // Extra fields
  1580. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1581. // Hook fields
  1582. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  1583. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  1584. print $hookmanager->resPrint;
  1585. if (!empty($arrayfields['f.datec']['checked'])) {
  1586. print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  1587. }
  1588. if (!empty($arrayfields['f.tms']['checked'])) {
  1589. print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  1590. }
  1591. if (!empty($arrayfields['f.date_closing']['checked'])) {
  1592. print_liste_field_titre($arrayfields['f.date_closing']['label'], $_SERVER["PHP_SELF"], "f.date_closing", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  1593. }
  1594. if (!empty($arrayfields['f.note_public']['checked'])) {
  1595. print_liste_field_titre($arrayfields['f.note_public']['label'], $_SERVER["PHP_SELF"], "f.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1596. }
  1597. if (!empty($arrayfields['f.note_private']['checked'])) {
  1598. print_liste_field_titre($arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1599. }
  1600. if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
  1601. print_liste_field_titre($arrayfields['f.fk_fac_rec_source']['label'], $_SERVER["PHP_SELF"], "facrec.titre", "", $param, '', $sortfield, $sortorder);
  1602. }
  1603. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  1604. print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "f.fk_statut,f.paye,f.type", "", $param, 'class="right"', $sortfield, $sortorder);
  1605. }
  1606. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  1607. print "</tr>\n";
  1608. $projectstatic = new Project($db);
  1609. $discount = new DiscountAbsolute($db);
  1610. $userstatic = new User($db);
  1611. if ($num > 0) {
  1612. $i = 0;
  1613. $totalarray = array();
  1614. $totalarray['nbfield'] = 0;
  1615. $totalarray['val'] = array();
  1616. $totalarray['val']['f.total_ht'] = 0;
  1617. $totalarray['val']['f.total_ttc'] = 0;
  1618. $with_margin_info = false;
  1619. if (!empty($conf->margin->enabled) && (
  1620. !empty($arrayfields['total_pa']['checked'])
  1621. || !empty($arrayfields['total_margin']['checked'])
  1622. || !empty($arrayfields['total_margin_rate']['checked'])
  1623. || !empty($arrayfields['total_mark_rate']['checked'])
  1624. )
  1625. ) {
  1626. $with_margin_info = true;
  1627. }
  1628. $total_ht = 0;
  1629. $total_margin = 0;
  1630. $last_num = min($num, $limit);
  1631. while ($i < $last_num) {
  1632. $obj = $db->fetch_object($resql);
  1633. $datelimit = $db->jdate($obj->datelimite);
  1634. $facturestatic->id = $obj->id;
  1635. $facturestatic->ref = $obj->ref;
  1636. $facturestatic->ref_client = $obj->ref_client;
  1637. $facturestatic->type = $obj->type;
  1638. $facturestatic->total_ht = $obj->total_ht;
  1639. $facturestatic->total_tva = $obj->total_tva;
  1640. $facturestatic->total_ttc = $obj->total_ttc;
  1641. $facturestatic->multicurrency_code = $obj->multicurrency_code;
  1642. $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
  1643. $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
  1644. $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
  1645. $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
  1646. $facturestatic->statut = $obj->fk_statut;
  1647. $facturestatic->close_code = $obj->close_code;
  1648. $facturestatic->total_ttc = $obj->total_ttc;
  1649. $facturestatic->paye = $obj->paye;
  1650. $facturestatic->fk_soc = $obj->fk_soc;
  1651. $facturestatic->date = $db->jdate($obj->datef);
  1652. $facturestatic->date_valid = $db->jdate($obj->date_valid);
  1653. $facturestatic->date_lim_reglement = $db->jdate($obj->datelimite);
  1654. $facturestatic->note_public = $obj->note_public;
  1655. $facturestatic->note_private = $obj->note_private;
  1656. if (!empty($conf->global->INVOICE_USE_SITUATION) && !empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
  1657. $facturestatic->retained_warranty = $obj->retained_warranty;
  1658. $facturestatic->retained_warranty_date_limit = $obj->retained_warranty_date_limit;
  1659. $facturestatic->situation_final = $obj->retained_warranty_date_limit;
  1660. $facturestatic->situation_final = $obj->retained_warranty_date_limit;
  1661. $facturestatic->situation_cycle_ref = $obj->situation_cycle_ref;
  1662. $facturestatic->situation_counter = $obj->situation_counter;
  1663. }
  1664. $companystatic->id = $obj->socid;
  1665. $companystatic->name = $obj->name;
  1666. $companystatic->name_alias = $obj->alias;
  1667. $companystatic->client = $obj->client;
  1668. $companystatic->fournisseur = $obj->fournisseur;
  1669. $companystatic->code_client = $obj->code_client;
  1670. $companystatic->code_compta_client = $obj->code_compta_client;
  1671. $companystatic->code_fournisseur = $obj->code_fournisseur;
  1672. $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
  1673. $companystatic->email = $obj->email;
  1674. $companystatic->phone = $obj->phone;
  1675. $companystatic->fax = $obj->fax;
  1676. $companystatic->address = $obj->address;
  1677. $companystatic->zip = $obj->zip;
  1678. $companystatic->town = $obj->town;
  1679. $companystatic->country_code = $obj->country_code;
  1680. $projectstatic->id = $obj->project_id;
  1681. $projectstatic->ref = $obj->project_ref;
  1682. $projectstatic->title = $obj->project_label;
  1683. $paiement = $facturestatic->getSommePaiement();
  1684. $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
  1685. $totaldeposits = $facturestatic->getSumDepositsUsed();
  1686. $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
  1687. $remaintopay = price2num($facturestatic->total_ttc - $totalpay);
  1688. $multicurrency_paiement = $facturestatic->getSommePaiement(1);
  1689. $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
  1690. $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
  1691. $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
  1692. $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
  1693. if ($facturestatic->statut == Facture::STATUS_CLOSED && $facturestatic->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment
  1694. $remaintopay = 0;
  1695. $multicurrency_remaintopay = 0;
  1696. }
  1697. if ($facturestatic->type == Facture::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consummed
  1698. $remaincreditnote = $discount->getAvailableDiscounts($companystatic, '', 'rc.fk_facture_source='.$facturestatic->id);
  1699. $remaintopay = -$remaincreditnote;
  1700. $totalpay = price2num($facturestatic->total_ttc - $remaintopay);
  1701. $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($companystatic, '', 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
  1702. $multicurrency_remaintopay = -$multicurrency_remaincreditnote;
  1703. $multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
  1704. }
  1705. $facturestatic->alreadypaid = $paiement;
  1706. $marginInfo = array();
  1707. if ($with_margin_info === true) {
  1708. $facturestatic->fetch_lines();
  1709. $marginInfo = $formmargin->getMarginInfosArray($facturestatic);
  1710. $total_ht += $obj->total_ht;
  1711. $total_margin += $marginInfo['total_margin'];
  1712. }
  1713. print '<tr class="oddeven"';
  1714. if ($contextpage == 'poslist') {
  1715. print ' onclick="parent.$(\'#poslines\').load(\'invoice.php?action=history&placeid='.$obj->id.'\', function() {parent.$.colorbox.close();';
  1716. if (strpos($obj->ref, 'PROV') !== false) {
  1717. //If is a draft invoice, load var to be able to add products
  1718. $place = str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $obj->ref));
  1719. print 'parent.place=\''.$place.'\'';
  1720. }
  1721. print '});"';
  1722. }
  1723. print '>';
  1724. // No
  1725. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER_IN_LIST)) {
  1726. print '<td>'.(($offset * $limit) + $i).'</td>';
  1727. }
  1728. // Ref
  1729. if (!empty($arrayfields['f.ref']['checked'])) {
  1730. print '<td class="nowraponall">';
  1731. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  1732. print '<td class="nobordernopadding nowraponall">';
  1733. if ($contextpage == 'poslist') {
  1734. print dol_escape_htmltag($obj->ref);
  1735. } else {
  1736. print $facturestatic->getNomUrl(1, '', 200, 0, '', 0, 1);
  1737. }
  1738. $filename = dol_sanitizeFileName($obj->ref);
  1739. $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  1740. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->id;
  1741. print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir);
  1742. print '</td>';
  1743. print '</tr>';
  1744. print '</table>';
  1745. print "</td>\n";
  1746. if (!$i) {
  1747. $totalarray['nbfield']++;
  1748. }
  1749. }
  1750. // Customer ref
  1751. if (!empty($arrayfields['f.ref_client']['checked'])) {
  1752. print '<td class="nowrap tdoverflowmax200">';
  1753. print dol_escape_htmltag($obj->ref_client);
  1754. print '</td>';
  1755. if (!$i) {
  1756. $totalarray['nbfield']++;
  1757. }
  1758. }
  1759. // Type
  1760. if (!empty($arrayfields['f.type']['checked'])) {
  1761. print '<td class="nowraponall tdoverflowmax100" title="'.$facturestatic->getLibType().'">';
  1762. print $facturestatic->getLibType();
  1763. print "</td>";
  1764. if (!$i) {
  1765. $totalarray['nbfield']++;
  1766. }
  1767. }
  1768. // Date
  1769. if (!empty($arrayfields['f.datef']['checked'])) {
  1770. print '<td align="center" class="nowraponall">';
  1771. print dol_print_date($db->jdate($obj->datef), 'day');
  1772. print '</td>';
  1773. if (!$i) {
  1774. $totalarray['nbfield']++;
  1775. }
  1776. }
  1777. // Date
  1778. if (!empty($arrayfields['f.date_valid']['checked'])) {
  1779. print '<td align="center" class="nowraponall">';
  1780. print dol_print_date($db->jdate($obj->date_valid), 'day');
  1781. print '</td>';
  1782. if (!$i) {
  1783. $totalarray['nbfield']++;
  1784. }
  1785. }
  1786. // Date limit
  1787. if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
  1788. print '<td align="center" class="nowraponall">'.dol_print_date($datelimit, 'day');
  1789. if ($facturestatic->hasDelay()) {
  1790. print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
  1791. }
  1792. print '</td>';
  1793. if (!$i) {
  1794. $totalarray['nbfield']++;
  1795. }
  1796. }
  1797. // Project ref
  1798. if (!empty($arrayfields['p.ref']['checked'])) {
  1799. print '<td class="nocellnopadd nowraponall">';
  1800. if ($obj->project_id > 0) {
  1801. print $projectstatic->getNomUrl(1);
  1802. }
  1803. print '</td>';
  1804. if (!$i) {
  1805. $totalarray['nbfield']++;
  1806. }
  1807. }
  1808. // Project title
  1809. if (!empty($arrayfields['p.title']['checked'])) {
  1810. print '<td class="nowraponall">';
  1811. if ($obj->project_id > 0) {
  1812. print dol_escape_htmltag($projectstatic->title);
  1813. }
  1814. print '</td>';
  1815. if (!$i) {
  1816. $totalarray['nbfield']++;
  1817. }
  1818. }
  1819. // Third party
  1820. if (!empty($arrayfields['s.nom']['checked'])) {
  1821. print '<td class="tdoverflowmax200">';
  1822. if ($contextpage == 'poslist') {
  1823. print dol_escape_htmltag($companystatic->name);
  1824. } else {
  1825. print $companystatic->getNomUrl(1, 'customer', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
  1826. }
  1827. print '</td>';
  1828. if (!$i) {
  1829. $totalarray['nbfield']++;
  1830. }
  1831. }
  1832. // Alias
  1833. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1834. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->name_alias).'">';
  1835. print dol_escape_htmltag($companystatic->name_alias);
  1836. print '</td>';
  1837. if (!$i) {
  1838. $totalarray['nbfield']++;
  1839. }
  1840. }
  1841. // Town
  1842. if (!empty($arrayfields['s.town']['checked'])) {
  1843. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
  1844. print dol_escape_htmltag($obj->town);
  1845. print '</td>';
  1846. if (!$i) {
  1847. $totalarray['nbfield']++;
  1848. }
  1849. }
  1850. // Zip
  1851. if (!empty($arrayfields['s.zip']['checked'])) {
  1852. print '<td class="nowraponall">';
  1853. print dol_escape_htmltag($obj->zip);
  1854. print '</td>';
  1855. if (!$i) {
  1856. $totalarray['nbfield']++;
  1857. }
  1858. }
  1859. // State
  1860. if (!empty($arrayfields['state.nom']['checked'])) {
  1861. print "<td>".dol_escape_htmltag($obj->state_name)."</td>\n";
  1862. if (!$i) {
  1863. $totalarray['nbfield']++;
  1864. }
  1865. }
  1866. // Country
  1867. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1868. print '<td class="center">';
  1869. $tmparray = getCountry($obj->fk_pays, 'all');
  1870. print $tmparray['label'];
  1871. print '</td>';
  1872. if (!$i) {
  1873. $totalarray['nbfield']++;
  1874. }
  1875. }
  1876. // Type ent
  1877. if (!empty($arrayfields['typent.code']['checked'])) {
  1878. print '<td class="center">';
  1879. if (!is_array($typenArray) || count($typenArray) == 0) {
  1880. $typenArray = $formcompany->typent_array(1);
  1881. }
  1882. print $typenArray[$obj->typent_code];
  1883. print '</td>';
  1884. if (!$i) {
  1885. $totalarray['nbfield']++;
  1886. }
  1887. }
  1888. // Staff
  1889. if (!empty($arrayfields['staff.code']['checked'])) {
  1890. print '<td class="center">';
  1891. if (!is_array($conf->cache['staff']) || count($conf->cache['staff']) == 0) {
  1892. $conf->cache['staff'] = $formcompany->effectif_array(1);
  1893. }
  1894. print $conf->cache['staff'][$obj->staff_code];
  1895. print '</td>';
  1896. if (!$i) {
  1897. $totalarray['nbfield']++;
  1898. }
  1899. }
  1900. // Payment mode
  1901. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  1902. print '<td class="tdoverflowmax100">';
  1903. $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
  1904. print '</td>';
  1905. if (!$i) {
  1906. $totalarray['nbfield']++;
  1907. }
  1908. }
  1909. // Payment terms
  1910. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  1911. print '<td>';
  1912. $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none');
  1913. print '</td>';
  1914. if (!$i) {
  1915. $totalarray['nbfield']++;
  1916. }
  1917. }
  1918. // Module Source
  1919. if (!empty($arrayfields['f.module_source']['checked'])) {
  1920. print '<td>';
  1921. print dol_escape_htmltag($obj->module_source);
  1922. print '</td>';
  1923. if (!$i) {
  1924. $totalarray['nbfield']++;
  1925. }
  1926. }
  1927. // POS Terminal
  1928. if (!empty($arrayfields['f.pos_source']['checked'])) {
  1929. print '<td>';
  1930. print dol_escape_htmltag($obj->pos_source);
  1931. print '</td>';
  1932. if (!$i) {
  1933. $totalarray['nbfield']++;
  1934. }
  1935. }
  1936. // Amount HT
  1937. if (!empty($arrayfields['f.total_ht']['checked'])) {
  1938. print '<td class="right nowraponall">'.price($obj->total_ht)."</td>\n";
  1939. if (!$i) {
  1940. $totalarray['nbfield']++;
  1941. }
  1942. if (!$i) {
  1943. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
  1944. }
  1945. $totalarray['val']['f.total_ht'] += $obj->total_ht;
  1946. }
  1947. // Amount VAT
  1948. if (!empty($arrayfields['f.total_tva']['checked'])) {
  1949. print '<td class="right nowraponall amount">'.price($obj->total_tva)."</td>\n";
  1950. if (!$i) {
  1951. $totalarray['nbfield']++;
  1952. }
  1953. if (!$i) {
  1954. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_tva';
  1955. }
  1956. $totalarray['val']['f.total_tva'] += $obj->total_tva;
  1957. }
  1958. // Amount LocalTax1
  1959. if (!empty($arrayfields['f.total_localtax1']['checked'])) {
  1960. print '<td class="right nowraponall amount">'.price($obj->total_localtax1)."</td>\n";
  1961. if (!$i) {
  1962. $totalarray['nbfield']++;
  1963. }
  1964. if (!$i) {
  1965. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
  1966. }
  1967. $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
  1968. }
  1969. // Amount LocalTax2
  1970. if (!empty($arrayfields['f.total_localtax2']['checked'])) {
  1971. print '<td class="right nowraponall amount">'.price($obj->total_localtax2)."</td>\n";
  1972. if (!$i) {
  1973. $totalarray['nbfield']++;
  1974. }
  1975. if (!$i) {
  1976. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
  1977. }
  1978. $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
  1979. }
  1980. // Amount TTC
  1981. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  1982. print '<td class="right nowraponall amount">'.price($obj->total_ttc)."</td>\n";
  1983. if (!$i) {
  1984. $totalarray['nbfield']++;
  1985. }
  1986. if (!$i) {
  1987. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
  1988. }
  1989. $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
  1990. }
  1991. $userstatic->id = $obj->fk_user_author;
  1992. $userstatic->login = $obj->login;
  1993. $userstatic->lastname = $obj->lastname;
  1994. $userstatic->firstname = $obj->firstname;
  1995. $userstatic->email = $obj->user_email;
  1996. $userstatic->statut = $obj->user_statut;
  1997. $userstatic->entity = $obj->entity;
  1998. $userstatic->photo = $obj->photo;
  1999. $userstatic->office_phone = $obj->office_phone;
  2000. $userstatic->office_fax = $obj->office_fax;
  2001. $userstatic->user_mobile = $obj->user_mobile;
  2002. $userstatic->job = $obj->job;
  2003. $userstatic->gender = $obj->gender;
  2004. // Author
  2005. if (!empty($arrayfields['u.login']['checked'])) {
  2006. print '<td class="tdoverflowmax200">';
  2007. if ($userstatic->id) {
  2008. print $userstatic->getNomUrl(-1);
  2009. } else {
  2010. print '&nbsp;';
  2011. }
  2012. print "</td>\n";
  2013. if (!$i) {
  2014. $totalarray['nbfield']++;
  2015. }
  2016. }
  2017. if (!empty($arrayfields['sale_representative']['checked'])) {
  2018. // Sales representatives
  2019. print '<td>';
  2020. if ($obj->socid > 0) {
  2021. $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
  2022. if ($listsalesrepresentatives < 0) {
  2023. dol_print_error($db);
  2024. }
  2025. $nbofsalesrepresentative = count($listsalesrepresentatives);
  2026. if ($nbofsalesrepresentative > 6) {
  2027. // We print only number
  2028. print $nbofsalesrepresentative;
  2029. } elseif ($nbofsalesrepresentative > 0) {
  2030. $j = 0;
  2031. foreach ($listsalesrepresentatives as $val) {
  2032. $userstatic->id = $val['id'];
  2033. $userstatic->lastname = $val['lastname'];
  2034. $userstatic->firstname = $val['firstname'];
  2035. $userstatic->email = $val['email'];
  2036. $userstatic->statut = $val['statut'];
  2037. $userstatic->entity = $val['entity'];
  2038. $userstatic->photo = $val['photo'];
  2039. $userstatic->login = $val['login'];
  2040. $userstatic->office_phone = $val['office_phone'];
  2041. $userstatic->office_fax = $val['office_fax'];
  2042. $userstatic->user_mobile = $val['user_mobile'];
  2043. $userstatic->job = $val['job'];
  2044. $userstatic->gender = $val['gender'];
  2045. //print '<div class="float">':
  2046. print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
  2047. $j++;
  2048. if ($j < $nbofsalesrepresentative) {
  2049. print ' ';
  2050. }
  2051. //print '</div>';
  2052. }
  2053. }
  2054. //else print $langs->trans("NoSalesRepresentativeAffected");
  2055. } else {
  2056. print '&nbsp;';
  2057. }
  2058. print '</td>';
  2059. if (!$i) {
  2060. $totalarray['nbfield']++;
  2061. }
  2062. }
  2063. if (!empty($arrayfields['f.retained_warranty']['checked'])) {
  2064. print '<td align="right">'.(!empty($obj->retained_warranty) ? price($obj->retained_warranty).'%' : '&nbsp;').'</td>';
  2065. }
  2066. if (!empty($arrayfields['dynamount_payed']['checked'])) {
  2067. print '<td class="right nowraponall amount">'.(!empty($totalpay) ? price($totalpay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
  2068. if (!$i) {
  2069. $totalarray['nbfield']++;
  2070. }
  2071. if (!$i) {
  2072. $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
  2073. }
  2074. $totalarray['val']['totalam'] += $totalpay;
  2075. }
  2076. // Pending amount
  2077. if (!empty($arrayfields['rtp']['checked'])) {
  2078. print '<td class="right nowraponall amount">';
  2079. print (!empty($remaintopay) ? price($remaintopay, 0, $langs) : '&nbsp;');
  2080. print '</td>'; // TODO Use a denormalized field
  2081. if (!$i) {
  2082. $totalarray['nbfield']++;
  2083. }
  2084. if (!$i) {
  2085. $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
  2086. }
  2087. $totalarray['val']['rtp'] += $remaintopay;
  2088. }
  2089. // Currency
  2090. if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
  2091. print '<td class="nowraponall tdoverflowmax125" title="'.dol_escape_htmltag($obj->multicurrency_code.' - '.$langs->transnoentitiesnoconv('Currency'.$obj->multicurrency_code)).'">';
  2092. if (empty($conf->global->MAIN_SHOW_ONLY_CODE_MULTICURRENCY)) {
  2093. print $langs->transnoentitiesnoconv('Currency'.$obj->multicurrency_code);
  2094. } else {
  2095. print dol_escape_htmltag($obj->multicurrency_code);
  2096. }
  2097. print "</td>\n";
  2098. if (!$i) {
  2099. $totalarray['nbfield']++;
  2100. }
  2101. }
  2102. // Currency rate
  2103. if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
  2104. print '<td class="nowraponall">';
  2105. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
  2106. print "</td>\n";
  2107. if (!$i) {
  2108. $totalarray['nbfield']++;
  2109. }
  2110. }
  2111. // Amount HT
  2112. if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
  2113. print '<td class="right nowraponall amount">'.price($obj->multicurrency_total_ht)."</td>\n";
  2114. if (!$i) {
  2115. $totalarray['nbfield']++;
  2116. }
  2117. }
  2118. // Amount VAT
  2119. if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
  2120. print '<td class="right nowraponall amount">'.price($obj->multicurrency_total_vat)."</td>\n";
  2121. if (!$i) {
  2122. $totalarray['nbfield']++;
  2123. }
  2124. }
  2125. // Amount TTC
  2126. if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
  2127. print '<td class="right nowraponall amount">'.price($obj->multicurrency_total_ttc)."</td>\n";
  2128. if (!$i) {
  2129. $totalarray['nbfield']++;
  2130. }
  2131. }
  2132. if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
  2133. print '<td class="right nowraponall amount">'.(!empty($multicurrency_totalpay) ?price($multicurrency_totalpay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
  2134. if (!$i) {
  2135. $totalarray['nbfield']++;
  2136. }
  2137. }
  2138. // Pending amount
  2139. if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
  2140. print '<td class="right nowraponall">';
  2141. print (!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '&nbsp;');
  2142. print '</td>'; // TODO Use a denormalized field
  2143. if (!$i) {
  2144. $totalarray['nbfield']++;
  2145. }
  2146. }
  2147. // Total buying or cost price
  2148. if (!empty($arrayfields['total_pa']['checked'])) {
  2149. print '<td class="right nowrap">'.price($marginInfo['pa_total']).'</td>';
  2150. if (!$i) {
  2151. $totalarray['nbfield']++;
  2152. }
  2153. }
  2154. // Total margin
  2155. if (!empty($arrayfields['total_margin']['checked'])) {
  2156. print '<td class="right nowrap">'.price($marginInfo['total_margin']).'</td>';
  2157. if (!$i) {
  2158. $totalarray['nbfield']++;
  2159. }
  2160. if (!$i) {
  2161. $totalarray['pos'][$totalarray['nbfield']] = 'total_margin';
  2162. }
  2163. $totalarray['val']['total_margin'] += $marginInfo['total_margin'];
  2164. }
  2165. // Total margin rate
  2166. if (!empty($arrayfields['total_margin_rate']['checked'])) {
  2167. print '<td class="right nowrap">'.(($marginInfo['total_margin_rate'] == '') ? '' : price($marginInfo['total_margin_rate'], null, null, null, null, 2).'%').'</td>';
  2168. if (!$i) {
  2169. $totalarray['nbfield']++;
  2170. }
  2171. }
  2172. // Total mark rate
  2173. if (!empty($arrayfields['total_mark_rate']['checked'])) {
  2174. print '<td class="right nowrap">'.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').'</td>';
  2175. if (!$i) {
  2176. $totalarray['nbfield']++;
  2177. }
  2178. if (!$i) {
  2179. $totalarray['pos'][$totalarray['nbfield']] = 'total_mark_rate';
  2180. }
  2181. if ($i >= $last_num - 1) {
  2182. if (!empty($total_ht)) {
  2183. $totalarray['val']['total_mark_rate'] = price2num($total_margin * 100 / $total_ht, 'MT');
  2184. } else {
  2185. $totalarray['val']['total_mark_rate'] = '';
  2186. }
  2187. }
  2188. }
  2189. // Extra fields
  2190. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  2191. // Fields from hook
  2192. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  2193. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  2194. print $hookmanager->resPrint;
  2195. // Date creation
  2196. if (!empty($arrayfields['f.datec']['checked'])) {
  2197. print '<td class="nowrap center">';
  2198. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  2199. print '</td>';
  2200. if (!$i) {
  2201. $totalarray['nbfield']++;
  2202. }
  2203. }
  2204. // Date modification
  2205. if (!empty($arrayfields['f.tms']['checked'])) {
  2206. print '<td class="nowrap center">';
  2207. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  2208. print '</td>';
  2209. if (!$i) {
  2210. $totalarray['nbfield']++;
  2211. }
  2212. }
  2213. // Date closing
  2214. if (!empty($arrayfields['f.date_closing']['checked'])) {
  2215. print '<td class="nowrap center">';
  2216. print dol_print_date($db->jdate($obj->date_closing), 'dayhour', 'tzuser');
  2217. print '</td>';
  2218. if (!$i) {
  2219. $totalarray['nbfield']++;
  2220. }
  2221. }
  2222. // Note public
  2223. if (!empty($arrayfields['f.note_public']['checked'])) {
  2224. print '<td class="center">';
  2225. print dol_escape_htmltag($obj->note_public);
  2226. print '</td>';
  2227. if (!$i) {
  2228. $totalarray['nbfield']++;
  2229. }
  2230. }
  2231. // Note private
  2232. if (!empty($arrayfields['f.note_private']['checked'])) {
  2233. print '<td class="center">';
  2234. print dol_escape_htmltag($obj->note_private);
  2235. print '</td>';
  2236. if (!$i) {
  2237. $totalarray['nbfield']++;
  2238. }
  2239. }
  2240. // Template Invoice
  2241. if (!empty($arrayfields['f.fk_fac_rec_source']['checked'])) {
  2242. print '<td class="center">';
  2243. if (!empty($obj->fk_fac_rec_source)) {
  2244. $facrec = new FactureRec($db);
  2245. $result = $facrec->fetch($obj->fk_fac_rec_source);
  2246. if ($result < 0) {
  2247. setEventMessages($facrec->error, $facrec->errors, 'errors');
  2248. } else {
  2249. print $facrec->getNomUrl();
  2250. }
  2251. }
  2252. print '</td>';
  2253. if (!$i) {
  2254. $totalarray['nbfield']++;
  2255. }
  2256. }
  2257. // Status
  2258. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  2259. print '<td class="nowrap right">';
  2260. print $facturestatic->LibStatut($obj->paye, $obj->fk_statut, 5, $paiement, $obj->type);
  2261. print "</td>";
  2262. if (!$i) {
  2263. $totalarray['nbfield']++;
  2264. }
  2265. }
  2266. // Action column (Show the massaction button only when this page is not opend from the Extended POS)
  2267. print '<td class="nowrap" align="center">';
  2268. if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  2269. $selected = 0;
  2270. if (in_array($obj->id, $arrayofselected)) {
  2271. $selected = 1;
  2272. }
  2273. print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
  2274. }
  2275. print '</td>';
  2276. if (!$i) {
  2277. $totalarray['nbfield']++;
  2278. }
  2279. print "</tr>\n";
  2280. $i++;
  2281. }
  2282. // Show total line
  2283. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  2284. }
  2285. $db->free($resql);
  2286. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  2287. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  2288. print $hookmanager->resPrint;
  2289. print "</table>\n";
  2290. print '</div>';
  2291. print "</form>\n";
  2292. // Show the file area only when this page is not opend from the Extended POS
  2293. if ($contextpage != 'poslist') {
  2294. $hidegeneratedfilelistifempty = 1;
  2295. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  2296. $hidegeneratedfilelistifempty = 0;
  2297. }
  2298. // Show list of available documents
  2299. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  2300. $urlsource .= str_replace('&amp;', '&', $param);
  2301. $filedir = $diroutputmassaction;
  2302. $genallowed = $user->rights->facture->lire;
  2303. $delallowed = $user->rights->facture->creer;
  2304. $title = '';
  2305. print $formfile->showdocuments('massfilesarea_invoices', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  2306. }
  2307. } else {
  2308. dol_print_error($db);
  2309. }
  2310. // End of page
  2311. llxFooter();
  2312. $db->close();