<?php
ini_set('display_errors', 0);
//error_reporting(E_ALL);
//ini_set('display_errors', 1);

session_start();
ob_start();

require_once('../../server_assets/server_connect.php');
require_once('../../server_assets/all_function.php');

 $jv_no 		= $_REQUEST['jv_no'];
 
 $page="secondary_journal_print_view.php";
 
$ms_sql="SELECT * FROM journal_master  WHERE jv_no='".$jv_no."'";
$ms_data = find_all_field_sql($conn,$ms_sql);
 
$grp_sql="SELECT * FROM user_group  WHERE id='".$ms_data->group_for."'";
$grp_data = find_all_field_sql($conn,$grp_sql);

$ref_sql="SELECT * FROM accounts_reference  WHERE ref_no='".$ms_data->ref_no."'";
$ref_data = find_all_field_sql($conn,$ref_sql);

$trm_sql="SELECT * FROM acc_terms  WHERE id='".$ms_data->acc_terms."'";
$trm_data = find_all_field_sql($conn,$trm_sql);



		  $barcode_content = $jv_no;
		  $barcodeText = $barcode_content;
          $barcodeType='code128';
		  $barcodeDisplay='horizontal';
          $barcodeSize=40;
          $printText='';




if(isset($_POST['confirm_data']))
{
$ms_sql="SELECT * FROM journal_master  WHERE jv_no='".$jv_no."'";
$ms_data = find_all_field_sql($conn,$ms_sql);

$entry_by =  $_SESSION['user']['id'];
$entry_at = $now=date('Y-m-d H:i:s');

$jv_no=$ms_data->jv_no;
$tr_from=$ms_data->tr_from;
$group_for=$ms_data->group_for;

sec_journal_journal($conn,$jv_no,$jv_no,$tr_from);

$time_now = date('Y-m-d H:i:s');

$up_sj='update secondary_journal set status="CHECKED", checked_at="'.$time_now.'", checked_by="'.$_SESSION['user']['id'].'" 
where jv_no="'.$jv_no.'" and tr_from="'.$tr_from.'"';
mysqli_query($conn,$up_sj);

$up_jv='update journal set status="CHECKED", checked_by="'.$_SESSION['user']['id'].'", checked_at="'.$time_now.'"
 where jv_no="'.$jv_no.'" and tr_from="'.$tr_from.'"';
mysqli_query($conn,$up_jv);

$up_jm='update journal_master set status="CHECKED", checked_by="'.$_SESSION['user']['id'].'", checked_at="'.$time_now.'"
 where jv_no="'.$jv_no.'" and tr_from="'.$tr_from.'"';
mysqli_query($conn,$up_jm);


header("location:".$page.'?jv_no='.$jv_no."");
?>



<?php

}


if(isset($_POST['draft_data']))
{
$ms_sql="SELECT * FROM journal_master  WHERE jv_no='".$jv_no."'";
$ms_data = find_all_field_sql($conn,$ms_sql);

$entry_by =  $_SESSION['user']['id'];
$entry_at = $now=date('Y-m-d H:i:s');

$jv_no=$ms_data->jv_no;
$tr_from=$ms_data->tr_from;
$group_for=$ms_data->group_for;

$sql_del3 = 'delete from journal where tr_from="'.$tr_from.'" and jv_no="'.$jv_no.'"';
mysqli_query($conn,$sql_del3);

 if($ms_data->jv_type==1){
 $sql_del_sc = 'delete from secondary_journal where tr_from="'.$tr_from.'" and jv_no="'.$jv_no.'" and dr_amt>0';
mysqli_query($conn,$sql_del_sc);
 }elseif($ms_data->jv_type==2){
 $sql_del_sc = 'delete from secondary_journal where tr_from="'.$tr_from.'" and jv_no="'.$jv_no.'" and cr_amt>0';
mysqli_query($conn,$sql_del_sc);
 }


$up_jm='update journal_master set status="MANUAL" where jv_no="'.$jv_no.'" and tr_from="'.$tr_from.'"';
mysqli_query($conn,$up_jm);


$up_sj='update secondary_journal set status="MANUAL" where jv_no="'.$jv_no.'" and tr_from="'.$tr_from.'"';
mysqli_query($conn,$up_sj);

?>

<script language="javascript">
window.location.href = "../27_voucher.php?active_id=307&menu_id=3";
</script>

<?php

}


if(isset($_POST['edit_data']))
{
$ms_sql="SELECT * FROM journal_master  WHERE jv_no='".$jv_no."'";
$ms_data = find_all_field_sql($conn,$ms_sql);
?>
 <?php if($ms_data->jv_type==1){?>
<script language="javascript">
window.location.href = "../21_voucher_edit.php?active_id=306&menu_id=3&request_no=<?php echo $jv_no;?>";
</script>
<?php } elseif ($ms_data->jv_type==2){ ?>
<script language="javascript">
window.location.href = "../22_voucher_edit.php?active_id=306&menu_id=3&request_no=<?php echo $jv_no;?>";
</script>
<?php }elseif ($ms_data->jv_type==3){?>
<script language="javascript">
window.location.href = "../23_voucher_edit.php?active_id=306&menu_id=3&request_no=<?php echo $jv_no;?>";
</script>
 <?php }elseif ($ms_data->jv_type==4){?>
<script language="javascript">
window.location.href = "../24_voucher_edit.php?active_id=306&menu_id=3&request_no=<?php echo $jv_no;?>";
</script>
<?php } ?>

<?php } ?>



<!DOCTYPE html>
<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title><?php echo $ms_data->view_jv_no?></title>


<link href="../../logo/favicon.png" rel="icon">

 <link href="https://fonts.gstatic.com" rel="preconnect">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
 

  <!-- Vendor CSS Files -->

  <!-- Template Main CSS File -->
 
  
   
<style type="text/css">

<!--

.header table tr td table tr td table tr td table tr td {

	color: #000;

}

@font-face {

  font-family: 'MYRIADPRO-REGULAR';

  src: url('MYRIADPRO-REGULAR.OTF'); /* IE9 Compat Modes */



}



@font-face {

  font-family: 'TradeGothicLTStd-Extended';

  src: url('TradeGothicLTStd-Extended.otf'); /* IE9 Compat Modes */



}





@font-face {

  font-family: 'Humaira demo';

  src: url('Humaira demo.otf'); /* IE9 Compat Modes */



}



@media print {

  .brack {page-break-after: always;}

}





</style>

</head>

<body style="font-family:Tahoma, Geneva, sans-serif; font-size: 10px;">



<div class="page_brack" >



<table width="900" border="0" cellspacing="0" cellpadding="0" align="center">

  <tbody>

  <tr>

    <td><div class="header">

        <table width="100%" border="0" cellspacing="0" cellpadding="0">

          <tr>

            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">

                <tr>

                  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">

                      <tr>

                        <td width="15%">

                       <!-- <img src="../../../logo/logo.png" width="100%" />-->
                        <td width="60%"><table  width="100%" border="0" align="center" cellpadding="3" cellspacing="0">

                            <tr>

                              <td style="text-align:center; color:#000; font-size:14px; font-weight:bold;">
<p style="font-size:18px; color:#000000; margin:0; padding: 0 0 5px 0; text-transform:uppercase;  font-weight:700; font-family: 'TradeGothicLTStd-Extended';"><?php echo $grp_data->group_name?></p>
<p style="font-size:14px; font-weight:300; color:#000000; margin:0; padding:0;"><?php echo $grp_data->address?></p>

								<p style="font-size:12px; font-weight:300; color:#000000; margin:0; padding:10px;">Contact No: <?php echo $grp_data->contact_no?>,  Email:  <?php echo $grp_data->email?></p>                              </td>
                            </tr>

                            <tr>





        <!--<td bgcolor="#666666" style="text-align:center; color:#FFF; font-size:18px; font-weight:bold;">WORK ORDER </td>-->
      </tr>

                          </table>
                        <td width="20%"> 

						

					<table width="100%" border="0" cellspacing="0" cellpadding="0">

					

					<tr>

					  

					  <td align="center"><h4 style="font-size:16px;"><!--Customer's Copy--></h4></td>
					  </tr>

                      

					  

					  <tr>

					  

					  <td>&nbsp;</td>
					  </tr>

					  

					  <tr>

					  

					  <td>&nbsp;</td>
					  </tr>
					  </table>						</td>
                      </tr>

                    </table></td>
                </tr>

              </table></td>
          </tr>

          <tr>          </tr>
        </table>

      </div></td>
  </tr>

  



 

 

 

 

 

 



 

  <tr> <td><hr /></td></tr>

 

  

  

  <tr> <td>

  <table width="100%" border="0" cellspacing="0" cellpadding="0"  style="font-size:12px">

  

  	<tr height="30">

  	  <td width="25%" valign="top"></td>

  	  <td width="50%"  style="text-align:center; color:#FFF; font-size:18px; text-transform:uppercase; padding:0px 0px 10px 0px; color:#000000; font-weight:bold; font-weight:700; font-family: 'TradeGothicLTStd-Extended';"><span style="text-decoration:underline;"><?php echo $ms_data->tr_from;?> Voucher</span> </td>

  	  <td width="25%" align="right" valign="right">&nbsp;</td>
	  </tr>
  </table>

  

  </td></tr>

  

  

  <tr> <td>&nbsp;</td></tr>

  

  

  

 <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="0">





		  <tr>





		    <td width="100%" valign="top">





		      <table width="100%" border="0" cellspacing="0" cellpadding="3"  style="font-size:12px">





		        <tr>

		          <td width="35%" style="font-size:14px; font-weight:700; text-transform:uppercase">Account Reference</td>

	              <td width="37%">&nbsp;</td>
	              <td width="11%"><span role="presentation" dir="ltr">JV NO </span></td>

	              <td width="17%">:&nbsp;<?php if($ms_data->tr_from=="Sales") {?>
				  <a href="sales_invoice_print_view.php?jv_no=<?php echo $ms_data->jv_no;?>" target="_blank"><?php echo $ms_data->view_jv_no?></a>
				  <?php }elseif($ms_data->tr_from=="Purchase"){?>
				  <a href="purchase_bill_print_view.php?jv_no=<?php echo $ms_data->jv_no;?>" target="_blank"><?php echo $ms_data->view_jv_no?></a>
				  <?php }else{?>
				  <?php echo $ms_data->view_jv_no?>
				  <?php }?></td>
		        </tr>

		        <tr>

		          <td  style="font-size:14px;"><?php echo $ref_data->full_name?></td>

	              <td>&nbsp;</td>
	              <td>DATE</td>

	              <td>: &nbsp;<?php echo date('d-M-Y',strtotime($ms_data->jv_date));?></td>
		        </tr>
		        <tr>
		          <td>&nbsp;</td>
		          <td>&nbsp;</td>
		          <td>&nbsp;</td>
		          <td>&nbsp;</td>
		          </tr>
		        </table>		      </td>
		  </tr>





		</table>		</td></tr>

  

  

 

  <tr>

    <td>

      

      <table  width="100%" border="1" bordercolor="#CCCCCC" cellspacing="0" cellpadding="5"  style="font-size:12px">
                <thead>
                  <tr>
                    <th width="2%" scope="col">SL</th>
                    <th width="15%" scope="col">GL GROUP</th>
                    <th width="24%" scope="col">ACCOUNT</th>
                    <th width="24%" scope="col">SUB LEDGER</th>
                    <th width="15%" scope="col">DESCRIPTION</th>
                    <th width="10%" scope="col"><div style="text-align:right">DEBIT&nbsp;</div></th>
                    <th width="10%" scope="col"><div style="text-align:right">CREDIT&nbsp;</div></th>
                  </tr>
                </thead>
                <tbody>
					<?php
					
					$sl=1;
					
		$sql = "select group_id, group_name from ledger_group where 1 group by group_id";
		 $query = mysqli_query($conn,$sql);
		 while($info=mysqli_fetch_object($query)){
  		 $group_name[$info->group_id]=$info->group_name;
	
		}
		
		 			$sql = "select ref_no, display_name from accounts_reference where 1 group by ref_no";
					 $query = mysqli_query($conn,$sql);
					 while($info=mysqli_fetch_object($query)){
					 $display_name[$info->ref_no]=$info->display_name;
					}
				
					
						 $sql = 'select j.*, a.ledger_group_id, a.ledger_name from secondary_journal j, accounts_ledger a
						where j.ledger_id=a.ledger_id and j.jv_no="'.$jv_no.'"  order by j.id,j.dr_amt,j.cr_amt';
						$query = mysqli_query($conn,$sql);
						while ($data = mysqli_fetch_object($query)) {

					?>
				
                  <tr>
                    <th scope="row"><?php echo $sl++;?></th>
                    <td><?php echo $group_name[$data->ledger_group_id]?></td>
                    <td><?php echo $data->ledger_name;?></td>
                    <td><?php echo $display_name[$data->ref_no];?></td>
                    <td><?php echo $data->narration;?></td>
                    <td align="right"><?php echo number_format($data->dr_amt,2); $total_dr_amt +=$data->dr_amt;?>&nbsp;</td>
                    <td align="right"><?php echo number_format($data->cr_amt,2); $total_cr_amt +=$data->cr_amt;?>&nbsp;</td>
                  </tr>
				   <?php }?>
                  <tr>
                    <th scope="row">&nbsp;</th>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td align="center">&nbsp;</td>
                    <td align="center"><strong>TOTAL</strong></td>
                    <td align="right"><strong><?php echo  number_format($total_dr_amt,2);?></strong>&nbsp;</td>
                    <td align="right"><strong><?php echo  number_format($total_cr_amt,2);?></strong>&nbsp;</td>
                  </tr>
                </tbody>
              </table>        </td>
  </tr>

  

  

  

  

  <tr>

  

  	<td>Entry By: <?php echo find_a_field($conn,'user_management','fname','user_id="'.$ms_data->entry_by.'"');?>, Entry At: <?php echo $ms_data->entry_at; ?></td>
  </tr>

  



  

  

  

	

	

	



	

	<tr>

	  <td>&nbsp;</td>
	  </tr>
	  <tr>

	  <td>&nbsp;</td>
	  </tr>
	  <tr>

	  <td>&nbsp;</td>
	  </tr>
	  <tr>
	    <td>&nbsp;</td>
      </tr>
	  <tr>
	    <td>&nbsp;</td>
      </tr>
	  <tr>
	    <td>&nbsp;</td>
      </tr>
	  
	  <?php if($ms_data->status=="UNCHECKED") {?>
	  <tr>

	  <td>
	  <form action="" method="post" name="form1" id="form1" onSubmit="return check()">   
			<div class="text-left">
				
                  <button type="submit" class="btn btn-success btn-sm" name="confirm_data" id="confirm_data" style="background: #198754; padding:8px 20px; color:#fff; font-weight:700; border-radius: 5px; font-size:12px; margin-right:20px;">Confirm &amp; Publish</button> 
				   
				   <?php if($ms_data->jv_special==0) {?>
				   <button type="submit" class="btn btn-success btn-sm" name="draft_data" id="confirm_data" style="background: #0d6efd; padding:8px 20px; color:#fff; font-weight:700; border-radius: 5px; font-size:12px; margin-right:20px;" >Send To Draft</button>
                   <button type="submit" class="btn btn-success btn-sm" name="edit_data" id="confirm_data" style="background: #dc3545; padding:8px 20px; color:#fff; font-weight:700; border-radius: 5px; font-size:12px; margin-right:20px;">Edit Voucher</button>
				    <?php }?>
				   </div>
        </form>	  </td>
	  </tr>
	  
	  <?php }else{?>
	  
	   <tr>
	  <td>
	   <span style="text-align:center; font-size:16px; padding: 10px 50px; background: #012970; color:#f6f9ff; font-weight:700;">THIS VOUCHER HAS BEEN <?php echo $ms_data->status;?></span>	  </td>
	  </tr>
 <?php }?>
  </tbody>
</table>


</div>







</body>

</html>

