list.php 106 KB

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