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

<?php $__env->startPush('css'); ?>
    <!--select2-->
    <link href="<?php echo e(asset('admin/assets/plugins/select2/css/select2.css')); ?>" rel="stylesheet" type="text/css" />
    <link href="<?php echo e(asset('admin/assets/plugins/select2/css/select2-bootstrap.min.css')); ?>" rel="stylesheet" type="text/css" />
    <!-- date time -->
    <link href="<?php echo e(asset('admin/assets/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css')); ?> " rel="stylesheet" media="screen">
<?php $__env->stopPush(); ?>

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

    <div class="page-bar">
        <div class="page-title-breadcrumb">

        </div>
    </div>

    <div class="row">
        <div class="col-12">
            <div class="text-center">
                <div class="btn-group btn-group-solid">
                    <button type="button" class="btn btn-lg btn-success" id="invoice_button">Invoice</button>
                    <button type="button" class="btn  btn-lg btn-warning" id="payment_button">Payment</button>
                </div>
            </div>
        </div>
        
        <div class="col-12 payment">
            <div class="card card-box">
                <div class="card-head text-black" style="background-color:#3FCC7E;">
                    <header>Farmer Payment</header>
                </div>
                <div class="card-body">
                    <div class="row">
                        <?php echo Form::open(['route' => ['admin.payment.advance','id' => $farmer->id],'method' => 'POST']); ?>

                        <div class="row">
                            <div class="col-md-6 col-12">

                                
                                <div class="form-group">
                                    <label for="purpose_head">Select PurposeHead</label>
                                    <select name="purposehead_id" id="purpose_head" class="form-control select2" >
                                        <?php $__currentLoopData = $purposeheads; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $purposehead): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($purposehead->id); ?>"><?php echo e($purposehead->name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                
                                <div class="form-group">
                                    <label for="payment_amount">Payment Amount</label>
                                    <input type="text" name="payment_amount" class="form-control" id="payment_amount" value="<?php echo e(old('payment_amount')); ?>" autocomplete="off" required>
                                </div>
                                

                                <div class="form-group">
                                    <label for="reference">Reference / Bill / Receipt No</label>
                                    <input type="text" name="reference" class="form-control" id="reference" value="<?php echo e(old('reference')); ?>" autocomplete="off">
                                </div>


                            </div>

                            <div class="col-md-6 col-12">


                                <div class="form-group">
                                    <label for="simpleFormEmail">Received By</label>
                                    <input type="text" name="received_by" class="form-control" id="simpleFormEmail" value="<?php echo e(old('received_by')); ?>">
                                </div>



                                <div class="form-group">
                                    <label class="">Payment Date</label>
                                    <div class="input-group date form_date" data-date="<?php echo e(\Carbon\Carbon::now()); ?>" data-date-format="dd MM yyyy" data-link-field="dtp_input1">
                                        <input class="form-control" size="16" type="text" name="payment_date" value="<?php echo e(\Carbon\Carbon::now()->format('d M Y')); ?>">
                                        <span class="input-group-addon ml-2">
                                            <span class="fa fa-calendar"></span>
                                        </span>
                                    </div>
                                    <input type="hidden" id="dtp_input1" value="" />
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-12">
                                <?php echo Form::submit('Complete',['class' => 'btn btn-success pull-right']); ?>

                            </div>
                        </div>

                        <?php echo Form::close(); ?>

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

        
        <div class="col-12 invoice">
            <div class="card card-box">
                <div class="card-head text-white " style="background-color:#3FCC7E;">
                    <header>Farmer Invoice</header>
                </div>
                <div class="card-body" id="bar-parent">
                    <div class="row">
                        <div class="col-12">
                            <h3 class="text-center">
                                <?php echo e(env('COMPANY_NAME','QBYTESOFT')); ?>

                                <span class="label label-rouded label-danger"><?php echo e(auth()->user()->branch->name); ?></span>
                            </h3>
                        </div>
                    </div>
                    <?php echo Form::open(['url' => '/farmer/'.$farmer->id.'/invoice','method' => 'POST']); ?>

                    
                    <div class="row">
                        <div class="col-12 col-md-2 col-sm-4">
                            <div class="form-group">
                                <label for="invoice_id">Invoice No.</label>
                                <input type="text" class="form-control" value="<?php if($invoice): ?> <?php echo e($invoice->id + 1); ?> <?php else: ?> <?php echo e(1); ?> <?php endif; ?>" readonly>
                            </div>
                        </div>
                        <div class="col-12 col-md-2 col-sm-4">
                            <div class="form-group">
                                <label for="user_id">Employee Name</label>
                                <input type="text" id="user_id" class="form-control" value="<?php echo e(Auth::user()->name); ?>" readonly>
                                <input type="hidden" name="user_d" value="<?php echo e(Auth::user()->id); ?>">
                            </div>
                        </div>
                        <div class="col-12 col-sm-4 col-md-2">
                            <div class="form-group">
                                <label for="batch_number">Batch name</label>
                                <input type="text" id="batch_number" class="form-control" value="<?php echo e($farmer->farmerbatches->where('status','active')->first()->batch_name ?? 'N/A'); ?>" readonly>
                                <input type="hidden" name="batch_number" value="<?php echo e($farmer->farmerbatches->where('status','active')->first()->batch_number ?? 'N/A'); ?>">
                            </div>

                        </div>
                        <div class="col-12 col-sm-6 col-md-3">
                            <div class="form-group">

                                <label for="farmer_id">Farmer Name</label>
                                <input type="text" id="farmer_id" class="form-control" value="<?php echo e($farmer->name); ?>" readonly>
                                <input type="hidden" value="<?php echo e($farmer->id); ?>" name="farmer_id">
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-md-3">
                            <div class="form-group">
                                <label for="farmer_address">Farmer Address</label>
                                <input type="text" id="farmer_address" class="form-control" value="<?php echo e($farmer->address); ?>" readonly>
                            </div>
                        </div>

                        <div class="col-12 col-sm-6 col-md-3">
                            <div class="form-group">
                                <label class="">Bill Date</label>
                                <div class="input-group date form_date" data-date="<?php echo e(Carbon\Carbon::now()); ?>" data-date-format="dd MM yyyy" data-link-field="dtp_input1">
                                    <input class="form-control" size="16" type="text" name="sale_date" value="<?php echo e(Carbon\Carbon::now()->format('d M Y')); ?>">
                                    <span class="input-group-addon ml-2">
                                            <span class="fa fa-calendar"></span>
                                        </span>
                                </div>
                                <input type="hidden" id="dtp_input1" value="" />
                            </div>
                        </div>


                    </div>
                    
                    <div class="row">
                        <div class="offset-9"></div>
                        <div class="col-3">
                            <div class="form-group">
                                <?php echo Form::label('memo','Memo No'); ?>

                                <?php echo Form::text('memo',old('memo'),['class' => 'form-control','required']); ?>

                                <?php $__errorArgs = ["memo"];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <p class="text-danger p-0"><small><?php echo e($message); ?></small></p>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>
                    </div>
                    <div class="row p-t-20" ng-controller="ProductSearchController">
                        <!-- Product Search  -->
                        <div class="col-xs-12 col-3">
                            <div class="form-group">
                                <label>Product Search</label>
                                <input ng-model="search" class="form-control underlined">
                            </div>
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover">
                                    <tr ng-repeat="product in products  | filter: search | limitTo:10">
                                        <td width="80%">{{product.product_name}}</td>
                                        <td ><button class="btn btn-primary btn-xs" type="button" ng-click="addTempSale(product)"><span class="glyphicon glyphicon-share-alt" aria-hidden="true">&#x2705;</span></button></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                        <div class="col-9">
                            <div class="table-responsive">
                                <table class="table table-bordered">
                                    <tr>
                                        <th>Product name</th>
                                        <th>Size</th>
                                        <th>Stock</th>
                                        <th>Selling Price</th>                                        
                                        <th>Quantity</th>
                                        <th>Discount</th>
                                        <th>Total</th>
                                        <th>&nbsp;</th>
                                    </tr>
                                    <tr ng-repeat="tempSale in tempSalesCollection">
                                        <td>{{ tempSale.product.product_name }}</td>
                                        <td>{{ tempSale.product.size }}</td>
                                        <td>{{ tempSale.stock }}</td>
                                        <td>
                                            <input type="text" style="text-align:center" autocomplete="off" ng-change="updateTempSale(tempSale)" ng-model="tempSale.selling_price" size="8">
                                        </td>
                                        <td width="15%">
                                            <input type="number" style="text-align:center;width: 100%" autocomplete="off" ng-change="updateTempSale(tempSale)" ng-model="tempSale.quantity" step="any">
                                        </td>
                                        <td>
                                            <input type="text" style="text-align:center" autocomplete="off" ng-change="updateTempSale(tempSale)" ng-model="tempSale.discount" size="2">
                                        </td>
                                        <td>{{ (tempSale.selling_price * tempSale.quantity) - tempSale.discount | currency:'Tk'}}</td>
                                        <td>
                                            <button class="btn btn-danger btn-xs" type="button" ng-click="deleteTempSale(tempSale.id)"><span class="fa fa-remove" aria-hidden="true"></span></button>
                                        </td>
                                    </tr>
                                    <tfoot>
                                        <tr>
                                            <td colspan="3">
                                            </td>
                                            <td class="text-center">
                                                <b>
                                                    TQ: {{ quantity }}
                                                </b>
    
                                            </td>
                                            <td>
                                                <b>
                                                    TD: {{ discount }}
                                                </b>
    
                                            </td>
                                            <td>
                                                <b>
                                                    TA: {{ sum | number:2 }}
                                                </b>
                                                <input type="hidden" name="sub_total" value="{{ sum }}">
                                            </td>
                                            <td></td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                            <div class="row">
                                <div class="col-6">
                                    <div class="row">
                                        <div class="col-6">
                                            <div class="form-group">
                                                <label for="invoiceDiscount">Discount</label>
                                                <input type="text" ng-model="invoiceDiscount" ng-init="invoiceDiscount=0" autocomplete="off" class="form-control" id="invoiceDiscount" name="invoiceDiscount">
                                            </div>
                                        </div>
                                        <div class="col-6">
                                            <div class="form-group">
                                                <label for="payment">Paid Amount</label>
                                                <input type="text" ng-model="payment" id="payment" ng-init="payment=0" class="form-control" name="payment" readonly>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-6">
                                    <div class="row">
                                        <div class="col-12">
                                            <div class="form-group">
                                                <label for="totalInvoiceAmount">Total Invoice Amount</label>
                                                <input type="text" value="{{ sum - invoiceDiscount | number:2 }}" class="form-control" id="totalInvoiceAmount" readonly style="font-weight: bold;text-align: center;font-size: 32px">
                                                <input type="hidden" value="{{ sum - invoiceDiscount }}" class="form-control" name="grand_total">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-6">
                                    <div class="row">
                                        <div class="col-6">
                                            <div class="form-group">
                                                <label for="remarks">Remarks</label>
                                                <input type="text" name="remarks" class="form-control" id="remarks">
                                            </div>

                                        </div>
                                        <div class="col-6">
                                            <div class="form-group">
                                                <label for="amountDue">Amount Due</label>
                                                <input type="text" id="amountDue" class="form-control" value="{{ (sum(saletemp) - discount) - payment }}" readonly style="font-size: 18px;font-weight: bold; text-align: center">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="row">
                                        <div class="col-12">
                                            <div class="form-group">
                                                <?php echo Form::submit('Complete Sale',['class' => 'mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect m-b-10 btn-success btn-block form-control','style' => 'margin-left:10px;margin-top:30px;']); ?>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php echo Form::close(); ?>

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

<?php $__env->startPush('js'); ?>
    <!--select2-->
    <script src="<?php echo e(asset('admin/assets/plugins/select2/js/select2.js')); ?>" ></script>
    <script src="<?php echo e(asset('admin/assets/js/pages/select2/select2-init.js')); ?>" ></script>

    <!-- data time -->
    <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('js/sale.js')); ?>"></script>
    <script src="<?php echo e(asset('js/sale-form.js')); ?>"></script>
    <script>
        $(document).ready(function () {
            $(".payment").hide();
            $("#payment_button").click(function () {
                $(".payment").show('fast');
                $(".invoice").hide('fast');
            });
            $("#invoice_button").click(function () {
                $(".payment").hide('fast');
                $(".invoice").show('fast');
            })
        })
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('template.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\forazi\resources\views/admin/farmerinvoice/create.blade.php ENDPATH**/ ?>