@extends('layouts.dashboard')

@section('page_title')
	Vendor Ledger Report
@endsection

@section('page_header_title')
    Vendor Ledger Report
@endsection



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

<div class="row">
    <div class="col-md-12">
                <div class="card">
                  <div class="card-header">
                    <h3 class="card-title">
                        <span class="fa fa-filter"></span>&nbsp;Filters
                        
                    </h3>
                    <div class="card-options">
                     {{ Form::open(['route' => 'vendorreport','target' => '_blank']) }}
                         <div class="btn-group-vertical push mr-3 float-right" role="group" aria-label="horizantal Outline Primary">
                                    <input type="hidden" name="pdf" value="1">
                                    <input type="hidden" name="to" @if(isset($to)) value="{{$to}} @endif">
                                    <input type="hidden" name="from" @if(isset($from)) value="{{$from}} @endif">

                                    <input type="hidden" name="user" @if(isset($user_id)) value="{{Crypt::encrypt($user_id)}}" @else value="{{Crypt::encrypt(0)}}"  @endif>

                                    <input type="hidden" name="project" @if(isset($project_id)) value="{{Crypt::encrypt($project_id)}}" @else value="{{Crypt::encrypt(0)}}"  @endif>

                                    <input type="hidden" name="flag" value="{{$flag}}">

                                    <input type="hidden" name="all_vendor_flag" value="{{$all_vendor_flag}}">



                                    <button type="submit" class="btn btn-sm btn-outline-primary"><span class="fa fa-file-pdf"></span> Export PDF</button>
                                </div>
                        {{ Form::close() }}
                      <a href="#" class="card-options-collapse" data-toggle="card-collapse"><i class="fe fe-chevron-up"></i></a>
                      <a href="#" class="card-options-remove" data-toggle="card-remove"><i class="fe fe-x"></i></a>

                    </div>
                  </div>
                  <div class="card-body">
                     {{ Form::open(['route' => 'vendorreport']) }}

                <div class="row">


                @php($name  = 'from')
                @php($label = 'From')

                <div class="col-lg-3 col-md-3 col-sm-12">
                    <div class="form-group ">
                        <label for="example-text-input">{{$label}}</label>
                        <span class="text-danger">{{ $errors->first($name,":message") }} </span>
                        <input  type="date" class=" js-flatpickr form-control form-control-sm bg-white" id="example-text-input" name="{{$name}}" @if(isset($from)) value="{{($from)}}" @else value="{{old($name)}}" @endif  placeholder="Year-Date-Month" data-alt-input="true" data-date-format="Y-m-d" data-alt-format="Y-d-m">
                    </div>
                </div>

                @php($name  = 'to')
                @php($label = 'To')

                <div class="col-lg-3 col-md-3 col-sm-12">
                    <div class="form-group">
                        <label for="example-text-input">{{$label}}</label>
                        <span class="text-danger">{{ $errors->first($name,":message") }} </span>
                        <input type="date" class=" js-flatpickr form-control form-control-sm bg-white" id="example-text-input" name="{{$name}}" @if(isset($to)) value="{{($to)}}" @else value="{{old($name)}}" @endif  placeholder="Year-Date-Month" data-alt-input="true" data-date-format="Y-m-d" data-alt-format="Y-d-m">
                    </div>
                </div>

                
                 @php($name   = 'project')
                @php($label  = 'Select Project')

                <div class="col-lg-3 col-md-3 col-sm-12" >
                    <div class="form-group">
                        <label for="example-text-input">{{$label}}</label>
                        <span class="text-danger">{{ $errors->first($name,":message") }} </span>
                        <select   class="form-control form-control-sm fstdropdown-select" id="example-text-input" name="{{$name}}" value="{{old($name)}}" placeholder="{{$label}}">
                            <option value="{{Crypt::encrypt(0)}}"> {{$label}} </option>
                            @foreach($branch_list as $rows)
                                <option @if(isset($project_id) && trim($project_id) == $rows->id) selected @endif  value="{{Crypt::encrypt($rows->id)}}"> {{$rows->name}} </option>
                            @endforeach
                        </select>
                    </div>
                </div>

                 @php($name   = 'user')
                @php($label  = 'Select Vendor')

                <div class="col-lg-3 col-md-3 col-sm-12" >
                    <div class="form-group">
                        <label for="example-text-input">{{$label}}</label>
                        <span class="text-danger">{{ $errors->first($name,":message") }} </span>
                        <select   class="form-control form-control-sm fstdropdown-select" id="example-text-input" name="{{$name}}" value="{{old($name)}}" placeholder="{{$label}}">
                            <option value="{{Crypt::encrypt(0)}}"> {{$label}} </option>
                            @foreach($user_list as $rows)
                                <option @if(isset($user_id) && trim($user_id) == $rows->id) selected @endif  value="{{Crypt::encrypt($rows->id)}}"> {{$rows->name}} </option>
                            @endforeach
                        </select>

                        
                        
                    </div>

                   
                </div>
                <div class="col-sm-12">
                    <label class="float-right" style="margin-left:1%;">
                            <input @if($flag == true) checked @endif type="checkbox" name="flag">&nbsp;<b>Net Balance Report</b>
                        </label>&nbsp;&nbsp;
                        <label class="float-right" >
                            <input @if($all_vendor_flag == true) checked @endif type="checkbox" name="all_vendor_flag">&nbsp;<b>All Vendor Report</b>
                        </label>
                </div>



                <div class="col-lg-12 col-md-12 col-sm-12">

                    <div class="form-group">
                        
                        <button style="float: right" class="btn btn-primary ">Update Report</button>
                    </div>
                </div>
            </div>

            {{ Form::close() }}

           
                  </div>
               
                </div>
              </div>
</div>
<div class="row row-cards row-deck">
    <div class="col-12">
        <div class="card">
                <div class="card-header">
                    
                   


                    <h3 class="card-title" style="width: 100%;">
                    <span class="fa fa-users"></span> &nbsp;VENDORS / CONTRACTORS PAYABLE SUMMARY  &nbsp; 
                         @php($balance  = $ledger_list->sum('balance'))
                        <strong class="badge badge-info" style="float: right;">Net Balance: 
                            @if(($balance) > 0) 
                                {{EF::numberFormat(($balance))}} 
                            @else 
                                ({{EF::numberFormat(abs($balance))}})  
                            @endif
                        </strong>
                </h3>

                </div>
        <div class=" "></div>
            <div class="table-responsive table-height">
                <table class="table table-hover table-outline table-vcenter text-nowrap card-table table-sm">
                <thead>
                    <tr>
                        <th>#</th>
                        @if(($flag) == false)
                        <th>Date</th>
                        @endif
                        @if(($flag) == false)
                        <th>Voucher #</th>
                        @endif

                             <th>Project</th>

                        <th style="width:10%; @if(isset($user_id) && $user_id > 0) display: none; @endif">Vendor / Contractor Name</th>
                        @if(($flag) == false)
                            <th>Description </th>
                            <th>Cheque No. </th>

                        @endif
                        <th>(Payable) / Receivable</th>
                    </tr>
                </thead>
                <tbody>
                @foreach($ledger_list as $rows)
                    <tr>
                        <td>{{$loop->iteration}}</td>

                        @if($flag == false)
                            <td>{{EF::dateFormat($rows->created_at)}}</td>
                        @endif

                        @if(($flag) == false)
                            <td>
                                <a target="blank" href="{{route('document.voucherpreview',['id' => Crypt::encrypt($rows->transaction_id)])}}">{{$rows->transaction->voucher_type}}-{{$rows->transaction->voucher_number}}
                                </a>
                            </td>
                        @endif

                        @if(($all_vendor_flag == false))
                        <td>{{$rows->branch->code}} - {{$rows->branch->name}}</td>
                        @else
                        <td>
                            {!! EF::textWrap(implode(',',$rows->getVendorBranches($rows->user_id)),20) !!}</td>
                        @endif

                        <td style="@if(isset($user_id) && $user_id > 0) display: none; @endif">{!! EF::textWrap($rows->user->name,15) !!}</td>
                        @if(($flag) == false)
                            <td>{!! EF::textWrap($rows->narration,30) !!}</td>

                            <td>
                                @if($rows->mode == "Cash")
                                    Cash
                                @elseif(strlen(trim($rows->instrument)) <= 0)
                                    -
                                @else
                                    {{str_replace(' ','-',trim($rows->instrument))}}  {{EF::dateFormat($rows->instrument_date)}}

                                @endif
                            </td>

                        @endif

                        @if($rows->balance > 0)
                        <td>{{EF::numberFormat($rows->balance)}}</td>
                        @else
                        <td>({{EF::numberFormat(abs($rows->balance))}})</td>
                        @endif

                  
                    </tr>
 
                    @endforeach

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



