dscf-banking 0.3.0 → 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: 77261771378e8c5903e5f77c66f3919e7528514bd7c8a44070dbe07c61c5aced
4
- data.tar.gz: 4db5b73418dc1a2625e1d01ba578d39e38655acf41361320735f75792eb986a7
3
+ metadata.gz: fb3d7fb4e0cee09c487b773f62c5fd87ac8a70f36a6ab19fd35478a11caf5b89
4
+ data.tar.gz: 2abfdc7273bde34ed021ac7111d42bb16c7ad796874d3007dd941b10c76a1aa0
5
5
  SHA512:
6
- metadata.gz: e23b8ca0fe1ed1ba9320edb49c4d22685547ea1a66fe5bcb7944ffafcb29ba9525107e42efe34f570006dcfe5364e5f70fb4d4be20eb4c9c51c3057f72883eff
7
- data.tar.gz: 475ee3557215bb66076ad7b5bd414a23c3e41422200bc9c64ebb1b21032c9f737c9407b31f4bbf8745ab562de8444d07d22c01d7c42adab7825830c35140365f
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,
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.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-banking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eyosiyas Mekbib