<?php require_once('../auth/auth.php');require_once('../auth/acid_balance.php');require_once('../auth/function.php');?>
<?php 
   $g_acid  = isset($_GET['g_acid'])?$_GET['g_acid']:0;
   $tid = $_GET['tid'];
$inacc= mysqli_query($conn,"SELECT 
  co_name,owner_name,co_phone,co_email,co_address,co_logo,t.tid,t.dr_acid,t.cr_acid,t.invoice,t.date,t.amount,t.details,t.ttype,a1.acid,a1.ac_name,a1.ac_number,em_acname
  FROM transaction t LEFT JOIN company c ON(t.coid=c.coid)
  LEFT JOIN accounts a ON(a.acid=t.dr_acid OR a.acid=t.cr_acid)
  LEFT JOIN accounts a1 ON(a1.acid=(IF(t.dr_acid= a.acid, t.cr_acid, t.dr_acid)))
  LEFT JOIN user u ON(u.uid=t.userid)
  LEFT JOIN em_employee e ON(e.em_id=u.us_em_id)
  WHERE t.coid='$coid' AND a.ac_type='opening' AND t.tid ='$tid' LIMIT 1") or die(mysqli_error($conn));
$inac= mysqli_fetch_assoc($inacc);

$co_name        = $inac['co_name'];
$owner_name     = $inac['owner_name'];
$co_address     = $inac['co_address'];
$co_phone       = $inac['co_phone'];
$co_email       = $inac['co_email'];
$co_logo        = $inac['co_logo'];

$tid            = $inac['tid'];
$invoice        = $inac['invoice'];
$date           = $inac['date'];
$amount         = $inac['amount'];
$details        = $inac['details'];
$ttype          = $inac['ttype'];
$dr_acid        = $inac['dr_acid'];
$cr_acid        = $inac['cr_acid'];


$acid           = $inac['acid'];
$ac_name        = $inac['ac_name'];
$ac_number      = $inac['ac_number'];


$em_acname      = $inac['em_acname'];
?>
<section class="content">
  <div class="row">
    <div class="col-md-12">
      <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">Money Receipt</h3>
          <div class="card-tools">
            <span id="sdf"></span>
          <button type="button" onclick="pdfMe('#m_receipt');" class="btn btn-tool" title="Download Pdf"><i class="fas fa-download"></i></button>
          <button type="button" class="btn btn-tool" onclick="printMe('#m_receipt',{'top':'7%','left':'37%'})" title="Print Now"><i class="fas fa-print"></i></button>
          <?php if ($g_acid>0) { ?>
            <div class="btn-group">
              <button type="button" class="btn btn-tool" data-toggle="dropdown"  title="More Tools"><i class="fa-solid fa-ellipsis-vertical"></i>
              </button>
              <ul class="dropdown-menu dropdown-menu-right">
               <?php if(per('vou_edit')==1){ ?>
                <li><a class="dropdown-item" title="Edit" onclick="pagecall('../voucher/op_voucher_edit.php?g_acid=<?php echo $g_acid?>'+'&tid=<?php echo $tid;?>','#mdview');"><i class="fas fa-edit"></i> Edit Now</a></li>
                <div class="dropdown-divider m-0"></div>
                <?php } ?>
                <?php if(per('vou_delete')==1){ ?>
                <li><a class="dropdown-item" title="Delete" id="delete"><i class="fas fa-trash"></i> Delete Now</a></li>
                <?php } ?>
              </ul>
            </div> 
          <?php } ?>
            <button type="button" class="btn btn-tool" data-card-widget="remove" data-dismiss="modal">
              <i class="fas fa-times"></i>
            </button>
          </div>
        </div>    	
            <div class="card-body p-1" id="m_receipt" style="overflow:hidden;position: relative;">
              <img class="bgimg" src="../../dist/img/a.png">
              <table style="width: 100%;border: 1px solid #afafaf7a;background:#fde7b46b;position: relative;" cellpadding="0" cellspacing="0">
                 <thead>
                    <tr>
                       <th style="width:2%;padding-top:5px;"></th>
                       <th class="text-left" style="width:10%;padding-top:10px;"><img class="profile-user-img img-fluid img-circle" src="../../dist/img/a.png" style="width:80px;height:75px;"></th>
                       <th style="width:10%;padding-top:5px;"></th>
                       <th class="text-right" colspan="6" style="padding-top:5px;">
                         <div style="padding-right:5px;">
                           <sss style="font-size:18px;font-weight: 600;"><?php echo $co_name;?></sss><br>
                           <sss><?php echo $owner_name;?></sss><br>
                           <sss><?php echo $co_address;?></sss><br>
                           <sss><?php echo $co_email;?></sss> # 
                           <sss><?php echo $co_phone;?></sss>
                         </div>
                       </th>
                       <th style="width:2%;padding-top:5px;">
                         <div style="background-color: green;width: 22px;height:90px;"></div>
                       </th>
                    </tr>
                    <tr>
                       <th style="width:2%;"></th>
                       <th class="text-center" colspan="8">
                        <sss style="font-size:25px;font-weight: 600;">MONEY RECEIPT<sss>
                       </th>
                       <th style="width:2%;"></th>
                    </tr>
                 </thead>
                 <tbody>
                    <tr>
                       <th style="width:2%;"></th>
                       <th colspan="5">INVOICE : <?php echo $invoice;?></th>
                       <th colspan="3" style="width:25%;">DATE : <?php echo date('d | m | Y | h:i:s a', strtotime($date));?></th>
                       <th style="width:2%;"></th>
                    </tr>
                    <tr>
                       <th style="width:2%;"></th>
                       <th colspan="8" style="padding-top: 10px;border-bottom: 1px dotted;">Received with thanks from : <?php echo $ac_name;?></th>
                       <th style="width:2%;"></th>
                    </tr>
                    <tr>
                       <th style="width:2%;"></th>
                       <th colspan="8" style="padding-top:10px;border-bottom: 1px dotted;">Amount of <?php echo $currency;?> : <?php echo inword($amount);?></th>
                       <th style="width:2%;"></th>
                    </tr>  
                    <tr>
                       <th style="width:2%;"></th>
                       <th colspan="2" style="padding-top:10px;border-bottom: 1px dotted;">By Cash/Check No : Cash</th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="padding-top:10px;width:25%;border-bottom: 1px dotted;">Bank : </th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="padding-top:10px;width:25%;border-bottom: 1px dotted;">Date : </th>
                       <th style="width:2%;"></th>
                    </tr>   
                    <tr>
                       <th style="width:2%;"></th>
                       <th colspan="5" style="padding-top:10px;border-bottom: 1px dotted;">For the purpose of : <?php echo $details;?></th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="padding-top:10px;border-bottom: 1px dotted;">Contuct : <?php echo $ac_number;?></th>
                       <th style="width:2%;"></th>
                    </tr>
                    <tr>
                       <th colspan="10">&nbsp;</th>
                    </tr>                     
                    <tr>
                       <th style="width:2%;"></th>
                       <th style="border-bottom:1px solid grey;font-size:15px;">Previous Due : </th>
                       <th class="text-right pr-1" style="border-bottom:1px solid grey;font-size:15px;"><dt>
                        <?php $chbll = invbalance($acid,$date,$tid);$pr_due = ($chbll)?$chbll['pr_due']:0;if ($pr_due >= 0) {echo money($pr_due,true).' '.'Dr';} else {echo money(-$pr_due,true).' '.'Cr';}?></dt></th>
                       <th colspan="5"></th>
                       <th style="width:2%;"></th>
                    </tr>                   
                    <tr>
                       <th style="width:2%;"></th>
                       <th style="width:15%;border-bottom:1px solid grey;font-size:15px;">Now Payment : </th>
                       <th class="text-right pr-1" style="width:15%;border-bottom:1px solid grey;font-size:15px;"><dt><?php echo money($amount,true).' ';?>
                       <?php 
                           if ($dr_acid===$acid) {echo $drcr = 'Dr';$n_balance=$pr_due+$amount;} else {echo $drcr = 'Cr';$n_balance=$pr_due-$amount;} 
                        ?> 
                       </dt></th>
                       <th style="width:1%;"></th>
                       <th class="text-center" style="border-bottom: 1px dotted;"><?php echo $em_acname;?></th>
                       <th></th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="border-bottom: 1px dotted;"></th>
                       <th style="width:2%;"></th>
                    </tr>
                    <tr>
                       <th style="width:2%;"></th>
                       <th style="width:15%;border-bottom:1px solid grey;font-size:15px;">Current Due : </th>
                       <th class="text-right pr-1" style="width:15%;border-bottom:1px solid grey;font-size:15px;"><dt><?php if ($n_balance >= 0) {echo money($n_balance,true).' '.'Dr';} else {echo money(-$n_balance,true).' '.'Cr';}?></dt></th>
                       <th style="width:1%;"></th>
                       <th class="text-center">Received By</th>
                       <th></th>
                       <th style="width:1%;"></th>
                       <th colspan="2" class="text-center">Authorized signature</th>
                       <th style="width:2%;"></th>
                    </tr>                    
                 </tbody>
                 <tfoot>
                    <tr>
                       <th colspan="10">&nbsp;</th>
                    </tr>                                                  	
                    <tr>
                       <th colspan="4" style="padding: 5px 15px;background:#17a2b8;color: #fff;"><dt>Powered by: <a href="https://welldiv.com" target="_blank" style="color:#fff;"> Welldiv</a></dt></th>
                       <th colspan="6" class="text-right" style="padding: 5px 15px;background: #ffc107;color: #fff;"><dt>Build your career, discover your creativity</dt></th>
                    </tr>
                 </tfoot>
              </table>
            </div>
           </div>
        </div>
   </div>
</section>

<script>
$(document).ready(function() {
$('#delete').on('click', function(e){
e.preventDefault();
  if (confirm("Are Sure To Delete Voucher !!")) {  
     $(".preloader").css('display','flex');
     $.post("../voucher/vou_delete_db.php",
      {tid:'<?php echo $tid;?>',dr_acid:<?php echo $dr_acid;?>,cr_acid:<?php echo $cr_acid;?>},
    function(data){
       toastr.success(Successfully, yourdata);
       pagecall('../accounts/ac_profile.php?acid=<?php echo $g_acid?>','#ac_view');
       $('.preloader').hide();
       $("#modal-lg").modal("hide");       
    });
  } else {return false;}
  });
});  
</script>