<?php
session_start();
ob_start();
require "../model/configuration.php";
$nofplateset=0;
$ttamt=0;
$ttamta=0;
$extra=0;
$option = $_POST['get_option'];
$prdselquery=$db->execute("select * from products where productcode='".$_SESSION['prdcode']."'");
$prdselrow=$prdselquery->fetch_assoc();
list($power,$exp) = explode("/", $_SESSION['printsize']);
$pow=$power;
$expon=$exp-1;
$prntcopy=pow(2,$expon);
	
$dummypaper=ceil(($option/$prntcopy)*$_SESSION['pagescount']);

$papercost=	$prdselrow['sellprice']*ceil($dummypaper);

$quot=(int)($_SESSION['pagescount']/$prntcopy);
$reminder=$_SESSION['pagescount'] % $prntcopy;
$nofplateset=$quot;
if($reminder>0)
{
	$adplate=1;
	//$nofplateset=$nofplateset+1;	
}
if($_SESSION['backprint']=='Yes' && $_SESSION['samematter']=='No')
{
	$nofplateset=$nofplateset*2;
	if(($prntcopy/2) < ($reminder))
	{
		$adplate=$adplate+1;
	}
}
	
$totalplate=($nofplateset+$adplate)*4;	




               //Maincalculation
			   
			   $mchprice=$db->execute("select * from other_settings where id='5'");
			   $mchqro=$mchprice->fetch_assoc();
			   $totalplatecost=$totalplate*$mchqro['amount'];
			   $mchqry=$db->execute("select * from machines_table where id='".$_SESSION['machineid']."'");
			   $mqro=$mchqry->fetch_assoc();
			   $basicimpression=$totalplate*$mqro['impression_charge'];
			   $mchpriceo=$db->execute("select * from other_settings where id='6'");
			   $mchqroo=$mchpriceo->fetch_assoc();
			   
			   
			   
			   
			   
			   
			   
			   
	//calculating additional impression charge		   
			   
	if($dummypaper>1000)
    {
       $cppy=$dummypaper/1000;  
       $cppy=ceil($cppy)-1;
       $ttamt=$cppy*$mqro['additional_impression_charge'];   
       $additionalimpression=$ttamt*$totalplate;
    }
   
    
    
    
    if($_SESSION['samematter']=='No')
    {
        if($dummypaper>1000)
  			  {
					$plateset=$totalplate/4;
					$eachpageset=$dummypaper/$plateset;
						if($eachpageset>1000)
 						   {
    						   $cppy=$eachpageset/1000;  
    						   $cppy1=ceil($cppy)-1;
     						   
							   if(($prntcopy/2) >= ($reminder))
									{
										$extra=ceil($cppy)*$mqro['additional_impression_charge']*4;
									} 
									 $ttamt=$cppy1*$mqro['additional_impression_charge']; 
      						         $vipin=$ttamt*$totalplate/4;
									 $vipin=$vipin+$extra;
   							}
    			}
    }
    if($_SESSION['samematter']=='Yes')
    {
		if($eachpageset>1000)
		   {
    						   $cppy=$eachpageset/1000;  
    						   $cppy=ceil($cppy)-1;
     						   $ttamt=$cppy*$mqro['additional_impression_charge'];   
      						   $vipin=$ttamt*$totalplate;
			}
				
		
		
		
		
		
      			  //$count=$dummypaper/1000;  
      			  //$count=ceil($count);
      			  //$additamt=($count+($count-1))*$mqro['additional_impression_charge']*$totalplate;
		//$pricesaa= ($additamt*$totalplate);
    }
			   
			   
			   
			   
			   
			   
			   
echo $vipin ;			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   

?>