<?php require_once('../auth/auth.php');require_once('../auth/function.php');?>
<?php
$acid = $_GET['acid'];
@$get_em_id = $_GET['get_em_id'];
$acc= mysqli_query($conn,"SELECT acid,gcatid,ac_name,ac_alise,balance,ac_number,ac_details,opdate,atime,picture FROM accounts WHERE coid='$coid' AND bid ='$bid' AND brid='$brid' AND acid='$acid' LIMIT 1") or die(mysqli_error($conn));
$ac= mysqli_fetch_assoc($acc);
$acid       = $ac['acid'];
$gcatid     = $ac['gcatid'];
$ac_name    = $ac['ac_name'];
$ac_alise   = $ac['ac_alise'];
$balance    = $ac['balance'];
$ac_number  = $ac['ac_number'];
$ac_details = $ac['ac_details'];
$opdate     = $ac['opdate'];
$picture    = $ac['picture'];
$g_name= mysqli_fetch_assoc(mysqli_query($conn,"SELECT ac_g_cat_name FROM ac_sub_g_category WHERE coid='$coid' AND ac_g_catid='$gcatid' LIMIT 1"))['ac_g_cat_name'];
$debitor_id = mysqli_fetch_assoc(mysqli_query($conn, "SELECT ac_g_catid FROM ac_sub_g_category WHERE  coid='$coid' AND g_type='su-deb' LIMIT 1 "))['ac_g_catid'];

?>
<section class="content">
  <div class="row">
    <div class="col-md-12 pl-0">
      <div class="card card-primary card-outline direct-chat direct-chat-primary shadow-none" style="border-left:1px solid #969c9d;border-right:1px solid #969c9d;border-bottom:1px solid #969c9d;">
        <div class="card-header" style="padding: 3px 8px;">
          <h3 class="card-title"> <i class="fa fa-address-card"> </i>   <?php echo language(213);?>  </h3>
          <div class="card-tools">
            <!-- <span title="3 New Messages" class="badge bg-primary">3</span> -->
            <button type="button" class="btn btn-tool" data-card-widget="remove" data-dismiss="modal">
            <i class="fas fa-times"></i>
            </button>
          </div>
        </div>
        <div style="display: flex;">
          <div class="col-md-2 pt-1" style="border-right:1px solid #969c9d;">
            <div class="card-body box-profile">
              <div class="text-center">
                <span style="float:right;position: relative;margin-left: -12px;cursor:pointer;">
                  <input type="file" id="new_img" accept="image/*" style="position: absolute;opacity: 0;"><i class="fa fa-edit new_Btn"></i>
                </span>
                <?php if($picture != ""): ?>
                <img id="img_data" class="profile-user-img img-fluid img-circle" src="data:image/gif;base64,<?php echo $picture;?>" alt="User profile picture">
                <?php else : ?>
                <img id="img_data" class="profile-user-img img-fluid img-circle" src="../../dist/img/no_img.jpg" alt="User profile picture">
                <?php endif; ?>
              </div>
              <h6 class="text-center pt-1 m-0"><dt><?php echo $ac_name;?></dt></h6>
              <p class="text-muted text-center m-0 text-xsm"><?php echo $g_name;?></p>
              <hr class="m-0 pt-1">
              <?php if ($balance >= 0) { ?>
              <h6 class="marksc text-center m-0 p-1"><dt><?php echo money($balance,true);?> Dr</dt></h6>
              <?php } else { ?>
              <h6 class="mark1 text-center m-0 p-1"><dt><?php echo money($balance,true);?> Cr</dt></h6>
              <?php } ?>
              <hr class="mb-0 mt-1">
              <strong><i class="fas fa-book mr-1"></i>  <?php echo language(110);?></strong>
              <p class="text-muted pl-3 m-0"><?php echo $ac_alise;?></p>
              <hr>
              <strong><i class="fa-solid fa-phone"></i> <?php echo language(111);?> </strong>
              <p class="text-muted pl-3 m-0"><?php echo $ac_number;?></p>
              <hr>
              <strong><i class="fa-solid fa-calendar-days"></i>  <?php echo language(131);?> </strong>
              <p class="text-muted pl-3 m-0"><?php echo date('d/m/y h:i:s a', strtotime($opdate));?></p>
              <hr>
              <strong><i class="fas fa-map-marker-alt mr-1"></i>  <?php echo language(150);?></strong>
              <p class="text-muted pl-3 m-0"><?php echo $ac_details;?></p>
            </div>
          </div>
          <div class="col-md-10 p-0">
            <ul class="nav nav-pills" style="background-color: honeydew;padding: 2px 0;border-bottom:1px solid #dee2e6;margin-left: 2px;">
              <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../accounts/ledger_search.php?acid=<?php echo $acid ?>','#pview<?php echo $acid?>',0);"><i class="fa fa-fw fa-archive"></i> <?php echo language(212);?></a></li>|
              <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../accounts/ac_dashboard.php?acid=<?php echo $acid ?>','#pview<?php echo $acid?>');"><i class="fa fa-area-chart  
"></i> <?php echo language(1);?> </a></li>|
<?php if (@$get_em_id ==''  && $acid >0 ){  ?>
              <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../accounts/ac_profile_update.php?acid=<?php echo $acid ?>','#pview<?php echo $acid?>');"><i class="fa fa-fw fa-edit"></i> <?php echo language(25);?> </a></li>|
<?php }else{ ?>
              <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../hr_manage/em_profile_update.php?get_em_id=<?php echo $get_em_id ?>','#pview<?php echo $acid?>');"><i class="fa fa-fw fa-edit"></i> <?php echo language(25);?> </a></li>|
<?php } ?>              
<!--               <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../accounts/ac_profile_active.php?acid=<?php echo $acid ?>','#pview<?php echo $acid?>');"><i class="fa fa-fw fa-calculator"></i> <?php echo language(90);?></a></li>|
 -->       
 
 
 
 <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../voucher/pay_voucher_index.php?payacid=<?php echo $acid ?>','#pview<?php echo $acid?>');"><i class="fa fa-fw fa-calculator"></i> <?php echo language(44);?> </a></li>|
              <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../voucher/re_voucher_index.php?recacid=<?php echo $acid ?>','#pview<?php echo $acid?>');"><i class="fa fa-fw fa-calculator"></i> <?php echo language(42);?>  </a></li>|
              <?php if ($debitor_id === $gcatid) { ?>
                <li class="nav-item"><a style="padding: 0px 8px;" class="nav-link" href="#" data-toggle="tab" onclick="pagecall('../accounts/ac_profile_print.php?acid=<?php echo $acid ?>','#pview<?php echo $acid ?>');"><i class="fa fa-fw fa-calculator"></i> <?php echo language(422); ?> </a></li>|
              <?php  } ?>
            </ul>
            <div id="pview<?php echo $acid?>" class="pt-1"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>
<script type="text/javascript">
$("#new_img").on('change', function (e) {
var ac_img_id = '<?php echo $acid;?>';
if (e.target.files) {
let imageFile = e.target.files[0];
var reader = new FileReader();
reader.onload = function (e) {
var img = document.createElement("img");
img.onload = function (event) {
var canvas = document.createElement("canvas");
var MAX_WIDTH = 300;
var MAX_HEIGHT = 300;
var width = img.width;
var height = img.height;
if (width > height) {
if (width > MAX_WIDTH) {
height *= MAX_WIDTH / width;
width = MAX_WIDTH;
}
} else {
if (height > MAX_HEIGHT) {
width *= MAX_HEIGHT / height;
height = MAX_HEIGHT;
}
}
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
var dataurl = canvas.toDataURL(imageFile.type);
$.ajax({
type: "POST",
url: "../accounts/add_accounts_db.php",
data: ({ac_img_id: ac_img_id,dataurl:dataurl}),
cache:false,
success:function(data){
}
});
document.getElementById("img_data").src = dataurl;
}
img.src = e.target.result;
}
reader.readAsDataURL(imageFile);
}
});
$('.new_Btn').click(function() {
$('#new_img').click();
});
</script>