diff --git a/app/Casts/EncryptedCast.php b/app/Casts/EncryptedCast.php index da17fac8b9..e13c69625d 100644 --- a/app/Casts/EncryptedCast.php +++ b/app/Casts/EncryptedCast.php @@ -17,11 +17,11 @@ class EncryptedCast implements CastsAttributes { public function get($model, string $key, $value, array $attributes) { - return ! is_null($value) ? decrypt($value) : null; + return strlen($value) > 1 ? decrypt($value) : null; } public function set($model, string $key, $value, array $attributes) - { + { return [$key => ! is_null($value) ? encrypt($value) : null]; } } diff --git a/app/Jobs/Entity/EmailEntity.php b/app/Jobs/Entity/EmailEntity.php index 82cbef1929..41473f1b8f 100644 --- a/app/Jobs/Entity/EmailEntity.php +++ b/app/Jobs/Entity/EmailEntity.php @@ -150,23 +150,6 @@ class EmailEntity implements ShouldQueue return ''; } - /** - * @deprecated - * @unused - */ - // private function entityEmailFailed($message) - // { - // switch ($this->entity_string) { - // case 'invoice': - // event(new InvoiceWasEmailedAndFailed($this->invitation, $this->company, $message, $this->reminder_template, Ninja::eventVars(auth()->user() ? auth()->user()->id : null))); - // break; - - // default: - // // code... - // break; - // } - // } - /* Builds the email builder object */ private function resolveEmailBuilder() { diff --git a/app/Listeners/Invoice/InvoiceEmailedNotification.php b/app/Listeners/Invoice/InvoiceEmailedNotification.php index bf0859e2da..1f37e7938d 100644 --- a/app/Listeners/Invoice/InvoiceEmailedNotification.php +++ b/app/Listeners/Invoice/InvoiceEmailedNotification.php @@ -63,20 +63,6 @@ class InvoiceEmailedNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); - // $template = $event->template ?? ''; - - // if(isset($event->reminder)){ - - // $template = match($event->reminder){ - // 63 => 'reminder1', - // 64 => 'reminder2', - // 65 => 'reminder3', - // 66 => 'endless_reminder', - // default => '' - // }; - - // } - $nmo = new NinjaMailerObject; $nmo->mailable = new NinjaMailer((new EntitySentObject($event->invitation, 'invoice', $event->template))->build()); $nmo->company = $invoice->company; diff --git a/app/Services/Chart/ChartQueries.php b/app/Services/Chart/ChartQueries.php index f4d0fb509d..7f284736c5 100644 --- a/app/Services/Chart/ChartQueries.php +++ b/app/Services/Chart/ChartQueries.php @@ -23,20 +23,26 @@ trait ChartQueries */ public function getExpenseQuery($start_date, $end_date) { - return DB::select(DB::raw(' + $user_filter = $this->is_admin ? '' : 'AND expenses.user_id = '.$this->user->id; + + return DB::select(DB::raw(" SELECT sum(expenses.amount) as amount, IFNULL(expenses.currency_id, :company_currency) as currency_id FROM expenses WHERE expenses.is_deleted = 0 AND expenses.company_id = :company_id AND (expenses.date BETWEEN :start_date AND :end_date) + {$user_filter} GROUP BY currency_id - '), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]); + "), ['company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, 'end_date' => $end_date]); } public function getExpenseChartQuery($start_date, $end_date, $currency_id) { - return DB::select(DB::raw(' + + $user_filter = $this->is_admin ? '' : 'AND expenses.user_id = '.$this->user->id; + + return DB::select(DB::raw(" SELECT sum(expenses.amount) as total, expenses.date, @@ -45,9 +51,10 @@ trait ChartQueries WHERE (expenses.date BETWEEN :start_date AND :end_date) AND expenses.company_id = :company_id AND expenses.is_deleted = 0 + {$user_filter} GROUP BY expenses.date HAVING currency_id = :currency_id - '), [ + "), [ 'company_currency' => $this->company->settings->currency_id, 'currency_id' => $currency_id, 'company_id' => $this->company->id, @@ -61,15 +68,19 @@ trait ChartQueries */ public function getPaymentQuery($start_date, $end_date) { - return DB::select(DB::raw(' + + $user_filter = $this->is_admin ? '' : 'AND payments.user_id = '.$this->user->id; + + return DB::select(DB::raw(" SELECT sum(payments.amount) as amount, IFNULL(payments.currency_id, :company_currency) as currency_id FROM payments WHERE payments.is_deleted = 0 + {$user_filter} AND payments.company_id = :company_id AND (payments.date BETWEEN :start_date AND :end_date) GROUP BY currency_id - '), [ + "), [ 'company_currency' => $this->company->settings->currency_id, 'company_id' => $this->company->id, 'start_date' => $start_date, @@ -79,7 +90,10 @@ trait ChartQueries public function getPaymentChartQuery($start_date, $end_date, $currency_id) { - return DB::select(DB::raw(' + + $user_filter = $this->is_admin ? '' : 'AND payments.user_id = '.$this->user->id; + + return DB::select(DB::raw(" SELECT sum(payments.amount - payments.refunded) as total, payments.date, @@ -87,11 +101,12 @@ trait ChartQueries FROM payments WHERE payments.company_id = :company_id AND payments.is_deleted = 0 + {$user_filter} AND payments.status_id IN (4,5,6) AND (payments.date BETWEEN :start_date AND :end_date) GROUP BY payments.date HAVING currency_id = :currency_id - '), [ + "), [ 'company_currency' => $this->company->settings->currency_id, 'currency_id' => $currency_id, 'company_id' => $this->company->id, @@ -105,6 +120,9 @@ trait ChartQueries */ public function getOutstandingQuery($start_date, $end_date) { + + $user_filter = $this->is_admin ? '' : 'AND clients.user_id = '.$this->user->id; + return DB::select(DB::raw(" SELECT sum(invoices.balance) as amount, @@ -116,6 +134,7 @@ trait ChartQueries WHERE invoices.status_id IN (2,3) AND invoices.company_id = :company_id AND clients.is_deleted = 0 + {$user_filter} AND invoices.is_deleted = 0 AND invoices.balance > 0 AND (invoices.date BETWEEN :start_date AND :end_date) @@ -125,6 +144,8 @@ trait ChartQueries public function getRevenueQuery($start_date, $end_date) { + $user_filter = $this->is_admin ? '' : 'AND clients.user_id = '.$this->user->id; + return DB::select(DB::raw(" SELECT sum(invoices.paid_to_date) as paid_to_date, @@ -134,6 +155,7 @@ trait ChartQueries on invoices.client_id = clients.id WHERE invoices.company_id = :company_id AND clients.is_deleted = 0 + {$user_filter} AND invoices.is_deleted = 0 AND invoices.amount > 0 AND invoices.status_id IN (3,4) @@ -144,6 +166,8 @@ trait ChartQueries public function getInvoicesQuery($start_date, $end_date) { + $user_filter = $this->is_admin ? '' : 'AND clients.user_id = '.$this->user->id; + return DB::select(DB::raw(" SELECT sum(invoices.amount) as invoiced_amount, @@ -153,6 +177,7 @@ trait ChartQueries on invoices.client_id = clients.id WHERE invoices.status_id IN (2,3,4) AND invoices.company_id = :company_id + {$user_filter} AND invoices.amount > 0 AND clients.is_deleted = 0 AND invoices.is_deleted = 0 @@ -163,6 +188,8 @@ trait ChartQueries public function getOutstandingChartQuery($start_date, $end_date, $currency_id) { + $user_filter = $this->is_admin ? '' : 'AND clients.user_id = '.$this->user->id; + return DB::select(DB::raw(" SELECT sum(invoices.balance) as total, @@ -175,6 +202,7 @@ trait ChartQueries AND invoices.company_id = :company_id AND clients.is_deleted = 0 AND invoices.is_deleted = 0 + {$user_filter} AND (invoices.date BETWEEN :start_date AND :end_date) GROUP BY invoices.date HAVING currency_id = :currency_id @@ -190,6 +218,8 @@ trait ChartQueries public function getInvoiceChartQuery($start_date, $end_date, $currency_id) { + $user_filter = $this->is_admin ? '' : 'AND clients.user_id = '.$this->user->id; + return DB::select(DB::raw(" SELECT sum(invoices.amount) as total, @@ -201,6 +231,7 @@ trait ChartQueries WHERE invoices.company_id = :company_id AND clients.is_deleted = 0 AND invoices.is_deleted = 0 + {$user_filter} AND invoices.status_id IN (2,3,4) AND (invoices.date BETWEEN :start_date AND :end_date) GROUP BY invoices.date