@extends('layouts.app')

@section('title', 'Add Inventroy')

@section('content')

<div class="container-fluid">

    <!-- Page Heading -->
    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">Add Inventroy</h1>
        <a href="{{route('productlist.index')}}" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i
                class="fas fa-arrow-left fa-sm text-white-50"></i> Back</a>
    </div>

    {{-- Alert Messages --}}
    @include('common.alert')
   
    <!-- DataTales Example -->
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">Add New Inventroy</h6>
        </div>
        <div class="card-body">
            <form method="POST" action="{{route('productlist.storeinventory')}}">
                @csrf
                <div class="form-group row">

                    {{-- Item_code --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Item_Code</label>
                        <input 
                            type="text" 
                            class="form-control form-control-user @error('itemcode') is-invalid @enderror" 
                            id="Item_Code"
                            placeholder="code" 
                            name="itemcode" 
                            value="{{ old('itemcode') }}">

                        @error('itemcode')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- UPC --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>UPC</label>
                        <input 
                            type="text" 
                            class="form-control form-control-user @error('upc') is-invalid @enderror" 
                            id="UPC"
                            placeholder="upc" 
                            name="upc" 
                            value="{{ old('upc') }}">

                        @error('upc')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- ITEM --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Item_Name</label>
                        <input 
                            type="text" 
                            class="form-control form-control-user @error('item') is-invalid @enderror" 
                            id="Item_Name"
                            placeholder="item" 
                            name="item" 
                            value="{{ old('item') }}">

                        @error('item')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                   
                    {{-- DESCRIPTION --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Description</label>
                        <input 
                            type="text" 
                            class="form-control form-control-user @error('description') is-invalid @enderror" 
                            id="Description"
                            placeholder="Description" 
                            name="description" 
                            value="{{ old('description') }}">

                        @error('description')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- INTERNALDESCRIPT --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Internal_Description</label>
                        <input 
                            type="text" 
                            class="form-control form-control-user @error('internaldescript') is-invalid @enderror" 
                            id="Internal_Description"
                            placeholder="internaldescript" 
                            name="internaldescript" 
                            value="{{ old('internaldescript') }}">

                        @error('internaldescript')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- MEASUREMENT --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Measurement</label>
                        <input 
                            type="text" 
                            class="form-control form-control-user @error('measurement') is-invalid @enderror" 
                            id="Measurement"
                            placeholder="measurement" 
                            name="measurement" 
                            value="{{ old('measurement') }}">

                        @error('measurement')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- STOCKINHAND --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>StockInHand</label>
                        <input 
                            type="number" 
                            class="form-control form-control-user @error('stockinhand') is-invalid @enderror" 
                            id="stockinhand"
                            placeholder="stockinhand" 
                            name="stockinhand" 
                            value=0 >

                        @error('stockinhand')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                     
                    </div>
                   
                    {{-- CURRENCY --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Currency</label>
                        <input 
                            type="text" 
                            class="form-control form-control-user @error('currency') is-invalid @enderror" 
                            id="Currency"
                            placeholder="currency" 
                            name="currency" 
                            value="{{ old('currency') }}">

                        @error('currency')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- COST --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Cost</label>
                      <input 
                      
                            type="number" 
                            class="form-control form-control-user @error('Cost') is-invalid @enderror" 
                            id="Cost"
                            placeholder="Cost" 
                            name="Cost" 
                            value=0.00 
                           >
                          
                        @error('Cost')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- MRPPRICE --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>MRP_Price</label>
                        <input 
                            type="number" 
                            class="form-control form-control-user @error('mrpprice') is-invalid @enderror" 
                            id="MRP_Price"
                            placeholder="mrpprice" 
                            name="mrpprice" 
                            value=0.00>

                        @error('mrpprice')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- RETAILPRICE --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Retail_Price</label>
                        <input 
                            type="number" 
                            class="form-control form-control-user @error('rprice') is-invalid @enderror" 
                            id="Retail_Price"
                            placeholder="rprice" 
                            name="rprice" 
                            value=0.00>

                        @error('rprice')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- WHOLESALEPRICE --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Wholesale_Price</label>
                        <input 
                            type="number" 
                            class="form-control form-control-user @error('wprice') is-invalid @enderror" 
                            id="Wholesale_Price"
                            placeholder="wprice" 
                            name="wprice" 
                            value=0.00>

                        @error('wprice')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- STOCKVALUE --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Stock_Value</label>
                        <input 
                            type="number" 
                            class="form-control form-control-user @error('stockvalue') is-invalid @enderror" 
                            id="stockvalue"
                            placeholder="stockvalue" 
                            name="stockvalue" 
                            value=0.00 readonly>

                        @error('stockvalue')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>

                    {{-- ORDERLEVEL --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Order_Level</label>
                        <input 
                            type="number" 
                            class="form-control form-control-user @error('orderlevel') is-invalid @enderror" 
                            id="Order_Level"
                            placeholder="orderlevel" 
                            name="orderlevel" 
                            value=0>

                        @error('orderlevel')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    
                    {{-- SERIALIZED --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Serializable</label>
                        <select class="form-control form-control-user @error('serializable') is-invalid @enderror" name="serializable">
                            <option selected disabled>Select....</option>
                            <option value="1" selected>YES</option>
                            <option value="0">NO</option>
                        </select>
                        @error('serializable')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                   
                    {{-- Status --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Status</label>
                        <select class="form-control form-control-user @error('status') is-invalid @enderror" name="status">
                            <option selected disabled>Select Status</option>
                            <option value="1" selected>YES</option>
                            <option value="0">NO</option>
                        </select>
                        @error('status')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>

                
                
                    {{-- ENTITY --}}
                    <div class="col-sm-6 mb-3  mb-sm-0">
                        <span style="color:red;">*</span>Warehouses</label> 
                        <select class="form-control form-control-user @error('entityid') is-invalid @enderror" name="entityid">
                            <option selected disabled>Select Warehouse</option>
                            @foreach ($warehouses as $wrows) 
                                <option value="{{$wrows->id}}">{{$wrows->name}}</option>
                            @endforeach
                        </select>
                        @error('entityid')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
               
                {{-- MANUFACTURED --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Manufactured </label>
                        <select class="form-control form-control-user @error('Manufactured') is-invalid @enderror" name="Manufactured">
                            <option selected disabled>Select</option>
                            <option value="1" selected>YES</option>
                            <option value="2">NO</option>
                        </select>
                        @error('Manufactured')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
                    {{-- CATEGORY --}}
                    <div class="col-sm-6 mb-3  mb-sm-0">
                        <span style="color:red;">*</span>Category</label> 
                        <select class="form-control form-control-user @error('categoryid') is-invalid @enderror" name="categoryid">
                            <option selected disabled>Select Category</option>
                            @foreach ($categories as $rows) 
                                <option value="{{$rows->id}}">{{$rows->category}}</option>
                            @endforeach
                        </select>
                        @error('categoryid')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>
               
                
        
                {{-- FOR_SALES --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>For_Sales </label>
                        <select class="form-control form-control-user @error('forsales') is-invalid @enderror" name="forsales">
                            <option selected>Select_Purpose</option>
                            <option value="1" selected>YES</option>
                            <option value="2">NO</option>
                        </select>
                        @error('forsales')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>

               
                {{-- TYPE --}}
                    <div class="col-sm-6 mb-3 mb-sm-0">
                        <span style="color:red;">*</span>Product_Type </label>
                        <select class="form-control form-control-user @error('type') is-invalid @enderror" name="type">
                            <option selected>Select_Purpose</option>
                            <option value="1" selected>Primary_Item</option>
                            <option value="2">secondary_Item</option>
                        </select>
                        @error('type')
                            <span class="text-danger">{{$message}}</span>
                        @enderror
                    </div>

                    </div>
           
           
                {{-- Save Button --}}
                <button type="submit" class="btn btn-success btn-user btn-block">
                    Save
                </button>

            </form>
        </div>
    </div>

</div>
@endsection
@section('scripts')


    <script>
$('#stockinhand, #Cost').keyup(function(){
    var st = parseFloat($('#stockinhand').val()) || 0;
    var cst = parseFloat($('#Cost').val()) || 0;

    $('#stockvalue').val(st * cst);    
});
</script>
<script>
    $('#stockinhand, #Cost').change(function(){
    var st = parseFloat($('#stockinhand').val()) || 0;
    var cst = parseFloat($('#Cost').val()) || 0;

    $('#stockvalue').val(st * cst);    
});
    </script>
@endsection