<?php 
define('DOCUMENT_ROOT_CLASS','../../');
define('DOCUMENT_ROOT_INC_FOLDER','inc/');

$filepath = realpath(dirname(__FILE__));
require "../../inc/header.php";
$msg = Session::get('msg');
Session::set("msg", NULL);
if(!empty($_POST)){
    $error_ = 0;
    if(empty($_POST['erp_sys_org_name'])){
        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 organization name!</div>');
    }else{
        $cntA = $commonFunctions->getRowData('erp_sys_organaization',' WHERE erp_sys_org_name = "'.$_POST['erp_sys_org_name'].'" ');
        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> organization name already exists !</div>');
        }
    }

    if(!empty($_POST['erp_sys_org_name']) and $error_ == 0){
        if($_GET['action'] == "add"){
            $commonFunctions->addData('erp_sys_organaization'," (erp_sys_org_name,erp_sys_org_address,erp_sys_org_city,erp_sys_org_province,erp_sys_org_country,erp_sys_org_zip_code,erp_sys_org_phone_work,erp_sys_org_fax,erp_sys_email_work,erp_sys_org_sm_page_linkedin,erp_sys_org_sm_page_twitter,erp_sys_org_sm_page_facebook,erp_sys_org_sm_page_instagram,erp_sys_org_id_msngr_whatsapp,erp_sys_org_department,erp_sys_org_cr_num,erp_sys_org_cr_address,erp_sys_org_cr_city,erp_sys_org_cr_province,erp_sys_org_cr_country,erp_sys_org_cr_zip_code,erp_sys_org_tax_id_1,erp_sys_org_tax_id_2,erp_sys_org_inport_id,erp_sys_org_export_id) VALUES ('".$_POST['erp_sys_org_name']."','".$_POST['erp_sys_org_address']."','".$_POST['erp_sys_org_city']."','".$_POST['erp_sys_org_province']."','".$_POST['erp_sys_org_country']."','".$_POST['erp_sys_org_zip_code']."','".$_POST['erp_sys_org_phone_work']."','".$_POST['erp_sys_org_fax']."','".$_POST['erp_sys_email_work']."','".$_POST['erp_sys_org_sm_page_linkedin']."','".$_POST['erp_sys_org_sm_page_twitter']."','".$_POST['erp_sys_org_sm_page_facebook']."','".$_POST['erp_sys_org_sm_page_instagram']."','".$_POST['erp_sys_org_id_msngr_whatsapp']."','".$_POST['erp_sys_org_department']."','".$_POST['erp_sys_org_cr_num']."','".$_POST['erp_sys_org_cr_address']."','".$_POST['erp_sys_org_cr_city']."','".$_POST['erp_sys_org_cr_province']."','".$_POST['erp_sys_org_cr_country']."','".$_POST['erp_sys_org_cr_zip_code']."','".$_POST['erp_sys_org_tax_id_1']."','".$_POST['erp_sys_org_tax_id_2']."','".$_POST['erp_sys_org_inport_id']."','".$_POST['erp_sys_org_export_id']."') ",'organization.php?state=form');
        }
        if($_GET['action'] == "edit"){
            $commonFunctions->updateData('erp_sys_organaization'," WHERE id = '".$_POST['org_id ']."' ", " erp_sys_org_name = '".$_POST['erp_sys_org_name']."', erp_sys_org_address='".$_POST['erp_sys_org_address']."', erp_sys_org_city='".$_POST['erp_sys_org_city']."' , erp_sys_org_province='".$_POST['erp_sys_org_province']."' , erp_sys_org_country='".$_POST['erp_sys_org_country']."' , erp_sys_org_zip_code='".$_POST['erp_sys_org_zip_code']."' , erp_sys_org_phone_work='".$_POST['erp_sys_org_phone_work']."', erp_sys_org_fax='".$_POST['erp_sys_org_fax']."', erp_sys_email_work='".$_POST['erp_sys_email_work']."', erp_sys_org_sm_page_linkedin='".$_POST['erp_sys_org_sm_page_linkedin']."', erp_sys_org_sm_page_twitter='".$_POST['erp_sys_org_sm_page_twitter']."', erp_sys_org_sm_page_facebook='".$_POST['erp_sys_org_sm_page_facebook']."', erp_sys_org_sm_page_instagram='".$_POST['erp_sys_org_sm_page_instagram']."', erp_sys_org_id_msngr_whatsapp='".$_POST['erp_sys_org_id_msngr_whatsapp']."', erp_sys_org_department='".$_POST['erp_sys_org_department']."', erp_sys_org_cr_num='".$_POST['erp_sys_org_cr_num']."', erp_sys_org_cr_address='".$_POST['erp_sys_org_cr_address']."', erp_sys_org_cr_city='".$_POST['erp_sys_org_cr_city']."', erp_sys_org_cr_province='".$_POST['erp_sys_org_cr_province']."', erp_sys_org_cr_country='".$_POST['erp_sys_org_cr_country']."', erp_sys_org_cr_zip_code='".$_POST['erp_sys_org_cr_zip_code']."', erp_sys_org_tax_id_1='".$_POST['erp_sys_org_tax_id_1']."', erp_sys_org_tax_id_2='".$_POST['erp_sys_org_tax_id_2']."', erp_sys_org_inport_id='".$_POST['erp_sys_org_inport_id']."', erp_sys_org_export_id='".$_POST['erp_sys_org_export_id']."'",'organization.php?state=form');
        }
    }else{
        echo "<script>location.href='organization.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">Organization Details</h4>
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="javascript:void(0);">Settings</a></li>
                        <li class="breadcrumb-item"><a href="javascript:void(0);">Organization Details</a></li>
                        <li class="breadcrumb-item"><a href="javascript:void(0);">Organization <?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">
                    <div class="form-row">
                        <div class="form-group searchForm col-md-6">
                            <a class="btn btn-sm btn-soft-primary" href="organization.php?state=form" role="button" style="float: left;"><i class="fas fa-plus mr-2"></i> Add New Organization Details</a>
                        </div>
                        <div class="form-group searchForm col-md-6">
                            <?php if(empty($_GET['state']) OR (!empty($_GET['state']) and $_GET['state'] == "list")): ?>
                            <form action="" id="searchForm" method="GET">
                                <div class="form-row">
                                    <div class="form-group searchForm col-md-8">
                                        <input type="text" name="search" id="search" placeholder="Search" class="form-control" value="<?php echo @$_GET['search']; ?>">
                                        <input type="hidden" name="state" value="<?php echo @$_GET['state']; ?>">
                                        <input type="hidden" name="page" value="<?php echo @$_GET['page']; ?>">
                                    </div>
                                    <div class="form-group searchForm col-md-4">
                                        <button type="submit" id="searchbtn" class="btn btn-primary"> <i class="fa fa-search"></i> Search</button>
                                        <button type="button" id="clearbtn" class="btn btn-danger"> <i class="fa fa-trash"></i> Clear</button>
                                    </div>
                                </div>
                            </form>
                            <?php endif; ?>
                        </div>
                    </div>
                </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="organization.php?state=form&action=add" method="post" name="formsoc" autocomplete="off">      
                                        <div class="form-row">
                                            <input type="hidden" name="action" value="add">
                                            <input type="hidden" name="org_id" value="">
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_name" class="">Company Name <span class="error">*</span></label>
                                                <input type="text" maxlength="128" name="erp_sys_org_name" id="erp_sys_org_name" value="" autofocus="autofocus" class="form-control" placeholder="Company Name" required="">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_address" class="">Company Address</label>
                                                <textarea name="erp_sys_org_address" class="form-control" placeholder="Company Address"></textarea>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_city" class="">Company City</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_city" id="erp_sys_org_city" value="" autofocus="autofocus" class="form-control" placeholder="Company City">
                                            </div>
                                            
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_province" class="">Company State / Province</label>
                                                <?php $stateData = $commonFunctions->getData('sys_erp_adm_countries_states',' WHERE active = 1 '); ?>
                                                <select name="erp_sys_org_province" id="erp_sys_org_province" class="select2 form-control" >
                                                    <option value="0">Select Company 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="erp_sys_org_country" class=""> Company Country </label>
                                                <?php $countryData = $commonFunctions->getData('sys_erp_adm_countries',' WHERE active = 1 '); ?>
                                                <select name="erp_sys_org_country" id="erp_sys_org_country" class="select2 form-control" >
                                                    <option value="0">Select Company 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="erp_sys_org_zip_code" class="">Company Zip Code</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_zip_code" id="erp_sys_org_zip_code" value="" autofocus="autofocus" class="form-control" placeholder="Company Zip Code">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_dprtmt_acnt" class="">Company Branch</label>
                                                
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_phone_work" class="">Work Phone</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_phone_work" id="erp_sys_org_phone_work" value="" autofocus="autofocus" class="form-control" placeholder="Work Phone">
                                            </div>
                                            
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_fax" class="">Work Fax</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_fax" id="erp_sys_org_fax" value="" autofocus="autofocus" class="form-control" placeholder="Work Fax">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_user_email_work" class="">Work eMail</label>
                                                <input type="text" maxlength="128" name="erp_sys_user_email_work" id="erp_sys_user_email_work" value="" autofocus="autofocus" class="form-control" placeholder="Work eMail">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_sm_page_linkedin" class="">linkedIn</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_sm_page_linkedin" id="erp_sys_org_sm_page_linkedin" value="" autofocus="autofocus" class="form-control" placeholder="linkedIn">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_sm_page_twitter" class="">Twitter</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_sm_page_twitter" id="erp_sys_org_sm_page_twitter" value="" autofocus="autofocus" class="form-control" placeholder="Twitter">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_sm_page_facebook" class="">Facebook</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_sm_page_facebook" id="erp_sys_org_sm_page_facebook" value="" autofocus="autofocus" class="form-control" placeholder="Facebook">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_sm_page_instagram" class="">Instagram</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_sm_page_instagram" id="erp_sys_org_sm_page_instagram" value="" autofocus="autofocus" class="form-control" placeholder="Facebook">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_id_msngr_whatsapp" class="">Business Whatsapp</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_id_msngr_whatsapp" id="erp_sys_org_id_msngr_whatsapp" value="" autofocus="autofocus" class="form-control" placeholder="Business Whatsapp">
                                            </div>
                                            
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_department" class="">Departnemt ( Company )</label>
                                                <?php $departmentData = $commonFunctions->getData('erp_sys_org_department',' '); ?>
                                                <select name="erp_sys_org_department" id="erp_sys_org_department" class="select2 form-control" >
                                                    <option value="0">Select Departnemt ( Company )</option>
                                                    <?php foreach ($departmentData as $rw) { ?>
                                                        <option value="<?php echo $rw['id'];?>" ><?php echo $rw['erp_sys_org_dprtmt_ops']; ?></option>     
                                                    <?php } ?>
                                                </select>
                                            </div>
                                            
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_cr_num" class="">Company Commercial Registration No</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_cr_num" id="erp_sys_org_cr_num" value="" autofocus="autofocus" class="form-control" placeholder="Company Commercial Registration No">
                                            </div>
                                            
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_cr_address" class="">Company Regiatration Address</label>
                                                <textarea name="erp_sys_org_cr_address" class="form-control" placeholder="Company Regiatration Address"></textarea>
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_cr_city" class="">Company Regiatration City</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_cr_city" id="erp_sys_org_cr_city" value="" autofocus="autofocus" class="form-control" placeholder="Company Regiatration City">
                                            </div>

                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_cr_province" class="">Company Regiatration Province</label>
                                                <?php $stateData = $commonFunctions->getData('sys_erp_adm_countries_states',' WHERE active = 1 '); ?>
                                                <select name="erp_sys_org_cr_province" id="erp_sys_org_cr_province" class="select2 form-control" >
                                                    <option value="0">Select Company 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="erp_sys_org_cr_country" class="">Company Regiatration Country</label>
                                                <?php $countryData = $commonFunctions->getData('sys_erp_adm_countries',' WHERE active = 1 '); ?>
                                                <select name="erp_sys_org_cr_country" id="erp_sys_org_cr_country" class="select2 form-control" >
                                                    <option value="0">Select Company 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="erp_sys_org_cr_zip_code" class="">Company Regiatration Zip Code</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_cr_zip_code" id="erp_sys_org_cr_zip_code" value="" autofocus="autofocus" class="form-control" placeholder="Company Regiatration Zip Code">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_tax_id_1" class="">Company TAX ID 1</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_tax_id_1" id="erp_sys_org_tax_id_1" value="" autofocus="autofocus" class="form-control" placeholder="Company TAX ID 1">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_tax_id_2" class="">Company TAX ID 2</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_tax_id_2" id="erp_sys_org_tax_id_2" value="" autofocus="autofocus" class="form-control" placeholder="Company TAX ID 2">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_inport_id" class="">Company Import ID</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_inport_id" id="erp_sys_org_inport_id" value="" autofocus="autofocus" class="form-control" placeholder="Company Import ID">
                                            </div>
                                            <div class="position-relative form-group col-md-4">
                                                <label for="erp_sys_org_export_id" class="">Company Export ID</label>
                                                <input type="text" maxlength="128" name="erp_sys_org_export_id" id="erp_sys_org_export_id" value="" autofocus="autofocus" class="form-control" placeholder="Company Export ID">
                                            </div>
                                            <div class="position-relative form-group col-md-12">
                                                <button type="submit" class="btn btn-success">Create</button>
                                                <a href="organization.php?state=list"><button type="button" class="btn btn-danger">Back to Organization List</button></a>
                                            </div>
                                        </div>
                                    </form>
                                <?php endif; ?>
                                <?php if(empty($_GET['state']) OR (!empty($_GET['state']) and $_GET['state'] == "list")): 

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

                                    $limit = 50;
                                    $total_pages = $commonFunctions->getData('erp_sys_organaization','');
                                    $total_pages = count($total_pages);
                                    $stages = 3;
                                    $page = @$_GET['page'];
                                    if($page){
                                        $start = ($page - 1) * $limit; 
                                    }else{
                                        $start = 0; 
                                    } 
                                    
                                    $search_con = "";
                                    if(!empty($_GET['search'])){
                                        
                                        $search_con = " AND erp_sys_org_name LIKE '%".$_GET['search']."%' OR erp_sys_org_address LIKE '%".$_GET['search']."%' OR erp_sys_org_city LIKE '%".$_GET['search']."%' OR erp_sys_org_branch LIKE '%".$_GET['search']."%' OR erp_sys_org_phone_work LIKE '%".$_GET['search']."%' OR erp_sys_org_fax LIKE '%".$_GET['search']."%' OR erp_sys_email_work LIKE '%".$_GET['search']."%' OR erp_sys_org_sm_page_linkedin LIKE '%".$_GET['search']."%' OR erp_sys_org_sm_page_twitter LIKE '%".$_GET['search']."%' OR erp_sys_org_sm_page_facebook LIKE '%".$_GET['search']."%' OR erp_sys_org_sm_page_instagram LIKE '%".$_GET['search']."%'  OR erp_sys_org_cr_address LIKE '%".$_GET['search']."%' OR erp_sys_org_cr_city LIKE '%".$_GET['search']."%' OR erp_sys_org_cr_zip_code LIKE '%".$_GET['search']."%' ";
                                    }
                                    $where = " WHERE id ".$search_con." 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('erp_sys_organaization',$where);
                                    ?>
                                    <div class="form-row1 table-rep-plugin">
                                        <div class="table-responsive1 mb-0" data-pattern="priority-columns">
                                            <table style="width: 100% !important;" class="table datatable_t table-hover table-striped table-bordered">
                                                <thead>
                                                    <tr>
                                                        <th  class="text-center">SL</th>
                                                        <th  class="text-center">Company Name</th>
                                                        <th  class="text-center">Company Address</th>
                                                        <th  class="text-center">Company City</th>
                                                        <th  class="text-center">Company Province</th>
                                                        <th  class="text-center">Company Country</th>
                                                        <th  class="text-center">Company Zip Code</th>
                                                        <th  class="text-center">Company Branch</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php $i = 1; foreach ($resultData as $rw) { ?>
                                                        <tr>
                                                            <td><?php echo $i++; ?></td>
                                                            <td><?php echo $rw['erp_sys_org_name'];?></td>
                                                            <td><?php echo $rw['erp_sys_org_address'];?></td>
                                                            <td><?php echo $rw['erp_sys_org_city'];?></td>
                                                            <td><?php echo $rw['erp_sys_org_province'];?></td>
                                                            <td><?php echo $rw['erp_sys_org_country'];?></td>
                                                            <td><?php echo $rw['erp_sys_org_zip_code'];?></td>
                                                            <td><?php echo $rw['erp_sys_org_branceh'];?></td>
                                                        </tr>
                                                    <?php } ?>
                                                </tbody>
                                            </table>
                                        </div>
                                    </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">
$("#clearbtn").click(function(){
    $("#search").val('');
    $("#searchForm").submit();
});
</script>