<?php 
define('DOCUMENT_ROOT_CLASS','../');
define('DOCUMENT_ROOT_INC_FOLDER','');
$filepath = realpath(dirname(__FILE__));
if(!empty(@$_POST["action"]) and @$_POST["action"] == "ajax_call"){
    require "../inc/ajax_header.php";
    $country_id = @$_POST["country_id"];
    $getData = $commonFunctions->getData('sys_erp_adm_countries_states'," WHERE country_id = '".$country_id."' and active = 1 ");
    $html = "";
    foreach ($getData as $rw) {
        $html .= "<option value='".$rw['rowid']."'>".$rw['label']."</option>";
    }
    echo json_encode(array("option"=>$html));
    exit();
}
if(!empty($_GET["action"]) and $_GET["action"] == "ajax_call1"){
    require "../inc/ajax_header.php";
    $country_id = $_GET["country_id"];
    $state_id = $_GET["state_id"];
    $keyword = $_GET["keyword"]; 
    $getData = $commonFunctions->getData('sys_erp_adm_countries_states_cities'," WHERE country_id = '".$country_id."' and state_id = '".$state_id."' and name LIKE '%".$keyword."%' ");
    $html = "";
    $skillData = array(); 
    foreach ($getData as $rw) {
        $data['id'] = $rw['name']; 
        $data['value'] = $rw['name']; 
        array_push($skillData, $data); 
    } 
    echo json_encode($skillData);
    exit();
}
require "../inc/header.php";
Session::CheckSession(); 
$msg = Session::get('msg');
Session::set("msg", NULL); 
if(!empty($_POST)){
    $error_ = 0;
    if(empty(@$_POST['customer_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('crm_cust_details',' WHERE customer_code = "'.@$_POST['customer_code'].'" and id != "'.@$_POST['customer_id'].'" ');
        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['customer_code']) and $error_ == 0){
        if(@$_POST['action'] == "add"){
            $column = $fileName = "";
            if(!empty($_FILES["logo"])){
                $target_dir = "../uploads/crm/";
                $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']);

            $last_id = $commonFunctions->addData('crm_cust_details'," (name,commercial_registration_no,alias_name,client_type,customer_code,vendor_type,vendor_code,status,barcode,address,address2,postcode,city,country,state,email,web,phone,fax,tax_id_1,tax_id_2,tax_id_3,import_id,export_id,type_of_company,staff,entity_type,capital,incoterm_id,customer_cat,currency,assigned_to_sales,org_sm_page_linkedin,org_sm_page_twitter,org_sm_page_facebook,org_sm_page_instagram,org_id_msngr_whatsapp".$column.") VALUES ('".@$_POST['name']."','".@$_POST['commercial_registration_no']."','".@$_POST['alias_name']."','".@$_POST['client']."','".@$_POST['customer_code']."','".@$_POST['fournisseur']."','".@$_POST['vendor_code']."','".@$_POST['status']."','".@$_POST['barcode']."','".@str_replace("'","",@$_POST['address'])."','".@str_replace("'","",@$_POST['address2'])."','".@$_POST['postcode']."','".@$_POST['city']."','".@$_POST['country']."','".@$_POST['state']."','".@$_POST['email']."','".@$_POST['web']."','".@$_POST['phone']."','".@$_POST['fax']."','".@$_POST['tax_id_1']."','".@$_POST['tax_id_2']."','".@$_POST['tax_id_3']."','".@$_POST['import_id']."','".@$_POST['export_id']."','".@$_POST['type_of_company']."','".@$_POST['staff']."','".@$_POST['entity_type']."','".@$_POST['capital']."','".@$_POST['incoterm_id']."','".$custcats."','".@$_POST['currency']."','".@$_POST['assigned_to_sales']."','".@$_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']."'".$fileName." ) ",'');
            
            if(@$_POST['fournisseur'] == 1){
                $commonFunctions->addData('vndr_details'," (name,commercial_registration_no,alias_name,client_type,customer_code,vendor_type,vendor_code,status,barcode,address,address2,postcode,city,country,state,email,web,phone,fax,tax_id_1,tax_id_2,tax_id_3,import_id,export_id,type_of_company,staff,entity_type,capital,incoterm_id,customer_cat,currency,assigned_to_sales,org_sm_page_linkedin,org_sm_page_twitter,org_sm_page_facebook,org_sm_page_instagram,org_id_msngr_whatsapp".$column.") VALUES ('".@$_POST['name']."','".@$_POST['commercial_registration_no']."','".@$_POST['alias_name']."','".@$_POST['client']."','".@$_POST['customer_code']."','".@$_POST['fournisseur']."','".@$_POST['vendor_code']."','".@$_POST['status']."','".@$_POST['barcode']."','".@str_replace("'","",@$_POST['address'])."','".@str_replace("'","",@$_POST['address2'])."','".@$_POST['postcode']."','".@$_POST['city']."','".@$_POST['country']."','".@$_POST['state']."','".@$_POST['email']."','".@$_POST['web']."','".@$_POST['phone']."','".@$_POST['fax']."','".@$_POST['tax_id_1']."','".@$_POST['tax_id_2']."','".@$_POST['tax_id_3']."','".@$_POST['import_id']."','".@$_POST['export_id']."','".@$_POST['type_of_company']."','".@$_POST['staff']."','".@$_POST['entity_type']."','".@$_POST['capital']."','".@$_POST['incoterm_id']."','".$custcats."','".@$_POST['currency']."','".@$_POST['assigned_to_sales']."','".@$_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']."'".$fileName." ) ",'');
            }

            $rand = rand(0,999999999999999);
            if(@$_POST['customer_status'] == 0){
                $commonFunctions->addData('global_organaization'," (global_org_name,global_org_address,global_org_city,global_org_province,global_org_country,global_org_zip_code,global_org_phone_work,global_org_fax,global_email_work,global_org_tax_id_1,crm_cust_id,crm_cust_ref_id,glo_org_rand_num,global_org_website) VALUES ('".@$_POST['name']."','".@str_replace("'","",@$_POST['address'])."','".@$_POST['city']."','".@$_POST['state']."','".@$_POST['country']."','".@$_POST['postcode']."','".@$_POST['phone']."','".@$_POST['fax']."','".@$_POST['email']."','".@$_POST['sales_tax_id']."','".$last_id."','".@$_POST['customer_code']."','".$rand."','".@$_POST['web']."' ) ",'');
            }else{
                $commonFunctions->addData('global_contacts'," (cont_random_num,global_user_name_first,global_user_email_personal,global_user_mobile1,global_org_name,global_user_job_title,global_org_fax,global_user_email_work,global_user_id_sm_linkedin,global_user_id_sm_twitter,global_user_id_sm_facebook,global_user_id_sm_instagram,global_user_id_msngr_whatsapp) VALUES ('".$rand."','".@$_POST['name']."','".@$_POST['email']."','".@$_POST['phone']."','".@$_POST['name']."','Vendor','".@$_POST['fax']."','".@$_POST['email']."','".@$_POST['fax']."','".@$_POST['email']."','".@$_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']."' ) ",'');
            }
            echo "<script> window.location.href='customer.php?state=customer-form'; </script>";
        }
        if(@$_POST['action'] == "edit"){
            $column = $fileName = "";
            if(!empty($_FILES["logo"]["name"])){
                $target_dir = "../uploads/crm/";
                $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('crm_cust_details'," WHERE id = '".@$_POST['customer_id']."' ", " alias_name='".@$_POST['alias_name']."',name='".@$_POST['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='".@str_replace("'","",@$_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']."', tax_id_1='".@$_POST['tax_id_1']."', tax_id_2='".@$_POST['tax_id_2']."', tax_id_3='".@$_POST['tax_id_3']."', export_id='".@$_POST['export_id']."', import_id='".@$_POST['import_id']."', address2='".@$_POST['address2']."', commercial_registration_no='".@$_POST['commercial_registration_no']."', 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,'customer-card.php?customer_id='.@$_POST['customer_id']); 
        }
    }else{
        echo "<script>location.href='customer.php?state=customer-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"><?php echo (!empty($_GET['state']) and $_GET['state'] == "customer-form")?" Add Customer ":" List of Customer"; ?></h4>
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="javascript:void(0);">CRM</a></li>
                            <li class="breadcrumb-item"><a href="javascript:void(0);">Customer</a></li>
                            <li class="breadcrumb-item active"><?php echo (!empty($_GET['state']) and $_GET['state'] == "customer-form")?" Add Customer ":" List of Customer"; ?></li>
                        </ol>

                    </div><!--end col-->
                    <?php if(!empty($_GET['state']) and $_GET['state'] == "customer-form"){ ?>
                        <div class="col-auto align-self-center">
                            <a href="" class="btn btn-secondary btn-sm">
                                <i class="fas fa-times-circle align-self-center icon-xs"></i>Clear
                            </a>
                            <a href="javascript:void(0);" class="btn btn-success btn-sm" id="saveForm">
                                <i class="fas fa-save align-self-center icon-xs"></i> Save
                            </a>

                            <a href="customer.php?state=customer-list" class="btn btn-danger btn-sm" >
                                <i class="fas fa-save align-self-center icon-xs"></i> Back to List
                            </a>
                        </div>
                    <?php } ?>
                       
                </div><!--end row-->                                                              
            </div><!--end page-title-box-->
        </div><!--end col-->
    </div><!--end row-->
    <!-- end page title end breadcrumb -->
    <?php if(empty($_GET['state']) OR (!empty($_GET['state']) and $_GET['state'] == "customer-list")): ?>
        <div class="row">
            <div class="col-lg-12">
                <div class="row justify-content-center">
                    <div class="col-md-6 col-lg-3">
                        <div class="card report-card">
                            <div class="card-body">
                                <div class="row d-flex justify-content-center">
                                    <div class="col">
                                        <p class="text-dark mb-0 font-weight-semibold">Total Customer</p>
                                        <h3 class="m-0"><?php echo $commonFunctions->getRowDataCount('crm_cust_details',''); ?></h3>
                                        <!--p class="mb-0 text-truncate text-muted">In Inventory</p-->
                                    </div>
                                    <div class="col-auto align-self-center">
                                        <div class="report-main-icon bg-light-alt">
                                            <i data-feather="users" class="align-self-center text-muted icon-sm"></i>  
                                        </div>
                                    </div>
                                </div>
                            </div><!--end card-body--> 
                        </div><!--end card--> 
                    </div> <!--end col--> 
                    <div class="col-md-6 col-lg-3">
                        <div class="card report-card">
                            <div class="card-body">
                                <div class="row d-flex justify-content-center">                                                
                                    <div class="col">
                                        <p class="text-dark mb-0 font-weight-semibold">My Customer</p>                                                    
                                        <!--p class="mb-0 text-truncate text-muted">Barwa Shop 4</p-->
                                        <h3 class="m-0"><?php echo $commonFunctions->getRowDataCount('crm_cust_details',' WHERE staff = "'.$_SESSION['id'].'"'); ?></h3>
                                    </div>
                                    <div class="col-auto align-self-center">
                                        <div class="report-main-icon bg-light-alt">
                                            <i data-feather="clock" class="align-self-center text-muted icon-sm"></i>  
                                        </div>
                                    </div> 
                                </div>
                            </div><!--end card-body--> 
                        </div><!--end card--> 
                    </div> <!--end col--> 
                    <div class="col-md-6 col-lg-3">
                        <div class="card report-card">
                            <div class="card-body">
                                <div class="row d-flex justify-content-center">                                                
                                    <div class="col">
                                        <p class="text-dark mb-0 font-weight-semibold">Active Customer</p>
                                        <h3 class="m-0"><?php echo $commonFunctions->getRowDataCount('crm_cust_details',' WHERE status = "1"'); ?> </h3>
                                        <!--p class="mb-0 text-truncate text-muted">Listed Products</p-->
                                    </div>
                                    <div class="col-auto align-self-center">
                                        <div class="report-main-icon bg-light-alt">
                                            <i data-feather="clock" class="align-self-center text-muted icon-sm"></i>  
                                        </div>
                                    </div> 
                                </div>
                            </div><!--end card-body--> 
                        </div><!--end card--> 
                    </div> <!--end col--> 
                    <div class="col-md-6 col-lg-3">
                        <div class="card report-card">
                            <div class="card-body">
                                <div class="row d-flex justify-content-center">                                                
                                    <div class="col">
                                        <p class="text-dark mb-0 font-weight-semibold">In-Active Customer</p>
                                        <h3 class="m-0"><?php echo $commonFunctions->getRowDataCount('crm_cust_details',' WHERE status = "0"'); ?></h3>
                                        <!--p class="mb-0 text-truncate text-muted">Products Below Desired Stock</p-->
                                    </div>
                                    <div class="col-auto align-self-center">
                                        <div class="report-main-icon bg-light-alt">
                                            <i data-feather="clock" class="align-self-center text-muted icon-sm"></i>  
                                        </div>
                                    </div> 
                                </div>
                            </div><!--end card-body--> 
                        </div><!--end card--> 
                    </div> <!--end col-->                        
                </div><!--end row-->
            </div>
        </div>
    <?php endif; ?>

    <div class="row">
        <?php if(empty($_GET['state']) OR (!empty($_GET['state']) and $_GET['state'] == "customer-list")): ?>
        <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 href="customer.php?state=customer-form"><button type="button" class="btn btn-outline-primary">Add Customer</button></a>
                                </div>
                                <div class="form-group searchForm col-md-6">
                                    <!-- <h4 class="card-title">Customer<?php echo (!empty($_GET['state']) and $_GET['state'] == "customer-form")?" Form ":" List "; ?></h4> -->
                                    
                                    <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>
                                </div>
                            </div>
                        </h4>
                    </div>
                <?php endif; ?>
                <div class="col-12">
                    <?php echo !empty($msg)?$msg:''; ?>        
                    <?php echo !empty($msg1)?$msg1:''; ?>        
                </div>
                <?php 
                if(!empty($_GET['customer_id'])){
                    $customerData = $commonFunctions->getRowData('crm_cust_details',' WHERE id = "'.$_GET['customer_id'].'" ');
                }
                ?> 
                <?php if(!empty($_GET['state']) and $_GET['state'] == "customer-form"): ?>
                     <div class="row">
                        <div class="col-12">
                            <div class="tab-content" id="pills-tabContent">

                                <!-- User Profile - Start --->
                                <div class="tab-pane fade show active" role="tabpanel" aria-labelledby="settings_detail_tab">
                                    <form enctype="multipart/form-data" action="customer.php?state=customer-form&action=add" method="post" name="formsoc" autocomplete="off" id="custForm"> 
                                        <div class="row">
                                            <!-- Personal Information Card - Start --->
                                            <div class="col-lg-6 col-xl-6">
                                                <div class="card">
                                                    <div class="card-header">
                                                        <div class="row align-items-center">
                                                            <div class="col-11">                      
                                                                <h4 class="card-title text-left">Company Information</h4>                      
                                                            </div><!--end col-->                                                 
                                                        </div>  <!--end row-->                                  
                                                    </div><!--end card-header-->
                                                    <div class="card-body">
                                                        <input type="hidden" name="action" value="<?php echo !empty($_GET['customer_id'])?'edit':'add';?>">
                                                        <input type="hidden" name="customer_id" value="<?php echo @$_GET['customer_id']; ?>">                              
                                                        <div class="form-group row">            
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Company Name <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" maxlength="128" name="name" id="name" value="<?php echo @$customerData['name'];?>" autofocus="autofocus" class="form-control">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Alias (Trademark etc.) <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" class="form-control" name="alias_name" value="<?php echo @$customerData['alias_name'];?>">
                                                            </div>
                                                        </div>
                                                        
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Commercial Registration No <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" name="commercial_registration_no" class="form-control" value="<?php echo @$customerData['commercial_registration_no'];?>" placeholder="Commercial Registration No" required>
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Customer No <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <?php $seriNo = $commonFunctions->getRowDataCount('crm_cust_details',''); 
                                                                $seriNo1 = $commonFunctions->random_num(10 - strlen($seriNo));
                                                                if(empty($_GET['customer_id'])){
                                                                ?>
                                                                    <input type="text" readonly="" class="form-control" name="customer_code" value="CUST-<?php echo @$seriNo1.$seriNo;?>">
                                                                    <input type="hidden" class="form-control" name="barcode" value="CUST-<?php echo @$seriNo1.$seriNo;?>">
                                                                <?php }else{ ?>
                                                                    <input type="text" readonly="" class="form-control" name="customer_code" value="<?php echo @$customerData['customer_code'];?>">
                                                                    <input type="hidden" class="form-control" name="barcode" value="<?php echo @$customerData['customer_code'];?>">
                                                                <?php } ?>
                                                            </div>
                                                        </div>                                    
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Company Logo</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="file" class="custom-file-input" name="logo" id="customFile">
                                                                <label class="custom-file-label" for="customFile">Choose file</label>
                                                            </div>
                                                        </div>  
                                                    </div>                                            
                                                </div>

                                                <div class="card">
                                                    <div class="card-header">
                                                        <div class="row align-items-center">
                                                            <div class="col-11">                      
                                                                <h4 class="card-title text-left">Company Contact Information <label class="col-xl-3 col-lg-3 mb-lg-0 align-self-center">( Official )</label></h4>
                                                            </div><!--end col-->                                                      
                                                        </div>  <!--end row-->                                  
                                                    </div><!--end card-header-->
                                                    <div class="card-body">                                                                          
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Work Phone </label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" class="form-control" name="phone" value="<?php echo @$customerData['phone'];?>">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Work Fax</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" class="form-control" name="fax" value="<?php echo @$customerData['fax'];?>">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Default Email Address <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="email" class="form-control" name="email" value="<?php echo @$customerData['email'];?>" required>
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Website / URL</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" class="form-control" name="web" value="<?php echo @$customerData['web'];?>">
                                                            </div>
                                                        </div>
                                                    </div><!--end card-body-->
                                                </div><!--end card-->

                                                <!-- Personal Information Card - End --->
                                                <div class="card">
                                                    <div class="card-header">
                                                        <div class="row align-items-center">
                                                            <div class="col-11">                      
                                                                <h4 class="card-title text-left">Social Media </h4>                      
                                                            </div><!--end col-->                                                    
                                                        </div>  <!--end row-->                                  
                                                    </div><!--end card-header-->
                                                    <div class="card-body">                                                                          
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Linkedin</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" maxlength="128" name="erp_sys_org_sm_page_linkedin" id="erp_sys_org_sm_page_linkedin" value="<?php echo @$customerData['erp_sys_org_sm_page_linkedin'];?>" autofocus="autofocus" class="form-control" placeholder="linkedIn">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Twitter</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" maxlength="128" name="erp_sys_org_sm_page_twitter" id="erp_sys_org_sm_page_twitter" value="<?php echo @$customerData['erp_sys_org_sm_page_twitter'];?>" autofocus="autofocus" class="form-control" placeholder="Twitter">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Facebook</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" maxlength="128" name="erp_sys_org_sm_page_facebook" id="erp_sys_org_sm_page_facebook" value="<?php echo @$customerData['erp_sys_org_sm_page_facebook'];?>" autofocus="autofocus" class="form-control" placeholder="Facebook">
                                                            </div>
                                                        </div>      
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Instagram</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" maxlength="128" name="erp_sys_org_sm_page_instagram" id="erp_sys_org_sm_page_instagram" value="<?php echo @$customerData['erp_sys_org_sm_page_instagram'];?>" autofocus="autofocus" class="form-control" placeholder="Facebook">
                                                            </div>
                                                        </div>      
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Business Whatsapp Number</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" maxlength="128" name="erp_sys_org_id_msngr_whatsapp" id="erp_sys_org_id_msngr_whatsapp" value="<?php echo @$customerData['erp_sys_org_id_msngr_whatsapp'];?>" autofocus="autofocus" class="form-control" placeholder="Business Whatsapp">
                                                            </div>
                                                        </div>                                            
                                                    </div><!--end card-body-->
                                                </div><!--end card-->

                                                <!-- Sales Representative --->
                                                <div class="card">
                                                    <div class="card-header">
                                                        <div class="row align-items-center">
                                                            <div class="col-11">                      
                                                                <h4 class="card-title text-left">Sales Representative </h4>                      
                                                            </div><!--end col-->                                                    
                                                        </div>  <!--end row-->                                  
                                                    </div><!--end card-header-->
                                                    <div class="card-body">                                                                          
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Assigned to Sales Representative</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <?php $staffData = $commonFunctions->getData('sys_erp_adm_user',' WHERE erp_sys_user_isActive = 0 '); ?>
                                                                <select id="assigned_to_sales" name="assigned_to_sales" class="flat assigned_to_sales form-control">
                                                                    <option value="0" >Select&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
                                                                    <?php foreach ($staffData as $rw) { ?>
                                                                        <option <?php echo (!empty($customerData['assigned_to_sales']) and $customerData['assigned_to_sales'] == $rw['id'] )?"selected":"";?> value="<?php echo $rw['id'];?>" ><?php echo $rw['erp_sys_user_name_first']." ".$rw['erp_sys_user_name_middle']." ".$rw['erp_sys_user_name_last']; ?></option>     
                                                                    <?php } ?>
                                                                </select>
                                                            </div>
                                                        </div>                                                
                                                    </div><!--end card-body-->
                                                </div><!--end card-->
                                            </div> <!--end col--> 
                                            <!-- Contact Information Personal  Card - End --->

                                            <!-- Contact Information Card Official - Start --->
                                            <div class="col-lg-6 col-xl-6">
                                                <div class="card">
                                                    <div class="card-header">
                                                        <div class="row align-items-center">
                                                            <div class="col-11">                      
                                                                <h4 class="card-title text-left">Company Category</h4>
                                                            </div><!--end col-->                                                      
                                                        </div>  <!--end row-->                                  
                                                    </div><!--end card-header-->
                                                    <div class="card-body">                                                                          
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Customer Status <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <select class="flat form-control" id="customer_status" name="customer_status">
                                                                    <option value="0" <?php echo empty($customerData['customer_status'])?"selected":"";?>>Organization</option>
                                                                    <option value="1" <?php echo !empty($customerData['customer_status'])?"selected":"";?>>Individual</option>
                                                                </select>
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">    
                                                            <?php $companyData = $commonFunctions->getData('global_org_type_of_company',' '); ?>
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Commercial Registration Type <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <select id="type_of_company" class="flat type_of_company form-control" name="type_of_company">
                                                                    <option>Select Type of Company</option>
                                                                    <?php foreach ($companyData as $rw) { ?>
                                                                        <option <?php echo (!empty($customerData['type_of_company']) and $customerData['type_of_company'] == $rw['id'] )?"selected":"";?> value="<?php echo $rw['id'];?>" ><?php echo $rw['label'];?></option>     
                                                                    <?php } ?>
                                                                </select>
                                                            </div>
                                                        </div>  
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Prospect / Customer <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <select class="flat form-control" name="client" id="customerprospect" >
                                                                    <option value="1" <?php echo (!empty($customerData['client']) and $customerData['client'] == 1)?"selected":"";?>>Customer</option>
                                                                    <option value="2" <?php echo (!empty($customerData['client']) and $customerData['client'] == 2)?"selected":"";?>>Prospect</option>
                                                                    <option value="3" <?php echo (!empty($customerData['client']) and $customerData['client'] == 3)?"selected":"";?>>Prospect / Customer</option>
                                                                    <option value="0" <?php echo (@$customerData['client'] == "0")?"selected":"";?>>Not Prospect, or Customer</option>
                                                                </select>
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Vendor / Supplier</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <select class="flat form-control" id="fournisseur" name="fournisseur">
                                                                    <option value="0" <?php echo (@$customerData['fournisseur'] == "0")?"selected":"";?> >No</option>
                                                                    <option value="1" <?php echo !empty($customerData['fournisseur'])?"selected":"";?> >Yes</option>
                                                                </select>
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Status <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <select id="status" class="flat status form-control" name="status" >
                                                                    <option value="1" <?php echo !empty($customerData['status'])?"selected":"";?> >Open</option>
                                                                    <option value="0" <?php echo (@$customerData['status'] == "0")?"selected":"";?>>Closed</option>
                                                                </select>
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center"> Cust./Prosp. Tags / Categories </label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <select id="custcats" name="custcats[]" class="flat custcats form-control">
                                                                    <option value="0">Select</option>
                                                                    <?php $TagData = $commonFunctions->getData('crm_cust_tag',''); ?>
                                                                    <?php foreach ($TagData as $rw) { ?>
                                                                        <option value="<?php echo $rw['id'];?>" ><?php 
                                                                        if($rw['parent_id'] > 0){
                                                                            echo $commonFunctions->getName($rw['parent_id'],'crm_cust_tag','label','id')." >> ";           
                                                                        }
                                                                        echo $rw['label']; ?></option>
                                                                    <?php } ?>
                                                                </select>
                                                            </div>
                                                        </div>
                                                    </div><!--end card-body-->
                                                </div><!--end card-->

                                                <div class="card">
                                                    <div class="card-header">
                                                        <div class="row align-items-center">
                                                            <div class="col-11">                      
                                                                <h4 class="card-title text-left">Office Address </h4>                      
                                                            </div><!--end col-->                                                   
                                                        </div>  <!--end row-->                                  
                                                    </div><!--end card-header-->
                                                    <div class="card-body">                                                                          
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Address ( Line 1 )</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" class="form-control" value="<?php echo @$customerData['address'];?>" name="address">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Address ( Line 2 )</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" name="address2" class="form-control" value="<?php echo @$customerData['address2'];?>">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Country <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <?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 <?php echo (!empty($customerData['country_id']) and $customerData['country_id'] == $rw['rowid'] )?"selected":"";?> value="<?php echo $rw['rowid'];?>" ><?php echo $rw['label']."(".$rw['code'].")"; ?></option>     
                                                                    <?php } ?>
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">State / Province <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <?php $stateData = $commonFunctions->getData('sys_erp_adm_countries_states',' WHERE rowid = "'.@$customerData['state_id'].'" '); ?>
                                                                <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>

                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">City <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" class="form-control" name="city" id="city" value="<?php echo @$customerData['city'];?>">
                                                            </div>
                                                        </div>

                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Zip / Pin / PO Box <span class="error">*</span></label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" class="form-control" name="postcode" value="<?php echo @$customerData['postcode'];?>">
                                                            </div>
                                                        </div>
                                                                                                            
                                                    </div><!--end card-body-->
                                                </div><!--end card-->

                                                <div class="card">
                                                    <div class="card-header">
                                                        <div class="row align-items-center">
                                                            <div class="col-11">                      
                                                                <h4 class="card-title text-left">TAX & Other Leagal's </h4>                      
                                                            </div><!--end col-->                                                   
                                                        </div>  <!--end row-->                                  
                                                    </div><!--end card-header-->
                                                    <div class="card-body">                                                                          
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">TAX ID 1</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" name="tax_id_1" class="form-control" value="<?php echo @$customerData['tax_id_1'];?>">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">TAX ID 2</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" name="tax_id_2" class="form-control" value="<?php echo @$customerData['tax_id_2'];?>">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">TAX ID 3</label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" name="tax_id_3" class="form-control" value="<?php echo @$customerData['tax_id_3'];?>">
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Import ID </label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" class="form-control" value="<?php echo @$customerData['import_id'];?>" name='import_id' >
                                                            </div>
                                                        </div>
                                                        <div class="form-group row">                                         
                                                            <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Export ID </label>
                                                            <div class="col-lg-9 col-xl-8">
                                                                <input type="text" class="form-control" value="<?php echo @$customerData['export_id'];?>" name='export_id' >
                                                            </div>
                                                        </div>                                        
                                                    </div><!--end card-body-->
                                                </div><!--end card-->
                                            </div> <!-- end col -->
                                            <!-- Contact Information Official Card - End --->
                                                                                  
                                        </div><!--end row-->
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php endif; ?>
                <?php if(empty($_GET['state']) OR (!empty($_GET['state']) and $_GET['state'] == "customer-list")): ?>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="main-card mb-3 ">
                                    <!-- <div class="card-body"> -->
                                    <?php    
                                        $targetpage = "customer.php?state=customer-list";

                                        $limit = 50;
                                        $total_pages = $commonFunctions->getData('crm_cust_details','');
                                        $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'])){
                                            $countryArr = $commonFunctions->getIDs('sys_erp_adm_countries','rowid'," WHERE label LIKE '%".$_GET['search']."%' ");
                                            $sys_erp_adm_countries_statesArr = $commonFunctions->getIDs('sys_erp_adm_countries_states','rowid'," WHERE label LIKE '%".$_GET['search']."%' ");
                                            $country_ids = @$countryArr["ids"];
                                            $state_ids = @$sys_erp_adm_countries_statesArr["ids"];
                                            $search_con = " AND customer_code LIKE '%".$_GET['search']."%' OR name LIKE '%".$_GET['search']."%' OR barcode LIKE '%".$_GET['search']."%' OR alias_name LIKE '%".$_GET['search']."%' OR vendor_code LIKE '%".$_GET['search']."%' OR email LIKE '%".$_GET['search']."%' OR phone LIKE '%".$_GET['search']."%' OR postcode LIKE '%".$_GET['search']."%' ";
                                            
                                            if(!empty($country_ids)){ $search_con .= "  OR country IN(".$country_ids.") "; }
                                            if(!empty($state_ids)){ $search_con .= "  OR state IN(".$state_ids.") "; }
                                        }
                                        $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('crm_cust_details',$where);
                                        ?>
                                        <div class="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  data-priority="1" class="text-center">Customer Name</th>
                                                            <th data-priority="4" class="text-center">Customer ID#</th>
                                                            <!-- <th data-priority="5" class="text-center">Vendor Code</th> -->
                                                            <th data-priority="6" class="text-center">Phone</th>
                                                            <th data-priority="6" class="text-center">Email Address</th>

                                                            <th data-priority="6" class="text-center">City</th>
                                                            <th data-priority="8" class="text-center">Country</th>
                                                            <!-- <th data-priority="7" class="text-center">State</th> -->
                                                            <th data-priority="7" class="text-center">Status</th>
                                                        </tr>

                                                    </thead>
                                                    <tbody>
                                                        <?php foreach ($resultData as $rw) { ?>
                                                            <tr onclick="redirect_('customer-card.php?customer_id=<?php echo $rw['id'];?>')">

                                                                <td><a href="javascript:void(0);" style="color: blue;"><?php echo $rw['name'];?></a></td>
                                                                <td><a href="javascript:void(0);" style="color: blue;"><?php echo $rw['customer_code'];?></a></td>
                                                                <td><?php echo $rw['phone'];?></td>
                                                                <td><?php echo $rw['email'];?></td>
                                                                <td><?php echo $rw['city'];?></td>
                                                                <td><?php echo $commonFunctions->getName($rw['country'],"sys_erp_adm_countries","label","rowid");?> </td>
                                                                <!-- <td><?php echo $commonFunctions->getName($rw['state'],"sys_erp_adm_countries_states","label","rowid");?></td> -->
                                                                <td>
                                                                    <?php if($rw['status'] == 1){ ?>
                                                                        <span class="badge badge-soft-success">Active</span>
                                                                    <?php }else{ ?>
                                                                        <span class="badge badge-soft-danger">Inactive</span>
                                                                    <?php } ?>
                                                                </td>
                                                            </tr>
                                                        <?php } ?>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                        <?php echo "<center>".$paginate."</center>";?>
                                <!-- </div> -->
                            </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div> <!-- end col -->
        <?php endif; ?>
    </div> <!-- end row -->

    
<?php require "../inc/footer.php"; ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.15.1/jquery.validate.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $(".datatable_t").dataTable();
    $('.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' );
        } );
    } );
} );*/

$("#clearbtn").click(function(){
    $("#search").val('');
    $("#searchForm").submit();
});
$("#country").change(function(){
    var country = $("#country option:selected").val();
    $.ajax({
        type: 'POST',
        url: "",
        data: {"country_id":country,"action":"ajax_call"},
        success: function(response) { 
            obj = JSON.parse(response);
            $("#state").html("<option value=''>Select State / Province</option>"+obj.option);
        }
    });
})
$(function() {
    $("#city").autocomplete({
        source: function(request, response) {
            $.getJSON("", { country_id: $('#country option:selected').val(),state_id: $('#state option:selected').val(),keyword: request.term,action:"ajax_call1" }, response);
        },
        minLength: 2,
    });
});
function redirect_(uri){
    window.location.href = uri;
}
$("#saveForm").click(function(){
    if($("#custForm").valid()){
        $("#custForm").submit();
    }
});
</script>