<?php
session_start();
ob_start();
require "../model/configuration.php";

$nofplateset = 0;
$ttamt = 0;
$ttamta = 0;
$extra = 0;
$impressioncharge = 0;
$totalnoofcopy = $_POST['get_option']; //Total Number of Copys
if($_SESSION['machineid']=='1') 
{
	echo 'Machine 1';
}
elseif($_SESSION['machineid']=='2') 
{
	








$prdselquery = $db->execute("select * from products where productcode='" . $_SESSION['prdcode'] . "'");
$prdselrow = $prdselquery->fetch_assoc();
list($power, $exp) = explode("/", $_SESSION['printsize']);
$pow = $power;
$expon = $exp;
$printingsize = $expon;

// Dummy Paper Calculation Start

$decvalue = ($_SESSION['pagescount'] / $printingsize);
$paperdevide = $decvalue;
$oldcalculation = ($totalnoofcopy / $printingsize);
list($actval, $decval) = explode(".", $decvalue);
$decimalvalue = "0." . $decval;

if ($decimalvalue > '0.5')
    {
    $dummypaper = ceil($paperdevide) * $totalnoofcopy;
    $decvalues = ceil($decvalue);
    }
  else
    {
    $dumcalc = ($paperdevide) * $totalnoofcopy;
    $dummypaper = round($dumcalc);
    $decvalues = round($decvalue, 2);
    }

// Dummy Paper Calculation End
// ceil(($totalnoofcopy/$printingsize)*$_SESSION['pagescount']);
// Paper Coast Start

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

// Paper Coast End
// Plate Calculation Start

$quot = (int)($paperdevide);
$reminder = $_SESSION['pagescount'] % $printingsize;
$nofplateset = $quot;
$platesets=$_SESSION['colourcount'];
if ($reminder > 0)
    {
    $adplate = 1;

    // $nofplateset=$nofplateset+1;

    }

if ($_SESSION['backprint'] == 'Yes' && $_SESSION['samematter'] == 'No')
    {
    $nofplateset = $nofplateset * $platesets;
    if (($printingsize / 2) < ($reminder))
        {
        $adplate = $adplate + 1;
        }
    }

$totalplate = ($nofplateset + $adplate) * $platesets;

// Plate Calculation End
// 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']) * $platesets;
        }

    for ($i = 0; $i < $adquot; $i++)
        {
        $adimchrg = ($dividereslt / 1000) - 1;
        $impressioncharge1 = $impressioncharge1 + (($adimchrg * $mqro['additional_impression_charge']) * $platesets);
        }
    }
  else
    {
    $additionalimpression = 0;
    }

if ($_SESSION['backprint'] == 'Yes')
    {
    if ($_SESSION['samematter'] == 'No')
        {
        if ($dummypaper > 1000)
            {
            $plateset = $totalplate / $platesets;
            $eachpageset = $dummypaper / $plateset;
            if ($eachpageset > 1000)
                {
                $cppy = $eachpageset / 1000;
                 $cppy = ceil($cppy) - 1;
                if (($printingsize / 2) >= ($reminder))
                    {
                    $extra = ceil($cppy) * $mqro['additional_impression_charge'] * $platesets;
                    }
                $ttamt = $cppy * $mqro['additional_impression_charge'];
                $vipin = $ttamt * $totalplate / $platesets;
                $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;
            }
        }
    }
  else
    {
    $vipin = $basicimpression + $impressioncharge;
    }

$total_price = ($dummypaper / 2) * $prdselrow['sellprice'];
$_SESSION['papercoast'] = $total_price;
$_SESSION['dummypaper'] = $dummypaper;
$_SESSION['printamt'] = $vipin;
$_SESSION['platecoast'] = $totalplatecost;
echo $vipin;





















}
elseif($_SESSION['machineid']=='3') 
{
$prdselquery = $db->execute("select * from products where productcode='" . $_SESSION['prdcode'] . "'");
$prdselrow = $prdselquery->fetch_assoc();
list($power, $exp) = explode("/", $_SESSION['printsize']);
$pow = $power;
$expon = $exp;
$printingsize = $expon;

// Dummy Paper Calculation Start

$decvalue = ($_SESSION['pagescount'] / $printingsize);
$paperdevide = $decvalue;
$oldcalculation = ($totalnoofcopy / $printingsize);
list($actval, $decval) = explode(".", $decvalue);
$decimalvalue = "0." . $decval;

if ($decimalvalue > '0.5')
    {
    $dummypaper = ceil($paperdevide) * $totalnoofcopy;
    $decvalues = ceil($decvalue);
    }
  else
    {
    $dumcalc = ($paperdevide) * $totalnoofcopy;
    $dummypaper = round($dumcalc);
    $decvalues = round($decvalue, 2);
    }

// Dummy Paper Calculation End
// ceil(($totalnoofcopy/$printingsize)*$_SESSION['pagescount']);
// Paper Coast Start

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

// Paper Coast End
// Plate Calculation Start

$quot = (int)($paperdevide);
$reminder = $_SESSION['pagescount'] % $printingsize;
$nofplateset = $quot;

if ($reminder > 0)
    {
    $adplate = 1;

    // $nofplateset=$nofplateset+1;

    }

if ($_SESSION['backprint'] == 'Yes' && $_SESSION['samematter'] == 'No')
    {
    $nofplateset = $nofplateset * 2;
    if (($printingsize / 2) < ($reminder))
        {
        $adplate = $adplate + 1;
        }
    }

$totalplate = ($nofplateset + $adplate) * 4;

// Plate Calculation End
// 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);
        $impressioncharge1 = ($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 (($printingsize / 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;
            }
        }
    }
  else
    {
    $vipin = $basicimpression + $impressioncharge1;
    }

$total_price = ($dummypaper / 2) * $prdselrow['sellprice'];
$_SESSION['papercoast'] = $total_price;
$_SESSION['dummypaper'] = $dummypaper;
$_SESSION['printamt'] = $vipin;
$_SESSION['platecoast'] = $totalplatecost;
echo $totalplate;// . "-" . $dummypaper;
}
?>