<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>
        Survey Report
    </title>
        <!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
   <link rel="stylesheet" href="//code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css">
   <script src="https://code.jquery.com/ui/1.13.2/jquery-ui.js"></script> -->

   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

   
   <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
   <script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
   <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

   <style>
    body{
        font-family: 'Times New Roman';
    }
    @media print {
        @page {
            size: A3 landscape;
        }

        /*.head_class{
                    position: fixed;
                    }*/
        .print_action {
            display: none ;
        }
        .page-break {
            page-break-after: always !important;
        }
    }
    .btn-primary,
    .btn-primary:hover {
        background-color: #008cba;
        border-color: #008cba;
    }

    /*button#dashboard {
                background-color: #008CBA;;
                padding:10px 24px;
                border:none;
                font-weight: bold;
                margin-top : 10px;
            }
            

            button#print {
                margin-top:-53px;
                margin-left: 180px;
                background-color: #008CBA;;
                padding:10px 24px;
                border:none;
                text-decoration:none;
                color:white;
                cursor:pointer;
                font-weight: bold;
                }*/

    .vertical-text {
        writing-mode: vertical-lr;
        /*transform: rotate(-180deg);*/
    }

    table {
        height: 300px;
        border-collapse: collapse;
        text-align: center;
    }

    .text-uppercase {
        text-transform: uppercase;
    }
    .heading {
        font-size: 20px;
        color: #000;
        font-weight: bold;
    }
    .sub-heading {
        font-size: 18px;
        color: #000;
        font-weight: bold;
    }
    .table td,
    .table th {
        padding: 4px;
    }
    .table td {
        vertical-align: middle;
         font-family: 'Times New Roman';
    }
    .table td,
    .table th {
        border-top: 1px solid #000;
         font-family: 'Times New Roman';
    }
    .table-bordered thead td,
    .table-bordered thead th {
        border-bottom-width: 1px;
    }
    .table-bordered td,
    .table-bordered th {
        border: 1px solid #000000;
    }
    .table thead th {
        border-bottom: 1px solid #000 !important;
    }
    *,
    ::after,
    ::before {
        box-sizing: content-box !important;
    }
    .row.px-3.pt-4.model *, .modal-dialog.modal-lg *{
      box-sizing: border-box !important;
    }
    .row.px-3.pt-4.model::before, .modal-dialog.modal-lg::before{
      box-sizing: border-box !important;
    }
    .row.px-3.pt-4.model::after, .modal-dialog.modal-lg::after{
      box-sizing: border-box !important;
    }

    .table tbody+tbody {
        border-top: 1px solid #000000;
    }
    .table td:last-child { 
        border-right: 1px solid #000 !important; 
    }
/*    .row px-3 pt-4 .model::after, .row px-3 pt-4 .model::before{
        box-sizing: border-box !important;
    }*/
</style>
<div class="container-fluid">
<div class="row ">
            <div class="col-6 my-3">
            
               <button class="btn btn-primary print_action" id="dashboard"><a href="{{url('/index')}}" style="text-decoration:none;color:white;">Back To Dashboard</a></button>
              </div>     
</div>
<div class="row ">
<div class="col-12">
    <div>
        <table class="table" border="1">
            <thead>
                <!-- Row 1 -->
                <tr class="table-primary">
                    <td class="text-center heading head_class" colspan="29">TSREDCO&nbsp;-&nbsp;MATERIAL&nbsp; STOCK&nbsp;REGISTER</td>
                </tr>

                <!-- Row 2 -->
                <tr class="table-success ">
                   
                    <th></th>
                     <th></th>
                    <th class="heading"  colspan="17">Lights&nbsp;</th>
                    <th class="heading" colspan="9">Arms&nbsp;Clamps&nbsp;Set</th>
                    <th class="heading" colspan="3">CCMS&nbsp;(1-PH&nbsp;&&nbsp3-PH)</th>
                </tr>

                <!-- Row 3 -->
                <tr class="table-warning">

                    <td colspan=""></td>
                     <td colspan=""></td>
                    <th class="heading" colspan="6" align="center">Received&nbsp;Quantity</th>
                    <td class="heading" colspan="6">Installed</td>
                     <td class="heading" colspan="5">Balance</td>

                     <th class="heading" colspan="3" align="center">Received&nbsp;Quantity</th>
                    <td class="heading" colspan="3">Installed</td>
                     <td class="heading" colspan="3">Balance</td>

                     <th class="heading" colspan="" align="center">Received&nbsp;Quantity</th>
                    <td class="heading" colspan="">Installed</td>
                     <td class="heading" colspan="">Balance</td>

                </tr>
                <tr class="table-danger">
                   
                    <th rowspan="" class="sub-heading">S.no</th>
                    <th rowspan="" class="sub-heading">Districts</th>
                    <th rowspan="" class="sub-heading">18w</th>
                    <th rowspan="" class="sub-heading">35w</th>
                    <th rowspan="" class="sub-heading">70w</th>
                    <th rowspan="" class="sub-heading">110w</th>
                    <th rowspan="" class="sub-heading">190w</th>
                    <th rowspan="" class="sub-heading">Total</th>

                    <th rowspan="" class="sub-heading">18w</th>
                    <th rowspan="" class="sub-heading">35w</th>
                    <th rowspan="" class="sub-heading">70w</th>
                    <th rowspan="" class="sub-heading">110w</th>
                    <th rowspan="" class="sub-heading">190w</th>
                    <th rowspan="" class="sub-heading">Total</th>

                    <th rowspan="" class="sub-heading">18w</th>
                    <th rowspan="" class="sub-heading">35w</th>
                    <th rowspan="" class="sub-heading">70w</th>
                    <th rowspan="" class="sub-heading">110w</th>
                    <th rowspan="" class="sub-heading">190w</th>
                    
                     <th rowspan="" class="sub-heading">25mm Arms & clamps set</th>
                    <th rowspan="" class="sub-heading">32mm Arms & clamps set</th>
                    <th rowspan="" class="sub-heading">40mm Arms & clamps set</th>

                    <th rowspan="" class="sub-heading">25mm Arms & clamps set</th>
                    <th rowspan="" class="sub-heading">32mm Arms & clamps set</th>
                    <th rowspan="" class="sub-heading">40mm Arms & clamps set</th>

                    <th rowspan="" class="sub-heading">25mm Arms & clamps set</th>
                    <th rowspan="" class="sub-heading">32mm Arms & clamps set</th>
                    <th rowspan="" class="sub-heading">40mm Arms & clamps set</th>
                    
                    <th rowspan="" class="sub-heading">Received&nbsp;Quantity</th>
                    <th rowspan="" class="sub-heading">Installed</th>
                    <th rowspan="" class="sub-heading">Balance</th>
                    
                </tr>
            </thead> 
            <tbody>

                 <?php $ts1=0;$ts2=0;$ts3=0;$ts4=0;$ts5=0; 
                      $tw1=0;$tw2=0;$tw3=0;$tw4=0;$tw5=0;
                      $tb1=0;$tb2=0;$tb3=0;$tb4=0;$tb5=0;
                      $tas1=0;$tas2=0;$tas3=0;$tas4=0;$tas5=0;
                      $ta1=0;$ta2=0;$ta3=0;
                      $tba1=0;$tba2=0;$tba3=0;
                      $tsc1=0;$tsc2=0;$tsc3=0;


                      $sum=0; $sum1=0; $i=0;?>
        @foreach($districtwise_report as $report)
        <?php  
                $list=[]; $i++;  $arms=["18 W","35 W","70 W","110 W","190 W"];
               
        ?>
                        @foreach($arms as $value) 
                        <?php $counts= DB::select("SELECT LED_wattage,    
                            ROUND (
                                (
                                    LENGTH(LED_wattage)
                                    - LENGTH( REPLACE ( LED_wattage, '".$value."', '') ) 
                                ) / LENGTH('".$value."')
                            ) AS count    
                            FROM survey_infos where jilla_id=".$report->id);
                        
                         $count=array_sum(array_column($counts,'count'));
                         $list[]=$count;
                        ?>
                        @endforeach

                        <?php $arm_list=[];  $sumofarm=0; $arms=["25mm","32mm","40mm"]?>
                         @foreach($arms as $value) 
                        <?php $arm_counts= DB::select("SELECT types_of_arms,    
                            ROUND (
                                (
                                LENGTH(types_of_arms)
                                - LENGTH( REPLACE ( types_of_arms, '".$value."', '') ) 
                                ) / LENGTH('".$value."')        
                            ) AS count    
                            FROM survey_infos where jilla_id=".$report->id);
                        
                            $arm_count=array_sum(array_column($arm_counts,'count'));
                            $arm_list[]=$arm_count;

                            $cable_used2 = DB::select("SELECT cable_user  
                                AS sum    
                                FROM survey_infos where jilla_id=".$report->id);
                            $cable_used2_count=array_sum(array_column($cable_used2,'sum'));
                            
                        ?>  
                        @endforeach
                        <?php 

                        $query="";
         // if($request->session()->get('role')==6){
         //    $query=" AND vendor_id=".$request->session()->get('id');
         // }
         
                        $ccmstypes = DB::select("SELECT install_qty AS instal,supply_qty AS supply FROM ccms_types where district_id=".$report->id);

                            $cable_used2_count=array_sum(array_column($ccmstypes,'instal'));
                            $ccms_info = DB::select("SELECT ccms_ph_receive_quantity  
                                AS ccmsph
                                FROM inwardccmstypes where jilla_id=".$report->id."".$query);
                            $supplied_ccms_count=array_sum(array_column($ccms_info,'ccmsph'));
                            $blc_ccms_count=$supplied_ccms_count-$cable_used2_count;

 
    
                          $inward_info = DB::select("SELECT rcv_qty_18w  
                                AS r18w,rcv_qty_35w  
                                AS r35w,rcv_qty_70w AS r70w,rcv_qty_110w AS r110w,rcv_qty_190w AS r190w
                                FROM inwards  where jilla_id=".$report->id."".$query);

                          $supplied_18w_count=array_sum(array_column($inward_info,'r18w'));
                          $supplied_35w_count=array_sum(array_column($inward_info,'r35w'));
                          $supplied_70w_count=array_sum(array_column($inward_info,'r70w'));
                          $supplied_110w_count=array_sum(array_column($inward_info,'r110w'));
                          $supplied_190w_count=array_sum(array_column($inward_info,'r190w'));
                          $balance_18w_count=$supplied_18w_count-$list[0];
                          $balance_35w_count=$supplied_35w_count-$list[1];
                          $balance_70w_count=$supplied_70w_count-$list[2];
                          $balance_110w_count=$supplied_110w_count-$list[3];
                          $balance_190w_count=$supplied_190w_count-$list[4];


                           $armsclamps_info = DB::select("SELECT received_arms_dia_inner_32  
                                AS arms_32,received_arms_dia_inner_40  
                                AS arms_40,received_arms_dia_25 AS arms_25
                                FROM armsclamps where jilla_id=".$report->id."".$query);

                        $supplied_25_count=array_sum(array_column($armsclamps_info,'arms_25'));
                        $supplied_32_count=array_sum(array_column($armsclamps_info,'arms_32'));
                        $supplied_40_count=array_sum(array_column($armsclamps_info,'arms_40'));
                    
                          $balance_25_count=$supplied_25_count-$arm_list[0];
                          $balance_32_count=$supplied_32_count-$arm_list[1];
                          $balance_40_count=$supplied_40_count-$arm_list[2];

                            


                            ?>
                        <tr>
                           
                            <td>{{$i}}</td>
                            <td>{{$report->area_name}}</td>
                            <td><?php $s1=isset($supplied_18w_count)?$supplied_18w_count:0?>{{$s1}}</td>
                            <td ><?php $s2=isset($supplied_35w_count)?$supplied_35w_count:0?>{{$s2}}</td>
                            <td><?php $s3=isset($supplied_70w_count)?$supplied_70w_count:0?>{{$s3}}</td>
                            <td><?php $s4=isset($supplied_110w_count)?$supplied_110w_count:0?>{{$s4}}</td>
                            <td><?php $s5=isset($supplied_190w_count)?$supplied_190w_count:0?>{{$s5}}</td>
                            <td><?php $counts=$s1+$s2+$s3+$s4+$s5;?>{{$counts}}</td>
                            <td><?php $w1=isset($list[0])?$list[0]:0?>{{$w1}}</td>
                            <td><?php $w2=isset($list[1])?$list[1]:0?>{{$w2}}</td>
                            <td><?php $w3=isset($list[2])?$list[2]:0?>{{$w3}}</td>
                            <td><?php $w4=isset($list[3])?$list[3]:0?>{{$w4}}</td>
                            <td><?php $w5=isset($list[4])?$list[4]:0?>{{$w5}}</td>
                            <td><?php $installed_counts=$w1+$w2+$w3+$w4+$w5;?>{{$installed_counts}}</td>
                            <td><?php $b1=isset($balance_18w_count)?$balance_18w_count:0?>{{$b1}}</td>
                            <td><?php $b2=isset($balance_35w_count)?$balance_35w_count:0?>{{$b2}}</td>
                            <td><?php $b3=isset($balance_70w_count)?$balance_70w_count:0?>{{$b3}}</td>
                            <td><?php $b4=isset($balance_110w_count)?$balance_110w_count:0?>{{$b4}}</td>
                            <td><?php $b5=isset($balance_190w_count)?$balance_190w_count:0?>{{$b5}}</td>
                            <td><?php $as1=isset($supplied_25_count)?$supplied_25_count:0?>{{$as1}}</td>
                            <td><?php $as2=isset($supplied_32_count)?$supplied_32_count:0?>{{$as2}}</td>
                            <td ><?php $as3=isset($supplied_40_count)?$supplied_40_count:0?>{{$as3}}</td>
                            <td><?php $a1=isset($arm_list[0])?$arm_list[0]:0?>{{$a1}}</td>
                            <td><?php $a2=isset($arm_list[1])?$arm_list[1]:0?>{{$a2}}</td>
                            <td><?php $a3=isset($arm_list[2])?$arm_list[2]:0?>{{$a3}}</td>
                            <td><?php $ab1=isset($balance_25_count)?$balance_25_count:0?>{{$ab1}}</td>
                            <td><?php $ab2=isset($balance_32_count)?$balance_32_count:0?>{{$ab2}}</td>
                            <td><?php $ab3=isset($balance_40_count)?$balance_40_count:0?>{{$ab3}}</td>
                            <td><?php $cs1=isset($supplied_ccms_count)?$supplied_ccms_count:0?>{{$cs1}}</td>
                            <td><?php $cs2=isset($cable_used2_count)?$cable_used2_count:0?>{{$cs2}}</td>
                            <td><?php $cs3=isset($blc_ccms_count)?$blc_ccms_count:0?>{{$cs3}}</td>
                      </tr>
                      <?php
                                $ts1=$s1+$ts1;
                                $ts2=$s2+$ts2;
                                $ts3=$s3+$ts3;
                                $ts4=$s4+$ts4;
                                $ts5=$s5+$ts5;
                                $sum = $ts1+$ts2+$ts3+$ts4+$ts5;
                                  
                                $tw1=$w1+$tw1;
                                $tw2=$w2+$tw2;
                                $tw3=$w3+$tw3;
                                $tw4=$w4+$tw4;
                                $tw5=$w5+$tw5;
                                $sum1 = $tw1+$tw2+$tw3+$tw4+$tw5;

                                $tb1=$b1+$tb1;
                                $tb2=$b2+$tb2;
                                $tb3=$b3+$tb3;
                                $tb4=$b4+$tb4;
                                $tb5=$b5+$tb5;

                               $tas1=$as1+$tas1;
                                $tas2=$as2+$tas2;
                                $tas3=$as3+$tas3;

                                 $ta1=$a1+$ta1;
                                $ta2=$a2+$ta2;
                                $ta3=$a3+$ta3;
                                 $tba1=$ab1+$tba1;
                                $tba2=$ab2+$tba2;
                                $tba3=$ab3+$tba3;

                                 $tsc1=$cs1+$tsc1;
                                $tsc2=$cs2+$tsc2;
                                $tsc3=$cs3+$tsc3;


                       
                    
                       ?>

                       @endforeach

                       <tr>

                        <td></td>
                        <td><b>Total</b></td>
                        <td><b>{{$ts1}}</b></td>
                        <td><b>{{$ts2}}</b></td>
                        <td><b>{{$ts3}}</b></td>
                        <td><b>{{$ts4}}</b></td>
                        <td><b>{{$ts5}}</b></td>
                        <td><b>{{$sum}}</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>{{$sum1}}</b></td>
                        <td><b>{{$tb1}}</b></td>
                         <td><b>{{$tb2}}</b></td>
                        <td><b>{{$tb3}}</b></td>
                        <td><b>{{$tb4}}</b></td>
                         <td><b>{{$tb5}}</b></td>
                        <td><b>{{$tas1}}</b></td>
                        <td><b>{{$tas2}}</b></td>
                        <td><b>{{$tas3}}</b></td>
                        <td><b>{{$ta1}}</b></td>
                        <td><b>{{$ta2}}</b></td>
                        <td><b>{{$ta3}}</b></td>
                        <td><b>{{$tba1}}</b></td>
                        <td><b>{{$tba2}}</b></td>
                        <td><b>{{$tba3}}</b></td>
                        <td><b>{{$tsc1}}</b></td>
                        <td><b>{{$tsc2}}</b></td>
                        <td><b>{{$tsc3}}</b></td>

                       </tr>
    
              </tbody>
 
        </table>
    </div>
</div>
</div>
                </div>
</head>
<body>