<?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);?>
<div id="printbox">
    <div class="row mb-4">
        <script>
        $('#navBox').html(
            '<li class="breadcrumb-item"><a href="index.php?t=includes/master&p=client.php&view=list">Client List</a><i class="fad fa-angle-double-right mx-2 mt-1"" aria-hidden="true"></i></li><li class="breadcrumb-item"><a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=load"><?= $cd['clientname']?></a><i class="fad fa-angle-double-right mx-2 mt-1"" aria-hidden="true"></i></li><li class="breadcrumb-item active">View Client</li>'
        )
        </script>
        <div class="w-100 d-flex justify-content-sm-around justify-content-md-end flex-wrap mt-0 mt-md-n5">
            <a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=asset" class="btn btn-secondary noprint" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover"
               totitle="hover" title="View Schedule"><i
                   class="fad fa-th-list"></i></a>

            <a id="newSite" href="index.php?t=includes/master&p=locations.php&clientnumber=<?= $_REQUEST['clientnumber']?>&clientname=<?= getClientName($_REQUEST['clientnumber'])?>" class="btn btn-secondary" data-toggle="tooltip"
               data-placement="bottom" title="View Locations"><i class="fad fa-building" aria-hidden="true"></i></a>

            <a id="phone" href="tel:<?= $cd['phone1']?>" class="btn btn-secondary noprint" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover" totitle="hover" title="Phone Client"><i class="fad fa-phone"></i></a>

            <?php if($_SESSION['access']==1 || $_SESSION['access']==999){?>
            <a href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=edit" class="btn btn-secondary noprint" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover" tom"
               data-mdb-trigger="hover"
               title="Edit Client Details"><i class="fad fa-edit"></i></a>
            <?php }?>

            <?php if(!filter_var($cd['email'], FILTER_VALIDATE_EMAIL) === false) {?>
            <a href="javascript:void(0)" class="btn btn-secondary noprint emailButton" data-values="<?= $_REQUEST['clientnumber']?>|<?= $cd['pri_contact_name']?>|<?= $cd['email']?>|<?= $cd['clientname']?>"
               data-href="includes/master/mailer.php" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover" totitle="hover" title="Email Client"><i class="fad fa-envelope"></i></a>
            <?php }?>

            <a href="index.php?t=includes/client&p=client_addressbook.php&clientnumber=<?= $_REQUEST['clientnumber']?>" class="btn btn-secondary noprint " data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover"
               totitle="hover" title="Address Book"><i
                   class="fad fa-address-book"></i></a>

            <?php if($cd['statuslive']==1){?>
            <a href="javascript:void(0)" class="btn btn-secondary noprint archiveButton" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover" totitle="hover" title="Archive Client" data-
               onClick="archiveClient('<?= $_REQUEST['clientnumber']?>')"><i
                   class="fad fa-archive"></i></a>
            <?php }?>

            <?php if($cd['statuslive']==0){?>
            <a href="javascript:void(0)" class="btn btn-secondary noprint archiveButton" data-mdb-tooltip-init data-mdb-placement="bottom" data-mdb-trigger="hover" totitle="hover" title="Activate Client"
               onClick="activateClient('<?= $_REQUEST['clientnumber']?>')"><i
                   class="fad fa-upload"></i></a>
            <?php }?>
        </div>

    </div>
    <?php if(empty($_SESSION['contractorNumber'])){?>
    <div class="row card-data card-block">
        <div class="col-12 col-md-9">
            <div class="row">

                <div class="col-12 col-md-6">
                    <div class="card card-cascade">
                        <div class="card-header">Client Detailss</div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12 col-md-6">
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Clientname</div>
                                        <div class="col-12 col-md-8"><?= $cd['clientname']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Address1</div>
                                        <div class="col-12 col-md-8"><?= $cd['address1']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Address2</div>
                                        <div class="col-12 col-md-8"><?= $cd['address2']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Town</div>
                                        <div class="col-12 col-md-8"><?= $cd['town']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">County</div>
                                        <div class="col-12 col-md-8"><?= $cd['county']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Postcode</div>
                                        <div class="col-12 col-md-8"><?= $cd['postcode']?></div>
                                    </div>
                                </div>
                                <div class="col-12 col-md-6">
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Phone1</div>
                                        <div class="col-12 col-md-8"><?= $cd['phone1']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Phone2</div>
                                        <div class="col-12 col-md-8"><?= $cd['phone2']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Mobile</div>
                                        <div class="col-12 col-md-8"><?= $cd['mobile']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Fax</div>
                                        <div class="col-12 col-md-8"><?= $cd['fax']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Email</div>
                                        <div class="col-12 col-md-8"><?= $cd['email']?></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="col-12 col-md-6 mt-5 mt-md-0">
                    <div class="card card-cascade">
                        <div class="card-header">Primary Contact</div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12 col-md-4 title">Pri Contact Name</div>
                                <div class="col-12 col-md-8"><?= $cd['pri_contact_name']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Pri Contact Position</div>
                                <div class="col-12 col-md-8"><?= $cd['pri_contact_position']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Pri Contact Tel</div>
                                <div class="col-12 col-md-8"><?= $cd['pri_contact_tel']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Pri Contact Mob</div>
                                <div class="col-12 col-md-8"><?= $cd['pri_contact_mob']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Pri Contact Email</div>
                                <div class="col-12 col-md-8"><?= $cd['pri_contact_email']?></div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-12 col-md-6 mt-5">
                    <div class="card card-cascade">
                        <div class="card-header">Secondary Contact</div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12 col-md-4 title">Sec Contact Name</div>
                                <div class="col-12 col-md-8"><?= $cd['sec_contact_name']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Sec Contact Position</div>
                                <div class="col-12 col-md-8"><?= $cd['sec_contact_position']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Sec Contact Tel</div>
                                <div class="col-12 col-md-8"><?= $cd['sec_contact_tel']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Sec Contact Mob</div>
                                <div class="col-12 col-md-8"><?= $cd['sec_contact_mob']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Sec Contact Email</div>
                                <div class="col-12 col-md-8"><?= $cd['sec_contact_email']?></div>
                            </div>
                        </div>
                    </div>
                </div>

                <?php if($_SESSION['access']==1 || $_SESSION['access']==999){?>
                <div class="col-12 col-md-6 mt-5">
                    <div class="card card-cascade">
                        <div class="card-header">Financial</div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12 col-sm-6 col-md-6">
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Rate Per Hour</div>
                                        <div class="col-12 col-md-8"><?= $cd['rate_per_hour']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Vat Rate</div>
                                        <div class="col-12 col-md-8"><?= $cd['vat_rate']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Commission</div>
                                        <div class="col-12 col-md-8"><?= $cd['commission']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Clientnotes</div>
                                        <div class="col-12 col-md-8"><?= $cd['clientnotes']?></div>
                                    </div>
                                </div>
                                <div class="col-12 col-sm-6 col-md-6">
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Statuslive</div>
                                        <div class="col-12 col-md-8"><?= $cd['statuslive']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Agent Number</div>
                                        <div class="col-12 col-md-8"><?= $cd['agent_number']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Account Handler</div>
                                        <div class="col-12 col-md-8"><?= $cd['account_handler']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Contract Number</div>
                                        <div class="col-12 col-md-8"><?= $cd['contract_number']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Incepton Date</div>
                                        <div class="col-12 col-md-8"><?= $cd['incepton_date']?></div>
                                    </div>
                                    <div class="row">
                                        <div class="col-12 col-md-4 title">Term Years</div>
                                        <div class="col-12 col-md-8"><?= $cd['term_years']?></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php }?>

                <div class="col-12 col-md-6 mt-5">
                    <div class="card card-cascade">
                        <div class="card-header">Billing Information</div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12 col-md-4 title">Billing Name</div>
                                <div class="col-12 col-md-8"><?= $cd['billing_name']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Billing1</div>
                                <div class="col-12 col-md-8"><?= $cd['billing1']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Billing2</div>
                                <div class="col-12 col-md-8"><?= $cd['billing2']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Billing3</div>
                                <div class="col-12 col-md-8"><?= $cd['billing3']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Billing Town</div>
                                <div class="col-12 col-md-8"><?= $cd['billing_town']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Billing County</div>
                                <div class="col-12 col-md-8"><?= $cd['billing_county']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Billing Postcode</div>
                                <div class="col-12 col-md-8"><?= $cd['billing_postcode']?></div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="col-12 col-md-6 mt-5">
                    <div class="card card-cascade">
                        <div class="card-header">Other</div>
                        <div class="card-body">
                            <div class="row">
                                <div class="col-12 col-md-4 title">Renewal Date</div>
                                <div class="col-12 col-md-8"><?php $cd['renewal_date']="23-11-2017"; echo $cd['renewal_date']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Renewal Status</div>
                                <div class="col-12 col-md-8"><?= $cd['renewal_status']?></div>
                            </div>
                            <div class="row">
                                <div class="col-12 col-md-4 title">Business Type</div>
                                <div class="col-12 col-md-8"><?= $cd['business_type']?></div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>

        </div>

        <div class="hidden-sm-down col-md-3">
            <?php
            $stmt = $GLOBALS['con']->prepare("SELECT `locnumber`,`locname` FROM `locations` WHERE `clientnumber`=?")or die(mysqli_error($GLOBALS['con']));
            $stmt->bind_param('i',$_REQUEST['clientnumber']);$stmt->execute();$lc=$stmt->get_result();$stmt->close();
            $ln=mysqli_num_rows($lc);
            $items=0;
            while($ld=mysqli_fetch_array($lc)){
            $stmt = $GLOBALS['con']->prepare("SELECT `itemnumber`,`desc` FROM `itemdetails` WHERE `locnumber`=?")or die(mysqli_error($GLOBALS['con']));
            $stmt->bind_param('i',$ld['locnumber']);$stmt->execute();$ic=$stmt->get_result();$stmt->close();
            $in=mysqli_num_rows($ic);
            $items=$items+$in;	
            }
            $stmt = $GLOBALS['con']->prepare("SELECT locnumber, COUNT(locnumber) AS occurrence FROM itemdetails GROUP BY locnumber")or die(mysqli_error($GLOBALS['con']));
            $stmt->execute();$cc=$stmt->get_result();$stmt->close();
            while($cdx=mysqli_fetch_array($cc)){
            //echo $cd['locnumber']." | ".$cd['occurrence']."<br>";	
            }
            ?>
            <div class="card card-cascade mt-5 mt-md-0">
                <div class="card-header">Details</div>
                <div class="card-body list-group">
                    <a class="list-group-item list-group-item-action" href="index.php?t=includes/master&p=locations.php&clientnumber=<?= $_REQUEST['clientnumber']?>&clientname=<?= $cd['clientname']?>">Locations: <?= $ln?></a>
                    <a class="list-group-item list-group-item-action" href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=asset">Items: <?= $items?></a>
                    <a class="list-group-item list-group-item-action" href="#"><?= checkItemDate($cdx['renewal_date'])?></a>

                </div>
            </div>




            <?php
            require_once('includes/forms/elements/client_ws.php');
            ?>

            <?php
            require_once('includes/forms/elements/client_loler_ws.php');
            ?>
        </div>
    </div>
    <?php }
    else{?>
    <div class="row mt-n3">
        <div class="col-12 lead"><?= $cd['clientname']?></div>
    </div>
    <div class="row mt-n3">
        <div class="hidden-sm-down col-md-3">
            <?php
            $stmt = $GLOBALS['con']->prepare("SELECT `locnumber`,`locname` FROM `locations` WHERE `clientnumber`=?")or die(mysqli_error($GLOBALS['con']));
            $stmt->bind_param('i',$_REQUEST['clientnumber']);$stmt->execute();$lc=$stmt->get_result();$stmt->close();
            $ln=mysqli_num_rows($lc);
            $items=0;
            while($ld=mysqli_fetch_array($lc)){
            $stmt = $GLOBALS['con']->prepare("SELECT `itemnumber`,`desc` FROM `itemdetails` WHERE `locnumber`=?")or die(mysqli_error($GLOBALS['con']));
            $stmt->bind_param('i',$ld['locnumber']);$stmt->execute();$ic=$stmt->get_result();$stmt->close();
            $in=mysqli_num_rows($ic);
            $items=$items+$in;	
            }
            $stmt = $GLOBALS['con']->prepare("SELECT locnumber, COUNT(locnumber) AS occurrence FROM itemdetails GROUP BY locnumber")or die(mysqli_error($GLOBALS['con']));
            $stmt->execute();$cc=$stmt->get_result();$stmt->close();
            while($cdx=mysqli_fetch_array($cc)){
            //echo $cd['locnumber']." | ".$cd['occurrence']."<br>";	
            }
            ?>
            <div class="card card-cascade mt-5 mt-3">
                <div class="card-header">Details</div>
                <div class="card-body list-group">
                    <a class="list-group-item list-group-item-action" href="index.php?t=includes/master&p=locations.php&clientnumber=<?= $_REQUEST['clientnumber']?>&clientname=<?= $cd['clientname']?>">Locations: <?= $ln?></a>
                    <a class="list-group-item list-group-item-action" href="index.php?t=includes/master&p=client.php&clientnumber=<?= $_REQUEST['clientnumber']?>&view=asset">Items: <?= $items?></a>
                    <a class="list-group-item list-group-item-action" href="#"><?= checkItemDate($cdx['renewal_date'])?></a>

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

        <div class="hidden-sm-down col-md-3">
            <?php require_once('includes/forms/elements/client_ws.php'); ?>
        </div>

        <div class="hidden-sm-down col-md-3">
            <?php require_once('includes/forms/elements/client_loler_ws.php'); ?>
        </div>
    </div>
    <?php }?>
    <script>
    function addWS() {
        $('#popupBox .modal-footer').html('');
        $('#popupBox .modal-body').html('');
        $('#popupBox').modal('show');
        $('#popupBox .modal-body').load('includes/client/client_ws.php?clientnumber=<?= $_REQUEST['clientnumber']?>');
    }

    function relWs() {
        $('#wsData').load('includes/master/ws_data.php?clientnumber=<?= $_REQUEST['clientnumber']?>');
    }

    function addLWS() {
        $('#popupBox .modal-footer').html('');
        $('#popupBox .modal-body').html('');
        $('#popupBox').modal('show');
        $('#popupBox .modal-body').load('includes/client/client_lws.php?clientnumber=<?= $_REQUEST['clientnumber']?>');
    }

    function relLWs() {
        $('#lwsData').load('includes/master/lws_data.php?clientnumber=<?= $_REQUEST['clientnumber']?>');
    }

    $(document).ready(function() {
        $('#wsData').load('includes/master/ws_data.php?clientnumber=<?= $_REQUEST['clientnumber']?>');
        $('#lwsData').load('includes/master/lws_data.php?clientnumber=<?= $_REQUEST['clientnumber']?>');
    })
    </script>