<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); // Make MySQLi throw exceptions.

        try {
            // Try Connect to the DB with new MySqli object - Params {hostname, userid, password, dbname}
            $mysqli = new mysqli("localhost", "lara1", "myLARA", "lara1");

            // Select all records from the db. Keep inside try block incase there an issue with sql query
            $query = "
            update inv 
            set existencia=existencia+".$_GET["cant"].",total=total+".$_GET["cant"]."
            WHERE tienda='".$_GET["tienda"]."' and codigo='".$_GET["codigo"]."'";         

            $mysqli->query($query);

            // actualiza inv_res
            $query = "REPLACE INTO inv_res
SELECT CURDATE() AS fecha,a.tienda,a.genero,a.rc,a.linea,a.sucursal,a.descripcion,SUM(a.existencia) AS existencia,tot_tallas AS tallas
,ROUND(SUM(b.participacion)*100) AS entallado
,a.`departamento`,b.tipo,a.anio,a.alta_suc
FROM inv a INNER JOIN tallas b
ON a.`linea`=b.`linea` AND a.talla=b.talla AND a.`genero`=b.`genero` AND a.`departamento`=b.`departamento`
WHERE a.tienda='".$_GET["tienda"]."' AND a.rc='".$_GET["rc"]."' AND a.total>0
GROUP BY a.tienda,a.rc,a.genero,a.`departamento`,b.tipo";

            //die($query);

            $mysqli->query($query);

        } catch (mysqli_sql_exception $e) { // Failed to connect? Lets see the exception details..
            echo "MySQLi Error Code: " . $e->getCode() . "<br />";
            echo "Exception Msg: " . $e->getMessage();
            exit; // exit and close connection.
        }

        $mysqli->close(); // finally, close the connection
        
 ?>  
<script>
    self.history.go(-1);
</script>