special offers backoffice is ready now
This commit is contained in:
8
back-office/app/controllers/reports_controller.rb
Normal file
8
back-office/app/controllers/reports_controller.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class ReportsController < ApplicationController
|
||||
|
||||
def items_to_order
|
||||
@items = Item.items_to_order
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
4
back-office/app/controllers/special_offers_controller.rb
Normal file
4
back-office/app/controllers/special_offers_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class SpecialOffersController < ApplicationController
|
||||
active_scaffold :"special_offer" do |conf|
|
||||
end
|
||||
end
|
||||
2
back-office/app/helpers/special_offers_helper.rb
Normal file
2
back-office/app/helpers/special_offers_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
module SpecialOffersHelper
|
||||
end
|
||||
@@ -3,8 +3,24 @@ class Item < ActiveRecord::Base
|
||||
has_many :multi_media_descriptions
|
||||
belongs_to :sub_category
|
||||
belongs_to :supplier
|
||||
belongs_to :special_offer
|
||||
|
||||
validates_presence_of :name, :description, :list_price, :current_input_price, :tags, :unit_id, :code, :sub_category_id, :weight, :supplier_id
|
||||
|
||||
|
||||
# todo build a front end in backoffice (rails)
|
||||
def self.items_to_order
|
||||
return Item.find_by_sql(%Q{
|
||||
select s.name as supplier, i.name as item, sum(iic.count) amount, i.current_input_price
|
||||
from carts c
|
||||
join item_in_carts iic on iic.cart_id = c.id
|
||||
join items i on i.id = iic.item_id
|
||||
join suppliers s on i.supplier_id = s.id
|
||||
where c.confirmed and not (c.packed or c.delivered)
|
||||
group by s.name, i.name, i.current_input_price
|
||||
order by s.name, amount desc;
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
16
back-office/app/models/special_offer.rb
Normal file
16
back-office/app/models/special_offer.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
class SpecialOffer < ActiveRecord::Base
|
||||
belongs_to :item
|
||||
belongs_to :category
|
||||
belongs_to :section
|
||||
belongs_to :sub_category
|
||||
has_many :items
|
||||
|
||||
validates_presence_of :beginning, :ending, :image_url
|
||||
validate :validate_beginning_before_ending
|
||||
|
||||
def validate_beginning_before_ending
|
||||
if beginning && ending
|
||||
errors.add(:ending, "End date must come after beginning date") if ending <= beginning
|
||||
end
|
||||
end
|
||||
end
|
||||
13
back-office/app/tabs/tabulous.rb
Normal file
13
back-office/app/tabs/tabulous.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
Tabulous.setup do
|
||||
tabs do
|
||||
|
||||
get_from_suppliers_tab do
|
||||
text { 'From suppliers' }
|
||||
link_path { '/' }
|
||||
visible_when { true }
|
||||
enabled_when { true }
|
||||
active_when { in_action('any').of_controller('pictures') }
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user