<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

try {

    include_once('../../../classes/manager.class.php');
    include_once('../../../classes/PHPMailer/PHPMailerAutoload.php');
    include_once('../../../fpdf/fpdf1.php');

    $m = new Manager();

    if (!isset($_SESSION['sess_userid'])) {
        header("Location: " . PROJECT_ADMIN_URL);
        exit();
    }

    $cat_type    = isset($_GET['cat_type']) ? $_GET['cat_type'] : 'All';
    $status_type = isset($_GET['status_type']) ? $_GET['status_type'] : 'All';

    $param_data = ControlConfifguration::GetConfiguration();
    define('PROJECT_NAME', $param_data->name);
    define('PROJECT_ADDRESS', $param_data->address);
    define('PROJECT_TEL', $param_data->contact);
    define('PROJECT_EMAIL', $param_data->email);
    define('PROJECT_WEBSITE', $param_data->website);
    define('PROJECT_COLOR', $param_data->color);
    define('PROJECT_DISCOUNT', $param_data->is_discount);
    define('PROJECT_TAX', $param_data->is_tax);

    $filterReport = " WHERE 1 ";

    if ($cat_type != 'All') {
        $filterReport .= " AND is_mart = '" . addslashes($cat_type) . "' ";
    }

    if ($status_type != 'All') {
        $filterReport .= " AND status = '" . addslashes($status_type) . "' ";
    }

    $filterReport .= " ORDER BY name ASC ";

    $customerList = CustomerSetup::GetCustomerSetupList($filterReport);

    $pdf = new FPDFWithOutWaterMark('P', 'mm', 'A4');
    $pdf->SetMargins(8, 8, 8);
    $pdf->SetAutoPageBreak(true, 10);
    $pdf->SetTitle('Customer List Report');
    $pdf->AddPage();

    // Header
    $pdf->SetFont('Arial', 'B', 16);
    $pdf->Cell(0, 8, PROJECT_NAME, 0, 1, 'C');

    $pdf->SetFont('Arial', '', 8);
    $pdf->Cell(0, 5, 'Printed Date: ' . date('d-m-Y h:i A'), 0, 1, 'C');

    $pdf->SetFont('Arial', '', 14);
    $pdf->Cell(0, 8, 'Customer List Report', 0, 1, 'C');

    $pdf->SetFont('Arial', '', 10);
    $typeLabel = 'All';
    if ($cat_type === '0') {
        $typeLabel = 'Wholesaler';
    } elseif ($cat_type === '1') {
        $typeLabel = 'Local Mart';
    }

    $pdf->Cell(0, 5, 'Customer Type: ' . $typeLabel, 0, 1, 'C');
    $pdf->Cell(0, 5, 'Status: ' . ucfirst($status_type), 0, 1, 'C');
    $pdf->Ln(5);

    // 5-column table
    $header = array('S.No', 'Customer Name', 'Contact', 'Location', 'Status');
    $widths = array(12, 58, 35, 55, 28);

    $drawHeader = function() use ($pdf, $header, $widths) {
        $pdf->SetFont('Arial', 'B', 8);
        $pdf->SetFillColor(220, 230, 245);
        $pdf->SetTextColor(0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.2);

        for ($i = 0; $i < count($header); $i++) {
            $pdf->Cell($widths[$i], 8, $header[$i], 1, 0, 'C', true);
        }
        $pdf->Ln();
    };

    $drawHeader();

    if (!empty($customerList)) {
        $pdf->SetFont('Arial', '', 7);
        $fill = false;
        $counter = 1;

        foreach ($customerList as $row) {

            if ($pdf->GetY() > 275) {
                $pdf->AddPage();
                $drawHeader();
                $pdf->SetFont('Arial', '', 7);
            }

            $name     = isset($row->name) ? $row->name : '';
            $contact  = isset($row->contact) ? $row->contact : '';
            $location = isset($row->location) ? $row->location : '';
            $status   = isset($row->status) ? $row->status : '';

            $pdf->Cell($widths[0], 7, $counter, 1, 0, 'C', $fill);
            $pdf->Cell($widths[1], 7, $name, 1, 0, 'L', $fill);
            $pdf->Cell($widths[2], 7, $contact, 1, 0, 'L', $fill);
            $pdf->Cell($widths[3], 7, $location, 1, 0, 'L', $fill);
            $pdf->Cell($widths[4], 7, $status, 1, 1, 'C', $fill);

            $fill = !$fill;
            $counter++;
        }
    } else {
        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(array_sum($widths), 8, 'No Customers Found', 1, 1, 'C');
    }

    $pdf->Output();
    exit;

} catch (Exception $e) {
    echo $e->getMessage();
}
?><?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

try {

    include_once('../../../classes/manager.class.php');
    include_once('../../../classes/PHPMailer/PHPMailerAutoload.php');
    include_once('../../../fpdf/fpdf1.php');

    $m = new Manager();

    if (!isset($_SESSION['sess_userid'])) {
        header("Location: " . PROJECT_ADMIN_URL);
        exit();
    }

    $cat_type    = isset($_GET['cat_type']) ? $_GET['cat_type'] : 'All';
    $status_type = isset($_GET['status_type']) ? $_GET['status_type'] : 'All';

    $param_data = ControlConfifguration::GetConfiguration();
    define('PROJECT_NAME', $param_data->name);
    define('PROJECT_ADDRESS', $param_data->address);
    define('PROJECT_TEL', $param_data->contact);
    define('PROJECT_EMAIL', $param_data->email);
    define('PROJECT_WEBSITE', $param_data->website);
    define('PROJECT_COLOR', $param_data->color);
    define('PROJECT_DISCOUNT', $param_data->is_discount);
    define('PROJECT_TAX', $param_data->is_tax);

    $filterReport = " WHERE 1 ";

    if ($cat_type != 'All') {
        $filterReport .= " AND is_mart = '" . addslashes($cat_type) . "' ";
    }

    if ($status_type != 'All') {
        $filterReport .= " AND status = '" . addslashes($status_type) . "' ";
    }

    $filterReport .= " ORDER BY name ASC ";

    $customerList = CustomerSetup::GetCustomerSetupList($filterReport);

    $pdf = new FPDFWithOutWaterMark('P', 'mm', 'A4');
    $pdf->SetMargins(8, 8, 8);
    $pdf->SetAutoPageBreak(true, 10);
    $pdf->SetTitle('Customer List Report');
    $pdf->AddPage();

    // Header
    $pdf->SetFont('Arial', 'B', 16);
    $pdf->Cell(0, 8, PROJECT_NAME, 0, 1, 'C');

    $pdf->SetFont('Arial', '', 8);
    $pdf->Cell(0, 5, 'Printed Date: ' . date('d-m-Y h:i A'), 0, 1, 'C');

    $pdf->SetFont('Arial', '', 14);
    $pdf->Cell(0, 8, 'Customer List Report', 0, 1, 'C');

    $pdf->SetFont('Arial', '', 10);
    $typeLabel = 'All';
    if ($cat_type === '0') {
        $typeLabel = 'Wholesaler';
    } elseif ($cat_type === '1') {
        $typeLabel = 'Local Mart';
    }

    $pdf->Cell(0, 5, 'Customer Type: ' . $typeLabel, 0, 1, 'C');
    $pdf->Cell(0, 5, 'Status: ' . ucfirst($status_type), 0, 1, 'C');
    $pdf->Ln(5);

    // 5-column table
    $header = array('S.No', 'Customer Name', 'Contact', 'Location', 'Status');
    $widths = array(12, 58, 35, 55, 28);

    $drawHeader = function() use ($pdf, $header, $widths) {
        $pdf->SetFont('Arial', 'B', 8);
        $pdf->SetFillColor(220, 230, 245);
        $pdf->SetTextColor(0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.2);

        for ($i = 0; $i < count($header); $i++) {
            $pdf->Cell($widths[$i], 8, $header[$i], 1, 0, 'C', true);
        }
        $pdf->Ln();
    };

    $drawHeader();

    if (!empty($customerList)) {
        $pdf->SetFont('Arial', '', 7);
        $fill = false;
        $counter = 1;

        foreach ($customerList as $row) {

            if ($pdf->GetY() > 275) {
                $pdf->AddPage();
                $drawHeader();
                $pdf->SetFont('Arial', '', 7);
            }

            $name     = isset($row->name) ? $row->name : '';
            $contact  = isset($row->contact) ? $row->contact : '';
            $location = isset($row->location) ? $row->location : '';
            $status   = isset($row->status) ? $row->status : '';

            $pdf->Cell($widths[0], 7, $counter, 1, 0, 'C', $fill);
            $pdf->Cell($widths[1], 7, $name, 1, 0, 'L', $fill);
            $pdf->Cell($widths[2], 7, $contact, 1, 0, 'L', $fill);
            $pdf->Cell($widths[3], 7, $location, 1, 0, 'L', $fill);
            $pdf->Cell($widths[4], 7, $status, 1, 1, 'C', $fill);

            $fill = !$fill;
            $counter++;
        }
    } else {
        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(array_sum($widths), 8, 'No Customers Found', 1, 1, 'C');
    }

    $pdf->Output();
    exit;

} catch (Exception $e) {
    echo $e->getMessage();
}
?><?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

try {

    include_once('../../../classes/manager.class.php');
    include_once('../../../classes/PHPMailer/PHPMailerAutoload.php');
    include_once('../../../fpdf/fpdf1.php');

    $m = new Manager();

    if (!isset($_SESSION['sess_userid'])) {
        header("Location: " . PROJECT_ADMIN_URL);
        exit();
    }

    $cat_type    = isset($_GET['cat_type']) ? $_GET['cat_type'] : 'All';
    $status_type = isset($_GET['status_type']) ? $_GET['status_type'] : 'All';

    $param_data = ControlConfifguration::GetConfiguration();
    define('PROJECT_NAME', $param_data->name);
    define('PROJECT_ADDRESS', $param_data->address);
    define('PROJECT_TEL', $param_data->contact);
    define('PROJECT_EMAIL', $param_data->email);
    define('PROJECT_WEBSITE', $param_data->website);
    define('PROJECT_COLOR', $param_data->color);
    define('PROJECT_DISCOUNT', $param_data->is_discount);
    define('PROJECT_TAX', $param_data->is_tax);

    $filterReport = " WHERE 1 ";

    if ($cat_type != 'All') {
        $filterReport .= " AND is_mart = '" . addslashes($cat_type) . "' ";
    }

    if ($status_type != 'All') {
        $filterReport .= " AND status = '" . addslashes($status_type) . "' ";
    }

    $filterReport .= " ORDER BY name ASC ";

    $customerList = CustomerSetup::GetCustomerSetupList($filterReport);

    $pdf = new FPDFWithOutWaterMark('P', 'mm', 'A4');
    $pdf->SetMargins(8, 8, 8);
    $pdf->SetAutoPageBreak(true, 10);
    $pdf->SetTitle('Customer List Report');
    $pdf->AddPage();

    // Header
    $pdf->SetFont('Arial', 'B', 16);
    $pdf->Cell(0, 8, PROJECT_NAME, 0, 1, 'C');

    $pdf->SetFont('Arial', '', 8);
    $pdf->Cell(0, 5, 'Printed Date: ' . date('d-m-Y h:i A'), 0, 1, 'C');

    $pdf->SetFont('Arial', '', 14);
    $pdf->Cell(0, 8, 'Customer List Report', 0, 1, 'C');

    $pdf->SetFont('Arial', '', 10);
    $typeLabel = 'All';
    if ($cat_type === '0') {
        $typeLabel = 'Wholesaler';
    } elseif ($cat_type === '1') {
        $typeLabel = 'Local Mart';
    }

    $pdf->Cell(0, 5, 'Customer Type: ' . $typeLabel, 0, 1, 'C');
    $pdf->Cell(0, 5, 'Status: ' . ucfirst($status_type), 0, 1, 'C');
    $pdf->Ln(5);

    // 5-column table
    $header = array('S.No', 'Customer Name', 'Contact', 'Location', 'Status');
    $widths = array(12, 58, 35, 55, 28);

    $drawHeader = function() use ($pdf, $header, $widths) {
        $pdf->SetFont('Arial', 'B', 8);
        $pdf->SetFillColor(220, 230, 245);
        $pdf->SetTextColor(0);
        $pdf->SetDrawColor(0, 0, 0);
        $pdf->SetLineWidth(0.2);

        for ($i = 0; $i < count($header); $i++) {
            $pdf->Cell($widths[$i], 8, $header[$i], 1, 0, 'C', true);
        }
        $pdf->Ln();
    };

    $drawHeader();

    if (!empty($customerList)) {
        $pdf->SetFont('Arial', '', 7);
        $fill = false;
        $counter = 1;

        foreach ($customerList as $row) {

            if ($pdf->GetY() > 275) {
                $pdf->AddPage();
                $drawHeader();
                $pdf->SetFont('Arial', '', 7);
            }

            $name     = isset($row->name) ? $row->name : '';
            $contact  = isset($row->contact) ? $row->contact : '';
            $location = isset($row->location) ? $row->location : '';
            $status   = isset($row->status) ? $row->status : '';

            $pdf->Cell($widths[0], 7, $counter, 1, 0, 'C', $fill);
            $pdf->Cell($widths[1], 7, $name, 1, 0, 'L', $fill);
            $pdf->Cell($widths[2], 7, $contact, 1, 0, 'L', $fill);
            $pdf->Cell($widths[3], 7, $location, 1, 0, 'L', $fill);
            $pdf->Cell($widths[4], 7, $status, 1, 1, 'C', $fill);

            $fill = !$fill;
            $counter++;
        }
    } else {
        $pdf->SetFont('Arial', 'B', 10);
        $pdf->Cell(array_sum($widths), 8, 'No Customers Found', 1, 1, 'C');
    }

    $pdf->Output();
    exit;

} catch (Exception $e) {
    echo $e->getMessage();
}
?>