Advertisement
Guest User

Recalcular valor de parcelas.

a guest
Sep 22nd, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.20 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6.  
  7. <!--
  8. <link rel="stylesheet" type="text/css" href="style.css?1" media="screen"/>
  9. <link rel="stylesheet" type="text/css" href="style_custon.css?1" media="screen"/>
  10. -->
  11.  
  12. <script type="text/javascript" src="jquery_1.7.2.js"></script>
  13.  
  14. <script type="text/javascript">
  15.  
  16. /**
  17. Insere ponto e a virgula em valores monetários:
  18. */
  19.  
  20. function moeda(z) {
  21.  
  22. v = z.value;
  23.  
  24. v = v.replace(/\D/g,""); // permite digitar apenas números
  25. v = v.replace(/[0-9]{12}/,"Valor inválido."); // limita pra máximo 999.999.999,99
  26. v = v.replace(/(\d{1})(\d{8})$/,"$1.$2"); // coloca ponto antes dos últimos 8 digitos
  27. v = v.replace(/(\d{1})(\d{5})$/,"$1.$2"); // coloca ponto antes dos últimos 5 digitos
  28. v = v.replace(/(\d{1})(\d{1,2})$/,"$1,$2"); // coloca virgula antes dos últimos 2 digitos
  29.  
  30. z.value = v;
  31.  
  32. }
  33.  
  34.  
  35. /**
  36. Insere ponto e a virgula em valores monetários:
  37. */
  38.  
  39. function formataMoeda(valor) {
  40.  
  41. v = valor;
  42. v = v.replace(/\D/g,""); // permite digitar apenas números
  43. v = v.replace(/[0-9]{12}/,"Valor inválido."); // limita pra máximo 999.999.999,99
  44. v = v.replace(/(\d{1})(\d{8})$/,"$1.$2"); // coloca ponto antes dos últimos 8 digitos
  45. v = v.replace(/(\d{1})(\d{5})$/,"$1.$2"); // coloca ponto antes dos últimos 5 digitos
  46. v = v.replace(/(\d{1})(\d{1,2})$/,"$1,$2"); // coloca virgula antes dos últimos 2 digitos
  47.  
  48. return v;
  49.  
  50. } // function formataMoeda(valor)
  51.  
  52.  
  53. /**
  54. Verifica se existe PONTO no valor recebido;
  55. */
  56. function retiraPonto(valor){
  57.  
  58. var regExp = /\./ig;
  59. var bool = regExp.test(valor);
  60. if (bool) {
  61. var valor = valor.replace('.','');
  62. return valor;
  63. }
  64.  
  65. return valor;
  66.  
  67. } // function retiraPonto(valor)
  68.  
  69.  
  70.  
  71. function recalcular_valor_demais_parcelas(id, valor_parcela){
  72.  
  73. /*
  74. Valor da parcela:
  75. */
  76. var valor = retiraPonto(valor_parcela);
  77. valor = valor.replace(',','.');
  78. total_valor_parcela = new Number(valor);
  79. var parcela = total_valor_parcela.toFixed(2);
  80. // console.log('PARCELA: '+parcela);
  81.  
  82.  
  83. /*
  84. Valor Total inicial:
  85. */
  86. var total1 = $("#valor_total").val();
  87. // console.log('TOTAL 1: '+total1);
  88. var total2 = retiraPonto(total1);
  89. total3 = total2.replace(',','.');
  90. // console.log('TOTAL 3: '+total3);
  91. valor_total = new Number(total3);
  92. var total4 = valor_total.toFixed(2);
  93. // console.log('TOTAL 4: '+total4);
  94.  
  95.  
  96. /*
  97. Novo total: Total inicial MENOS o novo valor da primeira
  98. parcela;
  99. */
  100. var novo_total = 0;
  101. novo_total += (+total4) - (+parcela);
  102. var total = new Number(novo_total);
  103. var resNovoTotal = total.toFixed(2);
  104. // console.log('NOVO TOTAL: '+resNovoTotal);
  105.  
  106.  
  107. /*
  108. Pega todos os inputs de parcela:
  109. */
  110. var tabela = document.getElementById("tabela");
  111. var inputs_parcela = tabela.getElementsByClassName("pmt");
  112. var inputs = (inputs_parcela.length - 1);
  113. // console.log('INPUTS: '+inputs);
  114.  
  115.  
  116. /*
  117. Novo valor das parcelas;
  118. */
  119. var resultado = 0;
  120. resultado += (+resNovoTotal) / (inputs);
  121. var total = new Number(resultado);
  122. var resTotal = total.toFixed(2);
  123.  
  124.  
  125. /*
  126. Insere o total atualizado no campo input: '#valor_total',
  127. em caso de outros campos de parcela terem seus
  128. valores alterados;
  129.  
  130. E recalcula o valor das demais parcelas com base neste novo
  131. valor total;
  132. */
  133. /*
  134. var total_atualizado = (+resTotal) * (+inputs);
  135. var total = new Number(total_atualizado);
  136. total_atualizado = total.toFixed(2);
  137. total_atualizado = retiraPonto(total_atualizado.toString());
  138. $("#valor_total").val( formataMoeda(total_atualizado) );
  139. */
  140.  
  141.  
  142.  
  143. /*
  144. Seta o novo valor das parcelas em todos os campos
  145. com id 'valor_parcela';
  146. */
  147. for (var i = 0; i < inputs_parcela.length; i++) {
  148.  
  149. /*
  150. Altera todos os campos, que ficam ABAIXO ou APARTIR do
  151. campo que está sendo editado, exceto o campo que está
  152. recebendo a edição:
  153. */
  154. if ((i+id) != id) {
  155. $('#valor_parcela'+(i+id)).val(formataMoeda(resTotal));
  156. }
  157.  
  158. }
  159.  
  160.  
  161. } // function recalcular_valor_demais_parcelas()
  162.  
  163. </script>
  164.  
  165.  
  166. </head>
  167.  
  168.  
  169. <fieldset class="lb">
  170. <legend id="load_parcelas"><strong>PARCELAS</strong>
  171. <i class="info" dica="Valores apresentados com base no cálculo da Tabela Price." rel="tooltip4"></i>
  172. </legend>
  173. </fieldset>
  174.  
  175. <!--Recebe a reposta do PHP (via AJAX);-->
  176. <div id="respAjaxValoresParcelas">
  177.  
  178.  
  179.  
  180. <input type="hidden" id="valor_total" value="10.000,00">
  181.  
  182. <table id="tabela" class="table table-striped status-orcamento table-hover">
  183. <thead>
  184. <tr><th>Parcela</th>
  185. <th>Vencimento</th>
  186. <th>Desconto <i class="f12">(R$)</i></th>
  187. <th>Juro <i class="f12">(R$)</i></th>
  188. <th>Recebido</th>
  189. <th>Valor Parcela</th>
  190. <th>Status</th>
  191. </tr></thead>
  192. <tbody>
  193.  
  194. <tr class="status-nao-aprovado"> <th><normal>1</normal></th>
  195.  
  196.  
  197. <th>
  198. <input type="date" class="form_alfa" id="lancamento_receita_data_incio" value="2019-09-21" onchange="data_conta_receber(1024, 000, this.value)" title="Alterar Data." rel="tooltip2">
  199. </th>
  200.  
  201.  
  202.  
  203.  
  204. <th>
  205. <input type="text" class="form_alfa" id="desconto1" value="0,00" onkeyup="moeda(this); recalcular_valor_recebido_desconto(1, this.value);">
  206. </th>
  207.  
  208. <th>
  209. <input type="text" class="form_alfa" id="juro1" value="0,00" onkeyup="moeda(this); recalcular_valor_recebido_juro(1, this.value);">
  210. </th>
  211.  
  212. <th>
  213. <input type="text" class="form_alfa" id="recebido1" value="0,00" onkeyup="moeda(this);">
  214. </th>
  215.  
  216. <th>
  217. <input type="text" class="form_alfa pmt" id="valor_parcela1" value="2.500,00" onkeyup="moeda(this); recalcular_valor_demais_parcelas(1, this.value);">
  218. </th>
  219.  
  220.  
  221.  
  222.  
  223.  
  224. <th>
  225. <select class="form_alfa" onchange="status_conta_receber('1','lrcb-1000844569', this.value)">
  226. <option id="status_conta_receber" 0="">Aguardando</option>
  227. <option value="1">Recebido</option>
  228. <option value="2">Cancelado</option>
  229. </select>
  230. </th>
  231.  
  232.  
  233. </tr>
  234.  
  235.  
  236. <tr class="status-aprovado"> <th><strong>2</strong></th>
  237.  
  238.  
  239. <th>
  240. <input type="date" class="form_alfa" id="lancamento_receita_data_incio" value="2019-10-21" onchange="data_conta_receber(1025, 000, this.value)" title="Alterar Data." rel="tooltip2">
  241. </th>
  242.  
  243.  
  244.  
  245.  
  246. <th>
  247. <input type="text" class="form_alfa" id="desconto2" value="0,00" onkeyup="moeda(this); recalcular_valor_recebido_desconto(2, this.value);">
  248. </th>
  249.  
  250. <th>
  251. <input type="text" class="form_alfa" id="juro2" value="0,00" onkeyup="moeda(this); recalcular_valor_recebido_juro(2, this.value);">
  252. </th>
  253.  
  254. <th>
  255. <input type="text" class="form_alfa" id="recebido2" value="0,00" onkeyup="moeda(this);" >
  256. </th>
  257.  
  258. <th>
  259. <input type="text" class="form_alfa pmt" id="valor_parcela2" value="2.500,00" onkeyup="moeda(this); recalcular_valor_demais_parcelas(2, this.value);">
  260. </th>
  261.  
  262.  
  263.  
  264.  
  265.  
  266. <th>
  267. <select class="form_alfa" onchange="status_conta_receber('2','lrcb-1000844569', this.value)">
  268. <option id="status_conta_receber" 0="">Aguardando</option>
  269. <option value="1">Recebido</option>
  270. <option value="2">Cancelado</option>
  271. </select>
  272. </th>
  273.  
  274.  
  275. </tr>
  276.  
  277.  
  278. <tr class="status-aprovado"> <th><normal>3</normal></th>
  279.  
  280.  
  281. <th>
  282. <input type="date" class="form_alfa" id="lancamento_receita_data_incio" value="2019-11-21" onchange="data_conta_receber(1026, 000, this.value)" title="Alterar Data." rel="tooltip2">
  283. </th>
  284.  
  285.  
  286.  
  287.  
  288. <th>
  289. <input type="text" class="form_alfa" id="desconto3" value="0,00" onkeyup="moeda(this); recalcular_valor_recebido_desconto(3, this.value);">
  290. </th>
  291.  
  292. <th>
  293. <input type="text" class="form_alfa" id="juro3" value="0,00" onkeyup="moeda(this); recalcular_valor_recebido_juro(3, this.value);" >
  294. </th>
  295.  
  296. <th>
  297. <input type="text" class="form_alfa" id="recebido3" value="0,00" onkeyup="moeda(this);" >
  298. </th>
  299.  
  300. <th>
  301. <input type="text" class="form_alfa pmt" id="valor_parcela3" value="2.500,00" onkeyup="moeda(this); recalcular_valor_demais_parcelas(3, this.value);" >
  302. </th>
  303.  
  304.  
  305.  
  306.  
  307.  
  308. <th>
  309. <select class="form_alfa" onchange="status_conta_receber('3','lrcb-1000844569', this.value)">
  310. <option id="status_conta_receber" 0="">Aguardando</option>
  311. <option value="1">Recebido</option>
  312. <option value="2">Cancelado</option>
  313. </select>
  314. </th>
  315.  
  316.  
  317. </tr>
  318.  
  319.  
  320. <tr class="status-aprovado"> <th><strong>4</strong></th>
  321.  
  322.  
  323. <th>
  324. <input type="date" class="form_alfa" id="lancamento_receita_data_incio" value="2019-12-21" onchange="data_conta_receber(1027, 000, this.value)" title="Alterar Data." rel="tooltip2" >
  325. </th>
  326.  
  327.  
  328.  
  329.  
  330. <th>
  331. <input type="text" class="form_alfa" id="desconto4" value="0,00" onkeyup="moeda(this); recalcular_valor_recebido_desconto(4, this.value);" >
  332. </th>
  333.  
  334. <th>
  335. <input type="text" class="form_alfa" id="juro4" value="0,00" onkeyup="moeda(this); recalcular_valor_recebido_juro(4, this.value);" >
  336. </th>
  337.  
  338. <th>
  339. <input type="text" class="form_alfa" id="recebido4" value="0,00" onkeyup="moeda(this);" >
  340. </th>
  341.  
  342. <th>
  343. <input type="text" class="form_alfa pmt" id="valor_parcela4" value="2.500,00" onkeyup="moeda(this); recalcular_valor_demais_parcelas(4, this.value);" >
  344. </th>
  345.  
  346.  
  347.  
  348.  
  349.  
  350. <th>
  351. <select class="form_alfa" onchange="status_conta_receber('4','lrcb-1000844569', this.value)">
  352. <option id="status_conta_receber" 0="">Aguardando</option>
  353. <option value="1">Recebido</option>
  354. <option value="2">Cancelado</option>
  355. </select>
  356. </th>
  357.  
  358.  
  359. </tr>
  360.  
  361. </tbody>
  362. </table>
  363.  
  364.  
  365.  
  366. <table class="table table-striped status-orcamento table-hover">
  367. <thead>
  368. <tr><th></th>
  369. <th></th>
  370. <th></th>
  371. <th></th>
  372. </tr></thead>
  373. <tbody>
  374.  
  375.  
  376. <tr>
  377. <td colspan="7">
  378.  
  379. <span style="float:right;text-align: right; margin-top:0px;" class="f24 grand_total box-shadow">
  380. <i class="f10">TOTAL </i>
  381.  
  382. <b id="grand_total">R$
  383.  
  384. 10.000,00
  385. </b>
  386.  
  387. </span>
  388.  
  389. </td>
  390.  
  391. </tr>
  392.  
  393. </tbody>
  394. </table>
  395.  
  396.  
  397. </div>
  398. <!--Recebe a reposta do PHP (via AJAX) - respAjaxValoresParcelas -->
  399.  
  400.  
  401.  
  402. <div class="clear_form"></div>
  403.  
  404.  
  405.  
  406. <body>
  407. </body>
  408. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement