cats_core 1.5.16 → 1.5.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/dispatch_authorizations_controller.rb +10 -0
- data/app/controllers/cats/core/receipt_authorizations_controller.rb +1 -1
- data/app/models/cats/core/round_plan.rb +1 -1
- data/app/notifications/cats/core/dispatch_authorization_notification.rb +31 -0
- data/app/services/cats/core/authorization_service.rb +18 -1
- data/lib/cats/core/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 289a8b8aee41d9ad997ac46f363357ebb9961d983aaac22cd234133fb40a4e7e
|
4
|
+
data.tar.gz: c2f3f4c71adbf4d2ffd07fd427d25afda5814459ca6217085882f5b2056049b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a48354b502b466fefb8b346eb4cad0453630dac9803afd10737b33e475b7d532c213f8425a29e91658c8b2aacf4a46bb2568eec41d67ff0e4586d10700dfdfac
|
7
|
+
data.tar.gz: f7b6788c688d1f6e95a1c182a083a24f6738db33d40ec11dfdc1899c3fe2c8b30b1f413ae489faeb61846974c3f2b5ffe4c74050ca52af20dbb68a1925d3ac18
|
@@ -9,6 +9,16 @@ module Cats
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
def create
|
13
|
+
authorization = DispatchAuthorization.new(model_params)
|
14
|
+
if authorization.save
|
15
|
+
AuthorizationService.new.send_dispatch_notification(authorization)
|
16
|
+
render json: { success: true, data: serialize(authorization) }, status: :created
|
17
|
+
else
|
18
|
+
render json: { success: false, error: authorization.errors.full_messages[0] }, status: :unprocessable_entity
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
12
22
|
def confirm
|
13
23
|
authorization = DispatchAuthorization.find(params[:id])
|
14
24
|
authorization = authorization.confirm
|
@@ -14,7 +14,7 @@ module Cats
|
|
14
14
|
def create
|
15
15
|
authorization = ReceiptAuthorization.new(model_params)
|
16
16
|
if authorization.save
|
17
|
-
AuthorizationService.new.
|
17
|
+
AuthorizationService.new.send_receipt_notification(authorization)
|
18
18
|
render json: { success: true, data: serialize(authorization) }, status: :created
|
19
19
|
else
|
20
20
|
render json: { success: false, error: authorization.errors.full_messages[0] }, status: :unprocessable_entity
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class DispatchAuthorizationNotification < Noticed::Base
|
4
|
+
deliver_by :database
|
5
|
+
|
6
|
+
param :dispatch_authorization
|
7
|
+
|
8
|
+
def message
|
9
|
+
authorization = params[:dispatch_authorization]
|
10
|
+
dispatch = authorization.dispatch
|
11
|
+
commodity = dispatch.dispatch_plan_item.commodity
|
12
|
+
title = "Dispatch Authorization Notification - #{commodity.name}"
|
13
|
+
date = Date.today
|
14
|
+
|
15
|
+
body = <<~BODY
|
16
|
+
Commodity with the following details is ordered to be dispatched from your store:
|
17
|
+
Authorization no. = #{dispatch.dispatch_plan_item.reference_no}
|
18
|
+
Dispatch Ref. = #{dispatch.reference_no}
|
19
|
+
Batch No. = #{commodity.batch_no}
|
20
|
+
Commodity = #{commodity.name}
|
21
|
+
Quantity = #{authorization.quantity}
|
22
|
+
Unit = #{authorization.unit.abbreviation}
|
23
|
+
Truck Plate No. = #{dispatch.plate_no}
|
24
|
+
Driver Name = #{dispatch.driver_name}
|
25
|
+
Driver Phone = #{dispatch.driver_phone}
|
26
|
+
BODY
|
27
|
+
{ title: title, date: date, body: body }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -96,7 +96,7 @@ module Cats
|
|
96
96
|
}
|
97
97
|
end
|
98
98
|
|
99
|
-
def
|
99
|
+
def send_receipt_notification(authorization)
|
100
100
|
notification_rule = NotificationRule.find_by(code: 'receipt_authorization')
|
101
101
|
error = 'Notification rule not found for receipt authorization notification.'
|
102
102
|
raise(StandardError, error) unless notification_rule
|
@@ -112,6 +112,23 @@ module Cats
|
|
112
112
|
notification = ReceiptAuthorizationNotification.with(receipt_authorization: authorization)
|
113
113
|
notification.deliver(recipients)
|
114
114
|
end
|
115
|
+
|
116
|
+
def send_dispatch_notification(authorization)
|
117
|
+
notification_rule = NotificationRule.find_by(code: 'dispatch_authorization')
|
118
|
+
error = 'Notification rule not found for dispatch authorization notification.'
|
119
|
+
raise(StandardError, error) unless notification_rule
|
120
|
+
|
121
|
+
users = User.joins(:roles).where(cats_core_roles: { name: notification_rule.roles })
|
122
|
+
recipients = users.map do |user|
|
123
|
+
details = user.details
|
124
|
+
|
125
|
+
user if details.key?('stores') && details['stores'].include?(authorization.store_id)
|
126
|
+
end.compact
|
127
|
+
return if recipients.empty?
|
128
|
+
|
129
|
+
notification = DispatchAuthorizationNotification.with(dispatch_authorization: authorization)
|
130
|
+
notification.deliver(recipients)
|
131
|
+
end
|
115
132
|
end
|
116
133
|
end
|
117
134
|
end
|
data/lib/cats/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cats_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|
@@ -358,6 +358,7 @@ files:
|
|
358
358
|
- app/models/cats/core/user.rb
|
359
359
|
- app/models/concerns/cats/core/dispatchable.rb
|
360
360
|
- app/notifications/cats/core/allocation_notification.rb
|
361
|
+
- app/notifications/cats/core/dispatch_authorization_notification.rb
|
361
362
|
- app/notifications/cats/core/dispatch_notification.rb
|
362
363
|
- app/notifications/cats/core/receipt_authorization_notification.rb
|
363
364
|
- app/notifications/cats/core/round_plan_notification.rb
|