price.php 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  7. * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
  8. * Copyright (C) 2014-2018 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2014-2019 Philippe Grand <philippe.grand@atoo-net.com>
  10. * Copyright (C) 2014 Ion agorria <ion@agorria.com>
  11. * Copyright (C) 2015-2023 Alexandre Spangaro <aspangaro@open-dsi.fr>
  12. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  13. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  14. * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
  15. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  29. */
  30. /**
  31. * \file htdocs/product/price.php
  32. * \ingroup product
  33. * \brief Page to show product prices
  34. */
  35. // Load Dolibarr environment
  36. require '../main.inc.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_expression.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
  42. if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
  43. require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
  44. $prodcustprice = new ProductCustomerPrice($db);
  45. }
  46. // Load translation files required by the page
  47. $langs->loadLangs(array('products', 'bills', 'companies', 'other'));
  48. $error = 0;
  49. $errors = array();
  50. $id = GETPOST('id', 'int');
  51. $ref = GETPOST('ref', 'alpha');
  52. $action = GETPOST('action', 'aZ09');
  53. $cancel = GETPOST('cancel', 'alpha');
  54. $eid = GETPOST('eid', 'int');
  55. $search_soc = GETPOST('search_soc');
  56. // Security check
  57. $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
  58. $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
  59. if ($user->socid) {
  60. $socid = $user->socid;
  61. }
  62. $object = new Product($db);
  63. if ($id > 0 || !empty($ref)) {
  64. $object->fetch($id, $ref);
  65. }
  66. // Clean param
  67. if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !getDolGlobalString('PRODUIT_MULTIPRICES_LIMIT')) {
  68. $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
  69. }
  70. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  71. $hookmanager->initHooks(array('productpricecard', 'globalcard'));
  72. if ($object->id > 0) {
  73. if ($object->type == $object::TYPE_PRODUCT) {
  74. restrictedArea($user, 'produit', $object->id, 'product&product', '', '');
  75. }
  76. if ($object->type == $object::TYPE_SERVICE) {
  77. restrictedArea($user, 'service', $object->id, 'product&product', '', '');
  78. }
  79. } else {
  80. restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
  81. }
  82. /*
  83. * Actions
  84. */
  85. if ($cancel) {
  86. $action = '';
  87. }
  88. $parameters = array('id'=>$id, 'ref'=>$ref);
  89. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  90. if ($reshook < 0) {
  91. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  92. }
  93. if (empty($reshook)) {
  94. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  95. $search_soc = '';
  96. }
  97. if ($action == 'setlabelsellingprice' && $user->admin) {
  98. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  99. $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.GETPOST('pricelevel');
  100. dolibarr_set_const($db, $keyforlabel, GETPOST('labelsellingprice', 'alpha'), 'chaine', 0, '', $conf->entity);
  101. $action = '';
  102. }
  103. if (($action == 'update_vat') && !$cancel && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  104. $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
  105. // We must define tva_tx, npr and local taxes
  106. $tva_tx = $tva_tx_txt;
  107. $reg = array();
  108. $vatratecode = '';
  109. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  110. $vatratecode = $reg[1];
  111. $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
  112. }
  113. $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot
  114. $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
  115. $localtax1 = 0;
  116. $localtax2 = 0;
  117. $localtax1_type = '0';
  118. $localtax2_type = '0';
  119. // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
  120. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  121. // We look into database using code (we can't use get_localtax() because it depends on buyer that is not known). Same in create product.
  122. $vatratecode = $reg[1];
  123. // Get record from code
  124. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  125. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  126. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  127. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  128. $sql .= " AND t.code = '".$db->escape($vatratecode)."'";
  129. $sql .= " AND t.entity IN (".getEntity('c_tva').")";
  130. $resql = $db->query($sql);
  131. if ($resql) {
  132. $obj = $db->fetch_object($resql);
  133. if ($obj) {
  134. $npr = $obj->recuperableonly;
  135. $localtax1 = $obj->localtax1;
  136. $localtax2 = $obj->localtax2;
  137. $localtax1_type = $obj->localtax1_type;
  138. $localtax2_type = $obj->localtax2_type;
  139. }
  140. }
  141. } else {
  142. // Get record with empty code
  143. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  144. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  145. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  146. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  147. $sql .= " AND t.code = ''";
  148. $sql .= " AND t.entity IN (".getEntity('c_tva').")";
  149. $resql = $db->query($sql);
  150. if ($resql) {
  151. $obj = $db->fetch_object($resql);
  152. if ($obj) {
  153. $npr = $obj->recuperableonly;
  154. $localtax1 = $obj->localtax1;
  155. $localtax2 = $obj->localtax2;
  156. $localtax1_type = $obj->localtax1_type;
  157. $localtax2_type = $obj->localtax2_type;
  158. }
  159. }
  160. }
  161. $object->default_vat_code = $vatratecode;
  162. $object->tva_tx = $tva_tx;
  163. $object->tva_npr = $npr;
  164. $object->localtax1_tx = $localtax1;
  165. $object->localtax2_tx = $localtax2;
  166. $object->localtax1_type = $localtax1_type;
  167. $object->localtax2_type = $localtax2_type;
  168. $db->begin();
  169. $resql = $object->update($object->id, $user);
  170. if ($resql <= 0) {
  171. $error++;
  172. setEventMessages($object->error, $object->errors, 'errors');
  173. }
  174. if (!$error) {
  175. if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  176. for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
  177. // Force the update of the price of the product using the new VAT
  178. if ($object->multiprices_base_type[$i] == 'HT') {
  179. $oldprice = $object->multiprices[$i];
  180. $oldminprice = $object->multiprices_min[$i];
  181. } else {
  182. $oldprice = $object->multiprices_ttc[$i];
  183. $oldminprice = $object->multiprices_min_ttc[$i];
  184. }
  185. $oldpricebasetype = $object->multiprices_base_type[$i];
  186. $oldnpr = $object->multiprices_recuperableonly[$i];
  187. //$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2);
  188. $localtaxarray = array(); // We do not store localtaxes into product, we will use instead the "vat code" to retrieve them.
  189. $level = $i;
  190. $ret = $object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode);
  191. if ($ret < 0) {
  192. $error++;
  193. setEventMessages($object->error, $object->errors, 'errors');
  194. }
  195. }
  196. } else {
  197. // Force the update of the price of the product using the new VAT
  198. if ($object->price_base_type == 'HT') {
  199. $oldprice = $object->price;
  200. $oldminprice = $object->price_min;
  201. } else {
  202. $oldprice = $object->price_ttc;
  203. $oldminprice = $object->price_min_ttc;
  204. }
  205. $oldpricebasetype = $object->price_base_type;
  206. $oldnpr = $object->tva_npr;
  207. //$localtaxarray=array('0'=>$localtax1_type,'1'=>$localtax1,'2'=>$localtax2_type,'3'=>$localtax2);
  208. $localtaxarray = array(); // We do not store localtaxes into product, we will use instead the "vat code" to retrieve them when required.
  209. $level = 0;
  210. $ret = $object->updatePrice($oldprice, $oldpricebasetype, $user, $tva_tx, $oldminprice, $level, $oldnpr, 0, 0, $localtaxarray, $vatratecode);
  211. if ($ret < 0) {
  212. $error++;
  213. setEventMessages($object->error, $object->errors, 'errors');
  214. }
  215. }
  216. }
  217. if (!$error) {
  218. $db->commit();
  219. } else {
  220. $db->rollback();
  221. }
  222. $action = '';
  223. }
  224. if (($action == 'update_price') && !$cancel && $object->getRights()->creer) {
  225. $error = 0;
  226. $pricestoupdate = array();
  227. $psq = GETPOST('psqflag');
  228. $psq = empty($newpsq) ? 0 : $newpsq;
  229. $maxpricesupplier = $object->min_recommended_price();
  230. if (isModEnabled('dynamicprices')) {
  231. $object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression
  232. if ($object->fk_price_expression != 0) {
  233. //Check the expression validity by parsing it
  234. require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php';
  235. $priceparser = new PriceParser($db);
  236. if ($priceparser->parseProduct($object) < 0) {
  237. $error++;
  238. setEventMessages($priceparser->translatedError(), null, 'errors');
  239. }
  240. }
  241. }
  242. // Multiprices
  243. if (!$error && (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
  244. $newprice = GETPOST('price', 'array');
  245. $newprice_min = GETPOST('price_min', 'array');
  246. $newpricebase = GETPOST('multiprices_base_type', 'array');
  247. $newvattx = GETPOST('tva_tx', 'array');
  248. $newvatnpr = GETPOST('tva_npr', 'array');
  249. $newlocaltax1_tx = GETPOST('localtax1_tx', 'array');
  250. $newlocaltax1_type = GETPOST('localtax1_type', 'array');
  251. $newlocaltax2_tx = GETPOST('localtax2_tx', 'array');
  252. $newlocaltax2_type = GETPOST('localtax2_type', 'array');
  253. //Shall we generate prices using price rules?
  254. $object->price_autogen = GETPOST('usePriceRules') == 'on';
  255. for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
  256. if (!isset($newprice[$i])) {
  257. continue;
  258. }
  259. $tva_tx_txt = $newvattx[$i];
  260. $tva_tx = $tva_tx_txt;
  261. $vatratecode = '';
  262. $reg = array();
  263. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  264. $vat_src_code = $reg[1];
  265. $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
  266. }
  267. $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot
  268. $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
  269. $localtax1 = $newlocaltax1_tx[$i];
  270. $localtax1_type = $newlocaltax1_type[$i];
  271. $localtax2 = $newlocaltax2_tx[$i];
  272. $localtax2_type = $newlocaltax2_type[$i];
  273. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  274. // We look into database using code
  275. $vatratecode = $reg[1];
  276. // Get record from code
  277. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  278. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  279. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  280. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  281. $sql .= " AND t.code ='".$db->escape($vatratecode)."'";
  282. $sql .= " AND t.entity IN (".getEntity('c_tva').")";
  283. $resql = $db->query($sql);
  284. if ($resql) {
  285. $obj = $db->fetch_object($resql);
  286. if ($obj) {
  287. $npr = $obj->recuperableonly;
  288. $localtax1 = $obj->localtax1;
  289. $localtax2 = $obj->localtax2;
  290. $localtax1_type = $obj->localtax1_type;
  291. $localtax2_type = $obj->localtax2_type;
  292. }
  293. // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
  294. if (in_array($mysoc->country_code, array('ES'))) {
  295. $localtax1 = get_localtax($tva_tx, 1);
  296. $localtax2 = get_localtax($tva_tx, 2);
  297. }
  298. }
  299. } else {
  300. // Get record with empty code
  301. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  302. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  303. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  304. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  305. $sql .= " AND t.code = ''";
  306. $resql = $db->query($sql);
  307. if ($resql) {
  308. $obj = $db->fetch_object($resql);
  309. if ($obj) {
  310. $npr = $obj->recuperableonly;
  311. $localtax1 = $obj->localtax1;
  312. $localtax2 = $obj->localtax2;
  313. $localtax1_type = $obj->localtax1_type;
  314. $localtax2_type = $obj->localtax2_type;
  315. }
  316. }
  317. }
  318. $pricestoupdate[$i] = array(
  319. 'price' => price2num($newprice[$i], '', 2),
  320. 'price_min' => price2num($newprice_min[$i], '', 2),
  321. 'price_base_type' => $newpricebase[$i],
  322. 'default_vat_code' => $vatratecode,
  323. 'vat_tx' => $tva_tx, // default_vat_code should be used in priority in a future
  324. 'npr' => $npr, // default_vat_code should be used in priority in a future
  325. 'localtaxes_array' => array('0'=>$localtax1_type, '1'=>$localtax1, '2'=>$localtax2_type, '3'=>$localtax2) // default_vat_code should be used in priority in a future
  326. );
  327. //If autogeneration is enabled, then we only set the first level
  328. if ($object->price_autogen) {
  329. break;
  330. }
  331. }
  332. } elseif (!$error) {
  333. $newprice = price2num(GETPOST('price', 'alpha'), '', 2);
  334. $newprice_min = price2num(GETPOST('price_min', 'alpha'), '', 2);
  335. $newpricebase = GETPOST('price_base_type', 'alpha');
  336. $tva_tx_txt = GETPOST('tva_tx', 'alpha'); // tva_tx can be '8.5' or '8.5*' or '8.5 (XXX)' or '8.5* (XXX)'
  337. $tva_tx = $tva_tx_txt;
  338. $vatratecode = '';
  339. $reg = array();
  340. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  341. $vat_src_code = $reg[1];
  342. $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
  343. }
  344. $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot
  345. $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
  346. $localtax1 = 0;
  347. $localtax2 = 0;
  348. $localtax1_type = '0';
  349. $localtax2_type = '0';
  350. // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
  351. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  352. // We look into database using code
  353. $vatratecode = $reg[1];
  354. // Get record from code
  355. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  356. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  357. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  358. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  359. $sql .= " AND t.code ='".$db->escape($vatratecode)."'";
  360. $sql .= " AND t.entity IN (".getEntity('c_tva').")";
  361. $resql = $db->query($sql);
  362. if ($resql) {
  363. $obj = $db->fetch_object($resql);
  364. if ($obj) {
  365. $npr = $obj->recuperableonly;
  366. $localtax1 = $obj->localtax1;
  367. $localtax2 = $obj->localtax2;
  368. $localtax1_type = $obj->localtax1_type;
  369. $localtax2_type = $obj->localtax2_type;
  370. }
  371. // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
  372. if (in_array($mysoc->country_code, array('ES'))) {
  373. $localtax1 = get_localtax($tva_tx, 1);
  374. $localtax2 = get_localtax($tva_tx, 2);
  375. }
  376. }
  377. } else {
  378. // Get record with empty code
  379. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  380. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  381. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  382. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  383. $sql .= " AND t.code = ''";
  384. $resql = $db->query($sql);
  385. if ($resql) {
  386. $obj = $db->fetch_object($resql);
  387. if ($obj) {
  388. $npr = $obj->recuperableonly;
  389. $localtax1 = $obj->localtax1;
  390. $localtax2 = $obj->localtax2;
  391. $localtax1_type = $obj->localtax1_type;
  392. $localtax2_type = $obj->localtax2_type;
  393. }
  394. }
  395. }
  396. $pricestoupdate[0] = array(
  397. 'price' => $newprice,
  398. 'price_min' => $newprice_min,
  399. 'price_base_type' => $newpricebase,
  400. 'default_vat_code' => $vatratecode,
  401. 'vat_tx' => $tva_tx, // default_vat_code should be used in priority in a future
  402. 'npr' => $npr, // default_vat_code should be used in priority in a future
  403. 'localtaxes_array' => array('0'=>$localtax1_type, '1'=>$localtax1, '2'=>$localtax2_type, '3'=>$localtax2) // default_vat_code should be used in priority in a future
  404. );
  405. }
  406. if (!$error) {
  407. $db->begin();
  408. foreach ($pricestoupdate as $key => $val) {
  409. $newprice = $val['price'];
  410. if ($val['price'] < $val['price_min'] && !empty($object->fk_price_expression)) {
  411. $newprice = $val['price_min']; //Set price same as min, the user will not see the
  412. }
  413. $newprice = price2num($newprice, 'MU');
  414. $newprice_min = price2num($val['price_min'], 'MU');
  415. $newvattx = price2num($val['vat_tx']);
  416. if (getDolGlobalString('PRODUCT_MINIMUM_RECOMMENDED_PRICE') && $newprice_min < $maxpricesupplier) {
  417. setEventMessages($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, - 1, - 1, 'auto')), null, 'errors');
  418. $error++;
  419. break;
  420. }
  421. // If price has changed, we update it
  422. if (!array_key_exists($key, $object->multiprices) || $object->multiprices[$key] != $newprice || $object->multiprices_min[$key] != $newprice_min || $object->multiprices_base_type[$key] != $val['price_base_type'] || $object->multiprices_tva_tx[$key] != $newvattx) {
  423. $res = $object->updatePrice($newprice, $val['price_base_type'], $user, $val['vat_tx'], $newprice_min, $key, $val['npr'], $psq, 0, $val['localtaxes_array'], $val['default_vat_code']);
  424. } else {
  425. $res = 0;
  426. }
  427. if ($res < 0) {
  428. $error++;
  429. setEventMessages($object->error, $object->errors, 'errors');
  430. break;
  431. }
  432. }
  433. }
  434. if (!$error && $object->update($object->id, $user) < 0) {
  435. $error++;
  436. setEventMessages($object->error, $object->errors, 'errors');
  437. }
  438. if (empty($error)) {
  439. $action = '';
  440. setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
  441. $db->commit();
  442. } else {
  443. $action = 'edit_price';
  444. $db->rollback();
  445. }
  446. }
  447. if ($action == 'delete' && $user->hasRight('produit', 'supprimer')) {
  448. $result = $object->log_price_delete($user, GETPOST('lineid', 'int'));
  449. if ($result < 0) {
  450. setEventMessages($object->error, $object->errors, 'errors');
  451. }
  452. }
  453. // Set Price by quantity
  454. if ($action == 'activate_price_by_qty') {
  455. // Activating product price by quantity add a new price line with price_by_qty set to 1
  456. $level = GETPOST('level', 'int');
  457. $ret = $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1);
  458. if ($ret < 0) {
  459. setEventMessages($object->error, $object->errors, 'errors');
  460. }
  461. }
  462. // Unset Price by quantity
  463. if ($action == 'disable_price_by_qty') {
  464. // Disabling product price by quantity add a new price line with price_by_qty set to 0
  465. $level = GETPOST('level', 'int');
  466. $ret = $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 0);
  467. if ($ret < 0) {
  468. setEventMessages($object->error, $object->errors, 'errors');
  469. }
  470. }
  471. if ($action == 'edit_price_by_qty') { // Edition d'un prix par quantité
  472. $rowid = GETPOST('rowid', 'int');
  473. }
  474. // Add or update price by quantity
  475. if ($action == 'update_price_by_qty') {
  476. // Récupération des variables
  477. $rowid = GETPOST('rowid', 'int');
  478. $priceid = GETPOST('priceid', 'int');
  479. $newprice = price2num(GETPOST("price"), 'MU', 2);
  480. // $newminprice=price2num(GETPOST("price_min"),'MU'); // TODO : Add min price management
  481. $quantity = price2num(GETPOST('quantity'), 'MS', 2);
  482. $remise_percent = price2num(GETPOST('remise_percent'), '', 2);
  483. $remise = 0; // TODO : allow discount by amount when available on documents
  484. if (empty($quantity)) {
  485. $error++;
  486. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Qty")), null, 'errors');
  487. }
  488. if (empty($newprice)) {
  489. $error++;
  490. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Price")), null, 'errors');
  491. }
  492. if (!$error) {
  493. // Calcul du prix HT et du prix unitaire
  494. if ($object->price_base_type == 'TTC') {
  495. $price = price2num($newprice) / (1 + ($object->tva_tx / 100));
  496. }
  497. $price = price2num($newprice, 'MU');
  498. $unitPrice = price2num($price / $quantity, 'MU');
  499. // Ajout / mise à jour
  500. if ($rowid > 0) {
  501. $sql = "UPDATE ".MAIN_DB_PREFIX."product_price_by_qty SET";
  502. $sql .= " price=".((float) $price).",";
  503. $sql .= " unitprice=".((float) $unitPrice).",";
  504. $sql .= " quantity=".((float) $quantity).",";
  505. $sql .= " remise_percent=".((float) $remise_percent).",";
  506. $sql .= " remise=".((float) $remise);
  507. $sql .= " WHERE rowid = ".((int) $rowid);
  508. $result = $db->query($sql);
  509. if (!$result) {
  510. dol_print_error($db);
  511. }
  512. } else {
  513. $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_price_by_qty (fk_product_price,price,unitprice,quantity,remise_percent,remise) values (";
  514. $sql .= ((int) $priceid).','.((float) $price).','.((float) $unitPrice).','.((float) $quantity).','.((float) $remise_percent).','.((float) $remise).')';
  515. $result = $db->query($sql);
  516. if (!$result) {
  517. if ($db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  518. setEventMessages($langs->trans("DuplicateRecord"), null, 'errors');
  519. } else {
  520. dol_print_error($db);
  521. }
  522. }
  523. }
  524. }
  525. }
  526. if ($action == 'delete_price_by_qty') {
  527. $rowid = GETPOST('rowid', 'int');
  528. if (!empty($rowid)) {
  529. $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty";
  530. $sql .= " WHERE rowid = ".((int) $rowid);
  531. $result = $db->query($sql);
  532. } else {
  533. setEventMessages(('delete_price_by_qty'.$langs->transnoentities('MissingIds')), null, 'errors');
  534. }
  535. }
  536. if ($action == 'delete_all_price_by_qty') {
  537. $priceid = GETPOST('priceid', 'int');
  538. if (!empty($rowid)) {
  539. $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price_by_qty";
  540. $sql .= " WHERE fk_product_price = ".((int) $priceid);
  541. $result = $db->query($sql);
  542. } else {
  543. setEventMessages(('delete_price_by_qty'.$langs->transnoentities('MissingIds')), null, 'errors');
  544. }
  545. }
  546. /**
  547. * ***************************************************
  548. * Price by customer
  549. * ****************************************************
  550. */
  551. if ($action == 'add_customer_price_confirm' && !$cancel && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  552. $maxpricesupplier = $object->min_recommended_price();
  553. $update_child_soc = GETPOST('updatechildprice', 'int');
  554. // add price by customer
  555. $prodcustprice->fk_soc = GETPOST('socid', 'int');
  556. $prodcustprice->ref_customer = GETPOST('ref_customer', 'alpha');
  557. $prodcustprice->fk_product = $object->id;
  558. $prodcustprice->price = price2num(GETPOST("price"), 'MU');
  559. $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU');
  560. $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha');
  561. $tva_tx_txt = GETPOST("tva_tx", 'alpha');
  562. $tva_tx = $tva_tx_txt;
  563. $vatratecode = '';
  564. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  565. $vat_src_code = $reg[1];
  566. $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
  567. }
  568. $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot
  569. $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
  570. $localtax1 = 0;
  571. $localtax2 = 0;
  572. $localtax1_type = '0';
  573. $localtax2_type = '0';
  574. // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
  575. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  576. // We look into database using code
  577. $vatratecode = $reg[1];
  578. // Get record from code
  579. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  580. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  581. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  582. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  583. $sql .= " AND t.code ='".$db->escape($vatratecode)."'";
  584. $sql .= " AND t.entity IN (".getEntity('c_tva').")";
  585. $resql = $db->query($sql);
  586. if ($resql) {
  587. $obj = $db->fetch_object($resql);
  588. if ($obj) {
  589. $npr = $obj->recuperableonly;
  590. $localtax1 = $obj->localtax1;
  591. $localtax2 = $obj->localtax2;
  592. $localtax1_type = $obj->localtax1_type;
  593. $localtax2_type = $obj->localtax2_type;
  594. }
  595. // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
  596. if (in_array($mysoc->country_code, array('ES'))) {
  597. $localtax1 = get_localtax($tva_tx, 1);
  598. $localtax2 = get_localtax($tva_tx, 2);
  599. }
  600. }
  601. } else {
  602. // Get record with empty code
  603. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  604. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  605. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  606. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  607. $sql .= " AND t.code = ''";
  608. $resql = $db->query($sql);
  609. if ($resql) {
  610. $obj = $db->fetch_object($resql);
  611. if ($obj) {
  612. $npr = $obj->recuperableonly;
  613. $localtax1 = $obj->localtax1;
  614. $localtax2 = $obj->localtax2;
  615. $localtax1_type = $obj->localtax1_type;
  616. $localtax2_type = $obj->localtax2_type;
  617. }
  618. }
  619. }
  620. $prodcustprice->default_vat_code = $vatratecode;
  621. $prodcustprice->tva_tx = $tva_tx;
  622. $prodcustprice->recuperableonly = $npr;
  623. $prodcustprice->localtax1_tx = $localtax1;
  624. $prodcustprice->localtax2_tx = $localtax2;
  625. $prodcustprice->localtax1_type = $localtax1_type;
  626. $prodcustprice->localtax2_type = $localtax2_type;
  627. if (!($prodcustprice->fk_soc > 0)) {
  628. $langs->load("errors");
  629. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty")), null, 'errors');
  630. $error++;
  631. $action = 'add_customer_price';
  632. }
  633. if (getDolGlobalString('PRODUCT_MINIMUM_RECOMMENDED_PRICE') && $prodcustprice->price_min < $maxpricesupplier) {
  634. $langs->load("errors");
  635. setEventMessages($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')), null, 'errors');
  636. $error++;
  637. $action = 'add_customer_price';
  638. }
  639. if (!$error) {
  640. $result = $prodcustprice->create($user, 0, $update_child_soc);
  641. if ($result < 0) {
  642. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  643. } else {
  644. setEventMessages($langs->trans('RecordSaved'), null, 'mesgs');
  645. }
  646. $action = '';
  647. }
  648. }
  649. if ($action == 'delete_customer_price' && ($user->hasRight('produit', 'supprimer') || $user->hasRight('service', 'supprimer'))) {
  650. // Delete price by customer
  651. $prodcustprice->id = GETPOST('lineid', 'int');
  652. $result = $prodcustprice->delete($user);
  653. if ($result < 0) {
  654. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  655. } else {
  656. setEventMessages($langs->trans('RecordDeleted'), null, 'mesgs');
  657. }
  658. $action = '';
  659. }
  660. if ($action == 'update_customer_price_confirm' && !$cancel && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  661. $maxpricesupplier = $object->min_recommended_price();
  662. $update_child_soc = GETPOST('updatechildprice', 'int');
  663. $prodcustprice->fetch(GETPOST('lineid', 'int'));
  664. // update price by customer
  665. $prodcustprice->ref_customer = GETPOST('ref_customer', 'alpha');
  666. $prodcustprice->price = price2num(GETPOST("price"), 'MU');
  667. $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU');
  668. $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha');
  669. $tva_tx_txt = GETPOST("tva_tx");
  670. $tva_tx = $tva_tx_txt;
  671. $vatratecode = '';
  672. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  673. $vat_src_code = $reg[1];
  674. $tva_tx = preg_replace('/\s*\(.*\)/', '', $tva_tx_txt); // Remove code into vatrate.
  675. }
  676. $tva_tx = price2num(preg_replace('/\*/', '', $tva_tx)); // keep remove all after the numbers and dot
  677. $npr = preg_match('/\*/', $tva_tx_txt) ? 1 : 0;
  678. $localtax1 = 0;
  679. $localtax2 = 0;
  680. $localtax1_type = '0';
  681. $localtax2_type = '0';
  682. // If value contains the unique code of vat line (new recommanded method), we use it to find npr and local taxes
  683. if (preg_match('/\((.*)\)/', $tva_tx_txt, $reg)) {
  684. // We look into database using code
  685. $vatratecode = $reg[1];
  686. // Get record from code
  687. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  688. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  689. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  690. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  691. $sql .= " AND t.code ='".$db->escape($vatratecode)."'";
  692. $sql .= " AND t.entity IN (".getEntity('c_tva').")";
  693. $resql = $db->query($sql);
  694. if ($resql) {
  695. $obj = $db->fetch_object($resql);
  696. if ($obj) {
  697. $npr = $obj->recuperableonly;
  698. $localtax1 = $obj->localtax1;
  699. $localtax2 = $obj->localtax2;
  700. $localtax1_type = $obj->localtax1_type;
  701. $localtax2_type = $obj->localtax2_type;
  702. }
  703. // If spain, we don't use the localtax found into tax record in database with same code, but using the get_localtax rule.
  704. if (in_array($mysoc->country_code, array('ES'))) {
  705. $localtax1 = get_localtax($tva_tx, 1);
  706. $localtax2 = get_localtax($tva_tx, 2);
  707. }
  708. }
  709. } else {
  710. // Get record with empty code
  711. $sql = "SELECT t.rowid, t.code, t.recuperableonly, t.localtax1, t.localtax2, t.localtax1_type, t.localtax2_type";
  712. $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
  713. $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$db->escape($mysoc->country_code)."'";
  714. $sql .= " AND t.taux = ".((float) $tva_tx)." AND t.active = 1";
  715. $sql .= " AND t.code = ''";
  716. $resql = $db->query($sql);
  717. if ($resql) {
  718. $obj = $db->fetch_object($resql);
  719. if ($obj) {
  720. $npr = $obj->recuperableonly;
  721. $localtax1 = $obj->localtax1;
  722. $localtax2 = $obj->localtax2;
  723. $localtax1_type = $obj->localtax1_type;
  724. $localtax2_type = $obj->localtax2_type;
  725. }
  726. }
  727. }
  728. $prodcustprice->default_vat_code = $vatratecode;
  729. $prodcustprice->tva_tx = $tva_tx;
  730. $prodcustprice->recuperableonly = $npr;
  731. $prodcustprice->localtax1_tx = $localtax1;
  732. $prodcustprice->localtax2_tx = $localtax2;
  733. $prodcustprice->localtax1_type = $localtax1_type;
  734. $prodcustprice->localtax2_type = $localtax2_type;
  735. if ($prodcustprice->price_min < $maxpricesupplier && getDolGlobalString('PRODUCT_MINIMUM_RECOMMENDED_PRICE')) {
  736. setEventMessages($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')), null, 'errors');
  737. $error++;
  738. $action = 'update_customer_price';
  739. }
  740. if (!$error) {
  741. $result = $prodcustprice->update($user, 0, $update_child_soc);
  742. if ($result < 0) {
  743. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  744. } else {
  745. setEventMessages($langs->trans("Save"), null, 'mesgs');
  746. }
  747. $action = '';
  748. }
  749. }
  750. }
  751. /*
  752. * View
  753. */
  754. $form = new Form($db);
  755. if (!empty($id) || !empty($ref)) {
  756. // fetch updated prices
  757. $object->fetch($id, $ref);
  758. }
  759. $title = $langs->trans('ProductServiceCard');
  760. $helpurl = '';
  761. $shortlabel = dol_trunc($object->label, 16);
  762. if (GETPOST("type") == '0' || ($object->type == Product::TYPE_PRODUCT)) {
  763. $title = $langs->trans('Product')." ".$shortlabel." - ".$langs->trans('SellingPrices');
  764. $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
  765. }
  766. if (GETPOST("type") == '1' || ($object->type == Product::TYPE_SERVICE)) {
  767. $title = $langs->trans('Service')." ".$shortlabel." - ".$langs->trans('SellingPrices');
  768. $helpurl = 'EN:Module_Services_En|FR:Module_Services|ES:M&oacute;dulo_Servicios';
  769. }
  770. llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'classforhorizontalscrolloftabs');
  771. $head = product_prepare_head($object);
  772. $titre = $langs->trans("CardProduct".$object->type);
  773. $picto = ($object->type == Product::TYPE_SERVICE ? 'service' : 'product');
  774. print dol_get_fiche_head($head, 'price', $titre, -1, $picto);
  775. $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  776. $object->next_prev_filter = "fk_product_type = ".((int) $object->type);
  777. $shownav = 1;
  778. if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
  779. $shownav = 0;
  780. }
  781. dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
  782. print '<div class="fichecenter">';
  783. print '<div class="underbanner clearboth"></div>';
  784. print '<table class="border tableforfield centpercent">';
  785. // Price per customer segment/level
  786. if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  787. // Price and min price are variable (depends on level of company).
  788. if (!empty($socid)) {
  789. $soc = new Societe($db);
  790. $soc->id = $socid;
  791. $soc->fetch($socid);
  792. // Type
  793. if (isModEnabled("product") && isModEnabled("service")) {
  794. $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
  795. print '<tr><td class="">';
  796. print (!getDolGlobalString('PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans('Type');
  797. print '</td><td>';
  798. print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat);
  799. print '</td></tr>';
  800. }
  801. // Selling price
  802. print '<tr><td class="titlefieldcreate">';
  803. print $langs->trans("SellingPrice");
  804. print '</td>';
  805. print '<td colspan="2">';
  806. if ($object->multiprices_base_type[$soc->price_level] == 'TTC') {
  807. print '<span class="amount">'.price($object->multiprices_ttc[$soc->price_level]).'</span>';
  808. } else {
  809. print '<span class="amount">'.price($object->multiprices[$soc->price_level]).'</span>';
  810. }
  811. if ($object->multiprices_base_type[$soc->price_level]) {
  812. print ' '.$langs->trans($object->multiprices_base_type[$soc->price_level]);
  813. } else {
  814. print ' '.$langs->trans($object->price_base_type);
  815. }
  816. print '</td></tr>';
  817. // Price min
  818. print '<tr><td>'.$langs->trans("MinPrice").'</td><td colspan="2">';
  819. if ($object->multiprices_base_type[$soc->price_level] == 'TTC') {
  820. print price($object->multiprices_min_ttc[$soc->price_level]).' '.$langs->trans($object->multiprices_base_type[$soc->price_level]);
  821. } else {
  822. print price($object->multiprices_min[$soc->price_level]).' '.$langs->trans(empty($object->multiprices_base_type[$soc->price_level]) ? 'HT' : $object->multiprices_base_type[$soc->price_level]);
  823. }
  824. print '</td></tr>';
  825. if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) { // using this option is a bug. kept for backward compatibility
  826. // TVA
  827. print '<tr><td>'.$langs->trans("DefaultTaxRate").'</td><td colspan="2">';
  828. $positiverates = '';
  829. if (price2num($object->multiprices_tva_tx[$soc->price_level])) {
  830. $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_tva_tx[$soc->price_level]);
  831. }
  832. if (price2num($object->multiprices_localtax1_type[$soc->price_level])) {
  833. $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_localtax1_tx[$soc->price_level]);
  834. }
  835. if (price2num($object->multiprices_localtax2_type[$soc->price_level])) {
  836. $positiverates .= ($positiverates ? '/' : '').price2num($object->multiprices_localtax2_tx[$soc->price_level]);
  837. }
  838. if (empty($positiverates)) {
  839. $positiverates = '0';
  840. }
  841. echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr);
  842. //print vatrate($object->multiprices_tva_tx[$soc->price_level], true);
  843. print '</td></tr>';
  844. } else {
  845. // TVA
  846. print '<tr><td>'.$langs->trans("DefaultTaxRate").'</td><td>';
  847. $positiverates = '';
  848. if (price2num($object->tva_tx)) {
  849. $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx);
  850. }
  851. if (price2num($object->localtax1_type)) {
  852. $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx);
  853. }
  854. if (price2num($object->localtax2_type)) {
  855. $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx);
  856. }
  857. if (empty($positiverates)) {
  858. $positiverates = '0';
  859. }
  860. echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr);
  861. /*
  862. if ($object->default_vat_code)
  863. {
  864. print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')';
  865. }
  866. else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/
  867. print '</td></tr>';
  868. }
  869. } else {
  870. if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) { // using this option is a bug. kept for backward compatibility
  871. // Type
  872. if (isModEnabled("product") && isModEnabled("service")) {
  873. $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
  874. print '<tr><td class="">';
  875. print (!getDolGlobalString('PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans('Type');
  876. print '</td><td>';
  877. print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat);
  878. print '</td></tr>';
  879. }
  880. // We show only vat for level 1
  881. print '<tr><td class="titlefieldcreate">'.$langs->trans("DefaultTaxRate").'</td>';
  882. print '<td colspan="2">'.vatrate($object->multiprices_tva_tx[1], true).'</td>';
  883. print '</tr>';
  884. } else {
  885. // Type
  886. if (isModEnabled("product") && isModEnabled("service")) {
  887. $typeformat = 'select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service");
  888. print '<tr><td class="">';
  889. print (!getDolGlobalString('PRODUCT_DENY_CHANGE_PRODUCT_TYPE')) ? $form->editfieldkey("Type", 'fk_product_type', $object->type, $object, 0, $typeformat) : $langs->trans('Type');
  890. print '</td><td>';
  891. print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, 0, $typeformat);
  892. print '</td></tr>';
  893. }
  894. // TVA
  895. print '<!-- Default VAT Rate -->';
  896. print '<tr><td class="titlefieldcreate">'.$langs->trans("DefaultTaxRate").'</td><td>';
  897. // TODO We show localtax from $object, but this properties may not be correct. Only value $object->default_vat_code is guaranted.
  898. $positiverates = '';
  899. if (price2num($object->tva_tx)) {
  900. $positiverates .= ($positiverates ? '<span class="opacitymedium">/</span>' : '').price2num($object->tva_tx);
  901. }
  902. if (price2num($object->localtax1_type)) {
  903. $positiverates .= ($positiverates ? '<span class="opacitymedium">/</span>' : '').price2num($object->localtax1_tx);
  904. }
  905. if (price2num($object->localtax2_type)) {
  906. $positiverates .= ($positiverates ? '<span class="opacitymedium">/</span>' : '').price2num($object->localtax2_tx);
  907. }
  908. if (empty($positiverates)) {
  909. $positiverates = '0';
  910. }
  911. print vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), true, $object->tva_npr, 1);
  912. /*
  913. if ($object->default_vat_code)
  914. {
  915. print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')';
  916. }
  917. else print vatrate($object->tva_tx . ($object->tva_npr ? '*' : ''), true);*/
  918. print '</td></tr>';
  919. }
  920. print '</table>';
  921. print '<br>';
  922. print '<table class="noborder tableforfield centpercent">';
  923. print '<tr class="liste_titre"><td>';
  924. print $langs->trans("PriceLevel");
  925. if ($user->admin) {
  926. print ' <a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editlabelsellingprice&token='.newToken().'&pricelevel='.$i.'&id='.$object->id.'">'.img_edit($langs->trans('EditSellingPriceLabel'), 0).'</a>';
  927. }
  928. print '</td>';
  929. print '<td style="text-align: right">'.$langs->trans("SellingPrice").'</td>';
  930. print '<td style="text-align: right">'.$langs->trans("MinPrice").'</td>';
  931. print '</tr>';
  932. for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
  933. print '<tr class="oddeven">';
  934. // Label of price
  935. print '<td>';
  936. $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$i;
  937. if (preg_match('/editlabelsellingprice/', $action)) {
  938. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">';
  939. print '<input type="hidden" name="token" value="'.newToken().'">';
  940. print '<input type="hidden" name="action" value="setlabelsellingprice">';
  941. print '<input type="hidden" name="pricelevel" value="'.$i.'">';
  942. print $langs->trans("SellingPrice").' '.$i.' - ';
  943. print '<input class="maxwidthonsmartphone" type="text" name="labelsellingprice" value="' . getDolGlobalString($keyforlabel).'">';
  944. print '&nbsp;<input type="submit" class="button smallpaddingimp" value="'.$langs->trans("Modify").'">';
  945. print '</form>';
  946. } else {
  947. print $langs->trans("SellingPrice").' '.$i;
  948. if (!empty($conf->global->$keyforlabel)) {
  949. print ' - '.$langs->trans($conf->global->$keyforlabel);
  950. }
  951. }
  952. print '</td>';
  953. if ($object->multiprices_base_type [$i] == 'TTC') {
  954. print '<td class="right"><span class="amount">'.price($object->multiprices_ttc[$i]);
  955. } else {
  956. print '<td class="right"><span class="amount">'.price($object->multiprices[$i]);
  957. }
  958. if ($object->multiprices_base_type[$i]) {
  959. print ' '.$langs->trans($object->multiprices_base_type [$i]).'</span></td>';
  960. } else {
  961. print ' '.$langs->trans($object->price_base_type).'</span></td>';
  962. }
  963. // Prix min
  964. print '<td style="text-align: right">';
  965. if (empty($object->multiprices_base_type[$i])) {
  966. $object->multiprices_base_type[$i] = "HT";
  967. }
  968. if ($object->multiprices_base_type[$i] == 'TTC') {
  969. print price($object->multiprices_min_ttc[$i]).' '.$langs->trans($object->multiprices_base_type[$i]);
  970. } else {
  971. print price($object->multiprices_min[$i]).' '.$langs->trans($object->multiprices_base_type[$i]);
  972. }
  973. print '</td></tr>';
  974. // Price by quantity
  975. if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) { // TODO Fix the form included into a tr instead of a td
  976. print '<tr><td>'.$langs->trans("PriceByQuantity").' '.$i;
  977. if (!empty($conf->global->$keyforlabel)) {
  978. print ' - '.$langs->trans($conf->global->$keyforlabel);
  979. }
  980. print '</td><td colspan="2">';
  981. if ($object->prices_by_qty[$i] == 1) {
  982. print '<table width="50%" class="border" summary="List of quantities">';
  983. print '<tr class="liste_titre">';
  984. print '<td>'.$langs->trans("PriceByQuantityRange").' '.$i.'</td>';
  985. print '<td class="right">'.$langs->trans("HT").'</td>';
  986. print '<td class="right">'.$langs->trans("UnitPrice").'</td>';
  987. print '<td class="right">'.$langs->trans("Discount").'</td>';
  988. print '<td>&nbsp;</td>';
  989. print '</tr>';
  990. foreach ($object->prices_by_qty_list[$i] as $ii => $prices) {
  991. if ($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  992. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  993. print '<input type="hidden" name="token" value="'.newToken().'">';
  994. print '<input type="hidden" name="action" value="update_price_by_qty">';
  995. print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].'">';
  996. print '<input type="hidden" value="'.$prices['rowid'].'" name="rowid">';
  997. print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
  998. print '<td><input size="5" type="text" value="'.$prices['quantity'].'" name="quantity"></td>';
  999. print '<td class="right" colspan="2"><input size="10" type="text" value="'.price2num($prices['price'], 'MU').'" name="price">&nbsp;'.$object->price_base_type.'</td>';
  1000. print '<td class="right nowraponall"><input size="5" type="text" value="'.$prices['remise_percent'].'" name="remise_percent"> %</td>';
  1001. print '<td class="center"><input type="submit" value="'.$langs->trans("Modify").'" class="button"></td>';
  1002. print '</tr>';
  1003. print '</form>';
  1004. } else {
  1005. print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
  1006. print '<td>'.$prices['quantity'].'</td>';
  1007. print '<td class="right">'.price($prices['price']).'</td>';
  1008. print '<td class="right">'.price($prices['unitprice']).'</td>';
  1009. print '<td class="right">'.price($prices['remise_percent']).' %</td>';
  1010. print '<td class="center">';
  1011. if (($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  1012. print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit_price_by_qty&token='.newToken().'&rowid='.$prices["rowid"].'">';
  1013. print img_edit().'</a>';
  1014. print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_price_by_qty&token='.newToken().'&rowid='.$prices["rowid"].'">';
  1015. print img_delete().'</a>';
  1016. } else {
  1017. print '&nbsp;';
  1018. }
  1019. print '</td>';
  1020. print '</tr>';
  1021. }
  1022. }
  1023. if ($action != 'edit_price_by_qty' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  1024. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  1025. print '<input type="hidden" name="token" value="'.newToken().'">';
  1026. print '<input type="hidden" name="action" value="update_price_by_qty">';
  1027. print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[$i].'">'; // id in product_price
  1028. print '<input type="hidden" value="0" name="rowid">'; // id in product_price
  1029. print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
  1030. print '<td><input size="5" type="text" value="1" name="quantity"></td>';
  1031. print '<td class="right" class="nowrap"><input size="10" type="text" value="0" name="price">&nbsp;'.$object->price_base_type.'</td>';
  1032. print '<td class="right">&nbsp;</td>';
  1033. print '<td class="right" class="nowraponall"><input size="5" type="text" value="0" name="remise_percent"> %</td>';
  1034. print '<td class="center"><input type="submit" value="'.$langs->trans("Add").'" class="button"></td>';
  1035. print '</tr>';
  1036. print '</form>';
  1037. }
  1038. print '</table>';
  1039. print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable_price_by_qty&level='.$i.'&token='.newToken().'">('.$langs->trans("DisablePriceByQty").')</a>';
  1040. } else {
  1041. print $langs->trans("No");
  1042. print '&nbsp; <a class="marginleftonly marginrightonly" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=activate_price_by_qty&level='.$i.'&token='.newToken().'">('.$langs->trans("Activate").')</a>';
  1043. }
  1044. print '</td></tr>';
  1045. }
  1046. }
  1047. }
  1048. } else {
  1049. // TVA
  1050. print '<tr><td class="titlefield">'.$langs->trans("DefaultTaxRate").'</td><td>';
  1051. $positiverates = '';
  1052. if (price2num($object->tva_tx)) {
  1053. $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx);
  1054. }
  1055. if (price2num($object->localtax1_type)) {
  1056. $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx);
  1057. }
  1058. if (price2num($object->localtax2_type)) {
  1059. $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx);
  1060. }
  1061. if (empty($positiverates)) {
  1062. $positiverates = '0';
  1063. }
  1064. echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr, 0, 1);
  1065. /*
  1066. if ($object->default_vat_code)
  1067. {
  1068. print vatrate($object->tva_tx, true) . ' ('.$object->default_vat_code.')';
  1069. }
  1070. else print vatrate($object->tva_tx, true, $object->tva_npr, true);*/
  1071. print '</td></tr>';
  1072. // Price
  1073. print '<tr class="field_selling_price"><td>'.$langs->trans("SellingPrice").'</td><td>';
  1074. if ($object->price_base_type == 'TTC') {
  1075. print price($object->price_ttc).' '.$langs->trans($object->price_base_type);
  1076. } else {
  1077. print price($object->price).' '.$langs->trans($object->price_base_type);
  1078. if (getDolGlobalString('PRODUCT_DISPLAY_VAT_INCL_PRICES') && !empty($object->price_ttc)) {
  1079. print '<i class="opacitymedium"> - ' . price($object->price_ttc).' '.$langs->trans('TTC') . '</i>';
  1080. }
  1081. }
  1082. print '</td></tr>';
  1083. // Price minimum
  1084. print '<tr class="field_min_price"><td>'.$langs->trans("MinPrice").'</td><td>';
  1085. if ($object->price_base_type == 'TTC') {
  1086. print price($object->price_min_ttc).' '.$langs->trans($object->price_base_type);
  1087. } else {
  1088. print price($object->price_min).' '.$langs->trans($object->price_base_type);
  1089. if (getDolGlobalString('PRODUCT_DISPLAY_VAT_INCL_PRICES') && !empty($object->price_min_ttc)) {
  1090. print '<i class="opacitymedium"> - ' . price($object->price_min_ttc).' '.$langs->trans('TTC') . '</i>';
  1091. }
  1092. }
  1093. print '</td></tr>';
  1094. // Price by quantity
  1095. if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) { // TODO Fix the form inside tr instead of td
  1096. print '<tr><td>'.$langs->trans("PriceByQuantity");
  1097. if ($object->prices_by_qty[0] == 0) {
  1098. print '&nbsp; <a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=activate_price_by_qty&level=1&token='.newToken().'">('.$langs->trans("Activate").')';
  1099. } else {
  1100. print '&nbsp; <a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=disable_price_by_qty&level=1&token='.newToken().'">('.$langs->trans("DisablePriceByQty").')';
  1101. }
  1102. print '</td><td>';
  1103. if ($object->prices_by_qty[0] == 1) {
  1104. print '<table width="50%" class="border" summary="List of quantities">';
  1105. print '<tr class="liste_titre">';
  1106. //print '<td>' . $langs->trans("PriceByQuantityRange") . '</td>';
  1107. print '<td>'.$langs->trans("Quantity").'</td>';
  1108. print '<td class="right">'.$langs->trans("Price").'</td>';
  1109. print '<td class="right"></td>';
  1110. print '<td class="right">'.$langs->trans("UnitPrice").'</td>';
  1111. print '<td class="right">'.$langs->trans("Discount").'</td>';
  1112. print '<td>&nbsp;</td>';
  1113. print '</tr>';
  1114. if ($action != 'edit_price_by_qty') {
  1115. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">'; // FIXME a form into a table is not allowed
  1116. print '<input type="hidden" name="token" value="'.newToken().'">';
  1117. print '<input type="hidden" name="action" value="update_price_by_qty">';
  1118. print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].'">'; // id in product_price
  1119. print '<input type="hidden" value="0" name="rowid">'; // id in product_price_by_qty
  1120. print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
  1121. print '<td><input size="5" type="text" value="1" name="quantity"></td>';
  1122. print '<td class="right"><input class="width50 right" type="text" value="0" name="price"></td>';
  1123. print '<td>';
  1124. //print $object->price_base_type;
  1125. print '</td>';
  1126. print '<td class="right">&nbsp;</td>';
  1127. print '<td class="right nowraponall"><input type="text" class="width50 right" value="0" name="remise_percent"> %</td>';
  1128. print '<td class="center"><input type="submit" value="'.$langs->trans("Add").'" class="button"></td>';
  1129. print '</tr>';
  1130. print '</form>';
  1131. }
  1132. foreach ($object->prices_by_qty_list[0] as $ii => $prices) {
  1133. if ($action == 'edit_price_by_qty' && $rowid == $prices['rowid'] && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  1134. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  1135. print '<input type="hidden" name="token" value="'.newToken().'">';
  1136. print '<input type="hidden" name="action" value="update_price_by_qty">';
  1137. print '<input type="hidden" name="priceid" value="'.$object->prices_by_qty_id[0].'">'; // id in product_price
  1138. print '<input type="hidden" value="'.$prices['rowid'].'" name="rowid">'; // id in product_price_by_qty
  1139. print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
  1140. print '<td><input size="5" type="text" value="'.$prices['quantity'].'" name="quantity"></td>';
  1141. print '<td class="right"><input class="width50 right" type="text" value="'.price2num($prices['price'], 'MU').'" name="price"></td>';
  1142. print '<td class="right">';
  1143. //print $object->price_base_type;
  1144. print $prices['price_base_type'];
  1145. print '</td>';
  1146. print '<td class="right">&nbsp;</td>';
  1147. print '<td class="right nowraponall"><input class="width50 right" type="text" value="'.$prices['remise_percent'].'" name="remise_percent"> %</td>';
  1148. print '<td class="center"><input type="submit" value="'.$langs->trans("Modify").'" class="button"></td>';
  1149. print '</tr>';
  1150. print '</form>';
  1151. } else {
  1152. print '<tr class="'.($ii % 2 == 0 ? 'pair' : 'impair').'">';
  1153. print '<td>'.$prices['quantity'].'</td>';
  1154. print '<td class="right">'.price($prices['price']).'</td>';
  1155. print '<td class="right">';
  1156. //print $object->price_base_type;
  1157. print $prices['price_base_type'];
  1158. print '</td>';
  1159. print '<td class="right">'.price($prices['unitprice']).'</td>';
  1160. print '<td class="right">'.price($prices['remise_percent']).' %</td>';
  1161. print '<td class="center">';
  1162. if (($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  1163. print '<a class="editfielda marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=edit_price_by_qty&token='.newToken().'&rowid='.$prices["rowid"].'">';
  1164. print img_edit().'</a>';
  1165. print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_price_by_qty&token='.newToken().'&rowid='.$prices["rowid"].'">';
  1166. print img_delete().'</a>';
  1167. } else {
  1168. print '&nbsp;';
  1169. }
  1170. print '</td>';
  1171. print '</tr>';
  1172. }
  1173. }
  1174. print '</table>';
  1175. } else {
  1176. print $langs->trans("No");
  1177. }
  1178. print '</td></tr>';
  1179. }
  1180. }
  1181. print "</table>\n";
  1182. print '</div>';
  1183. print '<div class="clearboth"></div>';
  1184. print dol_get_fiche_end();
  1185. /*
  1186. * Action bar
  1187. */
  1188. if (!$action || $action == 'delete' || $action == 'showlog_customer_price' || $action == 'showlog_default_price' || $action == 'add_customer_price'
  1189. || $action == 'activate_price_by_qty' || $action == 'disable_price_by_qty') {
  1190. print "\n".'<div class="tabsAction">'."\n";
  1191. $parameters = array();
  1192. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1193. if (empty($reshook)) {
  1194. if ($object->isVariant()) {
  1195. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  1196. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag($langs->trans("NoEditVariants")) . '">' . $langs->trans("UpdateDefaultPrice") . '</a></div>';
  1197. }
  1198. } else {
  1199. if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  1200. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  1201. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_price&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("UpdateDefaultPrice") . '</a></div>';
  1202. } else {
  1203. print '<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">' . $langs->trans("UpdateDefaultPrice") . '</span></div>';
  1204. }
  1205. }
  1206. if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
  1207. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  1208. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=add_customer_price&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("AddCustomerPrice") . '</a></div>';
  1209. } else {
  1210. print '<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">' . $langs->trans("AddCustomerPrice") . '</span></div>';
  1211. }
  1212. }
  1213. if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  1214. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  1215. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_vat&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("UpdateVAT") . '</a></div>';
  1216. } else {
  1217. print '<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">' . $langs->trans("UpdateVAT") . '</span></div>';
  1218. }
  1219. if ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer')) {
  1220. print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER['PHP_SELF'] . '?action=edit_price&token='.newToken().'&id=' . $object->id . '">' . $langs->trans("UpdateLevelPrices") . '</a></div>';
  1221. } else {
  1222. print '<div class="inline-block divButAction"><span class="butActionRefused" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">' . $langs->trans("UpdateLevelPrices") . '</span></div>';
  1223. }
  1224. }
  1225. }
  1226. }
  1227. print "\n</div>\n";
  1228. }
  1229. /*
  1230. * Edit price area
  1231. */
  1232. if ($action == 'edit_vat' && ($user->hasRight('produit', 'creer') || $user->hasRight('service', 'creer'))) {
  1233. print load_fiche_titre($langs->trans("UpdateVAT"), '');
  1234. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  1235. print '<input type="hidden" name="token" value="'.newToken().'">';
  1236. print '<input type="hidden" name="action" value="update_vat">';
  1237. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1238. print dol_get_fiche_head('');
  1239. print '<table class="border centpercent">';
  1240. // VAT
  1241. print '<tr><td>'.$langs->trans("DefaultTaxRate").'</td><td>';
  1242. print $form->load_tva("tva_tx", $object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1);
  1243. print '</td></tr>';
  1244. print '</table>';
  1245. print dol_get_fiche_end();
  1246. print $form->buttonsSaveCancel();
  1247. print '<br></form><br>';
  1248. }
  1249. if ($action == 'edit_price' && $object->getRights()->creer) {
  1250. print '<br>';
  1251. print load_fiche_titre($langs->trans("NewPrice"), '');
  1252. if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  1253. print '<!-- Edit price -->'."\n";
  1254. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  1255. print '<input type="hidden" name="token" value="'.newToken().'">';
  1256. print '<input type="hidden" name="action" value="update_price">';
  1257. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1258. print dol_get_fiche_head('');
  1259. print '<div class="div-table-responsive-no-min">';
  1260. print '<table class="border centpercent">';
  1261. // VAT
  1262. print '<tr><td class="titlefield">'.$langs->trans("DefaultTaxRate").'</td><td>';
  1263. print $form->load_tva("tva_tx", $object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1);
  1264. print '</td></tr>';
  1265. // Price base
  1266. print '<tr><td>';
  1267. print $langs->trans('PriceBase');
  1268. print '</td>';
  1269. print '<td>';
  1270. print $form->selectPriceBaseType($object->price_base_type, "price_base_type");
  1271. print '</td>';
  1272. print '</tr>';
  1273. // Only show price mode and expression selector if module is enabled
  1274. if (!empty($conf->dynamicprices->enabled)) {
  1275. // Price mode selector
  1276. print '<!-- Show price mode of dynamicprices editor -->'."\n";
  1277. print '<tr><td>'.$langs->trans("PriceMode").'</td><td>';
  1278. print img_picto('', 'dynamicprice', 'class="pictofixedwidth"');
  1279. $price_expression = new PriceExpression($db);
  1280. $price_expression_list = array(0 => $langs->trans("Numeric").' <span class="opacitymedium">('.$langs->trans("NoDynamicPrice").')</span>'); //Put the numeric mode as first option
  1281. foreach ($price_expression->list_price_expression() as $entry) {
  1282. $price_expression_list[$entry->id] = $entry->title;
  1283. }
  1284. $price_expression_preselection = GETPOST('eid') ? GETPOST('eid') : ($object->fk_price_expression ? $object->fk_price_expression : '0');
  1285. print $form->selectarray('eid', $price_expression_list, $price_expression_preselection);
  1286. print '&nbsp; <a id="expression_editor" class="classlink">'.$langs->trans("PriceExpressionEditor").'</a>';
  1287. print '</td></tr>';
  1288. // This code hides the numeric price input if is not selected, loads the editor page if editor button is pressed
  1289. ?>
  1290. <script type="text/javascript">
  1291. jQuery(document).ready(function() {
  1292. jQuery("#expression_editor").click(function() {
  1293. window.location = "<?php echo DOL_URL_ROOT ?>/product/dynamic_price/editor.php?id=<?php echo $id ?>&tab=price&eid=" + $("#eid").val();
  1294. });
  1295. jQuery("#eid").change(on_change);
  1296. on_change();
  1297. });
  1298. function on_change() {
  1299. if ($("#eid").val() == 0) {
  1300. jQuery("#price_numeric").show();
  1301. } else {
  1302. jQuery("#price_numeric").hide();
  1303. }
  1304. }
  1305. </script>
  1306. <?php
  1307. }
  1308. // Price
  1309. $product = new Product($db);
  1310. $product->fetch($id, $ref, '', 1); //Ignore the math expression when getting the price
  1311. print '<tr id="price_numeric"><td>';
  1312. $text = $langs->trans('SellingPrice');
  1313. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  1314. print '</td><td>';
  1315. if ($object->price_base_type == 'TTC') {
  1316. print '<input name="price" size="10" value="'.price($product->price_ttc).'">';
  1317. } else {
  1318. print '<input name="price" size="10" value="'.price($product->price).'">';
  1319. }
  1320. print '</td></tr>';
  1321. // Price minimum
  1322. print '<tr><td>';
  1323. $text = $langs->trans('MinPrice');
  1324. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  1325. print '</td><td>';
  1326. if ($object->price_base_type == 'TTC') {
  1327. print '<input name="price_min" size="10" value="'.price($object->price_min_ttc).'">';
  1328. } else {
  1329. print '<input name="price_min" size="10" value="'.price($object->price_min).'">';
  1330. }
  1331. if (getDolGlobalString('PRODUCT_MINIMUM_RECOMMENDED_PRICE')) {
  1332. print ' &nbsp; '.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'</td>';
  1333. }
  1334. print '</td>';
  1335. print '</tr>';
  1336. $parameters = array();
  1337. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1338. print '</table>';
  1339. print '</div>';
  1340. print dol_get_fiche_end();
  1341. print $form->buttonsSaveCancel();
  1342. print '</form>';
  1343. } else {
  1344. print '<!-- Edit price per level -->'."\n"; ?>
  1345. <script>
  1346. var showHidePriceRules = function () {
  1347. var otherPrices = $('div.fiche form table tbody tr:not(:first)');
  1348. var minPrice1 = $('div.fiche form input[name="price_min[1]"]');
  1349. if (jQuery('input#usePriceRules').prop('checked')) {
  1350. otherPrices.hide();
  1351. minPrice1.hide();
  1352. } else {
  1353. otherPrices.show();
  1354. minPrice1.show();
  1355. }
  1356. }
  1357. jQuery(document).ready(function () {
  1358. showHidePriceRules();
  1359. jQuery('input#usePriceRules').click(showHidePriceRules);
  1360. });
  1361. </script>
  1362. <?php
  1363. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  1364. print '<input type="hidden" name="token" value="'.newToken().'">';
  1365. print '<input type="hidden" name="action" value="update_price">';
  1366. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1367. //print dol_get_fiche_head('', '', '', -1);
  1368. if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && getDolGlobalString('PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL')) {
  1369. print $langs->trans('UseMultipriceRules').' <input type="checkbox" id="usePriceRules" name="usePriceRules" '.($object->price_autogen ? 'checked' : '').'><br><br>';
  1370. }
  1371. print '<div class="div-table-responsive-no-min">';
  1372. print '<table class="noborder">';
  1373. print '<thead><tr class="liste_titre">';
  1374. print '<td>'.$langs->trans("PriceLevel").'</td>';
  1375. if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) {
  1376. print '<td style="text-align: center">'.$langs->trans("DefaultTaxRate").'</td>';
  1377. } else {
  1378. print '<td></td>';
  1379. }
  1380. print '<td class="center">'.$langs->trans("SellingPrice").'</td>';
  1381. print '<td class="center">'.$langs->trans("MinPrice").'</td>';
  1382. if (getDolGlobalString('PRODUCT_MINIMUM_RECOMMENDED_PRICE')) {
  1383. print '<td></td>';
  1384. }
  1385. print '</tr></thead>';
  1386. print '<tbody>';
  1387. for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
  1388. print '<tr class="oddeven">';
  1389. print '<td>';
  1390. $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$i;
  1391. $text = $langs->trans('SellingPrice').' '.$i.' - '.getDolGlobalString($keyforlabel);
  1392. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  1393. print '</td>';
  1394. // VAT
  1395. if (!getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) {
  1396. print '<td>';
  1397. print '<input type="hidden" name="tva_tx['.$i.']" value="'.($object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx).'">';
  1398. print '<input type="hidden" name="tva_npr['.$i.']" value="'.$object->tva_npr.'">';
  1399. print '<input type="hidden" name="localtax1_tx['.$i.']" value="'.$object->localtax1_tx.'">';
  1400. print '<input type="hidden" name="localtax1_type['.$i.']" value="'.$object->localtax1_type.'">';
  1401. print '<input type="hidden" name="localtax2_tx['.$i.']" value="'.$object->localtax2_tx.'">';
  1402. print '<input type="hidden" name="localtax2_type['.$i.']" value="'.$object->localtax2_type.'">';
  1403. print '</td>';
  1404. } else {
  1405. // This option is kept for backward compatibility but has no sense
  1406. print '<td style="text-align: center">';
  1407. print $form->load_tva("tva_tx[".$i.']', $object->multiprices_tva_tx[$i], $mysoc, '', $object->id, false, $object->type, false, 1);
  1408. print '</td>';
  1409. }
  1410. // Selling price
  1411. print '<td style="text-align: center">';
  1412. if ($object->multiprices_base_type [$i] == 'TTC') {
  1413. print '<input name="price['.$i.']" size="10" value="'.price($object->multiprices_ttc [$i]).'">';
  1414. } else {
  1415. print '<input name="price['.$i.']" size="10" value="'.price($object->multiprices [$i]).'">';
  1416. }
  1417. print '&nbsp;'.$form->selectPriceBaseType($object->multiprices_base_type [$i], "multiprices_base_type[".$i."]");
  1418. print '</td>';
  1419. // Min price
  1420. print '<td style="text-align: center">';
  1421. if ($object->multiprices_base_type [$i] == 'TTC') {
  1422. print '<input name="price_min['.$i.']" size="10" value="'.price($object->multiprices_min_ttc [$i]).'">';
  1423. } else {
  1424. print '<input name="price_min['.$i.']" size="10" value="'.price($object->multiprices_min [$i]).'">';
  1425. }
  1426. if (getDolGlobalString('PRODUCT_MINIMUM_RECOMMENDED_PRICE')) {
  1427. print '<td class="left">'.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'</td>';
  1428. }
  1429. print '</td>';
  1430. print '</tr>';
  1431. }
  1432. print '</tbody>';
  1433. print '</table>';
  1434. print '</div>';
  1435. //print dol_get_fiche_end();
  1436. print $form->buttonsSaveCancel();
  1437. print '</form>';
  1438. }
  1439. }
  1440. // List of price changes - log historic (ordered by descending date)
  1441. if ((!getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || $action == 'showlog_default_price') && !in_array($action, array('edit_price', 'edit_vat'))) {
  1442. $sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx, p.default_vat_code, p.recuperableonly, p.localtax1_tx, p.localtax1_type, p.localtax2_tx, p.localtax2_type,";
  1443. $sql .= " p.price_level, p.price_min, p.price_min_ttc,p.price_by_qty,";
  1444. $sql .= " p.date_price as dp, p.fk_price_expression, u.rowid as user_id, u.login";
  1445. $sql .= " FROM ".MAIN_DB_PREFIX."product_price as p,";
  1446. $sql .= " ".MAIN_DB_PREFIX."user as u";
  1447. $sql .= " WHERE fk_product = ".((int) $object->id);
  1448. $sql .= " AND p.entity IN (".getEntity('productprice').")";
  1449. $sql .= " AND p.fk_user_author = u.rowid";
  1450. if (!empty($socid) && getDolGlobalString('PRODUIT_MULTIPRICES')) {
  1451. $sql .= " AND p.price_level = ".((int) $soc->price_level);
  1452. }
  1453. $sql .= " ORDER BY p.date_price DESC, p.rowid DESC, p.price_level ASC";
  1454. // $sql .= $db->plimit();
  1455. //print $sql;
  1456. $result = $db->query($sql);
  1457. if ($result) {
  1458. print '<div class="divlogofpreviouscustomerprice">';
  1459. $num = $db->num_rows($result);
  1460. if (!$num) {
  1461. $db->free($result);
  1462. // Il doit au moins y avoir la ligne de prix initial.
  1463. // On l'ajoute donc pour remettre a niveau (pb vieilles versions)
  1464. // We emulate the change of the price from interface with the same value than the one into table llx_product
  1465. if (getDolGlobalString('PRODUIT_MULTIPRICES')) {
  1466. $ret = $object->updatePrice(($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_ttc[1] : $object->multiprices[1]), $object->multiprices_base_type[1], $user, (empty($object->multiprices_tva_tx[1]) ? 0 : $object->multiprices_tva_tx[1]), ($object->multiprices_base_type[1] == 'TTC' ? $object->multiprices_min_ttc[1] : $object->multiprices_min[1]), 1);
  1467. } else {
  1468. $ret = $object->updatePrice(($object->price_base_type == 'TTC' ? $object->price_ttc : $object->price), $object->price_base_type, $user, $object->tva_tx, ($object->price_base_type == 'TTC' ? $object->price_min_ttc : $object->price_min));
  1469. }
  1470. if ($ret < 0) {
  1471. dol_print_error($db, $object->error, $object->errors);
  1472. } else {
  1473. $result = $db->query($sql);
  1474. $num = $db->num_rows($result);
  1475. }
  1476. }
  1477. if ($num > 0) {
  1478. // Default prices or
  1479. // Log of previous customer prices
  1480. $backbutton = '<a class="justalink" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">'.$langs->trans("Back").'</a>';
  1481. if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
  1482. print_barre_liste($langs->trans("DefaultPriceLog"), 0, $_SERVER["PHP_SELF"], '', '', '', $backbutton, 0, $num, 'title_accountancy.png');
  1483. } else {
  1484. print_barre_liste($langs->trans("PriceByCustomerLog"), 0, $_SERVER["PHP_SELF"], '', '', '', '', 0, $num, 'title_accountancy.png');
  1485. }
  1486. print '<!-- List of log prices -->'."\n";
  1487. print '<div class="div-table-responsive">'."\n";
  1488. print '<table class="liste centpercent">'."\n";
  1489. print '<tr class="liste_titre">';
  1490. print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
  1491. if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  1492. print '<td class="center">'.$langs->trans("PriceLevel").'</td>';
  1493. }
  1494. if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  1495. print '<td class="center">'.$langs->trans("Type").'</td>';
  1496. }
  1497. print '<td class="center">'.$langs->trans("PriceBase").'</td>';
  1498. if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  1499. print '<td class="right">'.$langs->trans("DefaultTaxRate").'</td>';
  1500. }
  1501. print '<td class="right">'.$langs->trans("HT").'</td>';
  1502. print '<td class="right">'.$langs->trans("TTC").'</td>';
  1503. if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
  1504. print '<td class="right">'.$langs->trans("INCT").'</td>';
  1505. }
  1506. if (!empty($conf->dynamicprices->enabled)) {
  1507. print '<td class="right">'.$langs->trans("PriceExpressionSelected").'</td>';
  1508. }
  1509. print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
  1510. print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
  1511. print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
  1512. if ($user->hasRight('produit', 'supprimer')) {
  1513. print '<td class="right">&nbsp;</td>';
  1514. }
  1515. print '</tr>';
  1516. $notfirstlineforlevel = array();
  1517. $i = 0;
  1518. while ($i < $num) {
  1519. $objp = $db->fetch_object($result);
  1520. print '<tr class="oddeven">';
  1521. // Date
  1522. print "<td>".dol_print_date($db->jdate($objp->dp), "dayhour", 'tzuserrel')."</td>";
  1523. // Price level
  1524. if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  1525. print '<td class="center">'.$objp->price_level."</td>";
  1526. }
  1527. // Price by quantity
  1528. if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  1529. $type = ($objp->price_by_qty == 1) ? 'PriceByQuantity' : 'Standard';
  1530. print '<td class="center">'.$langs->trans($type)."</td>";
  1531. }
  1532. print '<td class="center">';
  1533. if (empty($objp->price_by_qty)) {
  1534. print $langs->trans($objp->price_base_type);
  1535. }
  1536. print "</td>";
  1537. if (!getDolGlobalString('PRODUIT_MULTIPRICES') && !getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  1538. print '<td class="right">';
  1539. if (empty($objp->price_by_qty)) {
  1540. $positiverates = '';
  1541. if (price2num($objp->tva_tx)) {
  1542. $positiverates .= ($positiverates ? '/' : '').price2num($objp->tva_tx);
  1543. }
  1544. if (price2num($objp->localtax1_type)) {
  1545. $positiverates .= ($positiverates ? '/' : '').price2num($objp->localtax1_tx);
  1546. }
  1547. if (price2num($objp->localtax2_type)) {
  1548. $positiverates .= ($positiverates ? '/' : '').price2num($objp->localtax2_tx);
  1549. }
  1550. if (empty($positiverates)) {
  1551. $positiverates = '0';
  1552. }
  1553. echo vatrate($positiverates.($objp->default_vat_code ? ' ('.$objp->default_vat_code.')' : ''), '%', !empty($objp->tva_npr) ? $objp->tva_npr : 0);
  1554. /*
  1555. if ($objp->default_vat_code)
  1556. {
  1557. print vatrate($objp->tva_tx, true) . ' ('.$objp->default_vat_code.')';
  1558. }
  1559. else print vatrate($objp->tva_tx, true, $objp->recuperableonly);*/
  1560. }
  1561. print "</td>";
  1562. }
  1563. // Line for default price
  1564. if ($objp->price_base_type == 'HT') {
  1565. $pu = $objp->price;
  1566. } else {
  1567. $pu = $objp->price_ttc;
  1568. }
  1569. // Local tax was not saved into table llx_product on old version. So we will use value linked to VAT code.
  1570. $localtaxarray = getLocalTaxesFromRate($objp->tva_tx.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), 0, $mysoc, $mysoc);
  1571. // Define part of HT, VAT, TTC
  1572. $resultarray = calcul_price_total(1, $pu, 0, $objp->tva_tx, 1, 1, 0, $objp->price_base_type, $objp->recuperableonly, $object->type, $mysoc, $localtaxarray);
  1573. // Calcul du total ht sans remise
  1574. $total_ht = $resultarray[0];
  1575. $total_vat = $resultarray[1];
  1576. $total_localtax1 = $resultarray[9];
  1577. $total_localtax2 = $resultarray[10];
  1578. $total_ttc = $resultarray[2];
  1579. // Price
  1580. if (!empty($objp->fk_price_expression) && !empty($conf->dynamicprices->enabled)) {
  1581. $price_expression = new PriceExpression($db);
  1582. $res = $price_expression->fetch($objp->fk_price_expression);
  1583. $title = $price_expression->title;
  1584. print '<td class="right"></td>';
  1585. print '<td class="right"></td>';
  1586. if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
  1587. print '<td class="right"></td>';
  1588. }
  1589. print '<td class="right">'.$title."</td>";
  1590. } else {
  1591. // Price HT
  1592. print '<td class="right">';
  1593. if (empty($objp->price_by_qty)) {
  1594. print '<span class="amount">'.price($objp->price).'</span>';
  1595. }
  1596. print "</td>";
  1597. // Price TTC
  1598. print '<td class="right">';
  1599. if (empty($objp->price_by_qty)) {
  1600. $price_ttc = $objp->price_ttc;
  1601. print '<span class="amount">'.price($price_ttc).'<span>';
  1602. }
  1603. print "</td>";
  1604. if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
  1605. print '<td class="right">';
  1606. print $resultarray[2];
  1607. print '</td>';
  1608. }
  1609. if (!empty($conf->dynamicprices->enabled)) { //Only if module is enabled
  1610. print '<td class="right"></td>';
  1611. }
  1612. }
  1613. // Price min
  1614. print '<td class="right">';
  1615. if (empty($objp->price_by_qty)) {
  1616. print price($objp->price_min);
  1617. }
  1618. print '</td>';
  1619. // Price min inc tax
  1620. print '<td class="right">';
  1621. if (empty($objp->price_by_qty)) {
  1622. $price_min_ttc = $objp->price_min_ttc;
  1623. print price($price_min_ttc);
  1624. }
  1625. print '</td>';
  1626. // User
  1627. print '<td class="right">';
  1628. if ($objp->user_id > 0) {
  1629. $userstatic = new User($db);
  1630. $userstatic->fetch($objp->user_id);
  1631. print $userstatic->getNomUrl(1, '', 0, 0, 24, 0, 'login');
  1632. }
  1633. print '</td>';
  1634. // Action
  1635. if ($user->hasRight('produit', 'supprimer')) {
  1636. $candelete = 0;
  1637. if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
  1638. if (empty($notfirstlineforlevel[$objp->price_level])) {
  1639. $notfirstlineforlevel[$objp->price_level] = 1;
  1640. } else {
  1641. $candelete = 1;
  1642. }
  1643. } elseif ($i > 0) {
  1644. $candelete = 1;
  1645. }
  1646. print '<td class="right">';
  1647. if ($candelete || ($db->jdate($objp->dp) >= dol_now())) { // Test on date is to be able to delete a corrupted record with a date in future
  1648. print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id.'&lineid='.$objp->rowid.'">';
  1649. print img_delete();
  1650. print '</a>';
  1651. } else {
  1652. print '&nbsp;'; // Can not delete last price (it's current price)
  1653. }
  1654. print '</td>';
  1655. }
  1656. print "</tr>\n";
  1657. $i++;
  1658. }
  1659. $db->free($result);
  1660. print "</table>";
  1661. print '</div>';
  1662. print "<br>";
  1663. }
  1664. print '</div>';
  1665. } else {
  1666. dol_print_error($db);
  1667. }
  1668. }
  1669. // Add area to show/add/edit a price for a dedicated customer
  1670. if (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) {
  1671. $prodcustprice = new ProductCustomerPrice($db);
  1672. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  1673. $sortfield = GETPOST('sortfield', 'aZ09comma');
  1674. $sortorder = GETPOST('sortorder', 'aZ09comma');
  1675. $page = (GETPOST("page", 'int') ? GETPOST("page", 'int') : 0);
  1676. if (empty($page) || $page == -1) {
  1677. $page = 0;
  1678. } // If $page is not defined, or '' or -1
  1679. $offset = $limit * $page;
  1680. $pageprev = $page - 1;
  1681. $pagenext = $page + 1;
  1682. if (!$sortorder) {
  1683. $sortorder = "ASC";
  1684. }
  1685. if (!$sortfield) {
  1686. $sortfield = "soc.nom";
  1687. }
  1688. // Build filter to diplay only concerned lines
  1689. $filter = array('t.fk_product' => $object->id);
  1690. if (!empty($search_soc)) {
  1691. $filter['soc.nom'] = $search_soc;
  1692. }
  1693. if ($action == 'add_customer_price') {
  1694. // Form to add a new customer price
  1695. $maxpricesupplier = $object->min_recommended_price();
  1696. print '<!-- add_customer_price -->';
  1697. print load_fiche_titre($langs->trans('AddCustomerPrice'));
  1698. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  1699. print '<input type="hidden" name="token" value="'.newToken().'">';
  1700. print '<input type="hidden" name="action" value="add_customer_price_confirm">';
  1701. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1702. print '<div class="tabBar tabBarWithBottom">';
  1703. print '<table class="border centpercent">';
  1704. print '<tr>';
  1705. print '<td class="fieldrequired">'.$langs->trans('ThirdParty').'</td>';
  1706. print '<td>';
  1707. $filter = '(s.client:IN:1,2,3)';
  1708. print img_picto('', 'company').$form->select_company('', 'socid', $filter, 'SelectThirdParty', 0, 0, array(), 0, 'minwidth300');
  1709. print '</td>';
  1710. print '</tr>';
  1711. // Ref. Customer
  1712. print '<tr><td>' . $langs->trans('RefCustomer') . '</td>';
  1713. print '<td><input name="ref_customer" size="12"></td></tr>';
  1714. // VAT
  1715. print '<tr><td class="fieldrequired">'.$langs->trans("DefaultTaxRate").'</td><td>';
  1716. print $form->load_tva("tva_tx", $object->default_vat_code ? $object->tva_tx.' ('.$object->default_vat_code.')' : $object->tva_tx, $mysoc, '', $object->id, $object->tva_npr, $object->type, false, 1);
  1717. print '</td></tr>';
  1718. // Price base
  1719. print '<tr><td class="fieldrequired">';
  1720. print $langs->trans('PriceBase');
  1721. print '</td>';
  1722. print '<td>';
  1723. print $form->selectPriceBaseType($object->price_base_type, "price_base_type");
  1724. print '</td>';
  1725. print '</tr>';
  1726. // Price
  1727. print '<tr><td class="fieldrequired">';
  1728. $text = $langs->trans('SellingPrice');
  1729. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  1730. print '</td><td>';
  1731. if ($object->price_base_type == 'TTC') {
  1732. print '<input name="price" size="10" value="'.price($object->price_ttc).'">';
  1733. } else {
  1734. print '<input name="price" size="10" value="'.price($object->price).'">';
  1735. }
  1736. print '</td></tr>';
  1737. // Price minimum
  1738. print '<tr><td>';
  1739. $text = $langs->trans('MinPrice');
  1740. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  1741. if ($object->price_base_type == 'TTC') {
  1742. print '<td><input name="price_min" size="10" value="'.price($object->price_min_ttc).'">';
  1743. } else {
  1744. print '<td><input name="price_min" size="10" value="'.price($object->price_min).'">';
  1745. }
  1746. if (getDolGlobalString('PRODUCT_MINIMUM_RECOMMENDED_PRICE')) {
  1747. print '<td class="left">'.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'</td>';
  1748. }
  1749. print '</td></tr>';
  1750. print '</table>';
  1751. print '</div>';
  1752. print '<div class="center">';
  1753. // Update all child soc
  1754. print '<div class="marginbottomonly">';
  1755. print '<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
  1756. print '<label for="updatechildprice">'.$langs->trans('ForceUpdateChildPriceSoc').'</label>';
  1757. print '</div>';
  1758. print $form->buttonsSaveCancel();
  1759. print '</form>';
  1760. } elseif ($action == 'edit_customer_price') {
  1761. // Edit mode
  1762. $maxpricesupplier = $object->min_recommended_price();
  1763. print '<!-- edit_customer_price -->';
  1764. print load_fiche_titre($langs->trans('PriceByCustomer'));
  1765. $result = $prodcustprice->fetch(GETPOST('lineid', 'int'));
  1766. if ($result < 0) {
  1767. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  1768. }
  1769. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  1770. print '<input type="hidden" name="token" value="'.newToken().'">';
  1771. print '<input type="hidden" name="action" value="update_customer_price_confirm">';
  1772. print '<input type="hidden" name="lineid" value="'.$prodcustprice->id.'">';
  1773. print '<table class="liste centpercent">';
  1774. print '<tr>';
  1775. print '<td class="titlefield fieldrequired">'.$langs->trans('ThirdParty').'</td>';
  1776. $staticsoc = new Societe($db);
  1777. $staticsoc->fetch($prodcustprice->fk_soc);
  1778. print "<td>".$staticsoc->getNomUrl(1)."</td>";
  1779. print '</tr>';
  1780. // Ref. Customer
  1781. print '<tr><td>' . $langs->trans('RefCustomer') . '</td>';
  1782. print '<td><input name="ref_customer" size="12" value="' . dol_escape_htmltag($prodcustprice->ref_customer) . '"></td></tr>';
  1783. // VAT
  1784. print '<tr><td class="fieldrequired">'.$langs->trans("DefaultTaxRate").'</td><td>';
  1785. print $form->load_tva("tva_tx", $prodcustprice->default_vat_code ? $prodcustprice->tva_tx.' ('.$prodcustprice->default_vat_code.')' : $prodcustprice->tva_tx, $mysoc, '', $object->id, $prodcustprice->recuperableonly, $object->type, false, 1);
  1786. print '</td></tr>';
  1787. // Price base
  1788. print '<tr><td class="fieldrequired">';
  1789. print $langs->trans('PriceBase');
  1790. print '</td>';
  1791. print '<td>';
  1792. print $form->selectPriceBaseType($prodcustprice->price_base_type, "price_base_type");
  1793. print '</td>';
  1794. print '</tr>';
  1795. // Price
  1796. print '<tr><td class="fieldrequired">';
  1797. $text = $langs->trans('SellingPrice');
  1798. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  1799. print '</td><td>';
  1800. if ($prodcustprice->price_base_type == 'TTC') {
  1801. print '<input name="price" size="10" value="'.price($prodcustprice->price_ttc).'">';
  1802. } else {
  1803. print '<input name="price" size="10" value="'.price($prodcustprice->price).'">';
  1804. }
  1805. print '</td></tr>';
  1806. // Price minimum
  1807. print '<tr><td>';
  1808. $text = $langs->trans('MinPrice');
  1809. print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1);
  1810. print '</td><td>';
  1811. if ($prodcustprice->price_base_type == 'TTC') {
  1812. print '<input name="price_min" size="10" value="'.price($prodcustprice->price_min_ttc).'">';
  1813. } else {
  1814. print '<input name="price_min" size="10" value="'.price($prodcustprice->price_min).'">';
  1815. }
  1816. print '</td>';
  1817. if (getDolGlobalString('PRODUCT_MINIMUM_RECOMMENDED_PRICE')) {
  1818. print '<td class="left">'.$langs->trans("MinimumRecommendedPrice", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')).' '.img_warning().'</td>';
  1819. }
  1820. print '</tr>';
  1821. print '</table>';
  1822. print '<div class="center">';
  1823. print '<div class="marginbottomonly">';
  1824. print '<input type="checkbox" name="updatechildprice" id="updatechildprice" value="1"> ';
  1825. print '<label for="updatechildprice">'.$langs->trans('ForceUpdateChildPriceSoc').'</label>';
  1826. print "</div>";
  1827. print $form->buttonsSaveCancel();
  1828. print '<br></form>';
  1829. } elseif ($action == 'showlog_customer_price') {
  1830. // List of all log of prices by customers
  1831. print '<!-- list of all log of prices per customer -->'."\n";
  1832. $filter = array('t.fk_product' => $object->id, 't.fk_soc' => GETPOST('socid', 'int'));
  1833. // Count total nb of records
  1834. $nbtotalofrecords = '';
  1835. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  1836. $nbtotalofrecords = $prodcustprice->fetchAllLog($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
  1837. }
  1838. $result = $prodcustprice->fetchAllLog($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
  1839. if ($result < 0) {
  1840. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  1841. }
  1842. $option = '&socid='.GETPOST('socid', 'int').'&id='.$object->id;
  1843. $staticsoc = new Societe($db);
  1844. $staticsoc->fetch(GETPOST('socid', 'int'));
  1845. $title = $langs->trans('PriceByCustomerLog');
  1846. $title .= ' - '.$staticsoc->getNomUrl(1);
  1847. $backbutton = '<a class="justalink" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'">'.$langs->trans("Back").'</a>';
  1848. print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $option, $sortfield, $sortorder, $backbutton, count($prodcustprice->lines), $nbtotalofrecords, 'title_accountancy.png');
  1849. if (count($prodcustprice->lines) > 0) {
  1850. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  1851. print '<input type="hidden" name="token" value="'.newToken().'">';
  1852. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1853. print '<div class="div-table-responsive-no-min">';
  1854. print '<table class="liste centpercent">';
  1855. print '<tr class="liste_titre">';
  1856. print '<td>'.$langs->trans("ThirdParty").'</td>';
  1857. print '<td>'.$langs->trans('RefCustomer').'</td>';
  1858. print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
  1859. print '<td class="center">'.$langs->trans("PriceBase").'</td>';
  1860. print '<td class="right">'.$langs->trans("DefaultTaxRate").'</td>';
  1861. print '<td class="right">'.$langs->trans("HT").'</td>';
  1862. print '<td class="right">'.$langs->trans("TTC").'</td>';
  1863. if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
  1864. print '<td class="right">'.$langs->trans("INCT").'</td>';
  1865. }
  1866. print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
  1867. print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
  1868. print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
  1869. print '<td>&nbsp;</td>';
  1870. print '</tr>';
  1871. foreach ($prodcustprice->lines as $line) {
  1872. // Date
  1873. $staticsoc = new Societe($db);
  1874. $staticsoc->fetch($line->fk_soc);
  1875. $tva_tx = $line->default_vat_code ? $line->tva_tx.' ('.$line->default_vat_code.')' : $line->tva_tx;
  1876. // Line for default price
  1877. if ($line->price_base_type == 'HT') {
  1878. $pu = $line->price;
  1879. } else {
  1880. $pu = $line->price_ttc;
  1881. }
  1882. // Local tax is not saved into table of product. We use value linked to VAT code.
  1883. $localtaxarray = getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), 0, $staticsoc, $mysoc);
  1884. // Define part of HT, VAT, TTC
  1885. $resultarray = calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly, $object->type, $mysoc, $localtaxarray);
  1886. // Calcul du total ht sans remise
  1887. $total_ht = $resultarray[0];
  1888. $total_vat = $resultarray[1];
  1889. $total_localtax1 = $resultarray[9];
  1890. $total_localtax2 = $resultarray[10];
  1891. $total_ttc = $resultarray[2];
  1892. print '<tr class="oddeven">';
  1893. print '<td class="tdoverflowmax125">'.$staticsoc->getNomUrl(1)."</td>";
  1894. print '<td>'.$line->ref_customer.'</td>';
  1895. print "<td>".dol_print_date($line->datec, "dayhour", 'tzuserrel')."</td>";
  1896. print '<td class="center">'.$langs->trans($line->price_base_type)."</td>";
  1897. print '<td class="right">';
  1898. $positiverates = '';
  1899. if (price2num($line->tva_tx)) {
  1900. $positiverates .= ($positiverates ? '/' : '').price2num($line->tva_tx);
  1901. }
  1902. if (price2num($line->localtax1_type)) {
  1903. $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax1_tx);
  1904. }
  1905. if (price2num($line->localtax2_type)) {
  1906. $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax2_tx);
  1907. }
  1908. if (empty($positiverates)) {
  1909. $positiverates = '0';
  1910. }
  1911. echo vatrate($positiverates.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), '%', ($line->tva_npr ? $line->tva_npr : $line->recuperableonly));
  1912. //. vatrate($tva_tx, true, $line->recuperableonly) .
  1913. print "</td>";
  1914. print '<td class="right"><span class="amount">'.price($line->price)."</span></td>";
  1915. print '<td class="right"><span class="amount">'.price($line->price_ttc)."</span></td>";
  1916. if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
  1917. print '<td class="right">'.price($resultarray[2]).'</td>';
  1918. }
  1919. print '<td class="right">'.price($line->price_min).'</td>';
  1920. print '<td class="right">'.price($line->price_min_ttc).'</td>';
  1921. // User
  1922. $userstatic = new User($db);
  1923. $userstatic->fetch($line->fk_user);
  1924. print '<td class="right">';
  1925. print $userstatic->getNomUrl(1, '', 0, 0, 24, 0, 'login');
  1926. //print $userstatic->getLoginUrl(1);
  1927. print '</td>';
  1928. print '</tr>';
  1929. }
  1930. print "</table>";
  1931. print '</div>';
  1932. } else {
  1933. print $langs->trans('None');
  1934. }
  1935. } elseif ($action != 'showlog_default_price' && $action != 'edit_price') {
  1936. // List of all prices by customers
  1937. print '<!-- list of all prices per customer -->'."\n";
  1938. // Count total nb of records
  1939. $nbtotalofrecords = '';
  1940. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  1941. $nbtotalofrecords = $prodcustprice->fetchAll($sortorder, $sortfield, 0, 0, $filter);
  1942. }
  1943. $result = $prodcustprice->fetchAll($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
  1944. if ($result < 0) {
  1945. setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors');
  1946. }
  1947. $option = '&search_soc='.$search_soc.'&id='.$object->id;
  1948. print_barre_liste($langs->trans('PriceByCustomer'), $page, $_SERVER ['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords, 'title_accountancy.png');
  1949. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
  1950. print '<input type="hidden" name="token" value="'.newToken().'">';
  1951. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1952. print '<!-- List of prices per customer -->'."\n";
  1953. print '<div class="div-table-responsive-no-min">'."\n";
  1954. print '<table class="liste centpercent">'."\n";
  1955. if (count($prodcustprice->lines) > 0 || $search_soc) {
  1956. $colspan = 9;
  1957. if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
  1958. $colspan++;
  1959. }
  1960. print '<tr class="liste_titre">';
  1961. print '<td class="liste_titre"><input type="text" class="flat maxwidth125" name="search_soc" value="'.$search_soc.'"></td>';
  1962. print '<td class="liste_titre" colspan="'.$colspan.'">&nbsp;</td>';
  1963. // Print the search button
  1964. print '<td class="liste_titre maxwidthsearch">';
  1965. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  1966. print $searchpicto;
  1967. print '</td>';
  1968. print '</tr>';
  1969. }
  1970. print '<tr class="liste_titre">';
  1971. print '<td>'.$langs->trans("ThirdParty").'</td>';
  1972. print '<td>'.$langs->trans('RefCustomer').'</td>';
  1973. print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
  1974. print '<td class="center">'.$langs->trans("PriceBase").'</td>';
  1975. print '<td class="right">'.$langs->trans("DefaultTaxRate").'</td>';
  1976. print '<td class="right">'.$langs->trans("HT").'</td>';
  1977. print '<td class="right">'.$langs->trans("TTC").'</td>';
  1978. if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
  1979. print '<td class="right">'.$langs->trans("INCT").'</td>';
  1980. }
  1981. print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
  1982. print '<td class="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
  1983. print '<td class="right">'.$langs->trans("ChangedBy").'</td>';
  1984. print '<td></td>';
  1985. print '</tr>';
  1986. // Line for default price
  1987. if ($object->price_base_type == 'HT') {
  1988. $pu = $object->price;
  1989. } else {
  1990. $pu = $object->price_ttc;
  1991. }
  1992. // Local tax was not saved into table llx_product on old versions. So we will use the value linked to the VAT code.
  1993. $localtaxarray = getLocalTaxesFromRate($object->tva_tx.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), 0, $mysoc, $mysoc);
  1994. // Define part of HT, VAT, TTC
  1995. $resultarray = calcul_price_total(1, $pu, 0, $object->tva_tx, 1, 1, 0, $object->price_base_type, 0, $object->type, $mysoc, $localtaxarray);
  1996. // Calcul du total ht sans remise
  1997. $total_ht = $resultarray[0];
  1998. $total_vat = $resultarray[1];
  1999. $total_localtax1 = $resultarray[9];
  2000. $total_localtax2 = $resultarray[10];
  2001. $total_ttc = $resultarray[2];
  2002. print '<tr class="oddeven">';
  2003. print '<td colspan="3">' . $langs->trans('Default') . '</td>';
  2004. print '<td class="center">'.$langs->trans($object->price_base_type)."</td>";
  2005. // VAT Rate
  2006. print '<td class="right">';
  2007. $positiverates = '';
  2008. if (price2num($object->tva_tx)) {
  2009. $positiverates .= ($positiverates ? '/' : '').price2num($object->tva_tx);
  2010. }
  2011. if (price2num($object->localtax1_type)) {
  2012. $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax1_tx);
  2013. }
  2014. if (price2num($object->localtax2_type)) {
  2015. $positiverates .= ($positiverates ? '/' : '').price2num($object->localtax2_tx);
  2016. }
  2017. if (empty($positiverates)) {
  2018. $positiverates = '0';
  2019. }
  2020. echo vatrate($positiverates.($object->default_vat_code ? ' ('.$object->default_vat_code.')' : ''), '%', $object->tva_npr);
  2021. //print vatrate($object->tva_tx, true, $object->tva_npr);
  2022. //print $object->default_vat_code?' ('.$object->default_vat_code.')':'';
  2023. print "</td>";
  2024. print '<td class="right"><span class="amount">'.price($object->price)."</span></td>";
  2025. print '<td class="right"><span class="amount">'.price($object->price_ttc)."</span></td>";
  2026. if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
  2027. //print '<td class="right">' . price($object->price_ttc) . "</td>";
  2028. print '<td class="right"><span class="amount">'.price($resultarray[2]).'</span></td>';
  2029. }
  2030. print '<td class="right">'.price($object->price_min).'</td>';
  2031. print '<td class="right">'.price($object->price_min_ttc).'</td>';
  2032. print '<td class="right">';
  2033. print '</td>';
  2034. if ($user->hasRight('produit', 'supprimer') || $user->hasRight('service', 'supprimer')) {
  2035. print '<td class="nowraponall">';
  2036. print '<a class="marginleftonly marginrightonly" href="'.$_SERVER["PHP_SELF"].'?action=showlog_default_price&token='.newToken().'&id='.$object->id.'">';
  2037. print img_info($langs->trans('PriceByCustomerLog'));
  2038. print '</a>';
  2039. print ' ';
  2040. print '<a class="marginleftonly marginrightonly editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit_price&token='.newToken().'&id='.$object->id.'">';
  2041. print img_edit('default', 0, 'style="vertical-align: middle;"');
  2042. print '</a>';
  2043. print '</td>';
  2044. }
  2045. print "</tr>\n";
  2046. if (count($prodcustprice->lines) > 0) {
  2047. foreach ($prodcustprice->lines as $line) {
  2048. // Date
  2049. $staticsoc = new Societe($db);
  2050. $staticsoc->fetch($line->fk_soc);
  2051. $tva_tx = $line->default_vat_code ? $line->tva_tx.' ('.$line->default_vat_code.')' : $line->tva_tx;
  2052. // Line for default price
  2053. if ($line->price_base_type == 'HT') {
  2054. $pu = $line->price;
  2055. } else {
  2056. $pu = $line->price_ttc;
  2057. }
  2058. // Local tax is not saved into table of product. We use value linked to VAT code.
  2059. $localtaxarray = getLocalTaxesFromRate($line->tva_tx.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), 0, $staticsoc, $mysoc);
  2060. // Define part of HT, VAT, TTC
  2061. $resultarray = calcul_price_total(1, $pu, 0, $line->tva_tx, 1, 1, 0, $line->price_base_type, $line->recuperableonly, $object->type, $mysoc, $localtaxarray);
  2062. // Calcul du total ht sans remise
  2063. $total_ht = $resultarray[0];
  2064. $total_vat = $resultarray[1];
  2065. $total_localtax1 = $resultarray[9];
  2066. $total_localtax2 = $resultarray[10];
  2067. $total_ttc = $resultarray[2];
  2068. print '<tr class="oddeven">';
  2069. print '<td class="tdoverflowmax125">'.$staticsoc->getNomUrl(1)."</td>";
  2070. print '<td>'.dol_escape_htmltag($line->ref_customer).'</td>';
  2071. print "<td>".dol_print_date($line->datec, "dayhour", 'tzuserrel')."</td>";
  2072. print '<td class="center">'.$langs->trans($line->price_base_type)."</td>";
  2073. // VAT Rate
  2074. print '<td class="right">';
  2075. $positiverates = '';
  2076. if (price2num($line->tva_tx)) {
  2077. $positiverates .= ($positiverates ? '/' : '').price2num($line->tva_tx);
  2078. }
  2079. if (price2num($line->localtax1_type)) {
  2080. $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax1_tx);
  2081. }
  2082. if (price2num($line->localtax2_type)) {
  2083. $positiverates .= ($positiverates ? '/' : '').price2num($line->localtax2_tx);
  2084. }
  2085. if (empty($positiverates)) {
  2086. $positiverates = '0';
  2087. }
  2088. echo vatrate($positiverates.($line->default_vat_code ? ' ('.$line->default_vat_code.')' : ''), '%', ($line->tva_npr ? $line->tva_npr : $line->recuperableonly));
  2089. print "</td>";
  2090. print '<td class="right"><span class="amount">'.price($line->price)."</span></td>";
  2091. print '<td class="right"><span class="amount">'.price($line->price_ttc)."</span></td>";
  2092. if ($mysoc->localtax1_assuj == "1" || $mysoc->localtax2_assuj == "1") {
  2093. //print '<td class="right">' . price($line->price_ttc) . "</td>";
  2094. print '<td class="right"><span class="amount">'.price($resultarray[2]).'</span></td>';
  2095. }
  2096. print '<td class="right">'.price($line->price_min).'</td>';
  2097. print '<td class="right">'.price($line->price_min_ttc).'</td>';
  2098. // User
  2099. $userstatic = new User($db);
  2100. $userstatic->fetch($line->fk_user);
  2101. // @TODO Add a cache on $users object
  2102. print '<td class="right">';
  2103. print $userstatic->getNomUrl(-1, '', 0, 0, 24, 0, 'login');
  2104. print '</td>';
  2105. // Todo Edit or delete button
  2106. // Action
  2107. if ($user->hasRight('produit', 'supprimer') || $user->hasRight('service', 'supprimer')) {
  2108. print '<td class="right nowraponall">';
  2109. print '<a href="'.$_SERVER["PHP_SELF"].'?action=showlog_customer_price&token='.newToken().'&id='.$object->id.'&socid='.$line->fk_soc.'">';
  2110. print img_info($langs->trans('PriceByCustomerLog'));
  2111. print '</a>';
  2112. print ' ';
  2113. print '<a class="marginleftonly editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit_customer_price&token='.newToken().'&id='.$object->id.'&lineid='.$line->id.'">';
  2114. print img_edit('default', 0, 'style="vertical-align: middle;"');
  2115. print '</a>';
  2116. print ' ';
  2117. print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?action=delete_customer_price&token='.newToken().'&id='.$object->id.'&lineid='.$line->id.'">';
  2118. print img_delete('default', 'style="vertical-align: middle;"');
  2119. print '</a>';
  2120. print '</td>';
  2121. }
  2122. print "</tr>\n";
  2123. }
  2124. }
  2125. print "</table>";
  2126. print '</div>';
  2127. print "</form>";
  2128. }
  2129. }
  2130. // End of page
  2131. llxFooter();
  2132. $db->close();