<?php $__env->startSection('title', 'Create Sale 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">
    <style>
        .switch-button {
            display: flex;
            width: 200px;
            border: 2px solid #ccc;
            border-radius: 20px;
            overflow: hidden;
            margin: auto;
        }
        .option {
            flex: 1;
            text-align: center;
            padding: 10px 0;
            cursor: pointer;
            transition: background-color 0.3s, border-color 0.3s;
            font-weight: bold;
            color: #000 !important;
            background: transparent;
        }
        .option.checked {
            background: #3FCC7E;
            color: #fff !important;
        }
    </style>
<?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="card card-box">
            <div class="card-head text-white " style="background-color:#3FCC7E;">
                <header>Crete Sale 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(['route' => 'admin.sales.store','method' => 'POST']); ?>

                <div class="row">
                    <div class="col-12">
                        <div class="switch-button mb-3">
                            <a href="<?php echo e(route('admin.sales.create',['for' => 'customer'])); ?>" class="option <?php echo e($for == 'customer' ? 'checked' : ''); ?>">Customer</a>
                            <a href="<?php echo e(route('admin.sales.create',['for' => 'farmer'])); ?>" class="option <?php echo e($for == 'farmer' ? 'checked' : ''); ?>">Farmer</a>
                        </div>    
                    </div>
                    <div class="col-12 col-md-3 col-sm-4">
                        <div class="form-group">
                            <label for="invoice_id">Invoice No.</label>
                            <input type="text" class="form-control" value="<?php if($sale): ?> <?php echo e($sale->id + 1); ?> <?php else: ?> <?php echo e(1); ?> <?php endif; ?>" readonly>
                        </div>
                    </div>
                    <div class="col-12 col-md-3 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_id" value="<?php echo e(Auth::user()->id); ?>">
                        </div>
                    </div>
                    <div class="col-12 col-sm-4 col-md-3">
                        <div class="form-group">
                            <label for="branch_id">Branch Name</label>
                            <?php if(count($branches) > 1): ?>
                                <select name="branch_id" id="branch_id" class="form-control select2">
                                    <?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($branch->id); ?>" <?php echo e(Auth::user()->branch_id == $branch->id ? 'selected' : ''); ?>><?php echo e($branch->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            <?php else: ?>
                                <?php
                                    $firstBranch = $branches->first();
                                ?>
                                <input type="text" id="branch_id" class="form-control" value="<?php echo e(optional($firstBranch)->name ?? ''); ?>" readonly>
                                <input type="hidden" name="branch_id" value="<?php echo e(optional($firstBranch)->id ?? ''); ?>">
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="col-12 col-sm-6 col-md-3">                      
                        <div class="form-group">
                            <label for="customer_id">Select <?php echo e(ucfirst( $for )); ?></label>
                            <select id="customer_id" name="customer_id" class="form-control  select2 ">
                                <option value="0">Select <?php echo e(ucfirst( $for )); ?></option>
                                <?php $__currentLoopData = $customers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $name => $id): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($id); ?>"><?php echo e($name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                    </div>
                    <div class="col-12 col-sm-6 col-md-3">
                        <div class="form-group">
                            <label for="phone">Customer Phone</label>
                            <input type="tel" name="phone" id="phone" class="form-control">
                        </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_datetime" data-date="<?php echo e(Carbon\Carbon::now()); ?>" data-date-format="dd MM yyyy HH:ii p" data-link-field="dtp_input1">
                                <input class="form-control" size="16" type="text" name="sale_date" value="<?php echo e(Carbon\Carbon::now()->toDayDateTimeString()); ?>">
                                <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 class="col-12 col-sm-6 col-md-3">
                        <div class="form-group">
                            <label class="">Due Date</label>
                            <div class="input-group date form_datetime" data-date="<?php echo e(Carbon\Carbon::now()); ?>" data-date-format="dd MM yyyy HH:ii p" data-link-field="dtp_input2">
                                <input class="form-control" size="16" type="text" name="due_date" value="<?php echo e(Carbon\Carbon::now()->toDayDateTimeString()); ?>">
                                <span class="input-group-addon ml-2">
                                    <span class="fa fa-calendar"></span>
                                </span>
                            </div>
                            <input type="hidden" id="dtp_input2" value="" />
                        </div>
                    </div>
                    <div class="col-12 col-sm-6 col-md-3">
                        <div class="form-group">
                            <label for="payment_processor">Payment Processor</label>
                            <select name="payment_processor" id="payment_processor" class="form-control select2">
                                <?php $__currentLoopData = \App\Models\PaymentGateway::get(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $gateway): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?> 
                                    <option value="<?php echo e($gateway->id); ?>"><?php echo e($gateway->gateway_name); ?>(<?php echo e($gateway->gateway_account_number); ?>)</option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                    </div>
                    <div class="col-12 col-sm-12 col-md-12">
                         <div class="form-group">
                            <label for="purpose_head">Purpose Head <small>(Required if you take some payment now)</small></label>
                            <select name="purpose_head" id="purpose_head" class="form-control select2">
                                <?php $__currentLoopData = \App\Models\PurposeHead::get(); $__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>
                </div>
                <div class="row p-t-20" ng-controller="ProductSearchController">
                    <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>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>
                                        <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">
                                        </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" name="grand_total" value="{{ sum - invoiceDiscount }}">
                                        </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="{{ (calculateSum( tempSalesCollection ) - invoiceDiscount) - payment }}" readonly style="font-size: 18px;font-weight: bold; text-align: center" name="due">
                                        </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>
                <input type="hidden" name="for" value="<?php echo e($for); ?>">
                <?php echo Form::close(); ?>

            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>
  
<?php $__env->startPush('js'); ?>
<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>
<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>
<?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/saleinvoice/create.blade.php ENDPATH**/ ?>