Jump to content

syntax error, unexpected 'use' (T_USE)


Recommended Posts

hi

i added this code :

{php}
       use WHMCS\Database\Capsule;
       foreach (Capsule::table('tblinvoiceitems')->get() as $icosinvoiceitems) {
           echo $icosinvoiceitems->description;
       }
       {/php}

and i had this error cosed by using Capsule

Parse error: syntax error, unexpected 'use' (T_USE) in /var/www/html/manager/templates_c/72d89e63f9b687d11411376dbdde1aa26bc02b1d_0.file.viewinvoice.tpl.php on line 53

i nedd to interogate the table

Link to comment
Share on other sites

you shouldn't really be using {php} tags these days, it's better to use a hook and pass the array back to the template. :idea:

 

what exactly are you trying to do with this code? there is already an $invoiceitems array in the viewinvoice page, so i'm not sure why you need to query the database for the same information ?? :?:

Link to comment
Share on other sites

thank you for yor reply, finaly what i want is to costumize the invoice

in actual invoice the description of the product is like this :

2 x Pack Starter (03/07/2017 - 02/08/2017) @ 1000.00/chaque *

2 : indicate the quantity

so i want to create a new column with header is Quantity and i will put the values in there

and i need to delete the dates interval (03/07/2017 - 02/08/2017)

for the moment just i am trying to how to get the data from the table tblinvoiceitems

Link to comment
Share on other sites

thank you for yor reply, finaly what i want is to costumize the invoice

in actual invoice the description of the product is like this :

2 x Pack Starter (03/07/2017 - 02/08/2017) @ 1000.00/chaque *

if you're seeing "2 x " etc in the description, that means you have Group Similar Line Items enabled in General Settings.

 

Tick to enable automatically grouping identical line items into a quantity x description format.

if it was unticked, you'd see multiple copies of the same line item shown in the invoice - the existing $invoiceitems arrays adjusts the description value based on the value of the above checkbox.

 

2 : indicate the quantity

so i want to create a new column with header is Quantity and i will put the values in there

it's worth noting that there isn't a "Quantity" column stored in this database table - so you'd have to get that value another way.

 

and i need to delete the dates interval (03/07/2017 - 02/08/2017)

for the moment just i am trying to how to get the data from the table tblinvoiceitems

if you just wanted an action hook to query the tblinvoiceitems table, for the current invoice, then you could use this...

 

<?php

# Invoice Items Hook
# Written by brian!

use Illuminate\Database\Capsule\Manager as Capsule;

function invoice_items_hook($vars)
{
   $invoiceitems = Capsule::table('tblinvoiceitems')
                   ->where('invoiceid', $vars['invoiceid'])
                   ->get();

   if (count($invoiceitems)) {
       $encodedata = json_encode($invoiceitems);
       $decodedata = json_decode($encodedata, true);
       return array("invoiceitems2" => $decodedata);
   }
}
add_hook("ClientAreaPageViewInvoice", 1, "invoice_items_hook");

that would give you a new Smarty array, $invoiceitems2, that you can use in the viewinvoice template... if "Group Similar" is disabled, the two arrays should be very similar (any differences aren't relevant to your needs); if enabled, $invoiceitems2 will show individual line items whereas $invoiceitems will group them.

 

ZY5uGni.png

yZp0O7C.png

 

you could do what you want to do without any SQL queries or hooks, e.g just using Smarty/PHP (using no {php} tags!) - certainly the above hook doesn't give you any useful information that doesn't already exist in $invoiceitems... though you could get the qty with a more complex database query... and the date removal could be done using Smarty or PHP.

 

unfortunately, I don't think i'm going to be able to help you much with this... the problem being that i've very recently done something very similar for a couple of paying clients, and so I can't charge for the customisation one day, and give it away the next.... nor could I just ignore your reply... I might be able to give you clues, but no specific code... apologies for that.

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.

  • 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