<?php $__env->startSection('title', 'Farmer Record Dashboard'); ?>
<?php $__env->startPush('css'); ?>
    <link href="<?php echo e(asset('admin/assets/plugins/datatables/plugins/bootstrap/dataTables.bootstrap4.min.css')); ?> " rel="stylesheet" type="text/css"/>
<?php $__env->stopPush(); ?>
<?php $__env->startSection('content'); ?>
    <div id="app">
        <div class="row">
            <div class="col-12">
                <h2 class="font-weight-bolder font-weight-bolder text-center"><b>
                        <?php echo e(env('COMPANY_NAME','QBYTESOFT')); ?> <span class="label label-rouded label-danger"><?php echo e(auth()->user()->branch->name); ?></span></b>
                </h2>
            </div>
        </div>
        <div class="row justify-content-center">
            <div class="col-md-3 justify-content-center">
                <div class="card">
                    <div class="card-head">
                        <header>Profile Picture</header>
                    </div>
                    <div class="card-body no-padding height-9">
                        <div class="patient-profile">
                            <img src="<?php echo e(asset('storage/farmer/').'/'.$farmer->image); ?>" class="img-responsive" alt="">
                        </div>
                    </div>
                </div>
                <div class="card">
                    <div class="card-head">
                        <header> Quick Links </header>
                    </div>
                    <div class="card-body">
                        <div class="">
                            <a href="<?php echo e(url('/farmer/'.$farmer->id.'/batch/create')); ?>" class="btn btn-success btn-lg btn-block">Create Batch</a>
                            <a href="<?php echo e(url('/farmer/'.$farmer->id.'/invoice')); ?>" class="btn btn-primary btn-lg btn-block">Farmer Invoice</a>
                        </div>
                    </div>
                </div>

            </div>
            <div class="col-md-6 justify-content-center">
                <div class="card">
                    <div class="card-body no-padding height-9">
                        <div class="profile-usertitle">
                            <div class="profile-usertitle-name"> Farmer Profile </div>
                        </div>
                        <ul class="list-group list-group-unbordered">
                            <li class="list-group-item">
                                <b>ID</b> <a class="pull-right"><?php echo e($farmer->id); ?></a>
                            </li>
                            <li class="list-group-item">
                                <b>Name</b> <a class="pull-right"><?php echo e($farmer->name); ?></a>
                            </li>
                            <li class="list-group-item">
                                <b>Phone</b> <a class="pull-right"><?php echo e($farmer->phone1 ?? $farmer->phone2); ?></a>
                            </li>
                            <li class="list-group-item">
                                <b>Address</b> <a class="pull-right"><?php echo e($farmer->address); ?></a>
                            </li>
                            <li class="list-group-item">
                                <b>Total Cost</b>
                                <a class="pull-right">
                                    <?php echo e(\App\Helpers\Farmers::totalCost($farmer->id)); ?>

                                </a>
                            </li>
                            <li class="list-group-item">
                                <b>Total Collection</b>
                                <a class="pull-right">
                                    <?php echo e(\App\Helpers\Farmers::totalCollection($farmer->id)); ?>

                                </a>
                            </li>
                            <li class="list-group-item">
                                <b>Total Return</b>
                                <a class="pull-right">
                                    <?php echo e(\App\Helpers\Farmers::totalReturn($farmer->id)); ?>

                                </a>
                            </li>
                            <li class="list-group-item">
                                <b>Current Balance</b>
                                <a class="pull-right">
                                    <?php echo e(\App\Helpers\Farmers::currentBalance($farmer->id)); ?>

                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="col-md-3 justify-content-center">
                <div class="card">
                    <div class="card-body no-padding height-9">

                        <div class="profile-usertitle">
                            <div class="profile-usertitle-name">
                                Round - <?php echo e($farmer->farmerbatches->where('status','active')->count()); ?>

                            </div>
                        </div>
                        <ul class="list-group list-group-unbordered">
                            <?php
                                $latestBatch = DB::table('farmer_batches')->where('farmer_id',$farmer->id)->where('status','active')->orderBy('id','desc')->first();
                                if (!empty($latestBatch))
                                {
                                    $startDate = \Carbon\Carbon::parse($latestBatch->created_at);
                                    $endDate = \Carbon\Carbon::now();
                                }
                            ?>
                            <li class="list-group-item">
                                Opening Date <a class="pull-right">
                                    <b>
                                        <?php echo e($latestBatch !== null ? date('M d, y', strtotime($latestBatch->created_at)) : 'No Batch'); ?>

                                    </b>
                                </a>
                            </li>

                            <li class="list-group-item">
                                Running Day
                                <?php if(!empty($latestBatch)): ?>
                                    <a class="pull-right p-r-20 mdl-color-text--green-600">
                                        <b>
                                            <?php if($startDate->diffInDays($endDate) !== 0): ?>
                                            <?php echo e($startDate->diffInDays($endDate) + 1); ?>

                                            <?php else: ?> 
                                                <span class="text--red-900">1</span>
                                            <?php endif; ?>
                                        </b>
                                    </a>
                                <?php endif; ?>
                            </li>
                            <li class="list-group-item">
                                Current Chicks
                                <?php if(!empty($latestBatch)): ?>
                                    <a class="pull-right p-r-20 mdl-color-text--red-900">
                                        <b>
                                            <?php echo e($latestBatch->chicks_quantity); ?>

                                        </b>
                                    </a>
                                <?php endif; ?>
                            </li>

                            <li class="list-group-item">
                                Price
                                <?php if(!empty($latestBatch)): ?>
                                    <a class="pull-right p-r-20 mdl-color-text--red-900">
                                        <b>
                                            <?php echo e(\App\Helpers\Farmers::currentChicksPrice($farmer->id)); ?>

                                        </b>
                                    </a>
                                <?php endif; ?>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="card">
                    <div class="card-head">
                        <header>
                            Quick Links
                        </header>
                    </div>
                    <div class="card-body">
                        <div class="">
                            <a class="btn blue btn-outline m-b-10 btn-lg btn-block" id="daily-reports-button">Daily Reports</a>
                            <a class="btn red btn-outline btn-lg btn-block">Report Summary</a>
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <div class="row" id="daily-reports">

            <div class="col-sm-2">
                <div class="panel">
                    <header class="panel-heading panel-heading-blue text-center">
                        <strong> চলতি বয়স</strong>
                    </header>
                    <div class="panel-body text-center">
                        <?php if(!empty($latestBatch)): ?>
                            <b>
                                <?php echo e(($startDate->diffInDays($endDate) !== 0 ?$startDate->diffInDays($endDate) + 1 : 1)); ?>

                            </b>
                        <?php else: ?>
                            <b>
                                0
                            </b>
                        <?php endif; ?>

                    </div>
                </div>
            </div>
            <div class="col-sm-2">
                <div class="panel">
                    <header class="panel-heading panel-heading-blue text-center">
                        <strong> আজকে মৃত </strong>
                    </header>
                    <div class="panel-body text-center">
                        <b><?php echo e(!empty($latestBatch) ? App\Helpers\Farmers::todayDied($farmer->id) : 0); ?></b>
                    </div>
                </div>
            </div>
            <div class="col-sm-2">
                <div class="panel">
                    <header class="panel-heading panel-heading-blue text-center">
                        <strong> মোট মৃত </strong>
                    </header>
                    <div class="panel-body text-center">
                        <b><?php echo e(!empty($latestBatch) ? App\Helpers\Farmers::totalDied($farmer->id) : 0); ?></b>
                    </div>
                </div>
            </div>
            <div class="col-sm-2">
                <div class="panel">
                    <header class="panel-heading panel-heading-blue text-center">
                        <b> মোট খাদ্য (ব্যাগ) </b>
                    </header>
                    <div class="panel-body text-center">
                        <b><?php echo e(!empty($latestBatch) ? App\Helpers\Farmers::totalPurchaseFeed($farmer->id, 'bag') : 0); ?> Bag</b>
                    </div>
                </div>
            </div>
            <div class="col-sm-2">
                <div class="panel">
                    <header class="panel-heading panel-heading-blue text-center">
                        <b>মোট খাদ্য (কেজি)</b>
                    </header>
                    <div class="panel-body text-center">
                        <b><?php echo e(!empty($latestBatch) ? App\Helpers\Farmers::totalPurchaseFeed($farmer->id, 'kg') : 0); ?> KG</b>
                    </div>
                </div>
            </div>
            <div class="col-sm-2">
                <div class="panel">
                    <header class="panel-heading panel-heading-blue text-center">
                        <strong>আজকে খাওয়া (কেজি)</strong>
                    </header>
                    <div class="panel-body text-center">
                        <b><?php echo e(!empty($latestBatch) ? App\Helpers\Farmers::todayEatFeed($farmer->id, 'kg') : 0); ?> Kg</b>
                    </div>
                </div>
            </div>
            <div class="col-sm-2">
                <div class="panel">
                    <header class="panel-heading panel-heading-blue text-center">
                        <strong>মোট খাওয়া (কেজি)</strong>
                    </header>
                    <div class="panel-body text-center">
                        <b><?php echo e(!empty($latestBatch) ? App\Helpers\Farmers::totalFeed($farmer->id, 'kg') : 0); ?> Kg</b>
                    </div>
                </div>
            </div>
            <div class="col-sm-2">
                <div class="panel">
                    <header  class="panel-heading panel-heading-blue text-center">
                        <strong>অবশিষ্ট খাদ্য (কেজি)</strong>
                    </header>
                    <div class="panel-body text-center">
                        <b><?php echo e(!empty($latestBatch) ? App\Helpers\Farmers::totalFeedLeft($farmer->id, 'kg') : 0); ?> Kg</b>
                    </div>
                </div>
            </div>
            <div class="col-sm-2">
                <div class="panel">
                    <header class="panel-heading panel-heading-blue text-center">
                        <strong> ওজন (প্রতি পিস) </strong>
                    </header>
                    <div class="panel-body text-center">
                        <b><?php echo e(!empty($latestBatch) ? App\Helpers\Farmers::totalWeight($farmer->id) : 0); ?> gm</b> (বর্তমান)
                    </div>
                </div>
            </div>
            <div class="col-sm-2">
                <div class="panel">
                    <header class="panel-heading panel-heading-blue text-center">
                        <strong> FCR </strong>
                    </header>
                    <div class="panel-body text-center">
                        <b><?php
                                $totalEatFeed = !empty($latestBatch) ? App\Helpers\Farmers::totalFeed($farmer->id, 'kg') : 0;
                                $totalWeight = !empty($latestBatch) ? App\Helpers\Farmers::totalWeight($farmer->id) : 0;
                                $totalChick = !empty($latestBatch) ? App\Helpers\Farmers::totalChickStock($farmer->id) : 0;
                                $totalDead = !empty($latestBatch) ? App\Helpers\Farmers::totalDied($farmer->id) : 0;
                                $totalChick -= $totalDead;                                
                                $fcr = 0;
                                if($totalEatFeed > 0 && $totalWeight > 0) {
                                    $fcr = ($totalEatFeed) / (($totalWeight * $totalChick) / 1000);
                                }
                            ?>
                            <?php echo e(number_format($fcr, 4)); ?>

                            </b> 
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-12">
                <div class="panel tab-border card-box">
                    <header class="panel-heading panel-heading-gray custom-tab ">
                        <ul class="nav nav-tabs">
                            <li class="nav-item">
                                <a href="#medicine" data-toggle="tab" class="active">Medicine</a>
                            </li>
                            <li class="nav-item">
                                <a href="#feed" data-toggle="tab">Feed</a>
                            </li>
                            <li class="nav-item">
                                <a href="#batch" data-toggle="tab">Batch Details</a>
                            </li>
                            <li class="nav-item">
                                <a href="#payments" data-toggle="tab">Payments Details</a>
                            </li>
                            <li class="nav-item">
                                <a href="#collections" data-toggle="tab">Collection Details</a>
                            </li>
                            <li class="nav-item">
                                <a href="#return" data-toggle="tab">Return Invoice</a>
                            </li>
                        </ul>
                    </header>
                    <div class="panel-body">
                        <div class="tab-content">
                            <div class="tab-pane active" id="medicine">
                                <div class="col-md-12">
                                    <div class="card">
                                        <div class="card-body " style="">
                                            <div class="table-scrollable">
                                                <?php if(!$farmerInvoices->isEmpty()): ?>
                                                    <table class="table">
                                                        <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Date</th>
                                                            <th>Medicine</th>
                                                            <th>Quantity</th>
                                                            <th>Cost</th>
                                                            <th>Memo No</th>
                                                            <th>Remarks</th>
                                                        </tr>
                                                        </thead>
                                                        <?php
                                                        $i =1;
                                                        $totalQuantity = 0;
                                                        $totalCost = 0;
                                                        ?>
                                                        <tbody>

                                                            <?php $__currentLoopData = $medicines; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $medicine): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <tr>
                                                                    <td><?php echo e($i++); ?></td>
                                                                    <td><?php echo e(\Carbon\Carbon::parse($medicine->date)->format('d-M-Y')); ?></td>
                                                                    <td><?php echo e($medicine->product_name); ?></td>
                                                                    <td><?php echo e($medicine->quantity); ?></td>
                                                                    <td><?php echo e($medicine->total_selling); ?></td>
                                                                    <td><?php echo e($medicine->receipt_no); ?></td>
                                                                    <td><?php echo e($medicine->remarks); ?></td>
                                                                </tr>
                                                                <?php
                                                                $totalQuantity += $medicine->quantity;
                                                                $totalCost += $medicine->total_selling;
                                                                ?>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                        </tbody>
                                                        <tfoot>
                                                        <tr>
                                                            <td colspan="3">
                                                                <b>Total Summary</b>
                                                            </td>
                                                            <td>
                                                                <b>
                                                                    <?php echo e($totalQuantity ?? 0); ?>

                                                                </b>
                                                            </td>
                                                            <td>
                                                                <b><?php echo e(number_format($totalCost,2,'.',',') ?? 0); ?></b>
                                                            </td>
                                                        </tr>
                                                        </tfoot>
                                                    </table>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="tab-pane " id="feed">
                                <div class="col-md-12">
                                    <div class="card">
                                        <div class="card-body " style="">
                                            <div class="table-scrollable">
                                                <?php if(!$farmerInvoices->isEmpty()): ?>
                                                    <table class="table">
                                                        <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Date</th>
                                                            <th>Feed</th>
                                                            <th>Quantity</th>
                                                            <th>Cost</th>
                                                            <th>Memo No</th>
                                                            <th>Remarks</th>
                                                        </tr>
                                                        </thead>
                                                        <?php
                                                        $i =1;
                                                        $totalQuantity = 0;
                                                        $totalCost = 0;
                                                        ?>
                                                        <tbody>
                                                            <?php $__currentLoopData = $feeds; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $feed): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <tr>
                                                                    <td><?php echo e($i++); ?></td>
                                                                    <td><?php echo e(\Carbon\Carbon::parse($feed->date)->format('d-M-Y')); ?></td>
                                                                    <td><?php echo e($feed->product_name); ?></td>
                                                                    <td><?php echo e($feed->quantity); ?></td>
                                                                    <td><?php echo e($feed->total_selling); ?></td>
                                                                    <td><?php echo e($feed->receipt_no); ?></td>
                                                                    <td><?php echo e($feed->remarks); ?></td>
                                                                </tr>
                                                                <?php
                                                                $totalQuantity += $feed->quantity;
                                                                $totalCost += $feed->total_selling;
                                                                ?>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                        </tbody>
                                                        <tfoot>
                                                        <tr>
                                                            <td colspan="3">
                                                                <b>Total Summary</b>
                                                            </td>
                                                            <td>
                                                                <b>
                                                                    <?php echo e($totalQuantity ?? 0); ?>

                                                                </b>
                                                            </td>
                                                            <td>
                                                                <b><?php echo e(number_format($totalCost,2,'.',',') ?? 0); ?></b>
                                                            </td>
                                                        </tr>
                                                        </tfoot>
                                                    </table>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            
                            <div class="tab-pane" id="batch">
                                <div class="row">
                                    <div class="col-md-12 col-sm-12">
                                        <div class="card">
                                            <div class="card-head text-center">
                                                <header style="padding: 25px 0;">All BATCH RECORDS</header>
                                            </div>
                                            <div class="card-body" id="line-parent">
                                                <div class="panel-group accordion" id="accordion3">
                                                    <?php $__currentLoopData = $farmer->farmerbatches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $farmerBatch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <div class="panel panel-default" >
                                                            <div class="panel-heading panel-heading-gray">
                                                                <h4 class="panel-title">
                                                                    <a class="accordion-toggle accordion-toggle-styled collapsed" data-toggle="collapse" data-parent="#accordion3" href="#<?php echo e($farmerBatch->batch_number); ?>">

                                                                        

                                                                        Batch Name :  <span class="btn btn-<?php echo e(($farmerBatch->status=='active')?'success':'danger'); ?>"><?php echo e($farmerBatch->batch_name); ?></span> <span aria-hidden="true" class="icon-arrow-right "></span>
                                                                        Batch Number : <span class="btn btn-<?php echo e(($farmerBatch->status=='active')?'success':'danger'); ?>"><?php echo e($farmerBatch->batch_number); ?></span> <span aria-hidden="true" class="icon-arrow-right "></span>

                                                                        Status : <span class="btn btn-<?php echo e(($farmerBatch->status === 'active')?'success':'danger'); ?>"><?php echo e(($farmerBatch->status === 'active') ? 'Running' : 'Closed'); ?></span>



                                                                    </a>
                                                                    <?php if(auth()->user()->hasRole('superadmin')): ?>
                                                                    <span class="pull-right">
                                                <a class="text-primary" href="<?php echo e(url('/farmer/'.$farmer->id.'/batch/'.$farmerBatch->id.'/edit')); ?>">Edit</a> |
                                                <a class="text-danger" onclick="deleteFarmerBatch(<?php echo e($farmerBatch->id); ?>)" href="#">Delete</a>

                                                <form id="delete-form-<?php echo e($farmerBatch->id); ?>" action="<?php echo e(url('/farmer/'.$farmer->id.'/batch/'.$farmerBatch->id)); ?>" method="post" style="display:none;">
                                                    <?php echo csrf_field(); ?>
                                                    <?php echo method_field("DELETE"); ?>
                                                </form>
                                            </span>
                                            <?php endif; ?>

                                                                </h4>
                                                            </div>
                                                            <div id="<?php echo e($farmerBatch->batch_number); ?>" class="panel-collapse in collapse">
                                                                <br>

                                                                <div class="row justify-content-center">
                                                                    <div class="col-sm-6">
                                                                        <?php if($farmerBatch->status === 'active'): ?>
                                                                            
                                                                            <a data-toggle="modal" data-target="#farmerRecordForm" class="btn btn-info btn-lg m-b-10">Add Todays Record</a>
                                                                        <?php endif; ?>
                                                                        <?php if($farmerBatch->status === 'inactive'): ?>
                                                                            
                                                                            <a href="<?php echo e(route('admin.fcr.download.pdf', $farmerBatch->batch_number)); ?>" class="btn btn-primary btn-lg m-b-10">Download FCR</a>
                                                                            <a href="javascript:void(0)" onclick="printFcr('<?php echo e(route('admin.fcr.download.pdf', $farmerBatch->batch_number)); ?>')" class="btn btn-warning btn-lg m-b-10"><i class="fa fa-print"></i> Print FCR</a>
                                                                        <?php endif; ?>
                                                                    </div>
                                                                </div>

                                                                <div class="panel-body table-responsive">
                                                                    <table class="table table-bordered table-hover">
                                                                        <thead class="text-center">
                                                                        <tr>
                                                                            <th>
                                                                                <p style="font-size:17px; color:#A52A2A;"><b>Age</b></p>
                                                                            </th>
                                                                            <th>
                                                                                <p style="font-size:17px; color:#A52A2A;"><b>Died</b></p>
                                                                            </th>
                                                                            <th>
                                                                                <p style="font-size:17px; color:#A52A2A;"><b>Feed Eaten - kg</b></p>
                                                                            </th>
                                                                            <th>
                                                                                <p style="font-size:17px; color:#A52A2A;"><b>Feed Eaten - Sack</b></p>
                                                                            </th>
                                                                            <th>
                                                                                <p style="font-size:17px; color:#A52A2A;"><b>Feed left</b></p>
                                                                            </th>
                                                                            <th>
                                                                                <p style="font-size:17px; color:#A52A2A;"><b>Wieght</b></p>
                                                                            </th>
                                                                            <th>
                                                                                <p style="font-size:17px; color:#A52A2A;"><b>Sickness</b></p>
                                                                            </th>
                                                                            <th>
                                                                                <p style="font-size:17px; color:#A52A2A;"><b>Comments</b></p>
                                                                            </th>
                                                                        </tr>
                                                                        </thead>
                                                                        <tbody>
                                                                        <?php $__currentLoopData = \App\Helpers\Farmers::records($farmerBatch->batch_number); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $record): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                            <tr class="text-center">
                                                                                <td><?php echo e($record->age); ?></td>
                                                                                <td><?php echo e($record->child_death); ?></td>
                                                                                <td><?php echo e($record->feed_eaten_kg); ?></td>
                                                                                <td><?php echo e($record->feed_eaten_sack); ?> Sack</td>
                                                                                <td><?php echo e($record->feed_left); ?> Sack</td>
                                                                                <td><?php echo e($record->weight); ?></td>
                                                                                <td style="max-width: 150px;"><?php echo e($record->symtomp); ?></td>
                                                                                <td style="max-width: 250px;"><?php echo e($record->remarks); ?></td>
                                                                            </tr>
                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                        </tbody>
                                                                    </table>

                                                                </div>
                                                                <div class="fcr-calculation">
                                                                    <a href="<?php echo e(route('admin.farmer.fcr_calculate.page',$farmer->id)); ?>">
                                                                        <?php if($farmerBatch->status === 'active'): ?>
                                                                        <button class="btn btn-success">Generate FCR</button>
                                                                            <?php endif; ?>
                                                                    </a>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            
                            <div class="tab-pane" id="payments">
                                <div class="col-md-12">
                                    <div class="card">
                                        <div class="card-body " style="">
                                            <div class="table-scrollable">
                                                <?php if(!$payments->isEmpty() || $farmer->opening_balance > 0): ?>
                                                    <table class="table">
                                                        <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Date</th>
                                                            <th>Type</th>
                                                            <th>Amount</th>
                                                            <th>Remarks</th>
                                                        </tr>
                                                        </thead>
                                                        <?php
                                                        $serial =1;
                                                        ?>
                                                        <tbody>
                                                        <?php if($farmer->opening_balance > 0): ?>
                                                            <tr>
                                                                <td>-</td>
                                                                <td><?php echo e(\Carbon\Carbon::parse($farmer->starting_date)->format('d-M-Y')); ?></td>
                                                                <td>Opening Balance</td>
                                                                <td><?php echo e($farmer->opening_balance); ?></td>
                                                                <td>N/A</td>
                                                            </tr>
                                                        <?php endif; ?>

                                                        <?php $__currentLoopData = $payments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $payment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <tr>
                                                                <td><?php echo e($serial++); ?></td>
                                                                <td><?php echo e(\Carbon\Carbon::parse($payment->payment_date)->format('d-M-Y')); ?></td>
                                                                <td><?php echo e($payment->payment_type); ?></td>
                                                                <td><?php echo e($payment->payment_amount); ?></td>
                                                                <td><?php echo e($payment->remarks ?? 'N/A'); ?></td>
                                                            </tr>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                        </tbody>
                                                        <tfoot>
                                                        <tr>
                                                            <td colspan="4">
                                                                <b>Total Paid Amount</b>
                                                            </td>
                                                            <td>
                                                                <b><?php echo e(number_format($payments->sum('payment_amount') + ($farmer->opening_balance > 0 ? $farmer->opening_balance : 0), 2, '.', ',')); ?></b>
                                                            </td>
                                                        </tr>
                                                        </tfoot>
                                                    </table>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            
                            <div class="tab-pane" id="collections">
                                <div class="col-md-12">
                                    <div class="card">
                                        <div class="card-body " style="">
                                            <div class="table-scrollable">
                                                <?php if(!$collections->isEmpty()): ?>
                                                    <table class="table">
                                                        <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Date</th>
                                                            <th>Bank Name</th>
                                                            <th>Type</th>
                                                            <th>Amount</th>
                                                            <th>Remarks</th>
                                                        </tr>
                                                        </thead>
                                                        <?php
                                                        $serial =1;
                                                        ?>
                                                        <tbody>

                                                        <?php $__currentLoopData = $collections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $collection): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <tr>
                                                                <td><?php echo e($serial++); ?></td>
                                                                <td><?php echo e(\Carbon\Carbon::parse($collection->collection_date)->format('d-M-Y')); ?></td>
                                                                <td><?php echo e($collection->collection_type); ?></td>
                                                                <td><?php echo e($collection->collection_amount); ?></td>
                                                                <td><?php echo e($collection->remarks ?? 'N/A'); ?></td>
                                                            </tr>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                                        </tbody>
                                                        <tfoot>
                                                        <tr>
                                                            <td colspan="4">
                                                                <b>Total Collection Amount</b>
                                                            </td>
                                                            <td>
                                                                <b><?php echo e(number_format($collections->sum('collection_amount'),2,'.',',')); ?></b>
                                                            </td>
                                                        </tr>
                                                        </tfoot>
                                                    </table>
                                                <?php endif; ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            
                            <div class="tab-pane" id="return">
                                <div class="row">
                                    <div class="col-md-12 col-sm-12">
                                        <div class="card">
                                            <div class="card-body">
                                                <table class="table">
                                                    <thead>
                                                        <tr>
                                                            <th>#</th>
                                                            <th>Invoice</th>
                                                            <th>Product Name</th>
                                                            <th>Unit</th>
                                                            <th>Category</th>
                                                            <th>Unit Price</th>
                                                            <th>Qty</th>
                                                            <th>Total</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>
                                                        <?php $__empty_1 = true; $__currentLoopData = $farmerReturnInvoiceItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                                            <tr>
                                                                <td><?php echo e($loop->iteration); ?></td>
                                                                <td><?php echo e($item->farmerReturnInvoice->invoice_no); ?></td>
                                                                <td><?php echo e($item->product->product_name); ?></td>
                                                                <td><?php echo e($item->product->unit->name); ?></td>
                                                                <td><?php echo e($item->product->subcategory->category->name); ?></td>
                                                                <td><?php echo e($item->unit_price); ?></td>
                                                                <td><?php echo e($item->qty); ?></td>
                                                                <td><?php echo e($item->total); ?></td>
                                                            </tr>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                                            <tr>
                                                                <td class="text-center" colspan="6">No Data Found!</td>
                                                            </tr>
                                                        <?php endif; ?>
                                                    </tbody>
                                                </table>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php echo $__env->make('admin.modals.farmers.daily-record', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <?php echo csrf_field(); ?>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startPush('js'); ?>
<script src="<?php echo e(asset('admin/assets/plugins/datatables/jquery.dataTables.min.js')); ?>"></script>
<script src="<?php echo e(asset('admin/assets/plugins/datatables/plugins/bootstrap/dataTables.bootstrap4.min.js')); ?>" ></script>
<script src="<?php echo e(asset('admin/assets/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js')); ?>"  charset="UTF-8"></script>
<script src="<?php echo e(asset('admin/assets/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker-init.js')); ?>"  charset="UTF-8"></script>
<script src="<?php echo e(asset('admin/assets/js/sweetalert.min.js')); ?>"></script>
<script type="text/javascript">
    function deleteFarmerBatch(id) {
        const swalWithBootstrapButtons = Swal.mixin({
            customClass: {
                confirmButton: 'btn btn-success',
                cancelButton: 'btn btn-danger'
            },
            buttonsStyling: false,
        })
        swalWithBootstrapButtons.fire({
            title: 'Are you sure?',
            text: "You won't be able to revert this!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonText: 'Yes, delete it!',
            cancelButtonText: 'No, cancel!',
            reverseButtons: true
        }).then((result) => {
            if (result.value) {
                event.preventDefault();
                document.getElementById("delete-form-"+id).submit();
            } else if ( result.dismiss === Swal.DismissReason.cancel ) {
                swalWithBootstrapButtons.fire(
                    'Cancelled',
                    'Your Farmer Batch is safe :)',
                    'error'
                )
            }
        })
    }
</script>

<script src="<?php echo e(asset('js/daily-record-form.js')); ?>"></script>
<script>
    $(document).ready(function () {
        $("#daily-reports").hide();
        $("#daily-reports-button").click(function () {
            $("#daily-reports").toggle('slow');
        });
    })

    function printFcr(url) {
        // Open the PDF in a new window/iframe
        var printWindow = window.open(url, '_blank');
        
        // Wait for it to load then print
        printWindow.onload = function() {
            setTimeout(function() {
                printWindow.print();
            }, 1000);
        };
    }
</script>

<?php $__env->stopPush(); ?>
<?php echo $__env->make('template.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/forazitradersbd/public_html/resources/views/admin/farmer/view.blade.php ENDPATH**/ ?>