1 Commits

Author SHA1 Message Date
Senad Uka
19be6829f3 just sending files 2015-06-06 08:41:54 +02:00
3 changed files with 46 additions and 13 deletions

View File

@@ -7,5 +7,9 @@ class ReportsController < ApplicationController
def orders_to_confirm
@report = Item.orders_to_confirm
end
def orders_to_pack
@report = Item.orders_to_pack
end
end

View File

@@ -7,6 +7,7 @@ class Item < ActiveRecord::Base
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
@@ -57,7 +58,7 @@ class Item < ActiveRecord::Base
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
select dd.name + ' ' + dd.email + ' ' + dd.phone + ' ' + dd.address as dd_key , 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
@@ -67,28 +68,53 @@ class Item < ActiveRecord::Base
order by
c.created_at, iic.created_at;
})
return self.format_orders(items_raw)
end
def self.orders_to_pack
items_raw = Item.find_by_sql(%Q{
select dd.name + ' ' + dd.email + ' ' + dd.phone + ' ' + dd.address as dd_key, 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.confirmed and not(c.canceled_on_check or c.canceled_on_delivery or c.packed or c.delivered)
order by
c.created_at, iic.created_at;
})
return self.format_orders(items_raw)
end
private
def self.format_orders(items_raw)
items_sorted = {}
items_raw.each do |item|
items_sorted[item.phone] ||= []
items_sorted[item.phone] << item
items_sorted[item.dd_key] ||= {}
items_sorted[item.dd_key][item.order_id] ||= []
items_sorted[item.dd_key][item.order_id] << item
end
sections = []
complete_sum = 0
items_sorted.each_pair do |key,values|
items_sorted.each_pair do |key,values_hash|
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
section.orders = []
values_hash.each_pair do |vkey, values|
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
sections << section
end
full_report = OpenStruct.new
full_report.sections = sections
@@ -97,4 +123,5 @@ class Item < ActiveRecord::Base
return full_report
end
end

View File

@@ -1,3 +1,5 @@
<h1>Orders to confirm</h1>
<style type="text/css">
.tg {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
@@ -18,7 +20,7 @@
<div><%= section.delivery_destination.address %> </div>
<div><%= section.delivery_destination.place %> <%= Place.name_from_code(section.delivery_destination.place) %></div>
<div><%= section.delivery_destination.email %></div>
<div><strong><%= section.delivery_destinati on.phone %></strong></div>
<div><strong>+387 <%= section.delivery_destination.phone %></strong></div>
<% end %>