list.php 99 KB

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