1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
invoiceninja/app/Models/InvoiceDesign.php

34 lines
1013 B
PHP
Raw Normal View History

2015-04-20 16:47:14 +02:00
<?php namespace app\Models;
2015-03-16 22:45:25 +01:00
2015-03-27 06:02:19 +01:00
use Eloquent;
2015-04-20 16:47:14 +02:00
use Auth;
2015-07-21 20:51:56 +02:00
use App\Models\InvoiceDesign;
2015-03-27 06:02:19 +01:00
2015-03-16 22:45:25 +01:00
class InvoiceDesign extends Eloquent
{
public $timestamps = false;
2015-04-20 16:47:14 +02:00
2015-07-21 20:51:56 +02:00
public function scopeAvailableDesigns($query, $utf8 = false)
2015-04-20 16:47:14 +02:00
{
2015-07-21 20:51:56 +02:00
$account = Auth::user()->account;
$designs = $query->where('id', '<=', Auth::user()->maxInvoiceDesignId())->orderBy('id')->get();
2015-04-20 16:47:14 +02:00
2015-07-21 20:51:56 +02:00
foreach ($designs as $design) {
2015-04-21 13:42:31 +02:00
$fileName = public_path(strtolower("js/templates/{$design->name}.js"));
2015-07-21 20:51:56 +02:00
if (($utf8 || Auth::user()->account->utf8_invoices) && file_exists($fileName)) {
2015-04-21 13:42:31 +02:00
$design->javascript = file_get_contents($fileName);
2015-04-20 16:47:14 +02:00
}
2015-07-21 20:51:56 +02:00
if ($design->id == CUSTOM_DESIGN) {
if ($account->utf8_invoices && $account->custom_design) {
$design->javascript = $account->custom_design;
} else {
$designs->pop();
}
}
2015-04-13 11:23:43 +02:00
}
2015-04-20 16:47:14 +02:00
return $designs;
2015-04-13 11:23:43 +02:00
}
2015-03-16 22:45:25 +01:00
}