<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="15" align="center">Lights&nbsp;</th>
                    <th class="heading" colspan="9" align="center">Arms&nbsp;Clamps&nbsp;Set</th>
                    <th class="heading" colspan="3" align="center">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="5" align="center">Supplied</th>
                    <td class="heading" colspan="5">Installed</td>
                     <td class="heading" colspan="5">Balance</td>

                     <th class="heading" colspan="3" align="center">Supplied</th>
                    <td class="heading" colspan="3">Installed</td>
                     <td class="heading" colspan="3">Balance</td>

                     <th class="heading" colspan="" align="center">Supplied</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">Mandals</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">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">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">Supplied</th>
                    <th rowspan="" class="sub-heading">Installed</th>
                    <th rowspan="" class="sub-heading">Balance</th>
                    
                </tr>
            </thead> 
            <tbody>

                 <?php $tw1=0;$tw2=0;$tw3=0;$tw4=0;$tw5=0; $sum=0; $i=0;?>
        @foreach($mandalwise_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 taluka_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 taluka_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 taluka_id=".$report->id);
                            $cable_used2_count=array_sum(array_column($cable_used2,'sum'));
                            
                        ?>  
                        @endforeach
                        <?php 

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

                            $cable_used2_count=array_sum(array_column($ccmstypes,'instal'));
                            $ccms_info = DB::select("SELECT ccms_ph_receive_quantity  
                                AS ccmsph
                                FROM subvendor_ccms where mandal_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 18w,rcv_qty_35w  
                                AS 35w,rcv_qty_70w AS 70w,rcv_qty_110w AS 110w,rcv_qty_190w AS 190w
                                FROM subvendor_lights  where mandal_id=".$report->id."".$query);

                            



                          $supplied_18w_count=array_sum(array_column($inward_info,'18w'));
                          $supplied_35w_count=array_sum(array_column($inward_info,'35w'));
                          $supplied_70w_count=array_sum(array_column($inward_info,'70w'));
                          $supplied_110w_count=array_sum(array_column($inward_info,'110w'));
                          $supplied_190w_count=array_sum(array_column($inward_info,'190w'));
                          $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 subvendor_armsclamps where mandal_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>{{$supplied_18w_count}}</td>
                            <td >{{$supplied_35w_count}}</td>
                            <td>{{$supplied_70w_count}}</td>
                            <td>{{$supplied_110w_count}}</td>
                            <td>{{$supplied_190w_count}}</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>{{$balance_18w_count}}</td>
                            <td>{{$balance_35w_count}}</td>
                            <td>{{$balance_70w_count}}</td>
                            <td>{{$balance_110w_count}}</td>
                            <td>{{$balance_190w_count}}</td>
                            <td>{{$supplied_25_count}}</td>
                            <td>{{$supplied_32_count}}</td>
                            <td >{{$supplied_40_count}}</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>{{$balance_25_count}}</td>
                            <td>{{$balance_32_count}}</td>
                            <td>{{$balance_40_count}}</td>
                            <td>{{$supplied_ccms_count}}</td>
                            <td>{{$cable_used2_count}}</td>
                            <td>{{$blc_ccms_count}}</td>
                      </tr>
                      
                       @endforeach
                       
    
              </tbody>
 
        </table>
    </div>
</div>
</div>
</div>
</head>
<body>