Skip to content

Commit

Permalink
Added period of journal entry items selection capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Aquaj committed Jan 11, 2017
1 parent fc53d3e commit 569e486
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
21 changes: 21 additions & 0 deletions app/assets/javascripts/backend/bank_statements.js.coffee
Expand Up @@ -89,6 +89,27 @@
$(document).on "change", "#hide-lettered", ->
bankReconciliation.uiUpdate()

$(document).on "datepicker-change", "#set_period", (event, dates) ->
current_params = document.location.search

start = dates.date1
start = "period_start=#{start.getFullYear()}-#{start.getMonth()+1}-#{start.getDate()}"
param_space = new RegExp("(&|\\?)period_start=[^\&]*")
if param_space.exec(current_params)
current_params = current_params.replace(param_space, "$1" + start)
else
current_params += (if current_params.length > 0 then '&' else '?') + start

end = dates.date2
end = "period_end=#{end.getFullYear()}-#{end.getMonth()+1}-#{end.getDate()}"
param_space = new RegExp("(&|\\?)period_end=[^\&]*")
if param_space.exec(current_params)
current_params = current_params.replace(param_space, "$1" + end)
else
current_params += (if current_params.length > 0 then '&' else '?') + end

document.location.search = current_params

class BankReconciliation
constructor: (@precision) ->

Expand Down
3 changes: 1 addition & 2 deletions app/assets/javascripts/form/dates.js.coffee
Expand Up @@ -23,10 +23,9 @@
$.extend options,
format: "YYYY-MM-DD"
language: locale
singleMonth: true
showShortcuts: false
showTopbar: false
separator: ' -> '
separator: ' '
element.dateRangePicker options
element.attr "autocomplete", "off"
return
Expand Down
Expand Up @@ -36,12 +36,12 @@ def create
items_attributes:
{
'0' => {
name: 'Gap',
name: "#{'rest.actions.payment_gap'.t} #{Time.zone.today.l} - #{debit_account.name}",
real_debit: gap.abs,
account_id: debit_account.id
},
'-1' => {
name: 'Gap',
name: "#{'rest.actions.payment_gap'.t} #{Time.zone.today.l} - #{credit_account.name}",
real_credit: gap.abs,
account_id: credit_account.id
}
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/backend/bank_statements_controller.rb
Expand Up @@ -70,7 +70,11 @@ def import
def reconciliation
return unless @bank_statement = find_and_check
bank_statement_items = @bank_statement.items.order('ABS(debit-credit)')
journal_entry_items = @bank_statement.eligible_journal_entry_items.order('ABS(real_debit-real_credit)')
@period_start = @bank_statement.started_on - 20.days
@period_end = @bank_statement.started_on + 20.days
@period_start = Date.strptime(params[:period_start], '%Y-%m-%d') if params[:period_start]
@period_end = Date.strptime(params[:period_end ], '%Y-%m-%d') if params[:period_end ]
journal_entry_items = @bank_statement.eligible_journal_entry_items.between(@period_start, @period_end).order('ABS(real_debit-real_credit)')
unless journal_entry_items.any?
notify_error :need_entries_to_reconciliate
redirect_to params[:redirect] || { action: :show, id: @bank_statement.id }
Expand Down
4 changes: 2 additions & 2 deletions app/models/bank_statement.rb
Expand Up @@ -158,8 +158,8 @@ def letter_items(statement_items, journal_entry_items)
end

def eligible_journal_entry_items
margin = 20.days
unpointed = cash.unpointed_journal_entry_items.between(started_on - margin, stopped_on + margin)
# margin = 20.days
unpointed = cash.unpointed_journal_entry_items # .between(started_on - margin, stopped_on + margin)
pointed = JournalEntryItem.pointed_by(self)
JournalEntryItem.where(id: unpointed.pluck(:id) + pointed.pluck(:id))
end
Expand Down
1 change: 1 addition & 0 deletions app/themes/tekyla/stylesheets/all.scss
Expand Up @@ -31,6 +31,7 @@
@import "beehives";
@import "calendars";
@import "charts";
@import "daterangepicker";
@import "datetimepickers";
@import "equipments";
@import "forms";
Expand Down
5 changes: 5 additions & 0 deletions app/themes/tekyla/stylesheets/bank_statements.scss
Expand Up @@ -18,9 +18,14 @@
}

.details {
width: unset;
display: flex;
justify-content: center;
align-items: center;
* {
@include margin-left($default-gap);
text-align: center;
}
}
}

Expand Down
1 change: 1 addition & 0 deletions app/views/backend/bank_statements/reconciliation.html.haml
Expand Up @@ -13,6 +13,7 @@
- SaleNature.find_each do |nature|
- menu.item nature.name, new_backend_quick_sale_path(nature_id: nature.id, redirect: url_for), tabindex: -1, method: :get, class: 'from-selected-bank', title: nature.name
.details
%input#set_period{ type: 'daterange', value: "#{@period_start} – #{@period_end}".html_safe }
%label
%input#hide-lettered{ type: :checkbox, checked: true }
= :hide_lettered_lines.tl
Expand Down

0 comments on commit 569e486

Please sign in to comment.