@extends('layouts.dashboard')
@section('page_title')
	GRN
@endsection
@section('page_header_title')
	GRN
@endsection
@section('page_body')
{{ Breadcrumbs::render('grn.generate') }}
@php($label_list = EF::getWhiteLabel())
 <div class="my-3 my-md-5">
          <div class="container">
            <div class="row">
              <div class="col-md-12">
                <div class="card">
                  <div class="card-header">
                    <h3 class="card-title"><b>GRN</b> </h3>
                  </div>

                  <div class="card-body">
                    <div class = "card">
                      <div class ="card-body">
                        <div class ="row">
                          <div class="col-md-5">
                            <div class="row">
                            <h4 class="col-md-12" style="background:#656877;padding:5px;color:white">Vendor Detail</h4>
                            <div class="col-md-12">
                              <table style="width:100%">
                                <tr>
                                  <th>Name</th>
                                  <td>{{$po_detail[0]->user->name}}</td>
                                </tr>
                                <tr>
                                  <th>Type</th>
                                  <td>{{$po_detail[0]->user->type}}</td>
                                </tr>
                                <tr>
                                  <th>Email</th>
                                  <td>{{$po_detail[0]->user->email}}</td>
                                </tr>
                                <tr>
                                  <th>Contact</th>
                                  <td>{{$po_detail[0]->user->contact}}</td>
                                </tr>
                                <tr>
                                  <th>Address</th>
                                  <td>{{$po_detail[0]->user->per_address}}</td>
                                </tr>
                              </table>
                            </div>
                          </div>
                        </div>
                        <div class="col-md-2"></div>
                        <div class="col-md-5">
                          <div class="row">
                          <h4 class="col-md-12" style="background:#656877;padding:5px;color:white">Puchase Order Detail</h4>
                          <div class="col-md-12">
                            <table style="width:100%">
                              <tr>
                                <th>PO Number</th>
                                <td>{{$po_detail[0]->p_number}}</td>
                              </tr>
                              <tr>
                                <th>Created At</th>
                                <td>{{EF::dateFormat($po_detail[0]->created_at)}}</td>
                              </tr>
                              <tr>
                                <th>BOQ Number</th>
                                <td>{{$po_detail[0]->boq->sr_no}}</td>
                              </tr>
                              <tr>
                                <th>BOQ Remarks</th>
                                <td>{{$po_detail[0]->boq->remarks}}</td>
                              </tr>
                            </table>
                          </div>
                        </div>
                      </div>
                        </div>
                        <!-- <hr style="width:100%;border-top:1px solid #1c35b6"> -->
                        <div class ="row">
                          <div class="col-md-12">
                            <table style="width:100%" class="table table-bordered">
                              <thead style="background:#656877;">
                                <tr>
                                  <th>#</th>
                                  <th>Item</th>
                                  <th>Description</th>
                                  <th>Remarks</th>
                                  <th>Qty</th>
																	<th>Received Qty</th>
																	<th>Status</th>

                                </tr>
                              </thead>
                              <tbody>
																@foreach($po_detail as $row)
                                <tr>
                                  <td>1</td>
                                  <td>{{$row->boqitem->item->name}}</td>
                                  <td>{{$row->boqitem->item->description}}</td>
                                  <td>{{$row->boqitem->item_description}}</td>
                                  <td>{{$row->boqitem->quantity}}</td>
																	<th>{{$row->getGRNPO->sum('accepted_quantity')}}</th>
																	@if($row->getGRNPO->sum('accepted_quantity') == $row->boqitem->quantity)
																	<th><i class="fa fa-check" style="color:green"></i> Done</th>
																	@else
																	<th> Pending</th>
																	@endif
                                </tr>
																@endforeach
                              </tbody>
                            </table>
                          </div>
                        </div>
 <h5>Details for Receving Notes</h5>
 {{ Form::open(array('route' => 'grn.commit', 'id' => 'grn_commit', 'class' => 'cls_from ', 'enctype' => 'multipart/form-data' , 'method' => 'post')) }}
                        <div class ="row">
                          <div class="col-md-12">
                            <table style="width:100%" class="table table-bordered">
                              <thead>
                                <tr>
                                  <th>#</th>
                                  <th>Item</th>
                                  <th>Description</th>
                                  <th>Total quantity</th>
                                  <th>Received quantity</td>
                                  <th>Received By</th>
                                </tr>
                              </thead>
                              <tbody>

																	@foreach($po_detail as $row)
																	@if($row->getGRNPO->sum('accepted_quantity') != $row->boqitem->quantity)
																	<tr>
															    <td>1</td>
                                  <td>{{$row->boqitem->item->name}}</td>
                                  <td>{{$row->boqitem->item->description}}</td>
                                  <td>{{$row->boqitem->quantity - $row->getGRNPO->sum('accepted_quantity')}}</td>
                                  <td><input id="accept_qty" onkeyup="setValues()" step="0.01" type="number" min="0" max="{{$row->boqitem->quantity - $row->getGRNPO->sum('accepted_quantity')}}" required value="0" name="accept_qty[]" class="form-control"/></td>

                                  <td>
                                        <select class="form-control form-control-sm" name= "received_by[]">

                                           @foreach($employee_list as $rows)
                                             <option value="{{Crypt::encrypt($rows->id)}}">{{ucfirst($rows->name)}} | {{$rows->designation->title}}</option>
                                           @endforeach
                                         </select>

                                  </td>
                                </tr>
																<input type="hidden" value="{{$row->id}}" name="po_number[]"/>
																@endif
																@endforeach
                              </tbody>
                            </table>

                          </div>
                          <div class="col-md-12">
                            <input type="submit" class="btn btn-success" value="Submit GRN"/>
                          </div>
                        </div>
{{ Form::close() }}
                      </div>
                    </div>
                </div>
                </div>
              </div>
            </div>
            </div>
          </div>


@endsection

@section('page_modal')

@endsection

@section('page_script')
@include('inventory_module.scripts.grn')
@endsection
