0
Guys I know almost nothing about JS, and I am developing a php system with help from Cakephp 3, the following is part of my payment screen, my problem is that I need to get the values that are in Javascript from total_sale, and also take the amount of products that is in php in my id_cart Session and pass to js to send via post as soon as I click the close sell button. I’m not sure how to take this data in my view and not treat it in my controller.
My modal:
<!-- Button to Open the Modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bd-example-modal-xl" style="width: 90%; font-size: 130%;">Pagar Venda</button>
<!-- The Modal -->
<div class="modal fade bd-example-modal-xl" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" style="width:90%">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h2 class="modal-title" style="text-align: center;">Formas de Pagamento</h2>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<br />
<table class="payment-methods">
<tr>
<td>
<input type="radio" name="payment_methods" id="dinheiro" class="pg" />
<label for="dinheiro" class="labelpag">
<img src="/projeto/img/cash.png" class="imgpag" alt="" >
</label>
<br />
</td>
<td>
<input type="radio" name="payment_methods" id="credito" class="pg" />
<label for="credito" class="labelpag2">
<img src="/projeto/img/card2.png" class="imgpag2">
</label>
</td>
<br />
<td>
<input type="radio" name="payment_methods" id="debito" class="pg" />
<label for="debito" class="labelpag2">
<img src="/projeto/img/card.png" class="imgpag2">
</label>
</td>
</tr>
</table>
<table>
<tr>
<td>
<p class="p_pagamento totalpago">Total de Itens:
<?php
$id = $_SESSION['id_cart'];
$id = $id["id"];
if(isset($id)){
if($id == null){
$id = 0;
}
echo count($id);?>
<input type="hidden" name="produtos_id" value="$id">
<?php
} ?>
</p>
</td>
<td>
<p class="p_pagamento">Total da Venda: R$ <span class="total_venda"></p>
</td>
</tr>
<tr>
<td>
<p class="p_pagamento"> Total Pago: R$ <input type="" name="troco" value="" class="input_pagamento" id="total_pago"></p>
</td>
<td>
<p class="p_pagamento trocopagamento"> Troco R$
<span id="troco"></span></p>
</td>
</tr>
</table>
<br />
<button type="Submit" class="btn btn-primary" id="click">Fechar Venda</button>
</div>
<!-- Modal footer
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>-->
</div>
</div>
</div>
Js:
<script>
function soma_total(){
total = 0;
$(".total_unitario").each(function() {
total += parseFloat($(this).text());
});
$(".total_venda").text((total).toFixed(2));
total_venda = $(".total_venda").text((total).toFixed(2));
};
var quantidade = 0;
var precounitario = 0;
var total = 0;
$(".quant").each(function(){
quantidade = parseFloat($(this).val());
precounitario = parseFloat($(this).parent().parent().find(".preco_uni").text());
$(this).parent().parent().find(".total_unitario").text((quantidade*precounitario).toFixed(2));
soma_total();
})
$(".quant").change(function(){
quantidade = parseFloat($(this).val());
precounitario = parseFloat($(this).parent().parent().find(".preco_uni").text());
$(this).parent().parent().find(".total_unitario").text((quantidade*precounitario).toFixed(2));
soma_total();
});
$("#total_pago").keyup(function(){
var pago = $(this).val().replace(",",".");
$("#troco").text((pago-total).toFixed(2));
})
Do you already have the array/variable ready that receives the data? In case it would just pass the data to another page via _POST or also have limitations in assembling these variables?
– ElvisP
In case it would be to send the data to my controller and it can save in the database.
– LMT