1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/database/seeds/InvoiceDesignsSeeder.php

57 lines
1.5 KiB
PHP
Raw Normal View History

2016-02-27 21:12:38 +01:00
<?php
use App\Models\InvoiceDesign;
class InvoiceDesignsSeeder extends Seeder
{
public function run()
{
Eloquent::unguard();
$designs = [
'Clean',
'Bold',
'Modern',
'Plain',
'Business',
'Creative',
'Elegant',
'Hipster',
'Playful',
'Photo',
];
2017-06-01 18:13:13 +02:00
2017-01-30 20:40:43 +01:00
for ($i = 0; $i < count($designs); $i++) {
2016-02-27 21:12:38 +01:00
$design = $designs[$i];
$fileName = storage_path() . '/templates/' . strtolower($design) . '.js';
if (file_exists($fileName)) {
$pdfmake = file_get_contents($fileName);
if ($pdfmake) {
$record = InvoiceDesign::whereName($design)->first();
2017-01-30 20:40:43 +01:00
if (! $record) {
$record = new InvoiceDesign();
2016-02-27 21:12:38 +01:00
$record->id = $i + 1;
$record->name = $design;
}
2017-12-21 08:10:07 +01:00
$record->pdfmake = json_encode(json_decode($pdfmake)); // remove the white space
2016-02-27 21:12:38 +01:00
$record->save();
}
}
}
2017-06-01 18:13:13 +02:00
for ($i = 1; $i <= 3; $i++) {
$name = 'Custom' . $i;
$id = $i + 10;
if (InvoiceDesign::whereName($name)->orWhere('id', '=', $id)->first()) {
continue;
2017-06-01 18:13:13 +02:00
}
InvoiceDesign::create([
'id' => $id,
'name' => $name,
]);
2017-06-01 18:13:13 +02:00
}
2016-02-27 21:12:38 +01:00
}
}