Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Obliczanie cenny netto i brutto
Forum PHP.pl > Forum > Po stronie przeglądarki
wozniak
Witam, mam skrypt ktory ma obliczac cene netto lub brutto zalezy która sie wpisze ale cos mi nie działa:( Kod:
  1. <script language="javascript"><!--
  2. var tax_rates = new Array();
  3. tax_rates["1"] = 0;
  4. tax_rates["2"] = 3;
  5. tax_rates["3"] = 6;
  6. tax_rates["4"] = 7;
  7. tax_rates["5"] = 21;
  8. tax_rates["6"] = 22;
  9. function doRound(x, places) {
  10. return Math.round(x * Math.pow(10, places)) / Math.pow(10, places);
  11. }
  12.  
  13. function getTaxRate() {
  14. var selected_value = document.forms["new_product"].prod_z_vat.selectedIndex;
  15. var parameterVal = document.forms["new_product"].prod_z_vat[selected_value].value;
  16.  
  17. if ( (parameterVal > 0) && (tax_rates[parameterVal] > 0) ) {
  18. return tax_rates[parameterVal];
  19. } else {
  20. return 0;
  21. }
  22. }
  23.  
  24. function updateGross() {
  25. var taxRate = getTaxRate();
  26. var grossValue = document.forms["new_product"].prod_z_netto.value;
  27.  
  28. if (taxRate > 0) {
  29. grossValue = grossValue * ((taxRate / 100) + 1);
  30. }
  31.  
  32. document.forms["new_product"].prod_z_brutto .value = doRound(grossValue, 4);
  33. }
  34.  
  35. function updateNet() {
  36. var taxRate = getTaxRate();
  37. var netValue = document.forms["new_product"].prod_z_brutto.value;
  38.  
  39. if (taxRate > 0) {
  40. netValue = netValue / ((taxRate / 100) + 1);
  41. }
  42.  
  43. document.forms["new_product"].prod_z_netto.value = doRound(netValue, 4);
  44. }
  45. //--></script>
  46.  
  47.  
  48. <form method="POST" action="--WEBBOT-SELF--" enctype="multipart/form-data">
  49. <table border="0" cellpadding="0" cellspacing="0" width="567" height="605">
  50. <tr>
  51. <td height="38" width="567" colspan="2">&nbsp;</td>
  52. </tr>
  53. <tr>
  54. <td height="21" width="132">Nazwa Produktu:&nbsp;
  55. </td>
  56. <td height="21" width="435">
  57. <input type="text" name="T1" size="20"></td>
  58. </tr>
  59. <tr>
  60. <td height="23" width="132">Producent:</td>
  61. <td height="23" width="435"><select size="1" name="D1"></select></td>
  62. </tr>
  63. <tr>
  64. <td height="19" width="132">Jezyk:</td>
  65. <td height="19" width="435"><select size="1" name="D4"></select></td>
  66. </tr>
  67. <tr>
  68. <td height="21" width="132">Kod:</td>
  69. <td height="21" width="435"><input type="text" name="T2" size="20"></td>
  70. </tr>
  71. <tr>
  72. <td height="21" width="132">Magazyn:</td>
  73. <td height="21" width="435"><select size="1" name="D2"></select></td>
  74. </tr>
  75. <tr>
  76. <td height="21" width="132">Ilosc</td>
  77. <td height="21" width="435"><input type="text" name="T7" size="11"></td>
  78. </tr>
  79. <tr>
  80. <td height="21" width="132" bgcolor="#EBEBFF">
  81. <p align="right">Klasa podatku:</td>
  82. <td height="21" width="435" bgcolor="#EBEBFF">
  83. <select name="prod_z_vat" onchange="updateGross()">
  84. <option value="1" selected>Vat 0</option>
  85. <option value="2">Vat 3</option>
  86. <option value="3">Vat 6</option>
  87. <option value="4">Vat 7</option>
  88. <option value="5">Vat 21</option>
  89. <option value="6">Vat 22</option>
  90. </select>%</td>
  91. </tr>
  92. <tr>
  93. <td height="21" width="132" bgcolor="#EBEBFF">
  94. <p align="right">Zakup: Cena netto:</td>
  95. <td height="21" width="435" bgcolor="#EBEBFF">
  96. <input onkeyup="updateGross()" name="prod_z_netto" size="11"> x</td>
  97. </tr>
  98. <tr>
  99. <td height="7" width="132" bgcolor="#EBEBFF">
  100. <p align="right">brutto:</td>
  101. <td height="7" width="435" bgcolor="#EBEBFF">
  102. <input onkeyup="updateNet()" name="prod_z_brutto" size="11"> x</td>
  103. </tr>
  104. <tr>
  105. <td height="21" width="132" bgcolor="#EBEBFF">
  106. <p align="right">Klasa podatku:</td>
  107. <td height="21" width="435" bgcolor="#EBEBFF">
  108. <select size="1" name="D5">
  109. <option>21</option>
  110. <option>22</option>
  111. </select>%</td>
  112. </tr>
  113. <tr>
  114. <td height="21" width="132" bgcolor="#EBEBFF">
  115. <p align="right">Sprzedaz: Cena netto:</td>
  116. <td height="21" width="435" bgcolor="#EBEBFF">
  117. <input type="text" name="T5" size="11"> x</td>
  118. </tr>
  119. <tr>
  120. <td height="24" width="132" bgcolor="#EBEBFF">
  121. <p align="right">brutto:</td>
  122. <td height="24" width="435" bgcolor="#EBEBFF">
  123. <input type="text" name="T6" size="11"> x</td>
  124. </tr>
  125. <tr>
  126. <td height="19" width="132" bgcolor="#EBEBFF">
  127. <p align="right">Max upust w %: </td>
  128. <td height="19" width="435" bgcolor="#EBEBFF">
  129. <input type="text" name="T9" size="11">%</td>
  130. </tr>
  131. <tr>
  132. <td height="66" width="132">Opis:</td>
  133. <td height="66" width="435">&nbsp;</td>
  134. </tr>
  135. <tr>
  136. <td height="9" width="567" colspan="2">
  137. <textarea rows="11" name="S1" cols="72"></textarea></td>
  138. </tr>
  139. <tr>
  140. <td height="14" width="132">
  141. <p align="center"></td>
  142. <td height="14" width="435"></td>
  143. </tr>
  144. <tr>
  145. <td height="6" width="132">Zdjecie 1</td>
  146. <td height="6" width="435"><input type="file" name="F1" size="20"></td>
  147. </tr>
  148. <tr>
  149. <td height="13" width="132">Zdjecie 2</td>
  150. <td height="13" width="435"><input type="file" name="F2" size="20"></td>
  151. </tr>
  152. <tr>
  153. <td height="7" width="132">Zdjecie 3</td>
  154. <td height="7" width="435"><input type="file" name="F3" size="20"></td>
  155. </tr>
  156. <tr>
  157. <td height="19" width="132">Waga produktu</td>
  158. <td height="19" width="435">
  159. <input type="text" name="T8" size="8">kg</td>
  160. </tr>
  161. <tr>
  162. <td height="25" width="567" colspan="2">
  163. <p align="center"><input type="submit" value="Dodaj" name="B1"></td>
  164. </tr><script language="javascript"><!--
  165. updateGross();
  166. //--></SCRIPT>
  167. <p>&nbsp;</p>
  168. </form>
Zajec
Na początek przyda się
  1. <form name="new_product" method="POST" action="--WEBBOT-SELF--" enctype="multipart/form-data">
żeby JS mógł w ogóle odnaleźć formularz.
wozniak
A jak chce dodac jeszcze to przeliczanie do sprzedazy to musze jeszcze raz skopiowac funkcje i pozmieniac tam nazwy itp? czy mozna to jakosc łatwiej rozwiazac?
miedzna
Tu masz prościutki skrypcik do takich rzeczy smile.gif
  1. <script language="JavaScript" type="text/JavaScript">
  2. function brutto(){
  3. if(!isNaN(document.getElementById('netto').value))
  4. {
  5. document.getElementById('brutto').value = parseInt((document.getElementById('netto').value*(22/100)))+parseInt(document.getElementById('netto').value)
  6. }else{
  7. document.getElementById('netto').value = '';
  8. document.getElementById('brutto').value = '';
  9. alert('To nie jest liczba !')
  10. }
  11. }
  12.  
  13. Netto:<BR>
  14. <input id="netto" onkeyup="brutto()" rows="5" wrap="virtual" cols="35" onchange="brutto()">
  15. <BR><BR>
  16. Brutto:<BR>
  17. <input id="brutto">
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.