Jump to content

Service Associated With An Invoice/transaction


mcrowson

Recommended Posts

Your plan to build a table of transactions with service information is a little opposite of how Blesta fetches data internally. So you would need to fetch and derive that data using other methods.

 

You could do something like this:

for Transactions::getList as transaction:
    // Store services
    transaction->services := array()

    // Determine what invoices the transaction was applied to
    applied := Transactions::getApplied(transaction->id)

    // Fetch each invoice the transaction applied to and determine if it has services
    for applied as apply:
        invoice := Invoices::get(apply->invoice_id)
        for invoice->line_items as line:
            if line->service_id:
                transaction->services[] := Services::get(line->service_id)
            endif
        endfor
    endfor
endfor

Of course three for-loops will be pretty slow, so you may want to simplify what you're trying to do or determine another way to go about it.

Link to comment
Share on other sites

I got it down to only two calls: Invoice:getList and then Invoice:getLineItems for each invoice. The line items give descriptions for what was paid for. It was crazy slow. For looping through the invoices I am multithreading the API calls and it is somewhat faster (1.6 sec vs 5.8 sec) but I still would like it faster.

 

What is the Blesta-oriented way to do what i want that wouldn't have so many calls? My goal is just to show people what they have paid for and how much they paid in the past.

Link to comment
Share on other sites

Blesta lists transactions in the interface by themselves, without invoice/service information. If a client wants to see what that transaction applied to, they click on it and another request is made that will determine to what invoices it applied the transaction, if any. Determining the service would be another step, but Blesta doesn't go any further to show that information.

 

I think the best work-around is to write a custom query that will fetch exactly what you want. You can create a plugin for Blesta that provides a method that fetches exactly the information you want, then you can call that method over the API.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...