Adding a custom field to invoice

Discussion in 'Troubleshooting' started by borise, Apr 6, 2013.

  1. borise

    borise Member

    Joined:
    Jan 3, 2013
    Messages:
    42
    Hey Alex,

    I hope you can help me out here.

    One of the biggest issues I'm having with amember right now, is selling subscriptions to business owners. As you may know, VAT regulations require me to state the customer's VAT number on the invoice (which works fine in amember), but also their business name (which isn't possible right now).

    I've created a new field called 'business_name' and I'm trying to get it to appear on the invoice, right before the name.

    This brought me to /library/Am/Pdf/Invoice.php file and I'm looking to add some code right before the name statement on line 214:

    PHP:
    $rightCol->name $invoice->getName();
    In order for this to work, I know I'd need to create a function in /application/default/models/Invoice.php. For example, the getName() function is found on line 589:

    PHP:
    public function getName()
        {
            return 
    $this->getUser()->getName();
        }
    so I would need to create something like:

    PHP:
    public function getBusiness()
        {
            return 
    $this->getUser()->business_name;
        }
    and call on it in the /library/Am/Pdf/Invoice.php, something like:

    PHP:
    $rightCol->business $invoice->getBusiness();
    However, as I'm no programming guru, I'm not sure how to call this custom field as my example clearly doesn't work.

    One workaround would be to use the First Name as a Full Name field, and use the Last Name as the Business Name, but I think that adding a Business Name by itself is a must for any serious membership software.

    As you may know, many businesses in Europe rely on correct invoicing in order to get tax returns. This means that any invoice I'm sending out to businesses without their business name and VAT number stated are actually no good invoices.

    I hope you can help me out with the code above.
    Thank you in advance!!!
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    You can get user's custom field value from invoice record:
    PHP:
    // If your field have SQL type: 
    $invoice->getUser()->business_name

    // If your field have DATA type: 
    $invoice->getUser()->data()->get('business_name'); 
  3. borise

    borise Member

    Joined:
    Jan 3, 2013
    Messages:
    42
    Thanks Alexander, worked!

    For any other users looking to implement this:

    After adding the above code to /application/default/models/Invoice.php, change the code in /library/Am/Pdf/Invoice.php:

    PHP:
    $rightCol->name $invoice->getName();
    to

    PHP:
    $rightCol->business $invoice->getUser()->data()->get('business_name');
    $rightCol->name $invoice->getName();
  4. responsivelab

    responsivelab aMember Pro Customer

    Joined:
    Jan 5, 2014
    Messages:
    12
    i have read that to customize invoice must use a code in site.php!

    How can i do this through site.php file?

Share This Page