Skip to content

A free open source IT asset/license management system

Figure out declined notifications

Ivan Nieto Vivancoa33ca3923739
diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php
index 2146d52007..59c8f88430 100644
--- a/app/Http/Controllers/Account/AcceptanceController.php
+++ b/app/Http/Controllers/Account/AcceptanceController.php
@@ -20,6 +20,7 @@ use App\Models\License;
use App\Models\Component;
use App\Models\Consumable;
use App\Notifications\AcceptanceAssetAcceptedNotification;
+use App\Notifications\AcceptanceAssetDeclinedNotification;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
@@ -243,7 +244,43 @@ class AcceptanceController extends Controller
$return_msg = trans('admin/users/message.accepted');
} else {
+ // Format the data to send the declined notification
+ $branding_settings = SettingsController::getPDFBranding();
+
+ // This is the most horriblest
+ switch($acceptance->checkoutable_type){
+ case 'App\Models\Asset':
+ $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
+ break;
+
+ case 'App\Models\Accessory':
+ $assigned_to = User::find($item->assignedTo);
+ break;
+
+ case 'App\Models\LicenseSeat':
+ $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
+ break;
+
+ case 'App\Models\Component':
+ $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
+ break;
+
+ case 'App\Models\Consumable':
+ $assigned_to = User::find($acceptance->assigned_to_id)->present()->fullName;
+ break;
+ }
+ $data = [
+ 'item_tag' => $item->asset_tag,
+ 'item_model' => $display_model,
+ 'item_serial' => $item->serial,
+ 'declined_date' => Carbon::parse($acceptance->accepted_at)->format($branding_settings->date_display_format),
+ 'assigned_to' => $assigned_to,
+ 'company_name' => $branding_settings->site_name,
+ 'date_settings' => $branding_settings->date_display_format,
+ ];
+
$acceptance->decline($sig_filename);
+ $acceptance->notify(new AcceptanceAssetDeclinedNotification($data));
event(new CheckoutDeclined($acceptance));
$return_msg = trans('admin/users/message.declined');
}
diff --git a/app/Notifications/AcceptanceAssetAcceptedNotification.php b/app/Notifications/AcceptanceAssetAcceptedNotification.php
index 29d1dcba57..c667588dae 100644
--- a/app/Notifications/AcceptanceAssetAcceptedNotification.php
+++ b/app/Notifications/AcceptanceAssetAcceptedNotification.php
@@ -24,7 +24,7 @@ class AcceptanceAssetAcceptedNotification extends Notification
$this->item_tag = $params['item_tag'];
$this->item_model = $params['item_model'];
$this->item_serial = $params['item_serial'];
- $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'datetime', false);
+ $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'date', false);
$this->assigned_to = $params['assigned_to'];
$this->company_name = $params['company_name'];
$this->settings = Setting::getSettings();
diff --git a/app/Notifications/AcceptanceAssetDeclinedNotification.php b/app/Notifications/AcceptanceAssetDeclinedNotification.php
index 8085bb7d30..9446747353 100644
--- a/app/Notifications/AcceptanceAssetDeclinedNotification.php
+++ b/app/Notifications/AcceptanceAssetDeclinedNotification.php
@@ -24,7 +24,7 @@ class AcceptanceAssetDeclinedNotification extends Notification
$this->item_tag = $params['item_tag'];
$this->item_model = $params['item_model'];
$this->item_serial = $params['item_serial'];
- $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'datetime', false);
+ $this->declined_date = Helper::getFormattedDateObject($params['declined_date'], 'date', false);
$this->assigned_to = $params['assigned_to'];
$this->company_name = $params['company_name'];
$this->settings = Setting::getSettings();
@@ -52,19 +52,12 @@ class AcceptanceAssetDeclinedNotification extends Notification
*/
public function toMail($notifiable)
{
- $fields = [];
-
- // Check if the item has custom fields associated with it
- if (($this->item->model) && ($this->item->model->fieldset)) {
- $fields = $this->item->model->fieldset->fields;
- }
-
- $message = (new MailMessage)->markdown('notifications.markdown.asset-requested',
+ $message = (new MailMessage)->markdown('notifications.markdown.asset-acceptance',
[
'item_tag' => $this->item_tag,
'item_model' => $this->item_model,
'item_serial' => $this->item_serial,
- 'accepted_date' => $this->accepted_date,
+ 'declined_date' => $this->declined_date,
'assigned_to' => $this->assigned_to,
'company_name' => $this->company_name,
'intro_text' => trans('mail.acceptance_asset_declined'),
diff --git a/resources/views/notifications/markdown/asset-acceptance.blade.php b/resources/views/notifications/markdown/asset-acceptance.blade.php
index f4f25174b9..5616525b13 100644
--- a/resources/views/notifications/markdown/asset-acceptance.blade.php
+++ b/resources/views/notifications/markdown/asset-acceptance.blade.php
@@ -3,15 +3,16 @@
{{ $intro_text }}.
-@if (($snipeSettings->show_images_in_email =='1') && $item->getImageUrl())
-<center><img src="{{ $item->getImageUrl() }}" alt="Asset" style="max-width: 570px;"></center>
-@endif
-
@component('mail::table')
| | |
| ------------- | ------------- |
-| **{{ trans('mail.user') }}** | [{{ $assigned_to->present()->fullName() }}]({{ route('users.show', $assigned_to->id) }}) |
-| **{{ trans('general.requested') }}** | {{ $accepted_date }} |
+| **{{ trans('mail.user') }}** | {{ $assigned_to }} |
+@if (isset($accepted_date))
+| **{{ ucfirst(trans('general.accepted')) }}** | {{ $accepted_date }} |
+@endif
+@if (isset($declined_date))
+| **{{ trans('general.declined') }}** | {{ $declined_date }} |
+@endif
@if ((isset($item_tag)) && ($item_tag!=''))
| **{{ trans('mail.asset_tag') }}** | {{ $item_tag }} |
@endif