

<?php $__env->startSection('title'); ?>

    <?php if($block == 'summary'): ?>
        SUMMARY OF BOOKING, RECOVERY AND RECEIVABLES&nbsp;&nbsp; From
        <?php echo e(date('d/m/Y', strtotime($from_date))); ?>&nbsp;&nbsp;To&nbsp;&nbsp;<?php echo e(date('d/m/Y', strtotime($to_date))); ?>

    <?php else: ?>
        Account Statement & Recovery Sheet &nbsp;&nbsp;&nbsp;&nbsp; From
        <?php echo e(date('d/m/Y', strtotime($from_date))); ?>&nbsp;&nbsp;To&nbsp;&nbsp;<?php echo e(date('d/m/Y', strtotime($to_date))); ?>

    <?php endif; ?>

<?php $__env->stopSection(); ?>

<?php $__env->startSection('css'); ?>
    <style type="text/css" media="print">
        @page  {
            size: landscape;
        }
    </style>
    <style>
        .us_table_bdr>td,
        .us_table_bdr>th,
        .us_table_bdr>td,
        .us_table_bdr>th {
            border: 1px solid black !important;
        }
    </style>
    <!-- <link href="https://cdn.datatables.net/1.10.24/css/jquery.dataTables.min.css" rel="stylesheet"> -->
    <link href="https://cdn.datatables.net/buttons/1.7.0/css/buttons.dataTables.min.css" rel="stylesheet">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('breadcrumb'); ?>
    <ol class="breadcrumb pull-right no-print">
        <li><a href="<?php echo e(route('home')); ?>"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Account Statement</li>
    </ol>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <div class="container-fluid">
        <div class="row ">
            <div class="col-lg-12  ">
                <div class="white-box">
                    <div class="text-center">
                       
                        <h3><strong>


                                <?php $__currentLoopData = $project_names; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $project_name): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php echo e($project_name); ?>

                                    <?php if($key < count($project_names) - 1): ?>
                                        ,
                                    <?php endif; ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


                            </strong></h3>
                        <h4><strong>Account Statement & Recovery Sheet</strong></h4>
                    </div>
                    <div class="pull-left">
                        <span>Recovery Sheet(Due, Received & OS As On)</span>
                        <br>
                        <span><b>FROM&nbsp;&nbsp;<?php echo e(date('d/m/Y', strtotime($from_date))); ?>&nbsp;&nbsp;To&nbsp;&nbsp;<?php echo e(date('d/m/Y', strtotime($to_date))); ?></b></span>
                    </div>
                    <div class="pull-right" style="margin-bottom:2rem; padding-right:3rem;">
                        <span>Date: <b><?php echo e(date('d/m/Y')); ?></b></span>
                        <br>
                        <!--<span>Report No: &nbsp;202030</span><br>-->
                        <span>User ID: &nbsp; <?php echo e(Auth::user()->name); ?></span>
                    </div>
					<div style='  display: flex;
					justify-content: center;
					align-items: center;
					height: 300px;
					margin-top:60px;
					'>
					<canvas id="myChart"></canvas>
					</div>

                    <div class="table-responsive" style="clear: both;position: relative;bottom: 10rem; margin-top:200px;">
                        <div style="overflow-y: scroll;height: 565px;">
                           <?php
                           $gross_amount =0;
                           $discount_amount =0;
                           $extra_amount =0;
                           $total_amount=0;
                           $received_amount=0;
                           $outstanding_amount=0;
                           $over_due=0;
                           $grand_sum = [];
                           foreach ($period as $key => $dt) {
    $grand_sum[$key] = 0;
}
                           ?>
                            <table id="example1" class="table bdr table-responsive table-bordered"
                                 >
                                <thead>

                                  
                                    <tr class="us_table_bdr">
                                        
                                       
                                        <th class="text-center"><strong>Sr.</strong></th>
                                        <th class="text-center"><strong>Unit #</strong></th>
                                        <th class="text-center"><strong>Customer</strong></th>
                                        <th class="text-center"><strong>Unit Size</strong></th>
                                        <th class="text-center"><strong>Gross Price (PKR)</strong></th>
										
                                        <th class="text-center"><strong>Discount (PKR)</strong></th>
                                        <th class="text-center"><strong>Extra Amount (PKR)</strong></th>
                                        <th class="text-center"><strong>Total Amount (PKR)</strong></th>

                                        <th class="text-center"><strong>Received Amount (PKR)</strong></th>
                                        <th class="text-center"><strong>OutStanding (PKR)</strong></th>


                                        <th class="text-center"><strong>Overdues (PKR)</strong></th>

                                        <?php $__currentLoopData = $period; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $dt): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <th style="border-left:none;border-right:none;"> <?php echo e($dt->format('M Y')); ?></th>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tr>
                                </thead>
                                <tbody>
                                    

                                    <?php
                                   
                                    $serial_no = 1;
                                    $dataforcavas = [
										'due_amount' => [], // Initialize the first array
                                         'net_pay' => [],
                                         'received_amount'=>[],
										 'customer_name'=>[]
									]; 
									 
                                    $chart_rece_amount = [];
                                    $chart_net_amount = [];
                                    $chart_unit_no = [];
                                    ?>


                                    <?php $__currentLoopData = $required_properties; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr class="us_table_bdr">
                                            <th class="text-center"><?php echo e($serial_no++); ?></th>
											
                                            <th class="text-center">
                                            <?php
                                            $chart_unit_no[]=$p->inventory->unit_number;
                                            ?>    
                                                <?php echo e($p->inventory->unit_number); ?>

                                            </th>
											<th class="text-center"><?php echo e($p->customer->name); ?> -- <?php echo e($p->customer->cnic); ?></th>
											<th class="text-center"><?php echo e($p->inventory->size->name); ?>

											<?php if($p->inventory->multiProject->project_type_id == \App\ProjectType::high_rise): ?>
                                            <?php echo e(\App\ProjectType::high_rise_size); ?>

											<?php elseif($p->inventory->multiProject->project_type_id == \App\ProjectType::society): ?>
                                             <?php echo e(\App\ProjectType::society_size); ?>

											<?php endif; ?>
											</th>
                                          
											<th class="text-center">
                                                <?php
                                                  $gross_amount =   $gross_amount +$p->inventory->total_price;
                                                ?>
                                                <?php echo e(number_format($p->inventory->total_price)); ?>

                                            
                                            </th>
											<th class="text-center">
                                                <?php
                                                $discount_amount =   $discount_amount + $p->discount;
                                              ?>
                                                <?php echo e(number_format($p->discount)); ?></th>
											<th class="text-center">
                                                <?php
                                                $extra_amount =   $extra_amount + $p->extra_amount;
                                              ?>
                                                <?php echo e(number_format($p->extra_amount)); ?>

                                            
                                            </th>
											<th class="text-center"> 
                                                <?php
                                                $total_amount =   $total_amount + $p->net_pay;
                                           
                                              
                                    $chart_net_amount[] = $p->net_pay;
                                           ?>
                                                <?php echo e(number_format($p->net_pay)); ?>

                                            </th>
                                          
											<th class="text-center">
                                                <?php
                                                $received_amount =   $received_amount +$receivedAmt[$p->id];
                                          
                                                $chart_rece_amount[] = $receivedAmt[$p->id];
                                          ?>
                                                <?php echo e(number_format($receivedAmt[$p->id])); ?>

                                              
                                                <?php
                                                    $receivedamt_percentage = ($receivedAmt[$p->id] / $p->net_pay) * 100;
                                                ?>

                                                (<?php echo e(number_format($receivedamt_percentage,0)); ?> %)
                                            </th>

											<?php
								          	$outstanding =	$p->net_pay - $receivedAmt[$p->id];
											 
											?>

                                               

											<th class="text-center">
                                                <?php
                                                $outstanding_amount =   $outstanding_amount +$outstanding;
                                              ?>
                                                <?php echo e(number_format($outstanding)); ?>

                                            
                                            
                                                <?php
                                                $outstanding_percentage = ($outstanding / $p->net_pay) * 100;
                                            ?>

                                            (<?php echo e(number_format( $outstanding_percentage,0)); ?> %)
                                            </th>

											<th class="text-center">
                                                <?php
                                                $over_due =   $over_due +$overDueAmt[$p->id];
                                              ?>
                                               
                                                <?php echo e(number_format($overDueAmt[$p->id])); ?>

                                            
                                                <?php
                                                $overDueAmt_percent = ($overDueAmt[$p->id] / $p->net_pay) * 100;
                                            ?>

                                            (<?php echo e(number_format($overDueAmt_percent,0)); ?> %)
                                            </th>

                                           <?php
										    $due_ammount_data_array = [];
											$net_pay=[];
											$customer_name =[];
                                          

										   ?>
                                           
                                            <?php $__currentLoopData = $period; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $dt): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <th style="border-left:none;border-right:none;"  class="text-right">
												<?php
												
												$sumAmount = 0;
										 
												$statements = $p->statement->filter(function ($statement) use ($dt) {
                                                    return (new DateTime($statement->due_date))->format('Y-m') == $dt->format('Y-m');
                                                              });                             
												 
													$sumAmount += $statements->sum('due');
													$due_ammount_data_array[] =$sumAmount;
													if($sumAmount > 0){
													$customer_name[]= $p->customer->name;
													}
													$net_pay[]=$p->net_pay;
											    ?>
											 
											<span class="text-right">
                                            <?php
                                             $grand_sum[$key] =   $grand_sum[$key] + $sumAmount;
                                            ?>
                                                <?php echo e(number_format($sumAmount)); ?>


                                                <?php
                                                $sumAmount_percent = ($sumAmount / $p->net_pay) * 100;
                                            ?>

                                            (<?php echo e(number_format(  $sumAmount_percent,0)); ?> %)
                                            
                                            </span>
                                                   </th>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
											<?php
                                          
											$dataforcavas['due_amount'][] = $due_ammount_data_array;
											$dataforcavas['net_pay' ][] = $net_pay;
                                            $dataforcavas['received_amount'][] = $receivedAmt[$p->id];
                                            
											$dataforcavas['customer_name' ][] = $customer_name;
											?>
                                        </tr>

                                       
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                     
                                   

                                </tbody>
                               
                              
                                 
                                    <tr class="us_table_bdr">
										<td class="text-left" style="border-right: none;border-top: 1px solid;border-bottom: 1px solid;">Grand Total</td>
										<td style="border-right: none;border-left: none;border-top: 1px solid;border-bottom: 1px solid;"><b> </b></td>
										<td style="border-right: none;border-left: none;border-top: 1px solid;border-bottom: 1px solid;"></td>
										<td style="border-right: none;border-left: none;border-top: 1px solid;border-bottom: 1px solid;"></td>
										<td style="border-right: none;border-left: none;border-top: 1px solid;border-bottom: 1px solid;"><?php echo e(number_format($gross_amount)); ?></td>
										<td style="border-right: none;border-left: none;border-top: 1px solid;border-bottom: 1px solid;"><?php echo e(number_format(  $discount_amount)); ?></td>
										<td style="border-right: none;border-left: none;border-top: 1px solid;border-bottom: 1px solid;"><?php echo e(number_format($extra_amount)); ?></td>
										<td style="border-right: none;border-left: none;border-top: 1px solid;border-bottom: 1px solid;"><?php echo e(number_format( $total_amount)); ?></td>
										<td style="border-right: none;border-left: none;border-top: 1px solid;border-bottom: 1px solid;"><?php echo e(number_format($received_amount)); ?></td>
										 
                                        <td style="border-right: none;border-left: none;border-top: 1px solid;border-bottom: 1px solid;"><?php echo e(number_format($outstanding_amount)); ?></td>
										 
                                        <td style="border-right: none;border-left: none;border-top: 1px solid;border-bottom: 1px solid;"><?php echo e(number_format($over_due)); ?></td>
                                        <?php $__currentLoopData = $period; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $dt): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <th style="border-left:none;border-right:none;"  class="text-right">
                                     
                                            <?php echo e(number_format($grand_sum[$key])); ?>

                                        </th>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    
                            </table>
                        </div>
                        <a href="#" style="float: right; margin-top: 1rem;" onclick="openReminderModal2(this)"
                            class="btn btn-success" data-toggle="tooltip" data-original-title="Assign Units">
                            Assign&nbsp;&nbsp; <i class="fa fa-bell text-inverse m-r-10"></i> </a>
                    </div>
                </div>
            </div>
			<?php
 
$months = [];

foreach ($period as $date) {
    $months[] = $date->format('M Y');
}

?>


            <!-- /.container-fluid -->
            <div class="modal fade" id="exampleModal1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
                aria-hidden="true"> </div> <?php $__env->stopSection(); ?> <?php $__env->startSection('js'); ?>
            <script src="<?php echo e(asset('js/jquery.PrintArea.js')); ?>" type="text/JavaScript"></script>
            <!-- <script src="https://cdn.datatables.net/1.10.24/js/jquery.dataTables.min.js"></script> -->
            <script src="https://cdn.datatables.net/buttons/1.7.0/js/dataTables.buttons.min.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
            <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
            <script src="https://cdn.datatables.net/buttons/1.7.0/js/buttons.html5.min.js"></script>
            <script src="https://cdn.datatables.net/buttons/1.7.0/js/buttons.print.min.js"></script>
         
			<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
			<script>
      var chart_rece_amount=  <?php echo json_encode($chart_rece_amount, 15, 512) ?>;
   var chart_net_amount=   <?php echo json_encode($chart_net_amount, 15, 512) ?>;
   var chart_unit_no =<?php echo json_encode($chart_unit_no, 15, 512) ?>;


				 var months = <?php echo json_encode($months, 15, 512) ?>;
				 var due_data = <?php echo json_encode($dataforcavas, 15, 512) ?>;
				 var array1 = due_data.due_amount; // Access the first array
                 var array2 = due_data.net_pay;
                 var array4 = due_data.received_amount;
               
			  var array3 = due_data.customer_name;
				 
				 let datasets = [];
                 datasets.splice(0, datasets.length);
			for(var i =0;i < array1.length; i++ )
			{

               datasets.push(
				{
				label: array3[i],
                    data:  array1[i], 
					borderWidth: 1,
						fill: true,
						type: 'bar'
                  
					 
                }
				);
				
				 
			}
		  
			// console.log(chart_rece_amount);
            // console.log(chart_net_amount);

				// Example data
				const labels = months;
				 
			
				// Get the canvas element
				// const canvas = document.getElementById('myChart');
                const ctx = document.getElementById('myChart').getContext('2d');

// Sample data for total amounts and received amounts
const totalAmounts =  chart_net_amount;
const receivedAmounts =  chart_rece_amount;
 

// Create the chart
const lineChart = new Chart(ctx, {
  type: 'line',
  data: {
    labels: chart_unit_no,
    datasets: [
      {
        label: 'Total Amounts',
        data: totalAmounts,
        backgroundColor: 'rgba(75, 192, 192, 0.2)', // Adjust the color as needed
        borderColor: 'rgba(75, 192, 192, 1)', // Adjust the color as needed
        borderWidth: 1
      },
      {
        label: 'Received Amounts',
        data: receivedAmounts,
        backgroundColor: 'rgba(255, 99, 132, 0.2)', // Adjust the color as needed
        borderColor: 'rgba(255, 99, 132, 1)', // Adjust the color as needed
        borderWidth: 1
      }
    ]
  },
  options: {
    scales: {
      y: {
        beginAtZero: true
      }
    }
  }
});
			
			 
			  </script>
			 <script>
				 
		 
 



 

 



 



			 </script>
			
			  
		 <script>
                // A $( document ).ready() block.
                $(document).ready(function() {
                    $(".us_hack").each(function() {
                        $month = $(this).data("month");
                        $block = $(this).data("block");
                        $amount = $(this).data("amount");
                        $('#' + $block + '_' + $month).html($amount)
                    });
                    $(".us_grand_hack").each(function() {
                        $month = $(this).data("month");
                        $amount = $(this).data("amount");
                        $('#grand_' + $month).html($amount)
                    });
                    $('#example1').DataTable({
                        sorting: false,
                        paging: false,
                        ordering: false,
                        dom: 'Bfrtip',
                        buttons: ['copy', 'csv', 'excel', 'print', {
                            extend: 'pdfHtml5',
                            title: function() {
                                return "<?php echo e(env('APP_NAME')); ?>\nAccount Statement & Recovery Sheet";
                            },
                            orientation: 'landscape',
                            pageSize: 'A0', // You can also use "A1","A2" or "A3", most of the time "A3" works the best.
                            text: '<i class=""> PDF</i>',
                            titleAttr: 'PDF'
                        }]
                    });
                });
                $(function() {
                    $("#print").on("click", function() {
                        var mode = 'iframe'; //popup
                        var close = mode == "popup";
                        var options = {
                            mode: mode,
                            popClose: close
                        };
                        $("div.printableArea").printArea(options);
                    });
                });
            </script>
            <script>
                function openReminderModal(property_id) {
                    var data = {
                        'property_id': property_id
                    };
                    $.get('/update_chat_history', data, function(data) {
                        document.getElementById('exampleModal1').innerHTML = data;
                        $('#exampleModal1').modal();
                    });
                }

                function updateChat() {
                    var property_id = [];
                    $.each($(".chlid_checkbox:checked"), function() {
                        property_id.push(Number($(this).val()));
                    });
                    data = {
                        'property_id': property_id,
                        'remarks': $('#remarks').val(),
                        'next_follow_up': $('#next_follow_up').val(),
                        'status': $('#status').val(),
                        'user_assign': $('#user_assign').val()
                    };
                    $.get('/update_history', data, function(data) {
                        if (data.remarks || data.next_follow_up || data.status || data.user_assign) {
                            $("#remarks_eror").text(data.remarks);
                            $("#next_follow_up_error").text(data.next_follow_up);
                            $("#status_error").text(data.status);
                            $("#user_error").text(data.user_assign);
                        } else if (data.success == true) {
                            toastr.success(data.message);
                            $("#exampleModal1").click();
                        }
                    }, 'json');
                }

                function deleteFollowup(id) {
                    data = {
                        'id': id
                    };
                    $.get('/delete_followup', data, function(data) {
                        document.getElementById('exampleModal1').innerHTML = data;
                        toastr.success("Follow up Deleted Successfully.");
                    });
                }
                $(document).ready(function() {
                    $('#select_all').on('click', function() {
                        if (this.checked) {
                            $('.checkbox').each(function() {
                                this.checked = true;
                            });
                        } else {
                            $('.checkbox').each(function() {
                                this.checked = false;
                            });
                        }
                    });
                    $('.checkbox').on('click', function() {
                        if ($('.checkbox:checked').length == $('.checkbox').length) {
                            $('#select_all').prop('checked', true);
                        } else {
                            $('#select_all').prop('checked', false);
                        }
                    });
                });

                function openReminderModal2(self) {
                    var property_id = [];
                    $.each($(".chlid_checkbox:checked"), function() {
                        property_id.push(Number($(this).val()));
                    });
                    var data = {
                        'property_id': property_id
                    };
                    $.get('/update_chat_historyy', data, function(data) {
                        document.getElementById('exampleModal1').innerHTML = data;
                        $('#exampleModal1').modal();
                    });
                }
            </script>
        <?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/proje372/akram-city.projecterp.net/resources/views/report/account-statement.blade.php ENDPATH**/ ?>