list.php 116 KB

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