Skip to content

Commit

Permalink
Merge branch 'master' into debug/gh#1977-fix_linear_depreciation_on_a…
Browse files Browse the repository at this point in the history
…nnual_period

Merging last gitignore updates
  • Loading branch information
Zank94 committed Aug 17, 2017
2 parents 760305b + 9cc78c0 commit 89371ae
Show file tree
Hide file tree
Showing 150 changed files with 3,981 additions and 633 deletions.
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ AllCops:

Rails:
Enabled: true

Rails/HttpPositionalArguments:
Enabled: false

Expand All @@ -26,5 +26,8 @@ Rails/ApplicationJob:
Metrics/LineLength:
Enabled: false

Lint/AssignmentInCondition:
Enabled: false

Metrics/MethodLength:
Max: 60
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ GEM
activesupport (>= 3.0.0)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.12.0)
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
feedjira (2.1.2)
faraday (>= 0.9)
Expand Down Expand Up @@ -213,7 +213,7 @@ GEM
i18n (0.8.6)
i18n-complements (1.1.0)
i18n (>= 0.6)
i18n-js (3.0.0)
i18n-js (3.0.1)
i18n (~> 0.6, >= 0.6.6)
iban-tools (1.1.0)
interception (0.5)
Expand Down Expand Up @@ -441,7 +441,7 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
savon (2.11.1)
savon (2.11.2)
akami (~> 1.2)
builder (>= 2.1.2)
gyoku (~> 1.2)
Expand All @@ -456,7 +456,7 @@ GEM
selenium-webdriver (3.4.4)
childprocess (~> 0.5)
rubyzip (~> 1.0)
sentry-raven (2.6.1)
sentry-raven (2.6.2)
faraday (>= 0.7.6, < 1.0)
sepa_king (0.9.0)
activemodel (>= 3.0.0)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.48.2
2.49.1
46 changes: 35 additions & 11 deletions app/assets/javascripts/backend/bank_statements.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,37 @@
@_findAndCustomizeButton()

_initializeDatePicker: ->
minDate = $(this.dateInput).attr('data-min-date')
maxDate = $(this.dateInput).attr('data-max-date')
bankStatementDatesRanges = $(this.dateInput).attr('data-bank-statement-dates-ranges')

bankStatementDates = null
if bankStatementDatesRanges
bankStatementDates = JSON.parse("[" + bankStatementDatesRanges + "]")

@dateInput.datepicker
showOn: "button"
buttonText: @dateInput.data("label")
onSelect: @onSelect
dateFormat: "yy-mm-dd"
minDate: minDate
maxDate: maxDate
beforeShowDay: (date) ->
if bankStatementDates
enableDateCase = false
bankStatementDates[0].some (item, index) ->
startDate = new Date(item.start)
startDate.setHours(0, 0, 0)

endDate = new Date(item.end)
endDate.setHours(0, 0, 0)

if date >= startDate && date <= endDate
enableDateCase = true
return true

return [enableDateCase, 'disabled']

@dateInput.attr "autocomplete", "off"

_findAndCustomizeButton: ->
Expand All @@ -41,9 +67,6 @@
position_space = new RegExp(".*scroll_to=(\\d+).*")
position = position_space.exec location.search
if position
$("#hide-lettered").attr('checked', false)
$("#hide-lettered").change()

scrollTo = $("[data-type=bank_statement_item][data-id=#{position[1]}]").parents('.date-section')[0]
$('.list').scrollTop(scrollTo.offsetTop - $('.list')[0].offsetTop)

Expand All @@ -64,8 +87,9 @@
return if $(event.target).is("input,a")
bankReconciliation.deselectLine $(@)

$(document).on "click", ".reconciliation-item a#clear", ->
$(document).on "click", ".reconciliation-item a#clear", (event) ->
# Clear reconciliation letter
event.stopPropagation();
button = $(@)
line = bankReconciliation.closestLine(button)
bankReconciliation.clearReconciliationLetterFromLine line
Expand Down Expand Up @@ -368,11 +392,12 @@
bankLines = lines.filter(":not(.lettered)[data-type=bank_statement_item]")
bankIds = bankLines.get().map (line) =>
@_idForLine line
url = window.location.pathname.split('/').slice(0, -1).join('/') + '/letter'
url = '/backend/bank-reconciliation/letters'
$.ajax url,
type: 'PATCH'
type: 'POST'
dataType: 'JSON'
data:
cash_id: $('#cash_id').val()
journal_entry_items: journalIds
bank_statement_items: bankIds
success: (response) =>
Expand All @@ -388,12 +413,11 @@
return false

_unletterItems: (letter) ->
url = window.location.pathname.split('/').slice(0, -1).join('/') + '/unletter'
# url = '/backend/bank-reconciliation/letters/' + letter
url = $(event.target).closest('#clear').attr('href')
$.ajax url,
type: 'PATCH'
type: 'DELETE'
dataType: 'JSON'
data:
letter: letter
success: (response) =>
lines = @_linesWithReconciliationLetter(response.letter)
lines.find(".details .letter").text ""
Expand All @@ -407,7 +431,7 @@
return false

_deleteLine: (line) ->
url = (window.location.pathname.split('/').slice(0, -1).concat ['bank-statement-items', line.data('id')]).join('/')
url = '/backend/bank-statement-items/' + line.data('id')
$.ajax url,
type: 'DELETE'
dataType: 'JSON'
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/backend/interventions.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@
$(this).each ->
E.interventions.refresh $(this)

$(document).ready ->
$('*[data-intervention-updater]').each ->
E.interventions.refresh $(this)

# selector:initialized
$(document).on 'selector:change', '*[data-intervention-updater]', ->
$(this).each ->
Expand Down
18 changes: 11 additions & 7 deletions app/concepts/sequence_manager.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class SequenceManager
def initialize(klass, options)
options = { force: true }.merge(options)

@managed = klass

@start = options[:start]
Expand Down Expand Up @@ -31,20 +33,22 @@ def unique_predictable
value
end

def unique_reliable
value = sequence.next_value!
value = sequence.next_value! while @managed.find_by(@column => value)
value
end

def load_predictable_into(record)
return true if @force && number_of(record).present?
return true unless @force || number_of(record).nil?
set_number(record, unique_predictable)
true
end

def load_reliable_into(record)
return true if !@force && number_of(record)

return true unless @force || number_of(record).nil?
return load_predictable_into(record) unless sequence

value = sequence.next_value!
value = sequence.next_value! while @managed.find_by(@column => value)
set_number(record, value)
set_number(record, unique_reliable)
true
end

Expand Down
112 changes: 112 additions & 0 deletions app/controllers/backend/bank_reconciliation/gaps_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
module Backend
module BankReconciliation
# Handles creation of 'Various Operations' from bank_statement_items + journal_entry_items.
class GapsController < Backend::BaseController
def create
@period_start = params[:period_start]
@period_end = params[:period_end]

bank_statement_items = fetch_bank_items
journal_entry_items = fetch_journal_items

if !params[:bank_statement_id].nil?
@bank_statement = BankStatement.find(params[:bank_statement_id])
else
@bank_statements = bank_statement_items.map(&:bank_statement).uniq
end

@cash = Cash.find_by(id: params[:cash_id])

return head :bad_request unless @cash
# return head :bad_request unless @bank_statement

gap = sold(bank_statement_items, journal_entry_items)

return unless (accs = accounts(gap))
new_entry = regul_entry_for(gap.abs, *accs)
return head :bad_request unless new_entry

letter_and_redirect bank_statement_items,
fuse_items(journal_entry_items,
with_matching_items_of: new_entry)
end

private

def accounts(gap)
bank = @cash.account
if gap > 0
return (head(:bad_request) && nil) unless Account.of_usage(:other_usual_running_profits).count.nonzero?
return [bank, credit_gap_account]
end
return (head(:bad_request) && nil) unless Account.of_usage(:other_usual_running_expenses).count.nonzero?
[debit_gap_account, bank]
end

def sold(bank_items, journal_items)
[bank_items, journal_items].map { |items| items.sum(:credit) - items.sum(:debit) }
.sum
end

def credit_gap_account
shortest = Account.of_usage(:other_usual_running_profits).minimum('LENGTH(number)')
Account.of_usage(:other_usual_running_profits).where("LENGTH(number) = #{shortest}").first
end

def regul_entry_for(amount, debit, credit)
return false unless debit && credit
JournalEntry.create!(
journal_entry_params.merge(
currency: @cash.currency,
printed_on: Time.zone.now,
items_attributes:
{
'0' => item_for(amount, debit, :debit),
'-1' => item_for(amount, credit, :credit)
}
)
)
end

def fuse_items(source_items, with_matching_items_of: [])
cash_account_ids = [@bank_statement.cash_account_id] unless @bank_statement.nil?
cash_account_ids = @bank_statements.map(&:cash_account_id) unless @bank_statements.nil?

JournalEntryItem.where(id: source_items + with_matching_items_of.items.where(account_id: cash_account_ids))
end

def item_for(amount, account, key)
{
name: "#{'rest.actions.payment_gap'.t} #{Time.zone.today.l} - #{account.name}",
"real_#{key}": amount,
account_id: account.id
}
end

def letter_and_redirect(bank_items, entry_items)
head :bad_request unless @cash.letter_items(bank_items, entry_items)

redirect_to backend_bank_reconciliation_items_path(@bank_statement, scroll_to: bank_items.order(transfered_on: :asc).first.id) unless @bank_statement.nil?

redirect_to reconciliate_backend_bank_reconciliation_items_path(cash_id: @cash.id, scroll_to: bank_items.order(transfered_on: :asc).first.id, period_start: @period_start, period_end: @period_end) unless @bank_statements.nil?
end

def debit_gap_account
shortest = Account.of_usage(:other_usual_running_expenses).minimum('LENGTH(number)')
Account.of_usage(:other_usual_running_expenses).where("LENGTH(number) = #{shortest}").first
end

def fetch_bank_items
params[:bank_statement_item_ids] ? BankStatementItem.where(id: params[:bank_statement_item_ids]) : BankStatementItem.none
end

def fetch_journal_items
params[:journal_entry_item_ids] ? JournalEntryItem.where(id: params[:journal_entry_item_ids]) : JournalEntryItem.none
end

def journal_entry_params
params.permit(:journal_id)
end
end
end
end
Loading

0 comments on commit 89371ae

Please sign in to comment.