list.php 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061
  1. <?php
  2. /* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2013-2019 Philippe Grand <philippe.grand@atoo-net.com>
  6. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  7. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2015-2007 Juanjo Menent <jmenent@2byte.es>
  10. * Copyright (C) 2015 Abbes Bahfir <bafbes@gmail.com>
  11. * Copyright (C) 2015-2016 Ferran Marcet <fmarcet@2byte.es>
  12. * Copyright (C) 2017 Josep Lluís Amador <joseplluis@lliuretic.cat>
  13. * Copyright (C) 2018-2022 Charlene Benke <charlene@patas-monkey.com>
  14. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  15. * Copyright (C) 2019-2021 Alexandre Spangaro <aspangaro@open-dsi.fr>
  16. * Copyright (C) 2023 Nick Fragoulis
  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/fourn/facture/list.php
  33. * \ingroup fournisseur,facture
  34. * \brief List of suppliers 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. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  42. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  43. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  45. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  46. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  47. require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
  48. // Load translation files required by the page
  49. $langs->loadLangs(array('products', 'bills', 'companies', 'projects'));
  50. $action = GETPOST('action', 'aZ09');
  51. $massaction = GETPOST('massaction', 'alpha');
  52. $show_files = GETPOST('show_files', 'int');
  53. $confirm = GETPOST('confirm', 'alpha');
  54. $toselect = GETPOST('toselect', 'array');
  55. $optioncss = GETPOST('optioncss', 'alpha');
  56. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'supplierinvoicelist';
  57. $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
  58. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  59. $search_label = GETPOST("search_label", "alpha");
  60. $search_amount_no_tax = GETPOST("search_amount_no_tax", "alpha");
  61. $search_amount_all_tax = GETPOST("search_amount_all_tax", "alpha");
  62. $search_ref = GETPOST('sf_ref') ? GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
  63. $search_refsupplier = GETPOST('search_refsupplier', 'alpha');
  64. $search_type = GETPOST('search_type', 'int');
  65. $search_subtype = GETPOST('search_subtype', 'int');
  66. $search_project = GETPOST('search_project', 'alpha');
  67. $search_company = GETPOST('search_company', 'alpha');
  68. $search_company_alias = GETPOST('search_company_alias', 'alpha');
  69. $search_montant_ht = GETPOST('search_montant_ht', 'alpha');
  70. $search_montant_vat = GETPOST('search_montant_vat', 'alpha');
  71. $search_montant_localtax1 = GETPOST('search_montant_localtax1', 'alpha');
  72. $search_montant_localtax2 = GETPOST('search_montant_localtax2', 'alpha');
  73. $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
  74. $search_login = GETPOST('search_login', 'alpha');
  75. $search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
  76. $search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
  77. $search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
  78. $search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
  79. $search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
  80. $search_status = GETPOST('search_status', 'int');
  81. $search_paymentmode = GETPOST('search_paymentmode', 'int');
  82. $search_paymentcond = GETPOST('search_paymentcond', 'int');
  83. $search_town = GETPOST('search_town', 'alpha');
  84. $search_zip = GETPOST('search_zip', 'alpha');
  85. $search_state = GETPOST("search_state");
  86. $search_country = GETPOST("search_country", 'int');
  87. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  88. $search_user = GETPOST('search_user', 'int');
  89. $search_sale = GETPOST('search_sale', 'int');
  90. $search_date_start = GETPOSTDATE('search_date_start', '', 'tzserver');
  91. $search_date_end = GETPOSTDATE('search_date_end', '23:59:59', 'tzserver');
  92. $search_datelimit_startday = GETPOST('search_datelimit_startday', 'int');
  93. $search_datelimit_startmonth = GETPOST('search_datelimit_startmonth', 'int');
  94. $search_datelimit_startyear = GETPOST('search_datelimit_startyear', 'int');
  95. $search_datelimit_endday = GETPOST('search_datelimit_endday', 'int');
  96. $search_datelimit_endmonth = GETPOST('search_datelimit_endmonth', 'int');
  97. $search_datelimit_endyear = GETPOST('search_datelimit_endyear', 'int');
  98. $search_datelimit_start = dol_mktime(0, 0, 0, $search_datelimit_startmonth, $search_datelimit_startday, $search_datelimit_startyear);
  99. $search_datelimit_end = dol_mktime(23, 59, 59, $search_datelimit_endmonth, $search_datelimit_endday, $search_datelimit_endyear);
  100. $search_btn = GETPOST('button_search', 'alpha');
  101. $search_remove_btn = GETPOST('button_removefilter', 'alpha');
  102. $search_categ_sup = trim(GETPOST("search_categ_sup", 'int'));
  103. $search_product_category = GETPOST('search_product_category', 'int');
  104. $option = GETPOST('search_option');
  105. if ($option == 'late') {
  106. $search_status = '1';
  107. }
  108. $filter = GETPOST('filtre', 'alpha');
  109. // Load variable for pagination
  110. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  111. $sortfield = GETPOST('sortfield', 'aZ09comma');
  112. $sortorder = GETPOST('sortorder', 'aZ09comma');
  113. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  114. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  115. // If $page is not defined, or '' or -1 or if we click on clear filters
  116. $page = 0;
  117. }
  118. $offset = $limit * $page;
  119. if (!$sortorder) {
  120. $sortorder = "DESC";
  121. }
  122. if (!$sortfield) {
  123. $sortfield = "f.datef,f.rowid";
  124. }
  125. $pageprev = $page - 1;
  126. $pagenext = $page + 1;
  127. $socid = GETPOST('socid', 'int');
  128. // Security check
  129. if ($user->socid > 0) {
  130. $action = '';
  131. $_GET["action"] = '';
  132. $socid = $user->socid;
  133. }
  134. $diroutputmassaction = $conf->fournisseur->facture->dir_output.'/temp/massgeneration/'.$user->id;
  135. $now = dol_now();
  136. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  137. $object = new FactureFournisseur($db);
  138. $hookmanager->initHooks(array('supplierinvoicelist'));
  139. $extrafields = new ExtraFields($db);
  140. // Fetch optionals attributes and labels
  141. $extrafields->fetch_name_optionals_label($object->table_element);
  142. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  143. // List of fields to search into when doing a "search in all"
  144. $fieldstosearchall = array(
  145. 'f.ref'=>'Ref',
  146. 'f.ref_supplier'=>'RefSupplier',
  147. 'f.note_public'=>'NotePublic',
  148. 's.nom'=>"ThirdParty",
  149. 's.code_fournisseur'=>"SupplierCodeShort",
  150. 'pd.description'=>'Description',
  151. );
  152. if (empty($user->socid)) {
  153. $fieldstosearchall["f.note_private"] = "NotePrivate";
  154. }
  155. $checkedtypetiers = 0;
  156. $arrayfields = array(
  157. 'f.ref'=>array('label'=>"Ref", 'checked'=>1),
  158. 'f.ref_supplier'=>array('label'=>"RefSupplier", 'checked'=>1),
  159. 'f.type'=>array('label'=>"Type", 'checked'=>0),
  160. 'f.subtype'=>array('label'=>"InvoiceSubtype", 'checked'=>0,),
  161. 'f.label'=>array('label'=>"Label", 'checked'=>0),
  162. 'f.datef'=>array('label'=>"DateInvoice", 'checked'=>1),
  163. 'f.date_lim_reglement'=>array('label'=>"DateDue", 'checked'=>1),
  164. 'p.ref'=>array('label'=>"ProjectRef", 'checked'=>0),
  165. 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1, 'position'=>41),
  166. 's.name_alias'=>array('label'=>"AliasNameShort", 'checked'=>0, 'position'=>42),
  167. 's.town'=>array('label'=>"Town", 'checked'=>-1, 'position'=>43),
  168. 's.zip'=>array('label'=>"Zip", 'checked'=>1, 'position'=>44),
  169. 'state.nom'=>array('label'=>"StateShort", 'checked'=>0, 'position'=>45),
  170. 'country.code_iso'=>array('label'=>"Country", 'checked'=>0, 'position'=>46),
  171. 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers, 'position'=>49),
  172. 'f.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>1, 'position'=>52),
  173. 'f.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>1, 'position'=>50),
  174. 'f.total_ht'=>array('label'=>"AmountHT", 'checked'=>1, 'position'=>105),
  175. 'f.total_vat'=>array('label'=>"AmountVAT", 'checked'=>0, 'position'=>110),
  176. 'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax1_assuj == "1", 'position'=>95),
  177. 'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax2_assuj == "1", 'position'=>100),
  178. 'f.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0, 'position'=>115),
  179. 'dynamount_payed'=>array('label'=>"Paid", 'checked'=>0, 'position'=>116),
  180. 'rtp'=>array('label'=>"Rest", 'checked'=>0, 'position'=>117),
  181. 'f.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'position'=>205, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  182. 'f.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'position'=>206, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  183. 'f.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'position'=>207, 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  184. 'f.multicurrency_total_vat'=>array('label'=>'MulticurrencyAmountVAT', 'position'=>208, 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  185. 'f.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'position'=>209, 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  186. 'multicurrency_dynamount_payed'=>array('label'=>'MulticurrencyAlreadyPaid', 'position'=>210, 'checked'=>0, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)),
  187. 'multicurrency_rtp'=>array('label'=>'MulticurrencyRemainderToPay', 'checked'=>0, 'position'=>211, 'enabled'=>(!isModEnabled("multicurrency") ? 0 : 1)), // Not enabled by default because slow
  188. 'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>500),
  189. 'f.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>501),
  190. 'f.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>502),
  191. 'f.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
  192. 'f.nb_docs'=>array('label'=>"Documents", 'checked'=>1, 'position'=>510),
  193. );
  194. // Extra fields
  195. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  196. $object->fields = dol_sort_array($object->fields, 'position');
  197. $arrayfields = dol_sort_array($arrayfields, 'position');
  198. if (!isModEnabled('supplier_invoice')) {
  199. accessforbidden();
  200. }
  201. if ((!$user->hasRight("fournisseur", "facture", "lire") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD'))
  202. || (!$user->hasRight("supplier_invoice", "lire") && getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD'))) {
  203. accessforbidden();
  204. }
  205. if (!$user->hasRight('societe', 'client', 'voir')) {
  206. $search_sale = $user->id;
  207. }
  208. $permissiontoread = ($user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire"));
  209. $permissiontoadd = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
  210. $permissiontodelete = ($user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "supprimer"));
  211. /*
  212. * Actions
  213. */
  214. if (GETPOST('cancel', 'alpha')) {
  215. $action = 'list';
  216. $massaction = '';
  217. }
  218. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  219. $massaction = '';
  220. }
  221. $parameters = array('socid'=>$socid, 'arrayfields'=>&$arrayfields);
  222. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  223. if ($reshook < 0) {
  224. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  225. }
  226. if (empty($reshook)) {
  227. // Selection of new fields
  228. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  229. // Purge search criteria
  230. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha')) { // All tests must be present to be compatible with all browsers
  231. $search_all = "";
  232. $search_user = '';
  233. $search_sale = '';
  234. $search_product_category = '';
  235. $search_ref = "";
  236. $search_refsupplier = "";
  237. $search_type = "";
  238. $search_subtype = '';
  239. $search_label = "";
  240. $search_project = '';
  241. $search_company = "";
  242. $search_company_alias = "";
  243. $search_amount_no_tax = "";
  244. $search_amount_all_tax = "";
  245. $search_montant_ht = '';
  246. $search_montant_vat = '';
  247. $search_montant_localtax1 = '';
  248. $search_montant_localtax2 = '';
  249. $search_montant_ttc = '';
  250. $search_login = '';
  251. $search_multicurrency_code = '';
  252. $search_multicurrency_tx = '';
  253. $search_multicurrency_montant_ht = '';
  254. $search_multicurrency_montant_vat = '';
  255. $search_multicurrency_montant_ttc = '';
  256. $search_status = '';
  257. $search_paymentmode = '';
  258. $search_paymentcond = '';
  259. $search_town = '';
  260. $search_zip = "";
  261. $search_state = "";
  262. $search_country = '';
  263. $search_type_thirdparty = '';
  264. $search_date_start = '';
  265. $search_date_end = '';
  266. $search_datelimit_startday = '';
  267. $search_datelimit_startmonth = '';
  268. $search_datelimit_startyear = '';
  269. $search_datelimit_endday = '';
  270. $search_datelimit_endmonth = '';
  271. $search_datelimit_endyear = '';
  272. $search_datelimit_start = '';
  273. $search_datelimit_end = '';
  274. $toselect = array();
  275. $search_array_options = array();
  276. $search_categ_sup = 0;
  277. $filter = '';
  278. $option = '';
  279. $socid = "";
  280. }
  281. // Mass actions
  282. $objectclass = 'FactureFournisseur';
  283. $objectlabel = 'SupplierInvoices';
  284. $uploaddir = $conf->fournisseur->facture->dir_output;
  285. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  286. if ($massaction == 'banktransfertrequest') {
  287. $langs->load("withdrawals");
  288. if (!$user->hasRight("paymentbybanktransfer", "create")) {
  289. $error++;
  290. setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
  291. } else {
  292. //Checking error
  293. $error = 0;
  294. $arrayofselected = is_array($toselect) ? $toselect : array();
  295. $listofbills = array();
  296. foreach ($arrayofselected as $toselectid) {
  297. $objecttmp = new FactureFournisseur($db);
  298. $result = $objecttmp->fetch($toselectid);
  299. if ($result > 0) {
  300. $totalpaid = $objecttmp->getSommePaiement();
  301. $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
  302. $totaldeposits = $objecttmp->getSumDepositsUsed();
  303. $objecttmp->resteapayer = price2num($objecttmp->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
  304. if ($objecttmp->statut == FactureFournisseur::STATUS_DRAFT) {
  305. $error++;
  306. setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors');
  307. } elseif ($objecttmp->paye || $objecttmp->resteapayer == 0) {
  308. $error++;
  309. setEventMessages($objecttmp->ref.' '.$langs->trans("AlreadyPaid"), $objecttmp->errors, 'errors');
  310. } elseif ($objecttmp->resteapayer < 0) {
  311. $error++;
  312. setEventMessages($objecttmp->ref.' '.$langs->trans("AmountMustBePositive"), $objecttmp->errors, 'errors');
  313. }
  314. $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande";
  315. $rsql .= " , pfd.date_traite as date_traite";
  316. $rsql .= " , pfd.amount";
  317. $rsql .= " , u.rowid as user_id, u.lastname, u.firstname, u.login";
  318. $rsql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pfd";
  319. $rsql .= " , ".MAIN_DB_PREFIX."user as u";
  320. $rsql .= " WHERE fk_facture_fourn = ".((int) $objecttmp->id);
  321. $rsql .= " AND pfd.fk_user_demande = u.rowid";
  322. $rsql .= " AND pfd.traite = 0";
  323. $rsql .= " ORDER BY pfd.date_demande DESC";
  324. $result_sql = $db->query($rsql);
  325. if ($result_sql) {
  326. $numprlv = $db->num_rows($result_sql);
  327. }
  328. if ($numprlv > 0) {
  329. $error++;
  330. setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'warnings');
  331. } elseif (!empty($objecttmp->mode_reglement_code) && $objecttmp->mode_reglement_code != 'VIR') {
  332. $error++;
  333. setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors');
  334. } else {
  335. $listofbills[] = $objecttmp; // $listofbills will only contains invoices with good payment method and no request already done
  336. }
  337. }
  338. }
  339. // Massive withdraw request for request with no errors
  340. if (!empty($listofbills)) {
  341. $nbwithdrawrequestok = 0;
  342. foreach ($listofbills as $aBill) {
  343. $db->begin();
  344. $result = $aBill->demande_prelevement($user, $aBill->resteapayer, 'bank-transfer', 'supplier_invoice');
  345. if ($result > 0) {
  346. $db->commit();
  347. $nbwithdrawrequestok++;
  348. } else {
  349. $db->rollback();
  350. setEventMessages($aBill->error, $aBill->errors, 'errors');
  351. }
  352. }
  353. if ($nbwithdrawrequestok > 0) {
  354. setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs');
  355. }
  356. }
  357. }
  358. }
  359. }
  360. /*
  361. * View
  362. */
  363. $form = new Form($db);
  364. $formother = new FormOther($db);
  365. $formfile = new FormFile($db);
  366. $bankaccountstatic = new Account($db);
  367. $facturestatic = new FactureFournisseur($db);
  368. $formcompany = new FormCompany($db);
  369. $thirdparty = new Societe($db);
  370. $subtypearray = $object->getArrayOfInvoiceSubtypes(0);
  371. $now = dol_now();
  372. if ($socid > 0) {
  373. $soc = new Societe($db);
  374. $soc->fetch($socid);
  375. if (empty($search_company)) {
  376. $search_company = $soc->name;
  377. }
  378. }
  379. $title = $langs->trans("BillsSuppliers").($socid ? ' - '.$soc->name : '');
  380. $help_url = 'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores';
  381. // Build and execute select
  382. // --------------------------------------------------------------------
  383. $sql = "SELECT";
  384. if ($search_all) {
  385. $sql = 'SELECT DISTINCT';
  386. }
  387. $sql .= " f.rowid as facid, f.ref, f.ref_supplier, f.type, f.subtype, f.datef, f.date_lim_reglement as datelimite, f.fk_mode_reglement, f.fk_cond_reglement,";
  388. $sql .= " f.total_ht, f.total_ttc, f.total_tva as total_vat, f.paye as paye, f.close_code, f.fk_statut as fk_statut, f.libelle as label, f.datec as date_creation, f.tms as date_update,";
  389. $sql .= " f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,";
  390. $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,';
  391. $sql .= " f.note_public, f.note_private,";
  392. $sql .= " f.fk_user_author,";
  393. $sql .= " s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, 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,";
  394. $sql .= " typent.code as typent_code,";
  395. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  396. $sql .= " country.code as country_code,";
  397. $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,";
  398. $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';
  399. // 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)
  400. // TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field.
  401. if (!$search_all) {
  402. $sql .= ', SUM(pf.amount) as dynamount_payed';
  403. }
  404. // Add fields from extrafields
  405. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  406. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  407. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  408. }
  409. }
  410. // Add fields from hooks
  411. $parameters = array();
  412. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  413. $sql .= $hookmanager->resPrint;
  414. $sql = preg_replace('/,\s*$/', '', $sql);
  415. $sqlfields = $sql; // $sql fields to remove for count total
  416. $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
  417. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  418. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  419. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  420. $sql .= ', '.MAIN_DB_PREFIX.'facture_fourn as f';
  421. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  422. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
  423. }
  424. if (!$search_all) {
  425. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
  426. }
  427. if ($search_all) {
  428. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det as pd ON f.rowid=pd.fk_facture_fourn';
  429. }
  430. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON f.fk_user_author = u.rowid';
  431. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = f.fk_projet";
  432. if ($search_user > 0) {
  433. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
  434. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
  435. }
  436. // Add table from hooks
  437. $parameters = array();
  438. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  439. $sql .= $hookmanager->resPrint;
  440. $sql .= ' WHERE f.fk_soc = s.rowid';
  441. $sql .= ' AND f.entity IN ('.getEntity('facture_fourn').')';
  442. if ($socid > 0) {
  443. $sql .= ' AND s.rowid = '.((int) $socid);
  444. }
  445. if ($search_ref) {
  446. if (is_numeric($search_ref)) {
  447. $sql .= natural_search(array('f.ref'), $search_ref);
  448. } else {
  449. $sql .= natural_search('f.ref', $search_ref);
  450. }
  451. }
  452. if ($search_ref) {
  453. $sql .= natural_search('f.ref', $search_ref);
  454. }
  455. if ($search_refsupplier) {
  456. $sql .= natural_search('f.ref_supplier', $search_refsupplier);
  457. }
  458. if ($search_type != '' && $search_type >= 0) {
  459. if ($search_type == '0') {
  460. $sql .= " AND f.type = 0"; // standard
  461. }
  462. if ($search_type == '1') {
  463. $sql .= " AND f.type = 1"; // replacement
  464. }
  465. if ($search_type == '2') {
  466. $sql .= " AND f.type = 2"; // credit note
  467. }
  468. if ($search_type == '3') {
  469. $sql .= " AND f.type = 3"; // deposit
  470. }
  471. //if ($search_type == '4') $sql.=" AND f.type = 4"; // proforma
  472. //if ($search_type == '5') $sql.=" AND f.type = 5"; // situation
  473. }
  474. if ($search_subtype != '' && $search_subtype != '-1') {
  475. $sql .= " AND f.subtype IN (".$db->sanitize($db->escape($search_subtype)).")";
  476. }
  477. if ($search_project) {
  478. $sql .= natural_search('p.ref', $search_project);
  479. }
  480. if (empty($arrayfields['s.name_alias']['checked']) && $search_company) {
  481. $sql .= natural_search(array("s.nom", "s.name_alias"), $search_company);
  482. } else {
  483. if ($search_company) {
  484. $sql .= natural_search('s.nom', $search_company);
  485. }
  486. if ($search_company_alias) {
  487. $sql .= natural_search('s.name_alias', $search_company_alias);
  488. }
  489. }
  490. if ($search_town) {
  491. $sql .= natural_search('s.town', $search_town);
  492. }
  493. if ($search_zip) {
  494. $sql .= natural_search("s.zip", $search_zip);
  495. }
  496. if ($search_state) {
  497. $sql .= natural_search("state.nom", $search_state);
  498. }
  499. if ($search_country) {
  500. $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
  501. }
  502. if ($search_type_thirdparty != '' && $search_type_thirdparty >= 0) {
  503. $sql .= " AND s.fk_typent IN (".$db->sanitize($search_type_thirdparty).')';
  504. }
  505. if ($search_montant_ht != '') {
  506. $sql .= natural_search('f.total_ht', $search_montant_ht, 1);
  507. }
  508. if ($search_montant_vat != '') {
  509. $sql .= natural_search('f.total_tva', $search_montant_vat, 1);
  510. }
  511. if ($search_montant_localtax1 != '') {
  512. $sql .= natural_search('f.localtax1', $search_montant_localtax1, 1);
  513. }
  514. if ($search_montant_localtax2 != '') {
  515. $sql .= natural_search('f.localtax2', $search_montant_localtax2, 1);
  516. }
  517. if ($search_montant_ttc != '') {
  518. $sql .= natural_search('f.total_ttc', $search_montant_ttc, 1);
  519. }
  520. if ($search_multicurrency_code != '') {
  521. $sql .= " AND f.multicurrency_code = '".$db->escape($search_multicurrency_code)."'";
  522. }
  523. if ($search_multicurrency_tx != '') {
  524. $sql .= natural_search('f.multicurrency_tx', $search_multicurrency_tx, 1);
  525. }
  526. if ($search_multicurrency_montant_ht != '') {
  527. $sql .= natural_search('f.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
  528. }
  529. if ($search_multicurrency_montant_vat != '') {
  530. $sql .= natural_search('f.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
  531. }
  532. if ($search_multicurrency_montant_ttc != '') {
  533. $sql .= natural_search('f.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
  534. }
  535. if ($search_login) {
  536. $sql .= natural_search(array('u.login', 'u.lastname', 'u.firstname'), $search_login);
  537. }
  538. if ($search_status != '' && $search_status >= 0) {
  539. $sql .= " AND f.fk_statut = ".((int) $search_status);
  540. }
  541. if ($search_paymentmode > 0) {
  542. $sql .= " AND f.fk_mode_reglement = ".((int) $search_paymentmode);
  543. }
  544. if ($search_paymentcond > 0) {
  545. $sql .= " AND f.fk_cond_reglement = ".((int) $search_paymentcond);
  546. }
  547. if ($search_date_start) {
  548. $sql .= " AND f.datef >= '" . $db->idate($search_date_start) . "'";
  549. }
  550. if ($search_date_end) {
  551. $sql .= " AND f.datef <= '" . $db->idate($search_date_end) . "'";
  552. }
  553. if ($search_datelimit_start) {
  554. $sql .= " AND f.date_lim_reglement >= '" . $db->idate($search_datelimit_start) . "'";
  555. }
  556. if ($search_datelimit_end) {
  557. $sql .= " AND f.date_lim_reglement <= '" . $db->idate($search_datelimit_end) . "'";
  558. }
  559. if ($option == 'late') {
  560. $sql .= " AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->fournisseur->warning_delay)."'";
  561. }
  562. if ($search_label) {
  563. $sql .= natural_search('f.libelle', $search_label);
  564. }
  565. // Search on sale representative
  566. if ($search_sale && $search_sale != '-1') {
  567. if ($search_sale == -2) {
  568. $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc)";
  569. } elseif ($search_sale > 0) {
  570. $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = f.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
  571. }
  572. }
  573. $searchCategorySupplierList = $search_categ_sup ? array($search_categ_sup) : array();
  574. $searchCategorySupplierOperator = 0;
  575. // Search for tag/category ($searchCategorySupplierList is an array of ID)
  576. if (!empty($searchCategorySupplierList)) {
  577. $searchCategorySupplierSqlList = array();
  578. $listofcategoryid = '';
  579. foreach ($searchCategorySupplierList as $searchCategorySupplier) {
  580. if (intval($searchCategorySupplier) == -2) {
  581. $searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)";
  582. } elseif (intval($searchCategorySupplier) > 0) {
  583. if ($searchCategorySupplierOperator == 0) {
  584. $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategorySupplier).")";
  585. } else {
  586. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier);
  587. }
  588. }
  589. }
  590. if ($listofcategoryid) {
  591. $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  592. }
  593. if ($searchCategorySupplierOperator == 1) {
  594. if (!empty($searchCategorySupplierSqlList)) {
  595. $sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")";
  596. }
  597. } else {
  598. if (!empty($searchCategorySupplierSqlList)) {
  599. $sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")";
  600. }
  601. }
  602. }
  603. // Search for tag/category ($searchCategoryProductList is an array of ID)
  604. $searchCategoryProductList = $search_product_category ? array($search_product_category) : array();
  605. $searchCategoryProductOperator = 0;
  606. if (!empty($searchCategoryProductList)) {
  607. $searchCategoryProductSqlList = array();
  608. $listofcategoryid = '';
  609. foreach ($searchCategoryProductList as $searchCategoryProduct) {
  610. if (intval($searchCategoryProduct) == -2) {
  611. $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facture_fourn_det as fd WHERE fd.fk_facture_fourn = f.rowid AND p.rowid = ck.fk_product)";
  612. } elseif (intval($searchCategoryProduct) > 0) {
  613. if ($searchCategoryProductOperator == 0) {
  614. $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facture_fourn_det as fd WHERE fd.fk_facture_fourn = f.rowid AND p.rowid = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
  615. } else {
  616. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
  617. }
  618. }
  619. }
  620. if ($listofcategoryid) {
  621. $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."facture_fourn_det as fd WHERE fd.fk_facture_fourn = f.rowid AND p.rowid = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  622. }
  623. if ($searchCategoryProductOperator == 1) {
  624. if (!empty($searchCategoryProductSqlList)) {
  625. $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
  626. }
  627. } else {
  628. if (!empty($searchCategoryProductSqlList)) {
  629. $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
  630. }
  631. }
  632. }
  633. if ($filter && $filter != -1) {
  634. $aFilter = explode(',', $filter);
  635. foreach ($aFilter as $fil) {
  636. $filt = explode(':', $fil);
  637. $sql .= " AND ".$db->escape(trim($filt[0]))." = '".$db->escape(trim($filt[1]))."'";
  638. }
  639. }
  640. /*
  641. if ($search_sale > 0) {
  642. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
  643. }*/
  644. if ($search_user > 0) {
  645. $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='invoice_supplier' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".((int) $search_user);
  646. }
  647. // Add where from extra fields
  648. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  649. // Add where from hooks
  650. $parameters = array();
  651. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  652. $sql .= $hookmanager->resPrint;
  653. if (!$search_all) {
  654. $sql .= " GROUP BY f.rowid, f.ref, f.ref_supplier, f.type, f.subtype, f.datef, f.date_lim_reglement, f.fk_mode_reglement, f.fk_cond_reglement,";
  655. $sql .= " f.total_ht, f.total_ttc, f.total_tva, f.paye, f.close_code, f.fk_statut, f.libelle, f.datec, f.tms,";
  656. $sql .= " f.localtax1, f.localtax2,";
  657. $sql .= ' f.fk_multicurrency, f.multicurrency_code, f.multicurrency_tx, f.multicurrency_total_ht, f.multicurrency_total_tva, f.multicurrency_total_ttc,';
  658. $sql .= " f.note_public, f.note_private,";
  659. $sql .= " f.fk_user_author,";
  660. $sql .= ' s.rowid, s.nom, s.name_alias, s.email, s.town, s.zip, s.fk_pays, s.client, s.fournisseur, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,';
  661. $sql .= " typent.code,";
  662. $sql .= " state.code_departement, state.nom,";
  663. $sql .= ' country.code,';
  664. $sql .= " p.rowid, p.ref, p.title,";
  665. $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";
  666. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  667. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  668. //prevent error with sql_mode=only_full_group_by
  669. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ",ef.".$key : '');
  670. }
  671. }
  672. // Add GroupBy from hooks
  673. $parameters = array('all' => $search_all, 'fieldstosearchall' => $fieldstosearchall);
  674. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  675. $sql .= $hookmanager->resPrint;
  676. } else {
  677. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  678. }
  679. // Add HAVING from hooks
  680. $parameters = array();
  681. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  682. $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
  683. // Count total nb of records
  684. $nbtotalofrecords = '';
  685. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  686. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  687. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  688. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  689. $resql = $db->query($sqlforcount);
  690. if ($resql) {
  691. $objforcount = $db->fetch_object($resql);
  692. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  693. } else {
  694. dol_print_error($db);
  695. }
  696. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  697. $page = 0;
  698. $offset = 0;
  699. }
  700. $db->free($resql);
  701. }
  702. // Complete request and execute it with limit
  703. $sql .= $db->order($sortfield, $sortorder);
  704. if ($limit) {
  705. $sql .= $db->plimit($limit + 1, $offset);
  706. }
  707. //print $sql;
  708. $resql = $db->query($sql);
  709. if (!$resql) {
  710. dol_print_error($db);
  711. exit;
  712. }
  713. $num = $db->num_rows($resql);
  714. // Direct jump if only one record found
  715. if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  716. $obj = $db->fetch_object($resql);
  717. $id = $obj->facid;
  718. header("Location: ".DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$id);
  719. exit;
  720. }
  721. // Output page
  722. // --------------------------------------------------------------------
  723. llxHeader('', $title, $help_url);
  724. if ($socid) {
  725. $soc = new Societe($db);
  726. $soc->fetch($socid);
  727. if (empty($search_company)) {
  728. $search_company = $soc->name;
  729. $search_company_alias = $soc->name_alias;
  730. }
  731. }
  732. $arrayofselected = is_array($toselect) ? $toselect : array();
  733. $param = '&socid='.$socid;
  734. if (!empty($mode)) {
  735. $param .= '&mode='.urlencode($mode);
  736. }
  737. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  738. $param .= '&contextpage='.urlencode($contextpage);
  739. }
  740. if ($limit > 0 && $limit != $conf->liste_limit) {
  741. $param .= '&limit='.((int) $limit);
  742. }
  743. if ($optioncss != '') {
  744. $param .= '&optioncss='.urlencode($optioncss);
  745. }
  746. if ($search_all) {
  747. $param .= '&search_all='.urlencode($search_all);
  748. }
  749. if ($search_date_start) {
  750. $param .= buildParamDate('search_date_start', null, '', 'tzserver');
  751. }
  752. if ($search_date_end) {
  753. $param .= buildParamDate('search_date_end', null, '', 'tzserver');
  754. }
  755. if ($search_datelimit_startday) {
  756. $param .= '&search_datelimit_startday='.urlencode($search_datelimit_startday);
  757. }
  758. if ($search_datelimit_startmonth) {
  759. $param .= '&search_datelimit_startmonth='.urlencode($search_datelimit_startmonth);
  760. }
  761. if ($search_datelimit_startyear) {
  762. $param .= '&search_datelimit_startyear='.urlencode($search_datelimit_startyear);
  763. }
  764. if ($search_datelimit_endday) {
  765. $param .= '&search_datelimit_endday='.urlencode($search_datelimit_endday);
  766. }
  767. if ($search_datelimit_endmonth) {
  768. $param .= '&search_datelimit_endmonth='.urlencode($search_datelimit_endmonth);
  769. }
  770. if ($search_datelimit_endyear) {
  771. $param .= '&search_datelimit_endyear='.urlencode($search_datelimit_endyear);
  772. }
  773. if ($search_ref) {
  774. $param .= '&search_ref='.urlencode($search_ref);
  775. }
  776. if ($search_refsupplier) {
  777. $param .= '&search_refsupplier='.urlencode($search_refsupplier);
  778. }
  779. if ($search_type != '') {
  780. $param .= '&search_type='.urlencode($search_type);
  781. }
  782. if ($search_subtype != '') {
  783. $param .= '&search_subtype='.urlencode($search_subtype);
  784. }
  785. if ($search_label) {
  786. $param .= '&search_label='.urlencode($search_label);
  787. }
  788. if ($search_company) {
  789. $param .= '&search_company='.urlencode($search_company);
  790. }
  791. if ($search_company_alias) {
  792. $param .= '&search_company_alias='.urlencode($search_company_alias);
  793. }
  794. if ($search_login) {
  795. $param .= '&search_login='.urlencode($search_login);
  796. }
  797. if ($search_montant_ht != '') {
  798. $param .= '&search_montant_ht='.urlencode($search_montant_ht);
  799. }
  800. if ($search_montant_vat != '') {
  801. $param .= '&search_montant_vat='.urlencode($search_montant_vat);
  802. }
  803. if ($search_montant_localtax1 != '') {
  804. $param .= '&search_montant_localtax1='.urlencode($search_montant_localtax1);
  805. }
  806. if ($search_montant_localtax2 != '') {
  807. $param .= '&search_montant_localtax2='.urlencode($search_montant_localtax2);
  808. }
  809. if ($search_montant_ttc != '') {
  810. $param .= '&search_montant_ttc='.urlencode($search_montant_ttc);
  811. }
  812. if ($search_multicurrency_code != '') {
  813. $param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
  814. }
  815. if ($search_multicurrency_tx != '') {
  816. $param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
  817. }
  818. if ($search_multicurrency_montant_ht != '') {
  819. $param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
  820. }
  821. if ($search_multicurrency_montant_vat != '') {
  822. $param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
  823. }
  824. if ($search_multicurrency_montant_ttc != '') {
  825. $param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
  826. }
  827. if ($search_amount_no_tax) {
  828. $param .= '&search_amount_no_tax='.urlencode($search_amount_no_tax);
  829. }
  830. if ($search_amount_all_tax) {
  831. $param .= '&search_amount_all_tax='.urlencode($search_amount_all_tax);
  832. }
  833. if ($search_status >= 0) {
  834. $param .= "&search_status=".urlencode($search_status);
  835. }
  836. if ($search_paymentmode) {
  837. $param .= '&search_paymentmode='.urlencode($search_paymentmode);
  838. }
  839. if ($search_paymentcond) {
  840. $param .= '&search_paymentcond='.urlencode($search_paymentcond);
  841. }
  842. if ($show_files) {
  843. $param .= '&show_files='.urlencode($show_files);
  844. }
  845. if ($option) {
  846. $param .= "&search_option=".urlencode($option);
  847. }
  848. if ($search_categ_sup > 0) {
  849. $param .= '&search_categ_sup='.urlencode($search_categ_sup);
  850. }
  851. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  852. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  853. }
  854. // Add $param from extra fields
  855. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  856. // Add $param from hooks
  857. $parameters = array();
  858. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  859. $param .= $hookmanager->resPrint;
  860. // List of mass actions available
  861. $arrayofmassactions = array(
  862. 'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  863. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  864. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  865. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  866. );
  867. if (isModEnabled('paymentbybanktransfer') && $user->hasRight("paymentbybanktransfer", "create")) {
  868. $langs->load('withdrawals');
  869. $arrayofmassactions['banktransfertrequest'] = img_picto('', 'payment', 'class="pictofixedwidth"').$langs->trans("MakeBankTransferOrder");
  870. }
  871. if (!empty($permissiontodelete)) {
  872. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  873. }
  874. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  875. $arrayofmassactions = array();
  876. }
  877. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  878. $url = DOL_URL_ROOT.'/fourn/facture/card.php?action=create';
  879. if (!empty($socid)) {
  880. $url .= '&socid='.urlencode($socid);
  881. }
  882. $i = 0;
  883. print '<form method="POST" id="searchFormList" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  884. if ($optioncss != '') {
  885. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  886. }
  887. print '<input type="hidden" name="token" value="'.newToken().'">';
  888. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  889. print '<input type="hidden" name="action" value="list">';
  890. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  891. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  892. print '<input type="hidden" name="socid" value="'.$socid.'">';
  893. print '<input type="hidden" name="page" value="'.$page.'">';
  894. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  895. print '<input type="hidden" name="page_y" value="">';
  896. print '<input type="hidden" name="mode" value="'.$mode.'">';
  897. $newcardbutton = '';
  898. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  899. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  900. $newcardbutton .= dolGetButtonTitleSeparator();
  901. $newcardbutton .= dolGetButtonTitle($langs->trans('NewBill'), '', 'fa fa-plus-circle', $url, '', ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer")));
  902. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'supplier_invoice', 0, $newcardbutton, '', $limit, 0, 0, 1);
  903. // Add code for pre mass action (confirmation or email presend form)
  904. $topicmail = "SendBillRef";
  905. $modelmail = "invoice_supplier_send";
  906. $objecttmp = new FactureFournisseur($db);
  907. $trackid = 'sinv'.$object->id;
  908. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  909. if ($search_all) {
  910. $setupstring = '';
  911. foreach ($fieldstosearchall as $key => $val) {
  912. $fieldstosearchall[$key] = $langs->trans($val);
  913. $setupstring .= $key."=".$val.";";
  914. }
  915. print '<!-- Search done like if SUPPLIER_INVOICE_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  916. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  917. }
  918. // If the user can view prospects other than his'
  919. $moreforfilter = '';
  920. if ($user->hasRight("user", "user", "lire")) {
  921. $langs->load("commercial");
  922. $moreforfilter .= '<div class="divsearchfield">';
  923. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  924. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth200');
  925. $moreforfilter .= '</div>';
  926. }
  927. // If the user can view prospects other than his'
  928. if ($user->hasRight("user", "user", "lire")) {
  929. $moreforfilter .= '<div class="divsearchfield">';
  930. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  931. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
  932. $moreforfilter .= '</div>';
  933. }
  934. // If the user can view prospects other than his'
  935. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
  936. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  937. $moreforfilter .= '<div class="divsearchfield">';
  938. $tmptitle = $langs->trans('IncludingProductWithTag');
  939. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  940. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1);
  941. $moreforfilter .= '</div>';
  942. }
  943. if (isModEnabled('categorie')) {
  944. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  945. $moreforfilter .= '<div class="divsearchfield">';
  946. $tmptitle = $langs->trans('SuppliersCategoriesShort');
  947. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('supplier', $search_categ_sup, 'search_categ_sup', 1, $tmptitle);
  948. $moreforfilter .= '</div>';
  949. }
  950. $parameters = array();
  951. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  952. if (empty($reshook)) {
  953. $moreforfilter .= $hookmanager->resPrint;
  954. } else {
  955. $moreforfilter = $hookmanager->resPrint;
  956. }
  957. if (!empty($moreforfilter)) {
  958. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  959. print $moreforfilter;
  960. $parameters = array();
  961. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  962. print $hookmanager->resPrint;
  963. print '</div>';
  964. }
  965. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  966. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  967. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  968. print '<div class="div-table-responsive">';
  969. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  970. // Fields title search
  971. // --------------------------------------------------------------------
  972. print '<tr class="liste_titre_filter">';
  973. // Action column
  974. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  975. print '<td class="liste_titre center maxwidthsearch">';
  976. $searchpicto = $form->showFilterButtons('left');
  977. print $searchpicto;
  978. print '</td>';
  979. }
  980. // Ref
  981. if (!empty($arrayfields['f.ref']['checked'])) {
  982. print '<td class="liste_titre left">';
  983. print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  984. print '</td>';
  985. }
  986. // Ref supplier
  987. if (!empty($arrayfields['f.ref_supplier']['checked'])) {
  988. print '<td class="liste_titre">';
  989. print '<input class="flat maxwidth75" type="text" name="search_refsupplier" value="'.dol_escape_htmltag($search_refsupplier).'">';
  990. print '</td>';
  991. }
  992. // Type
  993. if (!empty($arrayfields['f.type']['checked'])) {
  994. print '<td class="liste_titre maxwidthonsmartphone">';
  995. $listtype = array(
  996. FactureFournisseur::TYPE_STANDARD=>$langs->trans("InvoiceStandard"),
  997. FactureFournisseur::TYPE_REPLACEMENT=>$langs->trans("InvoiceReplacement"),
  998. FactureFournisseur::TYPE_CREDIT_NOTE=>$langs->trans("InvoiceAvoir"),
  999. FactureFournisseur::TYPE_DEPOSIT=>$langs->trans("InvoiceDeposit"),
  1000. );
  1001. /*
  1002. if (!empty($conf->global->INVOICE_USE_SITUATION))
  1003. {
  1004. $listtype[Facture::TYPE_SITUATION] = $langs->trans("InvoiceSituation");
  1005. }
  1006. */
  1007. //$listtype[Facture::TYPE_PROFORMA]=$langs->trans("InvoiceProForma"); // A proformat invoice is not an invoice but must be an order.
  1008. print $form->selectarray('search_type', $listtype, $search_type, 1, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100');
  1009. print '</td>';
  1010. }
  1011. // Invoice Subtype
  1012. if (!empty($arrayfields['f.subtype']['checked'])) {
  1013. print '<td class="liste_titre maxwidthonsmartphone" align="center">';
  1014. print $form->selectarray('search_subtype', $subtypearray, $search_subtype, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
  1015. print '</td>';
  1016. }
  1017. // Label
  1018. if (!empty($arrayfields['f.label']['checked'])) {
  1019. print '<td class="liste_titre">';
  1020. print '<input class="flat maxwidth75" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
  1021. print '</td>';
  1022. }
  1023. // Date invoice
  1024. if (!empty($arrayfields['f.datef']['checked'])) {
  1025. print '<td class="liste_titre center">';
  1026. print '<div class="nowrapfordate">';
  1027. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  1028. print '</div>';
  1029. print '<div class="nowrapfordate">';
  1030. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  1031. print '</div>';
  1032. print '</td>';
  1033. }
  1034. // Date due
  1035. if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
  1036. print '<td class="liste_titre center">';
  1037. print '<div class="">';
  1038. /*
  1039. print $langs->trans('From').' ';
  1040. print $form->selectDate($search_datelimit_start ? $search_datelimit_start : -1, 'search_datelimit_start', 0, 0, 1);
  1041. print '</div>';
  1042. print '<div class="nowrap">';
  1043. print $langs->trans('to').' ';*/
  1044. print $form->selectDate($search_datelimit_end ? $search_datelimit_end : -1, 'search_datelimit_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("Before"));
  1045. //print '<br>';
  1046. print '<div class="nowraponall inline-block valignmiddle"><input type="checkbox" class="valignmiddle" name="search_option" id="search_option" value="late"'.($option == 'late' ? ' checked' : '').'><label for="search_option" class="valignmiddle">'.$langs->trans("Alert").'</label></div>';
  1047. print '</div>';
  1048. print '</td>';
  1049. }
  1050. // Project
  1051. if (!empty($arrayfields['p.ref']['checked'])) {
  1052. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'"></td>';
  1053. }
  1054. // Thirpdarty
  1055. if (!empty($arrayfields['s.nom']['checked'])) {
  1056. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'"'.($socid > 0 ? " disabled" : "").'></td>';
  1057. }
  1058. // Alias
  1059. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1060. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_company_alias" value="'.dol_escape_htmltag($search_company_alias).'"></td>';
  1061. }
  1062. // Town
  1063. if (!empty($arrayfields['s.town']['checked'])) {
  1064. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
  1065. }
  1066. // Zip
  1067. if (!empty($arrayfields['s.zip']['checked'])) {
  1068. print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
  1069. }
  1070. // State
  1071. if (!empty($arrayfields['state.nom']['checked'])) {
  1072. print '<td class="liste_titre">';
  1073. print '<input class="flat maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  1074. print '</td>';
  1075. }
  1076. // Country
  1077. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1078. print '<td class="liste_titre center">';
  1079. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  1080. print '</td>';
  1081. }
  1082. // Company type
  1083. if (!empty($arrayfields['typent.code']['checked'])) {
  1084. print '<td class="liste_titre maxwidthonsmartphone center">';
  1085. print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
  1086. print '</td>';
  1087. }
  1088. // Condition of payment
  1089. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  1090. print '<td class="liste_titre left">';
  1091. print $form->getSelectConditionsPaiements($search_paymentcond, 'search_paymentcond', -1, 1, 1, 'maxwidth100');
  1092. print '</td>';
  1093. }
  1094. // Payment mode
  1095. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  1096. print '<td class="liste_titre">';
  1097. print $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 20, 1, 'maxwidth100', 1);
  1098. print '</td>';
  1099. }
  1100. if (!empty($arrayfields['f.total_ht']['checked'])) {
  1101. // Amount without tax
  1102. print '<td class="liste_titre right">';
  1103. print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
  1104. print '</td>';
  1105. }
  1106. if (!empty($arrayfields['f.total_vat']['checked'])) {
  1107. // Amount vat
  1108. print '<td class="liste_titre right">';
  1109. print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
  1110. print '</td>';
  1111. }
  1112. if (!empty($arrayfields['f.total_localtax1']['checked'])) {
  1113. // Amount tax 1
  1114. print '<td class="liste_titre right">';
  1115. print '<input class="flat" type="text" size="5" name="search_montant_localtax1" value="'.dol_escape_htmltag($search_montant_localtax1).'">';
  1116. print '</td>';
  1117. }
  1118. if (!empty($arrayfields['f.total_localtax2']['checked'])) {
  1119. // Amount tax 2
  1120. print '<td class="liste_titre right">';
  1121. print '<input class="flat" type="text" size="5" name="search_montant_localtax2" value="'.dol_escape_htmltag($search_montant_localtax2).'">';
  1122. print '</td>';
  1123. }
  1124. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  1125. // Amount inc tac
  1126. print '<td class="liste_titre right">';
  1127. print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
  1128. print '</td>';
  1129. }
  1130. if (!empty($arrayfields['f.nb_docs']['checked'])) {
  1131. // Nb of attached documents
  1132. print '<td class="liste_titre" align="center">';
  1133. print '</td>';
  1134. }
  1135. if (!empty($arrayfields['u.login']['checked'])) {
  1136. // Author
  1137. print '<td class="liste_titre" align="center">';
  1138. print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
  1139. print '</td>';
  1140. }
  1141. if (!empty($arrayfields['dynamount_payed']['checked'])) {
  1142. print '<td class="liste_titre right">';
  1143. print '</td>';
  1144. }
  1145. if (!empty($arrayfields['rtp']['checked'])) {
  1146. print '<td class="liste_titre">';
  1147. print '</td>';
  1148. }
  1149. if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
  1150. // Currency
  1151. print '<td class="liste_titre">';
  1152. print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
  1153. print '</td>';
  1154. }
  1155. if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
  1156. // Currency rate
  1157. print '<td class="liste_titre">';
  1158. print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
  1159. print '</td>';
  1160. }
  1161. if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
  1162. // Amount
  1163. print '<td class="liste_titre right">';
  1164. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
  1165. print '</td>';
  1166. }
  1167. if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
  1168. // Amount
  1169. print '<td class="liste_titre right">';
  1170. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
  1171. print '</td>';
  1172. }
  1173. if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
  1174. // Amount
  1175. print '<td class="liste_titre right">';
  1176. print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
  1177. print '</td>';
  1178. }
  1179. if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
  1180. print '<td class="liste_titre">';
  1181. print '</td>';
  1182. }
  1183. if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
  1184. print '<td class="liste_titre right">';
  1185. print '</td>';
  1186. }
  1187. // Extra fields
  1188. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  1189. // Fields from hook
  1190. $parameters = array('arrayfields'=>$arrayfields);
  1191. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1192. print $hookmanager->resPrint;
  1193. // Date creation
  1194. if (!empty($arrayfields['f.datec']['checked'])) {
  1195. print '<td class="liste_titre">';
  1196. print '</td>';
  1197. }
  1198. // Date modification
  1199. if (!empty($arrayfields['f.tms']['checked'])) {
  1200. print '<td class="liste_titre">';
  1201. print '</td>';
  1202. }
  1203. // Status
  1204. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  1205. print '<td class="liste_titre center parentonrightofpage">';
  1206. $liststatus = array('0'=>$langs->trans("Draft"), '1'=>$langs->trans("Unpaid"), '2'=>$langs->trans("Paid"));
  1207. print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 0, 0, 0, '', 'center search_status width100 onrightofpage', 1);
  1208. print '</td>';
  1209. }
  1210. // Action column
  1211. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1212. print '<td class="liste_titre center maxwidthsearch">';
  1213. $searchpicto = $form->showFilterButtons();
  1214. print $searchpicto;
  1215. print '</td>';
  1216. }
  1217. print "</tr>\n";
  1218. $totalarray = array();
  1219. $totalarray['nbfield'] = 0;
  1220. // Fields title label
  1221. // --------------------------------------------------------------------
  1222. print '<tr class="liste_titre">';
  1223. // Action column
  1224. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1225. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  1226. $totalarray['nbfield']++;
  1227. }
  1228. if (!empty($arrayfields['f.ref']['checked'])) {
  1229. print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER['PHP_SELF'], 'f.ref,f.rowid', '', $param, '', $sortfield, $sortorder);
  1230. $totalarray['nbfield']++;
  1231. }
  1232. if (!empty($arrayfields['f.ref_supplier']['checked'])) {
  1233. print_liste_field_titre($arrayfields['f.ref_supplier']['label'], $_SERVER["PHP_SELF"], 'f.ref_supplier', '', $param, '', $sortfield, $sortorder);
  1234. $totalarray['nbfield']++;
  1235. }
  1236. if (!empty($arrayfields['f.type']['checked'])) {
  1237. print_liste_field_titre($arrayfields['f.type']['label'], $_SERVER["PHP_SELF"], 'f.type', '', $param, '', $sortfield, $sortorder);
  1238. $totalarray['nbfield']++;
  1239. }
  1240. if (!empty($arrayfields['f.subtype']['checked'])) {
  1241. print_liste_field_titre($arrayfields['f.subtype']['label'], $_SERVER["PHP_SELF"], 'f.subtype', '', $param, '', $sortfield, $sortorder);
  1242. }
  1243. if (!empty($arrayfields['f.label']['checked'])) {
  1244. print_liste_field_titre($arrayfields['f.label']['label'], $_SERVER['PHP_SELF'], "f.libelle,f.rowid", '', $param, '', $sortfield, $sortorder);
  1245. $totalarray['nbfield']++;
  1246. }
  1247. if (!empty($arrayfields['f.datef']['checked'])) {
  1248. print_liste_field_titre($arrayfields['f.datef']['label'], $_SERVER['PHP_SELF'], 'f.datef,f.rowid', '', $param, '', $sortfield, $sortorder, 'center ');
  1249. $totalarray['nbfield']++;
  1250. }
  1251. if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
  1252. print_liste_field_titre($arrayfields['f.date_lim_reglement']['label'], $_SERVER['PHP_SELF'], "f.date_lim_reglement", '', $param, '', $sortfield, $sortorder, 'center ');
  1253. $totalarray['nbfield']++;
  1254. }
  1255. if (!empty($arrayfields['p.ref']['checked'])) {
  1256. print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER['PHP_SELF'], "p.ref", '', $param, '', $sortfield, $sortorder);
  1257. $totalarray['nbfield']++;
  1258. }
  1259. if (!empty($arrayfields['s.nom']['checked'])) {
  1260. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER['PHP_SELF'], 's.nom', '', $param, '', $sortfield, $sortorder);
  1261. $totalarray['nbfield']++;
  1262. }
  1263. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1264. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER['PHP_SELF'], 's.name_alias', '', $param, '', $sortfield, $sortorder);
  1265. $totalarray['nbfield']++;
  1266. }
  1267. if (!empty($arrayfields['s.town']['checked'])) {
  1268. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  1269. $totalarray['nbfield']++;
  1270. }
  1271. if (!empty($arrayfields['s.zip']['checked'])) {
  1272. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder, 'center ');
  1273. $totalarray['nbfield']++;
  1274. }
  1275. if (!empty($arrayfields['state.nom']['checked'])) {
  1276. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.name_alias", "", $param, '', $sortfield, $sortorder);
  1277. $totalarray['nbfield']++;
  1278. }
  1279. if (!empty($arrayfields['state.name_alias']['checked'])) {
  1280. print_liste_field_titre($arrayfields['state.name_alias']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  1281. $totalarray['nbfield']++;
  1282. }
  1283. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1284. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  1285. $totalarray['nbfield']++;
  1286. }
  1287. if (!empty($arrayfields['typent.code']['checked'])) {
  1288. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  1289. $totalarray['nbfield']++;
  1290. }
  1291. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  1292. print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder);
  1293. $totalarray['nbfield']++;
  1294. }
  1295. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  1296. print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder);
  1297. $totalarray['nbfield']++;
  1298. }
  1299. if (!empty($arrayfields['f.total_ht']['checked'])) {
  1300. print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total_ht', '', $param, '', $sortfield, $sortorder, 'right ');
  1301. $totalarray['nbfield']++;
  1302. }
  1303. if (!empty($arrayfields['f.total_vat']['checked'])) {
  1304. print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
  1305. $totalarray['nbfield']++;
  1306. }
  1307. if (!empty($arrayfields['f.total_localtax1']['checked'])) {
  1308. print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, '', $sortfield, $sortorder, 'right ');
  1309. $totalarray['nbfield']++;
  1310. }
  1311. if (!empty($arrayfields['f.total_localtax2']['checked'])) {
  1312. print_liste_field_titre($arrayfields['f.total_localtax2']['label'], $_SERVER['PHP_SELF'], 'f.localtax2', '', $param, '', $sortfield, $sortorder, 'right ');
  1313. $totalarray['nbfield']++;
  1314. }
  1315. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  1316. print_liste_field_titre($arrayfields['f.total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
  1317. $totalarray['nbfield']++;
  1318. }
  1319. if (!empty($arrayfields['f.nb_docs']['checked'])) {
  1320. print_liste_field_titre($arrayfields['f.nb_docs']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1321. $totalarray['nbfield']++;
  1322. }
  1323. if (!empty($arrayfields['u.login']['checked'])) {
  1324. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, '', $sortfield, $sortorder);
  1325. $totalarray['nbfield']++;
  1326. }
  1327. if (!empty($arrayfields['dynamount_payed']['checked'])) {
  1328. print_liste_field_titre($arrayfields['dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1329. $totalarray['nbfield']++;
  1330. }
  1331. if (!empty($arrayfields['rtp']['checked'])) {
  1332. print_liste_field_titre($arrayfields['rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
  1333. $totalarray['nbfield']++;
  1334. }
  1335. if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
  1336. print_liste_field_titre($arrayfields['f.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_code', '', $param, '', $sortfield, $sortorder);
  1337. $totalarray['nbfield']++;
  1338. }
  1339. if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
  1340. print_liste_field_titre($arrayfields['f.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
  1341. $totalarray['nbfield']++;
  1342. }
  1343. if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
  1344. print_liste_field_titre($arrayfields['f.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ht', '', $param, '"', $sortfield, $sortorder, 'right ');
  1345. $totalarray['nbfield']++;
  1346. }
  1347. if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
  1348. print_liste_field_titre($arrayfields['f.multicurrency_total_vat']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_tva', '', $param, '', $sortfield, $sortorder, 'right ');
  1349. $totalarray['nbfield']++;
  1350. }
  1351. if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
  1352. print_liste_field_titre($arrayfields['f.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'f.multicurrency_total_ttc', '', $param, '', $sortfield, $sortorder, 'right ');
  1353. $totalarray['nbfield']++;
  1354. }
  1355. if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
  1356. print_liste_field_titre($arrayfields['multicurrency_dynamount_payed']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1357. $totalarray['nbfield']++;
  1358. }
  1359. if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
  1360. print_liste_field_titre($arrayfields['multicurrency_rtp']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'right ');
  1361. $totalarray['nbfield']++;
  1362. }
  1363. // Extra fields
  1364. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1365. // Hook fields
  1366. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  1367. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1368. print $hookmanager->resPrint;
  1369. if (!empty($arrayfields['f.datec']['checked'])) {
  1370. print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1371. $totalarray['nbfield']++;
  1372. }
  1373. if (!empty($arrayfields['f.tms']['checked'])) {
  1374. print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1375. $totalarray['nbfield']++;
  1376. }
  1377. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  1378. print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "fk_statut,paye,type", "", $param, '', $sortfield, $sortorder, 'center ');
  1379. $totalarray['nbfield']++;
  1380. }
  1381. // Action column
  1382. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1383. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  1384. $totalarray['nbfield']++;
  1385. }
  1386. print '</tr>'."\n";
  1387. $facturestatic = new FactureFournisseur($db);
  1388. $supplierstatic = new Fournisseur($db);
  1389. $projectstatic = new Project($db);
  1390. $userstatic = new User($db);
  1391. $discount = new DiscountAbsolute($db);
  1392. // Loop on record
  1393. // --------------------------------------------------------------------
  1394. $i = 0;
  1395. $savnbfield = $totalarray['nbfield'];
  1396. $totalarray = array();
  1397. $totalarray['nbfield'] = 0;
  1398. $totalarray['val'] = array();
  1399. $totalarray['val']['f.total_ht']=0;
  1400. $totalarray['val']['f.total_vat']=0;
  1401. $totalarray['val']['f.total_localtax1']=0;
  1402. $totalarray['val']['f.total_localtax1']=0;
  1403. $totalarray['val']['f.total_ttc']=0;
  1404. $imaxinloop = ($limit ? min($num, $limit) : $num);
  1405. while ($i < $imaxinloop) {
  1406. $obj = $db->fetch_object($resql);
  1407. if (empty($obj)) {
  1408. break; // Should not happen
  1409. }
  1410. $datelimit = $db->jdate($obj->datelimite);
  1411. $userstatic->id = $obj->fk_user_author;
  1412. $userstatic->login = $obj->login;
  1413. $userstatic->lastname = $obj->lastname;
  1414. $userstatic->firstname = $obj->firstname;
  1415. $userstatic->email = $obj->user_email;
  1416. $userstatic->statut = $obj->user_statut;
  1417. $userstatic->status = $obj->user_statut;
  1418. $userstatic->entity = $obj->entity;
  1419. $userstatic->photo = $obj->photo;
  1420. $userstatic->office_phone = $obj->office_phone;
  1421. $userstatic->office_fax = $obj->office_fax;
  1422. $userstatic->user_mobile = $obj->user_mobile;
  1423. $userstatic->job = $obj->job;
  1424. $userstatic->gender = $obj->gender;
  1425. $facturestatic->id = $obj->facid;
  1426. $facturestatic->ref = $obj->ref;
  1427. $facturestatic->type = $obj->type;
  1428. $facturestatic->subtype = $obj->subtype;
  1429. $facturestatic->total_ht = $obj->total_ht;
  1430. $facturestatic->total_tva = $obj->total_vat;
  1431. $facturestatic->total_ttc = $obj->total_ttc;
  1432. $facturestatic->close_code = $obj->close_code;
  1433. $facturestatic->ref_supplier = $obj->ref_supplier;
  1434. $facturestatic->date_echeance = $db->jdate($obj->datelimite);
  1435. $facturestatic->statut = $obj->fk_statut;
  1436. $facturestatic->status = $obj->fk_statut;
  1437. $facturestatic->note_public = $obj->note_public;
  1438. $facturestatic->note_private = $obj->note_private;
  1439. $facturestatic->multicurrency_code = $obj->multicurrency_code;
  1440. $facturestatic->multicurrency_tx = $obj->multicurrency_tx;
  1441. $facturestatic->multicurrency_total_ht = $obj->multicurrency_total_ht;
  1442. $facturestatic->multicurrency_total_tva = $obj->multicurrency_total_vat;
  1443. $facturestatic->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
  1444. $thirdparty->id = $obj->socid;
  1445. $thirdparty->name = $obj->name;
  1446. $thirdparty->name_alias = $obj->alias;
  1447. $thirdparty->client = $obj->client;
  1448. $thirdparty->fournisseur = $obj->fournisseur;
  1449. $thirdparty->code_client = $obj->code_client;
  1450. $thirdparty->code_compta_client = $obj->code_compta_client;
  1451. $thirdparty->code_fournisseur = $obj->code_fournisseur;
  1452. $thirdparty->code_compta_fournisseur = $obj->code_compta_fournisseur;
  1453. $thirdparty->email = $obj->email;
  1454. $thirdparty->country_code = $obj->country_code;
  1455. $paiement = $facturestatic->getSommePaiement();
  1456. $totalcreditnotes = $facturestatic->getSumCreditNotesUsed();
  1457. $totaldeposits = $facturestatic->getSumDepositsUsed();
  1458. $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
  1459. $remaintopay = $obj->total_ttc - $totalpay;
  1460. $multicurrency_paiement = $facturestatic->getSommePaiement(1);
  1461. $multicurrency_totalcreditnotes = $facturestatic->getSumCreditNotesUsed(1);
  1462. $multicurrency_totaldeposits = $facturestatic->getSumDepositsUsed(1);
  1463. $totalpay = $paiement + $totalcreditnotes + $totaldeposits;
  1464. $remaintopay = price2num($facturestatic->total_ttc - $totalpay);
  1465. $multicurrency_totalpay = $multicurrency_paiement + $multicurrency_totalcreditnotes + $multicurrency_totaldeposits;
  1466. $multicurrency_remaintopay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_totalpay);
  1467. if ($facturestatic->status == FactureFournisseur::STATUS_CLOSED && $facturestatic->close_code == 'discount_vat') { // If invoice closed with discount for anticipated payment
  1468. $remaintopay = 0;
  1469. $multicurrency_remaintopay = 0;
  1470. }
  1471. if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed
  1472. $remaincreditnote = $discount->getAvailableDiscounts($thirdparty, '', 'rc.fk_facture_source='.$facturestatic->id);
  1473. $remaintopay = -$remaincreditnote;
  1474. $totalpay = price2num($facturestatic->total_ttc - $remaintopay);
  1475. $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($thirdparty, '', 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1);
  1476. $multicurrency_remaintopay = -$multicurrency_remaincreditnote;
  1477. $multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay);
  1478. }
  1479. $facturestatic->alreadypaid = ($paiement ? $paiement : 0);
  1480. $facturestatic->paye = $obj->paye;
  1481. $facturestatic->socid = $thirdparty->getNomUrl(1, 'supplier', 3);
  1482. $facturestatic->date = $db->jdate($obj->datef);
  1483. $object = $facturestatic;
  1484. //If invoice has been converted and the conversion has been used, we dont have remain to pay on invoice
  1485. if ($facturestatic->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
  1486. if ($facturestatic->isCreditNoteUsed()) {
  1487. $remaintopay = -$facturestatic->getSumFromThisCreditNotesNotUsed();
  1488. }
  1489. }
  1490. if ($mode == 'kanban') {
  1491. if ($i == 0) {
  1492. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  1493. print '<div class="box-flex-container kanban">';
  1494. }
  1495. // Output Kanban
  1496. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1497. $selected = 0;
  1498. if (in_array($object->id, $arrayofselected)) {
  1499. $selected = 1;
  1500. }
  1501. }
  1502. $arraydata = array('alreadypaid' => $paiement, 'thirdparty' => $thirdparty->getNomUrl(1, '', 12), 'selected' => in_array($object->id, $arrayofselected));
  1503. print $facturestatic->getKanbanView('', $arraydata);
  1504. if ($i == ($imaxinloop - 1)) {
  1505. print '</div>';
  1506. print '</td></tr>';
  1507. }
  1508. } else {
  1509. // Show line of result
  1510. $j = 0;
  1511. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  1512. // Action column
  1513. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1514. print '<td class="nowrap center">';
  1515. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1516. $selected = 0;
  1517. if (in_array($obj->facid, $arrayofselected)) {
  1518. $selected = 1;
  1519. }
  1520. print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
  1521. }
  1522. print '</td>';
  1523. if (!$i) {
  1524. $totalarray['nbfield']++;
  1525. }
  1526. }
  1527. if (!empty($arrayfields['f.ref']['checked'])) {
  1528. print '<td class="nowraponall">';
  1529. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  1530. // Picto + Ref
  1531. print '<td class="nobordernopadding nowraponall">';
  1532. print $facturestatic->getNomUrl(1, '', 0, 0, '', 0, -1, 1);
  1533. $filename = dol_sanitizeFileName($obj->ref);
  1534. $filedir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
  1535. $subdir = get_exdir($obj->facid, 2, 0, 0, $facturestatic, 'invoice_supplier').dol_sanitizeFileName($obj->ref);
  1536. print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir);
  1537. print '</td></tr></table>';
  1538. print "</td>\n";
  1539. if (!$i) {
  1540. $totalarray['nbfield']++;
  1541. }
  1542. }
  1543. // Supplier ref
  1544. if (!empty($arrayfields['f.ref_supplier']['checked'])) {
  1545. print '<td class="nowrap tdoverflowmax150" title="'.dol_escape_htmltag($obj->ref_supplier).'">';
  1546. print $obj->ref_supplier;
  1547. print '</td>';
  1548. if (!$i) {
  1549. $totalarray['nbfield']++;
  1550. }
  1551. }
  1552. // Type
  1553. if (!empty($arrayfields['f.type']['checked'])) {
  1554. print '<td class="nowrap">';
  1555. print $facturestatic->getLibType();
  1556. print "</td>";
  1557. if (!$i) {
  1558. $totalarray['nbfield']++;
  1559. }
  1560. }
  1561. // Invoice Subtype
  1562. if (!empty($arrayfields['f.subtype']['checked'])) {
  1563. $labeltoshow = '';
  1564. if ($facturestatic->subtype > 0) {
  1565. $labeltoshow = $facturestatic->getSubtypeLabel('facture_fourn');
  1566. }
  1567. print '<td class="nowraponall tdoverflowmax300" title="'.$labeltoshow.'">';
  1568. print $labeltoshow;
  1569. print "</td>";
  1570. if (!$i) {
  1571. $totalarray['nbfield']++;
  1572. }
  1573. }
  1574. // Label
  1575. if (!empty($arrayfields['f.label']['checked'])) {
  1576. print '<td class="nowrap">';
  1577. print dol_escape_htmltag($obj->label);
  1578. print '</td>';
  1579. if (!$i) {
  1580. $totalarray['nbfield']++;
  1581. }
  1582. }
  1583. // Date
  1584. if (!empty($arrayfields['f.datef']['checked'])) {
  1585. print '<td class="center nowrap">';
  1586. print dol_print_date($db->jdate($obj->datef), 'day');
  1587. print '</td>';
  1588. if (!$i) {
  1589. $totalarray['nbfield']++;
  1590. }
  1591. }
  1592. // Date limit
  1593. if (!empty($arrayfields['f.date_lim_reglement']['checked'])) {
  1594. print '<td class="center nowraponall">'.dol_print_date($datelimit, 'day');
  1595. if ($facturestatic->hasDelay()) {
  1596. print img_warning($langs->trans('Alert').' - '.$langs->trans('Late'));
  1597. }
  1598. print '</td>';
  1599. if (!$i) {
  1600. $totalarray['nbfield']++;
  1601. }
  1602. }
  1603. // Project
  1604. if (!empty($arrayfields['p.ref']['checked'])) {
  1605. print '<td class="nowrap">';
  1606. if ($obj->project_id > 0) {
  1607. $projectstatic->id = $obj->project_id;
  1608. $projectstatic->ref = $obj->project_ref;
  1609. $projectstatic->title = $obj->project_label;
  1610. print $projectstatic->getNomUrl(1);
  1611. }
  1612. print '</td>';
  1613. if (!$i) {
  1614. $totalarray['nbfield']++;
  1615. }
  1616. }
  1617. // Third party
  1618. if (!empty($arrayfields['s.nom']['checked'])) {
  1619. print '<td class="tdoverflowmax150">';
  1620. print $thirdparty->getNomUrl(1, 'supplier', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
  1621. print '</td>';
  1622. if (!$i) {
  1623. $totalarray['nbfield']++;
  1624. }
  1625. }
  1626. // Alias
  1627. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1628. print '<td class="tdoverflowmax150">';
  1629. print dol_escape_htmltag($thirdparty->name_alias);
  1630. print '</td>';
  1631. if (!$i) {
  1632. $totalarray['nbfield']++;
  1633. }
  1634. }
  1635. // Town
  1636. if (!empty($arrayfields['s.town']['checked'])) {
  1637. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">';
  1638. print dol_escape_htmltag($obj->town);
  1639. print '</td>';
  1640. if (!$i) {
  1641. $totalarray['nbfield']++;
  1642. }
  1643. }
  1644. // Zip
  1645. if (!empty($arrayfields['s.zip']['checked'])) {
  1646. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->zip).'">';
  1647. print dol_escape_htmltag($obj->zip);
  1648. print '</td>';
  1649. if (!$i) {
  1650. $totalarray['nbfield']++;
  1651. }
  1652. }
  1653. // State
  1654. if (!empty($arrayfields['state.nom']['checked'])) {
  1655. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->state_name).'">';
  1656. print dol_escape_htmltag($obj->state_name);
  1657. print "</td>\n";
  1658. if (!$i) {
  1659. $totalarray['nbfield']++;
  1660. }
  1661. }
  1662. // Country
  1663. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1664. print '<td class="center">';
  1665. $tmparray = getCountry($obj->fk_pays, 'all');
  1666. print $tmparray['label'];
  1667. print '</td>';
  1668. if (!$i) {
  1669. $totalarray['nbfield']++;
  1670. }
  1671. }
  1672. // Type ent
  1673. if (!empty($arrayfields['typent.code']['checked'])) {
  1674. print '<td class="center">';
  1675. if (empty($typenArray)) {
  1676. $typenArray = $formcompany->typent_array(1);
  1677. }
  1678. print $typenArray[$obj->typent_code];
  1679. print '</td>';
  1680. if (!$i) {
  1681. $totalarray['nbfield']++;
  1682. }
  1683. }
  1684. // Payment condition
  1685. if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) {
  1686. $s = $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none', 1, '', -1, -1, 1);
  1687. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
  1688. print dol_escape_htmltag($s);
  1689. print '</td>';
  1690. if (!$i) {
  1691. $totalarray['nbfield']++;
  1692. }
  1693. }
  1694. // Payment mode
  1695. if (!empty($arrayfields['f.fk_mode_reglement']['checked'])) {
  1696. $s = $form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1, 0, '', 1);
  1697. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($s).'">';
  1698. print dol_escape_htmltag($s);
  1699. print '</td>';
  1700. if (!$i) {
  1701. $totalarray['nbfield']++;
  1702. }
  1703. }
  1704. // Amount HT
  1705. if (!empty($arrayfields['f.total_ht']['checked'])) {
  1706. print '<td class="right nowrap"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
  1707. if (!$i) {
  1708. $totalarray['nbfield']++;
  1709. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ht';
  1710. }
  1711. $totalarray['val']['f.total_ht'] += $obj->total_ht;
  1712. }
  1713. // Amount VAT
  1714. if (!empty($arrayfields['f.total_vat']['checked'])) {
  1715. print '<td class="right nowrap"><span class="amount">'.price($obj->total_vat)."</span></td>\n";
  1716. if (!$i) {
  1717. $totalarray['nbfield']++;
  1718. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_vat';
  1719. }
  1720. $totalarray['val']['f.total_vat'] += $obj->total_vat;
  1721. }
  1722. // Amount LocalTax1
  1723. if (!empty($arrayfields['f.total_localtax1']['checked'])) {
  1724. print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax1)."</span></td>\n";
  1725. if (!$i) {
  1726. $totalarray['nbfield']++;
  1727. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax1';
  1728. }
  1729. $totalarray['val']['f.total_localtax1'] += $obj->total_localtax1;
  1730. }
  1731. // Amount LocalTax2
  1732. if (!empty($arrayfields['f.total_localtax2']['checked'])) {
  1733. print '<td class="right nowrap"><span class="amount">'.price($obj->total_localtax2)."</span></td>\n";
  1734. if (!$i) {
  1735. $totalarray['nbfield']++;
  1736. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_localtax2';
  1737. }
  1738. $totalarray['val']['f.total_localtax2'] += $obj->total_localtax2;
  1739. }
  1740. // Amount TTC
  1741. if (!empty($arrayfields['f.total_ttc']['checked'])) {
  1742. print '<td class="right nowrap"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
  1743. if (!$i) {
  1744. $totalarray['nbfield']++;
  1745. $totalarray['pos'][$totalarray['nbfield']] = 'f.total_ttc';
  1746. }
  1747. $totalarray['val']['f.total_ttc'] += $obj->total_ttc;
  1748. }
  1749. // Number of attached documents
  1750. if (!empty($arrayfields['f.nb_docs']['checked'])) {
  1751. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  1752. require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
  1753. $upload_dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($facturestatic->id, 2, 0, 0, $facturestatic, 'invoice_supplier').$facturestatic->ref;
  1754. $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
  1755. $nbLinks = Link::count($db, $facturestatic->element, $facturestatic->id);
  1756. $nbTotal = $nbFiles + $nbLinks;
  1757. echo '<td class="center">'.(empty($nbTotal) ? '' : $nbTotal).'</td>';
  1758. if (!$i) {
  1759. $totalarray['nbfield']++;
  1760. }
  1761. }
  1762. // Author
  1763. if (!empty($arrayfields['u.login']['checked'])) {
  1764. print '<td class="tdoverflowmax125">';
  1765. if ($userstatic->id) {
  1766. print $userstatic->getNomUrl(-1);
  1767. } else {
  1768. print '&nbsp;';
  1769. }
  1770. print "</td>\n";
  1771. if (!$i) {
  1772. $totalarray['nbfield']++;
  1773. }
  1774. }
  1775. if (!empty($arrayfields['dynamount_payed']['checked'])) {
  1776. print '<td class="right nowrap"><span class="amount">'.(!empty($totalpay) ? price($totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
  1777. if (!$i) {
  1778. $totalarray['nbfield']++;
  1779. $totalarray['pos'][$totalarray['nbfield']] = 'totalam';
  1780. }
  1781. $totalarray['val']['totalam'] += $totalpay;
  1782. }
  1783. if (!empty($arrayfields['rtp']['checked'])) {
  1784. print '<td class="right nowrap">'.(!empty($remaintopay) ? price($remaintopay, 0, $langs) : '&nbsp;').'</td>'; // TODO Use a denormalized field
  1785. if (!$i) {
  1786. $totalarray['nbfield']++;
  1787. $totalarray['pos'][$totalarray['nbfield']] = 'rtp';
  1788. }
  1789. $totalarray['val']['rtp'] += $remaintopay;
  1790. }
  1791. // Currency
  1792. if (!empty($arrayfields['f.multicurrency_code']['checked'])) {
  1793. print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
  1794. if (!$i) {
  1795. $totalarray['nbfield']++;
  1796. }
  1797. }
  1798. // Currency rate
  1799. if (!empty($arrayfields['f.multicurrency_tx']['checked'])) {
  1800. print '<td class="nowrap">';
  1801. $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
  1802. print "</td>\n";
  1803. if (!$i) {
  1804. $totalarray['nbfield']++;
  1805. }
  1806. }
  1807. // Amount HT
  1808. if (!empty($arrayfields['f.multicurrency_total_ht']['checked'])) {
  1809. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
  1810. if (!$i) {
  1811. $totalarray['nbfield']++;
  1812. }
  1813. }
  1814. // Amount VAT
  1815. if (!empty($arrayfields['f.multicurrency_total_vat']['checked'])) {
  1816. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_vat)."</span></td>\n";
  1817. if (!$i) {
  1818. $totalarray['nbfield']++;
  1819. }
  1820. }
  1821. // Amount TTC
  1822. if (!empty($arrayfields['f.multicurrency_total_ttc']['checked'])) {
  1823. print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
  1824. if (!$i) {
  1825. $totalarray['nbfield']++;
  1826. }
  1827. }
  1828. if (!empty($arrayfields['multicurrency_dynamount_payed']['checked'])) {
  1829. print '<td class="right nowrap"><span class="amount">'.(!empty($multicurrency_totalpay) ? price($multicurrency_totalpay, 0, $langs) : '').'</span></td>'; // TODO Use a denormalized field
  1830. if (!$i) {
  1831. $totalarray['nbfield']++;
  1832. }
  1833. }
  1834. // Pending amount
  1835. if (!empty($arrayfields['multicurrency_rtp']['checked'])) {
  1836. print '<td class="right nowrap"><span class="amount">';
  1837. print(!empty($multicurrency_remaintopay) ? price($multicurrency_remaintopay, 0, $langs) : '');
  1838. print '</span></td>'; // TODO Use a denormalized field
  1839. if (!$i) {
  1840. $totalarray['nbfield']++;
  1841. }
  1842. }
  1843. // Extra fields
  1844. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1845. // Fields from hook
  1846. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1847. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1848. print $hookmanager->resPrint;
  1849. // Date creation
  1850. if (!empty($arrayfields['f.datec']['checked'])) {
  1851. print '<td class="center nowraponll">';
  1852. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1853. print '</td>';
  1854. if (!$i) {
  1855. $totalarray['nbfield']++;
  1856. }
  1857. }
  1858. // Date modification
  1859. if (!empty($arrayfields['f.tms']['checked'])) {
  1860. print '<td class="center nowraponall">';
  1861. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1862. print '</td>';
  1863. if (!$i) {
  1864. $totalarray['nbfield']++;
  1865. }
  1866. }
  1867. // Status
  1868. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  1869. print '<td class="center nowrap">';
  1870. print $facturestatic->getLibStatut(5, $paiement);
  1871. print "</td>";
  1872. if (!$i) {
  1873. $totalarray['nbfield']++;
  1874. }
  1875. }
  1876. // Action column
  1877. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1878. print '<td class="nowrap center">';
  1879. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1880. $selected = 0;
  1881. if (in_array($obj->facid, $arrayofselected)) {
  1882. $selected = 1;
  1883. }
  1884. print '<input id="cb'.$obj->facid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->facid.'"'.($selected ? ' checked="checked"' : '').'>';
  1885. }
  1886. print '</td>';
  1887. if (!$i) {
  1888. $totalarray['nbfield']++;
  1889. }
  1890. }
  1891. print '</tr>'."\n";
  1892. }
  1893. $i++;
  1894. }
  1895. // Show total line
  1896. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1897. // If no record found
  1898. if ($num == 0) {
  1899. $colspan = 1;
  1900. foreach ($arrayfields as $key => $val) {
  1901. if (!empty($val['checked'])) {
  1902. $colspan++;
  1903. }
  1904. }
  1905. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1906. }
  1907. $db->free($resql);
  1908. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  1909. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1910. print $hookmanager->resPrint;
  1911. print '</table>'."\n";
  1912. print '</div>'."\n";
  1913. print '</form>'."\n";
  1914. if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  1915. $hidegeneratedfilelistifempty = 1;
  1916. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1917. $hidegeneratedfilelistifempty = 0;
  1918. }
  1919. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  1920. $formfile = new FormFile($db);
  1921. // Show list of available documents
  1922. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1923. $urlsource .= str_replace('&amp;', '&', $param);
  1924. $filedir = $diroutputmassaction;
  1925. $genallowed = $permissiontoread;
  1926. $delallowed = $permissiontoadd;
  1927. $title = '';
  1928. print $formfile->showdocuments('massfilesarea_supplier_invoice', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1929. }
  1930. // End of page
  1931. llxFooter();
  1932. $db->close();