{{--Get the Page Format--}}
@extends('layouts.app')

{{--Set Page Title--}}
@section('title', 'Manage Old Inventory')

{{--Include any Internal JS Code--}}
@section('internal-js')
    <script>
        $(document).ready(function () {
            $('#example').DataTable( {
                dom: 'lBfrtip',
                buttons: [
                    { extend: 'excel', className: 'download-buttons' },
                    { extend: 'pdf', className: 'download-buttons' }
                ]
            } );
        });

    </script>
@endsection

{{--Include any Internal CSS Code--}}
@section('internal-css')
    <style>
        #example th, td {
            text-align: left;
            padding: 5px;
        }
        #example tr:hover {background-color: #a3aef6;}
    </style>
@endsection

{{--Control Page Header/Links--}}
@section('headers')
    @include('headers.inventory-header')
@endsection

{{--Set Page Heading--}}
@section('heading', 'Manage Inventory')
@section('searches')
@endsection
{{--Page Content Goes here--}}
@section('content')
    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'active')" id="defaultOpen">Manage Company Inventory</button>
    </div>

    <div class="tabcontent" id="active">
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <h3 class="error">
            Available Inventory Items
        </h3>
        <table id="example" class="display" style="width:100%; border-collapse: collapse">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Item Name</th>
                <th>Buying Price</th>
                <th>Minimum Selling Price</th>
                <th>Maximum Selling Price</th>
                <th>Date Created</th>
                <th>Created By</th>
                <th>Current Stock</th>
                <th>Stock Reminder Level</th>

            </tr>
            </thead>
            <tbody>
            @foreach($list as $row)
                <tr>
                    <td class="ar"></td>
                    <td><a href="{{url('inventory/'.$row->id)}}" target="_blank" class="inner" style="color: red; font-weight: bold">{{$row->name}}</a></td>
                    <td>{!! number_format($row->buying_price, 2) !!}</td>
                    <td><b class="error">{!! number_format($row->min_selling_price, 2) !!}</b></td>
                    <td><b class="success">{!! number_format($row->max_selling_price, 2) !!}</b></td>
                    <td>{!! date('d/m/Y H:i:s a', strtotime($row->created_at)) !!}</td>
                    <td>
                        @if($row->user)
                            {!! $row->user->firstName." ".$row->user->lastName !!}
                        @else
                            -
                        @endif
                    </td>
                    <td><b>{!! $row->itemInventory ? $row->itemInventory->sum('quantity') : 0 !!}</b></td>
                    <td>{!! Form::number('reminder-level', '', ['class'=>'input-text-height', 'onchange'=>'updateReminderLevel('.$row->id.')', 'style'=>'width: 80px; border:1px solid green']) !!}</td>
                </tr>
            @endforeach
            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Item Name</th>
                <th>Buying Price</th>
                <th>Minimum Selling Price</th>
                <th>Maximum Selling Price</th>
                <th>Date Created</th>
                <th>Created By</th>
                <th>Current Stock</th>
                <th>Stock Reminder Level</th>
            </tr>
            </tfoot>
        </table>
    </div>
@endsection

{{--System Hints Page--}}

@section('modal_heading')
    <h1>Manage Old Company Inventory</h1>
@endsection
@section('modal_title')
    <h3><u>Dashboard Functionalities</u></h3>
    <b>
        <ol>
            <li>View all Available Old Stock and Balances</li>
            <li>Export Old Inventory Listing</li>
        </ol>
    </b>
@endsection
