<?php echo $__env->make('admin::layouts.header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php
use App\Models\Supliers;
use App\Models\Products;
?>
<main id="main-container">
        <!-- Hero -->
        <div class="bg-body-light">
          <div class="content content-full">
            <div class="d-flex flex-column flex-sm-row justify-content-sm-between align-items-sm-center">
              <h1 class="flex-grow-1 fs-3 fw-semibold my-2 my-sm-3">Add GRN</h1>
              <nav class="flex-shrink-0 my-2 my-sm-0 ms-sm-3" aria-label="breadcrumb">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item">Dashboard</li>
                  <li class="breadcrumb-item">GRN</li>
                  <li class="breadcrumb-item active" aria-current="page">Add GRN</li>
                </ol>
              </nav>
            </div>
          </div>
        </div>
        <!-- END Hero -->

        <!-- Page Content -->
        <div class="content">
          <!-- Your Block -->
          <div class="block block-rounded">
            <div class="block-header block-header-default">
              <h3 class="block-title">Add GRN</h3>
            </div>
            <div class="block-content">
            <?php if(Session::has('success')): ?> <div class="alert alert-success mt-2 mb-2"><?php echo e(Session::get('success')); ?></div><?php endif; ?>
            <?php if(Session::has('fail')): ?> <div class="alert alert-danger mt-2 mb-2"><?php echo e(Session::get('fail')); ?></div><?php endif; ?>
            <form class="row" action="" method="POST" >
            <?php echo csrf_field(); ?>
                    <div class="col-md-3 mb-3">
                      <label class="form-label">GRN Number</label>
                      <input type="text" class="form-control" name="grn_number" value="<?php echo e($grnNumber); ?>" readonly>
                      <?php if($errors->has("grn_number")): ?> <div class="alert alert-danger mt-2"><?php echo e($errors->first('grn_number')); ?></div><?php endif; ?>
                    </div>
                    <div class="col-md-3 mb-3">
                    <label class="form-label">Suplier</label>
                    <select class="js-select2 form-select" id="suplier" name="suplier" style="width: 100%;" data-placeholder="Select a suplier..">
                    <?php if(old('suplier')) { ?> 
                        <option value="<?php echo e(old('suplier')); ?>"><?php echo e(Supliers::where('id', old('suplier'))->value('suplier_name')); ?></option>
                    <?php } ?>
                    <option></option>
                    <?php foreach($supliers as $suplier){ ?> 
                        <option value="<?php echo e($suplier->id); ?>"><?php echo e($suplier->suplier_name); ?></option>
                    <?php } ?>
                    </select>
                      <?php if($errors->has("suplier")): ?> <div class="alert alert-danger mt-2"><?php echo e($errors->first('suplier')); ?></div><?php endif; ?>
                    </div>
                    <div class="col-md-3 mb-3">
                      <label class="form-label">Purchase Order Number</label>
                      <input type="text" class="form-control" name="purchase_order_number" value="<?php echo e(old('purchase_order_number')); ?>">
                      <?php if($errors->has("purchase_order_number")): ?> <div class="alert alert-danger mt-2"><?php echo e($errors->first('purchase_order_number')); ?></div><?php endif; ?>
                    </div>

                    <div class="col-md-3 mb-3">
                      <label class="form-label">Received Date</label>
                      <input type="date" class="form-control" name="received_date" value="<?php echo e(old('received_date')); ?>">
                      <?php if($errors->has("received_date")): ?> <div class="alert alert-danger mt-2"><?php echo e($errors->first('received_date')); ?></div><?php endif; ?>
                    </div>
                    <div class="col-md-3 mb-3">
                    <label class="form-label">Warehouse Location</label>
                      <select class="js-select2 form-select" id="warehouse_location" name="warehouse_location" style="width: 100%;" data-placeholder="Select a warehouse..">
                    <?php if(old('warehouse_location')) { ?> 
                        <option value="<?php echo e(old('warehouse_location')); ?>"><?php echo e(old('warehouse_location')); ?></option>
                    <?php } ?>
                      <option></option>
                      <option value="Home">Home</option>
                    </select>
                      <?php if($errors->has("warehouse_location")): ?> <div class="alert alert-danger mt-2"><?php echo e($errors->first('warehouse_location')); ?></div><?php endif; ?>
                    </div>
                    <div class="col-md-3 mb-3">
                      <label class="form-label">Inspector Name</label>
                      <input type="text" class="form-control" name="inspector_name" value="<?php echo e(old('inspector_name')); ?>">
                      <?php if($errors->has("inspector_name")): ?> <div class="alert alert-danger mt-2"><?php echo e($errors->first('inspector_name')); ?></div><?php endif; ?>
                    </div>
                    <div class="col-md-12 mb-3">
                      <label class="form-label">Notes</label>
                     <textarea  class="form-control" name="notes" rows="3"><?php echo e(old('notes')); ?></textarea>
                      <?php if($errors->has("notes")): ?> <div class="alert alert-danger mt-2"><?php echo e($errors->first('notes')); ?></div><?php endif; ?>
                    </div>
                     <div>
                     <button type="button" class="btn btn-success me-1 mt-1" onclick="AddMoreProducts()">
                            <i class="fa fa-fw fa-plus me-1"></i> Add Product
                    </button>
                    <div class="table-responsive">
                            <table class="table table-bordered table-striped table-vcenter mt-4">
                                <thead>
                                    <tr>
                                        <th>Product</th>
                                        <th>Quantity</th>
                                        <th>Wholesale Purchase Price</th>
                                        <th>Wholesale Selling Price</th>
                                        <th>Retail Selling Price</th>
                                        <th></th>
                                    </tr>
                                </thead>
                                <tbody id="products-tbody">
                                    <tr>
                                        <td>
              
                                            <select class="js-select2 form-select product-select" name="product[]" style="width: 100%;" data-placeholder="Select a product.." required>
                                                <option></option>
                                                <?php foreach($products as $product){ ?> 
                                                    <option value="<?php echo e($product->id); ?>"><?php echo e($product->product_name); ?></option>
                                                <?php } ?>
                                            </select>
                                        </td>
                                        <td>
                                            <input type="number" class="form-control" name="quantity[]" required>
                                        </td>
                                        <td>
                                           <input type="number" class="form-control" name="wholesale_purchase_price[]" required>
                                        </td>
                                        <td>
                                             <input type="number" class="form-control" name="wholesale_selling_price[]" required>
                                        </td>
                                       <td>
                                             <input type="number" class="form-control" name="retail_selling_price[]" required>
                                        </td>
     
                                        <td >   <button type="button" class="btn btn-danger btn-xs btn-remove">
                                               X
                                            </button></td>
                                    </tr>
                                </tbody>
                              
                            </table>
                        </div>
                    </div>
                    <div>

                      <button type="submit" class="btn btn-primary">Save</button>
                    </div>
                  </form>
            </div>
          </div>
          <!-- END Your Block -->
        </div>
        <!-- END Page Content -->
</main>
<!-- END Main Container -->
<?php echo $__env->make('admin::layouts.footer', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<script>
    function AddMoreProducts() {
        var newRow = `<tr>
                                        <td>
              
                                            <select class="js-select2 form-select product-select" name="product[]" style="width: 100%;" data-placeholder="Select a product.." required>
                                                <option></option>
                                                <?php foreach($products as $product){ ?> 
                                                    <option value="<?php echo e($product->id); ?>"><?php echo e($product->product_name); ?></option>
                                                <?php } ?>
                                            </select>
                                        </td>
                                        <td>
                                            <input type="number" class="form-control" name="quantity[]" required>
                                        </td>
                                        <td>
                                           <input type="number" class="form-control" name="wholesale_purchase_price[]" required>
                                        </td>
                                        <td>
                                             <input type="number" class="form-control" name="wholesale_selling_price[]" required>
                                        </td>
                                       <td>
                                             <input type="number" class="form-control" name="retail_selling_price[]" required>
                                        </td>
     
                                        <td >   <button type="button" class="btn btn-danger btn-xs btn-remove">
                                               X
                                            </button></td>
                                    </tr>`;
        $('#products-tbody').append(newRow);

        // Initialize select2 for new elements
        $('.js-select2').select2();


    }
    
        document.getElementById('products-tbody').addEventListener('click', function(event) {
        if (event.target.matches('.btn-remove, .btn-remove *')) {
            removeRow(event);
        }
    });
    function removeRow(event) {
        const button = event.target;
        const row = button.closest('tr');
        row.remove();
    }
</script><?php /**PATH /var/www/erpadmin_ori_usr/data/www/erpadmin.orionux.xyz/Modules/Admin/resources/views/grn/add_grn.blade.php ENDPATH**/ ?>