Jump to:

3375 Posts in 999 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Invoice Numbering

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 209 Views
  • peterpall18
    Avatar
    Community Member
    1 Post

    Invoice Numbering Link to this post

    Hi

    I'm trying to populate the invoiceID by adding +1 to the previous number but it won't work. No error message, just a blank page.

    Here's my code:

    class Invoice extends DataObject {

    static $db = array(
          'InvoiceID' => 'Int'
    );

    public function populateDefaults() {

          parent::populateDefaults();

          $obj = Invoice::get()->sort('Created', 'ASC')->First();
       
        $this->InvoiceID = $obj->InvoiceID+1;
    }

    }

    Why isn't working?

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: Invoice Numbering Link to this post

    What happens if there is no invoices in the system? (you should use $this->InvoiceID = ($obj) ? $obj->InvoiceID+1: 1);

    Also this way you've implemented will not check for duplicates of anything like that. You could just just the automatic primary $ID key that is defined on every DataObject. Check your php error logs for any other syntax issues that could be causing an issue.

    209 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.