@extends('layout')
@section('title','Charger stock ')
@section('content')
		<br/>
          <div class="section-body">
		  <meta name="_token" content="{{ csrf_token() }}" />
            <div class="row">
              <div class="col-lg-10 offset-1 col-md-12 ">
				@if (session('status'))
            <div class="alert alert-warning" style="font-size: 15px; background-color: #328039; color: white">
                <i class="fa fa-check"></i> &nbsp; {{ session('status') }}
            </div>
        @endif

        @if (session('error'))
            <div class="alert alert-danger" style="font-size: 15px; background-color: #fb5757; color: white">
                <i class="ti-na"></i> {{ session('error') }}
            </div>
        @endif
        @if ($errors->any())
            <div class="alert alert-danger" style="font-size: 15px; background-color: #fb5757; color: white" >
                <ul>
                    @foreach ($errors->all() as $error)
                        <li> <i class="ti-na"></i> {{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif
		<br/>
                <div class="card">
                  <div class="card-header">
                    <h4>Charger stock (<h7><strong>Les champs en * sont obligatoires</strong></h7>)</h4>
                  </div>
                  <div class="card-body">
				 <form method="POST" id="formulaire2" enctype="multipart/form-data">
                         {{csrf_field()}}
				  <div class="row" style="padding-top: 30px">
					
					
                     <div class="col-lg-4 col-md-4"> 
					  <div class="form-group">
                      <label>Fichier <font color="red">*</font></label>
                      <input type="file" id="my-file" name="my-file" class="form-control" required>
                    </div>
					</div>
					
				
                      </div>
					 <hr>  	
					<div class="pull-left">
                    <input type="submit" class="btn btn-success" id="bRegister">
					</div>
					<br><br>	  
				</form>
					  
					    </div>
						 
                    </div>
                  </div>
                </div>
          </div>
		   
            </div>
          </div>
		  
 <div class="modal fade" id="Supprimermodal" >
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Suppression</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                Voulez-vous supprimer ce produit  ?
              </div>
              <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="delete">
                
              </div>
            </div>
          </div>
        </div>
		@push('scripts') 
	   <script>
			$(document).ready(function(){
				$("#formulaire2").on("submit", function(e) {
				e.preventDefault();
				
				var extension = $('#my-file').val().split('.').pop().toLowerCase();
				var file_data = $('#my-file').prop('files')[0];

				var form_data = new FormData();
				form_data.append('file', file_data);
				
				$.ajaxSetup({
				headers: {
					'X-CSRF-Token': $('meta[name=_token]').attr('content')
				}
			});
				$.ajax({
				url: "{{url('chargerstockPost')}}", // point to server-side PHP script
				data: form_data,
				type: 'POST',
				dataType: 'JSON',
				contentType: false, // The content type used when sending data to the server.
				cache: false, // To unable request pages to be cached
				processData: false,
				beforeSend: function(){
					$("#bRegister").attr("value", "Traitement en cours, veuillez patienter...");
				},
				success: function(data) {
					if(data.type == 'error'){
						toastr.error(data.response, data.title, {timeOut: 15000})
					} else {
					
					    toastr.success(data.response, data.title, {timeOut: 15000})
						$("#bRegister").attr("value", "Enregistrer");
						window.location.reload();
						//window.location.href = '/succes-demande';
					}
				}
                })
				});
				});
			
	    </script>
		@endpush

@endsection