<?php 
define('DOCUMENT_ROOT_CLASS','../');
define('DOCUMENT_ROOT_INC_FOLDER','');
$filepath = realpath(dirname(__FILE__));
require "../inc/header.php";
Session::CheckSession(); 
$msg = Session::get('msg');
Session::set("msg", NULL); 
if(!empty($_POST)){
    $error_ = 0;
    if(empty($_POST['vendor_code'])){
        Session::set('msg', '<div class="alert alert-danger alert-dismissible mt-3" id="flash-msg"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Error !</strong> Please enter code !</div>');
    }else{
        $cntA = $commonFunctions->getRowData('vndr_details',' WHERE vendor_code = "'.$_POST['vendor_code'].'" ');
        if(@count($cntA) > 1){
           $error_ = 1;
           Session::set('msg', '<div class="alert alert-danger alert-dismissible mt-3" id="flash-msg"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Error !</strong> Customer code already exists !</div>');
        }
    }

    if(!empty($_POST['vendor_code']) and $error_ == 0){
        if($_GET['action'] == "add"){
            $column = $fileName = "";
            if($_FILES["logo"]){
                $target_dir = "../uploads/vendor/";
                $target_file = $target_dir . basename($_FILES["logo"]["name"]);
                $uploadOk = 1;
                $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
                getimagesize($_FILES["logo"]["tmp_name"]);
                if(move_uploaded_file($_FILES["logo"]["tmp_name"], $target_file)){
                    $column = " ,logo";
                    $fileName = " , '".$_FILES["logo"]["name"]."'";
                }
            }
            $custcats = @implode(',', $_POST['custcats']);
            $commonFunctions->addData('vndr_details'," (name,alias_name,client_type,customer_code,vendor_type,vendor_code,status,barcode,address,postcode,city,country,state,email,web,phone,fax,professional_id_1,professional_id_2,professional_id_3,professional_id_4,professional_id_5,professional_id_6,sales_tax_use,sales_tax_id,type_of_company,staff,entity_type,capital,incoterm_id,customer_cat,currency,assigned_to_sales".$column.") VALUES ('".$_POST['name']."','".$_POST['alias_name']."','".$_POST['client']."','".$_POST['customer_code']."','".$_POST['fournisseur']."','".$_POST['vendor_code']."','".$_POST['status']."','".$_POST['barcode']."','".$_POST['address']."','".$_POST['postcode']."','".$_POST['city']."','".$_POST['country']."','".$_POST['state']."','".$_POST['email']."','".$_POST['web']."','".$_POST['phone']."','".$_POST['fax']."','".$_POST['professional_id_1']."','".$_POST['professional_id_2']."','".$_POST['professional_id_3']."','".$_POST['professional_id_4']."','".$_POST['professional_id_5']."','".$_POST['professional_id_6']."','".$_POST['sales_tax_use']."','".$_POST['sales_tax_id']."','".$_POST['type_of_company']."','".$_POST['staff']."','".$_POST['entity_type']."','".$_POST['capital']."','".$_POST['incoterm_id']."','".$custcats."','".$_POST['currency']."','".$_POST['assigned_to_sales']."'".$fileName." ) ",'vendor.php?state=form');
        }
        if($_GET['action'] == "edit"){
            $column = $fileName = "";
            if($_FILES["logo"]){
                $target_dir = "../uploads/vendor/";
                $target_file = $target_dir . basename($_FILES["logo"]["name"]);
                $uploadOk = 1;
                $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
                getimagesize($_FILES["logo"]["tmp_name"]);
                if(move_uploaded_file($_FILES["logo"]["tmp_name"], $target_file)){
                    $column = " ,logo";
                    $fileName = " ,logo = '".$_FILES["logo"]["tmp_name"]."' ";
                }
            }
            $commonFunctions->updateData('vndr_details'," WHERE name = '".$_POST['name']."' ", " alias_name='".$_POST['alias_name']."', client_type='".$_POST['client']."' , customer_code='".$_POST['customer_code']."' , vendor_type='".$_POST['fournisseur']."' , vendor_code='".$_POST['vendor_code']."' , status='".$_POST['status']."' , barcode='".$_POST['barcode']."', address='".$_POST['address']."', postcode='".$_POST['postcode']."', city='".$_POST['city']."', country='".$_POST['country']."', state='".$_POST['state']."', email='".$_POST['email']."', web='".$_POST['web']."', phone='".$_POST['phone']."', fax='".$_POST['fax']."', professional_id_1='".$_POST['professional_id_1']."', professional_id_2='".$_POST['professional_id_2']."', professional_id_3='".$_POST['professional_id_3']."', professional_id_4='".$_POST['professional_id_4']."', professional_id_5='".$_POST['professional_id_5']."', professional_id_6='".$_POST['professional_id_6']."', sales_tax_use='".$_POST['sales_tax_use']."', sales_tax_id='".$_POST['sales_tax_id']."', type_of_company='".$_POST['type_of_company']."', staff='".$_POST['staff']."', entity_type='".$_POST['entity_type']."', capital='".$_POST['capital']."', incoterm_id='".$_POST['incoterm_id']."', currency='".$_POST['currency']."', assigned_to_sales='".$_POST['assigned_to_sales']."'".$fileName,'vendor.php?state=form');
        }
    }else{
        echo "<script>location.href='vendor.php?state=form';</script>";
    }
}
?>    

<!-- Page-Title -->
<div class="row">
    <div class="col-sm-12">
        <div class="page-title-box">
            <div class="row">
                <div class="col">
                    <h4 class="page-title">Vendor & Suppliers</h4>
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="javascript:void(0);">Vendor & Suppliers</a></li>
                        <li class="breadcrumb-item"><a href="javascript:void(0);">Vendor & Suppliers <?php echo (!empty($_GET['state']) and $_GET['state'] == "form")?" Form ":" List "; ?></a></li>
                    </ol>
                </div><!--end col-->
                <!-- <div class="col-auto align-self-center">
                    <a href="#" class="btn btn-sm btn-outline-primary" id="Dash_Date">
                        <span class="day-name" id="Day_Name">Today:</span>&nbsp;
                        <span class="" id="Select_date">Jan 11</span>
                        <i data-feather="calendar" class="align-self-center icon-xs ml-1"></i>
                    </a>
                    <a href="#" class="btn btn-sm btn-outline-primary">
                        <i data-feather="download" class="align-self-center icon-xs"></i>
                    </a>
                </div> --><!--end col-->  
            </div><!--end row-->                                                              
        </div><!--end page-title-box-->
    </div><!--end col-->
</div><!--end row-->
<!-- end page title end breadcrumb -->
<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header">
                <h4 class="card-title">Vendor & Suppliers <?php echo (!empty($_GET['state']) and $_GET['state'] == "form")?" Form ":" List "; ?></h4>
                <?php echo !empty($msg)?$msg:''; ?>        
                <?php echo !empty($msg1)?$msg1:''; ?>        
            </div>
    
            <div class="card-body">
                <div class="row">
                    <div class="col-md-12">
                        <div class="main-card mb-3 ">
                            <!-- <div class="card-body"> -->
                                <?php if(!empty($_GET['state']) and $_GET['state'] == "form"): ?>
                                    <form enctype="multipart/form-data" action="vendor.php?state=form&action=add" method="post" name="formsoc" autocomplete="off">      
                                        <div class="form-row">
                                            <input type="hidden" name="action" value="add">

                                            <div class="position-relative form-group col-md-4">
                                                <label for="code" class="">Third-Party Name <span class="error">*</span></label>
                                                <input type="text" maxlength="128" name="name" id="name" value="" autofocus="autofocus" class="form-control">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="code" class=""> Alias Name (Commercial, Trademark, ...) <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="alias_name" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="code" class=""> Prospect / Customer <span class="error">*</span></label>
                                                <select class="flat form-control" name="client" id="customerprospect">
                                                    <option value="2">Prospect</option>
                                                    <option value="3" selected="">Prospect / Customer</option>
                                                    <option value="1">Customer</option>
                                                    <option value="0">Not Prospect, or Customer</option>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="code" class=""> Customer Code <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="customer_code" value="CUST-<?php echo @$commonFunctions->getRowDataCount('vndr_details','');?>">
                                            </div>
                                            <input type="hidden" name="fournisseur" value="1">
                                            <!-- <div class="position-relative form-group col-md-4">
                                                <label for="code" class=""> Vendor <span class="error">*</span></label>
                                                <select class="flat form-control" id="fournisseur" name="fournisseur">
                                                    <option value="1">Yes</option>
                                                    <option value="0" selected="">No</option>
                                                </select>
                                            </div> -->
                                            <div class="position-relative form-group col-md-4">
                                                <label for="code" class=""> Vendor Code <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="vendor_code" value="SU-<?php echo @$commonFunctions->getRowDataCount('vndr_details','');?>">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="code" class=""> Status <span class="error">*</span></label>
                                                <select id="status" class="flat status form-control" name="status" >
                                                    <option value="0">Closed</option>
                                                    <option value="1" selected="">Open</option>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="code" class=""> Barcode <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="barcode" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="code" class=""> Address <span class="error">*</span></label>
                                                <textarea name="address" class="form-control"></textarea>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="code" class=""> Postcode <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="postcode" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="city" class=""> City <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="city" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="city" class=""> Country <span class="error">*</span></label>
                                                <?php $countryData = $commonFunctions->getData('sys_erp_adm_countries',' WHERE active = 1 '); ?>
                                                <select name="country" id="country" class="select2 form-control" >
                                                    <option value="0">Select Country</option>
                                                    <?php foreach ($countryData as $rw) { ?>
                                                        <option value="<?php echo $rw['rowid'];?>" ><?php echo $rw['label']."(".$rw['code'].")"; ?></option>     
                                                    <?php } ?>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="city" class=""> State / Province <span class="error">*</span></label>
                                                <?php $stateData = $commonFunctions->getData('sys_erp_adm_countries_states',' WHERE active = 1 '); ?>
                                                <select name="state" id="state" class="select2 form-control" >
                                                    <option value="0">Select State / Province</option>
                                                    <?php foreach ($stateData as $rw) { ?>
                                                        <option value="<?php echo $rw['rowid'];?>" ><?php echo $rw['label']."(".$rw['region_code'].")"; ?></option>     
                                                    <?php } ?>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="email" class=""> Email <span class="error">*</span></label>
                                                <input type="email" class="form-control" name="email" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="web" class=""> Web <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="web" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="phone" class=""> Phone <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="phone" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="fax" class=""> Fax <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="fax" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="professional_id_1" class=""> Professional ID 1   <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="professional_id_1" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="professional_id_2" class=""> Professional ID 2   <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="professional_id_2" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="professional_id_3" class=""> Professional ID 3   <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="professional_id_3" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="professional_id_4" class=""> Professional ID 4   <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="professional_id_4" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="professional_id_5" class=""> Professional ID 5   <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="professional_id_5" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="professional_id_6" class=""> Professional ID 6   <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="professional_id_6" value="">
                                            </div>

                                            <div class="position-relative form-group col-md-4">
                                                <label for="sales_tax_use" class=""> Sales TAX Used <span class="error">*</span></label>
                                                <select class="flat form-control" id="fournisseur" name="sales_tax_use">
                                                    <option value="1">Yes</option>
                                                    <option value="0" selected="">No</option>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="sales_tax_id" class=""> Sales Tax/VAT ID <span class="error">*</span></label>
                                                
                                                <input type="text" class="form-control" name="sales_tax_id" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <?php $companyData = $commonFunctions->getData('vndr_type_of_company',' '); ?>
                                                <label for="type_of_company" class=""> Type of Company <span class="error">*</span></label>
                                                <select id="type_of_company" class="flat type_of_company form-control" name="type_of_company">
                                                    <option value="0">Select Type of Company</option>
                                                    <?php foreach ($companyData as $rw) { ?>
                                                        <option value="<?php echo $rw['id'];?>" ><?php echo $rw['label'];?></option>     
                                                    <?php } ?>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="staff" class=""> Staff <span class="error">*</span></label>.
                                                <?php $staffData = $commonFunctions->getData('tbl_staff',' WHERE status = 0 '); ?>
                                                <select id="staff" class="flat staff form-control" name="staff">
                                                    <option value="0">Select Staff</option>
                                                    <?php foreach ($staffData as $rw) { ?>
                                                        <option value="<?php echo $rw['rowid'];?>" ><?php echo $rw['label']."(".$rw['code'].")"; ?></option>     
                                                    <?php } ?>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="entity_type" class=""> Legal Entity Type </label>
                                                <select id="entity_type" class="flat entity_type form-control" name="entity_type">
                                                   <option value="0">Select Legal Entity Type</option>
                                                   
                                                </select>
                                            </div>

                                            <div class="position-relative form-group col-md-4">
                                                <label for="entity_type" class=""> Capital <span class="error">*</span></label>
                                                <input type="text" class="form-control" name="capital" value="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="incoterm_id" class=""> Incoterms </label>
                                                <?php $IncotermsData = $commonFunctions->getData('tbl_incoterms',' WHERE status = 0 '); ?>
                                                <select id="incoterm_id" class="flat incoterm_id form-control" name="incoterm_id">
                                                    <option value="0">Incoterm</option>
                                                    <?php foreach ($IncotermsData as $rw) { ?>
                                                        <option value="<?php echo $rw['id'];?>" ><?php echo $rw['label']."(".$rw['code'].")"; ?></option>     
                                                    <?php } ?>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="custcats" class=""> Cust./Prosp. Tags / Categories </label>
                                                <select id="custcats" name="custcats[]" class="flat custcats form-control">
                                                    <option value="0"></option>
                                                    <?php $TagData = $commonFunctions->getData('vndr_tag',''); ?>
                                                    <?php foreach ($TagData as $rw) { ?>
                                                        <option value="<?php echo $rw['id'];?>" ><?php 
                                                        if($rw['parent_id'] > 0){
                                                            echo $commonFunctions->getName($rw['parent_id'],'vndr_tag','label','id')." >> ";           
                                                        }
                                                        echo $rw['label']; ?></option>     
                                                    <?php } ?>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="currency" class=""> Currency </label>
                                                <?php $currencyData = $commonFunctions->getData('fin_accnt_currencies',' WHERE active = 1 '); ?>
                                                <select id="currency" name="currency" class="flat currency form-control">
                                                    <option value="0">Select</option>
                                                    <?php foreach ($currencyData as $rw) { ?>
                                                        <option value="<?php echo $rw['id'];?>" ><?php echo $rw['label']."(".$rw['code_iso'].")"; ?></option>     
                                                    <?php } ?>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="assigned_to_sales" class=""> Assigned to Sales Representative</label>
                                                <select id="assigned_to_sales" name="assigned_to_sales" class="flat assigned_to_sales form-control">
                                                    <option value="0"></option>
                                                </select>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="assigned_to_sales" class=""> Logo </label>
                                                <input type="file" name="logo" >
                                            </div>

                                            <div class="position-relative form-group col-md-12">
                                                <button type="submit" class="btn btn-success">Create</button>
                                                <a href="vendor.php?state=list"><button type="button" class="btn btn-danger">Back to Customer List</button></a>
                                            </div>
                                        </div>
                                    </form>
                                <?php endif; ?>
                                <?php if(empty($_GET['state']) OR (!empty($_GET['state']) and $_GET['state'] == "list")): 

                                    $targetpage = "vendor.php?state=list";

                                    $limit = 50;
                                    $total_pages = $commonFunctions->getData('vndr_details','');
                                    $total_pages = count($total_pages);
                                    $stages = 3;
                                    $page = @$_GET['page'];
                                    if($page){
                                        $start = ($page - 1) * $limit; 
                                    }else{
                                        $start = 0; 
                                    } 
                                    
                                    $where = " WHERE id ORDER BY id DESC LIMIT $start, $limit ";
                                    // Initial page num setup
                                    if ($page == 0){ $page = 1; }
                                    $prev = $page - 1;  
                                    $next = $page + 1;  
                                    $lastpage = ceil($total_pages/$limit);  
                                    $LastPagem1 = $lastpage - 1;    
                                    $paginate = '';
                                    if($lastpage > 1)
                                    {       
                                        $paginate .= "<div class='paginate'>";
                                        // Previous

                                        if ($page > 1){
                                            $paginate.= "<a href='$targetpage&page=$prev'>Previous</a>";
                                        }else{
                                            $paginate.= "<span class='disabled'>Previous</span>";   }
                                        // Pages    
                                        if ($lastpage < 7 + ($stages * 2))  // Not enough pages to breaking it up
                                        {   
                                            for ($counter = 1; $counter <= $lastpage; $counter++)
                                            {
                                                if ($counter == $page){
                                                    $paginate.= "<span class='current'>$counter</span>";
                                                }else{
                                                    $paginate.= "<a href='$targetpage&page=$counter'>$counter</a>";}    
                                            }
                                        }
                                        elseif($lastpage > 5 + ($stages * 2))   // Enough pages to hide a few?
                                        {
                                            // Beginning only hide later pages
                                            if($page < 1 + ($stages * 2))   
                                            {
                                                for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
                                                {
                                                    if ($counter == $page){
                                                        $paginate.= "<span class='current'>$counter</span>";
                                                    }else{
                                                        $paginate.= "<a href='$targetpage&page=$counter'>$counter</a>";}    
                                                }
                                                $paginate.= "...";
                                                $paginate.= "<a href='$targetpage&page=$LastPagem1'>$LastPagem1</a>";
                                                $paginate.= "<a href='$targetpage&page=$lastpage'>$lastpage</a>";
                                            }
                                            // Middle hide some front and some back
                                            elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
                                            {
                                                $paginate.= "<a href='$targetpage&page=1'>1</a>";
                                                $paginate.= "<a href='$targetpage&page=2'>2</a>";
                                                $paginate.= "...";
                                                for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
                                                {
                                                    if ($counter == $page){
                                                        $paginate.= "<span class='current'>$counter</span>";
                                                    }else{
                                                        $paginate.= "<a href='$targetpage&page=$counter'>$counter</a>";}    
                                                }
                                                $paginate.= "...";
                                                $paginate.= "<a href='$targetpage&page=$LastPagem1'>$LastPagem1</a>";
                                                $paginate.= "<a href='$targetpage&page=$lastpage'>$lastpage</a>";
                                            }
                                            // End only hide early pages
                                            else
                                            {
                                                $paginate.= "<a href='$targetpage&page=1'>1</a>";
                                                $paginate.= "<a href='$targetpage&page=2'>2</a>";
                                                $paginate.= "...";
                                                for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
                                                {
                                                    if ($counter == $page){
                                                        $paginate.= "<span class='current'>$counter</span>";
                                                    }else{
                                                        $paginate.= "<a href='$targetpage&page=$counter'>$counter</a>";}
                                                }
                                            }       
                                        }       
                                                // Next
                                        if ($page < $counter - 1){ 
                                            $paginate.= "<a href='$targetpage&page=$next'>Next</a>";
                                        }else{
                                            $paginate.= "<span class='disabled'>Next</span>";
                                            }
                                        $paginate.= "</div>";   
                                    }
                                    $resultData = $commonFunctions->getData('vndr_details',$where);
                                    ?>
                                    <div class="form-row">
                                        <table style="width: 100% !important;" class="table datatable_t table-hover table-striped table-bordered">
                                            <thead>
                                                <tr>
                                                    <th  class="text-center">Third-Party Name</th>
                                                    <th  class="text-center">Alias Name</th>
                                                    <th  class="text-center">Barcode</th>
                                                    <th  class="text-center">Customer Code</th>
                                                    <th  class="text-center">Vendor Code</th>
                                                    <th  class="text-center">City</th>
                                                    <th  class="text-center">State / Province</th>
                                                    <th  class="text-center">Country</th>
                                                    <th  class="text-center">Postcode</th>
                                                    <th  class="text-center">Type of Company</th>
                                                    <th  class="text-center">Phone</th>
                                                    <th  class="text-center">Email</th>
                                                    <th  class="text-center">Logo</th>
                                                </tr>

                                            </thead>
                                            <tbody>
                                                <?php foreach ($resultData as $rw) { ?>
                                                    <tr onclick="redirect_('vendor-card.php?vendor_id=<?php echo $rw['id'];?>')" >
                                                        <td><?php echo $rw['name'];?></td>
                                                        <td><?php echo $rw['alias_name'];?></td>
                                                        <td><?php echo $rw['barcode'];?></td>
                                                        <td><?php echo $rw['customer_code'];?></td>
                                                        <td><?php echo $rw['vendor_code'];?></td>
                                                        <td><?php echo $rw['city'];?></td>
                                                        <td><?php echo $rw['state'];?></td>
                                                        <td><?php echo $rw['country'];?></td>
                                                        <td><?php echo $rw['postcode'];?></td>
                                                        <td><?php echo $rw['type_of_company'];?></td>
                                                        <td><?php echo $rw['phone'];?></td>
                                                        <td><?php echo $rw['email'];?></td>
                                                        <td><?php if(!empty($rw['logo'])): ?><img class="d-flex mr-3 rounded-circle" src="../uploads/vendor/<?php echo $rw['logo'];?>" alt="Generic placeholder image" height="50">
                                                        <?php endif; ?></td>
                                                    </tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    <?php echo "<center>".$paginate."</center>";?>
                                <?php endif; ?>
                            <!-- </div> -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div> <!-- end col -->
</div> <!-- end row -->

<?php require "../inc/footer.php"; ?>
<script type="text/javascript">
$(document).ready(function() {
    $('.datatable_t1').DataTable({
        "scrollX": true,
        "paging":   false,
        "info":     false
    });
});
/*function format ( d ) {
    return 'Full name: '+d.first_name+' '+d.last_name+'<br>'+
        'Salary: '+d.salary+'<br>'+
        'The child row can contain any data you wish, including links, images, inner tables etc.';
}
 
$(document).ready(function() {
    var dt = $('.datatable_t').DataTable( {
        "processing": false,
        "serverSide": false,
        "columns": [ 
            {
                "class":          "details-control",
                "orderable":      false,
                "data":           null,
                "defaultContent": ""
            },
        ],
        "order": [[1, 'asc']]
    } );
 
    // Array to track the ids of the details displayed rows
    var detailRows = [];
 
    $('.datatable_t tbody').on( 'click', 'tr td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = dt.row( tr );
        var idx = $.inArray( tr.attr('id'), detailRows );
 
        if ( row.child.isShown() ) {
            tr.removeClass( 'details' );
            row.child.hide();
 
            // Remove from the 'open' array
            detailRows.splice( idx, 1 );
        }
        else {
            tr.addClass( 'details' );
            row.child( format( row.data() ) ).show();
 
            // Add to the 'open' array
            if ( idx === -1 ) {
                detailRows.push( tr.attr('id') );
            }
        }
    } );
 
    // On each draw, loop over the `detailRows` array and show any child rows
    dt.on( 'draw', function () {
        $.each( detailRows, function ( i, id ) {
            $('#'+id+' td.details-control').trigger( 'click' );
        } );
    } );
} );*/
function redirect_(uri){
    window.location.href = uri;
}
</script>