mcrowson Posted February 25, 2015 Report Posted February 25, 2015 I know with the API I can find the invoices associated with a given service, but is there a way to get the service associated with a invoice or transaction? My goal is to list the transactions and the service that the transaction goes with. Quote
Tyson Posted February 25, 2015 Report Posted February 25, 2015 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. Quote
mcrowson Posted February 26, 2015 Author Report Posted February 26, 2015 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. Quote
Tyson Posted February 26, 2015 Report Posted February 26, 2015 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. mcrowson 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.