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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 279f9103030fd0c0a858e6d2d5c2f71b69644f17b3654b7e8cd6226deeefabb3
4
- data.tar.gz: 58431c85a8824cd879b58f550fa28969b1f45bd9ba04cb16ab69553a6e01c3d3
3
+ metadata.gz: 289a8b8aee41d9ad997ac46f363357ebb9961d983aaac22cd234133fb40a4e7e
4
+ data.tar.gz: c2f3f4c71adbf4d2ffd07fd427d25afda5814459ca6217085882f5b2056049b1
5
5
  SHA512:
6
- metadata.gz: e3f8d565b6b939cadff349df0add73ba2e50ae4eef45629d412748754e307aaf7952b69bf3138232c549c560766f23e8dcfbceb5b14ae3f7b3ddccb9c428ab92
7
- data.tar.gz: e3d1c7576b48388d6f8144401218b47fd2d40b0320f1ffbe6f9ef674e70d2ab295aed46fb2ac6d9571ca0c99d611f529dc047d3e073bde557d9e02a9c726fb77
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.send_notification(authorization)
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
@@ -45,7 +45,7 @@ module Cats
45
45
  end
46
46
 
47
47
  def in_progress
48
- raise(StandardError, 'Plan is not approved.') unless status == APPROVED
48
+ raise(StandardError, 'Plan is not approved.') unless status == APPROVED || status == IN_PROGRESS
49
49
 
50
50
  self.status = IN_PROGRESS
51
51
  save!
@@ -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 send_notification(authorization)
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
@@ -1,5 +1,5 @@
1
1
  module Cats
2
2
  module Core
3
- VERSION = '1.5.16'.freeze
3
+ VERSION = '1.5.17'.freeze
4
4
  end
5
5
  end
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.16
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-04 00:00:00.000000000 Z
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