<?php

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

$formname = 'CHALLAN / BILL';
$maindb = 'challan';
// $trandb = 'saletran';
$file = 'chal_pdf.php';
$source = "";
$zcomp = $_SESSION["comp_" . $dbname];

$zdb = $_SESSION["zdbyear_" . $dbname];
$zroot = $_SESSION["zdir"];
mysqli_select_db($conn, $zdb);

$mht = 'height:20px;';
$admin = $_SESSION["admin_" . $dbname];
$vouchno = $_REQUEST["vouchno"];

$result = mysqli_query($conn, "SELECT *, DATE_FORMAT(`vouchdt`, '%d-%m-%Y') as mydt,
 DATE_FORMAT(`frmdt`, '%d-%m-%Y') as fdt, DATE_FORMAT(`todt`, '%d-%m-%Y') as tdt FROM `$maindb` WHERE vouchno='$vouchno' ") or die(mysqli_error($conn));
$get = mysqli_fetch_array($result);
if ($get['type'] == 'H') {
    $type = "Hours";
} else {
    $type = "Lumsum";
}

$imgpath = $get['imgpath'];
$getparty = mysqli_query($conn, "SELECT `accode`,`name` FROM `accmast` WHERE `accode`= '$get[accode]'") or die(mysqli_error($conn));
$lparty = mysqli_fetch_array($getparty);

$getanch = mysqli_query($conn, "SELECT `name` FROM `port` WHERE `code`= '$get[anchor]'") or die(mysqli_error($conn));
$fanch = mysqli_fetch_array($getanch);

$getlaunch = mysqli_query($conn, "SELECT `name` FROM `launch` WHERE `code`= '$get[launch]'") or die(mysqli_error($conn));
$flaunch = mysqli_fetch_array($getlaunch);


$cmpname = mysqli_query($conn, "SELECT * From $zroot.`company` where code ='$zcomp'") or die(mysqli_error($conn));
$getcmpname = mysqli_fetch_array($cmpname);
$logo = $getcmpname['logoimg'];

$gcust = mysqli_query($conn, "SELECT accode,name,gstno,add1,add2,add3,state,statecode,city,pin   FROM `accmast` WHERE `accode`='$getmdata[party]'") or die(mysqli_error($conn));
$cust = mysqli_fetch_array($gcust);

require("library/fpdf/fpdf.php");

class pdf extends fpdf
{

    function Footer()
    {
        $this->SetY(-15);
        $this->SetFont('Arial', 'I', 8);

    }
}

//browse('udar');

$pdf = new pdf('P', 'mm', 'A4');

$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetTitle('FAVOURITE');
$pdf->SetTextColor(0, 0, 0);

$pdf->SetFont('Arial', '', 9);
$pdf->SetTextColor(0, 0, 0);

$ht = 6;
$ln = 6;
$nl = 8;
$imageFile = 'images/fls1.jpg';
$pdf->Image($imageFile, 10, 5, 35, 25);

$pdf->SetFont('Arial', 'B', 18);
$pdf->Cell(190, $ht, "$getcmpname[compname]", 0, 0, 'C');
// $pdf->Cell(45, $ln, "Office -" . "$getcmpname[htel]", 0, 0, 'R');
$pdf->Ln($ln);

$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(190, $ht, "Launch Tug Owners & Operators", 0, 0, 'C');
$pdf->Ln($ln);

$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(190, $ln, "$getcmpname[hoadd1] $getcmpname[hoadd2] $getcmpname[hoadd3]", 0, 0,'C');
$pdf->Ln($ln);

$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(190, $ln, "Email : $getcmpname[email]" . " Office : $getcmpname[htel]" . " Phone : $getcmpname[hmob]", 0, 0,'C');
$pdf->Ln($ln);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(10, $ln, "No : ", 0, 0,'L');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(30, $ln, "$vouchno", 0, 0,'L');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(125, $ln, "Date : ", 0, 0,'R');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(25, $ln, "$get[mydt]", 'B', 0,'R');
$pdf->Ln($nl);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(45, $ln, "Service Rendered to M/s : ", 0, 0,'L');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(145, $ln, "$lparty[name]", 'B', 0,'L');
$pdf->Ln($nl);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(18, $ln, "Ordered By. ", 0, 0,'L');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(110, $ln, "$get[ordby]", 'B', 0,'L');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(12, $ln, "Anch. ", 0, 0,'L');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(50, $ln, "$fanch[name]", 'B', 0,'L');
$pdf->Ln($nl);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(18, $ln, "Purpose", 0, 0,'L');
$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(172, $ln, "$get[purpose] " . "$get[purpose2]" , 'B', 0,'L');
$pdf->Ln($ln);

$pdf->SetFont('Arial', 'B', 12);
$pdf->Cell(190, $ln, "$get[purpose3] " . "$get[purpose4]", 'B', 0,'L');
$pdf->Ln($ln);

$pdf->Cell(190, $ln, "", 'B', 0,'L');
$pdf->Ln($ln);
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(15, $ln, "Launch", 0, 0,'L');
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(30, $ln, "$flaunch[name]", 'B', 0,'L');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(10, $ln, "From", 0, 0,'L');
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(20, $ln, "$get[fdt]", 'BT', 0,'L');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(8, $ln, "To", 0, 0,'C');
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(20, $ln, "$get[tdt]", 'BT', 0,'L');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(12, $ln, "Hours", 0, 0,'L');
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(15, $ln, "$get[nohrs] . $get[nomin]", 'BT', 0,'L');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(10, $ln, "as Rs", 0, 0,'L');
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(15, $ln, "$get[rate]", 'BT', 0,'R');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(10, $ln, "P.Hr.", 0, 0,'L');
$pdf->SetFont('Arial', 'B', 10);
$pdf->Cell(25, $ln, "$get[amount]", 1, 0,'R');
$pdf->Ln($nl);
$pdf->Ln($nl);
$pdf->Ln($nl);
$pdf->Ln($nl);

$pdf->SetFont('Arial', '', 10);
$pdf->Cell(15, $ln, "Sign", 0, 0,'L');
$pdf->Cell(40, $ln, "", 'B', 0,'L');

$pdf->Cell(75, $ln, "For", 0, 0,'R');
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(60, $ln, "$getcmpname[compname]", 'B', 0,'R');

$y_aqui = $pdf->Gety();
$y_aqui2 = $pdf->Gety();

ob_end_clean();
$pdf->Output("$formname - $lparty[name]-" . $getmdata['vouchno'] . ".pdf", "I");
