added orders to confirm report / phone allows more digits now / added reports to rails admin navigation

This commit is contained in:
Senad Uka
2015-05-11 11:35:24 +02:00
parent 0490800ab3
commit fe452d359f
11 changed files with 661 additions and 19 deletions

View File

@@ -5,20 +5,20 @@ class Item < ActiveRecord::Base
belongs_to :supplier
belongs_to :brand
belongs_to :delivery_time_estimation
validates_presence_of :name, :description, :list_price, :current_input_price, :tags, :unit_id, :code, :sub_category_id, :weight, :supplier_id
def self.items_to_order
items_raw = Item.find_by_sql(%Q{
select s.id as supplier_id, i.code as code, i.name as name, sum(iic.count) amount, i.current_input_price
from carts c
left join item_in_carts iic on iic.cart_id = c.id
left join items i on i.id = iic.item_id
left join suppliers s on i.supplier_id = s.id
where c.confirmed and not (c.packed or c.delivered)
group by s.id, i.name, i.code, i.current_input_price
order by s.name, amount desc;
items_raw = Item.find_by_sql(%Q{
select s.id as supplier_id, i.code as code, i.name as name, sum(iic.count) amount, i.current_input_price
from carts c
left join item_in_carts iic on iic.cart_id = c.id
left join items i on i.id = iic.item_id
left join suppliers s on i.supplier_id = s.id
where c.confirmed and not (c.packed or c.delivered)
group by s.id, i.name, i.code, i.current_input_price
order by s.name, amount desc;
})
items_sorted = {}
@@ -35,6 +35,7 @@ class Item < ActiveRecord::Base
complete_sum = 0
suppliers_sorted.each_pair do |key, value|
rep_sec = OpenStruct.new # report section
rep_sec.supplier = value
rep_sec.items = items_sorted[key]
@@ -54,4 +55,46 @@ class Item < ActiveRecord::Base
end
def self.orders_to_confirm
items_raw = Item.find_by_sql(%Q{
select dd.*, c.id as order_id,i.code as code, i.name as item, iic.count as amount , i.list_price, iic.count * i.list_price as sum_price
from carts c
left join delivery_destinations dd on c.delivery_destination_id = dd.id
left join item_in_carts iic on iic.cart_id = c.id
left join items i on i.id = iic.item_id
where c.ordered and not(c.canceled_on_check or c.canceled_on_delivery or c.confirmed or c.packed or c.delivered)
order by
c.created_at, iic.created_at;
})
items_sorted = {}
items_raw.each do |item|
items_sorted[item.phone] ||= []
items_sorted[item.phone] << item
end
sections = []
complete_sum = 0
items_sorted.each_pair do |key,values|
section = OpenStruct.new
section.delivery_destination = values.first
section.sum_amount = 0
section.items = []
values.each do |item|
section.sum_amount += item.sum_price
complete_sum += item.sum_price
section.items << item
end
sections << section
end
full_report = OpenStruct.new
full_report.sections = sections
full_report.full_sum = complete_sum
return full_report
end
end