
<?php $__env->startSection('content'); ?>
<div class="col-md-12 content-header" >
    <h1><i class="fa fa-file-pdf-o"></i> <?php echo e(trans('application.invoices')); ?></h1>
</div>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-12" style="max-width:1040px;">
                            <a href="<?php echo e(route('invoices.index')); ?>" class="btn btn-info btn-xs"> <i class="fa fa-chevron-left"></i> <?php echo e(trans('application.back')); ?></a>
                            <a href="<?php echo e(route('invoices.show', $invoice->uuid)); ?>" class="btn btn-primary btn-xs pull-right"> <i class="fa fa-search"></i>  <?php echo e(trans('application.preview')); ?></a>
                        </div>
                    </div>
                    <div class="row">
                            <div class="invoice">
                                <?php echo Form::model($invoice, ['route' => ['invoices.update', $invoice->uuid],  'method' => 'PATCH', 'id' => 'invoice_form', 'data-toggle'=>"validator", 'role' =>"form"]); ?>

                                <div class="col-md-12">
                                    <div class="text-right"><h1 style="margin:0"><?php echo e(trans('application.invoice')); ?></h1></div>
                                    <div class="col-md-7" style="padding: 0px">
                                        <div class="contact to">
                                            <div class="form-group">
                                                <?php echo Form::label('client', trans('application.client')); ?>

                                                <div class="input-group col-md-9">
                                                    <?php echo Form::select('client',$clients,$invoice->client_id, ['class' => 'form-control chosen', 'id' => 'client', 'required']); ?>

                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <?php echo Form::label('currency', trans('application.currency')); ?>

                                                <div class="input-group col-md-9">
                                                    <?php echo Form::select('currency',$currencies,null, ['class' => 'form-control chosen', 'required']); ?>

                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <?php echo Form::label('number', trans('application.invoice_number')); ?>

                                                <div class="input-group col-md-9">
                                                    <?php echo Form::text('number',null, ['class' => 'form-control input-sm', 'id' => 'number', 'required', 'readonly']); ?>

                                                    <span class="input-group-addon" style="padding-top: 6px;padding-bottom: 6px;">
                                                        <a id="change_invoice_num" href="javascript:void(0)"><i class="fa fa-pencil"></i></a>
                                                    </span>
                                                </div>
                                           </div>
                                            <div class="form-group">
                                                <?php echo Form::label('number', trans('application.recurring')); ?>

                                                <div class="input-group col-md-9">
                                                    <?php echo Form::select('recurring',['0'=>trans('application.no'),'1'=>trans('application.yes')],null, ['class' => 'form-control input-sm chosen', 'required']); ?>

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-5" style="padding: 0px">
                                        <div class="form-group">
                                            <?php echo Form::label('invoice_date', trans('application.date')); ?>

                                            <?php echo Form::text('invoice_date',null, ['class' => 'form-control datepicker input-sm' , 'id' => 'invoice_date', 'required','readonly']); ?>

                                        </div>
                                        <div class="form-group">
                                            <?php echo Form::label('due_date', trans('application.due_date')); ?>

                                            <?php echo Form::text('due_date',null, ['class' => 'form-control datepicker input-sm' , 'id' => 'due_date', 'required','readonly']); ?>

                                        </div>
                                        <div class="form-group">
                                            <?php echo Form::label('status', trans('application.status')); ?>

                                            <select class="form-control chosen required input-sm" name="status" id="status">
                                                <?php $__currentLoopData = $statuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $status): $__env->incrementLoopIndices(); $loop = $__env->getFirstLoop(); ?>
                                                <option value="<?php echo e($key); ?>" <?php echo e($key == $invoice->status ?  'selected' : ''); ?>> <?php echo e(strtoupper($status['label'])); ?> </option>
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getFirstLoop(); ?>
                                            </select>
                                        </div>
                                        <div class="form-group">
                                            <?php echo Form::label('number', trans('application.recurring_cycle')); ?>

                                            <?php echo Form::select('recurring_cycle',['1'=>trans('application.monthly'),'2'=>trans('application.quartely'),'3'=>trans('application.semi_annually'),'4'=>trans('application.annually')],null, ['class' => 'form-control input-sm chosen', 'required']); ?>

                                        </div>
                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <table class="table table-striped" id="item_table">
                                        <thead style="background: #2e3e4e;color: #fff;">
                                        <tr>
                                            <th width="5%"></th>
                                            <th width="20%"><?php echo e(trans('application.product')); ?></th>
                                            <th width="35%"><?php echo e(trans('application.description')); ?></th>
                                            <th width="10%"><?php echo e(trans('application.quantity')); ?></th>
                                            <th width="10%"><?php echo e(trans('application.price')); ?></th>
                                            <th width="15%"><?php echo e(trans('application.tax')); ?></th>
                                            <th width="15%"class="text-right"><?php echo e(trans('application.amount')); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php $__currentLoopData = $invoice->items->sortBy('item_order'); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getFirstLoop(); ?>
                                        <tr class="item">
                                            <td><span class="btn btn-danger btn-xs deleteItem" data-id="<?php echo e($item->uuid); ?>"><i class="fa fa-trash"></i></span><?php echo Form::hidden('itemId',$item->uuid, ['id'=>'itemId', 'required']); ?></td>
                                            <td><div class="form-group"><?php echo Form::text('item_name',$item->item_name,['class' => 'form-control input-sm item_name', 'id'=>"item_name", 'required']); ?></div></td>
                                            <td><div class="form-group"><?php echo Form::textarea('item_description',$item->item_description,['class' => 'form-control input-sm item_description', 'id'=>"item_description",'rows'=>'1','style'=>'resize: vertical;text-transform: capitalize;']); ?></div></td>
                                            <td class="text-center"><div class="form-group"><?php echo Form::input('number', 'quantity',$item->quantity, ['class' => 'form-control calcEvent input-sm quantity', 'id'=>"quantity" , 'required', 'step' => 'any', 'min' => '0']); ?></div></td>
                                            <td class="text-right"><div class="form-group"><?php echo Form::input('number','price',$item->price, ['class' => 'form-control input-sm calcEvent rate', 'id'=>"price", 'required', 'step' => 'any', 'min' => '0']); ?></div></td>
                                            <td><div class="form-group"><?php echo Form::customSelect('tax',$taxes['options'],$item->tax_id, ['class' => 'form-control input-sm calcEvent tax', 'id'=>"tax"]); ?></div></td>
                                            <td class="text-right"><span class="itemTotal"><?php echo e($invoice->totals[$item->uuid]['itemTotal']); ?></span></td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getFirstLoop(); ?>
                                        </tbody>
                                    </table>
                                </div>
                                <div class="col-md-6">
                                    <span id="btn_add_row" class="btn btn-xs btn-info "><i class="fa fa-plus"></i> <?php echo e(trans('application.add_row')); ?></span>
                                    <span id="btn_product_list_modal" class="btn btn-xs btn-primary "><i class="fa fa-plus"></i> <?php echo e(trans('application.add_from_products')); ?></span>
                                </div>
                                <div class="col-md-6">
                                    <table class="table">
                                        <tbody>
                                        <tr>
                                            <th style="width:50%"><?php echo e(trans('application.subtotal')); ?>:</th>
                                            <td class="text-right">
                                                <span id="subTotal"><?php echo e($invoice->totals['subTotal']); ?></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th><?php echo e(trans('application.tax')); ?>:</th>
                                            <td class="text-right">
                                                <span id="taxTotal"><?php echo e($invoice->totals['taxTotal']); ?></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th style="vertical-align: middle"><?php echo e(trans('application.discount')); ?>

                                                <?php echo Form::select('discount_mode',array('1'=>'%','0'=>'Amount'), $invoice->discount_mode,['class' => 'text-right input-sm', 'id' => 'discount_mode','style'=>'width:50%']); ?>

                                            </th>
                                            <td class="text-right">
                                                <div class="form-group">
                                                    <?php echo Form::input('number','discount', null,['class' => 'form-control text-right input-sm calcEvent', 'id' => 'discount', 'step'=>'any', 'min'=>'0']); ?>

                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th><?php echo e(trans('application.total')); ?>:</th>
                                            <td class="text-right">
                                                <span id="grandTotal"><?php echo e($invoice->totals['grandTotal']); ?></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <th><?php echo e(trans('application.paid')); ?>:</th>
                                            <td class="text-right">
                                                <span id="paidTotal"><?php echo e($invoice->totals['paidFormatted']); ?></span>
                                                <?php echo Form::hidden('paid',$invoice->totals['paid'], ['id' => 'paidAmount']); ?>

                                            </td>
                                        </tr>
                                        <tr class="amount_due">
                                            <th><?php echo e(trans('application.amount_due')); ?>:</th>
                                            <td class="text-right">
                                                <span class="currencySymbol" style="display: inline-block;"><?php echo e($invoice->currency); ?> </span>
                                                <span id="amountDue"><?php echo e($invoice->totals['amountDue']); ?></span>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <?php echo Form::label('notes', trans('application.notes')); ?>

                                        <?php echo Form::textarea('notes',null, ['class' => 'form-control text_editor','rows' =>  '2']); ?>

                                    </div>
                                    <div class="form-group">
                                        <?php echo Form::label('terms', trans('application.terms')); ?>

                                        <?php echo Form::textarea('terms',null, ['class' => 'form-control text_editor', 'rows' =>  '2', 'id' => 'invoice_terms']); ?>

                                    </div>
                                </div>
                                <div class="col-md-12">
                                    <button type="submit" class="btn btn-xs btn-success pull-right" id="saveInvoice"><i class="fa fa-save"></i> <?php echo e(trans('application.save_invoice')); ?></button>
                                </div>
                                <?php echo Form::close(); ?>

                            </div>
                       </div>
                </div>
            </div>
        </div>>
    </div>
</section>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('scripts'); ?>
    <?php echo $__env->make('invoices.partials._invoices_js', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>