<?php
require "../model/configuration.php";
$id=$_GET['id'];
$estno=$_GET['estno'];
$cust=$_GET['cust'];
$date=$_GET['date'];
$total_amt=0;
$sqry=$db->execute("update  estimate_table set approve='1' WHERE id='$id'");

$pname = $db->execute("SELECT * FROM estimate_table where estimation_no='".$estno."'");
                             
 while($ar=$pname->fetch_assoc())
							 //extract($ar);
		 {
$stock=$db->execute("SELECT * from stock_master where product_code='".$ar['product_code']."' and delet='0'");
$stock_qty=$stock->num_rows;
    if($stock_qty>0){
        $st_val=$stock->fetch_assoc();
        $ttqty=$st_val['quantity']-$ar['dummypaper'];
        $db->execute("UPDATE stock_master set quantity='$ttqty' where product_code='".$ar['product_code']."' and delet='0' ");

   }


        $total_amt=$ar['total'];
        $adv=$ar['advamt'];
        $date=$ar['date'];

 }
 $db->execute("INSERT into cust_tran_main (custid,estimateno,total_amt,adv_amt,date) VALUES ('$cust','$estno','$total_amt','$adv','$date')");

header("location:../Pages/estimate_reciept.php?estno=$estno&cust=$cust&date=$date");
?>