<?php
ini_set('display_errors', 0);

require_once("../../common/lib.php");
require_once("../../common/define.php");

if(!isset($_SESSION['user'])){
    header("Location: login.php");
    exit();
}

$id = $_GET["id"];
$table = $_GET["table"];

$outp = array();
//===========================
$query_solde = "SELECT *,SUM(montant) as mnt, SUM(retenue_montant) as retenue from pm_transaction where ref_facture_achat = ".$id;
$result_solde = @$db->query($query_solde);
if($result_solde !== false){
	$res = $result_solde->fetch();
	$payer= $res["mnt"] + $res["retenue"] ;
}
//===========================	
	// $outp["total_reste"] = $row["total_ttc"] - $payer;
//===========================	
$query = "SELECT * from pm_".$table." where id = ".$id;
$result = @$db->query($query);
$cont = 0 ;

if($result !== false){
	$outp = $result->fetch();

	//===========================	
	// $total_reste = $outp["total_ttc"] - $payer;
	$outp["total_reste"] = $outp["total_ttc"] - $payer;
	//===========================		
		// $outp["total_ttc"] = $row["total_ttc"];
		

	
	echo json_encode($outp);
	
}	




?>