<?php 
session_start();
if ($_SESSION['login']!=true) {header("Location: ../salidausuario.php");}
require_once('../utilesphp/sql_oop.php'); //conexion a base de datos

if (isset($_POST['Idguias']) AND isset($_POST['Idcliente']) AND isset($_POST['dia']) AND isset($_POST['mes']) AND isset($_POST['anno']) AND isset($_POST['Idfactura'])){
		$fecha=$_POST['anno'].'-'.$_POST['mes'].'-'.$_POST['dia'];
		if ($_POST['formapago']=='credito') {$pagada="no";} else {$pagada="si";}		
		$insert=$mysqli->query('INSERT INTO facturas (Idfactura,fecha,Idcliente,total,pagada,formapago) VALUES ("'.$_POST['Idfactura'].'","'.$fecha.'","'.$_POST['Idcliente'].'","'.$_POST['totalfactura'].'","'.$pagada.'","'.$_POST['formapago'].'")');
		$Idguias=explode(',',$_POST['Idguias']);
		foreach ($Idguias as $guia){
			$insert=$mysqli->query('UPDATE ventas SET Idfactura="'.$_POST['Idfactura'].'" WHERE Idventa="'.$guia.'" LIMIT 1');
		}
}
if ($q) {
	$q->free();
}
$mysqli->close();
header('Location: ../movimientos-facturas.php?filtrofactura='.$_POST['Idfactura']);
?>