<?php
session_start();
require "../model/configuration.php";
$gtot=0;
$price=0;
if(isset($_POST['customer']))
{
//$datepicker=date("Y-m-d", strtotime($_POST['datepicker']));
$datepicker=date("Y-m-d");
$customer=$_POST['customer'];
$fr_bookno=$_POST['fr_bookno'];
$machinename=$_POST['machinename'];
list($code,$pname) = explode("|", $_POST['product']);
$name=$pname;
$cod=$code;
$printsize=$_POST['printsize'];
$numberofpages=$_POST['numberofpages'];
$bckprint=$_POST['bckprint'];
$samematter=$_POST['samematter'];
$pacopy=$_POST['pacopy'];
$paperinkColor=$_POST['paperinkColor'];
$typeofwrk=$_POST['typeofwrk'];
$wrkdescription=$_POST['wrkdescription'];
$numberofbooks=$_POST['numberofbooks'];
$numberofsetsperbooks=$_POST['numberofsetsperbooks'];
$startingno=$_POST['startingno'];
$typeofbndboard=$_POST['typeofbndboard'];
$plate=$_POST['plate'];
$ctp=$_POST['ctp'];
$sion=$_POST['sion'];



$lamination=$_POST['lamination'];
$folding=$_POST['folding'];
$creasing=$_POST['creasing'];
$binding=$_POST['binding'];
$stapling=$_POST['stapling'];
$stitching=$_POST['stitching'];
$pasting=$_POST['pasting'];
$prntlastcopy=$_POST['prntlastcopy'];


if($lamination=="Yes")
{
    $prceothsettings=$db->execute("select * from other_settings where other_name='Lamination'");
    $othro=$prceothsettings->fetch_assoc(); 
    $lamamt=$othro['amount'];  
}
else
{
    $lamamt=0; 
}

if($bckprint=="Yes")
{
    $prceothsettings=$db->execute("select * from other_settings where other_name='Back Printing'");
    $othro=$prceothsettings->fetch_assoc(); 
    $bckprntamt=$othro['amount'];  
}
else
{
    $bckprntamt=0; 
}

if($folding=="Yes")
{
    $prceothsettings=$db->execute("select * from other_settings where other_name='Folding'");
    $othro=$prceothsettings->fetch_assoc(); 
    $foldamt=$othro['amount'];  
}
else
{
    $foldamt=0; 
}

if($creasing=="Yes")
{
    $prceothsettings=$db->execute("select * from other_settings where other_name='Creasing'");
    $othro=$prceothsettings->fetch_assoc(); 
    $creaseamt=$othro['amount'];  
}
else
{
    $creaseamt=0; 
}






   
   
   
//$prcequery=$db->execute("select * from price_details where machine_id='$machinename' and cata_id='$categor'");
//$prcro=$prcequery->fetch_assoc();   
   
   
//$query="insert into temp_puechase(inno) values ('$pno')";
$query=$db->execute("insert into estimate_temp_table(bookno_frm,customer,product_code,product_name,machine_id,print_size,nopages,inkcolor,copies,numberofbooks,numberofsetsperbooks,startingno,typeofbndboard,plate,ctp,lamination,backprint,same_matter,folding,creasing,binding,stapling,stitching,pasting,prntlastcopy,typeofwork,workdescription,amount,laminat_amount,bckprnt_amt,fold_amt,creas_amt,tax,date,dummypaper,printamount,papercoast,platecoast,permission,user)

 values ('$fr_bookno','$customer','$cod','$name','$machinename','$printsize','$numberofpages','$paperinkColor','$pacopy','$numberofbooks','$numberofsetsperbooks','$startingno','$typeofbndboard','$plate','$ctp','$lamination','$bckprint','$samematter','$folding','$creasing','$binding','$stapling','$stitching','$pasting','$prntlastcopy','$typeofwrk','$wrkdescription','00','$lamamt','$bckprntamt','$foldamt','$creaseamt','00','$datepicker','".$_SESSION['dummypaper']."','".$_SESSION['printamt']."','".$_SESSION['papercoast']."','".$_SESSION['platecoast']."','$sion','".$_SESSION['UNAME']."')");



$selprdqy=$db->execute("select * from machines_table where id='$machinename'");
$prtx=$selprdqy->fetch_assoc();	

$catquery=$db->execute("select * from category_table where id='$categor' and machine_id='$machinename'");
$catro=$catquery->fetch_assoc();	

//	setcookie(	
		
		
if($query) {
	$c=0;
$selquery1=$db->execute("select * from estimate_temp_table where permission='$sion' order by id");
while($selrow1=$selquery1->fetch_assoc())
{
$c++;
$sl=$c;
$id=$selrow1['id'];	
}



$my_id = $db->lastid();

$limara= $_SESSION['papercoast'] + $_SESSION['printamt'] + $_SESSION['platecoast'];
$_SESSION['limara'] = $limara + $_SESSION['limara'];

echo '<tr id="item_'.$my_id.'">
<td width="7%">'.$sl.'</td>
<td width="10%">'.$prtx['Machine_Name'].'</td>
<td width="12%">'.$name.'</td>
<td width="12%">'.$printsize.'</td>
<td width="12%">'.$numberofpages.'</td>
<td width="11%">'.$pacopy.'</td>
<td>'.$ctp.'</td>
<td width="11%">'.$limara.'</td>
<td width="9%" class="text-center" style="border-right:none;"><span class="delete_button"><a href="#" class="del_button" id="del-'.$my_id.'" title="Delete"><i class="fa fa-trash-o"></i></a></span></td>
</tr>';
 }
}
?>