price.php 99 KB

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