<?php
function auto_close($db,$contract_id){
    include_once('wanted.php');
    
	$wanted = new  Wanted($db,$contract_id) ;
    $pay = $wanted->wanted() ;

    $cont_status = $pay["cont_status"] ;
    if($cont_status > 1){
    if($pay['wanted']== 0){$cont_status = 2 ;}

    $final = $db->prepare(" UPDATE contracts SET days_qty = ?, kilo_qty = ? ,
     kilos_cost = ?, hour_qty = ? ,  hours_cost = ? , net_cost = ?,
      total_in = ? ,total_out = ?  ,  wanted = ? ,  cont_status = ?  , vat_req = ? , after_vat = ?
      WHERE contract_id = ?  ");
      $final->bindParam(1,$pay['days_qty']);
      $final->bindParam(2,$pay['km_qty']);
      $final->bindParam(3,$pay['kilos_cost']);
      $final->bindParam(4,$pay['hour_qty']);
      $final->bindParam(5,$pay['hours_cost']);
      $final->bindParam(6,$pay['net_cost']);
      $final->bindParam(7,$pay['total_in']);
      $final->bindParam(8,$pay['total_out']);
      $final->bindParam(9,$pay['wanted']);
      $final->bindParam(10,$cont_status);
      $final->bindParam(11,$pay['vat_req']);
      $final->bindParam(12,$pay['after_vat']);
      $final->bindParam(13,$contract_id);
      $final->execute();
    }
}
?>
