<?php $_REQUEST['src']='ext2';require('../../functions/global.php');?>

<?php 
   $stmt = $GLOBALS['con']->prepare("SELECT * FROM `clientdetails` WHERE `clientnumber`=? ")or die(mysqli_error($GLOBALS['con']));
   $stmt->bind_param('i',$_REQUEST['clientnumber']);$stmt->execute();$cr=$stmt->get_result();$stmt->close();
   $cd=mysqli_fetch_array($cr);
   $renewOptions=json_decode($cd['renewOptions'],true);
  // print_r($renewOptions);
   switch($renewOptions['notice']){
    default:$renewMode="unset";break;
    case "0": $renewMode="client"; 
        $name=$cd['billing_name'];
        $name=str_replace("&","and",$name);
        $email=$cd['billing_email'];
        $phone=$nameData['billing_phone'];
        $address1=$cd['billing1'];
        $address2=$cd['billing2'];
        $address3=$cd['billing_town'];
        $address4=$cd['billing_county'];
        $address5=$cd['billing_postcode'];
        $billingLink='';
    break;
    case "1": $renewMode="agent"; 
        $bc=mysqli_query($GLOBALS['con'],"SELECT * FROM `agents` WHERE `agent_number`='".$cd['agent_number']."' ")or die(mysqli_error("Get_Name_Info: ".$GLOBALS['con']));
        $nameData=mysqli_fetch_array($bc);
        $name=$nameData['agent_name'];
        $name=str_replace("&","and",$name);
        $email=$nameData['billing_email'];
        $phone=$nameData['billing_phone'];
        $address1=$nameData['billing1'];
        $address2=$nameData['billing2'];
        $address3=$nameData['billing_town'];
        $address4=$nameData['billing_county'];
        $address5=$nameData['billing_postcode'];
        $billingLink='<a href="index.php?t=includes/master&p=agent.php&agent_number='.$cd['agent_number'].'&view=edit" class="btn btn-info mr-4">Edit Agent Details</a>';
    break;
    case "2": $renewMode="broker"; 
        $bc=mysqli_query($GLOBALS['con'],"SELECT * FROM `brokers` WHERE `broker_number`='".$cd['broker_number']."' ")or die(mysqli_error("Get_Name_Info: ".$GLOBALS['con']));
        $nameData=mysqli_fetch_array($bc);
        $name=$nameData['broker_name'];
        $name=str_replace("&","and",$name);
        $email=$nameData['billing_email'];
        $phone=$nameData['billing_phone'];
        $address1=$nameData['billing1'];
        $address2=$nameData['billing2'];
        $address3=$nameData['billing_town'];
        $address4=$nameData['billing_county'];
        $address5=$nameData['billing_postcode'];
        $billingLink='<a href="index.php?t=includes/master&p=broker.php&broker_number='.$cd['broker_number'].'&view=edit" class="btn btn-info mr-4">Edit Broker Details</a>';
    break;
  }
   ?>

<div class="row mb-5">
    <div class="col-12">
        <h4>Renewal information - <span id="name"><?= getClientName($_REQUEST['clientnumber'])?></span> <strong>(<?= strtoupper($renewMode)?>)</strong></h4>
    </div>
</div>


<div class="row">
    <div class="col-12 col-md-6">
        <div class="card">
            <div class="card-header"><strong><?= ucfirst($renewMode)?></strong> Billing Information</div>
            <div class="card-body">
                <div class="row">
                    <label class="col-12 col-md-5 control-label" for="billing_name">Billing Contact Name</label>
                    <div class="col-12 col-md-7"><?= $name?></div>
                </div>
                <div class="row">
                    <label class="col-12 col-md-5 control-label" for="billing1">Address 1</label>
                    <div class="col-12 col-md-7"><?= $address1?></div>
                </div>
                <div class="row">
                    <label class="col-12 col-md-5 control-label" for="billing2">Address 1</label>
                    <div class="col-12 col-md-7"><?= $address2?></div>
                </div>

                <div class="row">
                    <label class="col-12 col-md-5 control-label" for="billing_town">Town</label>
                    <div class="col-12 col-md-7"><?= $address3?></div>
                </div>
                <div class="row">
                    <label class="col-12 col-md-5 control-label" for="billing_county">County</label>
                    <div class="col-12 col-md-7"><?= $address4?></div>
                </div>
                <div class="row">
                    <label class="col-12 col-md-5 control-label" for="billing_postcode">Postcode</label>
                    <div class="col-12 col-md-7"><?= $address5?></div>
                </div>
                <div class="row">
                    <label class="col-12 col-md-5 control-label" for="billing_phone">Phone</label>
                    <div class="col-12 col-md-7"><?= $phone?></div>
                </div>
                <div class="row">
                    <label class="col-12 col-md-5 control-label" for="billing_email">Email</label>
                    <div class="col-12 col-md-7"><?= $email?></div>
                </div>
            </div>
        </div>
    </div>

    <div class="col-12 col-md-6">
        <div class="card">
            <div class="card-header">Contract Details</div>
            <div class="card-body">

                <div class="row">
                    <?php if($cd['contractMode']=="1"){$checked="Yes";}else{$checked="No";}?>
                    <label class="col-12 col-md-5 control-label" for="contractMode">Annual Contract</label>
                    <div class="col-12 col-md-7"><?= $checked?></div>
                </div>

                <div id="contractOptions">
                    <div class="row">
                        <label class="col-12 col-md-5 control-label" for="rate_per_hour">Contract Fee</label>
                        <div class="col-12 col-md-7"><?= $cd['rate_per_hour']?></div>
                    </div>
                    <div class="row">
                        <label class="col-12 col-md-5 control-label" for="incepton_date">Inception Date</label>
                        <div class="col-12 col-md-7"><?php if($cd['incepton_date']==""){echo date('d-m-Y');}else{ echo date('d-m-Y',$cd['incepton_date']);}?></div>
                    </div>
                    <div class="row">
                        <label class="col-12 col-md-5 control-label" for="term_years">Term Years</label>
                        <div class="col-12 col-md-5"><?php $cd['term_years']?></div>
                    </div>

                    <div class="row">
                        <label class="col-12 col-md-5 control-label" for="renewal_date">Renewal Date</label>
                        <div class="col-12 col-md-7"><?= date('d-m-Y',$cd['renewal_date'])?></div>
                    </div>
                    <div class="row">
                        <label class="col-12 col-md-5 control-label" for="renewal_status">Renewal Status</label>
                        <div class="col-12 col-md-5"><?= $cd['renewal_status']?></div>
                    </div>


                    <div class="row">
                        <label class="col-12 col-md-5 control-label" for="renewal_status">Auto Renew</label>
                        <div class="col-12 col-md-5"><?php if($cd['autoRenew']=="1"){$checked="YES";}if($cd['autoRenew']=="0"){$checked="NO";}?>
                            <?= $checked?></div>
                    </div>

                </div>
            </div>
        </div>
    </div>



</div>
<div class="row">
    <div class="col-12 text-center mt-3"><?= $billingLink?><a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=edit" class="btn btn-info">Edit Client Details</a></div>
</div>

<script>
$(".datepicker").pickadate({
    format: "dd-mm-yyyy",
    formatSubmit: "dd-mm-yyyy",
    selectMonths: true,
    max: new Date(),
});
</script>