cats_core 1.4.24 → 1.4.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/cats/core/dispatch_authorizations_controller.rb +2 -2
- data/app/controllers/cats/core/dispatches_controller.rb +13 -2
- data/app/models/cats/core/authorization.rb +22 -6
- data/app/models/cats/core/dispatch.rb +6 -0
- data/app/serializers/cats/core/dispatch_authorization_serializer.rb +1 -1
- data/app/serializers/cats/core/dispatch_serializer.rb +1 -1
- data/app/serializers/cats/core/receipt_authorization_serializer.rb +1 -1
- data/app/services/cats/core/authorization_service.rb +16 -14
- data/app/services/cats/core/dispatch_service.rb +22 -0
- data/config/routes.rb +1 -0
- data/db/migrate/20210718045516_create_cats_core_dispatches.rb +1 -0
- data/db/migrate/20210727074646_create_cats_core_receipt_authorizations.rb +2 -0
- data/lib/cats/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad828e18f9f084f3c2e0343af564a1f1cc4832e935c9eec068503f4293442b87
|
4
|
+
data.tar.gz: 8e0520ff2a6df1e2b4dd3f726a60aef02ef45915158c72c73ccbc74a9ae2786d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc1d8fc0861a5f8c46734cbbf029608625e8734d31361cf924834769166cc6d429f247b169b299616a5bedcf9dffd0cdc2ad4960e4caa502757a1a98cfd55865
|
7
|
+
data.tar.gz: '0850a3f89b88aea548765a78f46a8d4cac259642dc3f8c15837ab54c1d5c7911b311b8b55719972fe19312cf614d07042652376556a134ea2e20c8b1f7227fc1'
|
@@ -10,8 +10,8 @@ module Cats
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def confirm
|
13
|
-
|
14
|
-
authorization =
|
13
|
+
authorization = DispatchAuthorization.find(params[:id])
|
14
|
+
authorization = authorization.confirm
|
15
15
|
render json: { success: true, data: serialize(authorization) }
|
16
16
|
rescue StandardError => e
|
17
17
|
render json: { success: false, error: e.message }
|
@@ -2,8 +2,8 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class DispatchesController < ApplicationController
|
4
4
|
include Common
|
5
|
-
|
6
|
-
before_action :set_service, only: %i[create_receipt_authorization approve start search confirm]
|
5
|
+
skip_before_action :authenticate, only: %i[start_with_pin]
|
6
|
+
before_action :set_service, only: %i[create_receipt_authorization approve start start_with_pin search confirm]
|
7
7
|
|
8
8
|
def index
|
9
9
|
super do
|
@@ -35,6 +35,13 @@ module Cats
|
|
35
35
|
render json: { success: false, error: e.message }
|
36
36
|
end
|
37
37
|
|
38
|
+
def start_with_pin
|
39
|
+
dispatch = @service.start_with_pin(params[:id], start_with_pin_params[:pin])
|
40
|
+
render json: { success: true, data: serialize(dispatch) }
|
41
|
+
rescue StandardError => e
|
42
|
+
render json: { success: false, error: e.message }
|
43
|
+
end
|
44
|
+
|
38
45
|
def confirm
|
39
46
|
dispatch = set_object
|
40
47
|
dispatch.confirm
|
@@ -68,6 +75,10 @@ module Cats
|
|
68
75
|
params.require(:payload).permit(:reference_no, :dispatch_plan_item_id, :transporter_id, :plate_no, :unit_id,
|
69
76
|
:driver_name, :driver_phone, :remark)
|
70
77
|
end
|
78
|
+
|
79
|
+
def start_with_pin_params
|
80
|
+
params.require(:payload).permit(:pin)
|
81
|
+
end
|
71
82
|
end
|
72
83
|
end
|
73
84
|
end
|
@@ -46,11 +46,19 @@ module Cats
|
|
46
46
|
|
47
47
|
def confirm
|
48
48
|
if instance_of?(DispatchAuthorization)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
ActiveRecord::Base.transaction do
|
50
|
+
raise(StandardError, 'Authorization does not have transactions.') if transactions.blank?
|
51
|
+
|
52
|
+
transactions.each(&:commit)
|
53
|
+
self.status = CONFIRMED
|
54
|
+
save!
|
55
|
+
if dispatch.all_authorizations_confirmed?
|
56
|
+
dispatch.generate_pin
|
57
|
+
dispatch.quantity = dispatch.dispatch_transactions.sum(:quantity)
|
58
|
+
dispatch.dispatch_status = Dispatch::READY_TO_START
|
59
|
+
dispatch.save!
|
60
|
+
end
|
61
|
+
end
|
54
62
|
elsif instance_of?(ReceiptAuthorization)
|
55
63
|
raise(StandardError, 'Authorization does not have receipts.') unless receipts.count.positive?
|
56
64
|
|
@@ -60,8 +68,16 @@ module Cats
|
|
60
68
|
raise(StandardError, "A quantity of #{diff} is unaccounted for.") unless diff.zero?
|
61
69
|
|
62
70
|
self.received_quantity = total_received
|
71
|
+
self.status = CONFIRMED
|
72
|
+
save!
|
73
|
+
generate_pin
|
63
74
|
end
|
64
|
-
self
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
def generate_pin
|
79
|
+
pin = SecureRandom.hex(10)
|
80
|
+
self.auth_details = { pin: pin, active: true, expires_at: DateTime.now + 1.hour }
|
65
81
|
save!
|
66
82
|
end
|
67
83
|
|
@@ -2,7 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class DispatchAuthorizationSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :authorized_by_id,
|
5
|
-
:authorizer_full_name, :dispatch_status, :plate_no, :driver_name
|
5
|
+
:authorizer_full_name, :dispatch_status, :plate_no, :driver_name, :status
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -3,7 +3,7 @@ module Cats
|
|
3
3
|
class DispatchSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :reference_no, :dispatch_plan_item_id, :transporter_id, :transporter_name, :plate_no,
|
5
5
|
:driver_name, :driver_phone, :quantity, :remark, :prepared_by_id, :prepared_by_email,
|
6
|
-
:dispatch_status, :destination
|
6
|
+
:dispatch_status, :destination, :auth_details
|
7
7
|
|
8
8
|
def destination
|
9
9
|
object.dispatch_plan_item.destination.name
|
@@ -2,7 +2,7 @@ module Cats
|
|
2
2
|
module Core
|
3
3
|
class ReceiptAuthorizationSerializer < ActiveModel::Serializer
|
4
4
|
attributes :id, :dispatch_id, :dispatch_reference_no, :store_id, :store_name, :quantity, :received_quantity,
|
5
|
-
:remark, :status, :authorized_by_id, :authorizer_full_name
|
5
|
+
:remark, :status, :authorized_by_id, :authorizer_full_name, :auth_details
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
@@ -1,23 +1,25 @@
|
|
1
1
|
module Cats
|
2
2
|
module Core
|
3
3
|
class AuthorizationService
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
def driver_confirm(authorization_id, pin)
|
5
|
+
authorization = ReceiptAuthorization.find(authorization_id)
|
6
|
+
if authorization.status == Authorization::AUTHORIZED
|
7
|
+
raise(StandardError, 'Authorization not confirmed by storekeeper.')
|
8
|
+
end
|
9
|
+
|
10
|
+
raise(StandardError, 'No pin has been generated for receipt.') if authorization.auth_details.nil?
|
11
|
+
|
12
|
+
raise(StandardError, 'Incorrect pin.') unless pin == authorization.auth_details['pin']
|
9
13
|
|
10
|
-
|
11
|
-
authorization.confirm
|
14
|
+
raise(StandardError, 'Pin is not active.') unless authorization.auth_details['active']
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
dispatch.dispatch_status = Dispatch::READY_TO_START
|
18
|
-
dispatch.save!
|
19
|
-
end
|
16
|
+
if DateTime.now > authorization.auth_details['expires_at']
|
17
|
+
authorization.auth_details[:active] = false
|
18
|
+
authorization.save!
|
19
|
+
raise(StandardError, 'Pin has expired.')
|
20
20
|
end
|
21
|
+
authorization.driver_confirmed = true
|
22
|
+
authorization.save!
|
21
23
|
authorization
|
22
24
|
end
|
23
25
|
end
|
@@ -37,6 +37,28 @@ module Cats
|
|
37
37
|
dispatch
|
38
38
|
end
|
39
39
|
|
40
|
+
def start_with_pin(dispatch_id, pin)
|
41
|
+
dispatch = Dispatch.find(dispatch_id)
|
42
|
+
raise(StandardError, 'Dispatch is already started.') if dispatch.dispatch_status == Dispatch::STARTED
|
43
|
+
|
44
|
+
raise(StandardError, 'No pin has been generated for dispatch.') if dispatch.auth_details.nil?
|
45
|
+
|
46
|
+
raise(StandardError, 'Incorrect pin.') unless pin == dispatch.auth_details['pin']
|
47
|
+
|
48
|
+
raise(StandardError, 'Pin is not active.') unless dispatch.auth_details['active']
|
49
|
+
|
50
|
+
if DateTime.now > dispatch.auth_details['expires_at']
|
51
|
+
dispatch.auth_details[:active] = false
|
52
|
+
dispatch.save!
|
53
|
+
raise(StandardError, 'Pin has expired.')
|
54
|
+
end
|
55
|
+
dispatch.start
|
56
|
+
send_notification(dispatch)
|
57
|
+
dispatch.auth_details = nil
|
58
|
+
dispatch.save!
|
59
|
+
dispatch
|
60
|
+
end
|
61
|
+
|
40
62
|
def send_notification(dispatch)
|
41
63
|
notification_rule = Cats::Core::NotificationRule.find_by(code: 'dispatch')
|
42
64
|
raise(StandardError, 'Notification rule not found for dispatch notification.') unless notification_rule
|
data/config/routes.rb
CHANGED
@@ -13,6 +13,8 @@ class CreateCatsCoreReceiptAuthorizations < ActiveRecord::Migration[6.1]
|
|
13
13
|
t.float :received_quantity, null: false, default: 0
|
14
14
|
t.string :status, null: false, default: 'Authorized'
|
15
15
|
t.string :remark
|
16
|
+
t.jsonb :auth_details
|
17
|
+
t.boolean :driver_confirmed, null: false, default: false
|
16
18
|
t.references :authorized_by,
|
17
19
|
null: false,
|
18
20
|
index: { name: 'ab_on_receipt_authorizations_indx' },
|
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.4.
|
4
|
+
version: 1.4.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henock L.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: active_model_serializers
|