I want to generate a ticket or invoice. And I have the ticket window, an add button that leads to the product listing page, and in it the add button (selected products) and a finished one returns to the previous screen. But I can not list the details of the invoice. I'm thinking if I should make an AJAX call when the page is loaded to create the session, but for now I have it in the ticket index (work with MVC).
index.php:
<?php
session_start();
include_once ("/../../../models/claseTicket.php");
date_default_timezone_set("America/Argentina/Buenos_Aires");
$time=time();
$fecha = date("d/m/y (H:i:s)",$time);
echo date("d/m/y (H:i:s)",$time);
$ticket = new Ticket($fecha,$time);
$_SESSION['ticket']=serialize($ticket);
?>
This is executed when loading the page:
$(document).ready(function() {
listarDetalle();
});
function listarDetalle(){
var accion="listar";
$.ajax({
type: "POST",
url: "../gestionweb/includes/php/procesoDetalle.php",
data: { "accion":accion},
dataType:'json',
error: function(){
alert("error petición ajax");
},
success: function(data){
console.log(data);
for (var i = 0; i < data.length; i++) {
alert('fdsfgds')
var newRow =
"<tr>" +
"<td>" + data[i].idp + "</td>" +
"<td>" + data[i].nombre + "</td>"
"<td>" + data[i].marca + "</td>" +
"<td>" + data[i].cantidad + "</td>" +
"<td><input type='radio' id='"+data[i].idproducto+"' name='seleccion'/></td>"+
"</tr>";
$(newRow).appendTo("#ticket tbody");
} }
}).fail( function( jqXHR, textStatus, errorThrown ) {
if (jqXHR.status === 0) {
alert('Not connect: Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (textStatus === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (textStatus === 'timeout') {
alert('Time out error.');
} else if (textStatus === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error: ' + jqXHR.responseText);
}
});;
};
As you can see it is called a processdetail:
<?php
header('Content-Type: application/json');
include ("../../models/claseTicket.php");
session_start();
$ticket = unserialize($_SESSION['ticket']);
if (isset($_POST['accion'])){
if ($_POST['accion']="listar"){
$arrayarticulos[]=$ticket->listarArt();
echo json_encode($arrayarticulos);
}else if ($_POST['accion']="agregar"){
$id = $_POST['id'];
$precio = $_POST['precio'];
$cant=$_POST['cantidad'];
$nom=$_POST['nombre'];
$ticket->agregaDetalle(new detalleTicket($id,$precio,$cant,$nom));
}
}
?>
And that's where the problem is, I do not know if I'm serializing badly or what.
The idea is to obtain the ticket object and use the add and list methods. Or should I separate the logic in what way?