<?php
Fun::lang();
$unit = getUnit('material')->pluck('unit', 'id');
$category = getCategory('material')->pluck('category_name', 'id');
?>
<div class=" col-sm-12 col-xs-12">
    <div class="col-sm-2 col-xs-12 ">
        <label class="required" for="name"><?php echo e(__('administrator.item_name')); ?> </label>
    </div>
    <div class="col-sm-10 col-xs-12">
        <?php echo Form::text('product_name', null, array('placeholder' => __('administrator.item_name'),'class' => 'form-control input-sm','','maxlength'=>'50')); ?>

    </div>
</div>
<div class=" col-sm-12 col-xs-12">
    <div class="col-sm-2 col-xs-12 ">
        <label class="required" for="name"><?php echo e(__('administrator.barcode')); ?> </label>
    </div>
    <div class="col-sm-10 col-xs-12">
        <?php echo Form::text('barcode', null, array('placeholder' => __('administrator.barcode'),'class' => 'form-control input-sm','','maxlength'=>'50')); ?>

    </div>
</div>
<div class=" col-sm-12 col-xs-12">
    <div class="col-sm-2 col-xs-12 ">
        <label for="name" class="required"><?php echo e(__('administrator.category')); ?></label>
    </div>
    <div class="col-sm-10 paddin-0">
        <div class="col-sm-12">
            <?php echo Form::select('category_id', $category, null, ['placeholder' => __('administrator.please_select'),'class' => 'form-control select2','id'=>'category_id','']); ?>

        </div>
    </div>
</div>
<div class=" col-sm-12 col-xs-12">
    <div class="col-sm-2 col-xs-12 ">
    </div>
    <div class="col-sm-10">
        <table class="table table-bordered">
            <thead>
            <tr>
                <th>#</th>
                <th width="20%"><label class="required"><?php echo e(__('administrator.unit')); ?></label>
                </th>
                <th style="white-space: nowrap"><label class="required"><?php echo e(__('administrator.qty_per_unit')); ?></label>
                </th>
                <th><label class="required"><?php echo e(__('administrator.cost')); ?>(៛)</label></th>
                <th><label class="required"><?php echo e(__('administrator.cost')); ?>($)</label></th>
                <th><label class="required"><?php echo e(__('administrator.tailor_price')); ?>(៛)</label></th>
                <th><label class="required"><?php echo e(__('administrator.tailor_price')); ?>($)</label></th>
                <th style="text-align: center">
                    <a class="button_info fa fa-plus" id="add_unit"></a>
                </th>
            </tr>
            </thead>
            <tbody id="tbody">
            <?php if(@$product): ?>
                <?php $__currentLoopData = $product->get_product_unit; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $select_color = \App\Model\product\ProductUnitModel::where('product_id', $row->product_id)
                           ->where('cost', $row->cost)
                           ->where('wholesale_price', $row->wholesale_price)
                           ->where('retail_price', $row->retail_price)
                           ->groupBy('product_id');
                    ?>
                    <tr class="tr<?php echo e($key+1); ?>">
                        <td style="text-align: center"><?php echo e($key+1); ?></td>
                        <td><?php echo Form::select('unit_id[]', $unit, $row->unit_id, ['placeholder' => __('administrator.please_select'),'class' => 'form-control select2','required']); ?></td>
                        <td><?php echo Form::text('qty[]', $row->qty_per_unit, array('placeholder' => __('administrator.qty_per_unit'),'class' => 'form-control input-sm number-only')); ?></td>
                        <td><?php echo Form::text('cost_riel[]', $row->cost_riel, array('placeholder' => __('administrator.cost'),'class' => 'form-control input-sm number-only','required')); ?></td>
                        <td><?php echo Form::text('cost_usd[]', $row->cost_usd, array('placeholder' => __('administrator.cost'),'class' => 'form-control input-sm number-only','required')); ?></td>
                        <td><?php echo Form::text('tailor_price_riel[]', $row->tailor_price_riel, array('placeholder' => __('administrator.tailor_price'),'class' => 'form-control input-sm number-only','required')); ?></td>
                        <td><?php echo Form::text('tailor_price_usd[]', $row->tailor_price_usd, array('placeholder' => __('administrator.tailor_price'),'class' => 'form-control input-sm number-only','required')); ?></td>
                        <td style="text-align: center"><span class="cursor button_danger fa remove_row fa-close"></span>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php endif; ?>
            </tbody>
        </table>
        <div class="col-sm-12">
            <?php echo e(__('administrator.unit_note')); ?>

        </div>
    </div>
</div>
<div class="col-sm-10 col-sm-offset-2">
    <div class="form-group" id="drop-area">
        <input id="input-44" type="file" name="gallery" class="">
    </div>
</div>
<?php echo Form::submit('Submit', ['class' => 'hidden']); ?>


<?php $__env->startSection('jq'); ?>
    <script>
        <?php if(!@$product): ?>
        add_unit();
        <?php endif; ?>
        function add_unit() {
            let count = $('#tbody tr').length;
            let row = '<tr class=" tr' + (count + 1) + '">' +
                '<td>' + (count + 1) + '</td>' +
                '<td class="append_select">' +
                '<?php echo Form::select('unit_id[]', $unit, null, ['placeholder' => __('administrator.please_select'),'class' => 'form-control select2','required']); ?></td>' +
                '<td><input value="1" name="qty[]" type="text" class="form-control input-sm number-only" placeholder="<?php echo e(__('administrator.qty_per_unit')); ?>" required></td>' +
                '<td><input name="cost_riel[]" type="text" class="form-control input-sm number-only" placeholder="<?php echo e(__('administrator.cost')); ?>" required></td>' +
                '<td><input name="cost_usd[]" type="text" class="form-control input-sm number-only" placeholder="<?php echo e(__('administrator.cost')); ?>" required></td>' +
                '<td><input name="tailor_price_riel[]" type="text" class="form-control input-sm number-only" placeholder="<?php echo e(__('administrator.tailor_price')); ?>" required></td>' +
                '<td><input name="tailor_price_usd[]" type="text" class="form-control input-sm number-only" placeholder="<?php echo e(__('administrator.tailor_price')); ?>" required></td>' +
                '<td style="text-align: center"><span class="cursor button_danger fa fa-close remove_row" ></span></td>' +
                '</tr>';
            $('#tbody').append(row);
            $('.select2').select2()
        }

        $(document).ready(function () {
            $('#add_unit').on('click', function () {
                add_unit();
            });
            $(document).on('click', '.remove_row', function () {
                $(this).closest("tr").remove();
            });
        });

    </script>
<?php $__env->stopSection(); ?><?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/administrator/setup-item/product-material/form.blade.php ENDPATH**/ ?>