0

I am new to laravel framework. I want to complete a important task in my app. In that app they have modules like invoices,quotes,payment,customers. for particular customers they have multiple invoices with status of sent and partially paid.

enter image description here

Here is the receipt page, on type of customer name it will get autosuggestion from customer table. Onclick of cutomer name it will get invoice details from (invoice table) based on customer id,and need to show on table below that customer name textbox, onclick of table invoice it will open modal which means if the particular customer has unpaid invoice they need to record payment else proceed with normal receipt creation.

I try the code like this, But I am not getting proper output please anyone help me to get out of this issue.

  <input type="text" name="customername" required="required"  id="cust" placeholder="Customer Name" class="form-control col-md-7 col-xs-12 typeahead"/>

   $( function() {

    $( "#cust" ).autocomplete({      
      //source: "http://www.duminex.com/client/search",
      source: "{{route('search.client')}}",
      select: function( event, ui ) {

        get_invoices(ui.item.id);

        $('#id').val(ui.item.id);
        $('#clientAddress').val(ui.item.address);
      }

    });
  } );

function get_invoices(client_id)
{
      $.ajax({
    method: 'GET', 
    url: "{{route('client.details')}}"
  }).done(function(data){
        alert(data);
    });

}

routes

Route::get('/client/search',[

  'uses'=>'ClientsController@search',
  'as'=>'search.client'
]);

Route::get('/client/search2', 'ClientsController@search2')->name('client.details');

Controller

public function search(Request $request)

    {   
        $s= Input::get('term');
        $clients = Client::select("id" ,"user_id", "companyname", "companyaddress" , "billingAddress")->where('companyname','like','%'.$s.'%')->where('user_id',Auth::user()->id)->get();
               if(count($clients) == 0){
                                $searchResult[] = "No Item found";
                            }
                            else{
                                foreach ($clients as $key => $value) {

                                    $searchResult[] = ['id' => $value->id, 'value' => $value->companyname , 'email' => $value->companyaddress , 'address' => $value->billingAddress];

                                    }
                            }          

                            return $searchResult;                                                                     
    }

    public function search2(Request $request)

    {   
         $clients = Invoice::select("invoiceNo")->where('status',['sent,Partially paid'])->where('client_id',$request->client_id)->get();
               if(count($clients) == 0){
                                $searchResult[] = "No Item found";
                            }
                            else{
                                foreach ($clients as $key => $value) {
                                    $searchResult[] = ['invoiceNo' => $value->invoiceNo];
                                }
                            }          
                                return $searchResult;
    }

Thanks in advance. Please anyone to help me get out of this issue.

4
  • Where you stuck ?? Commented Oct 7, 2017 at 12:07
  • its not returning any values.., Commented Oct 7, 2017 at 12:09
  • Which one not return response, search or search2 function ?? Commented Oct 7, 2017 at 12:13
  • search2 is not returning.. its returning " no item found " Commented Oct 7, 2017 at 12:15

1 Answer 1

1

You are not passing any data to the ajax so thats why you are not getting any result. Try below code :

function get_invoices(client_id) {
    $.ajax({
        method: 'GET',
        data : {
            client_id: client_id
        },
        url: "{{route('client.details')}}"
    }).done(function(data){
        alert(data);
    });
}
Sign up to request clarification or add additional context in comments.

6 Comments

I tried this code ., please check search2 function () now also returns " no items found "
How to retrieve in controller?
then why its returning empty value again check the query I tried in search2
And are you getting the client_id in the get_invoices function ??
Console log the client_id in the get_invoices function. Check its blank or has value
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.