@extends('layouts.dashboard')

@section('page_title')
	Purchase Items
@endsection

@section('page_header_title')
    Purchase Items
@endsection



@section('page_body')
{{ Breadcrumbs::render('invoice') }}


<div class="row row-cards row-deck">
    <div class="col-12">
        <div class="card">
                <div class="card-header">
                    <a  class="float-right btn btn-sm btn-outline-primary" href="{{route('invoicecommit')}}"><i class="fa fa-plus"></i></a> &nbsp;&nbsp;

                    <h3 class="card-title">Add Purchase Invoice</h3>
                </div>

        <div class="card-status card-status-left bg-blue"></div>
            <div class="table-responsive table-height">
                <table class="table table-sm table-hover table-outline table-vcenter text-nowrap card-table cls_datatable">
                <thead>
                    <tr>

                    <th>#</th>
                    <th>Invoice No</th>
                    <th>Vendor</th>
                    <th>Project</th>
                    <th>Item Code</th>
                    <th>Description</th>
                    <th>Amount </th>
                    <th>Received Amount </th>
                    <th>Status</th>
                    <th>Due Date</th>
                    <th>Date</th>
                    <th style="text-align: center;"><i class="dropdown-icon fa fa-cogs"></i></th>

                    </tr>
                </thead>
                <tbody>
                @foreach($invoice_list as $rows)
                    <tr>
                        <td>{{$loop->iteration}}</td>

                        <td>{{$rows->invoice_no}}</td>

                        <td>{{$rows->user->name}}</td>

                        <td>{{$rows->branch->name}}</td>

                        <td>{{implode(',',$rows->purchaseItems->pluck('item_code')->toArray())}}</td>

                        <td>{!! wordwrap($rows->description,30,"<br>\n") !!}</td>



                        <td>{{EF::numberFormat($rows->amount)}}</td>

                        <td>{{EF::numberFormat($rows->received_amount)}}</td>

                        <td>{{$rows->status}}</td>

                        <td>{{EF::dateFormat($rows->due_date)}}</td>

                        <td>{{EF::dateFormat($rows->created_at)}}</td>


                        <td class="text-center">

                            <div class="item-action dropdown">
                                <a href="javascript:void(0)" data-toggle="dropdown" class="icon"><i class="fa fa-list-ul"></i></a>
                                <div class="dropdown-menu dropdown-menu-right">

                                @if($rows->received_amount == 0)   
                                {{-- --}}
                                <a href="{{route('invoiceupdate',['id' => Crypt::encrypt($rows->id)])}}" class="dropdown-item"><i class="dropdown-icon fa fa-edit"></i> Update </a>
                                
                                <a href="{{route('invoice.trash',['id' => Crypt::encrypt($rows->id)])}}" content="remove purchase item" class="dropdown-item cls_delete"><i class="dropdown-icon fa fa-trash"></i> Delete </a>

                                @endif

                                {{--
                                @if($rows->status == "Unpaid")
                                <a href="#" id="pay" class="dropdown-item" onclick="showPayPaymentModel(event,'{{Crypt::encrypt(EF::getGenericTableIndex()['Invoice'])}}','{{Crypt::encrypt($rows->id)}}')"><i class="dropdown-icon fa fa-money"   ></i> Pay </a>
                                @endif
                                --}}

                                <a target="_blank" href="{{route('document.print_invoice',['id' => Crypt::encrypt($rows->id)])}}"  class="dropdown-item "><i class="dropdown-icon  fa fa-print"></i> Invoice </a>

                            </div>
                        </div>
                        </td>
                    </tr>
 
                    @endforeach

                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
          </div>
@endsection

@section('page_modal')
<div id="modal_add_payment"> </div>

@endsection

@section('page_script')
<script>
    function showPayPaymentModel(event,generic_type,generic)
    {
        event.preventDefault();

    var route = "{{url('showpayinvoice')}}/"+generic_type+"/"+generic;

         showLoader();

        $.get(route, function(data, status)
        {
            $('#modal_add_payment').html(data);

            $('#md_add_payment').modal('show');

            removeLoader();

        });
    }


</script>

@endsection

