list.php 115 KB

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