<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

//require_once('library/fpdf/fpdf.php');
$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$zroot = $_SESSION["zdir"];

$compcd = $_SESSION["comp_" . $dbname];
$series = $_SESSION["series_" . $dbname];

$maindb = '';
$trandb = '';
$mvouch = $_REQUEST["code"];

if ($_GET["para"] == 3) {
    $mvouchdt = date("Y-m-d");
    $maindb = 'item';
    $trandb = '';
}
//set printing preference 
//width=35mm;
//height=38mm

//$getcomp = mysqli_query($conn, "SELECT custcare FROM $zroot.`company`") or die(mysqli_error($conn));
//$fetcomp = mysqli_fetch_array($getcomp);
//$custcare = $fetcomp['custcare'];

if ($_GET["para"] == 3) {
//    require("includes/dbconnect.php");
    $cmain = mysqli_query($conn, "SELECT * FROM `$maindb` WHERE code='$mvouch'") or die(mysqli_error($conn));
    $num = $_GET["number"];
    $xnum = $num - 1;
    $gcomp = mysqli_query($conn, "SELECT * FROM $zroot.`company`") or die(mysqli_error($conn));
    $fcomp = mysqli_fetch_object($gcomp);
}
$ctr = 0;
$breaker = 1;
require ('library/fpdf/code128.php');
$pdf = new PDF_Code128('P', 'mm', array(38, 53));

while ($ctmp = mysqli_fetch_object($cmain)) {
    $ctr++;
    if ($_GET["para"] == 3) {
        $num_qty = $_GET["number"];
        $itemname = $ctmp->name;
        $mrp = $ctmp->mrp;
        $barcode = $ctmp->barcode;
        $monthname = $ctmp->monthname;
        $yearname = $ctmp->yearname;
    } else {
        $num_qty = $ctmp->qty;
        $itemcode = $ctmp->itemcode;
        $citemname = mysqli_query($conn, "SELECT * FROM `item` WHERE code='$itemcode' ") or die(mysqli_error($conn));
        $fitemname = mysqli_fetch_array($citemname);
        $itemname = $fitemname['name'];
        $barcode = $fitemname['code'];
        $mrp = $ctmp->mrp;
    }

    for ($i = 1; $i <= $num_qty; $i++) {

        $pdf->AddPage();
        $pdf->SetXY("2", '3');


        $pdf->SetFont('Arial', 'B', 7);

//        $pdf->Cell(10, 0, 'Mfgd.By', 0);
//        $pdf->Cell(0, 0, $fcomp->pname, 0);
//        $pdf->Cell(20,10,'Title',1,1,'C');

        $pdf->Cell(35, 0, 'B IRRA FRAGRANCES LLP.', 0,0,'C');
        $pdf->SetFont('Arial', 'B', 5);
//        $pdf->Cell(0, 0, $fcomp->pname, 0);
        $pdf->Ln(3);
        $pdf->SetX('2');
//        $pdf->Cell(10, 0, 'Address', 0);
//        $pdf->Cell(5, 0, '', 0);
//        $pdf->Cell(3, 0, 'GALA NO.1, BLDG NO.C-8,', 0);
//        $pdf->SetFont('Arial', 'B', 5);
//        $pdf->Ln(2);
//        $pdf->SetX('2');
////        $pdf->Cell(10, 0, '', 0);
//        $pdf->Cell(5, 0, '', 0);
//        $pdf->Cell(3, 0, 'PURNA VILLAGE, THAN-421302', 0);
//        $pdf->SetFont('Arial', 'B', 4.5);
//        $pdf->Ln(2);
//        $pdf->SetX('2');

        $itemname1 = substr($itemname, 0, 18);
        $itemname2 = substr($itemname, 18, 40);
        $pdf->SetFont('Arial', 'B', 5);

        $pdf->Cell(10, 0, 'Product', 0);
        $pdf->SetFont('Arial', 'B', 6);

        $pdf->Cell(0, 0, $itemname1, 0);
        $pdf->Ln(2);
        $pdf->SetX('2');

        $pdf->Cell(10, 0, '', 0);
        $pdf->Cell(0, 0, $itemname2, 0);
        $pdf->Ln(2);
        $pdf->SetX('2');
        $pdf->SetFont('Arial', 'B', 5);

        
        
        $pdf->Cell(10, 0, 'Mfg.Date', 0);
        $pdf->Cell(3, 0, $ctmp->monthname . "  " . $ctmp->yearname, 0);
        $pdf->SetFont('Arial', 'B', 4.5);
        $pdf->Ln(2);
        $pdf->SetX('2');

        $pdf->Cell(10, 0, 'M.R.P', 0);
        $pdf->SetFont('Arial', 'B', 6.5);
        $pdf->Cell(12, 0, $ctmp->mrp, 0);
        $pdf->SetFont('Arial', 'B', 4.5);

        $pdf->Cell(8, 0, '(Incl.All Taxes)', 0);
        $pdf->SetFont('Arial', 'B', 5);
        $pdf->Ln(2);
        $pdf->SetX('2');

        $pdf->Cell(10, 0, 'Net Qty.', 0);
        $pdf->SetFont('Arial', 'B', 6.5);
        $pdf->Cell(0, 0, $ctmp->netqty, 0);
        $pdf->SetFont('Arial', 'B', 5);

        $pdf->Ln(2);
        $pdf->SetX('2');

        $pdf->Cell(10, 0, 'Cust.Care', 0);
        $pdf->Cell(0, 0, $fcomp->custcare, 0);
        $pdf->Ln(2);
        $pdf->SetX('2');

        $pdf->Cell(10, 0, 'Email Id', 0);
        $pdf->Cell(0, 0, $fcomp->email, 0);
        $pdf->Ln(2);
        $pdf->SetX('2');



        $pdf->GetY();
//                $pdf->Cell(14, 0, $pdf->GetX(), 0);
        $pdf->SetFont('Arial', '', 5);

        $pdf->Code128(3, $pdf->GetY(), $barcode, 32, 6);
        $pdf->Ln(2);
        $pdf->SetXY('2', $pdf->GetY());
        $pdf->Ln(6);
        $pdf->SetFont('Arial', 'B', 9);

        $pdf->Cell(0, 0, $barcode, 0, 0, 'C');
        $pdf->Ln(2);
        $pdf->SetX('2');
    }
}
$pdf->Output();
?>