<?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";
    $id = @$_POST["id"];
    $status = @$_POST["status"];
    $lastid = $commonFunctions->updateData('crm_cust_details'," WHERE id = '".@$id."'"," status='".@$status."'","");
    if(!empty($id)){
        Session::set('msg', '<div class="alert alert-success alert-dismissible mt-3" id="flash-msg"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Success !</strong> Customer status saved!</div>');
        echo 1;
    }else{
        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 status not saved!</div>');
        echo 2;
    }
    exit();
}
require "../inc/header.php";
$msg = Session::get('msg');
Session::set("msg", NULL);

if(!empty($_POST['action']) and $_POST['action'] == "profile"){
    $column = $fileName = "";
    if($_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 = " logo = '".$_FILES["logo"]["name"]."' ";
            $commonFunctions->updateData('crm_cust_details'," WHERE id = '".$_POST['customer_id']."' ", $fileName ,'customer-card.php?customer_id='.$_POST['customer_id']);
        }
    }else{
        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> User profile picture not saved!</div>');
        echo "<script>location.href='customer-card.php?customer_id=".$_POST['customer_id']."';</script>";
    }
}

$customerData = $commonFunctions->getRowData('crm_cust_details'," WHERE id = '".@$_GET['customer_id']."' ");

$cntB = $commonFunctions->getRecordCount('sys_erp_organaization','');
if($cntB == 1){
    $companyData = $commonFunctions->getRowData('sys_erp_organaization'," WHERE id != '0' ");
}

?>

    <!-- Page-Title -->
    <div class="row">
        <div class="col-sm-12">
            <div class="page-title-box">
                <div class="row">
                    <div class="col form-row">
                    	<div class="col-sm-9">
                            <h4 class="page-title"><?php echo @$customerData['name'];?></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<?php echo (!empty($_GET['state']) and $_GET['state'] == "customer-form")?" Form ":" List "; ?></a></li>
                                <li class="breadcrumb-item active"><?php echo @$customerData['name'];?></li>
                            </ol>
                        </div>
                        
                        <div class="col-auto align-self-center">
                            <a href="customer.php?state=customer-form&customer_id=<?php echo $customerData['id'];?>" class="btn btn-secondary btn-sm">
                                <i class="fas fa-edit align-self-center icon-xs"></i> Edit 
                            </a>
                            <?php $id = @$customerData['id'];?>
                            <?php if($customerData['status'] == 1){ ?>
                                <a href="javascript:void(0);" class="btn btn-danger btn-sm" onclick="change_flag('0','<?php echo $id;?>')">
                                    <i class="fas fa-times-circle align-self-center icon-xs"></i> Deactivate
                                </a>
                            <?php }else{ ?>
                                <a href="javascript:void(0);" class="btn btn-success btn-sm" onclick="change_flag('1','<?php echo $id;?>')" >
                                    <i class="fas fa-check-circle align-self-center icon-xs"></i> Activate
                                </a>
                            <?php } ?>
                            <a href="customer.php?state=customer-list" class="btn btn-secondary btn-sm" style="background: black;">
                                <i class="fas fa-angle-double-left align-self-center icon-xs"></i> Back to List
                            </a>
                        </div>
                        
                        <div class="col-sm-3" style="text-align: end;">


                            <!-- <a href="customer.php?state=customer-form&customer_id=<?php echo $customerData['id'];?>">
                            	<button type="button" class="btn btn-sm btn-outline-primary">Edit</button>
                            </a> -->
                            
                            <!-- <a href="customer.php?state=customer-list"><button type="button" class="btn btn-sm btn-outline-secondary clear_form">Back to Products List</button></a> -->
                            
                        </div>
                    </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-12">
            <div class="card">
                <!--div class="card-body p-0">
                    <div id="user_map" class="pro-map" style="height: 220px"></div>                                     
                </div--><!--end card-body-->                                
                <div class="card-body">
                    <div class="dastone-profile">
                        <div class="row">
                            <div class="col-lg-3 align-self-center mb-3 mb-lg-0">

                                <div class="dastone-profile-main">
                                    <div class="dastone-profile_user-detail dastone-profile-main-pic">
                                        <img src="../uploads/crm/<?php echo (@$customerData['logo'])?$customerData['logo']:'default-img.jpg';?>" alt="" height="110" class="thumb-lx rounded" style='max-width:140px;'>
                                        <span class="dastone-profile_main-pic-change">
                                            <i class="fas fa-camera"></i>
                                        </span>
                                        <form enctype="multipart/form-data" method="post" id="fileUploadForm">
                                            <input type="hidden" name="action" value="profile">
                                            <input type="hidden" name="customer_id" value="<?php echo $customerData['id'];?>">
                                            <input type="file" name="logo" value="" style='display: none;' id="fileUpload">
                                        </form>
                                    </div>
                                </div>

                            </div><!--end col-->
                            <div class="col-lg-5 align-self-center mb-3 mb-lg-0">
                                <div class="dastone-profile-main">     
                                    <div class="dastone-profile_user-detail">
                                        <h5 class="dastone-user-name"><?php echo $customerData["name"];?></h5>
                                        <p class="mt-0 mb-0"><i class="text-secondary font-22 align-middle"></i> <b> Company Registration No :</b>  <?php echo $customerData["commercial_registration_no"];?></p>
                                        <p class="mt-0 mb-0"><i class="text-secondary font-22 align-middle"></i> <b> H.O :</b>  <?php echo $customerData["address"];?> <?php echo $customerData["address2"];?>, <?php echo $customerData["city"];?>, <?php echo $commonFunctions->getName(@$customerData['country'],'sys_erp_adm_countries','label','rowid');?>

                                    </p>
                                    </div>
                                </div>                                                
                            </div><!--end col-->
                            
                            <div class="col-lg-4 ml-auto align-self-center">
                                <ul class="list-unstyled personal-detail mb-0">
                                    <li class="mt-2"><i class="las la-phone mr-2 text-secondary font-22 align-middle"></i> <b> phone </b> :  <?php echo $customerData["phone"];?></li>
                                    <li class="mt-2"><i class="las la-fax mr-2 text-secondary font-22 align-middle"></i> <b> mobile </b> :  </li>
                                    <li class="mt-2"><i class="las la-envelope text-secondary font-22 align-middle mr-2"></i> <b> Email </b> :   <a href="mailto:<?php echo $customerData['email'];?>"><?php echo $customerData["email"];?></a></li>                                                  
                                </ul>                                               
                            </div><!--end col-->
                        </div><!--end row-->
                    </div><!--end f_profile-->                                                                                
                </div><!--end card-body-->          
            </div> <!--end card-->    
        </div><!--end col-->
         
    </div><!--end row-->
    <div class="pb-4">
        <ul class="nav-border nav nav-pills mb-0" id="pills-tab" role="tablist">
            <li class="nav-item">
                <a class="nav-link active" id="CompanyProfileTab" data-toggle="pill" href="#CompanyProfileDetails">Company Profile</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="ContactPersonDetails_tab" data-toggle="pill" href="#ContactPersonDetails">Contact Persons</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="BranchORShippingAddress_tab" data-toggle="pill" href="#BranchORShippingAddress">Branch & Shipping Address</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="Invoice_tab" data-toggle="pill" href="#Invoice">Invoices</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="DeliveryNote_tab" data-toggle="pill" href="#DeliveryNote">Delivery Notes</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="QuoteTab" data-toggle="pill" href="#quote">Quote</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="PurchasesTab" data-toggle="pill" href="#Purchases">Purchases</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" id="note_tab" data-toggle="pill" href="#note">Notes</a>
            </li>
        </ul>        
    </div><!--end card-body-->
    <style type="text/css">
    	label.form-control1 {display: block;}
    	label.label-title {font-weight: 600;}
    </style>
    <div class="row">
        <div class="col-12">
            <div class="tab-content" id="pills-tabContent">
                <div class="tab-pane fade show active" id="CompanyProfileDetails" role="tabpanel" aria-labelledby="CompanyProfileTab">
                    <div class="row">
                    	<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 Profile</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">Company Name</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo $customerData["name"];?> </h5>
                                        </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.)</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo $customerData["alias_name"];?> </h5>
                                        </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</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"><?php echo $customerData["commercial_registration_no"];?></h5>
                                        </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</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo $customerData["customer_code"];?> </h5>
                                        </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">
                                            <h5 class="card-title"><?php echo $customerData["logo"];?></h5>
                                        </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 ( Official )</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">
                                            <h5 class="card-title"> <?php echo $customerData["phone"];?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo $customerData["fax"];?> </h5>
                                        </div>
                                    </div>
                                    <div class="form-group row">                                   
                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Email Address</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo $customerData["email"];?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo $customerData["web"];?> </h5>
                                        </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">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">
                                            <h5 class="card-title"> <?php echo $customerData["org_sm_page_linkedin"];?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo $customerData["org_sm_page_twitter"];?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo $customerData["org_sm_page_facebook"];?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo $customerData["org_sm_page_instagram"];?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo $customerData["org_id_msngr_whatsapp"];?> </h5>
                                        </div>
                                    </div>
                                    
                                </div>
                            </div>
                        </div>

                        <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</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo (@$customerData['customer_status'] == 0)?"Organization":"";?><?php echo (@$customerData['customer_status'] == 1)?"Individual":"";?> </h5>
                                        </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 Type</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo $commonFunctions->getName(@$customerData['type_of_company'],'global_org_type_of_company','label','id');?> </h5>
                                        </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</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo (!empty($customerData['client']) and $customerData['client'] == 1)?"Customer":"";?><?php echo (!empty($customerData['client']) and $customerData['client'] == 2)?"Prospect":"";?><?php echo (!empty($customerData['client']) and $customerData['client'] == 3)?"Prospect / Customer":"";?><?php echo (@$customerData['client'] == "0")?"Not Prospect, or Customer":"";?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo (@$customerData['fournisseur'] == "0")?"No":"";?><?php echo (@$customerData['fournisseur'] == "1")?"Yes":"";?> </h5>
                                        </div>
                                    </div>
                                    <div class="form-group row">                                         
                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Status</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo !empty($customerData['status'])?"Open":"";?><?php echo (@$customerData['status'] == "0")?"Closed":"";?> </h5>
                                        </div>
                                    </div>
                                </div><!--end card-body-->
                            </div>

                            <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</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo $customerData["address"];?> </h5>
                                        </div>
                                    </div>
                                    <div class="form-group row">                                   
                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">City</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo $customerData["city"];?> </h5>
                                        </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</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo $commonFunctions->getName(@$customerData['state'],'sys_erp_adm_countries_states','label','rowid');?> </h5>
                                        </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</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"> <?php echo $customerData["postcode"];?> </h5>
                                        </div>
                                    </div>
                                    <div class="form-group row">                                   
                                        <label class="col-xl-3 col-lg-3 text-left mb-lg-0 align-self-center">Country</label>
                                        <div class="col-lg-9 col-xl-8">
                                            <h5 class="card-title"><?php echo $commonFunctions->getName(@$customerData['country'],'sys_erp_adm_countries','label','rowid');?></h5>
                                        </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">TAX &amp; 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">
                                            <h5 class="card-title"> <?php echo $customerData["tax_id_1"];?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo $customerData["tax_id_2"];?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo $customerData["tax_id_3"];?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo $customerData["import_id"];?> </h5>
                                        </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">
                                            <h5 class="card-title"> <?php echo $customerData["export_id"];?> </h5>
                                        </div>
                                    </div>                                        
                                </div><!--end card-body-->
                            </div>
                        </div>
                    </div>
                </div>
                <div class="tab-pane" id="ContactPersonDetails" role="tabpanel" aria-labelledby="ContactPersonDetails_tab">
                    <div class="card">
                		<div class="card-body">
                            <div style="padding-bottom: 1em;">
                                <a class="btn btn-outline-primary" href="address-book.php?state=add&customer_id=<?php echo @$_GET['customer_id'];?>" role="button"><i class="fas fa-plus mr-2"></i> Add Contact</a>
                            </div>
                            <?php 
                            $where = " WHERE third_party_id = '".@$_GET['customer_id']."' ";
                            $resultData = $commonFunctions->getData('crm_add_bk',$where); ?>
                        	<table style="width: 100%;" class="table datatable_t table-hover table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th  class="text-center">First Name</th>
                                        <th  class="text-center">Last Name</th>
                                        <th  class="text-center">Title</th>
                                        <th  class="text-center">Job Position</th>
                                        <th  class="text-center">Address</th>
                                        <th  class="text-center">City</th>
                                        <th  class="text-center">State / Province</th>
                                        <th  class="text-center">Country</th>
                                        <th  class="text-center">Postcode</th>
                                        <th  class="text-center">Prof Phone</th>
                                        <th  class="text-center">Pers Phone</th>
                                        <th  class="text-center">Email</th>
                                    </tr>

                                </thead>
                                <tbody>
                                    <?php foreach ($resultData as $rw) { ?>
                                        <tr>
                                            <td><?php echo $rw['first_name'];?></td>
                                            <td><?php echo $rw['last_name'];?></td>
                                            <td><?php echo $rw['title'];?></td>
                                            <td><?php echo $rw['job_position'];?></td>
                                            <td><?php echo $rw['address'];?></td>
                                            <td><?php echo $rw['city'];?></td>
                                            <td><?php echo @$commonFunctions->getname($rw['state_id'],"sys_erp_adm_countries_states","label",'rowid');?></td>
                                            <td><?php echo @$commonFunctions->getname($rw['country_id'],"sys_erp_adm_countries","label",'rowid');?></td>
                                            <td><?php echo $rw['postcode'];?></td>
                                            <td><?php echo $rw['prof_phone'];?></td>
                                            <td><?php echo $rw['pers_phone'];?></td>
                                            <td><?php echo $rw['email'];?></td>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>

                    	</div><!--end row-->    
                    </div>
                </div>
                <div class="tab-pane" id="BranchORShippingAddress" role="tabpanel" aria-labelledby="BranchORShippingAddress_tab">
                    <div class="card">
                		<div class="card-body">
                            <div style="padding-bottom: 1em;">
                                <a class="btn btn-outline-primary" href="../product-services/warehouse/warehouse.php?state=add" role="button"><i class="fas fa-plus mr-2"></i> Add Branch</a>
                            </div>

                        	<table style="width: 100% !important;" class="table datatable_t table-hover table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th class="text-center">SR No.</th>
                                        <th class="text-center">Warehouse Name</th>
                                        <th class="text-center">Warehouse Ref</th>
                                        <th class="text-center">Address</th>
                                        <th class="text-center">Zip / Pin Code</th>
                                        <th class="text-center">City</th>
                                        <th class="text-center">Country</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php $where = ""; 
                                    $productData = $commonFunctions->getData('invty_wrhus',$where); 
                                    foreach ($productData as $row) { 
                                        $i++;?>
                                        <tr onclick="redirect_1('../product-services/warehouse/warehouse.php?state=edit&warehouse_id=<?php echo $row['id'];?>')" >
                                        <th class="text-center text-primary" ><?php echo $row['reference_number'];?></th>
                                        <th class="text-center text-primary"><?php echo $row['short_name_location'];?></th>
                                        <th class="text-center"><?php echo $row['description'];?></th>
                                        <th class="text-center"><?php echo $row['address'];?></th>
                                        <th class="text-center"><?php echo $row['zip_code'];?></th>
                                        <th class="text-center"><?php echo $row['city'];?></th>
                                        <th class="text-center"><?php echo $row['country_id'];?></th>
                                    </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                    	</div><!--end row-->    
                    </div> <!--end row-->
				</div>
				<div class="tab-pane" id="DeliveryNote" role="tabpanel" aria-labelledby="DeliveryNote_tab">
                    <div class="card">
                		<div class="card-body">
                            <div style="padding-bottom: 1em;">
                                <a class="btn btn-outline-dark" href="../sales-purchases/sales-and-invoices/delivery-note.php?state=add&customer_id=<?php echo @$_GET["customer_id"];?>" role="button"><i class="fas fa-plus mr-2"></i> Create Delivery Note</a>
                            </div>

                        	<?php 
                        	$where1 = " WHERE ship_to = '".@$_GET["customer_id"]."' ";
                        	$invtData = $commonFunctions->getData('sys_erp_sales_delivery_note',$where1); ?>
                        	<table style="margin-top: 10px;width: 100% !important;" class="table datatable_t table-hover table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th class="text-center">Delivery Note No#</th>
                                        <th class="text-center">Invoice No#</th>
                                        <th class="text-center">Customer</th>
                                        <th class="text-center">Delivery Date</th>
                                        <th class="text-center">Amount</th>
                                        <th class="text-center">Status</th>
                                        <th class="text-center">Created By</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php 
                                    foreach ($invtData as $row) { ?>
                                        <tr onclick="redirect_('delivery-note-card.php?delivery_note_id=<?php echo $row['id'];?>')"> 
                                        <!-- <tr> -->
                                            <th class="text-center">
                                                <?php echo $row['delivery_note_no']; ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $row['invoice_no']; ?>
                                            </th>
                                            <th class="text-center">
                                                <?php 
                                                $bill_to = $commonFunctions->getname($row['invoice_id'],"sys_erp_sales_invoice","bill_to","id");
                                                echo $commonFunctions->getname($bill_to,"crm_cust_details","name","id");
                                                ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $row['delivery_date']; ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $row['total']; ?>
                                            </th>
                                            <th class="text-center">
                                                <?php if($row['dn_status'] == 1){ echo "<span class='btn btn-soft-danger btn-sm'>Drafted</span>"; }
                                                if($row['dn_status'] == 2){ echo "<span class='btn btn-soft-success btn-sm'>Partially Delivered</span>"; }
                                                if($row['dn_status'] == 3){ echo "<span class='btn btn-soft-primary btn-sm'>Delivered</span>"; } ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $commonFunctions->getname($row['delivery_note_creator'],"sys_erp_adm_user","erp_sys_user_name_first","id")." ".$commonFunctions->getname($row['delivery_note_creator'],"sys_erp_adm_user","erp_sys_user_name_last","id");
                                                ?>
                                            </th>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                    	</div><!--end row-->    
                    </div> <!--end row-->
				</div>
                <div class="tab-pane" id="Invoice" role="tabpanel" aria-labelledby="Invoice_tab">
                    <div class="card">
                		<div class="card-body">
                            <div style="padding-bottom: 1em;">
                                <a class="btn btn-outline-dark" href="../sales-purchases/sales-and-invoices/invoice.php?state=add" role="button"><i class="fas fa-plus mr-2"></i> Create Invoice</a>
                            </div>
                        	<?php 
                        	$where = " WHERE bill_to = '".@$_GET["customer_id"]."' ";
                        	$invtData = $commonFunctions->getData('sys_erp_sales_invoice',$where); ?>
                        	<table style="margin-top: 10px;width: 100% !important;" class="table datatable_t table-hover table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th class="text-center">Invoice No#</th>
                                        <th class="text-center">Customer</th>
                                        <th class="text-center">Invoice Date</th>
                                        <th class="text-center">Amount</th>
                                        <th class="text-center">Status</th>
                                        <th class="text-center">Created By</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php 
                                    foreach ($invtData as $row) { ?>
                                        <tr onclick="redirect_('invoice-card.php?invoice_id=<?php echo $row['id'];?>')">
                                            <th class="text-center">
                                                <?php echo $row['invoice_no']; ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $commonFunctions->getname($row['bill_to'],"crm_cust_details","name","id");
                                                ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $row['invoice_date']; ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $row['total']; ?>
                                            </th>
                                            <th class="text-center">
                                                <?php if($row['invoice_status'] == 0){ echo "<span class='btn btn-soft-danger btn-sm'>Unpaid</span>"; }
                                                if($row['invoice_status'] == 1){ echo "<span class='btn btn-soft-success btn-sm'>Paid</span>"; }
                                                if($row['invoice_status'] == 2){ echo "<span class='btn btn-soft-primary btn-sm'>Overdue</span>"; } ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $commonFunctions->getname($row['invoice_creator'],"sys_erp_adm_user","erp_sys_user_name_first","id")." ".$commonFunctions->getname($row['invoice_creator'],"sys_erp_adm_user","erp_sys_user_name_last","id");
                                                ?>
                                            </th>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                    	</div><!--end row-->    
                    </div>
                </div>
                <div class="tab-pane" id="quote" role="tabpanel" aria-labelledby="QuoteTab">
                    <div class="card">
                        <div class="card-body">
                            <div style="padding-bottom: 1em;">
                                <a class="btn btn-outline-dark" href="../sales-purchases/sales-and-invoices/quotation.php?state=add" role="button"><i class="fas fa-plus mr-2"></i> Create Quotation</a>
                            </div>
                            <?php 
                            $where = " WHERE bill_to = '".@$_GET["customer_id"]."' ";
                            $quotationData = $commonFunctions->getData('sys_erp_sales_quotation',$where); ?>
                            <table style="margin-top: 10px;width: 100% !important;" class="table datatable_t table-hover table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th class="text-center">Quotation No#</th>
                                        <th class="text-center">Customer</th>
                                        <th class="text-center">Creation Date</th>
                                        <th class="text-center">Amount</th>
                                        <th class="text-center">Status</th>
                                        <th class="text-center">Created By</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php 
                                    foreach ($quotationData as $row) { ?>
                                        <tr onclick="redirect_('quotation.php?state=add&flag=<?php echo $row['quotation_flag'];?>&quotation_id=<?php echo $row['id'];?>')">
                                            <th class="text-center">
                                                <?php echo $row['quotation_no']; ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $commonFunctions->getname($row['bill_to'],"crm_cust_details","name","id");
                                                ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $row['quotation_date']; ?>
                                            </th>
                                            <th class="text-center">
                                                <?php echo $row['total']; ?>
                                            </th>
                                            <th class="text-center">
                                                <?php if($row['quotation_flag'] == 0){ echo "<span class='badge badge-soft-warning'>Drafted</span>"; }
                                                if($row['quotation_flag'] == 1){ echo "<span class='badge badge-soft-primary'>Created</span>"; }
                                                if($row['quotation_flag'] == 3){ echo "<span class='badge badge-soft-danger'>Rejected</span>"; }
                                                if($row['quotation_flag'] == 2){ echo "<span class='btn btn-soft-success btn-sm'>Saved</span>"; }
                                                if($row['quotation_flag'] == 4){ echo "<span class='badge badge-danger'>Deleted</span>"; } ?>

                                            </th>
                                            <th class="text-center">
                                                <?php echo $commonFunctions->getname($row['quotation_creator'],"sys_erp_adm_user","erp_sys_user_name_first","id")." ".$commonFunctions->getname($row['quotation_creator'],"sys_erp_adm_user","erp_sys_user_name_last","id");
                                                ?>
                                            </th>
                                        </tr>
                                    <?php } ?>
                                </tbody>
                            </table>
                        </div><!--end row-->    
                    </div>
                </div>
                <div class="tab-pane" id="Purchases" role="tabpanel" aria-labelledby="PurchasesTab">
                    <div class="card">
                        <div class="card-body">
                            Purchases
                        </div><!--end row-->    
                    </div>
                </div>

                <div class="tab-pane" id="note" role="tabpanel" aria-labelledby="note_tab">
                    <div class="card">
                		<div class="card-body">
                        	<div class="form-row">
                        		<div class="col-md-12 position-relative form-group">
                        			<?php echo @$customerData['description'];?>
                        		</div>
                        	</div>
                        </div>
                    </div><!--end row-->
                </div>
            </div>
        </div>
    </div>


<?php require "../inc/footer.php"; ?>
<script type="text/javascript" src="https://www.jqueryscript.net/demo/Simple-jQuery-Based-Barcode-Generator-Barcode/jquery-barcode.js"></script>
<script type="text/javascript">
    
  	function generateBarcode(){
	    var value = "<?php echo strtolower(@$customerData['barcode_value']); ?>";
	    var btype = "<?php echo strtolower(@$barcode_type); ?>";
	    var renderer = "css";
    	var quietZone = false;
	    
	    var settings = {
	      	output:renderer,
	      	bgColor: "#FFFFFF",
	      	color: "#000000",
	      	barWidth: "2",
	     	barHeight: "50",
	      	moduleSize: "5",
	      	posX: "10",
	      	posY: "20",
	      	addQuietZone: "1"
	    };
    	if (renderer == 'canvas'){
      		clearCanvas();
	      	$("#barcodeTarget").hide();
	      	$("#canvasTarget").show().barcode(value, btype, settings);
    	} else {
      		$("#canvasTarget").hide();
      		$("#barcodeTarget").html("").show().barcode(value, btype, settings);
    	}
  	}
      
  	function showConfig1D(){
	    $('.config .barcode1D').show();
	    $('.config .barcode2D').hide();
  	}
  
  	function showConfig2D(){
	    $('.config .barcode1D').hide();
	    $('.config .barcode2D').show();
  	}
  
  	function clearCanvas(){
	    var canvas = $('#canvasTarget').get(0);
	    var ctx = canvas.getContext('2d');
	    ctx.lineWidth = 1;
	    ctx.lineCap = 'butt';
	    ctx.fillStyle = '#FFFFFF';
	    ctx.strokeStyle  = '#000000';
	    ctx.clearRect (0, 0, canvas.width, canvas.height);
	    ctx.strokeRect (0, 0, canvas.width, canvas.height);
  	}
  
  	$(function(){
    	generateBarcode();
  	});
function redirect_(uri){
    window.location.href = uri;
}
function redirect_1(uri){
    $("<a>").prop({ target: "_blank",href: uri })[0].click();
}
$(".dastone-profile_main-pic-change").click(function(){
    $("#fileUpload").click();
});
$("#fileUpload").change(function(){
    if(confirm("Please make sure do you want to change your profile picture?")){
        $("#fileUploadForm").submit();
    }else{
        return false;
    }
});
$(".table").dataTable({

});
function change_flag(state,id){
    if(confirm("Do you want to change?")){
        $.ajax({
            type: 'POST',
            url: "",
            data: {"status":state,"action":"ajax_call","id":id},
            success: function(response) { 
                if(response == 1){
                    if(alert("Wow, Your Information updated Successfully !")){
                        window.location.href = '';
                    }else{
                        window.location.href = '';
                    }
                }else{
                    alert("Customer status not saved!");
                }
            }
        });
    }
}
</script>