@extends('master.app')
@section('title', 'customer')
@section('body')
    <main class="app-content">
        <section class=" gradient-custom-2">
            <div class="">
                <div class="row d-flex justify-content-center align-items-center h-100">
                    <div class="col-md-12 col-xl-12">

                        <div class="card mask-custom">
                            <div class="card-body p-4 ">

                                <div class="row">
                                    <div class="col-md-12">
                                        <i class="fa fa-3x fa-search text-center"></i>
                                        <h6 class="text-center">Filter By any Attribute</h6>
                                        <br>
                                    </div>
                                    <div class="col-md-12">
                                       <form action="{{ route('stock.filter_find') }}" method="get">
                                        @method('get')
                                        <div class="row mb-4">
                                            <div class="col-md-3">
                                                <select id="p_category_id" type="text"
                                                    class="form-control @error('p_category_id') is-invalid @enderror"
                                                     name="p_category_id">
                                                    <option value="0">Choose Category</option>
                                                    @foreach ($p_category as $row)
                                                        <option value="{{ $row->id }}">{{ $row->title_ps }}</option>
                                                    @endforeach
                                                </select>
                                                @error('p_category_id')
                                                    <span class="invalid-feedback" role="alert">
                                                        <strong>{{ $message }}</strong>
                                                    </span>
                                                @enderror
                                            </div>

                                            <div class="col-md-3">
                                                <select id="unit_type_id" type="text"
                                                    class="form-control @error('unit_id') is-invalid @enderror"
                                                    name="unit_type_id">
                                                    <option value="0">Choose Unit Type</option>
                                                    @foreach ($units as $row)
                                                        <option value="{{ $row->id }}">{{ $row->title_ps }}</option>
                                                    @endforeach
                                                </select>
                                                @error('unit_type_id')
                                                    <span class="invalid-feedback" role="alert">
                                                        <strong>{{ $message }}</strong>
                                                    </span>
                                                @enderror
                                            </div>
                                            <div class="col-md-3">
                                                <select id="wieight_id" type="text"
                                                    class="form-control @error('wieight_id') is-invalid @enderror"
                                                    name="wieight_id">
                                                    <option value="0">Choose Wieight</option>
                                                    @foreach ($weights as $row)
                                                        <option value="{{ $row->id }}">{{ $row->title_ps }}</option>
                                                    @endforeach
                                                </select>
                                                @error('wieight_id')
                                                    <span class="invalid-feedback" role="alert">
                                                        <strong>{{ $message }}</strong>
                                                    </span>
                                                @enderror
                                            </div>


                                        </div>
                                        <div class="row mt-4">

                                            <div class="col-md-3">
                                                <!-- Text input -->
                                                <div class="form-outline mb-4">
                                                    <input type="number" id="qty" name="qty"   value="{{ old('qty') }}"
                                                        class="form-control" />
                                                    <label class="form-label" for="qty" >QTY</label>
                                                </div>
                                            </div>
                                            <div class="col-md-3">
                                                <div class="form-outline mb-4">
                                                    <input type="number" id="cost_price" name="cost_price"  value="{{ old('cost_price') }}"
                                                        class="form-control" />
                                                    <label class="form-label" for="cost_price">Cost Price</label>
                                                </div>
                                            </div>
                                            <div class="col-md-3">
                                                <div class="form-outline mb-4">
                                                    <input type="number" id="sale_price" name="sale_price"  value="{{ old('sale_price') }}"
                                                        class="form-control" />
                                                    <label class="form-label" for="sale_price">Sale price</label>
                                                </div>
                                            </div>
                                            <div class="col-md-3">
                                                <button type="submit" class="btn btn-block btn-rounded btn-primary btn-sm">Filter Your Critira</button>
                                            </div>
                                        </div>
                                       </form>


                                    </div>
                                </div>

                                <table class="table  mb-0 data_table">
                                    <thead>
                                        <tr>
                                            <th scope="col">#</th>
                                            <th scope="col">Cat</th>
                                            <th scope="col">Sub/Cat</th>
                                            <th scope="col">Unit</th>
                                            <th scope="col">Weight</th>
                                            <th scope="col">QTY</th>
                                            <th scope="col">CPI</th>
                                            <th scope="col">SPI</th>
                                            <th scope="col">Actions</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach ($stock as $row)
                                            <tr class="fw-normal">
                                                <th class="border-0">{{ $loop->iteration }}</th>
                                                <td class="border-0 align-middle">{{ $row->cats->title_ps }}</td>
                                                <td class="border-0 align-middle">{{ $row->sub_cats->title_ps }}</td>
                                                <td class="border-0 align-middle">{{ $row->unit_category->title_ps }}</td>
                                                <td class="border-0 align-middle">
                                                    <h6 class="mb-0"><span
                                                            class="badge bg-success">{{ $row->unit_wieght->title_ps }}</span>
                                                    </h6>
                                                </td>
                                                <td class="border-0 align-middle">{{ $row->quantity }}</td>
                                                <td class="border-0 align-middle">{{ $row->cost_per_qty }}</td>
                                                <td class="border-0 align-middle">{{ $row->sale_price_per_qty }}</td>

                                                <td class="border-0 align-middle">
                                                    <a href="{{ route('stocks.edit', $row->id) }}"
                                                        data-mdb-toggle="tooltip" title="Edit"><i
                                                            class="fas fa-edit fa-lg text-success me-3"></i></a>
                                                    <a href="#!" data-mdb-toggle="tooltip" class="btn-delete"
                                                        data-id='{{ $row->id }}' title="Remove"><i
                                                            class="fas fa-trash-alt fa-lg text-warning "></i></a>
                                                </td>
                                            </tr>
                                        @endforeach
                                        <form id="delete-form" action="" method="POST" style="display: none;">
                                            {{ csrf_field() }}
                                            {{ method_field('DELETE') }}
                                        </form>

                                    </tbody>
                                    {{ $stock->links('pagination::bootstrap-4') }}
                                </table>


                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </section>
    </main>
@endsection


@section('pageJs')
    <script type="text/javascript">
        $(".app-menu").removeClass("active");

        $(document).on("click", ".btn-delete", function() {
            var id = $(this).attr("data-id");
            swal({
                title: "Are you sure want to delete?",
                text: "...",
                type: "warning",
                showCancelButton: true,
                confirmButtonText: "Yes!",
                cancelButtonText: "No!",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function(isConfirm) {
                if (isConfirm) {
                    var url = "{{ route('stocks.destroy', '') }}" + "/" + id;
                    $('#delete-form').attr('action', url);
                    $("#delete-form").submit();
                } else {
                    swal("Cancelled", "Record not deleted", "error");
                    return false;
                }
            });
        });
    </script>
@endsection
