mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
show invoice download link in wallet transaction debit operator
This commit is contained in:
parent
9ba8e46450
commit
909c204af5
@ -10,16 +10,19 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="t in transactions">
|
||||
<td>{{ t.created_at | amDateFormat:'L' }}</td>
|
||||
<td>{{ ::t.created_at | amDateFormat:'L' }}</td>
|
||||
<td>
|
||||
<span ng-if="t.transaction_type == 'credit'" translate>{{ 'credit' }}</span>
|
||||
<span ng-if="t.transaction_type == 'debit'" translate>{{ 'debit' }}</span>
|
||||
<a ng-href="api/invoices/{{t.invoice.id}}/download" target="_blank" ng-if="t.invoice.id">
|
||||
{{::t.invoice.reference}}
|
||||
</a>
|
||||
</td>
|
||||
<td>{{ t.user.full_name }}</td>
|
||||
<td>{{ ::t.user.full_name }}</td>
|
||||
<td ng-class="{'green':t.transaction_type == 'credit', 'red':t.transaction_type == 'debit'}">
|
||||
<span ng-if="t.transaction_type == 'credit'">+</span>
|
||||
<span ng-if="t.transaction_type == 'debit'">-</span>
|
||||
<strong>{{ t.amount | currency }}</strong>
|
||||
<strong>{{ ::t.amount | currency }}</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -10,7 +10,7 @@ class API::WalletController < API::ApiController
|
||||
def transactions
|
||||
@wallet = Wallet.find(params[:id])
|
||||
authorize @wallet
|
||||
@wallet_transactions = @wallet.wallet_transactions.includes(:transactable, user: [:profile]).order(created_at: :desc)
|
||||
@wallet_transactions = @wallet.wallet_transactions.includes(:invoice, user: [:profile]).order(created_at: :desc)
|
||||
end
|
||||
|
||||
def credit
|
||||
|
@ -7,6 +7,7 @@ class Invoice < ActiveRecord::Base
|
||||
has_many :invoice_items, dependent: :destroy
|
||||
accepts_nested_attributes_for :invoice_items
|
||||
belongs_to :user
|
||||
belongs_to :wallet_transaction
|
||||
|
||||
has_one :avoir, class_name: 'Invoice', foreign_key: :invoice_id, dependent: :destroy
|
||||
|
||||
|
@ -364,8 +364,10 @@ class Reservation < ActiveRecord::Base
|
||||
def debit_user_wallet
|
||||
if @wallet_amount_debit.present? and @wallet_amount_debit != 0
|
||||
amount = @wallet_amount_debit / 100.0
|
||||
WalletService.new(user: user, wallet: user.wallet).debit(amount, self)
|
||||
self.invoice.update_columns(wallet_amount: @wallet_amount_debit) if !user.invoicing_disabled?
|
||||
wallet_transaction = WalletService.new(user: user, wallet: user.wallet).debit(amount, self)
|
||||
if !user.invoicing_disabled? and wallet_transaction
|
||||
self.invoice.update_columns(wallet_amount: @wallet_amount_debit, wallet_transaction_id: wallet_transaction.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -48,7 +48,11 @@ class Subscription < ActiveRecord::Base
|
||||
if invoice
|
||||
invoc = generate_invoice(stp_invoice.id)
|
||||
# debit wallet
|
||||
invoc.wallet_amount = @wallet_amount_debit if debit_user_wallet
|
||||
wallet_transaction = debit_user_wallet
|
||||
if wallet_transaction
|
||||
invoc.wallet_amount = @wallet_amount_debit
|
||||
invoc.wallet_transaction_id = wallet_transaction.id
|
||||
end
|
||||
invoc.save
|
||||
end
|
||||
# cancel subscription after create
|
||||
@ -101,7 +105,11 @@ class Subscription < ActiveRecord::Base
|
||||
if invoice
|
||||
invoc = generate_invoice
|
||||
# debit wallet
|
||||
invoc.wallet_amount = @wallet_amount_debit if debit_user_wallet
|
||||
wallet_transaction = debit_user_wallet
|
||||
if wallet_transaction
|
||||
invoc.wallet_amount = @wallet_amount_debit
|
||||
invoc.wallet_transaction_id = wallet_transaction.id
|
||||
end
|
||||
invoc.save
|
||||
end
|
||||
return true
|
||||
@ -243,7 +251,7 @@ class Subscription < ActiveRecord::Base
|
||||
def debit_user_wallet
|
||||
if @wallet_amount_debit.present? and @wallet_amount_debit != 0
|
||||
amount = @wallet_amount_debit / 100.0
|
||||
WalletService.new(user: user, wallet: user.wallet).debit(amount, self)
|
||||
return WalletService.new(user: user, wallet: user.wallet).debit(amount, self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,6 +5,7 @@ class WalletTransaction < ActiveRecord::Base
|
||||
belongs_to :wallet
|
||||
belongs_to :reservation
|
||||
belongs_to :transactable, polymorphic: true
|
||||
has_one :invoice
|
||||
|
||||
validates_inclusion_of :transaction_type, in: %w( credit debit )
|
||||
validates :user, :wallet, presence: true
|
||||
|
@ -4,9 +4,8 @@ json.array!(@wallet_transactions) do |t|
|
||||
json.id t.user.id
|
||||
json.full_name t.user.profile.full_name
|
||||
end
|
||||
json.transactable do
|
||||
if t.transactable_type == 'Reservation'
|
||||
json.reservable_type t.transactable.reservable_type
|
||||
end
|
||||
end if t.transactable
|
||||
json.invoice do
|
||||
json.id t.invoice.id
|
||||
json.reference t.invoice.reference
|
||||
end if t.invoice
|
||||
end
|
||||
|
@ -0,0 +1,5 @@
|
||||
class AddWalletTransactionToInvoice < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :invoices, :wallet_transaction, index: true, foreign_key: true
|
||||
end
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160718165434) do
|
||||
ActiveRecord::Schema.define(version: 20160720124355) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -221,10 +221,12 @@ ActiveRecord::Schema.define(version: 20160718165434) do
|
||||
t.boolean "subscription_to_expire"
|
||||
t.text "description"
|
||||
t.integer "wallet_amount"
|
||||
t.integer "wallet_transaction_id"
|
||||
end
|
||||
|
||||
add_index "invoices", ["invoice_id"], name: "index_invoices_on_invoice_id", using: :btree
|
||||
add_index "invoices", ["user_id"], name: "index_invoices_on_user_id", using: :btree
|
||||
add_index "invoices", ["wallet_transaction_id"], name: "index_invoices_on_wallet_transaction_id", using: :btree
|
||||
|
||||
create_table "licences", force: :cascade do |t|
|
||||
t.string "name", limit: 255, null: false
|
||||
@ -737,6 +739,7 @@ ActiveRecord::Schema.define(version: 20160718165434) do
|
||||
add_foreign_key "availability_tags", "tags"
|
||||
add_foreign_key "events_event_themes", "event_themes"
|
||||
add_foreign_key "events_event_themes", "events"
|
||||
add_foreign_key "invoices", "wallet_transactions"
|
||||
add_foreign_key "o_auth2_mappings", "o_auth2_providers"
|
||||
add_foreign_key "open_api_calls_count_tracings", "open_api_clients"
|
||||
add_foreign_key "prices", "groups"
|
||||
|
@ -283,6 +283,7 @@ module Reservations
|
||||
assert_equal transaction.transaction_type, 'debit'
|
||||
assert_equal transaction.amount, 10
|
||||
assert_equal transaction.amount, invoice.wallet_amount / 100.0
|
||||
assert_equal transaction.id, invoice.wallet_transaction_id
|
||||
end
|
||||
|
||||
test "user without subscription and with invoicing disabled reserves a machine and pay wallet with success" do
|
||||
|
@ -141,5 +141,6 @@ class Subscriptions::CreateAsUserTest < ActionDispatch::IntegrationTest
|
||||
assert_equal transaction.transaction_type, 'debit'
|
||||
assert_equal transaction.amount, 10
|
||||
assert_equal transaction.amount, invoice.wallet_amount / 100.0
|
||||
assert_equal transaction.id, invoice.wallet_transaction_id
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user