<?php
// session_start();
// ob_start();
// $father = $_SESSION["user_id"];
include "../actions/dbPDO.php";

$sql = $db->prepare("SELECT mat_in_id , net_cost ,  vat_out FROM material_in WHERE vat_out > 0 ");
$sql->execute();
if($sql->rowCount()>0)
{
 while($row = $sql->fetch())
 { $mat_in_id = $row["mat_in_id"];
   $net_cost = $row["net_cost"]; $vat_out = $row["vat_out"];

   $sql2 =$db->prepare("SELECT line_id , unit_price , tot_price FROM items_line WHERE mat_in_id = ? ");
   $sql2->bindParam(1,$mat_in_id) ;
   $sql2->execute();
   if($sql2->rowCount()>0)
   while($row2 = $sql2->fetch())
   { $line_id = $row2["line_id"];
     $unit_price = $row2["unit_price"]; $tot_price = $row2["tot_price"];
     $unit_price = round((($unit_price/105)*100),2);$tot_price = round((($tot_price/105)*100),2);
     $up1=$db->prepare("UPDATE items_line set tot_price = ? ,unit_price = ? where line_id = ?");
     $up1->bindParam(1,$tot_price);
     $up1->bindParam(2,$unit_price);
     $up1->bindParam(3,$line_id);
     $up1->execute();
   }
   $net_cost = round((($net_cost/105)*100),2);$vat_out = round((($net_cost/105)*5),2);
   $up2=$db->prepare("UPDATE material_in set net_cost = ? ,vat_out = ? , vat = 1 where mat_in_id = ?");
   $up2->bindParam(1,$net_cost);
   $up2->bindParam(2,$vat_out);
   $up2->bindParam(3,$mat_in_id);
   $up2->execute();
 }}

?>
