<?php
	require ("./Funciones/funciones.php");
	require("conexion.php");
	$conexion = conecta();
	$datos = $_POST['dato'];
	
	$cont = $_POST['cont'];
	$area = $_POST['area'];
	$costo = $_POST['costo'];
	$insumos = explode("|",$datos);
	$areas = $_POST['areau'];
	$areau = explode("|",$areas);
	$grandtotal = 0;

	function round_up ( $value, $precision ) { 
    $pow = pow ( 10, $precision ); 
    return ( ceil ( $pow * $value ) + ceil ( $pow * $value - ceil ( $pow * $value ) ) ) / $pow; 
} 
	while($cont != 0){
		$id = $insumos[$cont];
		$areauni = $areau[$cont];
		$p = mysqli_query($conexion,"SELECT * FROM Insumos WHERE IdInsumo = $id");
		$f = mysqli_fetch_array($p);
		$total = $f['TotalUnit'];
		$subarea = $total * $areauni;
		$grandtotal += $subarea;
		$cont--;
	}
	$grandtotal = $grandtotal + $costo;
	$grandtotal = round_up($grandtotal,2);
	echo $grandtotal;
?>