diff --git a/app/Designs/Designer.php b/app/Designs/Designer.php index 76b288257925..0b7dc0fa985e 100644 --- a/app/Designs/Designer.php +++ b/app/Designs/Designer.php @@ -157,8 +157,7 @@ class Designer } elseif ($this->entity_string == 'quote') { //$this->exported_variables['$entity_labels'] = $this->processLabels($this->input_variables['quote_details'], $this->quoteDetails($company)); $this->exported_variables['$entity_details'] = $this->processVariables($this->input_variables['quote_details'], $this->quoteDetails($company)); - } - else { + } else { $this->exported_variables['$entity_details'] = $this->processVariables($this->input_variables['invoice_details'], $this->quoteDetails($company)); } @@ -268,7 +267,6 @@ class Designer private function invoiceDetails(Company $company) { - $data = [ '$invoice.number' => '$invoice.number_label: $invoice.number', '$invoice.po_number' => '$invoice.po_number_label: $invoice.po_number', diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index e93a9c3bef82..33d23f050a8d 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -55,31 +55,24 @@ class Handler extends ExceptionHandler */ public function report(Exception $exception) { - if (app()->bound('sentry') && $this->shouldReport($exception)) { - app('sentry')->configureScope(function (Scope $scope): void { - - if(auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) { + if (auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) { $scope->setUser([ 'id' => auth()->guard('contact')->user()->company->account->key, 'email' => "anonymous@example.com", 'name' => "Anonymous User", ]); - } - else if (auth()->guard('user')->user() && auth()->user()->company()->account->report_errors) { + } elseif (auth()->guard('user')->user() && auth()->user()->company()->account->report_errors) { $scope->setUser([ 'id' => auth()->user()->account->key, 'email' => "anonymous@example.com", 'name' => "Anonymous User", ]); } - - }); app('sentry')->captureException($exception); - } parent::report($exception); diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 5c13f74a0acb..1391df58f282 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -158,48 +158,4 @@ class AccountController extends BaseController return $this->listResponse($ct); } - /** - * Display the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function show($id) - { - // - } - - /** - * Show the form for editing the specified resource. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function edit($id) - { - // - } - - /** - * Update the specified resource in storage. - * - * @param \Illuminate\Http\Request $request - * @param int $id - * @return \Illuminate\Http\Response - */ - public function update(Request $request, $id) - { - // - } - - /** - * Remove the specified resource from storage. - * - * @param int $id - * @return \Illuminate\Http\Response - */ - public function destroy($id) - { - // - } } diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 0a0ab5b1535b..aebf6acae4f2 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -176,7 +176,6 @@ class LoginController extends BaseController $ct = CompanyUser::whereUserId($user->id); return $this->listResponse($ct); - } else { $this->incrementLoginAttempts($request); diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 8a3551e09e0b..0716a0644c56 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -81,8 +81,6 @@ class BaseController extends Controller $include = implode(",", $this->forced_includes); } -\Log::error(print_r($include,1)); - $this->manager->parseIncludes($include); $this->serializer = request()->input('serializer') ?: EntityTransformer::API_SERIALIZER_ARRAY; @@ -105,14 +103,24 @@ class BaseController extends Controller ->header('X-APP-VERSION', config('ninja.app_version')); } + /** + * 404 for the client portal + * @return Response 404 response + */ public function notFoundClient() { return abort(404); } - protected function errorResponse($response, $httpErrorCode = 400) + /** + * API Error response + * @param string $message The return error message + * @param integer $httpErrorCode 404/401/403 etc + * @return Response The JSON response + */ + protected function errorResponse($message, $httpErrorCode = 400) { - $error['error'] = $response; + $error['error'] = $message; $error = json_encode($error, JSON_PRETTY_PRINT); @@ -134,15 +142,7 @@ class BaseController extends Controller $query->with($includes); if (!auth()->user()->hasPermission('view_'.lcfirst(class_basename($this->entity_type)))) { - - // if ($this->entity_type == Company::class || $this->entity_type == Design::class) { - // //no user keys exist on the company table, so we need to skip - // } elseif ($this->entity_type == User::class) { - // //$query->where('id', '=', auth()->user()->id); @todo why? - // } else { - $query->where('user_id', '=', auth()->user()->id); - // } - + $query->where('user_id', '=', auth()->user()->id); } if (request()->has('updated_at') && request()->input('updated_at') > 0) { diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 1f2d23a9eef1..43933a978c43 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -92,7 +92,6 @@ class InvoiceController extends Controller */ public function bulk(ProcessInvoicesInBulkRequest $request) { - $transformed_ids = $this->transformKeys($request->invoices); if ($request->input('action') == 'payment') { diff --git a/app/Http/Controllers/EmailController.php b/app/Http/Controllers/EmailController.php index e629be700406..b731a92b0c51 100644 --- a/app/Http/Controllers/EmailController.php +++ b/app/Http/Controllers/EmailController.php @@ -75,12 +75,12 @@ class EmailController extends BaseController * property="entity_id", * description="The entity_id", * type="string", - * ), + * ), * @OA\Property( * property="template", * description="The template required", * type="string", - * ), + * ), * ) * ) * ), @@ -113,16 +113,12 @@ class EmailController extends BaseController $body = $request->input('body'); $entity_string = strtolower(class_basename($entity_obj)); - $entity_obj->invitations->each(function ($invitation) use($subject, $body, $entity_string, $entity_obj) { - + $entity_obj->invitations->each(function ($invitation) use ($subject, $body, $entity_string, $entity_obj) { if ($invitation->contact->send_email && $invitation->contact->email) { - $when = now()->addSeconds(1); $invitation->contact->notify((new SendGenericNotification($invitation, $entity_string, $subject, $body))->delay($when)); - } - }); if ($this instanceof Invoice) { @@ -143,7 +139,5 @@ class EmailController extends BaseController $entity_obj->service()->markSent()->save(); return $this->itemResponse($entity_obj); - - } } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index ed56eb57b90d..e092efb075c5 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -687,7 +687,6 @@ class InvoiceController extends BaseController }); if ($invoice->invitations->count() > 0) { - event(new InvoiceWasEmailed($invoice->invitations->first())); } diff --git a/app/Http/Controllers/SetupController.php b/app/Http/Controllers/SetupController.php index 188f6ff9ffdb..b1d412dae389 100644 --- a/app/Http/Controllers/SetupController.php +++ b/app/Http/Controllers/SetupController.php @@ -47,8 +47,9 @@ class SetupController extends Controller $mail_driver = $request->input('mail_driver'); - if(!$this->failsafeMailCheck($request)) + if (!$this->failsafeMailCheck($request)) { $mail_driver = 'log'; + } $_ENV['APP_KEY'] = config('app.key'); $_ENV['APP_URL'] = $request->input('url'); @@ -162,14 +163,13 @@ class SetupController extends Controller private function failsafeMailCheck($request) { - $response_array = SystemHealth::testMailServer($request); - if($response_array instanceof Response) + if ($response_array instanceof Response) { return true; + } return false; - } } diff --git a/app/Http/Controllers/Traits/VerifiesUserEmail.php b/app/Http/Controllers/Traits/VerifiesUserEmail.php index f4874860f26b..ef3adba6a245 100644 --- a/app/Http/Controllers/Traits/VerifiesUserEmail.php +++ b/app/Http/Controllers/Traits/VerifiesUserEmail.php @@ -30,16 +30,14 @@ trait VerifiesUserEmail public function confirm() { if ($user = User::whereRaw("BINARY `confirmation_code`= ?", request()->route('confirmation_code'))->first()) { + $user->email_verified_at = now(); $user->confirmation_code = null; $user->save(); return response()->json(['message' => ctrans('texts.security_confirmation')]); - //return redirect()->route('dashboard.index')->with('message', ctrans('texts.security_confirmation')); } return response()->json(['message' => ctrans('texts.wrong_confirmation')]); - - //return redirect()->route('login')->with('message', ctrans('texts.wrong_confirmation')); } } diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index 0a0d7d2cf9d8..3ad0a11d19f1 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -47,11 +47,10 @@ class QueryLogging $count = count($queries); $timeEnd = microtime(true); $time = $timeEnd - $timeStart; - // Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time); + // Log::info($request->method() . ' - ' . $request->url() . ": $count queries - " . $time); // if($count > 50) // Log::info($queries); - } } diff --git a/app/Http/Requests/Company/UpdateCompanyRequest.php b/app/Http/Requests/Company/UpdateCompanyRequest.php index 04b3efbe85fc..c051ac6e6d3b 100644 --- a/app/Http/Requests/Company/UpdateCompanyRequest.php +++ b/app/Http/Requests/Company/UpdateCompanyRequest.php @@ -56,5 +56,4 @@ class UpdateCompanyRequest extends Request protected function prepareForValidation() { } - } diff --git a/app/Http/Requests/Email/SendEmailRequest.php b/app/Http/Requests/Email/SendEmailRequest.php index b7bab220cca2..e0a2a5bfbea0 100644 --- a/app/Http/Requests/Email/SendEmailRequest.php +++ b/app/Http/Requests/Email/SendEmailRequest.php @@ -50,11 +50,13 @@ class SendEmailRequest extends Request $settings = auth()->user()->company()->settings; - if(empty($input['template'])) + if (empty($input['template'])) { $input['template'] = ''; + } - if(!property_exists($settings, $input['template'])) + if (!property_exists($settings, $input['template'])) { unset($input['template']); + } $input['entity_id'] = $this->decodePrimaryKey($input['entity_id']); $input['entity'] = "App\Models\\". ucfirst($input['entity']); @@ -74,8 +76,7 @@ class SendEmailRequest extends Request $input = $this->all(); /*Make sure we have all the require ingredients to send a template*/ - if(array_key_exists('entity', $input) && array_key_exists('entity_id', $input) && is_string($input['entity']) && $input['entity_id']) { - + if (array_key_exists('entity', $input) && array_key_exists('entity_id', $input) && is_string($input['entity']) && $input['entity_id']) { $company = auth()->user()->company(); $entity = $input['entity']; @@ -84,9 +85,9 @@ class SendEmailRequest extends Request $entity_obj = $entity::whereId($input['entity_id'])->company()->first(); /* Check object, check user and company id is same as users, and check user can edit the object */ - if($entity_obj && ($company->id == $entity_obj->company_id) && auth()->user()->can('edit', $entity_obj)) + if ($entity_obj && ($company->id == $entity_obj->company_id) && auth()->user()->can('edit', $entity_obj)) { return true; - + } } return false; diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index 6e00a5a59906..349d255e489b 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -20,7 +20,6 @@ use Symfony\Component\HttpFoundation\Response; class CreateAccount { - use Dispatchable; protected $request; @@ -32,27 +31,25 @@ class CreateAccount public function handle() { - - if(config('ninja.environment') == 'selfhost' && Account::all()->count() == 0) { + if (config('ninja.environment') == 'selfhost' && Account::all()->count() == 0) { return $this->create(); - }elseif (config('ninja.environment') == 'selfhost' && Account::all()->count() > 1) { - return response()->json(array('message' => Ninja::selfHostedMessage()), 400); + } elseif (config('ninja.environment') == 'selfhost' && Account::all()->count() > 1) { + return response()->json(array('message' => Ninja::selfHostedMessage()), 400); } elseif (!Ninja::boot()) { - return response()->json(array('message' => Ninja::parse()), 401); + return response()->json(array('message' => Ninja::parse()), 401); } return $this->create(); - } private function create() { - $sp794f3f = Account::create($this->request); $sp794f3f->referral_code = Str::random(32); - if(!$sp794f3f->key) + if (!$sp794f3f->key) { $sp794f3f->key = Str::random(32); + } $sp794f3f->save(); @@ -80,7 +77,5 @@ class CreateAccount $sp035a66->notification(new NewAccountCreated($spaa9f78, $sp035a66))->ninja(); return $sp794f3f; - } - } diff --git a/app/Jobs/Util/StartMigration.php b/app/Jobs/Util/StartMigration.php index dc1de72fc28d..7025bd751f9c 100644 --- a/app/Jobs/Util/StartMigration.php +++ b/app/Jobs/Util/StartMigration.php @@ -65,7 +65,6 @@ class StartMigration implements ShouldQueue */ public function handle() { - MultiDB::setDb($this->company->db); auth()->login($this->user, false); @@ -80,7 +79,6 @@ class StartMigration implements ShouldQueue $filename = pathinfo($this->filepath, PATHINFO_FILENAME); try { - if (!$archive) { throw new ProcessingMigrationArchiveFailed('Processing migration archive failed. Migration file is possibly corrupted.'); } @@ -103,10 +101,7 @@ class StartMigration implements ShouldQueue $data = json_decode(file_get_contents($file), 1); Import::dispatchNow($data, $this->company, $this->user); - - } catch (NonExistingMigrationFile | ProcessingMigrationArchiveFailed | ResourceNotAvailableForMigration | MigrationValidatorFailed | ResourceDependencyMissing $e) { - $this->company->setMigration(false); Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage())); @@ -115,11 +110,9 @@ class StartMigration implements ShouldQueue info($e->getMessage()); } } - } public function failed($exception = null) { } - } diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 0920227a47ce..457eee507023 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -182,7 +182,6 @@ class MultiDB public static function findAndSetDbByDomain($subdomain) :bool { - foreach (self::$dbs as $db) { if ($company = Company::on($db)->whereSubdomain($subdomain)->first()) { self::setDb($company->db); diff --git a/app/Listeners/Invoice/DeleteInvoiceActivity.php b/app/Listeners/Invoice/DeleteInvoiceActivity.php new file mode 100644 index 000000000000..e8eff7a3b3e8 --- /dev/null +++ b/app/Listeners/Invoice/DeleteInvoiceActivity.php @@ -0,0 +1,53 @@ +activity_repo = $activity_repo; + } + + /** + * Handle the event. + * + * @param object $event + * @return void + */ + public function handle($event) + { + $fields = new \stdClass; + + $fields->invoice_id = $event->invoice->id; + $fields->user_id = $event->invoice->user_id; + $fields->company_id = $event->invoice->company_id; + $fields->activity_type_id = Activity::DELETE_INVOICE; + + $this->activity_repo->save($fields, $event->invoice); + } +} diff --git a/app/Listeners/Payment/PaymentNotification.php b/app/Listeners/Payment/PaymentNotification.php index 3622f644c1a9..19944e4d4796 100644 --- a/app/Listeners/Payment/PaymentNotification.php +++ b/app/Listeners/Payment/PaymentNotification.php @@ -44,15 +44,14 @@ class PaymentNotification implements ShouldQueue $payment = $event->payment; foreach ($payment->company->company_users as $company_user) { - $user = $company_user->user; $notification = new NewPaymentNotification($payment, $payment->company); $notification->method = $this->findUserEntityNotificationType($payment, $company_user, ['all_notifications']); - if($user) + if ($user) { $user->notify($notification); - + } } if (isset($payment->company->slack_webhook_url)) { diff --git a/app/Listeners/SendVerificationNotification.php b/app/Listeners/SendVerificationNotification.php index 8c405603cac2..2a5a311bf813 100644 --- a/app/Listeners/SendVerificationNotification.php +++ b/app/Listeners/SendVerificationNotification.php @@ -47,14 +47,10 @@ class SendVerificationNotification implements ShouldQueue MultiDB::setDB($event->company->db); try { - $event->user->notify(new VerifyUser($event->user)); Ninja::registerNinjaUser($event->user); - - } - catch(\Exception $e){ - + } catch (\Exception $e) { } } } diff --git a/app/Listeners/User/UpdateUserLastLogin.php b/app/Listeners/User/UpdateUserLastLogin.php index 04afbcd3d164..f9a8afe5839f 100644 --- a/app/Listeners/User/UpdateUserLastLogin.php +++ b/app/Listeners/User/UpdateUserLastLogin.php @@ -39,7 +39,7 @@ class UpdateUserLastLogin implements ShouldQueue * @return void */ public function handle($event) - { + { $user = $event->user; $user->last_login = now(); diff --git a/app/Models/Client.php b/app/Models/Client.php index f0f315533410..fc077fb433c4 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -332,16 +332,14 @@ class Client extends BaseModel implements HasLocalePreference { $company_gateways = $this->getSetting('company_gateway_ids'); - info($company_gateways); -info($this->company->id); + info($company_gateways); + info($this->company->id); if (strlen($company_gateways)>=1) { $gateways = $this->company->company_gateways->whereIn('id', $payment_gateways); } else { $gateways = $this->company->company_gateways; } -\Log::error($gateways); - foreach ($gateways as $gateway) { if (in_array(GatewayType::CREDIT_CARD, $gateway->driver($this)->gatewayTypes())) { return $gateway; diff --git a/app/Models/Company.php b/app/Models/Company.php index 3f0ec0f05f40..995879a7add1 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -391,10 +391,9 @@ class Company extends BaseModel public function setMigration($status) { - $this->company_users->each(function ($cu) use($status){ + $this->company_users->each(function ($cu) use ($status) { $cu->is_migrating=$status; $cu->save(); }); } - } diff --git a/app/Models/CompanyUser.php b/app/Models/CompanyUser.php index e98fdc4723f4..bd357ca19190 100644 --- a/app/Models/CompanyUser.php +++ b/app/Models/CompanyUser.php @@ -55,12 +55,12 @@ class CompanyUser extends Pivot public function user_pivot() { - return $this->hasOne(User::class)->withPivot('permissions', 'settings', 'is_admin', 'is_owner', 'is_locked', 'slack_webhook_url','migrating'); + return $this->hasOne(User::class)->withPivot('permissions', 'settings', 'is_admin', 'is_owner', 'is_locked', 'slack_webhook_url', 'migrating'); } public function company_pivot() { - return $this->hasOne(Company::class)->withPivot('permissions', 'settings', 'is_admin', 'is_owner', 'is_locked', 'slack_webhook_url','migrating'); + return $this->hasOne(Company::class)->withPivot('permissions', 'settings', 'is_admin', 'is_owner', 'is_locked', 'slack_webhook_url', 'migrating'); } public function user() diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 7cfa471cd9ed..3d65b1e454cf 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -78,26 +78,29 @@ class Credit extends BaseModel const STATUS_PARTIAL = 3; const STATUS_APPLIED = 4; - public function getDateAttribute($value) { + public function getDateAttribute($value) + { if (!empty($value)) { //$value format 'Y:m:d H:i:s' to 'Y-m-d H:i' - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getDueDateAttribute($value) { + public function getDueDateAttribute($value) + { if (!empty($value)) { //$value format 'Y:m:d H:i:s' to 'Y-m-d H:i' - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getPartialDueDateAttribute($value) { + public function getPartialDueDateAttribute($value) + { if (!empty($value)) { //$value format 'Y:m:d H:i:s' to 'Y-m-d H:i' - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php index aabd03b3a6a9..cc76d7e673dd 100644 --- a/app/Models/CreditInvitation.php +++ b/app/Models/CreditInvitation.php @@ -33,30 +33,34 @@ class CreditInvitation extends BaseModel // 'company', ]; - public function getSignatureDateAttribute($value) { + public function getSignatureDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getSentDateAttribute($value) { + public function getSentDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getViewedDateAttribute($value) { + public function getViewedDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getOpenedDateAttribute($value) { + public function getOpenedDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index bbd4b964909d..0d772959d42a 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -128,23 +128,26 @@ class Invoice extends BaseModel const STATUS_UNPAID = -2; const STATUS_REVERSED = -3; - public function getDateAttribute($value) { + public function getDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getDueDateAttribute($value) { + public function getDueDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getPartialDueDateAttribute($value) { + public function getPartialDueDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 95cea4b983fb..5906d588c00f 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -34,30 +34,34 @@ class InvoiceInvitation extends BaseModel ]; - public function getSignatureDateAttribute($value) { + public function getSignatureDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getSentDateAttribute($value) { + public function getSentDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getViewedDateAttribute($value) { + public function getViewedDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getOpenedDateAttribute($value) { + public function getOpenedDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 9a062fab6fd4..86fb9a6c422a 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -84,23 +84,26 @@ class Quote extends BaseModel const STATUS_APPROVED = 3; const STATUS_EXPIRED = -1; - public function getDateAttribute($value) { + public function getDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getDueDateAttribute($value) { + public function getDueDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getPartialDueDateAttribute($value) { + public function getPartialDueDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } diff --git a/app/Models/QuoteInvitation.php b/app/Models/QuoteInvitation.php index f23b75ae7e24..5180524a92c9 100644 --- a/app/Models/QuoteInvitation.php +++ b/app/Models/QuoteInvitation.php @@ -27,30 +27,34 @@ class QuoteInvitation extends BaseModel 'client_contact_id', ]; - public function getSignatureDateAttribute($value) { + public function getSignatureDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getSentDateAttribute($value) { + public function getSentDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getViewedDateAttribute($value) { + public function getViewedDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getOpenedDateAttribute($value) { + public function getOpenedDateAttribute($value) + { if (!$value) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } diff --git a/app/Models/RecurringInvoice.php b/app/Models/RecurringInvoice.php index 1f63012dbdc2..8af1bc21016e 100644 --- a/app/Models/RecurringInvoice.php +++ b/app/Models/RecurringInvoice.php @@ -111,23 +111,26 @@ class RecurringInvoice extends BaseModel 'status' ]; - public function getDateAttribute($value) { + public function getDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getDueDateAttribute($value) { + public function getDueDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getPartialDueDateAttribute($value) { + public function getPartialDueDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } diff --git a/app/Models/RecurringQuote.php b/app/Models/RecurringQuote.php index 4ed6990222f8..e71c33bad636 100644 --- a/app/Models/RecurringQuote.php +++ b/app/Models/RecurringQuote.php @@ -94,23 +94,26 @@ class RecurringQuote extends BaseModel // 'company', ]; - public function getDateAttribute($value) { + public function getDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getDueDateAttribute($value) { + public function getDueDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } - public function getPartialDueDateAttribute($value) { + public function getPartialDueDateAttribute($value) + { if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); + return (new Carbon($value))->format('Y-m-d'); } return $value; } diff --git a/app/Models/User.php b/app/Models/User.php index 64b0e11e896b..dddededc5a2f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -289,8 +289,9 @@ class User extends Authenticatable implements MustVerifyEmail $parts = explode("_", $permission); $all_permission = ''; - if(count($parts) > 1) + if (count($parts) > 1) { $all_permission = $parts[0] . '_all'; + } return $this->isOwner() || $this->isAdmin() || diff --git a/app/Notifications/Admin/InvoiceViewedNotification.php b/app/Notifications/Admin/InvoiceViewedNotification.php index 0ee1deb4aca5..a99dddc5fc74 100644 --- a/app/Notifications/Admin/InvoiceViewedNotification.php +++ b/app/Notifications/Admin/InvoiceViewedNotification.php @@ -89,7 +89,7 @@ class InvoiceViewedNotification extends Notification implements ShouldQueue // if($this->settings->email_style == 'custom'){ - // $subject = + // $subject = // return (new MailMessage) // ->subject($subject) diff --git a/app/Notifications/Admin/NewPaymentNotification.php b/app/Notifications/Admin/NewPaymentNotification.php index c1ac51221987..e0828f73efe9 100644 --- a/app/Notifications/Admin/NewPaymentNotification.php +++ b/app/Notifications/Admin/NewPaymentNotification.php @@ -35,13 +35,11 @@ class NewPaymentNotification extends Notification implements ShouldQueue public function __construct($payment, $company, $is_system = false, $settings = null) { - $this->payment = $payment; $this->company = $company; $this->settings = $payment->client->getMergedSettings(); $this->is_system = $is_system; $this->method = null; - } /** diff --git a/app/Notifications/SendGenericNotification.php b/app/Notifications/SendGenericNotification.php index 9c72bc1e04f3..e35a40a30d25 100644 --- a/app/Notifications/SendGenericNotification.php +++ b/app/Notifications/SendGenericNotification.php @@ -70,13 +70,12 @@ class SendGenericNotification extends Notification implements ShouldQueue */ public function toMail($notifiable) { - $subject = $this->generateEmailEntityHtml($this->entity, $this->subject, $this->contact); $body = $this->generateEmailEntityHtml($this->entity, $this->body, $this->contact); $design_style = $this->settings->email_style; - if($design_style == 'custom') { + if ($design_style == 'custom') { $email_style_custom = $this->settings->email_style_custom; $body = str_replace("$body", $body, $email_style_custom); } @@ -96,7 +95,6 @@ class SendGenericNotification extends Notification implements ShouldQueue return (new MailMessage) ->subject($subject) ->markdown('email.admin.generic_email', $data); - } /** @@ -114,7 +112,6 @@ class SendGenericNotification extends Notification implements ShouldQueue public function toSlack($notifiable) { - return ''; // $logo = $this->company->present()->logo(); // $amount = Number::formatMoney($this->invoice->amount, $this->invoice->client); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 36bff8015ce3..3bb397b03a54 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -43,7 +43,6 @@ use Illuminate\Support\Facades\Queue; use Illuminate\Queue\Events\JobFailed; use Illuminate\Queue\Events\JobProcessing; - class AppServiceProvider extends ServiceProvider { /** @@ -89,7 +88,6 @@ class AppServiceProvider extends ServiceProvider // \Log::error('Event Job '.$event->job->getJobId); // // \Log::info('Event Job '.$event->job->payload()); // }); - } /** @@ -100,8 +98,6 @@ class AppServiceProvider extends ServiceProvider public function register() { $this->loadHelpers(); - - } protected function loadHelpers() diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 032161cbc375..df696168013c 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -16,6 +16,7 @@ use App\Events\Company\CompanyWasDeleted; use App\Events\Contact\ContactLoggedIn; use App\Events\Credit\CreditWasMarkedSent; use App\Events\Invoice\InvoiceWasCreated; +use App\Events\Invoice\InvoiceWasDeleted; use App\Events\Invoice\InvoiceWasEmailed; use App\Events\Invoice\InvoiceWasMarkedSent; use App\Events\Invoice\InvoiceWasPaid; @@ -39,6 +40,7 @@ use App\Listeners\Invoice\CreateInvoiceActivity; use App\Listeners\Invoice\CreateInvoiceHtmlBackup; use App\Listeners\Invoice\CreateInvoiceInvitation; use App\Listeners\Invoice\CreateInvoicePdf; +use App\Listeners\Invoice\DeleteInvoiceActivity; use App\Listeners\Invoice\InvoiceEmailActivity; use App\Listeners\Invoice\InvoiceEmailFailedActivity; use App\Listeners\Invoice\InvoiceEmailedNotification; @@ -136,7 +138,9 @@ class EventServiceProvider extends ServiceProvider InvoiceWasEmailedAndFailed::class => [ InvoiceEmailFailedActivity::class, ], - + InvoiceWasDeleted::class => [ + DeleteInvoiceActivity::class, + ], InvitationWasViewed::class => [ InvitationViewedListener::class ], @@ -166,7 +170,7 @@ class EventServiceProvider extends ServiceProvider // } public function boot() - { - parent::boot(); - } + { + parent::boot(); + } } diff --git a/app/Providers/MultiDBProvider.php b/app/Providers/MultiDBProvider.php index aa550d035c95..3cd7fc0d3792 100644 --- a/app/Providers/MultiDBProvider.php +++ b/app/Providers/MultiDBProvider.php @@ -32,13 +32,10 @@ class MultiDBProvider extends ServiceProvider */ public function register() { - $this->app['events']->listen( \Illuminate\Queue\Events\JobProcessing::class, function ($event) { - if (isset($event->job->payload()['db'])) { - MultiDB::setDb($event->job->payload()['db']); } } @@ -48,6 +45,5 @@ class MultiDBProvider extends ServiceProvider if ($this->app->runningInConsole()) { return; } - } } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index b0fa871dff4b..cf43c56a3178 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -213,11 +213,13 @@ class BaseRepository /* We need to unset some variable as we sometimes unguard the model */ - if(isset($tmp_data['invitations'])) + if (isset($tmp_data['invitations'])) { unset($tmp_data['invitations']); + } - if(isset($tmp_data['client_contacts'])) + if (isset($tmp_data['client_contacts'])) { unset($tmp_data['client_contacts']); + } $model->fill($tmp_data); diff --git a/app/Repositories/InvoiceRepository.php b/app/Repositories/InvoiceRepository.php index 26e063dad0a8..7ef315c1691d 100644 --- a/app/Repositories/InvoiceRepository.php +++ b/app/Repositories/InvoiceRepository.php @@ -11,6 +11,7 @@ namespace App\Repositories; +use App\Events\Invoice\InvoiceWasDeleted; use App\Factory\InvoiceInvitationFactory; use App\Jobs\Product\UpdateOrCreateProduct; use App\Models\Client; @@ -66,4 +67,20 @@ class InvoiceRepository extends BaseRepository { return InvoiceInvitation::whereRaw("BINARY `key`= ?", [$key])->first(); } + + public function delete($invoice) + { + if ($invoice->is_deleted) { + return; + } + + $invoice->is_deleted = true; + $invoice->save(); + + $invoice->delete(); + + if (class_exists($className)) { + event(new InvoiceWasDeleted($invoice)); + } + } } diff --git a/app/Services/Invoice/HandleDeletion.php b/app/Services/Invoice/HandleDeletion.php new file mode 100644 index 000000000000..dc83aa16b25c --- /dev/null +++ b/app/Services/Invoice/HandleDeletion.php @@ -0,0 +1,54 @@ +invoice = $invoice; + } + + public function run() + { + $balance_remainig = $this->invoice->balance; + $total_paid = $this->invoice->amount - $this->invoice->balance; + + //change invoice status + + //set invoice balance to 0 + + //decrease client balance by $total_paid + + //remove paymentables from payment + + //decreate client paid_to_date by $total_paid + + //generate credit for the $total paid + + } +} diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index c4276e14b46d..f960a4f3d340 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -18,6 +18,7 @@ use App\Services\Invoice\ApplyNumber; use App\Services\Invoice\ApplyPayment; use App\Services\Invoice\CreateInvitations; use App\Services\Invoice\GetInvoicePdf; +use App\Services\Invoice\HandleDeletion; use App\Services\Invoice\MarkInvoicePaid; use App\Services\Invoice\MarkSent; use App\Services\Invoice\UpdateBalance; @@ -43,9 +44,7 @@ class InvoiceService */ public function markPaid() { - $mark_invoice_paid = new MarkPaid($this->client_service, $this->invoice); - - $this->invoice = $mark_invoice_paid->run(); + $this->invoice = (new MarkPaid($this->client_service, $this->invoice))->run(); return $this; } @@ -56,9 +55,7 @@ class InvoiceService */ public function applyNumber() { - $apply_number = new ApplyNumber($this->invoice->client, $this->invoice); - - $this->invoice = $apply_number->run(); + $this->invoice = (new ApplyNumber($this->invoice->client, $this->invoice))->run(); return $this; } @@ -71,9 +68,7 @@ class InvoiceService */ public function applyPayment(Payment $payment, float $payment_amount) { - $apply_payment = new ApplyPayment($this->invoice, $payment, $payment_amount); - - $this->invoice = $apply_payment->run(); + $this->invoice = (new ApplyPayment($this->invoice, $payment, $payment_amount))->run(); return $this; } @@ -87,29 +82,23 @@ class InvoiceService */ public function updateBalance($balance_adjustment) { - $update_balance = new UpdateBalance($this->invoice, $balance_adjustment); - - $this->invoice = $update_balance->run(); + $this->invoice = (new UpdateBalance($this->invoice, $balance_adjustment))->run(); return $this; } public function createInvitations() { - $create_invitation = new CreateInvitations($this->invoice); - - $this->invoice = $create_invitation->run(); + $this->invoice = (new CreateInvitations($this->invoice))->run(); return $this; } public function markSent() { - $mark_sent = new MarkSent($this->invoice->client, $this->invoice); + $this->invoice = (new MarkSent($this->invoice->client, $this->invoice))->run(); - $this->invoice = $mark_sent->run(); - - return $this; + return $this; } @@ -127,6 +116,13 @@ class InvoiceService return $send_email->run(); } + public function handleDeletion() + { + $this->invoice = (new HandleDeletion($this->invoice))->run(); + + return $this; + } + public function markViewed() { $this->invoice->last_viewed = Carbon::now()->format('Y-m-d H:i'); @@ -166,14 +162,6 @@ class InvoiceService - - - - - - - - /** * Saves the invoice * @return Invoice object diff --git a/app/Utils/TemplateEngine.php b/app/Utils/TemplateEngine.php index c9e06a1cba9d..82da3236b3d0 100644 --- a/app/Utils/TemplateEngine.php +++ b/app/Utils/TemplateEngine.php @@ -156,15 +156,14 @@ class TemplateEngine $data['footer'] = ''; if ($email_style == 'custom') { - $wrapper = $this->settings_entity->getSetting('email_style_custom'); /*If no custom design exists, send back a blank!*/ - if(strlen($wrapper) > 1) + if (strlen($wrapper) > 1) { $wrapper = $this->renderView($wrapper, $data); - else + } else { $wrapper = ''; - + } } else { $wrapper = $this->getTemplate(); $wrapper = view($this->getTemplatePath($email_style), $data)->render(); diff --git a/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php b/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php index df7832269caf..5cc966a3c9de 100644 --- a/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php +++ b/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php @@ -98,6 +98,4 @@ trait CompanyGatewayFeesAndLimitsSaver return $new_arr; } - - } diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index 69830861a4f9..82ad02f5f18c 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -45,7 +45,12 @@ trait GeneratesCounter $pattern = $client->getSetting('invoice_number_pattern'); //Determine if we are using client_counters if (strpos($pattern, 'clientCounter')) { - $counter = $client->settings->invoice_number_counter; + if (property_exists($client->settings, 'invoice_number_counter')) { + $counter = $client->settings->invoice_number_counter; + } else { + $counter = 1; + } + $counter_entity = $client; } elseif (strpos($pattern, 'groupCounter')) { $counter = $client->group_settings->invoice_number_counter; @@ -297,6 +302,10 @@ trait GeneratesCounter { $settings = $entity->settings; + if ($counter_name == 'invoice_number_counter' && !property_exists($entity->settings, 'invoice_number_counter')) { + $settings->invoice_number_counter = 0; + } + $settings->{$counter_name} = $settings->{$counter_name} + 1; $entity->settings = $settings; diff --git a/app/Utils/Traits/MakesInvoiceHtml.php b/app/Utils/Traits/MakesInvoiceHtml.php index c45b1732d734..22c38f5c3c03 100644 --- a/app/Utils/Traits/MakesInvoiceHtml.php +++ b/app/Utils/Traits/MakesInvoiceHtml.php @@ -74,7 +74,6 @@ trait MakesInvoiceHtml $values = $entity->makeValues($contact); return $this->parseLabelsAndValues($labels, $values, $content); - } private function parseLabelsAndValues($labels, $values, $section) :string diff --git a/app/Utils/Traits/Notifications/UserNotifies.php b/app/Utils/Traits/Notifications/UserNotifies.php index 5c5b1d06ed70..8e5ce3a7cf30 100644 --- a/app/Utils/Traits/Notifications/UserNotifies.php +++ b/app/Utils/Traits/Notifications/UserNotifies.php @@ -19,9 +19,9 @@ trait UserNotifies { public function findUserNotificationTypes($invitation, $company_user, $entity_name, $required_permissions) :array { - - if($this->migrationRunning($company_user)) + if ($this->migrationRunning($company_user)) { return []; + } $notifiable_methods = []; $notifications = $company_user->notifications; @@ -43,9 +43,9 @@ trait UserNotifies public function findUserEntityNotificationType($entity, $company_user, $required_permissions) :array { - - if($this->migrationRunning($company_user)) + if ($this->migrationRunning($company_user)) { return []; + } $notifiable_methods = []; $notifications = $company_user->notifications; @@ -62,7 +62,6 @@ trait UserNotifies // array_push($notifiable_methods, 'slack'); return $notifiable_methods; - } private function migrationRunning($company_user) diff --git a/config/ninja.php b/config/ninja.php index 8c5b55de6d78..ce51168c6cba 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -11,7 +11,7 @@ return [ 'app_env' => env('APP_ENV', 'local'), 'app_url' => env('APP_URL', ''), 'app_domain' => env('APP_DOMAIN', ''), - 'app_version' => '0.0.1', + 'app_version' => '0.0.2', 'api_version' => '0.0.1', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 707afe95fc15..f3097930291e 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3193,4 +3193,5 @@ return [ 'oops_issues' => 'Oops, something doesn\'t look right!', 'open_in_new_tab' => 'Open in new tab', + 'complete_your_payment' => 'Complete payment', ]; diff --git a/resources/views/portal/ninja2020/auth/login.blade.php b/resources/views/portal/ninja2020/auth/login.blade.php index 092a65e0b548..d11dd3d1a5e2 100644 --- a/resources/views/portal/ninja2020/auth/login.blade.php +++ b/resources/views/portal/ninja2020/auth/login.blade.php @@ -11,8 +11,7 @@
{{ ctrans('texts.account_login_text') }}
+