cats_core 1.1.17 → 1.1.18
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/receipts_controller.rb +23 -0
- data/app/notifications/cats/core/dispatch_notification.rb +27 -0
- data/app/services/cats/core/dispatch_service.rb +20 -0
- data/lib/cats/core/version.rb +1 -1
- data/spec/factories/cats/core/locations.rb +5 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eced600b25c5d8bf5d8a0b55ba7a5d116879c5ee3f346f9e5128144066c14d8c
|
4
|
+
data.tar.gz: e88b60c25cd88cba88f0cce8ca83fe4acf6873b99b757c791a9806f3b22569c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb400975341e0ee1361e41f9cf93fdd1473af06f0bed0f06d75d36b0622766556110b3a3f75ab8b283776ff2c23a3263b5d493dd0035b27b965d2c31141eca78
|
7
|
+
data.tar.gz: edc3f5744ff0f9b4dde1f0b8d07649927b720540004fc891e357bcba30c9561963e4f3ece3238707496f23eb1fdf0d141fad44adbcf5c4ede25a59129c3e8717
|
@@ -8,6 +8,29 @@ module Cats
|
|
8
8
|
render json: { success: true, data: serialize(receipts) }
|
9
9
|
end
|
10
10
|
|
11
|
+
def create
|
12
|
+
p = model_params
|
13
|
+
receipt = Cats::Core::Receipt.find_by(
|
14
|
+
dispatch_id: p[:dispatch_id],
|
15
|
+
commodity_status: p[:commodity_status]
|
16
|
+
)
|
17
|
+
if receipt
|
18
|
+
receipt.quantity += p[:quantity]
|
19
|
+
if receipt.save
|
20
|
+
render json: { success: true, data: serialize(receipt) }
|
21
|
+
else
|
22
|
+
render json: { success: false, error: receipt.errors.full_messages[0] }, status: :unprocessable_entity
|
23
|
+
end
|
24
|
+
else
|
25
|
+
obj = Cats::Core::Receipt.new(model_params)
|
26
|
+
if obj.save
|
27
|
+
render json: { success: true, data: serialize(obj) }, status: :created
|
28
|
+
else
|
29
|
+
render json: { success: false, error: obj.errors.full_messages[0] }, status: :unprocessable_entity
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
11
34
|
def start_stacking
|
12
35
|
receipt = Cats::Core::Receipt.find(params[:id])
|
13
36
|
service = ReceiptService.new
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Cats
|
2
|
+
module Core
|
3
|
+
class DispatchNotification < Noticed::Base
|
4
|
+
deliver_by :database
|
5
|
+
|
6
|
+
param :dispatch
|
7
|
+
|
8
|
+
def message
|
9
|
+
dispatch = params[:dispatch]
|
10
|
+
title = 'Dispatch Notification'
|
11
|
+
date = Date.today
|
12
|
+
body = <<~BODY
|
13
|
+
Commodity with the following details has been dispatched to you:
|
14
|
+
Dispatch Ref. = #{dispatch.reference_no}
|
15
|
+
Batch No. = #{dispatch.allocation_item.allocation.commodity.batch_no}
|
16
|
+
Commodity = #{dispatch.allocation_item.allocation.commodity.name}
|
17
|
+
Allocated Quantity = #{dispatch.allocation_item.quantity}
|
18
|
+
Quantity = #{dispatch.quantity}
|
19
|
+
Truck Plate No. = #{dispatch.plate_no}
|
20
|
+
Driver Name = #{dispatch.driver_name}
|
21
|
+
Driver Phone = #{dispatch.driver_phone}
|
22
|
+
BODY
|
23
|
+
{ title: title, date: date, body: body }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -109,6 +109,7 @@ module Cats
|
|
109
109
|
dispatch.save
|
110
110
|
transactions = Cats::Core::DispatchTransaction.where(destination: dispatch)
|
111
111
|
transactions.each(&:commit)
|
112
|
+
send_notification(dispatch)
|
112
113
|
dispatch
|
113
114
|
end
|
114
115
|
|
@@ -131,6 +132,25 @@ module Cats
|
|
131
132
|
|
132
133
|
dispatch
|
133
134
|
end
|
135
|
+
|
136
|
+
def send_notification(dispatch)
|
137
|
+
notification_rule = Cats::Core::NotificationRule.find_by(code: 'dispatch')
|
138
|
+
raise(StandardError, 'Notification rule not found for dispatch notification.') unless notification_rule
|
139
|
+
|
140
|
+
users = Cats::Core::User.joins(:roles).where(cats_core_roles: { name: notification_rule.roles })
|
141
|
+
location_id = dispatch.allocation_item.destination_id
|
142
|
+
recipients = users.map do |user|
|
143
|
+
details = user.details
|
144
|
+
if (details.key?('warehouse') && details['warehouse'] == location_id) ||
|
145
|
+
(details.key?('hub') && details['hub'] == location_id)
|
146
|
+
user
|
147
|
+
end
|
148
|
+
end.compact
|
149
|
+
return if recipients.empty?
|
150
|
+
|
151
|
+
notification = DispatchNotification.with(dispatch: dispatch)
|
152
|
+
notification.deliver(recipients)
|
153
|
+
end
|
134
154
|
end
|
135
155
|
end
|
136
156
|
end
|
data/lib/cats/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cats_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
@@ -286,6 +286,7 @@ files:
|
|
286
286
|
- app/models/cats/core/transporter.rb
|
287
287
|
- app/models/cats/core/unit_of_measure.rb
|
288
288
|
- app/models/cats/core/user.rb
|
289
|
+
- app/notifications/cats/core/dispatch_notification.rb
|
289
290
|
- app/notifications/cats/core/simple_notification.rb
|
290
291
|
- app/serializers/cats/core/commodity_category_serializer.rb
|
291
292
|
- app/serializers/cats/core/commodity_serializer.rb
|