<?php

ini_set('display_errors', 0);
define("ADMIN", true);
require_once("../../common/lib.php");
require_once("../../common/define.php");
define("TITLE_ELEMENT", 'doc_vente');
if(!isset($_SESSION['user'])){
    header("Location: /admin/login.php");
    exit();
}
require_once("../includes/fn_module.php"); ?>

<?

if($_POST["id_fac"]) {
	
	$id_fac = $_POST["id_fac"] ;
	$type = $_POST["type"] ;
	$obs = addslashes($_POST["obs"]) ;
	
	if($type == "achat"){
		$query = "UPDATE `pm_facture_achat` SET `observation`='$obs' WHERE id=".$id_fac  ;
		$redir = "/admin/all_rapport/rapport_achat.php";
	}else{
		$query = "UPDATE `pm_facture` SET `observation`='$obs' WHERE id=".$id_fac  ;
		$redir = "/admin/all_rapport/rapport_vente.php";
	}
	// echo $redir;
	// exit();
	$result = @$db->query($query);
	
	
?>
<script>
	window.location.replace("<? echo $redir; ?>");
</script>
<?	
	// header("Location: ".$redir);
    // exit();	
}

$obs = "";
if($type == "achat"){
	$query_selcet = "select observation from `pm_facture_achat` WHERE id=".$_GET["id"]  ;
}else{
	$query_selcet = "select observation from `pm_facture` WHERE id=".$_GET["id"]  ;
}	
$result_select = @$db->query($query_selcet);	
if($result_select !== false){
	foreach($result_select as $row){
		$obs = $row["observation"];
	}
}
?>
<!DOCTYPE html>
<head>
    <?php include("../includes/inc_header_common.php"); ?>

</head>
<body>
    <div id="wrapper">
        <?php include("../includes/inc_top.php"); ?>
        <div id="page-wrapper">
            <div class="page-header">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-8">
                            <h1><i class="fa fa-random"></i> Observations</h1>
                        </div>
                    </div>
                </div>
            </div>
            <div class="container-fluid">
                <div class="alert-container">
                    <div class="alert alert-success alert-dismissable"></div>
                    <div class="alert alert-warning alert-dismissable"></div>
                    <div class="alert alert-danger alert-dismissable"></div>
                </div>
                <div class="row" >				
				
	<form method="POST" action="#">				
		<input type="hidden" name="id_fac" value="<? echo $_GET["id"]; ?>" />
		<input type="hidden" name="type" value="<? echo $_GET["type"]; ?>" />
		<div class="panel panel-default">
			<div class="panel-body">
				   <label class="col-lg-2 control-label text-right">Observation &nbsp;<span class="red">*</span></label>
				   <div class="col-lg-8">
					  <div class=" form-inline">
						 <textarea rows="4" cols="100" name="obs" class="form-control"><? echo $obs; ?></textarea>
					  </div>
				   </div>
			 </div>
		</div> 	
	
	
	<div class="panel panel-default">
		<div class="panel-body">
			   <label class="col-lg-4 control-label " ></label>
			   <div class="col-lg-6">
				  <div class=" form-inline">
						<button type="submit" class="btn btn-default mt15" data-toggle="tooltip" data-placement="bottom" title="Save">
							<i class="fa fa-floppy-o"></i><span class="hidden-sm hidden-xs"> Save</span>
						</button>
				  </div>
			   </div>
		 </div>
	</div> 


</form>	
									
                    <?php
                    if($db !== false){
                        
                    } ?>
					
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<?php
$_SESSION['msg_error'] = "";
$_SESSION['msg_success'] = "";
$_SESSION['msg_notice'] = ""; ?>
