Merge pull request #3831 from turbo124/v2

Add documents to any entity.
This commit is contained in:
David Bomba 2020-06-23 07:49:41 +10:00 committed by GitHub
commit f5cba4702e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 155 additions and 49 deletions

View File

@ -9,9 +9,9 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Events\Client; namespace App\Events\Design;
use App\Models\Client; use App\Models\Design;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**

View File

@ -9,9 +9,9 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Events\Client; namespace App\Events\Design;
use App\Models\Client; use App\Models\Design;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**
@ -45,5 +45,5 @@ class DesignWasDeleted
{ {
return new PrivateChannel('channel-name'); return new PrivateChannel('channel-name');
} }
}
} }

View File

@ -9,9 +9,9 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Events\Client; namespace App\Events\Design;
use App\Models\Client; use App\Models\Design;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**

View File

@ -9,9 +9,9 @@
* @license https://opensource.org/licenses/AAL * @license https://opensource.org/licenses/AAL
*/ */
namespace App\Events\Client; namespace App\Events\Design;
use App\Models\Client; use App\Models\Design;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**
@ -45,5 +45,5 @@ class DesignWasUpdated
{ {
return new PrivateChannel('channel-name'); return new PrivateChannel('channel-name');
} }
}
} }

View File

@ -64,22 +64,22 @@ class Handler extends ExceptionHandler
if (app()->bound('sentry') && $this->shouldReport($exception)) { if (app()->bound('sentry') && $this->shouldReport($exception)) {
// app('sentry')->configureScope(function (Scope $scope): void { app('sentry')->configureScope(function (Scope $scope): void {
// if (auth()->guard('contact') && auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) { if (auth()->guard('contact') && auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) {
// $scope->setUser([ $scope->setUser([
// 'id' => auth()->guard('contact')->user()->company->account->key, 'id' => auth()->guard('contact')->user()->company->account->key,
// 'email' => "anonymous@example.com", 'email' => "anonymous@example.com",
// 'name' => "Anonymous User", 'name' => "Anonymous User",
// ]); ]);
// } elseif (auth()->guard('user') && auth()->guard('user')->user() && auth()->user()->company() && auth()->user()->company()->account->report_errors) { } elseif (auth()->guard('user') && auth()->guard('user')->user() && auth()->user()->company() && auth()->user()->company()->account->report_errors) {
// $scope->setUser([ $scope->setUser([
// 'id' => auth()->user()->account->key, 'id' => auth()->user()->account->key,
// 'email' => "anonymous@example.com", 'email' => "anonymous@example.com",
// 'name' => "Anonymous User", 'name' => "Anonymous User",
// ]); ]);
// } }
// }); });
app('sentry')->captureException($exception); app('sentry')->captureException($exception);
} }

View File

@ -38,6 +38,16 @@ class StoreClientRequest extends Request
public function rules() public function rules()
{ {
if ($this->input('documents') && is_array($this->input('documents'))) {
$documents = count($this->input('documents'));
foreach (range(0, $documents) as $index) {
$rules['documents.' . $index] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
} elseif ($this->input('documents')) {
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
/* Ensure we have a client name, and that all emails are unique*/ /* Ensure we have a client name, and that all emails are unique*/
//$rules['name'] = 'required|min:1'; //$rules['name'] = 'required|min:1';
$rules['id_number'] = 'unique:clients,id_number,' . $this->id . ',id,company_id,' . $this->company_id; $rules['id_number'] = 'unique:clients,id_number,' . $this->id . ',id,company_id,' . $this->company_id;

View File

@ -41,6 +41,16 @@ class UpdateClientRequest extends Request
{ {
/* Ensure we have a client name, and that all emails are unique*/ /* Ensure we have a client name, and that all emails are unique*/
if ($this->input('documents') && is_array($this->input('documents'))) {
$documents = count($this->input('documents'));
foreach (range(0, $documents) as $index) {
$rules['documents.' . $index] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
} elseif ($this->input('documents')) {
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
$rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000'; $rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000';
$rules['industry_id'] = 'integer|nullable'; $rules['industry_id'] = 'integer|nullable';
$rules['size_id'] = 'integer|nullable'; $rules['size_id'] = 'integer|nullable';

View File

@ -98,6 +98,17 @@ class StorePaymentRequest extends Request
'number' => 'nullable', 'number' => 'nullable',
]; ];
if ($this->input('documents') && is_array($this->input('documents'))) {
$documents = count($this->input('documents'));
foreach (range(0, $documents) as $index) {
$rules['documents.' . $index] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
} elseif ($this->input('documents')) {
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
return $rules; return $rules;
} }
} }

View File

@ -36,11 +36,24 @@ class UpdatePaymentRequest extends Request
public function rules() public function rules()
{//min:1 removed, 'required' {//min:1 removed, 'required'
return [ $rules = [
'invoices' => ['array',new PaymentAppliedValidAmount,new ValidCreditsPresentRule], 'invoices' => ['array',new PaymentAppliedValidAmount,new ValidCreditsPresentRule],
'invoices.*.invoice_id' => 'distinct', 'invoices.*.invoice_id' => 'distinct',
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
]; ];
if ($this->input('documents') && is_array($this->input('documents'))) {
$documents = count($this->input('documents'));
foreach (range(0, $documents) as $index) {
$rules['documents.' . $index] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
} elseif ($this->input('documents')) {
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
return $rules;
} }
protected function prepareForValidation() protected function prepareForValidation()

View File

@ -29,12 +29,23 @@ class StoreProductRequest extends Request
public function rules() public function rules()
{ {
return [
//'product_key' => 'required|unique:products,product_key,null,null,company_id,'.auth()->user()->companyId(), if ($this->input('documents') && is_array($this->input('documents'))) {
'cost' => 'numeric', $documents = count($this->input('documents'));
'price' => 'numeric',
'quantity' => 'numeric', foreach (range(0, $documents) as $index) {
]; $rules['documents.' . $index] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
} elseif ($this->input('documents')) {
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
$rules['cost'] = 'numeric';
$rules['price'] = 'numeric';
$rules['quantity'] = 'numeric';
return $rules;
} }
protected function prepareForValidation() protected function prepareForValidation()

View File

@ -32,12 +32,23 @@ class UpdateProductRequest extends Request
public function rules() public function rules()
{ {
return [
//'product_key' => 'unique:products,product_key,'.$this->product->id.',id,company_id,'.auth()->user()->companyId(), if ($this->input('documents') && is_array($this->input('documents'))) {
'cost' => 'numeric', $documents = count($this->input('documents'));
'price' => 'numeric',
'quantity' => 'numeric', foreach (range(0, $documents) as $index) {
]; $rules['documents.' . $index] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
} elseif ($this->input('documents')) {
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
$rules['cost'] = 'numeric';
$rules['price'] = 'numeric';
$rules['quantity'] = 'numeric';
return $rules;
} }

View File

@ -75,9 +75,21 @@ class StoreQuoteRequest extends Request
public function rules() public function rules()
{ {
return [ $rules = [];
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
'client_id' => 'required|exists:clients,id,company_id,'.auth()->user()->company()->id, $rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
];
if ($this->input('documents') && is_array($this->input('documents'))) {
$documents = count($this->input('documents'));
foreach (range(0, $documents) as $index) {
$rules['documents.' . $index] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
} elseif ($this->input('documents')) {
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
return $rules;
} }
} }

View File

@ -38,9 +38,19 @@ class UpdateQuoteRequest extends Request
public function rules() public function rules()
{ {
return [ $rules = [];
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
]; if ($this->input('documents') && is_array($this->input('documents'))) {
$documents = count($this->input('documents'));
foreach (range(0, $documents) as $index) {
$rules['documents.' . $index] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
} elseif ($this->input('documents')) {
$rules['documents'] = 'file|mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx|max:20000';
}
return $rules;
} }
protected function prepareForValidation() protected function prepareForValidation()

View File

@ -94,8 +94,8 @@ class UploadFile implements ShouldQueue
$document->disk = $this->disk; $document->disk = $this->disk;
$document->hash = $this->file->hashName(); $document->hash = $this->file->hashName();
$document->size = $this->file->getSize(); $document->size = $this->file->getSize();
$document->width = isset($width) ?? null; $document->width = isset($width) ? $width : null;
$document->height = isset($height) ?? null; $document->height = isset($height) ? $height : null;
// $preview_path = $this->encodePrimaryKey($this->company->id); // $preview_path = $this->encodePrimaryKey($this->company->id);
// $document->preview = $this->generatePreview($preview_path); // $document->preview = $this->generatePreview($preview_path);

View File

@ -15,6 +15,7 @@ use App\Factory\ClientFactory;
use App\Models\Client; use App\Models\Client;
use App\Repositories\ClientContactRepository; use App\Repositories\ClientContactRepository;
use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\SavesDocuments;
use Illuminate\Http\Request; use Illuminate\Http\Request;
/** /**
@ -23,6 +24,8 @@ use Illuminate\Http\Request;
class ClientRepository extends BaseRepository class ClientRepository extends BaseRepository
{ {
use GeneratesCounter; use GeneratesCounter;
use SavesDocuments;
/** /**
* @var ClientContactRepository * @var ClientContactRepository
*/ */
@ -75,6 +78,9 @@ class ClientRepository extends BaseRepository
$data['name'] = $client->present()->name(); $data['name'] = $client->present()->name();
} }
if (array_key_exists('documents', $data)) {
$this->saveDocuments($data['documents'], $client);
}
return $client; return $client;
} }

View File

@ -21,6 +21,7 @@ use App\Models\Invoice;
use App\Models\Payment; use App\Models\Payment;
use App\Repositories\CreditRepository; use App\Repositories\CreditRepository;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use App\Utils\Traits\SavesDocuments;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
@ -30,6 +31,7 @@ use Illuminate\Support\Carbon;
class PaymentRepository extends BaseRepository class PaymentRepository extends BaseRepository
{ {
use MakesHash; use MakesHash;
use SavesDocuments;
protected $credit_repo; protected $credit_repo;
@ -89,6 +91,9 @@ class PaymentRepository extends BaseRepository
$payment->status_id = Payment::STATUS_COMPLETED; $payment->status_id = Payment::STATUS_COMPLETED;
$payment->save(); $payment->save();
if (array_key_exists('documents', $data)) {
$this->saveDocuments($data['documents'], $payment);
}
/*Ensure payment number generated*/ /*Ensure payment number generated*/
if (!$payment->number || strlen($payment->number) == 0) { if (!$payment->number || strlen($payment->number) == 0) {

View File

@ -12,6 +12,7 @@
namespace App\Repositories; namespace App\Repositories;
use App\Models\Product; use App\Models\Product;
use App\Utils\Traits\SavesDocuments;
use Illuminate\Http\Request; use Illuminate\Http\Request;
/** /**
@ -19,6 +20,8 @@ use Illuminate\Http\Request;
*/ */
class ProductRepository extends BaseRepository class ProductRepository extends BaseRepository
{ {
use SavesDocuments;
public function getClassName() public function getClassName()
{ {
return Product::class; return Product::class;
@ -34,6 +37,10 @@ class ProductRepository extends BaseRepository
$product->fill($data); $product->fill($data);
$product->save(); $product->save();
if (array_key_exists('documents', $data)) {
$this->saveDocuments($data['documents'], $product);
}
return $product; return $product;
} }
} }

View File

@ -37,7 +37,7 @@ class DocumentTransformer extends EntityTransformer
'assigned_user_id' => $this->encodePrimaryKey($document->assigned_user_id), 'assigned_user_id' => $this->encodePrimaryKey($document->assigned_user_id),
'project_id' => $this->encodePrimaryKey($document->project_id), 'project_id' => $this->encodePrimaryKey($document->project_id),
'vendor_id' => $this->encodePrimaryKey($document->vendor_id), 'vendor_id' => $this->encodePrimaryKey($document->vendor_id),
'url' => (string) $document->url ?: '', 'url' => (string) $document->generateUrl() ?: '',
'preview' => (string) $document->preview ?: '', 'preview' => (string) $document->preview ?: '',
'name' => (string) $document->name, 'name' => (string) $document->name,
'type' => (string) $document->type, 'type' => (string) $document->type,

View File

@ -5,7 +5,7 @@ return [
/** /**
* Enable or disable the beacon * Enable or disable the beacon
*/ */
'enabled' => true, 'enabled' => env('BEACON_ENABLED', false),
/** /**
* The API endpoint for logs * The API endpoint for logs