@extends('backend.header')
@section('index-content')
<style>
  .add-btn{
    width: auto !important;
    height: 31px !important;
    border-radius: 3px !important;
    line-height: 16px !important;
  }
  .table-responsive {
        width: 100%;
        height: 75vh !important;
    }
    /*th,
    td {
        white-space: nowrap;
    }*/
    table tr td:first-child {
        position: sticky;
        width: 50px;
        left: 0;
        background: #fff;
        color: #000;
        z-index: 9;
    }
    table tr td:nth-child(2) {
        position: sticky;
        left: 52px;
        background: #fff;
        color: #000;
        z-index: 9;
    }
    table tr th:first-child {
        position: sticky;
        width: 50px;
        left: 0;
        /*   background: #fff;*/
        color: #000;
        z-index: 10;
    }
    table tr th:nth-child(2) {
        position: sticky;
        left: 52px;
/*        background: #fff !important;*/
        color: #000;
        z-index: 10;
    }
    tr.table-success {
        position: sticky;
        left: 0;
        z-index: 10;
/*        background: #fff !important;*/
    }
    tr.table-success {
        top: 0px !important;
        position: sticky !important;
    }
    tr.table-warning {
         top: 36px !important;
         position: sticky !important;
    }
    tr.table-warning,
    tr.table-success{
         position: sticky;
         left: 0;
         z-index: 10;
/*         background: #fff !important;*/
    }
    .table-success,
    .table-success > td,
    .table-success > th {
        background-color: #c3e6cb !important;
    }
    .table-warning, .table-warning>td, .table-warning>th {
        background-color: #ffeeba !important;
    } 
</style>
<div class="row px-3">
  <section role="main" class="content-body">
    <header class="page-header">
        <div class="row">
          <div class="col-lg-5">
            @if(session()->get('role')==0)
              <h2>Outward Invoice</h2>
            @else
              <h2>Inward Invoice</h2>
            @endif
          </div>
        
          <div class="col-lg-5">
           @if(session()->get('role')==0)
            <ol class="breadcrumbs">
              <li>
                <a href="{{url('index')}}">
                  <i class="fa fa-home"></i>
                </a>
              </li>
              <li><a href="{{url('inwards_view')}}"><span class="active">{{$district->area_name??"District"}}</span></a></li>
            </ol>
            @endif
          </div>
          <div class="col-lg-2">
                 @if(!Session::has('dashboardurl')) 
                  <!--   <div class="add-btn-div">
                        <a href="{{url('outwards_store')}}" class="btn btn-primary add-btn" style="margin-right: 25px;">Add </a>
                    </div> -->
                    @endif
          </div>
      </div>
    </header>
  	<!-- @if(session()->get('role')==0)
      <header class="page-header">
          <h2>Outward Invoice</h2>
      </header>
      @else
      <header class="page-header">
          <h2>Inward Invoice</h2>
      </header>
      @endif
      <div class="row">
        <div class="col-xs-12">
          <div class="right-wrapper">
          	@if(session()->get('role')==0)
            <ol class="breadcrumbs">
              <li>
                <a href="{{url('index')}}">
                  <i class="fa fa-home"></i>
                </a>
              </li>
              <li><a href="{{url('inwards_view')}}"><span class="active">{{$district->area_name??"District"}}</span></a></li>
            </ol>
            @endif
          </div>
        </div>
        <div class="col-xs-12 mt-3">
          
        </div>
      </div> -->


		<section class="mt-1  ">
			<!-- @if(session()->get('role')==0)
			<header class="panel-heading">
				<h4 class="my-0">outward Invoice</h4>
			</header>
			@else
			<header class="panel-heading">
				<h4 class="my-0">Inward Invoice</h4>
			</header>
			@endif -->
			<div class="panel-body py-0 px-2">
				<div class="table-responsive">
            <table class="table table-bordered table-striped mb-none mt-0" id="datatable-default">
               <thead>
               	<tr >
           	<td colspan="11"><b>Inwards Quantity<b></td>
           	</tr>
 
             <tr class="table-success">

						<th>S.NO</th> 
					 <!-- <th class="text-left">Vendor&nbsp;Name</th> -->
					 <th>Invoice&nbsp;Number</th>
					 <th>Make Name</th> 
						<th>18 W </th>
						<th>35 W </th>
						<th>70 W </th>
						<th>110 W </th>
						<th>190 W </th>
						<th>Total Lights</th>
						<th>Buffer Stock </th>
						<th>Total Lights Including Bufferstock </th>      
						<th>Remarks</th>      
                   </tr>
               </thead>
               <tbody>
                <?php $tw1=0;$tw2=0;$tw3=0;$tw4=0;$tw5=0;$tw6=0; $sum=0;$buf=0; $i=0;?>
                @foreach($area_invoice as $list)
                <?php $i++;
                   $counts=$list['18w']+$list['35w']+$list['70w']+$list['110w']+$list['190w'];
			         $counts_buff_received=$list['buffer_stk_rcv_18']+$list['buffer_stk_rcv_35']+$list['buffer_stk_rcv_70']+$list['buffer_stk_rcv_110']+$list['buffer_stk_rcv_190'];

               $ex_buf_stock=$counts+$counts_buff_received;
            
				 ?>
                <tr>
					<td data-order="{{$i}}">{{$i}}</td>
					<!-- <td class="text-left"><a href="">{{$list['vendor_name']['name']??'0'}}</a></td> -->
					<td class="text-left"><a href="{{url('outwards_list')}}?id={{$list['invoice_number']}}&&jilla_id={{$list['jilla_id']}}">{{$list['invoice_number']??'0'}}</a></td>
					<td>{{$list['maker_name']??'0'}}</td>						
					<td>{{$list['18w']??'0'}}</td>
					<td>{{$list['35w']??'0'}}</td>
					<td>{{$list['70w']??'0'}}</td>
					<td>{{$list['110w']??'0'}}</td>
					<td>{{$list['190w']??'0'}}</td>
				<td><b>{{$counts??'0'}}</b></td>
				<td>{{$counts_buff_received??'0'}}</td>
				<td>{{$ex_buf_stock??'0'}}</td>
					 <td>{{$list['remarks']??''}}</td>
                </tr>
                <?php 
					$tw1=$list['18w']+$tw1;
					$tw2=$list['35w']+$tw2;
					$tw3=$list['70w']+$tw3;
					$tw4=$list['110w']+$tw4;
					$tw5=$list['190w']+$tw5;
					$tw6=$list['buffer_stk']+$tw6;
         

          $sum=$sum+$counts; 

         $buf=$buf+$counts_buff_received;
        $total_inclu_buf=$sum+$buf;
				?>                                
                @endforeach

            </tbody>
            <tfoot>
                <tr>
                	<td data-order="{{$i}}"></td>
					<td><b>Total</b></td>	
					<td></td>
					<td><b>{{$tw1??'0'}}</b></td>
					<td><b>{{$tw2??'0'}}</b></td>
					<td><b>{{$tw3??'0'}}</b></td>
					<td><b>{{$tw4??'0'}}</b></td>
					<td><b>{{$tw5??'0'}}</b></td>
					   <td><b>{{$sum??'0'}}</b></td>
          <td><b>{{$buf??'0'}}</b></td>
          <td><b>{{$total_inclu_buf??'0'}}</b></td>
					<td></td>
				</tr>
			<!-- 	<tr>
					<td colspan="2"><b>Grand Total Without Bufferstock </b></td>
					<td colspan="8"><b>{{$excl_bufstk??'0'}}</b></td>
					 <td colspan="2"><b></b></td>
				</tr> -->
               
               </tfoot>
            </table>
          </div>

          <div>
          <table class="table table-bordered table-striped mb-none mt-0" >
               <thead>
                <tr>
                  <th colspan="10">Quantity&nbsp;By&nbsp;Makewise</th></tr>
              
            <tr>
            <th>S.NO</th>
           
            <th>Make Name</th> 
            <th>18&nbsp;W </th>
            <th>35&nbsp;W </th>
            <th>70&nbsp;W </th>
            <th>110&nbsp;W </th>
            <th>190&nbsp;W </th>
            <th>Total&nbsp;Lights</th>
            <th>Buffer&nbsp;Stock </th>
            <th>Total&nbsp;Lights Including Bufferstock </th>      
                
             </tr>
               </thead>

               <tbody>
                <?php
               $count = 0;
                        ?>

                <?php $tw1=0;$tw2=0;$tw3=0;$tw4=0;$tw5=0;$tw6=0;  $sum=0; $sum1=0; $buf=0; $buf1=0; $i=0;
                $iw1=0;$iw2=0;$iw3=0;$iw4=0;$iw5=0;   $mw1=0;$mw2=0;$mw3=0;$mw4=0;$mw5=0;$mw6=0;?>
                @foreach($maker_counts as $list)
                <?php $i++;

          $counts=$list['18w']+$list['35w']+$list['70w']+$list['110w']+$list['190w'];
          $invoice_counts=$list['invoice_18w']+$list['invoice_35w']+$list['invoice_70w']+$list['invoice_110w']+$list['invoice_190w'];

         $counts_buff_invoice=$list['buffer_stk_18']+$list['buffer_stk_35']+$list['buffer_stk_70']+$list['buffer_stk_110']+$list['buffer_stk_190'];

         $counts_buff_received=$list['buffer_stk_rcv_18']+$list['buffer_stk_rcv_35']+$list['buffer_stk_rcv_70']+$list['buffer_stk_rcv_110']+$list['buffer_stk_rcv_190'];

         $ex_buf_stock=$counts+$counts_buff_received;
          $in_buf_stock=$invoice_counts+$counts_buff_received;

          
            
         ?>
                <tr>
          <td>{{$i}}</td>
      
          <td>{{$list['maker_name']}}</td>
          <!-- <td>
            @if($list['phase_no'] !=0 && $list['phase_no'] > 0)
              Phase_{{$list['phase_no']??'-'}}
            @else
              -
            @endif
          </td> -->
          <td>{{$list['18w']??'0'}}</td>
          <td>{{$list['35w']??'0'}}</td>
          <td>{{$list['70w']??'0'}}</td>
          <td>{{$list['110w']??'0'}}</td>
          <td>{{$list['190w']??'0'}}</td>
        <td>{{$counts??'0'}}</td>
         <td>{{$counts_buff_received??'0'}}</td>
        <td>{{$ex_buf_stock??'0'}}</td>
        
             
                </tr>
                <?php 
          $tw1=$list['18w']+$tw1;
          $tw2=$list['35w']+$tw2;             
          $tw3=$list['70w']+$tw3;
          $tw4=$list['110w']+$tw4;
          $tw5=$list['190w']+$tw5;
          // $tw6=$list['buffer_stk']+$tw6;

             $sum=$sum+$counts;


        $buf=$buf+$counts_buff_received;
        $total_inclu_buf=$sum+$buf;

         $sum1=$sum1+$invoice_counts; 
          $buf1=$buf1+$counts_buff_received;
            $total1_inclu_buf=$sum1+$buf1;

       $iw1=$list['invoice_18w']+$iw1;
          $iw2=$list['invoice_35w']+$iw2;
          $iw3=$list['invoice_70w']+$iw3;
          $iw4=$list['invoice_110w']+$iw4;
          $iw5=$list['invoice_190w']+$iw5;


        ?>        
                           
                @endforeach

                
    <tr>  
     <td></td>    
    <td><b>Total</b></td>

   
    <td><b>{{$tw1}}</b></td>
    <td><b>{{$tw2}}</b></td>
    <td><b>{{$tw3}}</b></td>
    <td><b>{{$tw4}}</b></td>
    <td><b>{{$tw5}}</b></td>
    <td><b>{{$sum??'0'}}</b></td>
    <td><b>{{$buf??'0'}}</b></td>
    <td><b>{{$total_inclu_buf??'0'}}</b></td>

</tr>
 

<!-- <tr>
    <td colspan="5"><b>Grand Total Without Bufferstock </b></td>
    <td colspan="5"><b></b>{{$sum}}</td>
    <td colspan="5"><b>Grand Total Without Bufferstock </b></td>
    <td colspan="5"><b></b>{{$sum1}}</td>
</tr> -->
               
               </tbody>
            </table>
          </div>
          @if(session()->get('role')==6)
          <div class="panel-body pt-5">
            <table class="table table-bordered table-striped mb-none mt-0">
               <thead>
               	<tr >
           	<td colspan="11"><b>Balance Quantity<b></td>
           	</tr>
                   <tr>
						<th>S.NO</th> 
					 <!-- <th class="text-left">Vendor&nbsp;Name</th> -->
					 <th>Invoice&nbsp;Number</th>
					 <th>Make&nbsp;Name</th> 
						<th>18&nbsp;W </th>
						<th>35&nbsp;W </th>
						<th>70&nbsp;W </th>
						<th>110&nbsp;W </th>
						<th>190&nbsp;W </th>
						<th>Total&nbsp;Lights</th>
						<th>Buffer&nbsp;Stock </th>
						<th>Total Lights Including Bufferstock </th>      
						<th>Remarks</th>      
                   </tr>
               </thead>
               <tbody>
                <?php $tw1=0;$tw2=0;$tw3=0;$tw4=0;$tw5=0;$tw6=0; $sum=0;$buf=0; $i=0;?>
                @foreach($balance_invoice as $list)
                <?php $i++;
                   $counts=$list['18w']+$list['35w']+$list['70w']+$list['110w']+$list['190w'];
			         $counts_buff_received=$list['buffer_stk_rcv_18']+$list['buffer_stk_rcv_35']+$list['buffer_stk_rcv_70']+$list['buffer_stk_rcv_110']+$list['buffer_stk_rcv_190'];

               $ex_buf_stock=$counts+$counts_buff_received;
            
				 ?>
                <tr>
					<td>{{$i}}</td>
					<!-- <td class="text-left"><a href="">{{$list['vendor_name']['name']??'0'}}</a></td> -->
					<td class="text-left"><a href="{{url('outwards_list')}}?id={{$list['invoice_number']}}&&jilla_id={{$list['jilla_id']}}">{{$list['invoice_number']??'0'}}</a></td>
					<td>{{$list['maker_name']??'0'}}</td>						
					<td>{{$list['18w']??'0'}}</td>
					<td>{{$list['35w']??'0'}}</td>
					<td>{{$list['70w']??'0'}}</td>
					<td>{{$list['110w']??'0'}}</td>
					<td>{{$list['190w']??'0'}}</td>
				<td><b>{{$counts??'0'}}</b></td>
				<td>{{$counts_buff_received??'0'}}</td>
				<td>{{$ex_buf_stock??'0'}}</td>
					 <td>{{$list['remarks']??''}}</td>
                </tr>
                <?php 
					$tw1=$list['18w']+$tw1;
					$tw2=$list['35w']+$tw2;
					$tw3=$list['70w']+$tw3;
					$tw4=$list['110w']+$tw4;
					$tw5=$list['190w']+$tw5;
					$tw6=$list['buffer_stk']+$tw6;
         

          $sum=$sum+$counts; 

         $buf=$buf+$counts_buff_received;
        $total_inclu_buf=$sum+$buf;
				?>                                
                @endforeach
                <tr>
                	<td></td>
					<td><b>Total</b></td>	
					<!-- <td></td> -->
						<td></td>
					<td><b>{{$tw1??'0'}}</b></td>
					<td><b>{{$tw2??'0'}}</b></td>
					<td><b>{{$tw3??'0'}}</b></td>
					<td><b>{{$tw4??'0'}}</b></td>
					<td><b>{{$tw5??'0'}}</b></td>
					   <td><b>{{$sum??'0'}}</b></td>
          <td><b>{{$buf??'0'}}</b></td>
          <td><b>{{$total_inclu_buf??'0'}}</b></td>
					<td></td>
				</tr>
			<!-- 	<tr>
					<td colspan="2"><b>Grand Total Without Bufferstock </b></td>
					<td colspan="8"><b>{{$excl_bufstk??'0'}}</b></td>
					 <td colspan="2"><b></b></td>
				</tr> -->
               
               </tbody>
            </table>
          </div>
          @endif
        </div>

       </section>
   </section>
 </div>
     @stop