list.php 110 KB

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