public function generateReference()
    {
        $reference = str_pad($this->ID, self::$reference_id_padding, '0', STR_PAD_LEFT);

        $this->extend('generateReference', $reference);

        $candidate = $reference;
        //prevent generating references that are the same
        $count = 0;
        while (Order::get()->filter('Reference', $candidate)->count() > 0) {
            $count++;
            $candidate = $reference . '' . $count;
        }
        $this->Reference = $candidate;
    }