diff --git a/app/controllers/payment_runs_controller.rb b/app/controllers/payment_runs_controller.rb index fa1b994..f07e296 100644 --- a/app/controllers/payment_runs_controller.rb +++ b/app/controllers/payment_runs_controller.rb @@ -31,12 +31,18 @@ def edit #print "#{op.amount} #{op2.amount} #{op.ledger.name} #{op2.ledger.name}\n" j2 = op2.journal - kid_match = ((j.kid != nil and j2.kid !=nil) and (j.kid == j2.kid)) bill_match = ((j.bill_number != nil and j2.bill_number != nil) and (j.bill_number == j2.bill_number)) + if kid_match + matched_by = "kid" + elsif bill_match + matched_by = "bill" + else + matched_by = nil + end if (op.amount == -op2.amount) and (op.ledger == op2.ledger) and (kid_match or bill_match) then - @matches << [op, op2] + @matches << [op, op2,matched_by] end end @@ -49,33 +55,47 @@ def create ClosedOperation.transaction do - if params['mops'] then + #when locked by matched operations using "lock all" + if params['mops'] + + puts "-------------------------------------" + puts "Locked by matched operations" + puts "-------------------------------------" + params['mops'].each do |idx, ops| - cl = ClosedOperation.new - cl.save - print "\n\n\nOp thingie #{ops}\n\n\n" + ops = ops.split(',').collect! {|n| n.to_i} + cl = ClosedOperation.new + cl.save ops.each do |op_id| - print "\n\n\nClose #{op_id}\n\n\n" - op = JournalOperation.where({:id => op_id}).first + op = JournalOperation.find(op_id) op.closed_operation = cl op.save - end + end + add_tag(cl.id) end else + puts "-------------------------------------" + puts "Locked manually" + puts "-------------------------------------" - print "WEEE!!!! #{params['ops']}\n\n" + #when locked manually cl = ClosedOperation.new - cl.save + cl.save + if params['ops'].is_a?(String) + params['ops'] = params['ops'].split(',').collect! {|n| n.to_i} + end params['ops'].each do - |op_id| - print "Close #{op_id}\n\n" - op = JournalOperation.where({:id => op_id}).first + |op_id| + puts op_id + op = JournalOperation.find(op_id) op.closed_operation = cl op.save - end + end + add_tag(cl.id) end + # redirect_to("/payment_runs/#{params['pay_id']}/edit") redirect_to :action => :edit, :id => params['pay_id'] end @@ -87,4 +107,25 @@ def update def destroy end + private + def add_tag(clid) + #investigate if it is matched by kid or invoice + jos = JournalOperation.where(:closed_operation_id => clid) + count = jos.count + kid = jos.first.journal.kid + bill = jos.first.journal.bill_number + + count_same_kid = Journal.joins(:journal_operations).where(:journal_operations => {:closed_operation_id => clid}).where("kid is not null").where(:journals=> {:kid => kid}).count + count_same_bill = Journal.joins(:journal_operations).where(:journal_operations => {:closed_operation_id => clid}).where("bill_number is not null").where(:journals=> {:bill_number => bill}).count + + if count == count_same_kid + cop = ClosedOperation.find(clid) + cop.matched_by = "k" + cop.save + elsif count == count_same_bill + cop = ClosedOperation.find(clid) + cop.matched_by = "b" + cop.save + end + end end diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index e94baac..557b269 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -158,6 +158,7 @@ def dagbok @project = ( project == 'null' ? nil : Project.find(project)) @car = ( car == 'null' ? nil : Car.find(car)) @journal_type = ( journal_type == 'null' ? nil : JournalType.find(journal_type)) + puts @journal_operations.count end private diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb index 931d1fd..727b437 100644 --- a/app/helpers/reports_helper.rb +++ b/app/helpers/reports_helper.rb @@ -87,4 +87,9 @@ def car(id) jo.car.to_s unless jo.car_id.blank? end + def closed_by(closed_op_id) + "closed by " + JournalOperation.where(:closed_operation_id => closed_op_id).first.closed_operation.matched_by.to_s + #t(:closed_status, :scope => :reports) + end + end diff --git a/app/views/payment_runs/edit.html.erb b/app/views/payment_runs/edit.html.erb index c9a739a..6fa264e 100644 --- a/app/views/payment_runs/edit.html.erb +++ b/app/views/payment_runs/edit.html.erb @@ -1,3 +1,6 @@ + +
+ | <%=ledger.number.to_s + " " + ledger.name.to_s %> | + <%= t(:matched_by, :scope => :reports) %> | +<% @@ -81,7 +84,7 @@ <% jrnl = Journal.find(ops[0].journal_id)%> | <%= jrnl.journal_type.to_s %> | -<%= jrnl.number %> | +<%= link_to jrnl.number, edit_journal_path(jrnl) %> | <%= jrnl.period.to_s %> | <%= jrnl.journal_date.to_s %> | @@ -109,10 +112,12 @@<%= ops[0].journal.description %> | ++ <%= ops[2] %> + | @@ -123,7 +128,7 @@ <% jrnl = Journal.find(ops[1].journal_id)%> | <%= jrnl.journal_type.to_s %> | -<%= jrnl.number %> | +<%= link_to jrnl.number, edit_journal_path(jrnl)%> | <%= jrnl.period.to_s %> | <%= jrnl.journal_date.to_s %> | @@ -150,12 +155,16 @@ | <%= ops[1].journal.description %> | +<% end %> |
---|