Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
karidyang committed Jul 13, 2014
1 parent 767de76 commit 4b82af8
Show file tree
Hide file tree
Showing 25 changed files with 217 additions and 48 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Expand Up @@ -12,7 +12,7 @@ gem 'sqlite3'
gem 'yajl-ruby', :require => 'yajl'
#gem 'nokogiri'
gem 'authlogic'
gem 'json'
gem 'json','1.8.1'
gem 'magic_encoding'

# Paginator
Expand All @@ -23,6 +23,8 @@ gem 'bootstrap-will_paginate', '0.0.6'
group :assets do
gem 'sass-rails'
gem 'sass'
gem 'therubyracer'
gem 'uglifier'
end
# File Uploads
# gem 'paperclip'
Expand Down
15 changes: 13 additions & 2 deletions Gemfile.lock
Expand Up @@ -53,17 +53,19 @@ GEM
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.2.3)
erubis (2.7.0)
execjs (2.0.1)
highline (1.6.19)
hike (1.2.3)
i18n (0.6.5)
journey (1.0.4)
jquery-rails (2.1.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.0)
json (1.8.1)
kaminari (0.14.1)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
libv8 (3.16.14.3)
magic_encoding (0.0.2)
mail (2.4.4)
i18n (>= 0.4.0)
Expand Down Expand Up @@ -105,6 +107,7 @@ GEM
rake (10.1.0)
rdoc (3.12.2)
json (~> 1.4)
ref (1.0.5)
ruby-ole (1.2.11.7)
sass (3.2.10)
sass-rails (3.2.6)
Expand All @@ -119,12 +122,18 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.8)
therubyracer (0.12.0)
libv8 (~> 3.16.14.0)
ref
thor (0.18.1)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.37)
uglifier (2.2.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
uuidtools (2.1.4)
will_paginate (3.0.3)
yajl-ruby (1.1.0)
Expand All @@ -139,7 +148,7 @@ DEPENDENCIES
carrierwave
debugger
jquery-rails (= 2.1.4)
json
json (= 1.8.1)
kaminari
magic_encoding
mime-types
Expand All @@ -150,6 +159,8 @@ DEPENDENCIES
sass-rails
spreadsheet
sqlite3
therubyracer
uglifier
uuidtools
will_paginate (= 3.0.3)
yajl-ruby
27 changes: 25 additions & 2 deletions app/controllers/bills_controller.rb
Expand Up @@ -70,10 +70,11 @@ def calculate
end
plot = Plot.find(current_plot)
logger.info "plot name is #{plot.name}"
day = params[:day] || Date.today
plot.areas.each do |area|
logger.info "area is #{area.id}"
area.houses.each do |house|
house.create_bill(Date.today, @current_user.name)
house.create_bill(day, @current_user.name)
end
end
redirect_to :action => :index
Expand Down Expand Up @@ -137,11 +138,13 @@ def push
house = House.find(params[:house_id])
bill_items = BillItem.find(bill_item_ids)
begin
push_money = []
bill_items.each do |bi|
bi.push_item true, @current_user.name
push_money << {:item_name=>bi.item_name, :push => bi.push_money}
bi.bill.check_status
end
result = {:result => 'success', :msg => '冲销成功', :house_code => house.house_code}
result = {:result => 'success', :msg => '冲销成功', :house_code => house.house_code, :push_money=> push_money}
rescue Exception => e
puts "exception : #{e.message}"
result = {:result => 'fail', :msg => e.message}
Expand Down Expand Up @@ -188,4 +191,24 @@ def save_temporary

redirect_to controller: 'home', action: 'index', id: params[:house_id]
end

def del_items
unless @current_user.has_privilege?('bills', 'destroy')
miss_privilege
return
end
bill_item_ids = params[:bill_item_ids].each { |itemId| itemId.to_i }

if bill_item_ids.empty?
result = {:result => 'fail', :msg => '数组为空'}
else
house = House.find(params[:house_id])
bill_items = BillItem.find(bill_item_ids)
bill_items.each do |bi|
bi.destroy()
end
result = {:result => 'success', :msg => '删除成功', :house_code => house.house_code}
end
render :json => result
end
end
2 changes: 1 addition & 1 deletion app/controllers/charges_controller.rb
Expand Up @@ -18,7 +18,7 @@ def index
return
end
if params[:item_name].nil?
@charges = Charge.paginate(:page => params[:page])
@charges = Charge.where('plot_id=?', current_plot).paginate(:page => params[:page])
else
@charges = Charge.where('item_name like ?', "%#{params[:item_name]}%").paginate(:page => params[:page])
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/owners_controller.rb
Expand Up @@ -24,7 +24,7 @@ def index
@owners = house.owners.order('name')
else
@house_code = 0
@owners = Owner.order('house_id').paginate(:page => params[:page])
@owners = Owner.where("plot_id=#{current_plot}").order('house_id').paginate(:page => params[:page])
end

end
Expand Down Expand Up @@ -73,6 +73,7 @@ def create
return
end
pt = params[:owner]
pt[:plot_id] = @owner.house.plot_id
@owner = Owner.new(pt)
@owner.house_id = params[:house] || pt[:house_id]
if @owner.save
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/report_controller.rb
Expand Up @@ -6,7 +6,7 @@ def user_report
miss_privilege
return
end
@user_reports = UserReport.find_by_user(params[:start_time], params[:end_time])
@user_reports = UserReport.find_by_user(params[:start_time], params[:end_time],current_plot)
end

def user_report_detail
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/notices_helper.rb
@@ -1,3 +1,4 @@
# -*- encoding : utf-8 -*-
module NoticesHelper
def get_read(user_notice)
get_boolean({false => '未读', true => '已读'}, user_notice.is_read)
Expand All @@ -6,4 +7,4 @@ def get_read(user_notice)
def get_publish_type(notice)
get({1 => '全局公告', 2 => '特定公告'}, notice.publish_type)
end
end
end
1 change: 1 addition & 0 deletions app/models/bill_item.rb
Expand Up @@ -52,6 +52,7 @@ def push_item(can_push=false, operator='系统')
pushmoney = 0
if can_push
pushmoney = push_money(operator)
#这里可能会导致后续冲销流程断掉
# raise '余额不足' if pushmoney.zero?
end
if pushmoney.zero?
Expand Down
6 changes: 3 additions & 3 deletions app/models/house.rb
Expand Up @@ -72,7 +72,7 @@ def create_bill(day = Date.today, operator=nil)
#1、是否有业主、是否业主已收房
#2、查询本月是否已经生成账单,未生成则新建,否则追加
#3、循环收费项,根据收费项生成账单详细
return if !can_create_bill?
return if !can_create_bill?(day)
logger.info "开始计算#{self.house_code}#{day.year}#{day.month}月账单"
begin
Bill.transaction do
Expand Down Expand Up @@ -166,12 +166,12 @@ def create_bill(day = Date.today, operator=nil)

end

def can_create_bill?
def can_create_bill?(day = Date.today)
return false if owners.empty? || self.receive_time.nil?
result = true

#收房日期大于当月20号
today = Date.today
today = day

if today.month == self.receive_time.month && self.receive_time.day > 20
result = false
Expand Down
2 changes: 1 addition & 1 deletion app/models/notices_users.rb
Expand Up @@ -4,4 +4,4 @@ class NoticesUsers < ActiveRecord::Base

belongs_to :user
belongs_to :notice
end
end
4 changes: 2 additions & 2 deletions app/models/user_report.rb
Expand Up @@ -4,14 +4,14 @@ class UserReport < ActiveRecord::Base
belongs_to :charge
belongs_to :house

def self.find_by_user(start_time = nil, end_time = nil)
def self.find_by_user(start_time = nil, end_time = nil, plot_id)
sql = "select concat(min(trans_time),'~~~',max(trans_time)) trans_time,
operator,
sum(total_pay_money) total_pay_money,
sum(total_pre_money) total_pre_money
from (
select r.trans_time, item_id,operator,sum(pay_money) total_pay_money ,sum(pre_money) total_pre_money
from user_reports r where (pay_money>0 or pre_money>0) "
from user_reports r where (pay_money>0 or pre_money>0) and plot_id=#{plot_id} "
#params = {}
#if !start_time.nil?
# sql += " and t.trans_time >= :start_time"
Expand Down
10 changes: 7 additions & 3 deletions app/views/accounts/_form.html.erb
Expand Up @@ -27,8 +27,12 @@
alert("请填写正确的数量!");
}
if (!isNaN(unitPrice) && !isNaN(record)) {
money = unitPrice * record;
var result = confirm("你确定预存" + money + "元?");
money = parseFloat(unitPrice * record);
var _money = $("#money").val();
if (_money > money) {
money = _money;
}
var result = confirm("你确定预存" + money.toFixed(2) + "元?");
if (result) {
$("form").submit();
}
Expand All @@ -43,7 +47,7 @@
if (record != 0) {
$(this).removeAttr("style");
var money = parseFloat($("#unitPrice").val() * record);
$("#money").val(money);
$("#money").val(money.toFixed(2));
} else {
$(this).focus();
alert("请填写正确的数量!");
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/users/_form.html.erb
Expand Up @@ -32,7 +32,7 @@

<div class="controls">
<button id="btnSubmit" class="btn btn-primary">提交</button>
<%= link_to '返回', root_path, :class => 'btn' %>
<%= link_to '返回', users_path, :class => 'btn' %>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/bills/add_temporary.html.erb
Expand Up @@ -150,7 +150,7 @@
<label class="control-label">时间</label>

<div class="controls">
<%= text_field_tag 'charge_time', nil, :placeholder => '时间' %>
<%= text_field_tag 'charge_time', Date.today, :placeholder => '时间' %>
</div>
</div>
<div class="control-group">
Expand Down
13 changes: 12 additions & 1 deletion app/views/bills/index.html.erb
Expand Up @@ -11,6 +11,7 @@
</div>
<div class="input-append">
<%= form_tag(:controller => :bills, :action => :calculate) do %>
<input id="day" name="day" type="text" class="span2" style="margin-bottom: 0;" placeholder="账单月份"/>
<button type="submit" class="btn">计算小区当月账单</button>
<button type="button" class="btn"><i class="icon-remove"></i>批量删除</button>
<% end %>
Expand Down Expand Up @@ -62,4 +63,14 @@

</div>
</fieldset>

<script type="text/javascript">
$(document).ready(function () {
$("#day").datetimepicker({
format: 'yyyy-mm-dd',
minView: 'month',
autoclose: true,
todayBtn: true,
todayHighlight: true
});
});
</script>
6 changes: 5 additions & 1 deletion app/views/home/_common_button.erb
Expand Up @@ -25,11 +25,15 @@
<% if @current_user.has_privilege?('houses', 'add_house_charge') %>
<button class="btn" onclick="bindCharges()"><span></span>绑定收费项目</button>
<% end %>
<% if @current_user.has_privilege?('bills', 'destroy') %>
<button class="btn" onclick="delBill()"><span></span>删除收费账单</button>
<% end %>
</div>
</div>
<table id="house_base_info" class="table table-bordered table-condensed">
<thead>
<tr>
<th>ID</th>
<th>房号</th>
<th>业主</th>
<th>建筑面积</th>
Expand All @@ -38,7 +42,7 @@
</thead>
<tbody>
<tr>
<td colspan="4">数据准备</td>
<td colspan="5">数据准备</td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/_house_info.html.erb
Expand Up @@ -38,7 +38,7 @@
</thead>
<tbody>
<tr>
<td colspan="5">数据准备</td>
<td colspan="6">数据准备</td>
</tr>
</tbody>
</table>
Expand Down

0 comments on commit 4b82af8

Please sign in to comment.