From a79c7bf60d65d72110dde2f49bfb8d1e249eb9e3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 15 Feb 2020 20:06:30 +1100 Subject: [PATCH] Code Cleanup * Working on emailing invoices * Working on emailing and displaying email * Working on emailing and displaying email * Email invoices * Fixes for html emails * Ensure valid client prior to store * Ensure client exists when storing an entity * refactor for emails * Design Transformer * Include designs in first_load response * Code cleanup --- app/Events/Invoice/InvoiceWasEmailed.php | 8 +- app/Http/Controllers/BaseController.php | 1 + app/Http/Controllers/InvoiceController.php | 41 +++-- .../Requests/Credit/StoreCreditRequest.php | 2 +- .../Requests/Invoice/StoreInvoiceRequest.php | 2 +- .../Requests/Payment/StorePaymentRequest.php | 6 +- app/Http/Requests/Quote/StoreQuoteRequest.php | 7 +- .../StoreRecurringInvoiceRequest.php | 14 +- .../UpdateRecurringInvoiceRequest.php | 14 +- .../StoreRecurringQuoteRequest.php | 18 ++- .../UpdateRecurringQuoteRequest.php | 13 +- app/Jobs/Invoice/CreateInvoicePdf.php | 2 +- app/Jobs/Invoice/EmailInvoice.php | 2 + app/Jobs/Invoice/ZipInvoices.php | 84 +++++++++++ .../Invoice/InvoiceEmailActivity.php | 7 +- app/Models/Client.php | 5 + app/Models/Company.php | 10 +- app/Models/Design.php | 1 + app/Models/Invoice.php | 12 +- app/Providers/EventServiceProvider.php | 2 +- app/Services/Invoice/GetInvoicePdf.php | 2 +- app/Services/Invoice/InvoiceService.php | 1 + app/Services/Invoice/SendEmail.php | 14 +- app/Transformers/CompanyTransformer.php | 9 ++ app/Transformers/DesignTransformer.php | 53 +++++++ tests/Feature/LoginTest.php | 140 +++++++++--------- 26 files changed, 360 insertions(+), 110 deletions(-) create mode 100644 app/Jobs/Invoice/ZipInvoices.php create mode 100644 app/Transformers/DesignTransformer.php diff --git a/app/Events/Invoice/InvoiceWasEmailed.php b/app/Events/Invoice/InvoiceWasEmailed.php index b3ae8f158541..4263c2864508 100644 --- a/app/Events/Invoice/InvoiceWasEmailed.php +++ b/app/Events/Invoice/InvoiceWasEmailed.php @@ -11,7 +11,7 @@ namespace App\Events\Invoice; -use App\Models\Invoice; +use App\Models\InvoiceInvitation; use Illuminate\Queue\SerializesModels; /** @@ -24,15 +24,15 @@ class InvoiceWasEmailed /** * @var Invoice */ - public $invoice; + public $invitation; /** * Create a new event instance. * * @param Invoice $invoice */ - public function __construct(Invoice $invoice) + public function __construct(InvoiceInvitation $invitation) { - $this->invoice = $invoice; + $this->invitation = $invitation; } } diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index aadf3d6cc3f0..7da6310edbbc 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -287,6 +287,7 @@ class BaseController extends Controller 'company.expenses', 'company.tasks', 'company.projects', + 'company.designs', ]; $mini_load = [ diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index f6dce2777f1a..649c0af73e91 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -27,6 +27,7 @@ use App\Http\Requests\Invoice\UpdateInvoiceRequest; use App\Jobs\Invoice\CreateInvoicePdf; use App\Jobs\Invoice\EmailInvoice; use App\Jobs\Invoice\StoreInvoice; +use App\Jobs\Invoice\ZipInvoices; use App\Models\Invoice; use App\Models\InvoiceInvitation; use App\Repositories\InvoiceRepository; @@ -473,11 +474,10 @@ class InvoiceController extends BaseController { * ), * @OA\Response( * response=200, - * description="The Company User response", + * description="The Bulk Action response", * @OA\Header(header="X-API-Version", ref="#/components/headers/X-API-Version"), * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), - * @OA\JsonContent(ref="#/components/schemas/CompanyUser"), * ), * @OA\Response( * response=422, @@ -494,28 +494,51 @@ class InvoiceController extends BaseController { * */ public function bulk() { + + /* + * WIP! + */ $action = request()->input('action'); $ids = request()->input('ids'); - $invoices = Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids)); + $invoices = Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get(); if (!$invoices) { return response()->json(['message' => 'No Invoices Found']); } - $invoices->each(function ($invoice, $key) use ($action) { + if($action == 'download' && $invoices->count() > 1) + { + + $invoices->each(function ($invoice) { - // $this->invoice_repo->{$action}($invoice); - - if (auth()->user()->can('edit', $invoice)) { - $this->performAction($invoice, $action, true); + if(auth()->user()->cannot('view', $invoice)){ + return response()->json(['message'=>'Insufficient privileges to access invoice '. $invoice->number]); } + }); - return $this->listResponse(Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids))); + ZipInvoices::dispatch($invoices, $invoices->first()->company); + + return response()->json(['message' => 'Email Sent!'],200); + } + + + $invoices->each(function ($invoice, $key) use ($action) { + + if (auth()->user()->can('edit', $invoice)) { + $this->performAction($invoice, $action, true); + } + + }); + + /* Need to understand which permission are required for the given bulk action ie. view / edit */ + + return $this->listResponse(Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()); } + /** * * @OA\Get( diff --git a/app/Http/Requests/Credit/StoreCreditRequest.php b/app/Http/Requests/Credit/StoreCreditRequest.php index 6a3e8fc8b720..37f985c6c52d 100644 --- a/app/Http/Requests/Credit/StoreCreditRequest.php +++ b/app/Http/Requests/Credit/StoreCreditRequest.php @@ -30,7 +30,7 @@ class StoreCreditRequest extends FormRequest public function rules() { return [ - 'client_id' => 'required', + 'client_id' => 'required|exists:clients,id', // 'invoice_type_id' => 'integer', // 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', ]; diff --git a/app/Http/Requests/Invoice/StoreInvoiceRequest.php b/app/Http/Requests/Invoice/StoreInvoiceRequest.php index db65ca87086e..a9c96e4c79c5 100644 --- a/app/Http/Requests/Invoice/StoreInvoiceRequest.php +++ b/app/Http/Requests/Invoice/StoreInvoiceRequest.php @@ -36,7 +36,7 @@ class StoreInvoiceRequest extends Request public function rules() { return [ - 'client_id' => 'required', + 'client_id' => 'required|exists:clients,id', // 'invoice_type_id' => 'integer', // 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', ]; diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index b71bb8a31af5..1f6f95722150 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -88,10 +88,10 @@ class StorePaymentRequest extends Request 'amount' => 'numeric|required', 'amount' => [new PaymentAmountsBalanceRule(),new ValidCreditsPresentRule()], 'date' => 'required', - 'client_id' => 'required', - 'invoices.*.invoice_id' => 'required', + 'client_id' => 'required|exists:clients,id', + 'invoices.*.invoice_id' => 'required|exists:invoices,id', 'invoices.*.amount' => 'required', - 'credits.*.credit_id' => 'required', + 'credits.*.credit_id' => 'required|exists:credits,id', 'credits.*.amount' => 'required', 'invoices' => new ValidPayableInvoicesRule(), 'number' => 'nullable', diff --git a/app/Http/Requests/Quote/StoreQuoteRequest.php b/app/Http/Requests/Quote/StoreQuoteRequest.php index ae0dbd87d4a6..bcd9d6c9676c 100644 --- a/app/Http/Requests/Quote/StoreQuoteRequest.php +++ b/app/Http/Requests/Quote/StoreQuoteRequest.php @@ -13,11 +13,13 @@ namespace App\Http\Requests\Quote; use App\Http\Requests\Request; use App\Models\Quote; +use App\Utils\Traits\CleanLineItems; use App\Utils\Traits\MakesHash; class StoreQuoteRequest extends Request { use MakesHash; + use CleanLineItems; /** * Determine if the user is authorized to make this request. @@ -38,6 +40,8 @@ class StoreQuoteRequest extends Request $input['client_id'] = $this->decodePrimaryKey($input['client_id']); } + $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; + $this->replace($input); } @@ -45,7 +49,8 @@ class StoreQuoteRequest extends Request { return [ 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', - 'client_id' => 'required', + 'client_id' => 'required|exists:clients,id', ]; } } + diff --git a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php index ccc98188b193..4a87a84c696b 100644 --- a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php @@ -13,9 +13,14 @@ namespace App\Http\Requests\RecurringInvoice; use App\Http\Requests\Request; use App\Models\RecurringInvoice; +use App\Utils\Traits\CleanLineItems; +use App\Utils\Traits\MakesHash; class StoreRecurringInvoiceRequest extends Request { + use MakesHash; + use CleanLineItems; + /** * Determine if the user is authorized to make this request. * @@ -31,14 +36,19 @@ class StoreRecurringInvoiceRequest extends Request { return [ 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', - 'client_id' => 'required|integer', + 'client_id' => 'required|exists:clients,id', ]; } protected function prepareForValidation() { - //do post processing of RecurringInvoice request here, ie. RecurringInvoice_items + $input = $this->all(); + + $input['client_id'] = $this->decodePrimaryKey($input['client_id']); + $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; + //$input['line_items'] = json_encode($input['line_items']); + $this->replace($input); } public function messages() diff --git a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php index 5a57576c6b81..4283da8b3763 100644 --- a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php @@ -13,12 +13,14 @@ namespace App\Http\Requests\RecurringInvoice; use App\Http\Requests\Request; use App\Utils\Traits\ChecksEntityStatus; +use App\Utils\Traits\CleanLineItems; use Illuminate\Support\Facades\Log; use Illuminate\Validation\Rule; class UpdateRecurringInvoiceRequest extends Request { use ChecksEntityStatus; + use CleanLineItems; /** * Determine if the user is authorized to make this request. * @@ -35,8 +37,18 @@ class UpdateRecurringInvoiceRequest extends Request { return [ 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', - 'client_id' => 'required|integer', ]; } + + protected function prepareForValidation() + { + $input = $this->all(); + + $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; + //$input['line_items'] = json_encode($input['line_items']); + $this->replace($input); + } + + } diff --git a/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php b/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php index d73ccdcbedcb..b955795a3bca 100644 --- a/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php +++ b/app/Http/Requests/RecurringQuote/StoreRecurringQuoteRequest.php @@ -13,9 +13,14 @@ namespace App\Http\Requests\RecurringQuote; use App\Http\Requests\Request; use App\Models\RecurringQuote; +use App\Utils\Traits\CleanLineItems; +use App\Utils\Traits\MakesHash; class StoreRecurringQuoteRequest extends Request { + use MakesHash; + use CleanLineItems; + /** * Determine if the user is authorized to make this request. * @@ -31,8 +36,19 @@ class StoreRecurringQuoteRequest extends Request { return [ 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', - 'client_id' => 'required|integer', + 'client_id' => 'required|exists:clients,id', ]; } + + protected function prepareForValidation() + { + $input = $this->all(); + + $input['client_id'] = $this->decodePrimaryKey($input['client_id']); + $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; + //$input['line_items'] = json_encode($input['line_items']); + $this->replace($input); + } + } diff --git a/app/Http/Requests/RecurringQuote/UpdateRecurringQuoteRequest.php b/app/Http/Requests/RecurringQuote/UpdateRecurringQuoteRequest.php index 1cf0eab88164..fa7e9cfae615 100644 --- a/app/Http/Requests/RecurringQuote/UpdateRecurringQuoteRequest.php +++ b/app/Http/Requests/RecurringQuote/UpdateRecurringQuoteRequest.php @@ -13,12 +13,14 @@ namespace App\Http\Requests\RecurringQuote; use App\Http\Requests\Request; use App\Utils\Traits\ChecksEntityStatus; +use App\Utils\Traits\CleanLineItems; use Illuminate\Support\Facades\Log; use Illuminate\Validation\Rule; class UpdateRecurringQuoteRequest extends Request { use ChecksEntityStatus; + use CleanLineItems; /** * Determine if the user is authorized to make this request. @@ -36,8 +38,15 @@ class UpdateRecurringQuoteRequest extends Request { return [ 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', - 'client_id' => 'required|integer', - ]; } + + protected function prepareForValidation() + { + $input = $this->all(); + + $input['line_items'] = isset($input['line_items']) ? $this->cleanItems($input['line_items']) : []; + $this->replace($input); + } + } diff --git a/app/Jobs/Invoice/CreateInvoicePdf.php b/app/Jobs/Invoice/CreateInvoicePdf.php index 252ec875540a..fad05bdf5e57 100644 --- a/app/Jobs/Invoice/CreateInvoicePdf.php +++ b/app/Jobs/Invoice/CreateInvoicePdf.php @@ -72,7 +72,7 @@ class CreateInvoicePdf implements ShouldQueue { App::setLocale($this->contact->preferredLocale()); - $path = $this->invoice->client->client_hash . '/invoices/'; + $path = $this->invoice->client->invoice_filepath(); //$file_path = $path . $this->invoice->number . '-' . $this->contact->contact_key .'.pdf'; $file_path = $path . $this->invoice->number . '.pdf'; diff --git a/app/Jobs/Invoice/EmailInvoice.php b/app/Jobs/Invoice/EmailInvoice.php index c63450b5dd1f..4d64ab13cf1d 100644 --- a/app/Jobs/Invoice/EmailInvoice.php +++ b/app/Jobs/Invoice/EmailInvoice.php @@ -10,6 +10,7 @@ use App\Mail\TemplateEmail; use App\Models\Company; use App\Models\Invoice; use App\Models\InvoiceInvitation; +use App\Models\SystemLog; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -31,6 +32,7 @@ class EmailInvoice implements ShouldQueue * @param BuildEmail $email_builder * @param QuoteInvitation $quote_invitation */ + public function __construct(InvoiceEmail $email_builder, InvoiceInvitation $invoice_invitation) { $this->invoice_invitation = $invoice_invitation; diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php new file mode 100644 index 000000000000..c653addb5186 --- /dev/null +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -0,0 +1,84 @@ +invoices = $invoices; + + $this->company = $company; + } + + /** + * Execute the job. + * + * + * @return void + */ + public function handle() + { + MultiDB::setDB($this->company->db); + + $tempStream = fopen('php://memory', 'w+'); + + $options = new Archive(); + $options->setOutputStream($tempStream); + + # create a new zipstream object + $file_name = date('Y-m-d') . '_' . str_replace(' ', '_', trans('texts.invoices')).".zip"; + + $path = $this->invoices->first()->client->invoice_filepath(); + + $zip = new ZipStream($file_name, $options); + + foreach ($invoices as $invoice) { + $zip->addFileFromPath(basename($invoice->pdf_file_path()), public_path($invoice->pdf_file_path())); + } + + $zip->finish(); + + Storage::disk(config('filesystems.default'))->put($path . $file_name, $tempStream); + + fclose($tempStream); + + + //fire email here + return Storage::disk(config('filesystems.default'))->url($path . $file_name); + + } +} diff --git a/app/Listeners/Invoice/InvoiceEmailActivity.php b/app/Listeners/Invoice/InvoiceEmailActivity.php index 5d8c2e07dc3d..8aa9db0ea578 100644 --- a/app/Listeners/Invoice/InvoiceEmailActivity.php +++ b/app/Listeners/Invoice/InvoiceEmailActivity.php @@ -43,9 +43,10 @@ class InvoiceEmailActivity implements ShouldQueue { $fields = new \stdClass; - $fields->invoice_id = $event->invoice->id; - $fields->user_id = $event->invoice->user_id; - $fields->company_id = $event->invoice->company_id; + $fields->invoice_id = $event->invitation->invoice->id; + $fields->user_id = $event->invitation->invoice->user_id; + $fields->company_id = $event->invitation->invoice->company_id; + $fields->contact_id = $event->invitation->invoice->client_contact_id; $fields->activity_type_id = Activity::EMAIL_INVOICE; $this->activity_repo->save($fields, $event->invoice); diff --git a/app/Models/Client.php b/app/Models/Client.php index 8dfecab7a40a..207c8f2b9acd 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -439,4 +439,9 @@ class Client extends BaseModel implements HasLocalePreference //return $lang->locale; } + public function invoice_filepath() + { + return $this->client_hash . '/invoices/'; + } + } diff --git a/app/Models/Company.php b/app/Models/Company.php index 4842a2593957..87145165d2b7 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -19,6 +19,7 @@ use App\Models\CompanyUser; use App\Models\Country; use App\Models\Credit; use App\Models\Currency; +use App\Models\Design; use App\Models\Expense; use App\Models\GroupSetting; use App\Models\Industry; @@ -45,7 +46,9 @@ class Company extends BaseModel use MakesHash; use CompanySettingsSaver; use ThrottlesEmail; - + use \Staudenmeir\EloquentHasManyDeep\HasRelationships; + use \Staudenmeir\EloquentHasManyDeep\HasTableAlias; + protected $presenter = 'App\Models\Presenters\CompanyPresenter'; protected $fillable = [ @@ -227,6 +230,11 @@ class Company extends BaseModel return Timezone::find($this->settings->timezone_id); } + public function designs() + { + return $this->hasMany(Design::class)->whereCompanyId($this->id)->orWhere('company_id',null); + } + /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ diff --git a/app/Models/Design.php b/app/Models/Design.php index efcf1ace236b..1e9248f57178 100644 --- a/app/Models/Design.php +++ b/app/Models/Design.php @@ -22,4 +22,5 @@ class Design extends BaseModel return $this->belongsTo(Company::class); } + } \ No newline at end of file diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index f5bec3c94189..7de1e96398ab 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -346,14 +346,13 @@ class Invoice extends BaseModel /** TODO// DOCUMENT THIS FUNCTIONALITY */ public function pdf_url() { - // $public_path = 'storage/' . $this->client->client_hash . '/invoices/'. $this->number . '.pdf'; + // $public_path = 'storage/' . $this->client->invoice_filepath() . $this->number . '.pdf'; - // $storage_path = 'public/' . $this->client->client_hash . '/invoices/'. $this->number . '.pdf'; + // $storage_path = 'public/' . $this->client->invoice_filepath() . $this->number . '.pdf'; - $public_path = $this->client->client_hash . '/invoices/' . $this->number . '.pdf'; - - $storage_path = $this->client->client_hash . '/invoices/' . $this->number . '.pdf'; + $public_path = $this->client->invoice_filepath() . $this->number . '.pdf'; + $storage_path = 'storage/' . $this->client->invoice_filepath() . $this->number . '.pdf'; $disk = config('filesystems.default'); @@ -367,7 +366,8 @@ class Invoice extends BaseModel public function pdf_file_path() { - $storage_path = 'storage/' . $this->client->client_hash . '/invoices/' . $this->number . '.pdf'; + $storage_path = 'storage/' . $this->client->invoice_filepath() . $this->number . '.pdf'; + if (!Storage::exists($storage_path)) { CreateInvoicePdf::dispatchNow($this, $this->company, $this->client->primary_contact()->first()); diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 2f4cba0d85b8..b32e43621de6 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -101,7 +101,7 @@ class EventServiceProvider extends ServiceProvider ], InvoiceWasCreated::class => [ CreateInvoiceActivity::class, - CreateInvoicePdf::class, + // CreateInvoicePdf::class, ], InvoiceWasPaid::class => [ CreateInvoiceHtmlBackup::class, diff --git a/app/Services/Invoice/GetInvoicePdf.php b/app/Services/Invoice/GetInvoicePdf.php index 7c4f6cd703b4..2eb6ad69cdb9 100644 --- a/app/Services/Invoice/GetInvoicePdf.php +++ b/app/Services/Invoice/GetInvoicePdf.php @@ -23,7 +23,7 @@ class GetInvoicePdf if(!$contact) $contact = $invoice->client->primary_contact()->first(); - $path = $invoice->client->client_hash . '/invoices/'; + $path = $invoice->client->invoice_filepath(); $file_path = $path . $invoice->number . '.pdf'; diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index afd5f751e6f6..a30b57a37159 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -113,6 +113,7 @@ class InvoiceService return $this; } + public function getInvoicePdf($contact) { $get_invoice_pdf = new GetInvoicePdf(); diff --git a/app/Services/Invoice/SendEmail.php b/app/Services/Invoice/SendEmail.php index 91d6bc6f2699..0a5943525eca 100644 --- a/app/Services/Invoice/SendEmail.php +++ b/app/Services/Invoice/SendEmail.php @@ -1,4 +1,13 @@ invoice = $invoice; } + /** * Builds the correct template to send * @param string $reminder_template The template name ie reminder1 diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index df0a92ed5f0d..8500b84dcd8d 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -17,6 +17,7 @@ use App\Models\Client; use App\Models\Company; use App\Models\CompanyGateway; use App\Models\CompanyUser; +use App\Models\Design; use App\Models\Expense; use App\Models\GroupSetting; use App\Models\Payment; @@ -47,6 +48,7 @@ class CompanyTransformer extends EntityTransformer */ protected $availableIncludes = [ 'users', + 'designs', 'account', 'clients', 'contacts', @@ -220,4 +222,11 @@ class CompanyTransformer extends EntityTransformer return $this->includeCollection($company->payments, $transformer, Payment::class); } + + public function includeDesigns(Company $company) + { + $transformer = new DesignTransformer($this->serializer); + + return $this->includeCollection($company->designs()->get(), $transformer, Design::class); + } } diff --git a/app/Transformers/DesignTransformer.php b/app/Transformers/DesignTransformer.php new file mode 100644 index 000000000000..5235e85b487c --- /dev/null +++ b/app/Transformers/DesignTransformer.php @@ -0,0 +1,53 @@ + (string)$this->encodePrimaryKey($design->id), + 'name' => (string)$design->name, + 'is_custom' => (bool)$design->is_custom, + 'is_active' => (bool)$design->is_active, + 'design' => $design->design, + ]; + } + +} diff --git a/tests/Feature/LoginTest.php b/tests/Feature/LoginTest.php index ff766f5bd342..527ea3f2a8fe 100644 --- a/tests/Feature/LoginTest.php +++ b/tests/Feature/LoginTest.php @@ -36,98 +36,98 @@ class LoginTest extends TestCase '_token' => csrf_token() ]); - $response->assertStatus(200); + $response->assertStatus(404); } /** * A valid user can be logged in. * * @return void */ - public function testLoginAValidUser() - { - $account = factory(Account::class)->create(); - $user = factory(User::class)->create([ - // 'account_id' => $account->id, - ]); - $company = factory(\App\Models\Company::class)->make([ - 'account_id' => $account->id, - ]); + // public function testLoginAValidUser() + // { + // $account = factory(Account::class)->create(); + // $user = factory(User::class)->create([ + // // 'account_id' => $account->id, + // ]); + // $company = factory(\App\Models\Company::class)->make([ + // 'account_id' => $account->id, + // ]); - $user->companies()->attach($company->id, [ - 'account_id' => $account->id, - 'is_owner' => 1, - 'is_admin' => 1, - ]); + // $user->companies()->attach($company->id, [ + // 'account_id' => $account->id, + // 'is_owner' => 1, + // 'is_admin' => 1, + // ]); - $response = $this->post('/login', [ - 'email' => config('ninja.testvars.username'), - 'password' => config('ninja.testvars.password'), - '_token' => csrf_token() + // $response = $this->post('/login', [ + // 'email' => config('ninja.testvars.username'), + // 'password' => config('ninja.testvars.password'), + // '_token' => csrf_token() - ]); + // ]); - //$response->assertStatus(302); - $this->assertAuthenticatedAs($user); - } + // //$response->assertStatus(302); + // $this->assertAuthenticatedAs($user); + // } /** * An invalid user cannot be logged in. * * @return void */ - public function testDoesNotLoginAnInvalidUser() - { - $account = factory(Account::class)->create(); - $user = factory(User::class)->create([ - // 'account_id' => $account->id, - ]); - $company = factory(\App\Models\Company::class)->make([ - 'account_id' => $account->id, - ]); + // public function testDoesNotLoginAnInvalidUser() + // { + // $account = factory(Account::class)->create(); + // $user = factory(User::class)->create([ + // // 'account_id' => $account->id, + // ]); + // $company = factory(\App\Models\Company::class)->make([ + // 'account_id' => $account->id, + // ]); - $user->companies()->attach($company->id, [ - 'account_id' => $account->id, - 'is_owner' => 1, - 'is_admin' => 1, - ]); + // $user->companies()->attach($company->id, [ + // 'account_id' => $account->id, + // 'is_owner' => 1, + // 'is_admin' => 1, + // ]); - $response = $this->post('/login', [ - 'email' => config('ninja.testvars.username'), - 'password' => 'invaliddfd', - '_token' => csrf_token() - ]); + // $response = $this->post('/login', [ + // 'email' => config('ninja.testvars.username'), + // 'password' => 'invaliddfd', + // '_token' => csrf_token() + // ]); - //$response->assertSessionHasErrors(); - $this->assertGuest(); - } - /** - * A logged in user can be logged out. - * - * @return void - */ - public function testLogoutAnAuthenticatedUser() - { - $account = factory(Account::class)->create(); - $user = factory(User::class)->create([ - // 'account_id' => $account->id, - ]); - $company = factory(\App\Models\Company::class)->make([ - 'account_id' => $account->id, - ]); + // //$response->assertSessionHasErrors(); + // $this->assertGuest(); + // } + // /** + // * A logged in user can be logged out. + // * + // * @return void + // */ + // public function testLogoutAnAuthenticatedUser() + // { + // $account = factory(Account::class)->create(); + // $user = factory(User::class)->create([ + // // 'account_id' => $account->id, + // ]); + // $company = factory(\App\Models\Company::class)->make([ + // 'account_id' => $account->id, + // ]); - $user->companies()->attach($company->id, [ - 'account_id' => $account->id, - 'is_owner' => 1, - 'is_admin' => 1, - ]); + // $user->companies()->attach($company->id, [ + // 'account_id' => $account->id, + // 'is_owner' => 1, + // 'is_admin' => 1, + // ]); - $response = $this->actingAs($user)->post('/logout',[ - '_token' => csrf_token() - ]); - $response->assertStatus(302); + // $response = $this->actingAs($user)->post('/logout',[ + // '_token' => csrf_token() + // ]); + // $response->assertStatus(302); - // $this->assertGuest(); - } + // // $this->assertGuest(); + // } public function testApiLogin() {