<?php require_once('../auth/auth.php');require_once('../auth/acid_balance.php');require_once('../auth/function.php');?>
<?php 
    $invoice=$_GET['n_re_invoice'];
    $pinvoice_query= mysqli_query($conn,"SELECT 
      c.co_name,c.co_email,c.co_phone,c.co_address,c.co_logo,
      b.brid,b.branch_name,b.branch_number,b.branch_email,b.branch_address,
      t.tid,t.invoice,t.m_invoice,date(t.date) tdate,t.date date_time,t.amount,t.details,t.em_id,
      a.acid,a.ac_name,a.ac_number,a.ac_details,a.ac_email,a.outlet_id
      FROM transaction t 
      LEFT JOIN company c ON(t.coid=c.coid)
      LEFT JOIN branch b ON(t.brid=b.brid)
      LEFT JOIN accounts a ON(a.acid=t.cr_acid)
      WHERE t.coid='$coid' AND t.invoice ='$invoice' AND ttype='R' ORDER BY tid ASC  ") or die(mysqli_error($conn));
    $pin_row= mysqli_fetch_assoc($pinvoice_query);

    $co_name        = $pin_row['co_name'];
    $co_address     = $pin_row['co_address'];
    $co_phone       = $pin_row['co_phone'];
    $co_email       = $pin_row['co_email'];
    $co_logo       = $pin_row['co_logo'];
    
    
    $get_brid         = $pin_row['brid'];
    $branch_name    = $pin_row['branch_name'];
    $branch_address = $pin_row['branch_address'];
    $branch_number  = $pin_row['branch_number'];
    $branch_email   = $pin_row['branch_email'];

    $acid          = $pin_row['acid'];
    $ac_name        = $pin_row['ac_name'];
    $ac_number      = $pin_row['ac_number'];
    $ac_address     = $pin_row['ac_details'];
    $ac_email       = $pin_row['ac_email'];
    $outlet_id      = $pin_row['outlet_id'];

    $getem_id         = $pin_row['em_id'];

    $em_name=mysqli_fetch_assoc(mysqli_query($conn,"SELECT em_acname FROM em_employee WHERE  em_id='$getem_id' LIMIT 1 "))['em_acname'];

    $tid            = $pin_row['tid'];
    $tdate          = $pin_row['tdate'];
    $m_invoice      = $pin_row['m_invoice'];
    $date_time      = $pin_row['date_time'];
    $details        = $pin_row['details'];





?>


<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>
            <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/re_voucher_edit.php?g_acid=<?php echo $g_acid?>'+'&tid=<?php echo $tid;?>','#mdview');"> <i class="fas fa-edit"> </i> <?php echo language(25); ?> </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>   <?php echo language(324); ?> </a></li>
                <?php } ?>
              </ul>
               
              
              
            </div> 
            <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;">
                <?php if($co_logo != ""): ?>
                            <img class="bgimg" src="data:image/gif;base64,<?php echo $co_logo;?>">
                        <?php else : ?>
                           <img class="bgimg " src="../../dist/img/a.png">
                        <?php endif; ?>
                                      <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;">

                                <?php if($co_logo != ""): ?>
                            <img class="profile-user-img img-fluid img-circle" src="data:image/gif;base64,<?php echo $co_logo;?>" style="width:80px;height:75px;border-color:#2b3536;">
                        <?php else : ?>
                           <img class="profile-user-img img-fluid img-circle  " src="../../dist/img/a.png" style="width:80px;height:75px;border-color:#2b3536;">
                        <?php endif; ?>

                       </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 $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: #2b3536;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;border-radius:12px;padding:4px 10px ;border:2px solid #2b3536;">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_time));?></th>
                       <th style="width:2%;"></th>
                    </tr>
             
                    
    
                    
                     <tr>
                       <th style="width:2%;"></th>
                       <th colspan="2" style="padding-top:10px;border-bottom: 1px dotted;">Received from : <?php echo $ac_name;?></th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="padding-top:10px;width:25%;border-bottom: 1px dotted;">Contact : <?php echo $ac_number;?> </th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="padding-top:10px;width:25%;border-bottom: 1px dotted;"> Outlet id : <?php echo  $outlet_id ?> </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="8" style="padding-top:10px;border-bottom: 1px dotted;">For the purpose of : <?php echo $details;?></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 Taka : 
                          <?php 
                               @$amount= mysqli_fetch_assoc(mysqli_query($conn,"SELECT amount FROM transaction WHERE coid='$coid' AND invoice ='$invoice' AND ttype='R' AND note = 'rec' LIMIT 1"))['amount'];
                                @number_format($amount);
                            ?>

                       	<?php echo inword($amount);?></th>
                       <th style="width:2%;"></th>
                    </tr>
                    <tr>
                       <th colspan="10">&nbsp;</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).' '.'Cr';?></dt></th>
                       <th style="width:1%;"></th>
                       <th class="text-center" style="border-bottom: 1px ;"></th>
                       <th></th>
                       <th style="width:1%;"></th>
                       <th colspan="2" style="border-bottom: 1px ;"></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;"> Discount : </th>
                       <th class="text-right pr-1" style="width:15%;border-bottom:1px solid grey;font-size:15px;"><dt>
                            <?php 
                               @$discounttk= mysqli_fetch_assoc(mysqli_query($conn,"SELECT amount FROM transaction WHERE coid='$coid' AND invoice ='$invoice' AND ttype='RD' AND note = 'receive Discount' LIMIT 1"))['amount'];
                                 $discounttk=@number_format($discounttk);
                                  echo $discounttk.' '.'Cr';?></dt></th>
                       <th style="width:1%;"></th>
                       
                       
                       
                       
                       <th class="text-center" style="border-bottom: 1px dotted;"><?php echo $em_name;?></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 $n_balance = balance($acid)['ac_balance'];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:#2b3536;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: #2b3536;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",
      {rece_invoice:'<?php echo $invoice ?>'},
    function(data){
       toastr.success(Successfully, yourdata);
       pagecall('../accounts/ac_profile.php?acid=<?php echo $acid?>','#ac_view');
       $('.preloader').hide();
       $("#modal-lg").modal("hide");       
    });
  } else {return false;}
  });
});  
</script>