dscf-banking 0.2.9 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df271e9f69727201aab1508e782bf5a18e7b59fba9e67dffd2224d92319f9280
4
- data.tar.gz: '0618830ecf6bbab8f90cfffc3da24303cd08788cc8387d42070c4093b9be5b45'
3
+ metadata.gz: fb3d7fb4e0cee09c487b773f62c5fd87ac8a70f36a6ab19fd35478a11caf5b89
4
+ data.tar.gz: 2abfdc7273bde34ed021ac7111d42bb16c7ad796874d3007dd941b10c76a1aa0
5
5
  SHA512:
6
- metadata.gz: 8ff010dc9f9a04cddbcebf7dcdd83b5ba0b592a6bac40da63422002a7db9e2f9ecede7ae7aef4cc0cafd8ce579c2d8df8c3773f1e4ea8261de8839de353c8788
7
- data.tar.gz: 8e52eeaa335df4fbeb0af438cbb1ac1f9a9c9ee15de8629212ad9bae3ce7eb2984e2936f485f9a5edb052e45ab7bd2738c0cc3fe898dcf5ce5bcb5971ed4d393
6
+ metadata.gz: 24266cf3117b88ad84bd18067fe015025f14680d782b8d1f46b0e9b1af5683844474d49e6e4a3bd06e3b19033ff210d52a810e605ad85a4351ad0eea09ece1d9
7
+ data.tar.gz: 5dcf5ed06d580fdf6166298d0bb63a656e21aaee29e5be1fbc10dbf51f035d094208fa215b99b511d5739acb859e38ed95b510f399ee91aa0ba0cb6fdb97f40b
@@ -213,8 +213,92 @@ module Dscf::Banking
213
213
  }
214
214
  end
215
215
 
216
+ def transactions
217
+ account = Dscf::Banking::Account.find(params[:id])
218
+
219
+ transactions = Dscf::Banking::Transaction
220
+ .where("account_id = ? OR debit_account_id = ? OR credit_account_id = ?", account.id, account.id, account.id)
221
+ .includes(:account, :transaction_type, :debit_account, :credit_account)
222
+
223
+ # Apply pagination if requested
224
+ page = params[:page].to_i
225
+ per_page = (params[:per_page] || 10).to_i
226
+
227
+ # Apply filters
228
+ transactions = transactions.where(status: params[:status]) if params[:status].present?
229
+ transactions = transactions.where(transaction_type_id: params[:transaction_type_id]) if params[:transaction_type_id].present?
230
+
231
+ # Apply ordering
232
+ order_column = %w[id reference_number amount currency status created_at updated_at].include?(params[:order_by]) ? params[:order_by] : "created_at"
233
+ order_direction = %w[asc desc].include?(params[:order_direction]) ? params[:order_direction] : "desc"
234
+ transactions = transactions.order("#{order_column} #{order_direction}")
235
+
236
+ if page.positive?
237
+ total_count = transactions.count
238
+ total_pages = (total_count.to_f / per_page).ceil
239
+ transactions = transactions.offset((page - 1) * per_page).limit(per_page)
240
+
241
+ render json: {
242
+ success: true,
243
+ message: "Account transactions retrieved successfully",
244
+ data: transactions.map { |transaction| transaction_data(transaction) },
245
+ pagination: {
246
+ current_page: page,
247
+ per_page: per_page,
248
+ total_count: total_count,
249
+ total_pages: total_pages
250
+ }
251
+ }
252
+ else
253
+ render json: {
254
+ success: true,
255
+ message: "Account transactions retrieved successfully",
256
+ data: transactions.map { |transaction| transaction_data(transaction) }
257
+ }
258
+ end
259
+ rescue ActiveRecord::RecordNotFound
260
+ render json: {
261
+ success: false,
262
+ error: "Account not found"
263
+ }, status: :not_found
264
+ end
265
+
216
266
  private
217
267
 
268
+ def transaction_data(transaction)
269
+ {
270
+ id: transaction.id,
271
+ reference_number: transaction.reference_number,
272
+ amount: transaction.amount.to_f,
273
+ currency: transaction.currency,
274
+ description: transaction.description,
275
+ status: transaction.status,
276
+ account_id: transaction.account_id,
277
+ debit_account_id: transaction.debit_account_id,
278
+ credit_account_id: transaction.credit_account_id,
279
+ transaction_type_id: transaction.transaction_type_id,
280
+ transaction_type: {
281
+ id: transaction.transaction_type.id,
282
+ code: transaction.transaction_type.code,
283
+ name: transaction.transaction_type.name
284
+ },
285
+ debit_account: account_summary(transaction.debit_account),
286
+ credit_account: account_summary(transaction.credit_account),
287
+ created_at: transaction.created_at,
288
+ updated_at: transaction.updated_at
289
+ }
290
+ end
291
+
292
+ def account_summary(account)
293
+ return nil unless account
294
+ {
295
+ id: account.id,
296
+ account_number: account.account_number,
297
+ name: account.name,
298
+ currency: account.currency
299
+ }
300
+ end
301
+
218
302
  def account_data(account)
219
303
  {
220
304
  id: account.id,
@@ -4,6 +4,42 @@ module Dscf::Banking
4
4
 
5
5
  before_action :find_application
6
6
 
7
+ def index
8
+ super do
9
+ documents = @application.documents
10
+ options = { each_serializer: DocumentSerializer }
11
+ [documents, options]
12
+ end
13
+ end
14
+
15
+ def show
16
+ super do
17
+ document = @application.documents.find(params[:id])
18
+ options = { serializer: DocumentSerializer }
19
+ [document, options]
20
+ end
21
+ end
22
+
23
+ def create
24
+ document = @application.documents.build(model_params)
25
+
26
+ if document.save
27
+ # Attach file if provided
28
+ document.files.attach(params[:document][:file]) if params[:document][:file].present?
29
+
30
+ render json: {
31
+ success: true,
32
+ data: DocumentSerializer.new(document).as_json
33
+ }, status: :created
34
+ else
35
+ render json: {
36
+ success: false,
37
+ error: "Failed to create document",
38
+ errors: document.errors.full_messages
39
+ }, status: :unprocessable_entity
40
+ end
41
+ end
42
+
7
43
  private
8
44
 
9
45
  def find_application
@@ -49,5 +85,9 @@ module Dscf::Banking
49
85
  update: []
50
86
  }
51
87
  end
88
+
89
+ def serializer_class
90
+ Dscf::Banking::DocumentSerializer
91
+ end
52
92
  end
53
93
  end
@@ -9,7 +9,7 @@ module Dscf::Banking
9
9
  belongs_to :assigned_branch_manager, optional: true
10
10
  has_one :account, serializer: AccountSerializer, if: :has_account?
11
11
  has_many :reviews, serializer: Dscf::Core::ReviewSerializer
12
- has_many :documents, serializer: DocumentSerializer
12
+ has_many :documents, serializer: Dscf::Banking::DocumentSerializer
13
13
 
14
14
  def has_account?
15
15
  object.has_account?
@@ -1,12 +1,15 @@
1
1
  module Dscf::Banking
2
2
  class DocumentSerializer < ActiveModel::Serializer
3
- attributes :id, :document_type, :is_verified, :verified_at, :metadata, :created_at, :updated_at, :file_url
3
+ attributes :id, :document_type, :is_verified, :verified_at, :metadata, :file_urls, :created_at, :updated_at
4
4
 
5
- # Remove polymorphic association that causes ActiveStorage issues
6
- # belongs_to :verified_by, polymorphic: true, optional: true
7
-
8
- def file_url
9
- object.file_url
5
+ def file_urls
6
+ return [] unless object.files.attached?
7
+
8
+ object.files.map do |file|
9
+ Rails.application.routes.url_helpers.rails_blob_path(file, only_path: true)
10
+ end
11
+ rescue StandardError
12
+ []
10
13
  end
11
14
  end
12
15
  end
@@ -0,0 +1,23 @@
1
+ Rails.application.config.to_prepare do
2
+ ActiveSupport::Notifications.subscribe("review.created") do |name, start, finish, id, payload|
3
+ reviewable = payload[:reviewable]
4
+
5
+ if reviewable.is_a?(Dscf::Banking::Application)
6
+ reviewable.reload
7
+ review_status = reviewable.review_status
8
+
9
+ status_map = {
10
+ "submitted" => "submitted",
11
+ "under_review" => "under_review",
12
+ "approved" => "approved",
13
+ "rejected" => "rejected",
14
+ "request_modification" => "request_modification"
15
+ }
16
+
17
+ mapped_status = status_map[review_status]
18
+ if mapped_status && reviewable.status != mapped_status
19
+ reviewable.update!(status: mapped_status)
20
+ end
21
+ end
22
+ end
23
+ end
data/config/routes.rb CHANGED
@@ -7,6 +7,7 @@ Dscf::Banking::Engine.routes.draw do
7
7
  post :activate
8
8
  post :suspend
9
9
  post :close
10
+ get :transactions
10
11
  end
11
12
  end
12
13
  resources :product_categories
data/db/seeds.rb CHANGED
@@ -48,6 +48,26 @@ user7 = User.create(name: "Fikirte Alemayehu", email: "fikirte@example.com", pas
48
48
  user7.roles << branch_manager_role
49
49
  puts "Created user: #{user7.name}"
50
50
 
51
+ # Seed transaction types
52
+ puts "Seeding transaction types..."
53
+ deposit_type = Dscf::Banking::TransactionType.find_or_create_by(code: "DEPOSIT") do |tt|
54
+ tt.name = "Deposit"
55
+ tt.description = "Deposit transaction - money coming into account"
56
+ end
57
+ puts "Created transaction type: #{deposit_type.name}"
58
+
59
+ withdrawal_type = Dscf::Banking::TransactionType.find_or_create_by(code: "WITHDRAWAL") do |tt|
60
+ tt.name = "Withdrawal"
61
+ tt.description = "Withdrawal transaction - money going out of account"
62
+ end
63
+ puts "Created transaction type: #{withdrawal_type.name}"
64
+
65
+ transfer_type = Dscf::Banking::TransactionType.find_or_create_by(code: "TRANSFER") do |tt|
66
+ tt.name = "Transfer"
67
+ tt.description = "Transfer transaction - money moving between accounts"
68
+ end
69
+ puts "Created transaction type: #{transfer_type.name}"
70
+
51
71
  # Seed system accounts for transaction processing
52
72
  puts "Seeding system accounts..."
53
73
  system_deposit_account = Dscf::Banking::Account.find_or_create_by(
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Banking
3
- VERSION = "0.2.9"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-banking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eyosiyas Mekbib
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-10-15 00:00:00.000000000 Z
10
+ date: 2025-10-16 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -482,6 +482,7 @@ files:
482
482
  - app/services/dscf/banking/deposit_service.rb
483
483
  - app/services/dscf/banking/transfer_service.rb
484
484
  - app/services/dscf/banking/withdrawal_service.rb
485
+ - config/initializers/review_callbacks.rb
485
486
  - config/initializers/review_extensions.rb
486
487
  - config/locales/en.yml
487
488
  - config/routes.rb