cats_core 1.5.17 → 1.5.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +7 -7
  3. data/app/controllers/cats/core/access_controller.rb +4 -4
  4. data/app/controllers/cats/core/application_controller.rb +4 -4
  5. data/app/controllers/cats/core/commodities_controller.rb +7 -7
  6. data/app/controllers/cats/core/commodity_categories_controller.rb +4 -4
  7. data/app/controllers/cats/core/dispatch_authorizations_controller.rb +22 -9
  8. data/app/controllers/cats/core/dispatch_plan_items_controller.rb +4 -4
  9. data/app/controllers/cats/core/dispatch_plans_controller.rb +10 -10
  10. data/app/controllers/cats/core/dispatch_transactions_controller.rb +5 -5
  11. data/app/controllers/cats/core/dispatches_controller.rb +19 -19
  12. data/app/controllers/cats/core/loans_controller.rb +1 -1
  13. data/app/controllers/cats/core/locations_controller.rb +4 -4
  14. data/app/controllers/cats/core/menus_controller.rb +1 -1
  15. data/app/controllers/cats/core/notifications_controller.rb +5 -5
  16. data/app/controllers/cats/core/purchase_orders_controller.rb +3 -3
  17. data/app/controllers/cats/core/receipt_authorizations_controller.rb +29 -17
  18. data/app/controllers/cats/core/receipt_transactions_controller.rb +4 -4
  19. data/app/controllers/cats/core/receipts_controller.rb +1 -1
  20. data/app/controllers/cats/core/roles_controller.rb +3 -3
  21. data/app/controllers/cats/core/round_beneficiaries_controller.rb +13 -13
  22. data/app/controllers/cats/core/round_plans_controller.rb +13 -13
  23. data/app/controllers/cats/core/routes_controller.rb +2 -2
  24. data/app/controllers/cats/core/spaces_controller.rb +1 -1
  25. data/app/controllers/cats/core/stack_transactions_controller.rb +3 -3
  26. data/app/controllers/cats/core/stacks_controller.rb +15 -7
  27. data/app/controllers/cats/core/stores_controller.rb +14 -14
  28. data/app/controllers/cats/core/swaps_controller.rb +2 -2
  29. data/app/controllers/cats/core/transporters_controller.rb +1 -1
  30. data/app/controllers/cats/core/users_controller.rb +24 -12
  31. data/app/controllers/concerns/cats/core/common.rb +24 -23
  32. data/app/helpers/cats/core/document_helper.rb +1 -1
  33. data/app/models/cats/core/authorization.rb +9 -9
  34. data/app/models/cats/core/beneficiary.rb +6 -6
  35. data/app/models/cats/core/beneficiary_plan_item.rb +9 -9
  36. data/app/models/cats/core/beneficiary_round_plan_item.rb +2 -2
  37. data/app/models/cats/core/cash_donation.rb +1 -1
  38. data/app/models/cats/core/commodity.rb +47 -33
  39. data/app/models/cats/core/commodity_donation.rb +2 -2
  40. data/app/models/cats/core/commodity_substitution.rb +15 -7
  41. data/app/models/cats/core/contract_item.rb +2 -2
  42. data/app/models/cats/core/dispatch.rb +36 -21
  43. data/app/models/cats/core/dispatch_authorization.rb +31 -5
  44. data/app/models/cats/core/dispatch_plan.rb +19 -10
  45. data/app/models/cats/core/dispatch_plan_item.rb +27 -14
  46. data/app/models/cats/core/dispatch_transaction.rb +15 -5
  47. data/app/models/cats/core/gift_certificate.rb +3 -3
  48. data/app/models/cats/core/hub_authorization.rb +7 -7
  49. data/app/models/cats/core/loan.rb +2 -2
  50. data/app/models/cats/core/location.rb +12 -8
  51. data/app/models/cats/core/lost_commodity.rb +2 -2
  52. data/app/models/cats/core/notification.rb +2 -2
  53. data/app/models/cats/core/offer_item.rb +4 -4
  54. data/app/models/cats/core/plan.rb +9 -9
  55. data/app/models/cats/core/plan_item.rb +5 -5
  56. data/app/models/cats/core/plan_item_detail.rb +2 -2
  57. data/app/models/cats/core/project.rb +1 -1
  58. data/app/models/cats/core/purchase_order.rb +5 -5
  59. data/app/models/cats/core/ration.rb +1 -1
  60. data/app/models/cats/core/receipt.rb +5 -5
  61. data/app/models/cats/core/receipt_authorization.rb +6 -2
  62. data/app/models/cats/core/receipt_transaction.rb +8 -4
  63. data/app/models/cats/core/rhn_request.rb +8 -8
  64. data/app/models/cats/core/role_menu.rb +1 -1
  65. data/app/models/cats/core/round_beneficiary.rb +10 -2
  66. data/app/models/cats/core/round_plan.rb +15 -11
  67. data/app/models/cats/core/round_plan_item.rb +9 -5
  68. data/app/models/cats/core/round_plan_item_detail.rb +3 -3
  69. data/app/models/cats/core/round_ration.rb +2 -2
  70. data/app/models/cats/core/route.rb +12 -8
  71. data/app/models/cats/core/stack.rb +52 -34
  72. data/app/models/cats/core/stack_transaction.rb +3 -3
  73. data/app/models/cats/core/stacking_rule.rb +2 -2
  74. data/app/models/cats/core/store.rb +29 -7
  75. data/app/models/cats/core/swap.rb +5 -5
  76. data/app/models/cats/core/transaction.rb +6 -6
  77. data/app/models/cats/core/transport_bid.rb +13 -13
  78. data/app/models/cats/core/transport_bid_item.rb +2 -2
  79. data/app/models/cats/core/transport_offer.rb +3 -3
  80. data/app/models/cats/core/transport_order.rb +8 -8
  81. data/app/models/cats/core/transport_order_item.rb +2 -2
  82. data/app/models/cats/core/transport_plan.rb +7 -7
  83. data/app/models/cats/core/transport_plan_item.rb +2 -2
  84. data/app/models/cats/core/transport_requisition.rb +9 -9
  85. data/app/models/cats/core/transport_requisition_detail.rb +2 -2
  86. data/app/models/cats/core/transport_requisition_item.rb +3 -3
  87. data/app/models/cats/core/transporter.rb +4 -0
  88. data/app/models/cats/core/unit_conversion.rb +4 -4
  89. data/app/models/cats/core/unit_of_measure.rb +4 -4
  90. data/app/models/cats/core/user.rb +11 -11
  91. data/app/models/concerns/cats/core/dispatchable.rb +3 -3
  92. data/app/notifications/cats/core/allocation_notification.rb +1 -1
  93. data/app/notifications/cats/core/dispatch_authorization_notification.rb +5 -1
  94. data/app/notifications/cats/core/dispatch_notification.rb +1 -1
  95. data/app/notifications/cats/core/receipt_authorization_notification.rb +1 -1
  96. data/app/notifications/cats/core/round_plan_notification.rb +1 -1
  97. data/app/notifications/cats/core/simple_notification.rb +1 -1
  98. data/app/serializers/cats/core/cash_donation_serializer.rb +1 -1
  99. data/app/serializers/cats/core/commodity_donation_serializer.rb +2 -2
  100. data/app/serializers/cats/core/commodity_serializer.rb +2 -2
  101. data/app/serializers/cats/core/dispatch_authorization_serializer.rb +2 -2
  102. data/app/serializers/cats/core/dispatch_plan_item_serializer.rb +3 -3
  103. data/app/serializers/cats/core/dispatch_plan_serializer.rb +1 -1
  104. data/app/serializers/cats/core/dispatch_serializer.rb +2 -2
  105. data/app/serializers/cats/core/dispatch_transaction_serializer.rb +1 -1
  106. data/app/serializers/cats/core/loan_serializer.rb +1 -1
  107. data/app/serializers/cats/core/purchase_order_serializer.rb +2 -2
  108. data/app/serializers/cats/core/receipt_authorization_serializer.rb +2 -2
  109. data/app/serializers/cats/core/receipt_serializer.rb +1 -1
  110. data/app/serializers/cats/core/receipt_transaction_serializer.rb +2 -2
  111. data/app/serializers/cats/core/round_beneficiary_serializer.rb +1 -1
  112. data/app/serializers/cats/core/round_plan_serializer.rb +1 -1
  113. data/app/serializers/cats/core/stack_serializer.rb +1 -1
  114. data/app/serializers/cats/core/store_serializer.rb +1 -1
  115. data/app/serializers/cats/core/swap_serializer.rb +2 -2
  116. data/app/services/cats/core/authorization_service.rb +22 -21
  117. data/app/services/cats/core/beneficiary_service.rb +11 -11
  118. data/app/services/cats/core/dispatch_plan_service.rb +10 -10
  119. data/app/services/cats/core/dispatch_service.rb +31 -31
  120. data/app/services/cats/core/notification_service.rb +5 -5
  121. data/app/services/cats/core/round_plan_service.rb +23 -23
  122. data/app/services/cats/core/space_service.rb +11 -11
  123. data/app/services/cats/core/stack_service.rb +10 -10
  124. data/app/services/cats/core/token_auth_service.rb +4 -4
  125. data/app/services/cats/core/user_service.rb +19 -0
  126. data/app/utils/cats/core/util.rb +1 -1
  127. data/config/routes.rb +110 -105
  128. data/config/spring.rb +1 -0
  129. data/db/migrate/20210715114910_create_cats_core_users.rb +3 -3
  130. data/db/migrate/20210715120018_create_cats_core_roles.rb +14 -14
  131. data/db/migrate/20210715121244_create_cats_core_menus.rb +3 -3
  132. data/db/migrate/20210715122141_create_cats_core_menu_items.rb +3 -3
  133. data/db/migrate/20210715122423_create_cats_core_role_menus.rb +13 -13
  134. data/db/migrate/20210717031810_create_cats_core_plans.rb +4 -4
  135. data/db/migrate/20210717032024_create_cats_core_plan_items.rb +18 -18
  136. data/db/migrate/20210717032260_create_cats_core_beneficiary_categories.rb +3 -3
  137. data/db/migrate/20210717032270_create_cats_core_rations.rb +10 -10
  138. data/db/migrate/20210717032290_create_cats_core_beneficiary_plan_items.rb +7 -7
  139. data/db/migrate/20210717032295_create_cats_core_plan_item_details.rb +7 -7
  140. data/db/migrate/20210717032330_create_cats_core_commodity_donations.rb +12 -12
  141. data/db/migrate/20210717032408_create_cats_core_cash_donations.rb +6 -6
  142. data/db/migrate/20210717032602_create_cats_core_gift_certificates.rb +12 -12
  143. data/db/migrate/20210717032855_create_cats_core_purchase_orders.rb +12 -12
  144. data/db/migrate/20210717032927_create_cats_core_projects.rb +3 -3
  145. data/db/migrate/20210717033223_create_cats_core_commodities.rb +10 -10
  146. data/db/migrate/20210717140855_create_cats_core_stores.rb +3 -3
  147. data/db/migrate/20210717171101_create_cats_core_stacks.rb +11 -11
  148. data/db/migrate/20210718040129_create_cats_core_routes.rb +9 -9
  149. data/db/migrate/20210718042755_create_cats_core_rhn_requests.rb +6 -6
  150. data/db/migrate/20210718043328_create_cats_core_dispatch_plans.rb +7 -7
  151. data/db/migrate/20210718043401_create_cats_core_dispatch_plan_items.rb +17 -17
  152. data/db/migrate/20210718045516_create_cats_core_dispatches.rb +13 -13
  153. data/db/migrate/20210718055414_create_cats_core_dispatch_authorizations.rb +13 -13
  154. data/db/migrate/20210718202957_create_cats_core_dispatch_transactions.rb +11 -11
  155. data/db/migrate/20210727074646_create_cats_core_receipt_authorizations.rb +13 -13
  156. data/db/migrate/20210727105834_create_cats_core_receipts.rb +6 -6
  157. data/db/migrate/20210728041505_create_cats_core_lost_commodities.rb +6 -6
  158. data/db/migrate/20210814160628_create_cats_core_receipt_transactions.rb +10 -10
  159. data/db/migrate/20210814175406_create_cats_core_stack_transactions.rb +10 -10
  160. data/db/migrate/20211024063240_add_status_to_cats_core_rhn_requests.rb +1 -1
  161. data/db/migrate/20211030133752_add_status_to_cats_core_commodities.rb +1 -1
  162. data/db/migrate/20211215114737_create_cats_core_transport_plans.rb +4 -4
  163. data/db/migrate/20211215114835_create_cats_core_transport_plan_items.rb +9 -9
  164. data/db/migrate/20211215121151_create_cats_core_transport_bids.rb +4 -4
  165. data/db/migrate/20211215124452_create_cats_core_transport_bid_items.rb +10 -10
  166. data/db/migrate/20211229160125_create_cats_core_transport_offers.rb +7 -7
  167. data/db/migrate/20211229160126_create_cats_core_offer_items.rb +6 -6
  168. data/db/migrate/20211229160127_create_cats_core_transport_contracts.rb +6 -6
  169. data/db/migrate/20211229160128_create_cats_core_contract_items.rb +9 -9
  170. data/db/migrate/20211229160129_create_cats_core_commodity_substitutions.rb +10 -10
  171. data/db/migrate/20220103152802_create_cats_core_tenderers.rb +6 -6
  172. data/db/migrate/20220107121752_create_cats_core_round_plans.rb +7 -7
  173. data/db/migrate/20220107122280_create_cats_core_round_rations.rb +12 -12
  174. data/db/migrate/20220107125025_create_cats_core_round_plan_items.rb +19 -19
  175. data/db/migrate/20220107126025_create_cats_core_beneficiary_round_plan_items.rb +8 -8
  176. data/db/migrate/20220107132433_create_cats_core_round_plan_item_details.rb +9 -9
  177. data/db/migrate/20220209083928_create_cats_core_hub_authorizations.rb +12 -12
  178. data/db/migrate/20220416143416_create_cats_core_unit_conversions.rb +6 -6
  179. data/db/migrate/20220417105839_create_cats_core_transport_requisitions.rb +12 -12
  180. data/db/migrate/20220417123835_create_cats_core_transport_requisition_items.rb +9 -9
  181. data/db/migrate/20220417151821_create_cats_core_transport_requisition_details.rb +6 -6
  182. data/db/migrate/20220506082329_create_cats_core_transport_orders.rb +10 -10
  183. data/db/migrate/20220506083042_create_cats_core_transport_order_items.rb +13 -13
  184. data/db/migrate/20220511082354_create_cats_core_beneficiaries.rb +6 -6
  185. data/db/migrate/20220626063501_create_cats_core_loans.rb +6 -6
  186. data/db/migrate/20220626063757_create_cats_core_swaps.rb +12 -12
  187. data/db/migrate/20220626132050_create_cats_core_round_beneficiaries.rb +13 -13
  188. data/db/migrate/20220923190857_create_cats_core_application_settings.rb +3 -3
  189. data/lib/cats/core/engine.rb +4 -4
  190. data/lib/cats/core/version.rb +1 -1
  191. data/lib/cats_core.rb +8 -8
  192. data/spec/factories/cats/core/application_modules.rb +1 -1
  193. data/spec/factories/cats/core/application_settings.rb +1 -1
  194. data/spec/factories/cats/core/beneficiaries.rb +3 -3
  195. data/spec/factories/cats/core/beneficiary_categories.rb +1 -1
  196. data/spec/factories/cats/core/beneficiary_plan_items.rb +1 -1
  197. data/spec/factories/cats/core/beneficiary_round_plan_items.rb +1 -1
  198. data/spec/factories/cats/core/cash_donations.rb +1 -1
  199. data/spec/factories/cats/core/commodities.rb +1 -1
  200. data/spec/factories/cats/core/commodity_categories.rb +1 -1
  201. data/spec/factories/cats/core/commodity_donations.rb +1 -1
  202. data/spec/factories/cats/core/commodity_substitutions.rb +2 -2
  203. data/spec/factories/cats/core/contract_items.rb +1 -1
  204. data/spec/factories/cats/core/currencies.rb +1 -1
  205. data/spec/factories/cats/core/dispatch_authorizations.rb +7 -11
  206. data/spec/factories/cats/core/dispatch_plan_items.rb +16 -1
  207. data/spec/factories/cats/core/dispatch_plans.rb +1 -1
  208. data/spec/factories/cats/core/dispatch_transactions.rb +2 -4
  209. data/spec/factories/cats/core/dispatches.rb +16 -25
  210. data/spec/factories/cats/core/donors.rb +1 -1
  211. data/spec/factories/cats/core/gift_certificates.rb +1 -1
  212. data/spec/factories/cats/core/hub_authorizations.rb +1 -1
  213. data/spec/factories/cats/core/loans.rb +1 -1
  214. data/spec/factories/cats/core/locations.rb +6 -6
  215. data/spec/factories/cats/core/lost_commodities.rb +1 -1
  216. data/spec/factories/cats/core/menu_items.rb +1 -1
  217. data/spec/factories/cats/core/menus.rb +1 -1
  218. data/spec/factories/cats/core/notification_rules.rb +1 -1
  219. data/spec/factories/cats/core/notifications.rb +2 -2
  220. data/spec/factories/cats/core/offer_items.rb +1 -1
  221. data/spec/factories/cats/core/operators.rb +1 -1
  222. data/spec/factories/cats/core/plan_item_details.rb +1 -1
  223. data/spec/factories/cats/core/plan_items.rb +1 -1
  224. data/spec/factories/cats/core/plans.rb +1 -1
  225. data/spec/factories/cats/core/programs.rb +1 -1
  226. data/spec/factories/cats/core/projects.rb +1 -1
  227. data/spec/factories/cats/core/purchase_orders.rb +1 -1
  228. data/spec/factories/cats/core/rations.rb +1 -1
  229. data/spec/factories/cats/core/receipt_authorizations.rb +1 -1
  230. data/spec/factories/cats/core/receipt_transactions.rb +2 -2
  231. data/spec/factories/cats/core/receipts.rb +1 -1
  232. data/spec/factories/cats/core/rhn_requests.rb +1 -1
  233. data/spec/factories/cats/core/role_menus.rb +1 -1
  234. data/spec/factories/cats/core/roles.rb +1 -1
  235. data/spec/factories/cats/core/round_beneficiaries.rb +1 -1
  236. data/spec/factories/cats/core/round_plan_item_details.rb +3 -3
  237. data/spec/factories/cats/core/round_plan_items.rb +1 -1
  238. data/spec/factories/cats/core/round_plans.rb +1 -1
  239. data/spec/factories/cats/core/round_rations.rb +1 -1
  240. data/spec/factories/cats/core/routes.rb +1 -1
  241. data/spec/factories/cats/core/stack_transactions.rb +1 -1
  242. data/spec/factories/cats/core/stacking_rules.rb +1 -1
  243. data/spec/factories/cats/core/stacks.rb +1 -1
  244. data/spec/factories/cats/core/stores.rb +1 -1
  245. data/spec/factories/cats/core/suppliers.rb +1 -1
  246. data/spec/factories/cats/core/swaps.rb +1 -1
  247. data/spec/factories/cats/core/tenderers.rb +1 -1
  248. data/spec/factories/cats/core/transport_bid_items.rb +1 -1
  249. data/spec/factories/cats/core/transport_bids.rb +1 -1
  250. data/spec/factories/cats/core/transport_contracts.rb +1 -1
  251. data/spec/factories/cats/core/transport_offers.rb +1 -1
  252. data/spec/factories/cats/core/transport_order_items.rb +1 -1
  253. data/spec/factories/cats/core/transport_orders.rb +1 -1
  254. data/spec/factories/cats/core/transport_plan_items.rb +1 -1
  255. data/spec/factories/cats/core/transport_plans.rb +1 -1
  256. data/spec/factories/cats/core/transport_requisition_details.rb +1 -1
  257. data/spec/factories/cats/core/transport_requisition_items.rb +1 -1
  258. data/spec/factories/cats/core/transport_requisitions.rb +1 -1
  259. data/spec/factories/cats/core/transporters.rb +1 -1
  260. data/spec/factories/cats/core/unit_conversions.rb +1 -1
  261. data/spec/factories/cats/core/unit_of_measures.rb +1 -1
  262. data/spec/factories/cats/core/users.rb +2 -2
  263. metadata +18 -2
@@ -2,33 +2,33 @@ module Cats
2
2
  module Core
3
3
  class User < ApplicationRecord
4
4
  has_secure_password
5
- rolify role_cname: 'Cats::Core::Role'
5
+ rolify role_cname: "Cats::Core::Role"
6
6
 
7
7
  belongs_to :application_module
8
8
  has_many :notifications, as: :recipient
9
9
 
10
- validates :password, length: { minimum: 6 }, if: proc { |u| u.password.present? }, on: :update
10
+ validates :password, length: {minimum: 6}, if: proc { |u| u.password.present? }, on: :update
11
11
  validates :first_name, :last_name, :email, presence: true
12
- validates :password, presence: true, length: { minimum: 6 }, on: :create
13
- validates :email, uniqueness: true, format: { with: URI::MailTo::EMAIL_REGEXP }
12
+ validates :password, presence: true, length: {minimum: 6}, on: :create
13
+ validates :email, uniqueness: true, format: {with: URI::MailTo::EMAIL_REGEXP}
14
14
  validate :validate_phone_number
15
15
 
16
16
  def warehouse
17
- return unless details.key?('warehouse')
17
+ return unless details.key?("warehouse")
18
18
 
19
- Cats::Core::Location.find_by(id: details['warehouse'], location_type: Cats::Core::Location::WAREHOUSE)
19
+ Cats::Core::Location.find_by(id: details["warehouse"], location_type: Cats::Core::Location::WAREHOUSE)
20
20
  end
21
21
 
22
22
  def stores
23
- return unless details.key?('stores')
23
+ return unless details.key?("stores")
24
24
 
25
- Cats::Core::Store.where(id: details['stores'])
25
+ Cats::Core::Store.where(id: details["stores"])
26
26
  end
27
27
 
28
28
  def hub
29
- return unless details.key?('hub')
29
+ return unless details.key?("hub")
30
30
 
31
- Cats::Core::Location.find_by(id: details['hub'], location_type: Cats::Core::Location::HUB)
31
+ Cats::Core::Location.find_by(id: details["hub"], location_type: Cats::Core::Location::HUB)
32
32
  end
33
33
 
34
34
  def add_detail(key, value)
@@ -48,7 +48,7 @@ module Cats
48
48
 
49
49
  return if phone_number.length == 12 && /251\d{9}/.match(phone_number)
50
50
 
51
- errors.add(:phone_number, 'must be 10 or 12 digits and should match with local phone pattern')
51
+ errors.add(:phone_number, "must be 10 or 12 digits and should match with local phone pattern")
52
52
  end
53
53
 
54
54
  def full_name
@@ -7,9 +7,9 @@ module Cats
7
7
  module Dispatchable
8
8
  extend ActiveSupport::Concern
9
9
 
10
- DRAFT = 'Draft'.freeze
11
- APPROVED = 'Approved'.freeze
12
- COMPLETED = 'Completed'.freeze
10
+ DRAFT = "Draft".freeze
11
+ APPROVED = "Approved".freeze
12
+ COMPLETED = "Completed".freeze
13
13
 
14
14
  # rubocop:disable Style/MutableConstant
15
15
  STATUSES = [DRAFT, APPROVED, COMPLETED]
@@ -24,7 +24,7 @@ module Cats
24
24
  Quantity = #{allocation_item.quantity}
25
25
  The commodity is expected to be delivered from #{source} to #{destination}
26
26
  BODY
27
- { title: title, date: date, body: body }
27
+ {title: title, date: date, body: body}
28
28
  end
29
29
  end
30
30
  end
@@ -8,6 +8,8 @@ module Cats
8
8
  def message
9
9
  authorization = params[:dispatch_authorization]
10
10
  dispatch = authorization.dispatch
11
+ plan_item_ref = dispatch.dispatch_plan_item.reference_no
12
+ plan_ref = dispatch.dispatch_plan_item.dispatch_plan.reference_no
11
13
  commodity = dispatch.dispatch_plan_item.commodity
12
14
  title = "Dispatch Authorization Notification - #{commodity.name}"
13
15
  date = Date.today
@@ -16,6 +18,8 @@ module Cats
16
18
  Commodity with the following details is ordered to be dispatched from your store:
17
19
  Authorization no. = #{dispatch.dispatch_plan_item.reference_no}
18
20
  Dispatch Ref. = #{dispatch.reference_no}
21
+ Dispatch Plan Ref. = #{plan_ref}
22
+ Dispatch Plan Item Ref. = #{plan_item_ref}
19
23
  Batch No. = #{commodity.batch_no}
20
24
  Commodity = #{commodity.name}
21
25
  Quantity = #{authorization.quantity}
@@ -24,7 +28,7 @@ module Cats
24
28
  Driver Name = #{dispatch.driver_name}
25
29
  Driver Phone = #{dispatch.driver_phone}
26
30
  BODY
27
- { title: title, date: date, body: body }
31
+ {title: title, date: date, body: body}
28
32
  end
29
33
  end
30
34
  end
@@ -23,7 +23,7 @@ module Cats
23
23
  Driver Name = #{dispatch.driver_name}
24
24
  Driver Phone = #{dispatch.driver_phone}
25
25
  BODY
26
- { title: title, date: date, body: body }
26
+ {title: title, date: date, body: body}
27
27
  end
28
28
  end
29
29
  end
@@ -24,7 +24,7 @@ module Cats
24
24
  Driver Name = #{dispatch.driver_name}
25
25
  Driver Phone = #{dispatch.driver_phone}
26
26
  BODY
27
- { title: title, date: date, body: body }
27
+ {title: title, date: date, body: body}
28
28
  end
29
29
  end
30
30
  end
@@ -20,7 +20,7 @@ module Cats
20
20
  Year = #{plan.year}
21
21
  Season = #{plan.season}
22
22
  BODY
23
- { title: title, date: date, body: body }
23
+ {title: title, date: date, body: body}
24
24
  end
25
25
  end
26
26
  end
@@ -13,7 +13,7 @@ module Cats
13
13
  def message
14
14
  title = params[:title]
15
15
  body = params[:body]
16
- { title: title, body: body }
16
+ {title: title, body: body}
17
17
  end
18
18
  end
19
19
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class CashDonationSerializer < ActiveModel::Serializer
4
4
  attributes :id, :reference_no, :description, :donated_on, :donor_id, :donor_name, :amount, :currency_id,
5
- :currency_code
5
+ :currency_code
6
6
  end
7
7
  end
8
8
  end
@@ -2,8 +2,8 @@ module Cats
2
2
  module Core
3
3
  class CommodityDonationSerializer < ActiveModel::Serializer
4
4
  attributes :id, :reference_no, :donated_on, :donor_id, :donor_name, :plan_id, :plan_reference_no,
5
- :quantity, :unit_id, :unit_abbreviation, :description, :commodity_category_id,
6
- :commodity_category_name, :shipping_reference
5
+ :quantity, :unit_id, :unit_abbreviation, :description, :commodity_category_id,
6
+ :commodity_category_name, :shipping_reference
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@ module Cats
2
2
  module Core
3
3
  class CommoditySerializer < ActiveModel::Serializer
4
4
  attributes :id, :name, :batch_no, :description, :unit_of_measure_id, :unit_abbreviation, :project_id,
5
- :project_code, :quantity, :best_use_before, :volume_per_metric_ton, :arrival_status, :status,
6
- :shipping_reference, :commodity_grade, :package_unit_id, :package_unit_abbreviation
5
+ :project_code, :quantity, :best_use_before, :volume_per_metric_ton, :arrival_status, :status,
6
+ :shipping_reference, :commodity_grade, :package_unit_id, :package_unit_abbreviation
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@ 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, :status, :unit_id,
6
- :unit_abbreviation
5
+ :authorizer_full_name, :dispatch_status, :plate_no, :driver_name, :status, :unit_id,
6
+ :unit_abbreviation
7
7
  end
8
8
  end
9
9
  end
@@ -2,9 +2,9 @@ module Cats
2
2
  module Core
3
3
  class DispatchPlanItemSerializer < ActiveModel::Serializer
4
4
  attributes :id, :reference_no, :dispatch_plan_id, :plan_reference_no, :source_id, :source_name, :destination_id,
5
- :destination_name, :quantity, :source_location_type, :destination_location_type, :commodity_status,
6
- :status, :commodity_id, :commodity_name, :commodity_batch_no, :unit_abbreviation,
7
- :commodity_shipping_reference, :unit_id
5
+ :destination_name, :quantity, :source_location_type, :destination_location_type, :commodity_status,
6
+ :status, :commodity_id, :commodity_name, :commodity_batch_no, :unit_abbreviation,
7
+ :commodity_shipping_reference, :unit_id
8
8
  end
9
9
  end
10
10
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class DispatchPlanSerializer < ActiveModel::Serializer
4
4
  attributes :id, :reference_no, :status, :dispatchable_id, :dispatchable_type, :request_reference,
5
- :request_quantity, :upstream
5
+ :request_quantity, :upstream
6
6
  end
7
7
  end
8
8
  end
@@ -2,8 +2,8 @@ module Cats
2
2
  module Core
3
3
  class DispatchSerializer < ActiveModel::Serializer
4
4
  attributes :id, :reference_no, :dispatch_plan_item_id, :transporter_id, :transporter_name, :plate_no,
5
- :driver_name, :driver_phone, :quantity, :remark, :prepared_by_id, :prepared_by_email,
6
- :dispatch_status, :destination, :auth_details, :unit_id, :unit_abbreviation, :commodity_status
5
+ :driver_name, :driver_phone, :quantity, :remark, :prepared_by_id, :prepared_by_email,
6
+ :dispatch_status, :destination, :auth_details, :unit_id, :unit_abbreviation, :commodity_status
7
7
  end
8
8
  end
9
9
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class DispatchTransactionSerializer < ActiveModel::Serializer
4
4
  attributes :id, :source_id, :source_code, :dispatch_authorization_id, :quantity, :transaction_date, :status,
5
- :unit_id, :unit_abbreviation, :reference_no
5
+ :unit_id, :unit_abbreviation, :reference_no
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class LoanSerializer < ActiveModel::Serializer
4
4
  attributes :id, :reference_no, :lender, :agreement_date, :repayment_date, :commodity_category_id,
5
- :commodity_category_name, :quantity, :unit_id, :unit_abbreviation
5
+ :commodity_category_name, :quantity, :unit_id, :unit_abbreviation
6
6
  end
7
7
  end
8
8
  end
@@ -2,8 +2,8 @@ module Cats
2
2
  module Core
3
3
  class PurchaseOrderSerializer < ActiveModel::Serializer
4
4
  attributes :id, :reference_no, :order_date, :requisition_no, :supplier, :cash_donation_id, :purchase_type,
5
- :commodity_category_id, :commodity_category_name, :quantity, :unit_id, :unit_name, :currency_id,
6
- :currency_code, :price
5
+ :commodity_category_id, :commodity_category_name, :quantity, :unit_id, :unit_name, :currency_id,
6
+ :currency_code, :price
7
7
  end
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@ 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, :auth_details, :plate_no, :driver_name,
6
- :dispatch_status, :unit_id, :unit_abbreviation, :driver_confirmed
5
+ :remark, :status, :authorized_by_id, :authorizer_full_name, :auth_details, :plate_no, :driver_name,
6
+ :dispatch_status, :unit_id, :unit_abbreviation, :driver_confirmed
7
7
  end
8
8
  end
9
9
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class ReceiptSerializer < ActiveModel::Serializer
4
4
  attributes :id, :receipt_authorization_id, :commodity_status, :commodity_grade, :quantity, :remark,
5
- :unit_id, :unit_abbreviation, :reference_no
5
+ :unit_id, :unit_abbreviation, :reference_no
6
6
  end
7
7
  end
8
8
  end
@@ -2,8 +2,8 @@ module Cats
2
2
  module Core
3
3
  class ReceiptTransactionSerializer < ActiveModel::Serializer
4
4
  attributes :id, :receipt_authorization_id, :receipt_number,
5
- :dispatch_reference_no, :destination_id, :destination_code, :quantity,
6
- :transaction_date, :status, :unit_id, :unit_abbreviation
5
+ :dispatch_reference_no, :destination_id, :destination_code, :quantity,
6
+ :transaction_date, :status, :unit_id, :unit_abbreviation
7
7
  end
8
8
  end
9
9
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class RoundBeneficiarySerializer < ActiveModel::Serializer
4
4
  attributes :id, :beneficiary_id, :beneficiary_full_name, :round_plan_item_id, :commodity_category_id,
5
- :commodity_category_name, :quantity, :unit_id, :unit_abbreviation, :received
5
+ :commodity_category_name, :quantity, :unit_id, :unit_abbreviation, :received
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class RoundPlanSerializer < ActiveModel::Serializer
4
4
  attributes :id, :reference_no, :status, :plan_id, :plan_reference_no, :region_id, :region_name, :rounds,
5
- :program_code
5
+ :program_code
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class StackSerializer < ActiveModel::Serializer
4
4
  attributes :id, :code, :length, :width, :height, :start_x, :start_y, :commodity_id, :store_id, :commodity_status,
5
- :stack_status, :quantity, :commodity_batch_no, :unit_id, :unit_abbreviation
5
+ :stack_status, :quantity, :commodity_batch_no, :unit_id, :unit_abbreviation
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Cats
2
2
  module Core
3
3
  class StoreSerializer < ActiveModel::Serializer
4
4
  attributes :id, :code, :name, :length, :width, :height, :temporary, :has_gangway, :gangway_length,
5
- :gangway_width, :gangway_corner_dist, :warehouse_id
5
+ :gangway_width, :gangway_corner_dist, :warehouse_id
6
6
 
7
7
  has_many :stacks
8
8
  end
@@ -2,8 +2,8 @@ module Cats
2
2
  module Core
3
3
  class SwapSerializer < ActiveModel::Serializer
4
4
  attributes :id, :reference_no, :swapper, :agreement_date, :issued_commodity_id, :issued_commodity_name,
5
- :issued_quantity, :received_commodity_id, :received_commodity_name, :received_quantity,
6
- :issued_unit_id, :issued_unit_abbreviation, :received_unit_id, :received_unit_abbreviation
5
+ :issued_quantity, :received_commodity_id, :received_commodity_name, :received_quantity,
6
+ :issued_unit_id, :issued_unit_abbreviation, :received_unit_id, :received_unit_abbreviation
7
7
  end
8
8
  end
9
9
  end
@@ -1,22 +1,22 @@
1
1
  module Cats
2
2
  module Core
3
3
  class AuthorizationService
4
- def driver_confirm(authorization_id, pin)
4
+ def driver_confirm(authorization_id, pin, receipt_number)
5
5
  authorization = ReceiptAuthorization.find(authorization_id)
6
6
  if authorization.status == Authorization::AUTHORIZED
7
- raise(StandardError, 'Authorization not confirmed by storekeeper.')
7
+ raise(StandardError, "Authorization not confirmed by storekeeper.")
8
8
  end
9
9
 
10
- raise(StandardError, 'No pin has been generated for receipt.') if authorization.auth_details.nil?
10
+ raise(StandardError, "No pin has been generated for receipt.") if authorization.auth_details.nil?
11
11
 
12
- raise(StandardError, 'Incorrect pin.') unless pin == authorization.auth_details['pin']
12
+ raise(StandardError, "Incorrect pin.") unless pin == authorization.auth_details["pin"]
13
13
 
14
- raise(StandardError, 'Pin is not active.') unless authorization.auth_details['active']
14
+ raise(StandardError, "Pin is not active.") unless authorization.auth_details["active"]
15
15
 
16
- if DateTime.now > authorization.auth_details['expires_at']
16
+ if DateTime.now > authorization.auth_details["expires_at"]
17
17
  authorization.auth_details[:active] = false
18
18
  authorization.save!
19
- raise(StandardError, 'Pin has expired.')
19
+ raise(StandardError, "Pin has expired.")
20
20
  end
21
21
 
22
22
  authorization.driver_confirmed = true
@@ -27,7 +27,7 @@ module Cats
27
27
  # Create destination stack and transaction for FDP
28
28
  location = authorization.dispatch.dispatch_plan_item.destination
29
29
  if location.location_type == Location::FDP
30
- create_stack(authorization_id)
30
+ create_stack(authorization_id, receipt_number)
31
31
  stack(authorization_id)
32
32
  end
33
33
 
@@ -35,7 +35,7 @@ module Cats
35
35
  end
36
36
 
37
37
  # A method to create stack and stack transactions for FDP
38
- def create_stack(authorization_id)
38
+ def create_stack(authorization_id, receipt_number)
39
39
  authorization = ReceiptAuthorization.find(authorization_id)
40
40
  commodity = authorization.dispatch.dispatch_plan_item.commodity
41
41
  stack = Stack.create!(
@@ -57,7 +57,8 @@ module Cats
57
57
  quantity: authorization.received_quantity,
58
58
  unit: authorization.unit,
59
59
  status: Transaction::DRAFT,
60
- transaction_date: Date.today
60
+ transaction_date: Date.today,
61
+ receipt_number: receipt_number
61
62
  )
62
63
  stack
63
64
  end
@@ -65,12 +66,12 @@ module Cats
65
66
  def stack(authorization_id)
66
67
  authorization = ReceiptAuthorization.find(authorization_id)
67
68
  unless authorization.dispatch.dispatch_status == Dispatch::RECEIVED
68
- raise(StandardError, 'Dispatch is not received.')
69
+ raise(StandardError, "Dispatch is not received.")
69
70
  end
70
71
 
71
72
  total = authorization.transactions.sum(:quantity)
72
73
  if total != authorization.received_quantity
73
- raise(StandardError, 'Received quantity is not the same as quantity to be stacked.')
74
+ raise(StandardError, "Received quantity is not the same as quantity to be stacked.")
74
75
  end
75
76
 
76
77
  authorization.transactions.each(&:commit)
@@ -83,7 +84,7 @@ module Cats
83
84
  item = DispatchPlanItem.find(id).includes(
84
85
  :destination,
85
86
  :unit,
86
- commodity: { project: :source }
87
+ commodity: {project: :source}
87
88
  )
88
89
  {
89
90
  date: Date.today,
@@ -97,15 +98,15 @@ module Cats
97
98
  end
98
99
 
99
100
  def send_receipt_notification(authorization)
100
- notification_rule = NotificationRule.find_by(code: 'receipt_authorization')
101
- error = 'Notification rule not found for receipt authorization notification.'
101
+ notification_rule = NotificationRule.find_by(code: "receipt_authorization")
102
+ error = "Notification rule not found for receipt authorization notification."
102
103
  raise(StandardError, error) unless notification_rule
103
104
 
104
- users = User.joins(:roles).where(cats_core_roles: { name: notification_rule.roles })
105
+ users = User.joins(:roles).where(cats_core_roles: {name: notification_rule.roles})
105
106
  recipients = users.map do |user|
106
107
  details = user.details
107
108
 
108
- user if details.key?('stores') && details['stores'].include?(authorization.store_id)
109
+ user if details.key?("stores") && details["stores"].include?(authorization.store_id)
109
110
  end.compact
110
111
  return if recipients.empty?
111
112
 
@@ -114,15 +115,15 @@ module Cats
114
115
  end
115
116
 
116
117
  def send_dispatch_notification(authorization)
117
- notification_rule = NotificationRule.find_by(code: 'dispatch_authorization')
118
- error = 'Notification rule not found for dispatch authorization notification.'
118
+ notification_rule = NotificationRule.find_by(code: "dispatch_authorization")
119
+ error = "Notification rule not found for dispatch authorization notification."
119
120
  raise(StandardError, error) unless notification_rule
120
121
 
121
- users = User.joins(:roles).where(cats_core_roles: { name: notification_rule.roles })
122
+ users = User.joins(:roles).where(cats_core_roles: {name: notification_rule.roles})
122
123
  recipients = users.map do |user|
123
124
  details = user.details
124
125
 
125
- user if details.key?('stores') && details['stores'].include?(authorization.store_id)
126
+ user if details.key?("stores") && details["stores"].include?(authorization.store_id)
126
127
  end.compact
127
128
  return if recipients.empty?
128
129
 
@@ -3,9 +3,9 @@ module Cats
3
3
  class BeneficiaryService
4
4
  def clear_distribution_list(id)
5
5
  round_plan = RoundPlan.find(id)
6
- raise(StandardError, 'Round plan is not in draft state.') unless round_plan.status == RoundPlan::DRAFT
6
+ raise(StandardError, "Round plan is not in draft state.") unless round_plan.status == RoundPlan::DRAFT
7
7
 
8
- RoundBeneficiary.joins(:round_plan_item).where(round_plan_item: { round_plan_id: id }).delete_all
8
+ RoundBeneficiary.joins(:round_plan_item).where(round_plan_item: {round_plan_id: id}).delete_all
9
9
  end
10
10
 
11
11
  def generate_distribution_list(id)
@@ -14,7 +14,7 @@ module Cats
14
14
  plan_days = round_plan.plan.no_of_round_days
15
15
  rounds = round_plan.rounds.count
16
16
  beneficiaries = Beneficiary.joins(:beneficiary_category).where(
17
- beneficiary_category: { plan_id: round_plan.plan_id }
17
+ beneficiary_category: {plan_id: round_plan.plan_id}
18
18
  ).group_by(&:fdp_id)
19
19
  beneficiaries.each_key do |key|
20
20
  beneficiaries[key] = beneficiaries[key].group_by(&:beneficiary_category_id)
@@ -48,38 +48,38 @@ module Cats
48
48
  end
49
49
 
50
50
  def remove_items(plan_id, ids)
51
- raise(StandardError, 'No beneficiaries specified.') if ids.count.zero?
51
+ raise(StandardError, "No beneficiaries specified.") if ids.count.zero?
52
52
 
53
53
  begin
54
54
  plan = RoundPlan.find(plan_id)
55
55
  rescue ActiveRecord::RecordNotFound
56
- raise(StandardError, 'Round plan not found.') unless plan
56
+ raise(StandardError, "Round plan not found.") unless plan
57
57
  end
58
58
 
59
59
  beneficiaries = RoundBeneficiary.joins(:round_plan_item)
60
- .where(round_plan_item: { round_plan_id: plan_id })
60
+ .where(round_plan_item: {round_plan_id: plan_id})
61
61
  to_delete = RoundBeneficiary.where(id: ids)
62
62
  diff = to_delete - beneficiaries
63
- raise(StandardError, 'Round plan beneficiaries should be from the same plan.') if diff.count.positive?
63
+ raise(StandardError, "Round plan beneficiaries should be from the same plan.") if diff.count.positive?
64
64
 
65
65
  to_delete.delete_all
66
66
  true
67
67
  end
68
68
 
69
69
  def confirm_receipt(plan_id, ids)
70
- raise(StandardError, 'No beneficiaries specified.') if ids.count.zero?
70
+ raise(StandardError, "No beneficiaries specified.") if ids.count.zero?
71
71
 
72
72
  begin
73
73
  plan = RoundPlan.find(plan_id)
74
74
  rescue ActiveRecord::RecordNotFound
75
- raise(StandardError, 'Round plan not found.') unless plan
75
+ raise(StandardError, "Round plan not found.") unless plan
76
76
  end
77
77
 
78
78
  beneficiaries = RoundBeneficiary.joins(:round_plan_item)
79
- .where(round_plan_item: { round_plan_id: plan_id })
79
+ .where(round_plan_item: {round_plan_id: plan_id})
80
80
  to_confirm = RoundBeneficiary.where(id: ids)
81
81
  diff = to_confirm - beneficiaries
82
- raise(StandardError, 'Round plan beneficiaries should be from the same plan.') if diff.count.positive?
82
+ raise(StandardError, "Round plan beneficiaries should be from the same plan.") if diff.count.positive?
83
83
 
84
84
  to_confirm.update_all(received: true)
85
85
  true
@@ -7,8 +7,8 @@ module Cats
7
7
  if plan.upstream
8
8
  # Create source hub authorizations for each item and
9
9
  # put them in a `Source Authorized` state
10
- store = Store.find_by(code: 'SUP-STORE')
11
- keeper = User.find_by(first_name: 'SUP-Storekeeper')
10
+ store = Store.find_by(code: "SUP-STORE")
11
+ keeper = User.find_by(first_name: "SUP-Storekeeper")
12
12
  authorizations = []
13
13
  plan.dispatch_plan_items.each do |item|
14
14
  authorizations << {
@@ -40,17 +40,17 @@ module Cats
40
40
  end
41
41
 
42
42
  def send_notification(allocation)
43
- notification_rule = Cats::Core::NotificationRule.find_by(code: 'allocation')
44
- raise(StandardError, 'Notification rule not found for allocation notification.') unless notification_rule
43
+ notification_rule = Cats::Core::NotificationRule.find_by(code: "allocation")
44
+ raise(StandardError, "Notification rule not found for allocation notification.") unless notification_rule
45
45
 
46
- users = Cats::Core::User.joins(:roles).where(cats_core_roles: { name: notification_rule.roles })
46
+ users = Cats::Core::User.joins(:roles).where(cats_core_roles: {name: notification_rule.roles})
47
47
  allocation.dispatch_plan_items.each do |item|
48
48
  location_id = item.destination_id
49
49
 
50
50
  recipients = users.map do |user|
51
51
  details = user.details
52
- if (details.key?('warehouse') && details['warehouse'] == location_id) ||
53
- (details.key?('hub') && details['hub'] == location_id)
52
+ if (details.key?("warehouse") && details["warehouse"] == location_id) ||
53
+ (details.key?("hub") && details["hub"] == location_id)
54
54
  user
55
55
  end
56
56
  end.compact
@@ -69,9 +69,9 @@ module Cats
69
69
  #
70
70
  def generate(id)
71
71
  details = RoundPlanItemDetail.joins(
72
- beneficiary_round_plan_item: { round_plan_item: :round_plan }
72
+ beneficiary_round_plan_item: {round_plan_item: :round_plan}
73
73
  ).where(
74
- beneficiary_round_plan_item: { cats_core_round_plan_items: { round_plan_id: id } }
74
+ beneficiary_round_plan_item: {cats_core_round_plan_items: {round_plan_id: id}}
75
75
  ).includes(
76
76
  beneficiary_round_plan_item: {
77
77
  round_plan_item: %i[round_plan region zone woreda fdp]
@@ -99,7 +99,7 @@ module Cats
99
99
  {
100
100
  reference_no: nil,
101
101
  dispatchable_id: id,
102
- dispatchable_type: 'Cats::Core::RoundPlan',
102
+ dispatchable_type: "Cats::Core::RoundPlan",
103
103
  items: items
104
104
  }
105
105
  end