Jump to content

Export values from item description


Marcell

Recommended Posts

Hey,

I was wondering if it's possible to extract some values from the item's description to make a cleaner look for the PDF template via PHP.

Talking about 

$item['description']

actually in more details.

Can someone help with this?

Edited by Marcell
Link to comment
Share on other sites

8 minutes ago, Marcell said:

I was wondering if it's possible to extract some values from the item's description to make a cleaner look for the PDF template via PHP.

by extract/export, you mean remove specific content from the description ?

if it's purely in the PDF template only, then it's just a case of working out what you want to remove, and manipulating the description value using various PHP replacement methods... and what method to choose depends on what you want to remove.

Link to comment
Share on other sites

brian!  well not removing, more like getting specific data of it, so let's say I want to know the quantity of the first product on the invoice

$qty = $item['description', 'quantity'];
$cycle = $item['description', 'cycle'];
$cycle = $item['description', 'amount']; 

So then I could easily just provide to product(s) details,

// There are amount for individual products, when the quantity is more than 1. See picture bellow, in case product amount is not valid.

image.png.8a4beabe5f8966d9b8f89fee0e2dad36.png

Link to comment
Share on other sites

3 minutes ago, Marcell said:

brian!  well not removing, more like getting specific data of it

oh ok - I wasn't sure if you were removing or adding...

6 minutes ago, Marcell said:

so let's say I want to know the quantity of the first product on the invoice

the invoice database tables don't store quantities of products as a separate value - they will just be multiple line items... and they will either be listed individually on the invoice, or if you have "Group Similar Line Items" enabled, they'll be grouped and shown as per your screenshot.

11 minutes ago, Marcell said:

Just attached a PDF what I exactly trying to do here.

generally speaking to get a qty for a line item, you would do a count of the tblinvoiceitems table (the pdf template will know the invoice id)... and similarly for cycles, amounts, etc, it is often easier to get them direct from the database rather than manipulating, or trying to figure out, from the description string.

the added complication for your situation is that you're using the Clean PDF addon - I know there is an overrides template that is not encrypted, but I don't know if you have options to modify the template in the way that this would need.

Link to comment
Share on other sites

On 8/6/2020 at 3:27 PM, Marcell said:

Just attached a PDF what I exactly trying to do here.

BIT_000065.pdf 89.79 kB · 5 downloads

This is an example that you're trying to achieve within WHMCS, isn't it? I guess it'll come down to regex, mostly. For one of my addons I've made a basic regex to be able to extract the cycle dates from the individual invoice lines:

/^.*(\(((\d{2})\/(\d{2})\/(\d{4})) - ((\d{2})\/(\d{2})\/(\d{4}))\))$/

Which could be simplified a lot depending on how you want to print the dates. Another regex could be used to get the quantity, I'd say.

Link to comment
Share on other sites

  • 3 weeks later...

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated