<?php
	include "db_connection/db_connection.php";
	include "config/config.php";

	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='index.php';</script>";
	}
	
	$check_acc  = check_access('41');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title><?php echo $PROJECT_TITLE ?></title>

<link href="css/styles.css" rel="stylesheet" type="text/css" />
<!--[if IE]> <link href="css/ie.css" rel="stylesheet" type="text/css"> <![endif]-->

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

<script type="text/javascript" src="js/plugins/forms/ui.spinner.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.mousewheel.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/plugins/charts/excanvas.min.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.orderBars.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.pie.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.resize.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.sparkline.min.js"></script>

<script type="text/javascript" src="js/plugins/tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/plugins/tables/jquery.sortable.js"></script>
<script type="text/javascript" src="js/plugins/tables/jquery.resizable.js"></script>

<script type="text/javascript" src="js/plugins/forms/autogrowtextarea.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.uniform.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.inputlimiter.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.maskedinput.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.autotab.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.chosen.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.dualListBox.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.cleditor.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.ibutton.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine.js"></script>

<script type="text/javascript" src="js/plugins/uploader/plupload.js"></script>
<script type="text/javascript" src="js/plugins/uploader/plupload.html4.js"></script>
<script type="text/javascript" src="js/plugins/uploader/plupload.html5.js"></script>
<script type="text/javascript" src="js/plugins/uploader/jquery.plupload.queue.js"></script>

<script type="text/javascript" src="js/plugins/wizards/jquery.form.wizard.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.validate.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.form.js"></script>

<script type="text/javascript" src="js/plugins/ui/jquery.collapsible.min.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.breadcrumbs.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.tipsy.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.progress.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.timeentry.min.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.colorpicker.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.jgrowl.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.fancybox.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.fileTree.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.sourcerer.js"></script>

<script type="text/javascript" src="js/plugins/others/jquery.fullcalendar.js"></script>
<script type="text/javascript" src="js/plugins/others/jquery.elfinder.js"></script>

<script type="text/javascript" src="js/plugins/ui/jquery.easytabs.min.js"></script>
<script type="text/javascript" src="js/files/bootstrap.js"></script>
<script type="text/javascript" src="js/files/functions.js"></script>

<script type="text/javascript" src="js/charts/chart.js"></script>
<script type="text/javascript" src="js/charts/hBar_side.js"></script>

<!-- Shared on MafiaShare.net  --><!-- Shared on MafiaShare.net  --></head>

<body>

<!-- Top line begins -->
<?php include "header_footer/header.php"; ?>
<!-- Top line ends -->


<!-- Sidebar begins -->
<?php include "menus/left_menu.php"; ?>
<!-- Sidebar ends -->
<!-- Content begins -->
<div id="content">
<?php include "menus/top_menu.php"; ?>
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="#">Dashboard</a></li>
                <li><a href="javascript:">Billing</a></li>
            </ul>
        </div>
	<?php include "menus/top_left_menu.php"; ?>
    </div>
    <!-- Main content -->
    <div class="wrapper">
	<?php if($check_acc==1){?>
        <ul class="middleNavR">
            <!--<li><a href="#" title="Add an article" class="tipN"><img src="images/icons/middlenav/create.png" alt="" /></a></li>
            <li><a href="#" title="Upload files" class="tipN"><img src="images/icons/middlenav/upload.png" alt="" /></a></li>-->
			<?php
			$des_list41 = check_rights('41','add');
			if($des_list41==1){ ?>
          <li><a href="billing_add.php" title="Add Bill" class="tipN"><img src="images/icons/middlenav/add.png" alt="" /></a></li>
			<?php } ?>
            <!--<li><a href="#" title="Messages" class="tipN"><img src="images/icons/middlenav/dialogs.png" alt="" /></a><strong>8</strong></li>
            <li><a href="#" title="Check statistics" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>-->
    	</ul>
    	<!-- Chart --><!-- 6 + 6 -->

    	<div class="widget"> <!--style="width:600px; margin-left:150px;"-->
        <div class="whead"><h6>Billing List</h6><div class="clear"></div></div>
        <div id="dyn" class="hiddenpars">
        	<a class="tOptions" title="Options"><img src="images/icons/options.png" alt="" /></a>
            <table cellpadding="0" cellspacing="0" border="0" class="dTable" id="dynamic">
            <thead>
            <tr>
            <th width="26" align="center">S.No<span class="sorting" style="display: block;"></span></th>
            <th width="125" align="center">Bill No</th>
            <th width="30" align="left">Bill Type</th>
            <th width="79" align="center">Bill Date</th>
            <th width="172" align="left">Company Name</th>
            <th width="86"  align="right">Bill Amt</th>
            <th width="50" align="right">Tax Amt</th>
            <th width="50" align="right">Courier Amt</th>
            <th width="50" align="right">Round off</th>
            <th width="96" align="right">Total Bill Amt</th>
            <!--<th width="78">Image</th>-->
            <th width="89" align="center">View</th>
            <!--<th width="61">Status</th>-->
            </tr>
            </thead>
            <tbody>
            <?php
			$page_id= base64_encode(base64_encode(base64_encode(2))); //THIS IS FOR PAGE IDENTIFICATION IN BL FILE for active inactive

			//$SLCT = "SELECT * FROM  `billing_det` ORDER BY  `bill_no` DESC ";
			$SLCT = "SELECT * FROM billing_det ORDER BY STR_TO_DATE(bill_date,'%d-%m-%Y') DESC , `billing_det_id` DESC";
			//echo $SLCT;
			$QURY = mysqli_query($connect,$SLCT);
			$loop=1;
			if(mysqli_num_rows($QURY)>0)
			{
			while($FTCH = mysqli_fetch_object($QURY))
			{

				$bill_id	=	base64_encode(base64_encode(base64_encode($FTCH->billing_det_id)));
				$SLCT_tp = "SELECT * FROM party_det WHERE party_det_id = '$FTCH->party_det_id'";
				$QURY_tp = mysqli_query($connect,$SLCT_tp);
				$FTCH_tp = mysqli_fetch_object($QURY_tp);

				$SLCT_p = "SELECT * FROM party_det WHERE party_det_id = '$FTCH->party_det_id'";
				$QURY_p = mysqli_query($connect,$SLCT_p);
				$FTCH_p = mysqli_fetch_object($QURY_p);

				$SLCT_part = "SELECT cmp_name FROM party_det_log WHERE party_det_id = '$FTCH->party_det_id' AND STR_TO_DATE(REPLACE('$FTCH->bill_date','/','-'),'%d-%m-%Y') BETWEEN STR_TO_DATE(`active_date`,'%Y-%m-%d') AND STR_TO_DATE(`inactive_date`,'%Y-%m-%d')";
				$QURY_part = mysqli_query($connect,$SLCT_part);
				if(mysqli_num_rows($QURY_part)>0)
				{
					$FTCH_part = mysqli_fetch_object($QURY_part);
					$cmp_name  = $FTCH_part->cmp_name;
				}
				else
				{
					$cmp_name  = $FTCH_tp->cmp_name;
				}

				$rnd_off = str_replace(array(".", ","), array(",", "."), $FTCH->round_off);
//str_replace(array( '(', ')' ), '', $FTCH->round_off);

				//$rnd_off = substr($rnd_off, 1);

				if($FTCH->courier_amt==''){
					$courier_amount=0;
				} else {
					$courier_amount=$FTCH->courier_amt;
				}
				if($rnd_off!='')
				{
					if($FTCH->bill_tax_lable == "SGST,  CGST")
					{
						$bl_amt =  $FTCH->bill_amt -(((float)$FTCH->bill_tax_amt * 2) + (float)$rnd_off) - $FTCH->courier_amt;//$FTCH->bill_amt - (($FTCH->bill_tax_amt * 2) + $rnd_off) - $FTCH->courier_amt;
						$rnd_lbl = $FTCH->round_off;
					}
					else
					{
						$bl_amt = $FTCH->bill_amt-((float)$FTCH->bill_tax_amt+(float)$rnd_off)-$FTCH->courier_amt;
						$rnd_lbl = $FTCH->round_off;
					}
				}
				else if($rnd_off=='')
				{
					if($FTCH->bill_tax_lable == "SGST,  CGST")
					{
						$bl_amt = $FTCH->bill_amt - ($FTCH->bill_tax_amt * 2) - $FTCH->courier_amt;
						$rnd_lbl = "0.00";
					}
					else
					{
						$bl_amt = $FTCH->bill_amt - (float)$FTCH->bill_tax_amt - $FTCH->courier_amt;
						$rnd_lbl = "0.00";
					}
				}

				if($loop%2 != "0")
					$bg = "gradeX";
				else
					$bg = "class='gradeC'";
			?>
            <tr <?php echo $bg ?>>
            <td align="center" style="vertical-align:middle;"><?php echo $loop ?></td>
            <td align="center" style="vertical-align:middle;"><?php echo $FTCH->bill_no; ?></td>
            <td align="left" style="vertical-align:middle;"><?php echo $FTCH->bill_type; ?></td>
            <td align="center" style="vertical-align:middle;"><?php echo str_replace("-", "/", $FTCH->bill_date); ?></td>
            <td align="left" style="vertical-align:middle;"><?php echo $FTCH_tp->party_code; ?> - 
			<?php //echo $cmp_name; ?>
			<?php 
				$name_count = strlen($cmp_name);
				$name='';
				if($name_count>10){
					$name = substr($cmp_name,0,10)."...";
				} else {
					$name = $cmp_name;
				} ?>
			<?php if($name_count>10){?>
			<div class="tooltip1">
			<?php echo $name;?>
				<span class="tooltiptext1"><?php echo $cmp_name;?></span>
			</div>
			<?php } else { ?>
			<?php echo $name;?>
			<?php } ?>
			
			</td>            
            <td align="right" style="vertical-align:middle;"><?php echo number_format($bl_amt, 2); ?></td> 
            <td align="right" style="vertical-align:middle;">
			<?php
			if($FTCH->bill_tax_lable == "SGST,  CGST")
			{
				echo number_format((float)$FTCH->bill_tax_amt *2, 2); 
			}
			else
			{
				echo number_format($FTCH->bill_tax_amt, 2); 
			}	
			?>
			</td>
            <td align="right" style="vertical-align:middle;"><?php echo number_format($FTCH->courier_amt,2); ?></td> 
             <td align="right" style="vertical-align:middle;"><?php echo $rnd_lbl; ?></td>
            <td align="right" style="vertical-align:middle;"><?php echo number_format(round($FTCH->bill_amt),2); ?></td>
            <?php /*?><td class="center"><a href=""><img src="design_images/S.<?php echo $FTCH->imag_ext; ?>" width="60" height="60"/></a></td><?php */?>
            <td align="center" class="center" style="vertical-align:middle;">
			<?php if($FTCH->bill_type == 'Non Tax'){ ?>
			<a href="bill_non_tax.php?bill_id=<?php echo $bill_id ?>" target="_blank" class="an_own">View |</a>
			<?php }else if($FTCH->bill_type == 'Tax'){ ?>
			<a href="bill_tax.php?bill_id=<?php echo $bill_id ?>" target="_blank" class="an_own">View |</a>
			<?php } ?>			
				<a href="courier_address.php?bill_id=<?php echo $bill_id ?>" target="_blank" class="an_own">Courier Address</a>
			</td>
            <?php /*?><td class="center"><?php if($FTCH->statu_s=="active"){ ?><a href="bl/design_BL.php?design_id=<?php echo $design_id ?>&page_id=<?php echo $page_id; ?>&statu_s=active">Active</a><?php }else{ ?><a href="bl/design_BL.php?design_id=<?php echo $design_id ?>&page_id=<?php echo $page_id; ?>&statu_s=inactive">Inactive</a> <?php } ?></td><?php */?>
            </tr>
            
            <?php
			$loop ++;
			 }
			 }
			 ?>
            </tbody>
            </table> 
        </div>
        </div>    
        
        <div class="fluid"><!-- Media table --></div>
<?php } else {  echo ACCESS_MSG;} ?>

    </div>
    <!-- Main content ends -->
    
</div>
<!-- Content ends -->
<?php /*?><?php include "header_footer/footer.php"; ?><?php */?>
</body>
</html>
