<?php
session_start();
ob_start();
require "../model/configuration.php";
$nofplateset=0;
$ttamt=0;
$ttamta=0;
$extra=0;
$impressioncharge=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;
$prntcopy=$expon;


$decvalue=($_SESSION['pagescount'] / $prntcopy);

list($actval,$decval) = explode(".", $decvalue);

$decimalvalue="0.".$decval;

if($decimalvalue>'0.5')
{
    $dummypaper=  ceil($_SESSION['pagescount'] / $prntcopy) * $option;
    $decvalues=ceil($decvalue);
}
else{
	$dumcalc=($_SESSION['pagescount'] / $prntcopy) * $option;
    $dummypaper= round($dumcalc);
    $decvalues=round($decvalue,2);
}
 //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)
    {
        $devident = ($decvalues * 100);
        $devider = $dummypaper * 100;
        $dividereslt = $devider / $devident;
        $adquot = round($dummypaper / $dividereslt);
        $valreminder=($dummypaper % $dividereslt);
    if($valreminder>1000)
    {
        $a = ceil(($valreminder/1000)-1);
        $impressioncharge = ($a * $mqro['additional_impression_charge'])*4;
    }
        for($i=0; $i<$adquot; $i++)
        {
            $adimchrg = ($dividereslt / 1000) - 1;
            $impressioncharge = $impressioncharge + (($adimchrg * $mqro['additional_impression_charge']) * 4);
        }
        
       
       
    }
    else{
        $additionalimpression=0;
    }
   
    
  if($_SESSION['backprint']=='Yes')
  {  
    
    if($_SESSION['samematter']=='No')
    {
        if($dummypaper>1000)
  			  {
					$plateset=$totalplate/4;
					$eachpageset=$dummypaper/$plateset;
						if($eachpageset>1000)
 						   {
    						   $cppy=$eachpageset/1000;  
    						   $cppy=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);
    }
}
else
{
    $vipin = $basicimpression+$impressioncharge;
}			   
			   
			   
			   
			   
			   
			   
echo $dummypaper."-".$vipin ;//$totalplate."-".			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   
			   

?>