1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00
This commit is contained in:
David Bomba 2019-06-03 15:31:20 +10:00
parent c2791815a7
commit d057903229
6 changed files with 42 additions and 17 deletions

View File

@ -49,8 +49,8 @@ class QueryLogging
$time = $timeEnd - $timeStart;
Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time);
// if($count > 20)
// Log::info($queries);
if($count > 20)
Log::info($queries);
}
}

View File

@ -58,22 +58,25 @@ class UploadFile implements ShouldQueue
public function handle() : ?Document
{
//$path = $this->encodePrimaryKey($this->company->id) . '/' . sha1(time()) . '_' . str_replace(" ", "", $this->file->getClientOriginalName());
$path = $this->encodePrimaryKey($this->company->id);
$file_path = $path . '/' . $this->file->hashName();
// Storage::makeDirectory($path);
$file_path = $path . '/' . $this->file->hashName();
Storage::put($path, $this->file);
$width = 0;
$height = 0;
if (in_array($this->file->getClientOriginalExtension(),['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'psd']))
{
$imageSize = getimagesize($this->file);
$width = $imageSize[0];
$height = $imageSize[1];
}
$document = new Document();
@ -88,21 +91,33 @@ class UploadFile implements ShouldQueue
$document->width = $width;
$document->height = $height;
$preview_path = $this->encodePrimaryKey($this->company->id) . '/' . sha1(time()) . '_preview_' . str_replace(" ", "", $this->file->getClientOriginalName());
$preview_path = $this->encodePrimaryKey($this->company->id);
$document->preview = $this->generatePreview($preview_path);
$this->entity->documents()->save($document);
return $document;
return $document;
}
private function generatePreview($preview_path) : string
{
$extension = $this->file->getClientOriginalExtension();
if (empty(Document::$types[$extension]) && ! empty(Document::$extraExtensions[$extension])) {
$documentType = Document::$extraExtensions[$extension];
} else {
$documentType = $extension;
}
if (empty(Document::$types[$documentType])) {
return 'Unsupported file type';
}
$preview = '';
if (in_array($this->file->getClientOriginalExtension(), ['jpeg', 'png', 'gif', 'bmp', 'tiff', 'psd']))
if (in_array($this->file->getClientOriginalExtension(),['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'psd']))
{
$makePreview = false;
$imageSize = getimagesize($this->file);
@ -135,7 +150,7 @@ class UploadFile implements ShouldQueue
// We haven't created a preview yet
$imgManager = new ImageManager($imgManagerConfig);
$img = $imgManager->make($filePath);
$img = $imgManager->make($preview_path);
if ($width <= Document::DOCUMENT_PREVIEW_SIZE && $height <= Document::DOCUMENT_PREVIEW_SIZE) {
$previewWidth = $width;

View File

@ -18,6 +18,7 @@ use App\Models\Company;
use App\Models\Country;
use App\Models\Filterable;
use App\Models\Timezone;
use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use Hashids\Hashids;
@ -32,6 +33,7 @@ class Client extends BaseModel
use MakesDates;
use SoftDeletes;
use Filterable;
use GeneratesCounter;
protected $presenter = 'App\Models\Presenters\ClientPresenter';
@ -50,7 +52,7 @@ class Client extends BaseModel
'country',
'shipping_country'
];
/*
protected $with = [
'contacts',
'primary_contact',
@ -58,7 +60,7 @@ class Client extends BaseModel
'shipping_country',
'company'
];
*/
protected $casts = [
'settings' => 'object'
];

View File

@ -76,6 +76,15 @@ class Document extends BaseModel
],
];
/**
* @var array
*/
public static $extraExtensions = [
'jpg' => 'jpeg',
'tif' => 'tiff',
];
public function documentable()
{
return $this->morphTo();

View File

@ -71,7 +71,7 @@ class RandomDataSeeder extends Seeder
]);
factory(\App\Models\Client::class, 5)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
factory(\App\Models\Client::class, 6)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
factory(\App\Models\ClientContact::class,1)->create([
'user_id' => $user->id,
@ -92,14 +92,16 @@ class RandomDataSeeder extends Seeder
factory(\App\Models\Product::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id]);
/** Invoice Factory */
factory(\App\Models\Invoice::class,50)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
factory(\App\Models\Invoice::class,500)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
$clients = Client::all();
foreach($clients as $client)
{
$client->getNextNumber($client);
$client->getNextClientNumber($client);
$client->save();
}
}
}

View File

@ -45,9 +45,6 @@ class UploadFileTest extends TestCase
$this->assertNotNull($document);
Log::error($document);
// $this->assertEquals($invoice->amount, $payment);
}