Enter data to 2 tables

0

I'm doing a shopping module. The code is already made to enter the sales table and sales detail. When I enter a product it works correctly but when I want to enter more than 2 objects at once I get this error:

preg_replace(): Parameter mismatch, pattern is a string while replacement is an array   

It is worth mentioning that I send the data through array with js and in the controller I receive them through the loop while . This is the code of js:

$(document).ready(function(){
  $("#bt_add").click(function(){
        agregar();
  });
});
   var cont=0;
   total = 0;
   subtotal=[];
   precioIva=[];

  $("#guardar").hide();
  $("#pidConcepto").change(mostrarValores);

  function mostrarValores() {
    datosArticulo=document.getElementById('pidConcepto').value.split("_");
    $('#pprecio').val(datosArticulo[1]);
    $('#pimpuesto').val(datosArticulo[2]);
  }

  function agregar() {

        datosArticulo=document.getElementById('pidConcepto').value.split('_');

        idConceptosPagos=datosArticulo[0];
        consepto=$("#pidConcepto option:selected").text();
        precio=$("#pprecio").val();
        impuesto=$("#pimpuesto").val();
        cantidad=$("#pcantidad").val();

        if(consepto!=" " &&  precio!=" " && impuesto!=" " && cantidad!= " ")
        {

              precioCantidad = precio * cantidad;
              iva = precioCantidad * 16 / 100;
              subtotal[cont] = precioCantidad;
              precioIva[cont] = iva;
              total1=precioIva[cont]+subtotal[cont];
              total=total+total1;

              var fila ='<tr class="selected" id="fila' + cont +'" ><td><button type="button" class="btn btn-warning" onclick="eliminar('+cont+');">X</button></td><td><input type="hidden" name="idConceptosPagos[]" value="'+idConceptosPagos+'">'+consepto+'</td><td><input type="text" name="precio[]" readonly="readonly" style="text-align: right;" value="$/. '+precio+'"></td><td><input type="text" name="cantidad[]" disabled  value="'+cantidad+'"></td><td type="text" name=precioCantidad[] style="text-align: right;" readonly>$/.'+precioCantidad+'</td><td type="number" style="text-align: right;" name=iva[]>$/.'+iva+'</td><td style="text-align: right;">$/.'+ total1+'</td></tr>';

              cont++;
              limpiar();
              $("#total").html("$/. " + total);
              $("#total_venta").val(total);
              evaluar();
              $("#detalles").append(fila);

        }else {


              alert("Error al ingresar el detalle de la venta, revise los datos del articulo");

        }
  }

function limpiar() {
  $("#pfechaPago").val("");
  $("#pprecio_venta").val("");   
 }

  function evaluar(){

  if (total>0) {
        $("#guardar").show();
  }
  else {
       $("#guardar").hide();  
  }
}

function eliminar(index) {

 total=total-subtotal[index];
 $("#total").html("$/. " + total);
 $("#total_venta").val(total);
 $("#fila" + index).remove();
 evaluar();
}

and in the controller I do it this way:

 $venta = new VentaUtp;
        $venta->idAlumno=$request->get('idAlumno');
        $venta->idCiclo=$request->get('idCiclo');
        $venta->clave=$request->get('clave');
        $venta->anio=$request->get('anio');
        $venta->mes=$request->get('mes');
        $venta->pagado= 'N';
        $venta->cantidadProgramada = $request->get('total_venta');
        $venta->cantidadPagada = null;

        $venta->save();


        $idAlumno = $request->get('idAlumno');
        $idCiclo = $request->get('idCiclo');
        $idConceptosPagos = $request->get('idConceptosPagos');
        $precio = $request->get('precio');
        $pcantidad = $request->get('pcantidad');




         foreach ($idConceptosPagos as $detalle=>$value) {
            $detalle = new DetalleVentaUtp();
            $detalle->idAlumnoCxC= $venta->idAlumnosCxC;
            $detalle->idAlumno = $idAlumno;
            $detalle->idCiclo = $idCiclo;
            $detalle->idConseptoPago= $idConceptosPagos;
            $detalle->cantidad=$pcantidad;
            $detalle->save();

        }

But I do not know what is due. I appreciate if you can help me.

    
asked by Juan Antonio 20.06.2018 в 16:19
source

0 answers