list.php 111 KB

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