price.php 89 KB

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