Browse Source

bugfix, when they are payments from past ocr sale

Jose Miguel Ledon Nieblas 8 years ago
parent
commit
a81bb8ad93
1 changed files with 5 additions and 1 deletions
  1. 5 1
      app/controllers/cash_outs_controller.rb

+ 5 - 1
app/controllers/cash_outs_controller.rb

@@ -168,7 +168,11 @@ class CashOutsController < ApplicationController
       @initial_cash = @opened_cash_register.initial_cash
       @incomings = CashRegistersMove.where("open_cash_register_id = (?) and move_type = '1' and status = 1", @opened_cash_register.id).order('created_at')
       @outgoings = CashRegistersMove.where("open_cash_register_id = (?) and move_type = '0' and status = 1", @opened_cash_register.id).order('created_at')
-      all_sales = Sale.where("open_cash_register_id = (?) and status != 1", @opened_cash_register.id)
+
+      # all_sales = Sale.where("open_cash_register_id = (?) and status != 1", @opened_cash_register.id)
+      sales_ids = CashRegistersMove.where("open_cash_register_id = (?) and move_type = '1' and status = 1", @opened_cash_register.id).pluck("DISTINCT sale_id")
+      all_sales = Sale.activas.where("id IN (?)", sales_ids)
+
       @cash_sales = CashRegistersMove.where("open_cash_register_id = (?) and move_type = '1' and status = 1 and sale_id IN (?)", @opened_cash_register.id, all_sales.where(saletype: 1).pluck(:id)).sum(:quantity)
       @credit_sales = CashRegistersMove.where("open_cash_register_id = (?) and move_type = '1' and status = 1 and concept = 3", @opened_cash_register.id).sum(:quantity)
       @reserved_sales = CashRegistersMove.where("open_cash_register_id = (?) and move_type = '1' and status = 1 and sale_id IN (?)", @opened_cash_register.id, all_sales.where(saletype: 2).pluck(:id)).sum(:quantity)