<?php
error_reporting(0);

  include("../config.php");
  $id = $_GET['eid']; 
  
  $mr = "SELECT * FROM `mr` WHERE `mr_no` = '".$id."' AND company_id = '".$_SESSION['company_id']."' AND branch_id = '".$_SESSION['branch_id']."'";
  $mr_res         = mysqli_query($conn,$mr);
  $mr_row         = mysqli_num_rows($mr_res);
  $num = $mr_row;

  $bill_data  = array();
  while ($mr_rows = mysqli_fetch_assoc($mr_res)) { 
    $bill_data[] = $mr_rows;

    if($mr_rows['payment_mode'] == 'NEFT'){
      $payment_mode = 'NEFT';
      $payment_ref  = $mr_rows['neft_number'];
    }

    if($mr_rows['payment_mode'] == 'RTGS'){
      $payment_mode = 'RTGS';
      $payment_ref  = $mr_rows['rtgs_number'];
    }

    if($mr_rows['payment_mode'] == 'IMPS'){
      $payment_mode = 'IMPS';
      $payment_ref  = $mr_rows['imps_number'];
    }

    if($mr_rows['payment_mode'] == 'CHEQUE'){
      $payment_mode = 'CHEQUE';
      $payment_ref  = $mr_rows['cheque_number'];
    }

    $mr_no       = $mr_rows['mr_no'];
    $mr_date     = $mr_rows['mr_date'];
    $branch_id   = $mr_rows['branch_id'];
    $cheque_date = $mr_rows['cheque_date'];
    $vendor_id   = $mr_rows['vendor_id'];
  }
  
  $bank_det         = "SELECT * FROM company_mst WHERE id = '".$_SESSION['company_id']."'";
  $bank_det_res     = mysqli_query($conn,$bank_det);
  $bank_det_rows    = mysqli_fetch_assoc($bank_det_res);
  $master_vendor    = combine(getAllRecords('vendor_master'), 'id', 'name');
  $master_branch    = combine(getAllRecords('branch_mst'), 'id', 'branch');
  $branch_name      = @$master_branch[$_SESSION['branch_id']];
  $output  = ''; 
  $output .= '<!DOCTYPE html>';
  $output .= '<html lang="en">';
  $output .= '<head>';
    $output .= '<meta charset="utf-8">';
    $output .= '<title>MR COPY</title>';
    $output .= '<link rel="stylesheet" href="../assets/pdf.css" media="all" />';
    //$output .= '<link rel="stylesheet" href="/assets/print.css" type="text/css" media="print">';
  $output .= '</head>';
  $output .= '<body>';
  if( isset($_POST['include_header']) && !empty($_POST['include_header']) ) {
    $output .='
    <div class="hide-header-blank"></div>';
  }else{
    $output .='
    <div class="show-header-blank clickable">
      <img src="../assets/logo/gati_logo.jpg" style="width:100%;height:120px;">
    </div><hr/>';  
  }
  $output .='<table class="table no-top-border-table">
          <thead>
            
            <tr>
              <td width="70%" class="text-left" colspan="4"><strong class="control-label bill-fontsize-bold hitz-control-label">BRANCH : '.@$master_branch[$branch_id].'</strong></td>
              <td width="30%" class="text-left" colspan="4"><label class="control-label bill-fontsize-bold hitz-control-label"><strong class="hitz-top-header capitals">No.</strong> : <span>'.$mr_no.'</span></label></td>
            </tr>
            <tr>
              <td width="100%" colspan="4" class="text-left">
              <label class="control-label"><span class="bill-fontsize-bold capitals">Received with thank from:</span></label>
              </td>
              <td class="text-left" colspan="4"><label class="control-label bill-fontsize-bold hitz-control-label"><strong class="hitz-top-header capitals">Dated</strong> : <span>'.risFormatDate($mr_date).'</span></label></td>
            </tr>
            <tr>
              <td class="text-left" colspan="4"><label class="control-label bill-fontsize-bold hitz-control-label capitals">M/s.<span style="text-decoration: underline;">'.@$master_vendor[$vendor_id].'</span></label></td>
              <td class="text-left" colspan="4"><label class="control-label bill-fontsize-bold hitz-control-label"><strong class="hitz-top-header capitals">Party Code</strong> : <span></span></label></td>
            </tr>
            <tr>
              
              <td class="text-left" colspan="4"><label class="control-label bill-fontsize-bold hitz-control-label capitals">By Cash/Cheque No. <span style="text-decoration: underline;"> '.$payment_mode.' </span> - <span style="text-decoration: underline;">'.$payment_ref.'</span> Dated <span style="text-decoration: underline;">'.risFormatDate($mr_date).'</span></label></td>
            </tr>
             
          </thead>
       </table>
       <table class="custom-bill-border">
          <tbody>
             <tr class="text-center">
                <th class="text-center hitz-td table-th capital" width="8%">Bill No</th>
                <th class="text-center hitz-td table-th capital" width="7%">Dated</th>
                <th class="text-center hitz-td table-th capital" width="7%">Bill Amount Freight</th>
                <th class="text-center hitz-td table-th capital" width="7%">Received Amount Freight</th>
                <th class="text-center hitz-td table-th capital" width="7%">TDS</th>
                <th class="text-center hitz-td table-th capital" width="7%">Cash Discount</th>
                <th class="text-center hitz-td table-th capital" width="7%">Late Delivery</th>
                <th class="text-center hitz-td table-th capital" width="7%">Claim</th>
                <th class="text-center hitz-td table-th capital">Remarks</th>
             </tr>
             ';
             $advance = 0;
             foreach ($bill_data as $bill_datas) { 
              $total_bill_fright   += $bill_datas['bill_amount'];
              $total_bill_rec      += $bill_datas['bill_rec'];
              $total_tds           += $bill_datas['tds'];
              $total_cash_disc     += $bill_datas['cash_diss'];
              $total_late_delivery += $bill_datas['late_delivery'];
              $total_claim         += $bill_datas['claim'];
               $output .='
               <tr>
                  <td class="table-td text-center bill-height11 bill-padding1">'.$bill_datas['bill_no'].'</td>
                  <td class="table-td text-center bill-height11 bill-padding1">'.risFormatDate($bill_datas['bill_date']).'</td>
                  <td class="table-td text-center bill-height11 bill-padding1">'.customFormatMoney($bill_datas['bill_amount']).'</td>
                  <td class="table-td text-center bill-height11 bill-padding1">'.customFormatMoney($bill_datas['bill_rec']).'</td>
                  <td class="table-td text-center bill-height11 bill-padding1">'.customFormatMoney($bill_datas['tds']).'</td>
                  <td class="table-td text-center bill-height11 bill-padding1">'.customFormatMoney($bill_datas['cash_diss']).'</td>
                  <td class="table-td text-center bill-height11 bill-padding1">'.customFormatMoney($bill_datas['late_delivery']).'</td>
                  <td class="table-td text-center bill-height11 bill-padding1">'.customFormatMoney($bill_datas['claim']).'</td>
                  <td class="table-td text-center bill-height11 bill-padding1">'.$bill_datas['remarks'].'</td>
               </tr>
               ';
              }
            if( $num < 15 ) {
              for ($j=1; $j <= ( 15 - $num ); $j++) {
                $output .='<tr>
                <td class="table-td text-center bill-height11 bill-padding1"></td>
                <td class="table-td text-center bill-height11 bill-padding1"></td>
                <td class="table-td text-center bill-height11 bill-padding1"></td>
                <td class="table-td text-center bill-height11 bill-padding1"></td>
                <td class="table-td text-center bill-height11 bill-padding1"></td>
                <td class="table-td text-center bill-height11 bill-padding1"></td>
                <td class="table-td text-center bill-height11 bill-padding1"></td>
                <td class="table-td text-center bill-height11 bill-padding1"></td>
                <td class="table-td text-center bill-height11 bill-padding1"></td>
             </tr>';
              }
            }
            $output .='<tr>
              <td class="table-td text-left bill-height11 bill-padding1" colspan="1"></td>
              <td class="table-td text-center bill-height11 bill-padding1"><span class="bill-font-bold">TOTAL</span></td>
              <td class="table-td text-center bill-height11 bill-padding1"><span class="bill-font-bold">'.customFormatMoney($total_bill_fright).'</span></td>
              <td class="table-td text-center bill-height11 bill-padding1"><span class="bill-font-bold">'.customFormatMoney($total_bill_rec).'</span></td>
              <td class="table-td text-center bill-height11 bill-padding1"><span class="bill-font-bold">'.customFormatMoney($total_tds).'</span></td>
              <td class="table-td text-center bill-height11 bill-padding1"><span class="bill-font-bold">'.customFormatMoney($total_cash_disc).'</span></td>
              <td class="table-td text-center bill-height11 bill-padding1"><span class="bill-font-bold">'.customFormatMoney($total_late_delivery).'</span></td>
              <td class="table-td text-center bill-height11 bill-padding1"><span class="bill-font-bold">'.customFormatMoney($total_claim).'</span></td>
              <td class="table-td text-center bill-height11 bill-padding1"></td>
            </tr>

            <tr>
              <td class="text-left bill-height11 bill-padding1" colspan="5" style="padding: 4px;"><strong class="hitz-top-header bill-fontsize-bold capitals">Cheque Subject to Realisation</strong></td>

              <td class="text-right bill-height11 bill-padding1" colspan="4" style="padding: 4px;"><strong class="hitz-top-header bill-font-bold">For, '.$bank_det_rows['name'].'</strong></td>
            </tr>
            <tr>
              <td class="text-left bill-height11 bill-padding1" colspan="5" style="padding: 4px;"></td>

              <td class="text-right bill-height11 bill-padding1" colspan="4" style="padding: 4px;"><img src="../assets/logo/itc_stamp.png" style="width:800%;height:120px;"></td>
            </tr>
            <tr>
              <td class="text-left bill-height11 bill-padding1" colspan="5" style="border-bottom:1px solid;padding: 4px;"><strong class="hitz-top-header capitals bill-fontsize-bold">Rs.&nbsp;<span style="text-decoration: underline;">'.customFormatMoney($total_bill_rec).'</span></strong></td>

              <td class="text-right bill-height11 bill-padding1" colspan="4" style="border-bottom:1px solid;padding: 4px;"><b>auth sign</b></td>
            </tr> 

            ';
            
             $output .='
          </tbody>
       </table>
       ';  


  $output .= '</body>';
$output .= '</html>';
/*echo'<pre>';
print_r($output);
echo'</pre>';
die();*/
require_once '../dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf->loadHtml($output);
$dompdf->setPaper('A4', 'Portrit');
$dompdf->render();

$filename = $pro = $_GET['pro_name'] . $id;
$dompdf->stream($filename,array("Attachment" => 0));

?>

