@extends('layouts.dashboard')
@section('page_title')
	GRN
@endsection
@section('page_header_title')
	GRN
@endsection
@section('page_body')
{{ Breadcrumbs::render('grn.view') }}
@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" style ="width:100%;" >
                    <div class ="row">
                      <div class = "col-md-4">
                      <div class = "card">
                      <div class ="card-body" >
                        {{ Form::open(array('route' => 'grn.generate', 'id' => 'grn_generate', 'class' => 'cls_from ', 'enctype' => 'multipart/form-data' , 'method' => 'get')) }}
                        <div class ="row">

													<div class="col-md-12">
														<label>Project</label>
													@php($branch_label = EF::branchWhiteLabel())
													<select name="{{$branch_label['module']}}" class="form-control form-control-sm cls_selection branch" id="b_id" onChange="getMyPO()">
														 <option value="{{Crypt::encrypt(0)}}">Select {{ucwords(str_replace('_',' ',$branch_label['module']))}}</option>
														@foreach($branch as $rows)
														@if(Auth::user()->usertoprojectCheck($rows->id) == 1 || Auth::user()->type="Super Admin")
															<option @if(isset($current_branch) && $rows->id === $current_branch) selected  @endif value="{{Crypt::encrypt($rows->id)}}">{{$rows->code}} {{$rows->name}}</option>
															@endif
														@endforeach
													</select>
												</div>

												<div class="col-md-12">
													<label>Vendor</label>

												<select name="vendor" class="form-control form-control-sm cls_selection" id="v_id1" onChange="getMyPO3()">
													 <option value="{{Crypt::encrypt(0)}}">Select Vendor</option>
													@foreach($user_list as $rows1)
														<option  value="{{Crypt::encrypt($rows1->id)}}">{{$rows1->name}}</option>
													@endforeach
												</select>
												</div>


                         					 <div class="col-md-12">
											<label>Please Select PO number</label>
                            					<select  class="form-control form-control-sm category_list select2" name= "po_number" required  id="item_list_vendor">

                              				</select>

                        				</div>
                      <br>
                        <div class="col-md-12" style="margin-top:10px;">


                          <input type="submit" value="Generate GRN"  class="form-control btn btn-success" />
                      </div>
                        </div>
                        {{ Form::close() }}
                      <br>
                        <!-- <hr style="width:100%;border-top:1px solid #1c35b6"> -->

                      </div>
                    </div>
                    </div>

					<div class = "col-md-4">
                      <div class = "card">
                      <div class ="card-body" >
                        {{ Form::open(array('route' => 'grn.generate', 'id' => 'grn_generate', 'class' => 'cls_from ', 'enctype' => 'multipart/form-data' , 'method' => 'get')) }}
                        <div class ="row">

						<div class="col-md-12">
							<label>Vendor</label>

						<select name="vendor" class="form-control form-control-sm cls_selection" id="v_id" onChange="getMyPO2()">
								<option value="{{Crypt::encrypt(0)}}">Select Vendor</option>
							@foreach($user_list as $rows1)
								<option  value="{{Crypt::encrypt($rows1->id)}}">{{$rows1->name}}</option>
							@endforeach
						</select>
					</div>

					<div class="col-md-12">
						<label>Please Select PO number</label>
						<select  class="form-control form-control-sm category_list select2" name= "po_number" required  id="item_list2">

						</select>

					</div>
                      <br>
                        <div class="col-md-12" style="margin-top:10px;">


                          <input type="submit" value="Generate GRN"  class="form-control btn btn-success" />
        	              </div>
                        </div>
                        {{ Form::close() }}
                      <br>
                        <!-- <hr style="width:100%;border-top:1px solid #1c35b6"> -->

                      </div>
                    </div>
                      </div>

					<div class = "col-md-4">
					<div class = "card">
					<div class ="card-body" >
						{{ Form::open(array('route' => 'grn.generate', 'id' => 'grn_generate', 'class' => 'cls_from ', 'enctype' => 'multipart/form-data' , 'method' => 'get')) }}
						<div class ="row">

							<div class="col-md-12">
								<label>Product</label>

							<select name="product" class="form-control form-control-sm cls_selection" id="product" onChange="getproduct()">
									<option value="{{Crypt::encrypt(0)}}">Select Product</option>
								@foreach($product_list as $pl)
									<option  value="{{Crypt::encrypt($pl->id)}}">{{$pl->name}}</option>
								@endforeach
							</select>
						</div>

					<div class="col-md-12">
						<label>Please Select PO number</label>
						<select  class="form-control form-control-sm category_list select2" name= "po_number" required  id="productpo">
							</select>

					</div>
				<br>
				<div class="col-md-12" style="margin-top:10px;">
					<input type="submit" value="Generate GRN"  class="form-control btn btn-success" />
				</div>
				</div>
					{{ Form::close() }}
				<br>
					<!-- <hr style="width:100%;border-top:1px solid #1c35b6"> -->

				</div>
			</div>
		</div>
        </div>

		</div>
		</div>
		</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">Good Receiving Notes (GRN)</h3>
							</div>
							<div class="card-status card-status-left bg-blue"></div>
							<div class="table-responsive table-height">
								<table class="table table-hover table-outline table-vcenter text-nowrap card-table cls_datatable">
									<thead>
										<tr>

											<th>#</th>
											<th>GRN No.</th>
										{{--<th>GRN Type</th> --}}
											<th>PO No.</th>
										{{--<th>BOQ No.</th> --}}
											<th>PR No.</th>
											<th>Total Qty</th>
											<th>Received Qty</th>
											<th>Received By</th>
											<th>Dated</th>
											<th>Project</th>
											<th>Status</th>
											<th>Actions</th>

										</tr>
									</thead>
									<tbody>
									{
										@if(isset($all_grn))
												@foreach($all_grn as $rows)
												<tr>
												<td>{{$loop->iteration}}</td>
												
												<td>
												@if($rows->status == "Approved")
													<input @if($rows->grn_status == 1) checked disabled @endif type="checkbox" name = "grn_invoice" onchange="showInvoiceModal(event,this);" value= "{{Crypt::encrypt($rows->id)}}"/> 
												@endif
												{{$rows->grn_number}}</>
											{{--<td>{{$rows->grn_type}}</td> --}}
												<td>{{$rows->purchaseOrder->p_number}}</td>
											{{--<td>{{$rows->purchaseOrder->boq->sr_no}}</td> --}}
												<td>RS/PR/000{{$rows->purchaseOrder->boq->id}}</td>
												<td>{{EF::numberFormat($rows->total_quantity)}}</td>
												<td>{{EF::numberFormat($rows->accepted_quantity)}}</td>
												<td>{{$rows->receiver->name}}</td>
												<td>{{EF::dateFormat($rows->receive_date)}}</td>
												<td>{{$rows->purchaseOrder->boq->branch->name}}</td>
												<td>

													@if($rows->status == "Pending")
														<span class="badge badge-danger"> Pending</span>
														@else
														@if($rows->grn_status == "1")
															<span class="badge badge-success"> {{$rows->status}}</span>
														@else
															<span class="badge badge-warning"> Pending for payable</span>
														@endif
													@endif
												</td>
												
												<td class="text-center">
												<a href="{{ route('downloadPDF.grn', Crypt::encrypt($rows->id))}}" target="_blank"><i class="fa fa-print"></i></a> &nbsp;
													<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->status == 'Pending')
															<a  href="{{route('mygrn.accept',['id' => Crypt::encrypt($rows->id)])}}"  class="dropdown-item cls_accept" content="Accept GRN"><i class="dropdown-icon fa fa-check "></i> Accept</a>
															<a  href="{{route('mygrn.reject',['id' => Crypt::encrypt($rows->id)])}}"  class="dropdown-item cls_delete" content="Reject GRN"><i class="dropdown-icon fa fa-trash "></i> Reject</a>
														@endif
															<a  href="{{route('viewdetail.grn',['id' => Crypt::encrypt($rows->id)])}}"  class="dropdown-item " target="_blank" content="Reject GRN"><i class="dropdown-icon fa fa-eye "></i> Details</a>
			
														</div>
													</div>
												</td>

												</tr>
												@endforeach
											@endif
											</tbody>
										</table>
									</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">Good Receiving Notes (GRN)</h3>
            </div>
                  <div class="card-status card-status-left bg-blue"></div>
                  <div class="table-responsive table-height">
                    <table class="table table-hover table-outline table-vcenter text-nowrap card-table cls_datatable">
                      <thead>
                        <tr>
							<th>#</th>
							<th>GRN Invoice</th>
							<th>GRN No.</th>
							<th>GRN Type</th> 
							<th>PO No.</th>
							<th>BOQ No.</th> 
							<th>PR No.</th>
							<th>Total Qty</th>
							<th>Received Qty</th>
							<th>Received By</th>
							<th>Dated</th>
							<th>Project</th>
							<th>Status</th>
							<th>Actions</th>
                        </tr>
                      </thead>
                      <tbody>
                        @if(isset($grn_list))
                        @foreach($grn_list as $rows)
                        <tr @if($rows->grn_status == "1") style="background-color:#e5d7d7" @endif>
                        <td>{{$loop->iteration}}</td>
                        <td>
                          <input @if($rows->grn_status == 1) checked disabled @endif type="checkbox" name = "grn_invoice" onchange="showInvoiceModal(event,this);" value= "{{Crypt::encrypt($rows->id)}}"/>

                        <td>{{$rows->grn_number}}</td>
                    	<td>{{$rows->grn_type}}</td> 
                        <td>{{$rows->purchaseOrder->p_number}}</td>
						<td>{{$rows->purchaseOrder->boq->sr_no}}</td>
						<td>RS/PR/000{{$rows->purchaseOrder->boq->id}}</td>
                        <td>{{EF::numberFormat($rows->total_quantity)}}</td>
                        <td>{{EF::numberFormat($rows->accepted_quantity)}}</td>
                        <td>{{$rows->receiver->name}}</td>
                        <td>{{EF::dateFormat($rows->receive_date)}}</td>
						<td>{{$rows->purchaseOrder->boq->branch->name}}</td>
                        <td>
	                        @if($rows->grn_status == "1")
    	                        <span class="badge badge-success"> Approved</span>
							@else
								<span class="badge badge-warning"> Pending for payable</span>
                          	@endif
                        </td>

						<td>
							<a href="{{ route('downloadPDF.grn', Crypt::encrypt($rows->id))}}" target="_blank"><i class="fa fa-print"></i></a> &nbsp;
						
							<a href="{{ route('viewdetail.grn', Crypt::encrypt($rows->id))}}" target="_blank"><i class="fa fa-eye"></i></a>
						</td>

				
                        </tr>
                        @endforeach
                      @endif
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
          </div>
		  --}}
@endsection

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

@section('page_script')

   @include('inventory_module.scripts.boq')
   @include('inventory_module.scripts.grn')


	 <script>

	 function getMyPO()
	 {
	       event.preventDefault();
	       var project_id = $("#b_id").val();

	     var route = "{{url('/getPOList')}}/"+project_id;

	       showLoader();

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

			  removeLoader();

			 });
	 }
	 </script>

	 <script>

	 function getMyPO2()
	 {
	       event.preventDefault();
	       var vendor_id = $("#v_id").val();

	     var route = "{{url('/getPOListvendor')}}/"+vendor_id;

	       showLoader();

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

			  removeLoader();

			 });
	 }
	 </script>

	 <script>

	 function getMyPO3()
	 {
				 event.preventDefault();
				 var vendor_id = $("#v_id1").val();

			 var route = "{{url('/getPOListvendor')}}/"+vendor_id;

				 showLoader();

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

				removeLoader();

			 });
	 }
	 </script>


	 <script>

	 function getproduct()
	 {
				 event.preventDefault();
				 var product = $("#product").val();

			 var route = "{{url('/getPOListproduct')}}/"+product;

				 showLoader();

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

				removeLoader();

			 });
	 }
	 </script>

@endsection
