<?php
    if($create){
        $title = __('adminforms.invoices.title_insert');
        $formpar = array('route' => 'admin.invoice.store', 'autocomplete' => 'off');
    } else {
        $title = __('adminforms.invoices.title_update');
        $formpar = array('route' => array('admin.invoice.update', $invoice->inv_id), 'method' => 'PUT', 'autocomplete' => 'off');
    }

    $tr = [
       
        'user id'            => __('adminforms.invoices.user_id'),

        'inv po num'         => __('adminforms.invoices.inv_po_num'),
        'inv po date'        => __('adminforms.invoices.inv_po_date'),
        'inv loc num'        => __('adminforms.invoices.inv_loc_num'),
        'inv currency'       => __('adminforms.invoices.inv_currency'),
        'inv pay terms'      => __('adminforms.invoices.inv_pay_terms'),
        'inv est shipp date' => __('adminforms.invoices.inv_est_shipp_date'),
        'inv mod of trans'   => __('adminforms.invoices.inv_mod_of_trans'),
        'inv transp terms'   => __('adminforms.invoices.inv_transp_terms'),
        'inv pac num'        => __('adminforms.invoices.inv_pac_num'),
        'inv est gw'         => __('adminforms.invoices.inv_est_gw'),
        'inv est nw'         => __('adminforms.invoices.inv_est_nw'),
        'inv carrier'        => __('adminforms.invoices.inv_carrier'),
        'inv rfe'            => __('adminforms.invoices.inv_rfe'),
        'inv emb port'       => __('adminforms.invoices.inv_emb_port'),
        'inv disc port'      => __('adminforms.invoices.inv_disc_port'),
        'inv orig count'     => __('adminforms.invoices.inv_orig_count'),
        'inv awb bl num'     => __('adminforms.invoices.inv_awb_bl_num'),
        'inv note'           => __('adminforms.invoices.inv_note'),



        'inv subtotal'       => __('adminforms.invoices.inv_subtotal'),
        'inv subject to'     => __('adminforms.invoices.inv_subject_to'),
        'inv rate'           => __('adminforms.invoices.inv_rate'),
        'inv sales tax'      => __('adminforms.invoices.inv_sales_tax'),
        'inv sh'             => __('adminforms.invoices.inv_sh'),
        'inv insurance'      => __('adminforms.invoices.inv_insurance'),
        'inv total'          => __('adminforms.invoices.inv_total'),



        'prod id'               => __('adminforms.invoices.prod_id'),
        'invi desc'             => __('adminforms.invoices.invi_desc'),
        'invi qnt'              => __('adminforms.invoices.invi_qnt'),
        'invi uom'              => __('adminforms.invoices.invi_uom'),
        'invi price'            => __('adminforms.invoices.invi_price'),
        'item'                  => __('adminforms.invoices.item'),
        'yesterday'             => __('adminforms.common.yesterday'),
        'today'                 => __('adminforms.common.today'),
        'tomorrow'              => __('adminforms.common.tomorrow'),

        'Polje stavka fakture je obavezno.' => __('adminforms.invoices.must_have_one_item'),
    ];
?>

<?php $__env->startSection('title'); ?><?php echo e($title); ?><?php $__env->stopSection(); ?>
<?php $__env->startSection('header'); ?><?php echo e($title); ?><?php $__env->stopSection(); ?>
<?php $__env->startSection('header_desc'); ?> <?php $__env->stopSection(); ?>
<?php $__env->startSection('breadcumbs'); ?> <?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <!-- Main content -->
    <section class="content">



        <div class="row">

            <div class="col-xs-12">
                <?php if(session('error')): ?>
                    <div class="alert alert-danger alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <i class="icon fa fa-exclamation-triangle"></i> <strong>Info: </strong> &nbsp;  &nbsp;
                        <?php echo e(session('error')); ?>

                    </div>
                <?php endif; ?>
                <?php if($errors->any()): ?>
                    <div style="font-weight: bold; color: #9e0505"><?php echo e(__('adminforms.common.correct_errors')); ?></div>
                    <div><?php echo print_r($errors->all()); ?></div>
                <?php endif; ?>
            </div>

            <?php echo Form::open($formpar); ?>


            <div class="col-xs-12">



                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-list-alt"></i> <?php echo e(__('adminforms.invoices.general_block')); ?></h3>
                    </div><!-- /. panel-heading -->

                    <div class="panel-body">
                        <div class="row">

                            

                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php
                                    $type = old('inv_type', $invoice->inv_type);
                                ?>
                                <?php echo e(Form::label('inv_type', ucfirst(__('adminforms.invoices.inv_type').':'))); ?>

                                <select class="form-control" name="inv_type" id="type-select">
                                    <option value="i" <?php echo $type == 'i' ? ' selected="selected"' : ''; ?>><?php echo e(ucfirst(__('adminforms.invoices.inv_type_i'))); ?></option>
                                    <option value="p" <?php echo $type == 'p' ? ' selected="selected"' : ''; ?>><?php echo e(ucfirst(__('adminforms.invoices.inv_type_p'))); ?></option>
                                </select>
                                <small class="error"><?php echo e(strtr($errors->first('inv_type'),$tr)); ?></small>
                            </div>





                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php
                                    $olddata = (isset($order)) ? $order->user_id : $invoice->user_id;
                                    $cgId = old('user_id', $olddata);
                                ?>
                                <?php echo e(Form::label('user_id', ucfirst(__('adminforms.invoices.user_id').':'))); ?>

                                <?php echo e(Form::select('user_id', $buyers, $cgId, ['placeholder' => __('adminforms.invoices.select_buyer'), 'class' => 'form-control', 'id' => 'com-select'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('user_id'),$tr)); ?></small>
                            </div>


                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php
                                    $sa = old('inv_sa', $invoice->inv_sa, 1);
                                ?>
                                <?php echo e(Form::label('inv_sa', ucfirst(__('adminforms.invoices.inv_sa').':'))); ?>

                                <select class="form-control" name="inv_sa" id="sa">
                                    <option value="1" <?php echo $sa == '1' ? ' selected="selected"' : ''; ?>><?php echo e(ucfirst(__('adminforms.common.true'))); ?></option>
                                    <option value="0" <?php echo $sa == '0' ? ' selected="selected"' : ''; ?>><?php echo e(ucfirst(__('adminforms.common.false'))); ?></option>
                                </select>
                                <small class="error"><?php echo e(strtr($errors->first('inv_type'),$tr)); ?></small>
                            </div>

                            <br clear="all">

                            <div id="deldata" class="" <?php echo $sa = 1 ? ' style="display: none" ' : ''; ?>>

                                <?php
                                if(isset($invoice->addresses)){
                                    $sname = $invoice->addresses->st_name;
                                    $sadr  = $invoice->addresses->st_address;
                                    $szc   = $invoice->addresses->st_zip_city;
                                    $sph   = $invoice->addresses->st_phone;
                                } else {
                                    $sname = '';
                                    $sadr  = '';
                                    $szc   = '';
                                    $sph   = '';
                                }

                                ?>

                                <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                    <?php echo e(Form::label('st_name', ucfirst(__('adminforms.invoices.st_name').':'))); ?>

                                    <?php echo e(Form::text('st_name', old('st_name', $sname), ['class' => 'form-control'])); ?>

                                    <small class="error"><?php echo e(strtr($errors->first('st_name'),$tr)); ?></small>
                                </div>

                                <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                    <?php echo e(Form::label('st_address', ucfirst(__('adminforms.invoices.st_address').':'))); ?>

                                    <?php echo e(Form::text('st_address', old('st_address', $sadr), ['class' => 'form-control'])); ?>

                                    <small class="error"><?php echo e(strtr($errors->first('st_address'),$tr)); ?></small>
                                </div>

                                <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                    <?php echo e(Form::label('st_zip_city', ucfirst(__('adminforms.invoices.st_zip_city').':'))); ?>

                                    <?php echo e(Form::text('st_zip_city', old('st_zip_city', $szc), ['class' => 'form-control'])); ?>

                                    <small class="error"><?php echo e(strtr($errors->first('st_zip_city'),$tr)); ?></small>
                                </div>

                                <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                    <?php echo e(Form::label('st_phone', ucfirst(__('adminforms.invoices.st_phone').':'))); ?>

                                    <?php echo e(Form::text('st_phone', old('st_phone', $sph), ['class' => 'form-control'])); ?>

                                    <small class="error"><?php echo e(strtr($errors->first('st_phone'),$tr)); ?></small>
                                </div>

                            </div>



                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php echo e(Form::label('inv_po_num', ucfirst(__('adminforms.invoices.inv_po_num').':'))); ?>

                                <?php echo e(Form::text('inv_po_num', old('inv_po_num', $invoice->inv_po_num), ['class' => 'form-control'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('inv_po_num'),$tr)); ?></small>
                            </div>



                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <div class="form-group">
                                    <?php echo e(Form::label('inv_po_date', ucfirst(__('adminforms.invoices.inv_po_date').':'))); ?>

                                    <div class="input-group date">
                                        <div class="input-group-addon"><i class="fa fa-calendar"></i></div>
                                        <?php echo e(Form::text('inv_po_date', old('inv_po_date', $invoice->inv_po_date ), ['class' => 'form-control pull-right', 'id' => 'datepicker'])); ?>

                                    </div><!-- /.input group date -->
                                    <small class="error"><?php echo e(strtr($errors->first('inv_po_date'),$tr)); ?></small>
                                </div><!-- /.form-group -->
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php echo e(Form::label('inv_loc_num', ucfirst(__('adminforms.invoices.inv_loc_num').':'))); ?>

                                <?php echo e(Form::text('inv_loc_num', old('inv_loc_num', $invoice->inv_loc_num), ['class' => 'form-control'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('inv_loc_num'),$tr)); ?></small>
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php echo e(Form::label('inv_currency', ucfirst(__('adminforms.invoices.inv_currency').':'))); ?>

                                <?php echo e(Form::text('inv_currency', old('inv_currency', $invoice->inv_currency), ['class' => 'form-control'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('inv_currency'),$tr)); ?></small>
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php echo e(Form::label('inv_pay_terms', ucfirst(__('adminforms.invoices.inv_pay_terms').':'))); ?>

                                <?php echo e(Form::text('inv_pay_terms', old('inv_pay_terms', $invoice->inv_pay_terms), ['class' => 'form-control'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('inv_pay_terms'),$tr)); ?></small>
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <div class="form-group">
                                    <?php echo e(Form::label('inv_est_shipp_date', ucfirst(__('adminforms.invoices.inv_est_shipp_date').':'))); ?>

                                    <div class="input-group date">
                                        <div class="input-group-addon"><i class="fa fa-calendar"></i></div>
                                        <?php echo e(Form::text('inv_est_shipp_date', old('inv_est_shipp_date', $invoice->inv_est_shipp_date ), ['class' => 'form-control pull-right', 'id' => 'datepicker2'])); ?>

                                    </div><!-- /.input group date -->
                                    <small class="error"><?php echo e(strtr($errors->first('inv_est_shipp_date'),$tr)); ?></small>
                                </div><!-- /.form-group -->
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php echo e(Form::label('inv_mod_of_trans', ucfirst(__('adminforms.invoices.inv_mod_of_trans').':'))); ?>

                                <?php echo e(Form::text('inv_mod_of_trans', old('inv_mod_of_trans', $invoice->inv_mod_of_trans), ['class' => 'form-control'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('inv_mod_of_trans'),$tr)); ?></small>
                            </div>


                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php echo e(Form::label('inv_transp_terms', ucfirst(__('adminforms.invoices.inv_transp_terms').':'))); ?>

                                <?php echo e(Form::text('inv_transp_terms', old('inv_transp_terms', $invoice->inv_transp_terms), ['class' => 'form-control'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('inv_transp_terms'),$tr)); ?></small>
                            </div>


                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php echo e(Form::label('inv_pac_num', ucfirst(__('adminforms.invoices.inv_pac_num').':'))); ?>

                                <?php echo e(Form::text('inv_pac_num', old('inv_pac_num', $invoice->inv_pac_num), ['class' => 'form-control'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('inv_pac_num'),$tr)); ?></small>
                            </div>

                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php echo e(Form::label('inv_est_gw', ucfirst(__('adminforms.invoices.inv_est_gw').':'))); ?>

                                <?php echo e(Form::text('inv_est_gw', old('inv_est_gw', $invoice->inv_est_gw), ['class' => 'form-control'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('inv_est_gw'),$tr)); ?></small>
                            </div>


                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php echo e(Form::label('inv_est_nw', ucfirst(__('adminforms.invoices.inv_est_nw').':'))); ?>

                                <?php echo e(Form::text('inv_est_nw', old('inv_est_nw', $invoice->inv_est_nw), ['class' => 'form-control'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('inv_est_nw'),$tr)); ?></small>
                            </div>


                            <div class="col-xs-12 col-sm-6 col-md-3 pbb">
                                <?php echo e(Form::label('inv_carrier', ucfirst(__('adminforms.invoices.inv_carrier').':'))); ?>

                                <?php echo e(Form::text('inv_carrier', old('inv_carrier', $invoice->inv_carrier), ['class' => 'form-control'])); ?>

                                <small class="error"><?php echo e(strtr($errors->first('inv_carrier'),$tr)); ?></small>
                            </div>


                        </div> <!-- /.row -->
                    </div> <!-- /.panel-body -->
                </div> <!-- /.panel panel-default-->




                <div class="box">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <div class="row">
                                <div class="col-md-4"><h3 class="panel-title"><i class="fa fa-list-alt"></i> <?php echo e(__('adminforms.invoices.items_block')); ?></h3></div>
                                <?php $items_err = strtr($errors->first('item'),$tr) ?>
                                <div class="col-md-8 error"><strong><?php echo e(strtr($items_err,$tr)); ?></strong></div>
                            </div>

                        </div>
                        <div class="panel-body">
                            <div class="row">

                                <div class="col-md-12">
                                    <table class="table table-bordered table-hover" id="invtable">
                                        <thead>
                                        <tr>
                                            <th width="2%"><input id="check_all" class="formcontrol" type="checkbox"/></th>
                                            <th width="10%">Sifra</th>
                                            <th width="35%">Naziv</th>
                                            <th width="12%">Kol</th>
                                            <th width="6%">jm</th>
                                            <th width="8%">Cena </th>
                                            <th width="8%">PDV %</th>
                                            <th width="8%">PDV </th>
                                            <th width="17%">Total</th>
                                        </tr>
                                        </thead>
                                        <tbody>


                                        <?php
                                            $olditems  = old('item',   []);
                                            $subTotal = 0;
                                            $x=0;
                                        ?>


                                        <?php if(count($olditems)): ?>

                                            <?php
                                            // Get which fields has errors
                                            $oldErrorKeys = array_keys($errors->getMessages());
                                            ?>

                                            <?php $__currentLoopData = $olditems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                                <?php

                                                $curentFields = [
                                                    "item.$index.prod_id",
                                                    "item.$index.prod_sku",
                                                    "item.$index.invi_desc",
                                                    "item.$index.invi_qnt",
                                                    "item.$index.invi_uom",
                                                    "item.$index.invi_price",
                                                    "item.$index.invi_vrate",
                                                    "item.$index.invi_vat",
                                                    ];


                                                $id      = $row['prod_id'];
                                                $sku     = $row['prod_sku'];
                                                $name    = $row['invi_desc'];
                                                $qnt     = $row['invi_qnt'];
                                                $uom     = $row['invi_uom'];
                                                $price   = number_format($row['invi_price'], 2, '.', '');
                                                $vrate   = $row['invi_vrate'];
                                                $vat     = number_format($row['invi_vat'], 2, '.', '');
                                                $tot     = number_format((($row['invi_price']+$row['invi_vat'])*$row['invi_qnt']), 2, '.', '');
                                                $subTotal = $subTotal+$tot;
                                                ?>

                                                <tr class="iitem" data-index="<?php echo e($index); ?>">

                                                    <td>
                                                        <input class="case" type="checkbox"/>
                                                        <input name="item[<?php echo e($index); ?>][prod_id]" class="pid" type="hidden" value="<?php echo e($id); ?>" />
                                                    </td>

                                                    <td><input name="item[<?php echo e($index); ?>][prod_sku]" value="<?php echo e($sku); ?>" class="form-control input-sm sku" autocomplete="off" onkeypress="return false"
                                                               onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                                    <td><input type="text" data-type="poiDesc" name="item[<?php echo e($index); ?>][invi_desc]"  value="<?php echo e($name); ?>"
                                                               class="form-control input-sm pn" autocomplete="off"></td>

                                                    <td><input name="item[<?php echo e($index); ?>][invi_qnt]" class="form-control input-sm qnt" value="<?php echo e($qnt); ?>"
                                                               autocomplete="off" onkeypress="return IsNumeric(event);"></td>

                                                    <td><input type="text" name="item[<?php echo e($index); ?>][invi_uom]"  value="<?php echo e($uom); ?>"
                                                               class="form-control input-sm pn" autocomplete="off"></td>

                                                    <td><input name="item[<?php echo e($index); ?>][invi_price]" class="form-control input-sm price"  value="<?php echo e($price); ?>" autocomplete="off"
                                                               onkeypress="return IsNumeric(event);"></td>

                                                    <td><input name="item[<?php echo e($index); ?>][invi_vrate]" class="form-control input-sm vr"  value="<?php echo e($vrate); ?>" autocomplete="off"
                                                               onkeypress="return false"  onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                                    <td><input name="item[<?php echo e($index); ?>][invi_vat]" class="form-control input-sm vat"  value="<?php echo e(number_format($vat, 2,".","")); ?>" autocomplete="off"
                                                               onkeypress="return false"  onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>


                                                    <td><input name="item[<?php echo e($index); ?>][total]" class="form-control input-sm tot"  value="<?php echo e(number_format($tot, 2,".","")); ?>" autocomplete="off"
                                                        onkeypress="return false"  onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                                </tr>
                                                <?php if(array_intersect($curentFields, $oldErrorKeys)): ?>
                                                    <tr class="errorrow">
                                                        <td style="padding: 2px;">&nbsp;</td>
                                                        <td colspan="6" style="padding: 2px;">
                                                           <span class="error" style="font-size: 11px;">
                                                               <?php echo e(__('adminforms.invoices.in_row_above')); ?>: &nbsp;
                                                               <?php echo e(preg_replace('/(item)\.(\d+)\.(prod_id)/i',    __('adminforms.invoices.prod_id'),    $errors->first('item.'.$index.'.prod_id'))); ?> &nbsp;
                                                               <?php echo e(preg_replace('/(item)\.(\d+)\.(prod_sku)/i',   __('adminforms.invoices.prod_sku'),   $errors->first('item.'.$index.'.prod_sku'))); ?> &nbsp;
                                                               <?php echo e(preg_replace('/(item)\.(\d+)\.(invi_desc)/i',  __('adminforms.invoices.invi_desc'),  $errors->first('item.'.$index.'.invi_desc'))); ?> &nbsp;
                                                               <?php echo e(preg_replace('/(item)\.(\d+)\.(invi_qnt)/i',   __('adminforms.invoices.invi_qnt'),   $errors->first('item.'.$index.'.invi_qnt'))); ?> &nbsp;
                                                               <?php echo e(preg_replace('/(item)\.(\d+)\.(invi_uom)/i',   __('adminforms.invoices.invi_uom'),   $errors->first('item.'.$index.'.invi_uom'))); ?> &nbsp;
                                                               <?php echo e(preg_replace('/(item)\.(\d+)\.(invi_price)/i', __('adminforms.invoices.invi_price'), $errors->first('item.'.$index.'.invi_price'))); ?> &nbsp;
                                                               <?php echo e(preg_replace('/(item)\.(\d+)\.(invi_vrate)/i', __('adminforms.invoices.invi_vrate'), $errors->first('item.'.$index.'.invi_vrate'))); ?> &nbsp;
                                                               <?php echo e(preg_replace('/(item)\.(\d+)\.(invi_vat)/i',   __('adminforms.invoices.invi_vat'),   $errors->first('item.'.$index.'.invi_vat'))); ?> &nbsp;
                                                           </span>
                                                        </td>
                                                    </tr>
                                                <?php endif; ?>

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



                                        <?php elseif(isset($order) && count($order->items)): ?>

                                            <?php $__currentLoopData = $order->items; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                                <?php
                                                    $index   = $x;
                                                    $id      = $row->prod_id;
                                                    $sku     = '';
                                                    $name    = $row->ord_item_name;
                                                    $qnt     = $row->ord_item_qnty;
                                                    $uom     = 'kom';
                                                    /*$price   = number_format($row->ord_item_price, 2, '.', '');
                                                    $tot     = number_format(($row->ord_item_price*$row->ord_item_qnty), 2, '.', '');
                                                    $subTotal = $subTotal+$tot;*/

                                                    $price   = number_format($row->ord_item_nvprice, 2, '.', '');
                                                    $vrate   = $row->ord_item_vrate;
                                                    $vat     = $row->ord_item_vat;
                                                    $tot     = number_format((($price+$vat)*$row->ord_item_qnty), 2, '.', '');
                                                    $subTotal = $subTotal+$tot;
                                                ?>


                                                <tr class="iitem" data-index="<?php echo e($index); ?>">

                                                    <td>
                                                        <input class="case" type="checkbox"/>
                                                        <input name="item[<?php echo e($index); ?>][prod_id]" class="pid" type="hidden" value="<?php echo e($id); ?>" />
                                                    </td>

                                                    <td><input name="item[<?php echo e($index); ?>][prod_sku]" value="<?php echo e($sku); ?>" class="form-control input-sm sku" autocomplete="off" onkeypress="return false"
                                                               onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                                    <td><input type="text" data-type="poiDesc" name="item[<?php echo e($index); ?>][invi_desc]"  value="<?php echo e($name); ?>"
                                                               class="form-control input-sm pn" autocomplete="off"></td>

                                                    <td><input name="item[<?php echo e($index); ?>][invi_qnt]" class="form-control input-sm qnt" value="<?php echo e($qnt); ?>"
                                                               autocomplete="off" onkeypress="return IsNumeric(event);"></td>

                                                    <td><input type="text" name="item[<?php echo e($index); ?>][invi_uom]"  value="<?php echo e($uom); ?>"
                                                               class="form-control input-sm pn" autocomplete="off"></td>

                                                    <td><input name="item[<?php echo e($index); ?>][invi_price]" class="form-control input-sm price"  value="<?php echo e($price); ?>" autocomplete="off"
                                                               onkeypress="return IsNumeric(event);"></td>

                                                    <td><input name="item[<?php echo e($index); ?>][invi_vrate]" class="form-control input-sm vr"  value="<?php echo e($vrate); ?>" autocomplete="off"
                                                               onkeypress="return false"  onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                                    <td><input name="item[<?php echo e($index); ?>][invi_vat]" class="form-control input-sm vat"  value="<?php echo e(number_format($vat, 2,".","")); ?>" autocomplete="off"
                                                               onkeypress="return false"  onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                                    <td><input name="item[<?php echo e($index); ?>][total]" class="form-control input-sm tot"  value="<?php echo e(number_format($tot, 2,".","")); ?>" autocomplete="off"
                                                               onkeypress="return false"  onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                                </tr>

                                                <?php ++$x; ?>

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

                                        <?php elseif(count($invoiceItems)): ?>

                                            <?php $__currentLoopData = $invoiceItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                            <?php
                                                $index   = $row->invi_id+$x;
                                                $id      = $row->prod_id;
                                                $sku     = $row->invi_sku;
                                                $name    = $row->invi_desc;
                                                $qnt     = $row->invi_qnt;
                                                $uom     = $row->invi_uom;
                                                $price   = number_format($row->invi_price, 2, '.', '');
                                                $vrate   = $row->invi_vrate;
                                                $vat     = $row->invi_vat;
                                                $tot     = number_format(($row->invi_price*$row->invi_qnt), 2, '.', '');
                                                $subTotal = $subTotal+$tot;
                                            ?>


                                        <tr class="iitem" data-index="<?php echo e($index); ?>">

                                            <td>
                                                <input class="case" type="checkbox"/>
                                                <input name="item[<?php echo e($index); ?>][prod_id]" class="pid" type="hidden" value="<?php echo e($id); ?>" />
                                            </td>

                                            <td><input name="item[<?php echo e($index); ?>][prod_sku]" value="<?php echo e($sku); ?>" class="form-control input-sm sku" autocomplete="off" onkeypress="return false"
                                                       onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                            <td><input type="text" data-type="poiDesc" name="item[<?php echo e($index); ?>][invi_desc]"  value="<?php echo e($name); ?>"
                                                       class="form-control input-sm pn" autocomplete="off"></td>

                                            <td><input name="item[<?php echo e($index); ?>][invi_qnt]" class="form-control input-sm qnt" value="<?php echo e($qnt); ?>"
                                                       autocomplete="off" onkeypress="return IsNumeric(event);"></td>

                                            <td><input type="text" name="item[<?php echo e($index); ?>][invi_uom]"  value="<?php echo e($uom); ?>"
                                                       class="form-control input-sm pn" autocomplete="off"></td>

                                            <td><input name="item[<?php echo e($index); ?>][invi_price]" class="form-control input-sm price"  value="<?php echo e($price); ?>" autocomplete="off"
                                                       onkeypress="return IsNumeric(event);"></td>

                                            <td><input name="item[<?php echo e($index); ?>][invi_vrate]" class="form-control input-sm vr"  value="<?php echo e($vrate); ?>" autocomplete="off"
                                                       onkeypress="return false"  onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                            <td><input name="item[<?php echo e($index); ?>][invi_vat]" class="form-control input-sm vat"  value="<?php echo e(number_format($vat, 2,".","")); ?>" autocomplete="off"
                                                       onkeypress="return false"  onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                            <td><input name="item[<?php echo e($index); ?>][total]" class="form-control input-sm tot"  value="<?php echo e(number_format($tot, 2,".","")); ?>" autocomplete="off"
                                                       onkeypress="return false"  onkeydown="return false"  ondrop="return false;" onpaste="return false;"></td>

                                        </tr>

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

                                        <?php endif; ?>

                                        </tbody>
                                    </table>
                                </div><!-- /.col-md-12 -->

                                <div class="col-xs-12">
                                    <div class="row">

                                        <div class="col-md-6">
                                            <div>
                                                <button class="btn btn-danger btn-sm delete" type="button">- Obriši selectovane stavke</button>
                                                <button class="btn btn-success btn-sm addmore" type="button" data-toggle="modal" data-target="#addprodmodal" >
                                                    + Dodaj novu stavku
                                                </button>
                                            </div>
                                            <div>
                                                <br><br>
                                                <?php echo e(Form::label('inv_note', ucfirst(__('adminforms.invoices.inv_note').':'))); ?>

                                                <?php echo e(Form::textarea('inv_note', old('inv_note', $invoice->inv_note), ['class' => 'form-control', 'rows' => 4])); ?>

                                                <br><small class="error"><?php echo e(strtr($errors->first('inv_note'),$tr)); ?></small>

                                            </div>
                                        </div>

                                        <div class="col-md-offset-2 col-md-4 form-inline text-right">
                                            <div class="form-group">
                                                <label><?php echo e(__('adminforms.invoices.inv_subtotal')); ?>: &nbsp;</label>
                                                <div class="input-group">
                                                    <input name="inv_subtotal" class="form-control input-sm" id="subTotal" onkeypress="return false" onkeydown="return false"
                                                           value="<?php echo e($subTotal); ?>"
                                                           ondrop="return false;" onpaste="return false;">
                                                    <div class="input-group-addon">RSD</div>
                                                </div>
                                                <div><small class="error"><?php echo e(strtr($errors->first('inv_subtotal'),$tr)); ?></small></div>
                                            </div>
                                            <!--  -->

                                            

                                            <div class="form-group">
                                                <label><?php echo e(__('adminforms.invoices.inv_sales_tax')); ?>: &nbsp;</label>
                                                <div class="input-group">
                                                    <input name="inv_sales_tax" class="form-control input-sm" id="salesTax" value="<?php echo e(old('inv_sales_tax', $invoice->inv_sales_tax)); ?>" onkeypress="return IsNumeric(event);">
                                                    <div class="input-group-addon">RSD</div>
                                                </div>
                                                <div><small class="error"><?php echo e(strtr($errors->first('inv_sales_tax'),$tr)); ?></small></div>
                                            </div>

                                            <div class="form-group">
                                                <label><?php echo e(__('adminforms.invoices.inv_sh')); ?>: &nbsp;</label>
                                                <div class="input-group">
                                                    <input name="inv_sh" class="form-control input-sm" id="invSh" value="<?php echo e(old('inv_sh', $invoice->inv_sh)); ?>" onkeypress="return IsNumeric(event);">
                                                    <div class="input-group-addon">RSD</div>
                                                </div>
                                                <div><small class="error"><?php echo e(strtr($errors->first('inv_sh'),$tr)); ?></small></div>
                                            </div>
                                            
                                            <div class="form-group">
                                                <label><?php echo e(__('adminforms.invoices.inv_insurance')); ?>: &nbsp;</label>
                                                <div class="input-group">
                                                    <input name="inv_insurance" class="form-control input-sm" id="insurance"  value="<?php echo e(old('inv_insurance', $invoice->inv_insurance)); ?>" onkeypress="return IsNumeric(event);">
                                                    <div class="input-group-addon">RSD</div>
                                                </div>
                                                <div><small class="error"><?php echo e(strtr($errors->first('inv_insurance'),$tr)); ?></small></div>
                                            </div>

                                            <div class="form-group">
                                                <label><?php echo e(__('adminforms.invoices.inv_total')); ?>: &nbsp;</label>
                                                <div class="input-group">
                                                    <input name="inv_total" class="form-control input-sm" id="total" onkeypress="return false" onkeydown="return false"
                                                           value="<?php echo e(old('inv_total', $invoice->inv_total)); ?>"
                                                           ondrop="return false;" onpaste="return false;">
                                                    <div class="input-group-addon">RSD</div>
                                                </div>
                                                <div><small class="error"><?php echo e(strtr($errors->first('inv_total'),$tr)); ?></small></div>

                                            </div>
                                            
                                            
                                            <!--  -->
                                        </div>


                                    </div><!--row-->
                                </div><!-- / .col-xs-12 -->

                            </div><!-- /.row -->
                        </div><!-- /.panel-body -->
                    </div><!-- /.panel -->
                </div> <!-- /.box -->

              

                <div class="row">
                    <div class="col-xs-12">
                        <hr>
                        <?php $btntext = ($create) ? __('adminforms.invoices.btn_insert') : __('adminforms.invoices.btn_update')?>
                        <?php echo e(Form::submit($btntext, ['class' => 'btn btn-success pull-right'])); ?>

                    </div>
                </div>

            </div> <!-- /.col -->

            <?php if($create == 1): ?>
            <input type="hidden" name="ord_id" value="<?php echo e($order->ord_id); ?>">
            <?php endif; ?>

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


        </div>
        <!-- /.row -->



        <div class="modal fade" id="addprodmodal" role="dialog" aria-labelledby="exampleModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title text-center" id="exampleModalLabel">Dodavanje proizvoda</h4>
                    </div>
                    <div class="modal-body">
                        <form id="addprodform">
                            <div class="row text-center">
                                <br>
                                <div class="text center"><small>Unesite termin za pretragu proizvoda (sifra, naziv...)</small></div>
                                <br>
                                <div class="col-xs-12">
                                    <input type="text" name="prodsearch" id="prodsearch" class="form-control input-sm autocomplete_txt" autocomplete="off">
                                </div>
                                <br>
                                <br>
                                <br>
                                <div class="col-xs-12" id="prodsearchresults">
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" id="closeapm" class="btn btn-default" data-dismiss="modal">Otkaži</button>
                        <button type="button" class="btn btn-success" id="addprod"><i class="fa fa-plus-square"></i> Dodaj proizvod</button>
                    </div>
                </div>
            </div>
        </div>

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

<?php $__env->startPush('css'); ?>
    <link rel="stylesheet" href="<?php echo e(asset('assets/tags/jquery-ui-1.10.0.custom.css')); ?>">
    <link rel="stylesheet" href="<?php echo e(asset('assets/components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css')); ?>">
    <link rel="stylesheet" href="<?php echo e(asset('assets/css/invoice.css')); ?>">
    <style type="text/css">
        .modal-backdrop {
            z-index: 1000;
        }
        .modal {
            z-index: 1001;
        }
        .ui-front {
            z-index: 1002;
        }
        #invtable .input-sm {
            font-size: 13px;
            line-height: 1.5;
        }
        .modal-dialog {
            margin: 80px auto;
        }
    </style>

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


<?php $__env->startPush('scripts'); ?>
    <script src="<?php echo e(asset('assets/js/equalpbb.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/tags/jquery-ui.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/js/jquery_number_2.1.3.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/js/invoice.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js')); ?>"></script>
    <script src="<?php echo e(asset('assets/components/bootstrap-datepicker/dist/locales/bootstrap-datepicker.sr-latin.min.js')); ?>" charset="UTF-8"></script>
    <script>
        //Date picker
        $('#datepicker').datepicker({
            format: 'yyyy-mm-dd',
            todayHighlight: true,
            autoclose: true,
            language: "sr-latin",
            locale: "sr-latin",
        });
        $('#datepicker2').datepicker({
            format: 'yyyy-mm-dd',
            todayHighlight: true,
            autoclose: true,
            language: "sr-latin",
            locale: "sr-latin",
        });
    </script>
    <script type="text/javascript">
        $("#addprodmodal").on("show.bs.modal", function (event) {

            var button = $(event.relatedTarget);
            var modal  = $(this);

            modal.find("#prodsearch").val("");

            modal.find("#prodsearchresults").html("");

            setTimeout(function(){
                $("#prodsearch").focus();
            }, 500);
        })
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            var cv = $('#sa').val();
            if(cv == 0){$('#deldata').slideDown();}

            $('#sa').change(function () {
                var cval = $(this).val();
                if(cval == 1) {
                    $('#deldata').slideUp();
                } else {
                    $('#deldata').slideDown();
                }
            });
        });
    </script>

<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), array('__data', '__path')))->render(); ?>