Compare commits
86 Commits
edos_stuff
...
migration_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19be6829f3 | ||
|
|
328067e78b | ||
|
|
28e81c27ed | ||
|
|
b5fdc6d173 | ||
|
|
2ddfcf2141 | ||
|
|
d358934a01 | ||
|
|
d5cef64cb6 | ||
|
|
a2ecdc5d63 | ||
|
|
ac41e8aef7 | ||
|
|
12f48ab0e7 | ||
|
|
db6dd6a1ab | ||
|
|
8bed4eb3f7 | ||
|
|
850e4a267c | ||
|
|
d23a4c0c0e | ||
|
|
458b67f185 | ||
|
|
e1be044fd9 | ||
|
|
c99bcbda7a | ||
|
|
16ff955c21 | ||
|
|
8e3f071ef3 | ||
|
|
6453b1b241 | ||
|
|
49dd10acbc | ||
|
|
fe452d359f | ||
|
|
0490800ab3 | ||
|
|
1f0e005723 | ||
|
|
c9949c444a | ||
|
|
e4536055df | ||
|
|
729393d88c | ||
|
|
ecbe58c626 | ||
|
|
a5836a428f | ||
|
|
9eb7690d2d | ||
|
|
0cdf57d4a9 | ||
|
|
2f809cfbcf | ||
|
|
79752fca47 | ||
|
|
195bee516b | ||
|
|
aafda1d187 | ||
|
|
269ad19e4f | ||
|
|
fc9f7496d2 | ||
|
|
19cdca76b1 | ||
|
|
f71ab5ea47 | ||
|
|
452a2cd5f4 | ||
|
|
96420fc547 | ||
|
|
9865cb5f0a | ||
|
|
ea2837bd00 | ||
|
|
8197104040 | ||
|
|
82f40de96b | ||
|
|
6da4e6c9fd | ||
|
|
670f58fcff | ||
|
|
5464ec5770 | ||
|
|
76d5fd7599 | ||
|
|
7c1eb2f4fd | ||
|
|
8e3557cf2e | ||
|
|
b3fc46633c | ||
|
|
7acf1a8d6c | ||
|
|
71fbde93de | ||
|
|
6c7a1b962f | ||
|
|
1e256f728d | ||
|
|
b90b4035aa | ||
|
|
d8668115ed | ||
|
|
5bc77597a4 | ||
|
|
b534d15866 | ||
|
|
0ff47313df | ||
|
|
e23bfe0a7f | ||
|
|
9154d216a2 | ||
|
|
bbedb4a877 | ||
|
|
38548e3e33 | ||
|
|
88c53a8512 | ||
|
|
fb080ed487 | ||
|
|
76379c4ae5 | ||
|
|
a7e40e579f | ||
|
|
bc10740780 | ||
|
|
69f5faffe4 | ||
|
|
4b019d6b9e | ||
|
|
1d16951fcf | ||
|
|
70635ebd1e | ||
|
|
a1b9250865 | ||
|
|
658fe4931d | ||
|
|
3b95500635 | ||
|
|
8815267a79 | ||
|
|
e7793f0884 | ||
|
|
0bafbb4b2f | ||
|
|
b2d4122940 | ||
|
|
648dee4636 | ||
|
|
e3abc09891 | ||
|
|
549424b903 | ||
|
|
f4e258cb82 | ||
|
|
e12c2b01d0 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@
|
|||||||
/back-office/log/*
|
/back-office/log/*
|
||||||
!/back-office/log/.keep
|
!/back-office/log/.keep
|
||||||
/back-office/tmp
|
/back-office/tmp
|
||||||
|
/back-office/import.log
|
||||||
*.gem
|
*.gem
|
||||||
*.rbc
|
*.rbc
|
||||||
/front-api/.config
|
/front-api/.config
|
||||||
|
|||||||
BIN
back-office/.DS_Store
vendored
BIN
back-office/.DS_Store
vendored
Binary file not shown.
@@ -31,6 +31,8 @@ gem 'puma'
|
|||||||
# for uploading images
|
# for uploading images
|
||||||
gem 'cloudinary'
|
gem 'cloudinary'
|
||||||
|
|
||||||
|
gem 'tabulous'
|
||||||
|
|
||||||
# Use ActiveModel has_secure_password
|
# Use ActiveModel has_secure_password
|
||||||
# gem 'bcrypt', '~> 3.1.7'
|
# gem 'bcrypt', '~> 3.1.7'
|
||||||
|
|
||||||
@@ -54,3 +56,4 @@ group :development, :test do
|
|||||||
gem 'spring'
|
gem 'spring'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
gem 'elasticsearch'
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
GIT
|
GIT
|
||||||
remote: git://github.com/activescaffold/active_scaffold.git
|
remote: git://github.com/activescaffold/active_scaffold.git
|
||||||
revision: 4693e8a3278702143b1668fb5f6317b1c4f90388
|
revision: 6f637d62c7b4eb7ae49a28f6b8c9b86997a326a3
|
||||||
branch: master
|
branch: master
|
||||||
specs:
|
specs:
|
||||||
active_scaffold (3.4.14)
|
active_scaffold (3.4.17)
|
||||||
rails (>= 3.2.18, < 5)
|
rails (>= 3.2.18, < 5)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
@@ -63,11 +63,22 @@ GEM
|
|||||||
coffee-script-source
|
coffee-script-source
|
||||||
execjs
|
execjs
|
||||||
coffee-script-source (1.8.0)
|
coffee-script-source (1.8.0)
|
||||||
|
colored (1.2)
|
||||||
columnize (0.9.0)
|
columnize (0.9.0)
|
||||||
debug_inspector (0.0.2)
|
debug_inspector (0.0.2)
|
||||||
debugger-linecache (1.2.0)
|
debugger-linecache (1.2.0)
|
||||||
|
elasticsearch (1.0.9)
|
||||||
|
elasticsearch-api (= 1.0.9)
|
||||||
|
elasticsearch-transport (= 1.0.9)
|
||||||
|
elasticsearch-api (1.0.9)
|
||||||
|
multi_json
|
||||||
|
elasticsearch-transport (1.0.9)
|
||||||
|
faraday
|
||||||
|
multi_json
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
execjs (2.2.2)
|
execjs (2.2.2)
|
||||||
|
faraday (0.9.1)
|
||||||
|
multipart-post (>= 1.2, < 3)
|
||||||
font-awesome-rails (4.3.0.0)
|
font-awesome-rails (4.3.0.0)
|
||||||
railties (>= 3.2, < 5.0)
|
railties (>= 3.2, < 5.0)
|
||||||
globalid (0.3.0)
|
globalid (0.3.0)
|
||||||
@@ -97,6 +108,7 @@ GEM
|
|||||||
mini_portile (0.6.2)
|
mini_portile (0.6.2)
|
||||||
minitest (5.5.1)
|
minitest (5.5.1)
|
||||||
multi_json (1.10.1)
|
multi_json (1.10.1)
|
||||||
|
multipart-post (2.0.0)
|
||||||
nested_form (0.3.2)
|
nested_form (0.3.2)
|
||||||
netrc (0.10.2)
|
netrc (0.10.2)
|
||||||
nokogiri (1.6.5)
|
nokogiri (1.6.5)
|
||||||
@@ -177,6 +189,9 @@ GEM
|
|||||||
actionpack (>= 3.0)
|
actionpack (>= 3.0)
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 3.0)
|
||||||
sprockets (>= 2.8, < 4.0)
|
sprockets (>= 2.8, < 4.0)
|
||||||
|
tabulous (2.1.3)
|
||||||
|
colored (~> 1.2.0)
|
||||||
|
rails (>= 3.0, < 5.0.0)
|
||||||
thor (0.19.1)
|
thor (0.19.1)
|
||||||
thread_safe (0.3.4)
|
thread_safe (0.3.4)
|
||||||
tilt (1.4.1)
|
tilt (1.4.1)
|
||||||
@@ -201,6 +216,7 @@ DEPENDENCIES
|
|||||||
byebug
|
byebug
|
||||||
cloudinary
|
cloudinary
|
||||||
coffee-rails (~> 4.1.0)
|
coffee-rails (~> 4.1.0)
|
||||||
|
elasticsearch
|
||||||
jbuilder (~> 2.0)
|
jbuilder (~> 2.0)
|
||||||
jquery-rails
|
jquery-rails
|
||||||
jquery-ui-rails
|
jquery-ui-rails
|
||||||
@@ -211,6 +227,7 @@ DEPENDENCIES
|
|||||||
sass-rails (~> 5.0)
|
sass-rails (~> 5.0)
|
||||||
sdoc (~> 0.4.0)
|
sdoc (~> 0.4.0)
|
||||||
spring
|
spring
|
||||||
|
tabulous
|
||||||
turbolinks
|
turbolinks
|
||||||
uglifier (>= 1.3.0)
|
uglifier (>= 1.3.0)
|
||||||
web-console (~> 2.0)
|
web-console (~> 2.0)
|
||||||
|
|||||||
BIN
back-office/app/assets/images/.DS_Store
vendored
BIN
back-office/app/assets/images/.DS_Store
vendored
Binary file not shown.
@@ -0,0 +1,4 @@
|
|||||||
|
class DeliveryTimeEstimationsController < ApplicationController
|
||||||
|
active_scaffold :"delivery_time_estimation" do |conf|
|
||||||
|
end
|
||||||
|
end
|
||||||
4
back-office/app/controllers/item_groups_controller.rb
Normal file
4
back-office/app/controllers/item_groups_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class ItemGroupsController < ApplicationController
|
||||||
|
active_scaffold :"item_group" do |conf|
|
||||||
|
end
|
||||||
|
end
|
||||||
4
back-office/app/controllers/item_in_groups_controller.rb
Normal file
4
back-office/app/controllers/item_in_groups_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class ItemInGroupsController < ApplicationController
|
||||||
|
active_scaffold :"item_in_group" do |conf|
|
||||||
|
end
|
||||||
|
end
|
||||||
4
back-office/app/controllers/link_banners_controller.rb
Normal file
4
back-office/app/controllers/link_banners_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class LinkBannersController < ApplicationController
|
||||||
|
active_scaffold :"link_banner" do |conf|
|
||||||
|
end
|
||||||
|
end
|
||||||
4
back-office/app/controllers/places_controller.rb
Normal file
4
back-office/app/controllers/places_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class PlacesController < ApplicationController
|
||||||
|
active_scaffold :"place" do |conf|
|
||||||
|
end
|
||||||
|
end
|
||||||
15
back-office/app/controllers/reports_controller.rb
Normal file
15
back-office/app/controllers/reports_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class ReportsController < ApplicationController
|
||||||
|
def items_to_order
|
||||||
|
@report = Item.items_to_order
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def orders_to_confirm
|
||||||
|
@report = Item.orders_to_confirm
|
||||||
|
end
|
||||||
|
|
||||||
|
def orders_to_pack
|
||||||
|
@report = Item.orders_to_pack
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
4
back-office/app/controllers/suppliers_controller.rb
Normal file
4
back-office/app/controllers/suppliers_controller.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class SuppliersController < ApplicationController
|
||||||
|
active_scaffold :"supplier" do |conf|
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
module DeliveryTimeEstimationsHelper
|
||||||
|
end
|
||||||
2
back-office/app/helpers/item_groups_helper.rb
Normal file
2
back-office/app/helpers/item_groups_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module ItemGroupsHelper
|
||||||
|
end
|
||||||
2
back-office/app/helpers/item_in_groups_helper.rb
Normal file
2
back-office/app/helpers/item_in_groups_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module ItemInGroupsHelper
|
||||||
|
end
|
||||||
2
back-office/app/helpers/link_banners_helper.rb
Normal file
2
back-office/app/helpers/link_banners_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module LinkBannersHelper
|
||||||
|
end
|
||||||
2
back-office/app/helpers/places_helper.rb
Normal file
2
back-office/app/helpers/places_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module PlacesHelper
|
||||||
|
end
|
||||||
2
back-office/app/helpers/suppliers_helper.rb
Normal file
2
back-office/app/helpers/suppliers_helper.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
module SuppliersHelper
|
||||||
|
end
|
||||||
3
back-office/app/models/brand.rb
Normal file
3
back-office/app/models/brand.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class Brand < ActiveRecord::Base
|
||||||
|
has_many :items
|
||||||
|
end
|
||||||
@@ -1,2 +1,10 @@
|
|||||||
class Cart < ActiveRecord::Base
|
class Cart < ActiveRecord::Base
|
||||||
|
|
||||||
|
has_many :item_in_carts
|
||||||
|
belongs_to :user
|
||||||
|
belongs_to :delivery_destination
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
2
back-office/app/models/delivery_time_estimation.rb
Normal file
2
back-office/app/models/delivery_time_estimation.rb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
class DeliveryTimeEstimation < ActiveRecord::Base
|
||||||
|
end
|
||||||
@@ -2,6 +2,126 @@ class Item < ActiveRecord::Base
|
|||||||
belongs_to :unit
|
belongs_to :unit
|
||||||
has_many :multi_media_descriptions
|
has_many :multi_media_descriptions
|
||||||
belongs_to :sub_category
|
belongs_to :sub_category
|
||||||
|
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_sorted = {}
|
||||||
|
suppliers_sorted = {}
|
||||||
|
|
||||||
|
items_raw.each do |item|
|
||||||
|
items_sorted[item.supplier_id] ||= []
|
||||||
|
suppliers_sorted[item.supplier_id] ||= item.supplier
|
||||||
|
items_sorted[item.supplier_id] << item
|
||||||
|
end
|
||||||
|
|
||||||
|
report_items = []
|
||||||
|
|
||||||
|
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]
|
||||||
|
rep_sec.sum_amount = rep_sec.items.reduce(0) do |sum, item|
|
||||||
|
sum + (item.current_input_price * item.amount)
|
||||||
|
end
|
||||||
|
complete_sum += rep_sec.sum_amount
|
||||||
|
|
||||||
|
report_items << rep_sec
|
||||||
|
end
|
||||||
|
|
||||||
|
full_report = OpenStruct.new
|
||||||
|
full_report.sections = report_items
|
||||||
|
full_report.full_sum = complete_sum
|
||||||
|
|
||||||
|
return full_report
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def self.orders_to_confirm
|
||||||
|
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.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;
|
||||||
|
})
|
||||||
|
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.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_hash|
|
||||||
|
section = OpenStruct.new
|
||||||
|
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
|
||||||
|
end
|
||||||
|
full_report = OpenStruct.new
|
||||||
|
full_report.sections = sections
|
||||||
|
full_report.full_sum = complete_sum
|
||||||
|
|
||||||
|
return full_report
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
validates_presence_of :name, :description, :list_price, :current_input_price, :tags, :unit_id, :code, :sub_category_id
|
|
||||||
end
|
end
|
||||||
|
|||||||
5
back-office/app/models/item_group.rb
Normal file
5
back-office/app/models/item_group.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
class ItemGroup < ActiveRecord::Base
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
@@ -5,4 +5,12 @@ class ItemInCart < ActiveRecord::Base
|
|||||||
validates_uniqueness_of :item_id, scope: :cart_id
|
validates_uniqueness_of :item_id, scope: :cart_id
|
||||||
validates :item_id, presence: true
|
validates :item_id, presence: true
|
||||||
validates :cart_id, presence: true
|
validates :cart_id, presence: true
|
||||||
|
|
||||||
|
def name
|
||||||
|
if item
|
||||||
|
item.name + " " + count.to_s + " " + price.to_s
|
||||||
|
else
|
||||||
|
" no item "
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
8
back-office/app/models/item_in_group.rb
Normal file
8
back-office/app/models/item_in_group.rb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
class ItemInGroup < ActiveRecord::Base
|
||||||
|
belongs_to :item_group
|
||||||
|
belongs_to :item
|
||||||
|
|
||||||
|
validates_presence_of :item_group_id
|
||||||
|
validates_presence_of :item_id
|
||||||
|
validates_presence_of :position
|
||||||
|
end
|
||||||
15
back-office/app/models/link_banner.rb
Normal file
15
back-office/app/models/link_banner.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class LinkBanner < ActiveRecord::Base
|
||||||
|
|
||||||
|
belongs_to :category
|
||||||
|
belongs_to :section
|
||||||
|
belongs_to :sub_category
|
||||||
|
|
||||||
|
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
|
||||||
3
back-office/app/models/menu_item.rb
Normal file
3
back-office/app/models/menu_item.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class MenuItem < ActiveRecord::Base
|
||||||
|
has_many :menu_sub_items
|
||||||
|
end
|
||||||
4
back-office/app/models/menu_sub_item.rb
Normal file
4
back-office/app/models/menu_sub_item.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
class MenuSubItem < ActiveRecord::Base
|
||||||
|
belongs_to :menu_item
|
||||||
|
has_many :menu_sub_sub_items
|
||||||
|
end
|
||||||
3
back-office/app/models/menu_sub_sub_item.rb
Normal file
3
back-office/app/models/menu_sub_sub_item.rb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
class MenuSubSubItem < ActiveRecord::Base
|
||||||
|
belongs_to :menu_sub_item
|
||||||
|
end
|
||||||
524
back-office/app/models/place.rb
Normal file
524
back-office/app/models/place.rb
Normal file
@@ -0,0 +1,524 @@
|
|||||||
|
class Place < ActiveRecord::Base
|
||||||
|
|
||||||
|
|
||||||
|
def self.name_from_code(code)
|
||||||
|
places_bulk = %Q{Aleksandrovac 78255
|
||||||
|
Avtovac 89245
|
||||||
|
Balatun 76310
|
||||||
|
Banja Luka 78000
|
||||||
|
Banovici 75290
|
||||||
|
Batkovic 76312
|
||||||
|
Begov Han 72233
|
||||||
|
Berkovici 88363
|
||||||
|
Bihac 77000
|
||||||
|
Bijela 76204
|
||||||
|
Bijeljina 76300
|
||||||
|
Bijelo Brdo 73263
|
||||||
|
Bileca 89230
|
||||||
|
Biljesevo 72248
|
||||||
|
Bjelimici 88407
|
||||||
|
Blagaj 88201
|
||||||
|
Blatnica 74275
|
||||||
|
Blatnica Kod Mostara 88263
|
||||||
|
Blazuj 71215
|
||||||
|
Bok 76277
|
||||||
|
Boljanic 74322
|
||||||
|
Bosanska Krupa 77240
|
||||||
|
Bosanski Petrovac 77250
|
||||||
|
Bosansko Grahovo 80270
|
||||||
|
Bradina 88408
|
||||||
|
Bratunac 75420
|
||||||
|
Brcko 76000
|
||||||
|
Brcko Distrikt 76100
|
||||||
|
Brekovica 77205
|
||||||
|
Brestovo 74210
|
||||||
|
Brestovsko 71255
|
||||||
|
Breza 71370
|
||||||
|
Brezicani 79208
|
||||||
|
Brezik 76109
|
||||||
|
Brezovo Polje 76216
|
||||||
|
Brijesnica 74206
|
||||||
|
Brijesnica Kod Doboja 74206
|
||||||
|
Brijesnica Mala 74206
|
||||||
|
Brijesnica Velika 74206
|
||||||
|
Brka 76206
|
||||||
|
Brnjic 72243
|
||||||
|
Brocanac 88243
|
||||||
|
Brocanac 88243
|
||||||
|
Brod Kod Foce 73309
|
||||||
|
Brodac 76313
|
||||||
|
Bronzani Majdan 78204
|
||||||
|
Bucici 72290
|
||||||
|
Bugojno 70230
|
||||||
|
Bukinje 75203
|
||||||
|
Buletic 74277
|
||||||
|
Buna 88202
|
||||||
|
Busovaca 72260
|
||||||
|
Buturovicpolje 88409
|
||||||
|
Buzim 77245
|
||||||
|
Cajnice 73280
|
||||||
|
Caparde 75405
|
||||||
|
Capljina 88300
|
||||||
|
Cardak 72224
|
||||||
|
Careva Cuprija 71347
|
||||||
|
Catici 72246
|
||||||
|
Cazin 77220
|
||||||
|
Cecava 74274
|
||||||
|
Celebici 88404
|
||||||
|
Celebici Lusnic 80203
|
||||||
|
Celebici Kod Foce 73307
|
||||||
|
Celic 75246
|
||||||
|
Celinac 78240
|
||||||
|
Cemerno 89243
|
||||||
|
Cerin 88265
|
||||||
|
Cerovica 74211
|
||||||
|
Cerovljani 78403
|
||||||
|
Citluk 88260
|
||||||
|
Coralici 77226
|
||||||
|
Crkvina 76239
|
||||||
|
Crnici 88367
|
||||||
|
Crnjelovo 76328
|
||||||
|
Dejcici 71221
|
||||||
|
Demirovac 79243
|
||||||
|
Derventa 74400
|
||||||
|
Derventa Kod Vlasenice 75444
|
||||||
|
Divin 89233
|
||||||
|
Doboj 74000
|
||||||
|
Doboj Istok 74206
|
||||||
|
Doboj Jug 74203
|
||||||
|
Doborovci 75328
|
||||||
|
Dobosnica 75308
|
||||||
|
Dobretici 77210
|
||||||
|
Dobrinja 71245
|
||||||
|
Dobrljin 79223
|
||||||
|
Dobro Selo 77242
|
||||||
|
Dobrun 73247
|
||||||
|
Dokanj 75206
|
||||||
|
Dolac Na Lasvi 72278
|
||||||
|
Domaljevac 76233
|
||||||
|
Domanovici 88305
|
||||||
|
Donja Mahala 76274
|
||||||
|
Donja Medjidja 76257
|
||||||
|
Donja Slatina 76327
|
||||||
|
Donje Mostre 71305
|
||||||
|
Donji Agici 79228
|
||||||
|
Donji Memici 88343
|
||||||
|
Donji Vakuf 70220
|
||||||
|
Donji Vijacani 78432
|
||||||
|
Donji Vrbljani 79289
|
||||||
|
Donji Zabar 76273
|
||||||
|
Dragaljevac 76323
|
||||||
|
Dragalovci 74209
|
||||||
|
Dragocaj 78215
|
||||||
|
Dreznica 88215
|
||||||
|
Drinjaca 75410
|
||||||
|
Drinovci 88344
|
||||||
|
Drvar 80260
|
||||||
|
Duboki Potok 75358
|
||||||
|
Dubostica 75308
|
||||||
|
Dubrave 78411
|
||||||
|
Dubrave Donje 75274
|
||||||
|
Dubrave Gornje 75273
|
||||||
|
Dubrovik 79227
|
||||||
|
Dugo Polje 74483
|
||||||
|
Djurdjevik 75272
|
||||||
|
Dusanovo 75445
|
||||||
|
Duzice 88342
|
||||||
|
Dvorovi 76311
|
||||||
|
Fajtovci 79264
|
||||||
|
Foca 73300
|
||||||
|
Fojnica 71270
|
||||||
|
Fojnica Kod Gacka 89247
|
||||||
|
Gabela Polje 88306
|
||||||
|
Gacko 89240
|
||||||
|
Glamoc 80230
|
||||||
|
Glavicice 76318
|
||||||
|
Globarica 72230
|
||||||
|
Gojevici 71275
|
||||||
|
Gorazde 73000
|
||||||
|
Gorica 88340
|
||||||
|
Gornja Koprivna 77222
|
||||||
|
Gornja Slatina 76238
|
||||||
|
Gornja Tuzla 75208
|
||||||
|
Gornji Kamengrad 79266
|
||||||
|
Gornji Podgradci 78405
|
||||||
|
Gornji Rahic 76207
|
||||||
|
Gornji Strpci 78439
|
||||||
|
Gornji Teslic 74272
|
||||||
|
Gornji Vakuf Uskoplje 70240
|
||||||
|
Gornji Zovik 76207
|
||||||
|
Grab 89201
|
||||||
|
Grabovica 78227
|
||||||
|
Gracanica 75320
|
||||||
|
Gracanica Kod Bugojna 70233
|
||||||
|
Gracanica Selo 75276
|
||||||
|
Gradac 88392
|
||||||
|
Gradacac 76250
|
||||||
|
Gradiska 78400
|
||||||
|
Grude 88340
|
||||||
|
Guber 80205
|
||||||
|
Listani 80204
|
||||||
|
Guca Gora 72277
|
||||||
|
Hadzici 71240
|
||||||
|
Hajdarevici 72225
|
||||||
|
Haljinici 72245
|
||||||
|
Han Bila 72281
|
||||||
|
Han Pijesak 71360
|
||||||
|
Hrasnica 71212
|
||||||
|
Hrasno 88395
|
||||||
|
Hresa 71144
|
||||||
|
Hrvacani 78436
|
||||||
|
Husino 75216
|
||||||
|
Hutovo 88394
|
||||||
|
Ilidza 71210
|
||||||
|
Ilijas 71380
|
||||||
|
Ilovaca 73208
|
||||||
|
Imljani 78234
|
||||||
|
Izacic 77208
|
||||||
|
Jablanica 88420
|
||||||
|
Jahorina 71423
|
||||||
|
Jajce 70101
|
||||||
|
Janja 76316
|
||||||
|
Janjici 72215
|
||||||
|
Jare 88224
|
||||||
|
Javorani 78233
|
||||||
|
Jelah 74264
|
||||||
|
Jezerski 77241
|
||||||
|
Johova 79244
|
||||||
|
Josanica 73319
|
||||||
|
Josavka 78244
|
||||||
|
Kacuni 72264
|
||||||
|
Kakanj 72240
|
||||||
|
Kalenderovci 74413
|
||||||
|
Kalesija 75260
|
||||||
|
Kalinovik 71230
|
||||||
|
Kamenica 77204
|
||||||
|
Kaonik 72265
|
||||||
|
Kasindo 71213
|
||||||
|
Kazaginac 80246
|
||||||
|
Kifino Selo 88283
|
||||||
|
Kiseljak 71250
|
||||||
|
Kiseljak, Kod Tuzle 75211
|
||||||
|
Kladanj 75280
|
||||||
|
Klakar Donji 74452
|
||||||
|
Kljuc 79280
|
||||||
|
Klobuk 88324
|
||||||
|
Klokotnica 74207
|
||||||
|
Knezevo 78230
|
||||||
|
Skender Vakuf 78230
|
||||||
|
Knezica 79246
|
||||||
|
Knezina 71356
|
||||||
|
Kobas 78423
|
||||||
|
Kocerin 88226
|
||||||
|
Kocicevo 78409
|
||||||
|
Kola 78207
|
||||||
|
Kongora 80244
|
||||||
|
Konjic 88400
|
||||||
|
Konjoder 77249
|
||||||
|
Koprivna 74489
|
||||||
|
Koraj 75247
|
||||||
|
Kornica 76236
|
||||||
|
Kosova 74253
|
||||||
|
Kostric 76276
|
||||||
|
Kotor Varos 78220
|
||||||
|
Kotorsko 74215
|
||||||
|
Kovaci 72226
|
||||||
|
Kozarac 79002
|
||||||
|
Bosanska Dubica 79240
|
||||||
|
Kozluk 75413
|
||||||
|
Kraljeva Sutjeska 72244
|
||||||
|
Kresevo 71260
|
||||||
|
Kriskovci 78256
|
||||||
|
Krupa Na Vrbasu 78206
|
||||||
|
Krusevo 88203
|
||||||
|
Kukulje 78424
|
||||||
|
Kula 71216
|
||||||
|
Kulasi 78443
|
||||||
|
Kulen Vakuf 77206
|
||||||
|
Kupres 80320
|
||||||
|
Laktasi 78250
|
||||||
|
Laminci Sredjani 78407
|
||||||
|
Lamovita 79204
|
||||||
|
Lastva 89208
|
||||||
|
Lasva 72216
|
||||||
|
Liplje 78222
|
||||||
|
Lipnica 75213
|
||||||
|
Lisnja 78434
|
||||||
|
Livno 80101
|
||||||
|
Ljubace 75214
|
||||||
|
Ljubija 79206
|
||||||
|
Ljubinje 88380
|
||||||
|
Ljubomir 89209
|
||||||
|
Ljubuski 88320
|
||||||
|
Ljuti Dolac 88223
|
||||||
|
Loncari 76278
|
||||||
|
Lopare 75240
|
||||||
|
Lukavac 75300
|
||||||
|
Lukavac Mjesto 75301
|
||||||
|
Lukavica 75327
|
||||||
|
Lusci Palanka 79267
|
||||||
|
Maglaj 74250
|
||||||
|
Majevac 74216
|
||||||
|
Mala Kladusa 77235
|
||||||
|
Mala Socanica 74418
|
||||||
|
Malesici 75320
|
||||||
|
Maoca 76208
|
||||||
|
Masici 78410
|
||||||
|
Maslovare 78223
|
||||||
|
Matici 76271
|
||||||
|
Matuzici 74203
|
||||||
|
Medjugorje 88266
|
||||||
|
Medjuvodje 79247
|
||||||
|
Mehurici 72282
|
||||||
|
Mesihovina 80243
|
||||||
|
Milici 75446
|
||||||
|
Miljeno 73283
|
||||||
|
Miljevina 73313
|
||||||
|
Milosevac 74485
|
||||||
|
Miricina 75329
|
||||||
|
Modrica 74480
|
||||||
|
Mokro 71428
|
||||||
|
Mosko 89204
|
||||||
|
Mostar 88000
|
||||||
|
Mostar, Jug 88000
|
||||||
|
Mostar, Jugozapad 88000
|
||||||
|
Mostar, Sjever 88000
|
||||||
|
Mostar, Zapad 88000
|
||||||
|
Mramor 75212
|
||||||
|
Mravinjac 73206
|
||||||
|
Mrkodol 79544
|
||||||
|
Mrkonjic Grad 70260
|
||||||
|
Nemila 72212
|
||||||
|
Neum 88390
|
||||||
|
Nevesinje 88280
|
||||||
|
Nova Bila 72276
|
||||||
|
Nova Topola 78418
|
||||||
|
Bosanski Novi 79220
|
||||||
|
Novi Seher 74254
|
||||||
|
Novi Travnik 72290
|
||||||
|
Nozicko 78428
|
||||||
|
Oborci 70225
|
||||||
|
Obudovac 76235
|
||||||
|
Odzak 76290
|
||||||
|
Vukosavlje 74470
|
||||||
|
Odzak Kod Nevesinja 88285
|
||||||
|
Olovo 71340
|
||||||
|
Omarska 79203
|
||||||
|
Orahova 78406
|
||||||
|
Orahovica Donja 75323
|
||||||
|
Orasje 76270
|
||||||
|
Osinja 74412
|
||||||
|
Osjecani 74225
|
||||||
|
Osmaci 75406
|
||||||
|
Ostra Luka 79263
|
||||||
|
Ostrozac 88423
|
||||||
|
Ostrozac Kod Cazina 77228
|
||||||
|
Otoka 77244
|
||||||
|
Ozimica 72238
|
||||||
|
Palackovci 78437
|
||||||
|
Pale 71420
|
||||||
|
Papraca 75435
|
||||||
|
Pazaric 71243
|
||||||
|
Pecigrad 77227
|
||||||
|
Pelagicevo 76256
|
||||||
|
Perin Han 72112
|
||||||
|
Petrovo 74317
|
||||||
|
Pilica 75412
|
||||||
|
Piskavica 78217
|
||||||
|
Pocitelj 88305
|
||||||
|
Poculica 72252
|
||||||
|
Podgrab 71425
|
||||||
|
Podhum 80209
|
||||||
|
Podlugovi 71387
|
||||||
|
Podnovlje 74217
|
||||||
|
Podorasje Kod Srebrenika 75355
|
||||||
|
Podzvizd 77232
|
||||||
|
Poljice 75303
|
||||||
|
Popovi 75320
|
||||||
|
Posusje 88240
|
||||||
|
Potkozarje 78216
|
||||||
|
Potocani 78435
|
||||||
|
Potoci 88208
|
||||||
|
Praca 73290
|
||||||
|
Prelovo 73245
|
||||||
|
Previja 79287
|
||||||
|
Pribinic 74276
|
||||||
|
Priboj Kod Lopara 75249
|
||||||
|
Prijedor 79101
|
||||||
|
Priluka 80202
|
||||||
|
Prisoje 80245
|
||||||
|
Prnjavor 78430
|
||||||
|
Prolog 80206
|
||||||
|
Prozor 88440
|
||||||
|
Prusac 70223
|
||||||
|
Przici 71335
|
||||||
|
Puhovac 72207
|
||||||
|
Puracic 75305
|
||||||
|
Radisici 88325
|
||||||
|
Rainci Gornji 75268
|
||||||
|
Rakitno 88245
|
||||||
|
Rakovica 71217
|
||||||
|
Rasko Polje 80247
|
||||||
|
Razboj Lijevce 78429
|
||||||
|
Razljevo 76218
|
||||||
|
Ribnik 79288
|
||||||
|
Ripac 77215
|
||||||
|
Rogatica 73220
|
||||||
|
Rudice 79226
|
||||||
|
Rudo 73260
|
||||||
|
Ruzici 88347
|
||||||
|
Bosanski Samac 76230
|
||||||
|
Sanica Gornja 79285
|
||||||
|
Sanski Most 79260
|
||||||
|
Sapna 75411
|
||||||
|
Saracica 78202
|
||||||
|
Sarajevo 71000
|
||||||
|
Sarajevo, Centar 71103
|
||||||
|
Sarajevo, Novi Grad 71160
|
||||||
|
Sarajevo, Novo Sarajevo 71120
|
||||||
|
Sarajevo, Stari Grad 71140
|
||||||
|
Satorovici 76209
|
||||||
|
Sekovici 73305
|
||||||
|
Sekovici 75450
|
||||||
|
Semizovac 71321
|
||||||
|
Seonjaci 76205
|
||||||
|
Serici 75275
|
||||||
|
Sibosnica 75245
|
||||||
|
Sibovska 78433
|
||||||
|
Simin Han 75207
|
||||||
|
Sipovo 78364
|
||||||
|
Siprage 78224
|
||||||
|
Siroki Brijeg 88220
|
||||||
|
Sitnesi 78422
|
||||||
|
Sitnica 79283
|
||||||
|
Skelani 75436
|
||||||
|
Skugric 74261
|
||||||
|
Sladna 75353
|
||||||
|
Slatina Ilidza 78253
|
||||||
|
Smrtici 78438
|
||||||
|
Snjegotina Gornja 74279
|
||||||
|
Sockovac 74323
|
||||||
|
Sokolac 71350
|
||||||
|
Sokolovici 71210
|
||||||
|
Sovici 88345
|
||||||
|
Spionica 75356
|
||||||
|
Srbac 78420
|
||||||
|
Srebrenica 75430
|
||||||
|
Srebrenik 75350
|
||||||
|
Srednje 71385
|
||||||
|
Sreflije 79249
|
||||||
|
Srnice 76258
|
||||||
|
Bosanska Kostajnica 79224
|
||||||
|
Bosanski Brod 74450
|
||||||
|
Istocno Gorazde 73110
|
||||||
|
Istocno Orasje 76278
|
||||||
|
Istocno Sarajevo 71123
|
||||||
|
Stanari 74208
|
||||||
|
Stara Dubrava 78243
|
||||||
|
Stari Majdan 79268
|
||||||
|
Stijena 77224
|
||||||
|
Stjenice 73223
|
||||||
|
Stjepan Polje 75324
|
||||||
|
Stolac 88360
|
||||||
|
Stranjani 72209
|
||||||
|
Stricici 78208
|
||||||
|
Strpci 75305
|
||||||
|
Studenci 88323
|
||||||
|
Stupari 75283
|
||||||
|
Sturlic 77223
|
||||||
|
Suho Polje 75344
|
||||||
|
Sujica 80249
|
||||||
|
Svodna 79229
|
||||||
|
Tarcin 71244
|
||||||
|
Teocak 75414
|
||||||
|
Tesanj 74260
|
||||||
|
Tesanjka 74266
|
||||||
|
Teslic 74270
|
||||||
|
Tihaljina 88348
|
||||||
|
Tinja 75357
|
||||||
|
Tisca 75455
|
||||||
|
Todorovo 77233
|
||||||
|
Tojsici 75265
|
||||||
|
Tolisa 76272
|
||||||
|
Tomina 79265
|
||||||
|
Tomislavgrad 80240
|
||||||
|
Topcic Polje 72213
|
||||||
|
Travnik 72270
|
||||||
|
Trebinja 88375
|
||||||
|
Trebinje 89000
|
||||||
|
Trn 78252
|
||||||
|
Trnava Donja 76335
|
||||||
|
Trnjaci 76310
|
||||||
|
Trnovo 71220
|
||||||
|
Trzacka Rastela 77225
|
||||||
|
Turbe 72283
|
||||||
|
Turija 75306
|
||||||
|
Turjak Kod Bosanske Gradiske 78404
|
||||||
|
Tuzla 75000
|
||||||
|
Ugljevik 76330
|
||||||
|
Ugodnovici 74278
|
||||||
|
Ulog 71233
|
||||||
|
Usora 74230
|
||||||
|
Ustikolina 73250
|
||||||
|
Uvac 73265
|
||||||
|
Vardiste 73249
|
||||||
|
Vares 71330
|
||||||
|
Varoska Rijeka 77245
|
||||||
|
Velika Bukovica 74213
|
||||||
|
Velika Gata 77207
|
||||||
|
Velika Kladusa 77230
|
||||||
|
Velika Obarska 76329
|
||||||
|
Vidosi 88208
|
||||||
|
Vidovice 76275
|
||||||
|
Vinac 70202
|
||||||
|
Vir Kod Posusja 88247
|
||||||
|
Visegrad 73240
|
||||||
|
Visici 88307
|
||||||
|
Visoko 71300
|
||||||
|
Vitez 72250
|
||||||
|
Vitina 88326
|
||||||
|
Vitkovci Donji 74265
|
||||||
|
Vitkovici 73205
|
||||||
|
Vlasenica 75440
|
||||||
|
Vogosca 71320
|
||||||
|
Vojkovici 71123
|
||||||
|
Voljevac 70246
|
||||||
|
Vozuca 72227
|
||||||
|
Vranjak 74488
|
||||||
|
Vrapcici 88113
|
||||||
|
Vrazici 75248
|
||||||
|
Vrbanja Kod Banja Luke 78211
|
||||||
|
Vrbanjci 78225
|
||||||
|
Vrbaska 78408
|
||||||
|
Vrnograc 77231
|
||||||
|
Vrsani 76325
|
||||||
|
Vrsta 77203
|
||||||
|
Vuckovci 76254
|
||||||
|
Vukosavlje 74470
|
||||||
|
Zabar Donji 76273
|
||||||
|
Zaborak 73287
|
||||||
|
Zabrdje 72220
|
||||||
|
Zabrdje 76333
|
||||||
|
Zabrdje Kod Kotor Varosi 78221
|
||||||
|
Zaluzani 78214
|
||||||
|
Zavidovici 72220
|
||||||
|
Zboriste 74451
|
||||||
|
Zelinja 76259
|
||||||
|
Zeljezno Polje 72236
|
||||||
|
Zenica 72000
|
||||||
|
Zepce 72230
|
||||||
|
Zitomislici 88268
|
||||||
|
Zivinice 75270
|
||||||
|
Zupca 71370
|
||||||
|
Zvornik 75400}
|
||||||
|
|
||||||
|
separator = /(.*)\s(\d{5})/
|
||||||
|
places = places_bulk.split("\n")
|
||||||
|
places.each do |place|
|
||||||
|
matches = separator.match(place)
|
||||||
|
return matches[1].strip if matches and matches[2] === code
|
||||||
|
end
|
||||||
|
|
||||||
|
return "<nepoznato mjesto>";
|
||||||
|
end
|
||||||
|
end
|
||||||
6
back-office/app/models/supplier.rb
Normal file
6
back-office/app/models/supplier.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class Supplier < ActiveRecord::Base
|
||||||
|
has_many :items
|
||||||
|
|
||||||
|
validates_uniqueness_of :name
|
||||||
|
validates_presence_of :name
|
||||||
|
end
|
||||||
10
back-office/app/models/user.rb
Normal file
10
back-office/app/models/user.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class User < ActiveRecord::Base
|
||||||
|
has_many :carts
|
||||||
|
|
||||||
|
validates_presence_of :first_name, :last_name, :password, :email, :password_confirmation
|
||||||
|
|
||||||
|
validates :email, :uniqueness => {:case_sensitive => false, :message => "Email already exists!"},
|
||||||
|
format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, message: "invalid email" }
|
||||||
|
|
||||||
|
validates :password, confirmation: true, length: { in:6..20, too_short: 'password needs to be at least 6 characters long' }
|
||||||
|
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
|
||||||
32
back-office/app/views/reports/items_to_order.html.erb
Normal file
32
back-office/app/views/reports/items_to_order.html.erb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<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;}
|
||||||
|
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
|
||||||
|
</style>
|
||||||
|
<div><%= "report is nil" if @report.nil? %></div>
|
||||||
|
<table class="tg">
|
||||||
|
<tr>
|
||||||
|
<th class="tg-031e">Code</th>
|
||||||
|
<th class="tg-031e">Item name</th>
|
||||||
|
<th class="tg-031e">Amount</th>
|
||||||
|
<th class="tg-031e">Price</th>
|
||||||
|
<th class="tg-031e">Total</th>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<% unless @report.nil? %>
|
||||||
|
<% @report.sections.each do |section| %>
|
||||||
|
<tr><td><%= section.supplier.name %></td></tr>
|
||||||
|
<% section.items.each do |item| %>
|
||||||
|
<tr>
|
||||||
|
<td class="tg-031e"><%= item.code %></td>
|
||||||
|
<td class="tg-031e"><%= item.name %></td>
|
||||||
|
<td class="tg-031e"><%= item.amount %></td>
|
||||||
|
<td class="tg-031e"><%= item.current_input_price %></td>
|
||||||
|
<td class="tg-031e"><%= item.current_input_price * item.amount %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<tr><td>Sub-total: <%= section.sum_amount %></td></tr>
|
||||||
|
<% end %>
|
||||||
|
<tr><td><strong>Total: <%= @report.full_sum %></strong> </td></tr>
|
||||||
|
<% end %>
|
||||||
|
</table>
|
||||||
63
back-office/app/views/reports/orders_to_confirm.html.erb
Normal file
63
back-office/app/views/reports/orders_to_confirm.html.erb
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<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;}
|
||||||
|
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
|
||||||
|
</style>
|
||||||
|
<div><%= "report is nil" if @report.nil? %></div>
|
||||||
|
|
||||||
|
|
||||||
|
<% unless @report.nil? %>
|
||||||
|
<% @report.sections.each do |section| %>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<% unless section.delivery_destination.nil? %>
|
||||||
|
<div><%= section.delivery_destination.name %></div>
|
||||||
|
<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>+387 <%= section.delivery_destination.phone %></strong></div>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
|
||||||
|
<table class="tg">
|
||||||
|
<tr>
|
||||||
|
<th class="tg-031e">Code</th>
|
||||||
|
<th class="tg-031e">Item name</th>
|
||||||
|
<th class="tg-031e">Amount</th>
|
||||||
|
<th class="tg-031e">Price</th>
|
||||||
|
<th class="tg-031e">Total</th>
|
||||||
|
</tr>
|
||||||
|
<% section.items.each do |item| %>
|
||||||
|
<tr>
|
||||||
|
<td class="tg-031e"><%= item.code %></td>
|
||||||
|
<td class="tg-031e"><%= item.name %></td>
|
||||||
|
<td class="tg-031e"><%= item.amount %></td>
|
||||||
|
<td class="tg-031e"><%= item.list_price %></td>
|
||||||
|
<td class="tg-031e"><%= item.sum_price %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<tr><td><strong>Total for cart: <%= section.sum_amount %></strong></td></tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div><a href="<%= rails_admin.edit_url(model_name: 'cart', id: section.delivery_destination.order_id.to_i)%>" >Update Order</a></div>
|
||||||
|
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<strong>Total: <%= @report.full_sum %></strong>
|
||||||
|
|
||||||
|
|
||||||
|
<% end %>
|
||||||
@@ -22,5 +22,8 @@ module Ribicabackoffice
|
|||||||
|
|
||||||
# Do not swallow errors in after_commit/after_rollback callbacks.
|
# Do not swallow errors in after_commit/after_rollback callbacks.
|
||||||
config.active_record.raise_in_transactional_callbacks = true
|
config.active_record.raise_in_transactional_callbacks = true
|
||||||
|
config.assets.precompile += %w(*.svg *.eot *.woff *.ttf *.gif *.png *.ico)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
86
back-office/config/dossier.yml
Normal file
86
back-office/config/dossier.yml
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# PostgreSQL. Versions 8.2 and up are supported.
|
||||||
|
#
|
||||||
|
# Install the pg driver:
|
||||||
|
# gem install pg
|
||||||
|
# On OS X with Homebrew:
|
||||||
|
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
|
||||||
|
# On OS X with MacPorts:
|
||||||
|
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
|
||||||
|
# On Windows:
|
||||||
|
# gem install pg
|
||||||
|
# Choose the win32 build.
|
||||||
|
# Install PostgreSQL and put its /bin directory on your path.
|
||||||
|
#
|
||||||
|
# Configure Using Gemfile
|
||||||
|
# gem 'pg'
|
||||||
|
#
|
||||||
|
default: &default
|
||||||
|
adapter: postgresql
|
||||||
|
encoding: unicode
|
||||||
|
# For details on connection pooling, see rails configuration guide
|
||||||
|
# http://guides.rubyonrails.org/configuring.html#database-pooling
|
||||||
|
pool: 5
|
||||||
|
|
||||||
|
development:
|
||||||
|
<<: *default
|
||||||
|
database: ribica
|
||||||
|
|
||||||
|
# The specified database role being used to connect to postgres.
|
||||||
|
# To create additional roles in postgres see `$ createuser --help`.
|
||||||
|
# When left blank, postgres will use the default role. This is
|
||||||
|
# the same name as the operating system user that initialized the database.
|
||||||
|
username: postgres
|
||||||
|
|
||||||
|
# The password associated with the postgres role (username).
|
||||||
|
password: testni_hamo2
|
||||||
|
|
||||||
|
# Connect on a TCP socket. Omitted by default since the client uses a
|
||||||
|
# domain socket that doesn't need configuration. Windows does not have
|
||||||
|
# domain sockets, so uncomment these lines.
|
||||||
|
host: localhost
|
||||||
|
|
||||||
|
# The TCP port the server listens on. Defaults to 5432.
|
||||||
|
# If your server runs on a different port number, change accordingly.
|
||||||
|
#port: 5432
|
||||||
|
|
||||||
|
# Schema search path. The server defaults to $user,public
|
||||||
|
#schema_search_path: myapp,sharedapp,public
|
||||||
|
|
||||||
|
# Minimum log levels, in increasing order:
|
||||||
|
# debug5, debug4, debug3, debug2, debug1,
|
||||||
|
# log, notice, warning, error, fatal, and panic
|
||||||
|
# Defaults to warning.
|
||||||
|
#min_messages: notice
|
||||||
|
|
||||||
|
# Warning: The database defined as "test" will be erased and
|
||||||
|
# re-generated from your development database when you run "rake".
|
||||||
|
# Do not set this db to the same as development or production.
|
||||||
|
test:
|
||||||
|
<<: *default
|
||||||
|
database: ribicabackoffice_test
|
||||||
|
|
||||||
|
# As with config/secrets.yml, you never want to store sensitive information,
|
||||||
|
# like your database password, in your source code. If your source code is
|
||||||
|
# ever seen by anyone, they now have access to your database.
|
||||||
|
#
|
||||||
|
# Instead, provide the password as a unix environment variable when you boot
|
||||||
|
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
|
||||||
|
# for a full rundown on how to provide these environment variables in a
|
||||||
|
# production deployment.
|
||||||
|
#
|
||||||
|
# On Heroku and other platform providers, you may have a full connection URL
|
||||||
|
# available as an environment variable. For example:
|
||||||
|
#
|
||||||
|
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
|
||||||
|
#
|
||||||
|
# You can use this database configuration with:
|
||||||
|
#
|
||||||
|
# production:
|
||||||
|
# url: <%= ENV['DATABASE_URL'] %>
|
||||||
|
#
|
||||||
|
production:
|
||||||
|
<<: *default
|
||||||
|
database: ribica
|
||||||
|
username: postgres
|
||||||
|
password: testni_hamo2
|
||||||
|
host: localhost
|
||||||
@@ -31,4 +31,9 @@ RailsAdmin.config do |config|
|
|||||||
# history_index
|
# history_index
|
||||||
# history_show
|
# history_show
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.navigation_static_links = {
|
||||||
|
'Orders to Confirm' => '../reports/orders_to_confirm',
|
||||||
|
'Items to Order' => '../reports/items_to_order'
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
|
|
||||||
|
resources :item_in_groups do as_routes end
|
||||||
|
resources :item_groups do as_routes end
|
||||||
|
resources :link_banners do as_routes end
|
||||||
|
resources :delivery_time_estimations do as_routes end
|
||||||
|
resources :suppliers do as_routes end
|
||||||
|
resources :places do as_routes end
|
||||||
resources :delivery_destinations do as_routes end
|
resources :delivery_destinations do as_routes end
|
||||||
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
|
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
|
||||||
resources :filter_criteria_values do as_routes end
|
resources :filter_criteria_values do as_routes end
|
||||||
@@ -13,6 +19,7 @@ Rails.application.routes.draw do
|
|||||||
resources :units do as_routes end
|
resources :units do as_routes end
|
||||||
resources :sub_categories do as_routes end
|
resources :sub_categories do as_routes end
|
||||||
resources :categories do as_routes end
|
resources :categories do as_routes end
|
||||||
|
get ':controller(/:action(/:id))'
|
||||||
# The priority is based upon order of creation: first created -> highest priority.
|
# The priority is based upon order of creation: first created -> highest priority.
|
||||||
# See how all your routes lay out with "rake routes".
|
# See how all your routes lay out with "rake routes".
|
||||||
|
|
||||||
|
|||||||
19
back-office/db/schema.rb
Normal file
19
back-office/db/schema.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# encoding: UTF-8
|
||||||
|
# This file is auto-generated from the current state of the database. Instead
|
||||||
|
# of editing this file, please use the migrations feature of Active Record to
|
||||||
|
# incrementally modify your database, and then regenerate this schema definition.
|
||||||
|
#
|
||||||
|
# Note that this schema.rb definition is the authoritative source for your
|
||||||
|
# database schema. If you need to create the application database on another
|
||||||
|
# system, you should be using db:schema:load, not running all the migrations
|
||||||
|
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||||
|
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||||
|
#
|
||||||
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
|
ActiveRecord::Schema.define(version: 0) do
|
||||||
|
|
||||||
|
# These are extensions that must be enabled in order to support this database
|
||||||
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
|
end
|
||||||
9
back-office/import_validate.log
Normal file
9
back-office/import_validate.log
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Logfile created on 2015-05-13 06:59:32 +0200 by logger.rb/47272
|
||||||
|
I, [2015-05-13T06:59:32.650998 #35530] INFO -- : Item import starting at 2015-05-13 06:59:32 +0200
|
||||||
|
I, [2015-05-13T06:59:32.651035 #35530] INFO -- : Will be importing items from /Users/senaduka/Downloads/items_for_import.csv
|
||||||
|
E, [2015-05-13T06:59:40.201578 #35530] ERROR -- : Could not import item on row number 608 (Dunjica), reason: Subcategory is missing!
|
||||||
|
I, [2015-05-13T06:59:45.758509 #35530] INFO -- : Rolling back because of errors
|
||||||
|
I, [2015-05-13T06:59:46.065723 #35530] INFO -- : Import done
|
||||||
|
I, [2015-05-13T07:00:24.402397 #35642] INFO -- : Item import starting at 2015-05-13 07:00:24 +0200
|
||||||
|
I, [2015-05-13T07:00:24.402456 #35642] INFO -- : Will be importing items from /Users/senaduka/Downloads/items_for_import.csv
|
||||||
|
I, [2015-05-13T07:00:37.829898 #35642] INFO -- : Import done
|
||||||
365
back-office/lib/tasks/ribica.rake
Normal file
365
back-office/lib/tasks/ribica.rake
Normal file
@@ -0,0 +1,365 @@
|
|||||||
|
require 'csv'
|
||||||
|
|
||||||
|
def get_column_lookup
|
||||||
|
columns = [
|
||||||
|
:name,
|
||||||
|
:name_on_ribica,
|
||||||
|
:picture,
|
||||||
|
:brand,
|
||||||
|
:code,
|
||||||
|
:current_input_price,
|
||||||
|
:list_price,
|
||||||
|
:units_in_pack,
|
||||||
|
:description,
|
||||||
|
:stock,
|
||||||
|
:on_display,
|
||||||
|
:tags,
|
||||||
|
:traits,
|
||||||
|
:weight,
|
||||||
|
:delivery_time_estimation,
|
||||||
|
|
||||||
|
:name_unit,
|
||||||
|
:short_name_unit,
|
||||||
|
:description_suffix_unit,
|
||||||
|
:number_of_pieces_suffix_unit,
|
||||||
|
|
||||||
|
:name_sub_category,
|
||||||
|
:order_sub_category,
|
||||||
|
|
||||||
|
:name_supplier,
|
||||||
|
:address_supplier,
|
||||||
|
:postal_code_supplier,
|
||||||
|
:town_supplier,
|
||||||
|
:phone_supplier,
|
||||||
|
:contact_person_supplier,
|
||||||
|
:email_supplier,
|
||||||
|
:note_supplier
|
||||||
|
]
|
||||||
|
|
||||||
|
columns.map.with_index { |x, i| [x, i] }.to_h
|
||||||
|
end
|
||||||
|
|
||||||
|
def lookup_delivery_time_estimation(row, lookup)
|
||||||
|
dte = DeliveryTimeEstimation.where(
|
||||||
|
duration_in_days: row[lookup[:delivery_time_estimation]]
|
||||||
|
).take
|
||||||
|
|
||||||
|
if dte.nil?
|
||||||
|
dte = DeliveryTimeEstimation.new
|
||||||
|
dte.duration_in_days = row[lookup[:delivery_time_estimation]]
|
||||||
|
dte.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
if dte.duration_in_days == 0
|
||||||
|
raise "Delivery time estimation input is missing or incorrect: #{dte.delivery_time_estimation}"
|
||||||
|
end
|
||||||
|
|
||||||
|
return dte
|
||||||
|
end
|
||||||
|
|
||||||
|
def lookup_unit(row, lookup)
|
||||||
|
unit = Unit.where(
|
||||||
|
name: row[lookup[:name_unit]],
|
||||||
|
short_name: row[lookup[:short_name_unit]],
|
||||||
|
description_suffix: row[lookup[:description_suffix_unit]],
|
||||||
|
number_of_pieces_suffix: row[lookup[:number_of_pieces_suffix_unit]]).take
|
||||||
|
|
||||||
|
if unit.nil?
|
||||||
|
new_unit = Unit.new
|
||||||
|
new_unit.name = row[lookup[:name_unit]]
|
||||||
|
new_unit.short_name = "kom" #row[lookup[:short_name_unit]]
|
||||||
|
new_unit.description_suffix = row[lookup[:description_suffix_unit]]
|
||||||
|
new_unit.number_of_pieces_suffix = row[lookup[:number_of_pieces_suffix_unit]]
|
||||||
|
new_unit.save!
|
||||||
|
new_unit
|
||||||
|
else
|
||||||
|
unit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def lookup_brand(row, lookup)
|
||||||
|
brand = Brand.find_by name: row[lookup[:brand]]
|
||||||
|
if brand.nil?
|
||||||
|
new_brand = Brand.new
|
||||||
|
new_brand.name = row[lookup[:brand]]
|
||||||
|
new_brand.save!
|
||||||
|
new_brand
|
||||||
|
else
|
||||||
|
brand
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def lookup_supplier(row, lookup)
|
||||||
|
supplier = Supplier.find_by name: row[lookup[:name_supplier]]
|
||||||
|
if supplier.nil?
|
||||||
|
new_supplier = Supplier.new
|
||||||
|
new_supplier.name = row[lookup[:name_supplier]]
|
||||||
|
new_supplier.address = row[lookup[:address_supplier]]
|
||||||
|
new_supplier.postal_code = row[lookup[:postal_code_supplier]]
|
||||||
|
new_supplier.town = row[lookup[:town_supplier]]
|
||||||
|
new_supplier.phone = row[lookup[:phone_supplier]]
|
||||||
|
new_supplier.contact_person = row[lookup[:contact_person_supplier]]
|
||||||
|
new_supplier.email = row[lookup[:email_supplier]]
|
||||||
|
new_supplier.note = row[lookup[:note_supplier]]
|
||||||
|
new_supplier.save!
|
||||||
|
new_supplier
|
||||||
|
else
|
||||||
|
supplier
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def resolve_subcategory(str)
|
||||||
|
raise "Subcategory is missing!" if str.nil?
|
||||||
|
|
||||||
|
parts = str.split(">").map{ |s| s.strip }
|
||||||
|
subcategory = parts[2]
|
||||||
|
category = parts[1]
|
||||||
|
section = parts[0]
|
||||||
|
|
||||||
|
if subcategory.to_s == '' || category.to_s == '' || section.to_s == ''
|
||||||
|
raise "Invalid subcategory : #{str}"
|
||||||
|
end
|
||||||
|
|
||||||
|
subcategory = subcategory.downcase
|
||||||
|
category = category.downcase
|
||||||
|
section = section.downcase
|
||||||
|
|
||||||
|
sc = SubCategory.eager_load(category: :section)
|
||||||
|
.where("lower(sub_categories.name) = '#{subcategory}' and lower(categories.name) = '#{category}' and lower(sections.name) = '#{section}'")
|
||||||
|
.take
|
||||||
|
|
||||||
|
return sc unless sc.nil?
|
||||||
|
|
||||||
|
section_in_db = Section.where("lower(name) = '#{section}'").take
|
||||||
|
if section_in_db.nil?
|
||||||
|
section_in_db = Section.new
|
||||||
|
section_in_db.name = section.capitalize
|
||||||
|
section_in_db.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
cat_in_db =
|
||||||
|
Category
|
||||||
|
.eager_load(:section)
|
||||||
|
.where("lower(categories.name) = '#{category}' and lower(sections.name) = '#{section}'")
|
||||||
|
.take
|
||||||
|
|
||||||
|
if cat_in_db.nil?
|
||||||
|
cat_in_db = Category.new
|
||||||
|
cat_in_db.name = category.capitalize
|
||||||
|
cat_in_db.section_id = section_in_db.id
|
||||||
|
cat_in_db.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
sub_cat_in_db =
|
||||||
|
SubCategory
|
||||||
|
.eager_load(:category)
|
||||||
|
.where("lower(sub_categories.name) = '#{subcategory}' and lower(categories.name) = '#{category}'")
|
||||||
|
.take
|
||||||
|
|
||||||
|
if sub_cat_in_db.nil?
|
||||||
|
sub_cat_in_db = SubCategory.new
|
||||||
|
sub_cat_in_db.name = subcategory.capitalize
|
||||||
|
sub_cat_in_db.category_id = cat_in_db.id
|
||||||
|
sub_cat_in_db.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
sub_cat_in_db
|
||||||
|
#item.sub_category.order = row[lookup[:order_sub_category]]
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_multimedia(item, row, index, logger, lookup)
|
||||||
|
multimedia = row[lookup[:picture]]
|
||||||
|
return if multimedia.to_s == ""
|
||||||
|
|
||||||
|
parts = multimedia.split(";").map{ |s| s.strip }
|
||||||
|
|
||||||
|
parts.each do |part|
|
||||||
|
mmd = MultiMediaDescription.new
|
||||||
|
|
||||||
|
if part != "" and not part.start_with? "https://"
|
||||||
|
raise "Invalid url for the image: #{part}"
|
||||||
|
end
|
||||||
|
|
||||||
|
mmd.url = part
|
||||||
|
item.multi_media_descriptions << mmd
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def import_single_item(row, index, logger)
|
||||||
|
succes = true
|
||||||
|
begin
|
||||||
|
lookup = get_column_lookup
|
||||||
|
code = row[lookup[:code]]
|
||||||
|
|
||||||
|
item = (Item.find_by code: code) || Item.new
|
||||||
|
item.name = row[lookup[:name_on_ribica]]
|
||||||
|
item.code = code
|
||||||
|
item.current_input_price = row[lookup[:current_input_price]] || 11.00
|
||||||
|
item.list_price = row[lookup[:list_price]] || 12.00
|
||||||
|
item.units_in_pack = row[lookup[:units_in_pack]]
|
||||||
|
item.description = row[lookup[:description]] || "default description"
|
||||||
|
item.stock = row[lookup[:stock]]
|
||||||
|
item.on_display = row[lookup[:on_display]]
|
||||||
|
item.tags = row[lookup[:tags]]
|
||||||
|
item.traits = row[lookup[:traits]]
|
||||||
|
item.weight = row[lookup[:weight]] || 1.0
|
||||||
|
item.delivery_time_estimation = lookup_delivery_time_estimation(row, lookup)
|
||||||
|
|
||||||
|
item.sub_category = resolve_subcategory(row[lookup[:name_sub_category]])
|
||||||
|
# todo multimedia, item groups
|
||||||
|
|
||||||
|
handle_multimedia(item, row, index, logger, lookup)
|
||||||
|
|
||||||
|
item.unit = lookup_unit(row, lookup)
|
||||||
|
item.supplier = lookup_supplier(row, lookup)
|
||||||
|
item.brand = lookup_brand(row, lookup)
|
||||||
|
item.save(validate: false)
|
||||||
|
# logger.info "Successfully imported item with on row position #{index}: #{row[lookup[:name_on_ribica]]}"
|
||||||
|
success = true
|
||||||
|
rescue Exception => e
|
||||||
|
logger.error "Could not import item on row number #{index} (#{row[lookup[:name_on_ribica]]}), reason: #{e}"
|
||||||
|
success = false
|
||||||
|
end
|
||||||
|
|
||||||
|
success
|
||||||
|
end
|
||||||
|
|
||||||
|
def trim_whitespace(row)
|
||||||
|
row.map! do |value|
|
||||||
|
trimmed = value.strip if not value.nil? # value.to_s.strip
|
||||||
|
# puts "trimming '#{value}' to '#{trimmed}'"
|
||||||
|
trimmed
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def do_import(validate_only)
|
||||||
|
begin
|
||||||
|
input_file = ENV['INPUT']
|
||||||
|
if input_file.to_s == ""
|
||||||
|
puts "Input file is missing! Please provide input file in form INPUT=somefile.csv"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
lookup = get_column_lookup
|
||||||
|
path = Rails.root.join(input_file)
|
||||||
|
|
||||||
|
log_filename = "import.log"
|
||||||
|
log_filename = "import_validate.log" if validate_only
|
||||||
|
|
||||||
|
logger = Logger.new(log_filename)
|
||||||
|
|
||||||
|
logger.info "Item import starting at #{Time.now}"
|
||||||
|
logger.info "Will be importing items from #{path}"
|
||||||
|
|
||||||
|
i = 1
|
||||||
|
should_rollback = false
|
||||||
|
Item.transaction do
|
||||||
|
CSV.foreach(path) do |row|
|
||||||
|
if i != 1
|
||||||
|
trim_whitespace(row)
|
||||||
|
if import_single_item(row, i, logger) == false
|
||||||
|
should_rollback = true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
i += 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if validate_only || should_rollback
|
||||||
|
if should_rollback
|
||||||
|
puts "Import failed, please check the import log file for error details."
|
||||||
|
logger.info "Rolling back because of errors"
|
||||||
|
end
|
||||||
|
|
||||||
|
raise ActiveRecord::Rollback
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
puts "Import failed, please check the import log file for error details."
|
||||||
|
logger.error "Error while importing: #{e}"
|
||||||
|
end
|
||||||
|
logger.info "Import done"
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace :ribica do
|
||||||
|
task copy_sections_to_menu: :environment do
|
||||||
|
Section.transaction do
|
||||||
|
Section.all.each do |section|
|
||||||
|
mi = MenuItem.new
|
||||||
|
mi.title = section.name
|
||||||
|
mi.url = "/sekcija/#{section.id}/#{section.name}"
|
||||||
|
mi.ordinal = section.order
|
||||||
|
|
||||||
|
section.categories.each do |category|
|
||||||
|
msi = MenuSubItem.new
|
||||||
|
msi.title = category.name
|
||||||
|
msi.url = "/sekcija/#{section.name}/kategorija/#{category.id}/#{category.name}"
|
||||||
|
msi.ordinal = section.order
|
||||||
|
mi.menu_sub_items << msi
|
||||||
|
|
||||||
|
category.sub_categories.each do |sub_category|
|
||||||
|
mssi = MenuSubSubItem.new
|
||||||
|
mssi.title = sub_category.name
|
||||||
|
mssi.url = "/podkategorija/#{sub_category.id}/#{sub_category.name}"
|
||||||
|
mssi.ordinal = sub_category.order
|
||||||
|
msi.menu_sub_sub_items << mssi
|
||||||
|
end
|
||||||
|
end
|
||||||
|
mi.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace :ribica do
|
||||||
|
task clear_database: :environment do
|
||||||
|
conn = ActiveRecord::Base.connection
|
||||||
|
|
||||||
|
tables = conn.execute("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';").map { |r| r["table_name"] }
|
||||||
|
tables.delete "schema_migrations"
|
||||||
|
tables.each { |t| conn.execute("TRUNCATE TABLE #{t}") }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace :ribica do
|
||||||
|
task validate_items: :environment do
|
||||||
|
do_import true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace :ribica do
|
||||||
|
task import_items: :environment do
|
||||||
|
do_import false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
namespace :ribica do
|
||||||
|
task reindex: :environment do
|
||||||
|
es_client = Elasticsearch::Client.new log: true
|
||||||
|
|
||||||
|
# first delete the index
|
||||||
|
begin
|
||||||
|
es_client.indices.delete index: 'ribica'
|
||||||
|
rescue
|
||||||
|
logger.warn "Ribica index could not be deleted. Continuing with indexing operation..."
|
||||||
|
end
|
||||||
|
|
||||||
|
# now index items
|
||||||
|
all_items = Item.includes(sub_category: { category: :section }).all.to_a
|
||||||
|
all_items.each do |item|
|
||||||
|
es_client.index index: 'ribica', type: 'items', id: item.id, body: {
|
||||||
|
title: 'Test',
|
||||||
|
name: item.name,
|
||||||
|
code: item.code,
|
||||||
|
description: item.description,
|
||||||
|
sub_category: item.sub_category.name,
|
||||||
|
category: item.sub_category.category.name,
|
||||||
|
section: item.sub_category.category.section.name,
|
||||||
|
brand: item.brand.name
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
puts "ok!"
|
||||||
|
end
|
||||||
|
end
|
||||||
BIN
back-office/public/.DS_Store
vendored
BIN
back-office/public/.DS_Store
vendored
Binary file not shown.
@@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class DeliveryTimeEstimationsControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@delivery_time_estimation = delivery_time_estimations(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:delivery_time_estimations)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create delivery_time_estimation" do
|
||||||
|
assert_difference('DeliveryTimeEstimation.count') do
|
||||||
|
post :create, delivery_time_estimation: { duration_in_days: @delivery_time_estimation.duration_in_days, name: @delivery_time_estimation.name }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to delivery_time_estimation_path(assigns(:delivery_time_estimation))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show delivery_time_estimation" do
|
||||||
|
get :show, id: @delivery_time_estimation
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @delivery_time_estimation
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update delivery_time_estimation" do
|
||||||
|
patch :update, id: @delivery_time_estimation, delivery_time_estimation: { duration_in_days: @delivery_time_estimation.duration_in_days, name: @delivery_time_estimation.name }
|
||||||
|
assert_redirected_to delivery_time_estimation_path(assigns(:delivery_time_estimation))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy delivery_time_estimation" do
|
||||||
|
assert_difference('DeliveryTimeEstimation.count', -1) do
|
||||||
|
delete :destroy, id: @delivery_time_estimation
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to delivery_time_estimations_path
|
||||||
|
end
|
||||||
|
end
|
||||||
49
back-office/test/controllers/item_groups_controller_test.rb
Normal file
49
back-office/test/controllers/item_groups_controller_test.rb
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ItemGroupsControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@item_group = item_groups(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:item_groups)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create item_group" do
|
||||||
|
assert_difference('ItemGroup.count') do
|
||||||
|
post :create, item_group: { description: @item_group.description, name: @item_group.name, visible: @item_group.visible }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to item_group_path(assigns(:item_group))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show item_group" do
|
||||||
|
get :show, id: @item_group
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @item_group
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update item_group" do
|
||||||
|
patch :update, id: @item_group, item_group: { description: @item_group.description, name: @item_group.name, visible: @item_group.visible }
|
||||||
|
assert_redirected_to item_group_path(assigns(:item_group))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy item_group" do
|
||||||
|
assert_difference('ItemGroup.count', -1) do
|
||||||
|
delete :destroy, id: @item_group
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to item_groups_path
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ItemInGroupsControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@item_in_group = item_in_groups(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:item_in_groups)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create item_in_group" do
|
||||||
|
assert_difference('ItemInGroup.count') do
|
||||||
|
post :create, item_in_group: { item_group_id: @item_in_group.item_group_id, item_id: @item_in_group.item_id, position: @item_in_group.position }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to item_in_group_path(assigns(:item_in_group))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show item_in_group" do
|
||||||
|
get :show, id: @item_in_group
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @item_in_group
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update item_in_group" do
|
||||||
|
patch :update, id: @item_in_group, item_in_group: { item_group_id: @item_in_group.item_group_id, item_id: @item_in_group.item_id, position: @item_in_group.position }
|
||||||
|
assert_redirected_to item_in_group_path(assigns(:item_in_group))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy item_in_group" do
|
||||||
|
assert_difference('ItemInGroup.count', -1) do
|
||||||
|
delete :destroy, id: @item_in_group
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to item_in_groups_path
|
||||||
|
end
|
||||||
|
end
|
||||||
49
back-office/test/controllers/link_banners_controller_test.rb
Normal file
49
back-office/test/controllers/link_banners_controller_test.rb
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class LinkBannersControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@link_banner = link_banners(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:link_banners)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create link_banner" do
|
||||||
|
assert_difference('LinkBanner.count') do
|
||||||
|
post :create, link_banner: { beginning: @link_banner.beginning, category_id: @link_banner.category_id, checkout_page: @link_banner.checkout_page, ending: @link_banner.ending, footer: @link_banner.footer, header: @link_banner.header, image_url: @link_banner.image_url, item_id: @link_banner.item_id, link_url: @link_banner.link_url, search_result_page: @link_banner.search_result_page, section_id: @link_banner.section_id, start_page: @link_banner.start_page, sub_category_id: @link_banner.sub_category_id, thank_you_page: @link_banner.thank_you_page }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to link_banner_path(assigns(:link_banner))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show link_banner" do
|
||||||
|
get :show, id: @link_banner
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @link_banner
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update link_banner" do
|
||||||
|
patch :update, id: @link_banner, link_banner: { beginning: @link_banner.beginning, category_id: @link_banner.category_id, checkout_page: @link_banner.checkout_page, ending: @link_banner.ending, footer: @link_banner.footer, header: @link_banner.header, image_url: @link_banner.image_url, item_id: @link_banner.item_id, link_url: @link_banner.link_url, search_result_page: @link_banner.search_result_page, section_id: @link_banner.section_id, start_page: @link_banner.start_page, sub_category_id: @link_banner.sub_category_id, thank_you_page: @link_banner.thank_you_page }
|
||||||
|
assert_redirected_to link_banner_path(assigns(:link_banner))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy link_banner" do
|
||||||
|
assert_difference('LinkBanner.count', -1) do
|
||||||
|
delete :destroy, id: @link_banner
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to link_banners_path
|
||||||
|
end
|
||||||
|
end
|
||||||
49
back-office/test/controllers/places_controller_test.rb
Normal file
49
back-office/test/controllers/places_controller_test.rb
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class PlacesControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@place = places(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:places)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create place" do
|
||||||
|
assert_difference('Place.count') do
|
||||||
|
post :create, place: { delivery_price: @place.delivery_price, name: @place.name, postal_code: @place.postal_code }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to place_path(assigns(:place))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show place" do
|
||||||
|
get :show, id: @place
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @place
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update place" do
|
||||||
|
patch :update, id: @place, place: { delivery_price: @place.delivery_price, name: @place.name, postal_code: @place.postal_code }
|
||||||
|
assert_redirected_to place_path(assigns(:place))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy place" do
|
||||||
|
assert_difference('Place.count', -1) do
|
||||||
|
delete :destroy, id: @place
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to places_path
|
||||||
|
end
|
||||||
|
end
|
||||||
49
back-office/test/controllers/suppliers_controller_test.rb
Normal file
49
back-office/test/controllers/suppliers_controller_test.rb
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SuppliersControllerTest < ActionController::TestCase
|
||||||
|
setup do
|
||||||
|
@supplier = suppliers(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get :index
|
||||||
|
assert_response :success
|
||||||
|
assert_not_nil assigns(:suppliers)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get :new
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create supplier" do
|
||||||
|
assert_difference('Supplier.count') do
|
||||||
|
post :create, supplier: { address: @supplier.address, contact_person: @supplier.contact_person, email: @supplier.email, name: @supplier.name, note: @supplier.note, phone: @supplier.phone, postal_code: @supplier.postal_code, town: @supplier.town }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to supplier_path(assigns(:supplier))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show supplier" do
|
||||||
|
get :show, id: @supplier
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get :edit, id: @supplier
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update supplier" do
|
||||||
|
patch :update, id: @supplier, supplier: { address: @supplier.address, contact_person: @supplier.contact_person, email: @supplier.email, name: @supplier.name, note: @supplier.note, phone: @supplier.phone, postal_code: @supplier.postal_code, town: @supplier.town }
|
||||||
|
assert_redirected_to supplier_path(assigns(:supplier))
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy supplier" do
|
||||||
|
assert_difference('Supplier.count', -1) do
|
||||||
|
delete :destroy, id: @supplier
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to suppliers_path
|
||||||
|
end
|
||||||
|
end
|
||||||
9
back-office/test/fixtures/delivery_time_estimations.yml
vendored
Normal file
9
back-office/test/fixtures/delivery_time_estimations.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: MyString
|
||||||
|
duration_in_days: 1
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: MyString
|
||||||
|
duration_in_days: 1
|
||||||
11
back-office/test/fixtures/item_groups.yml
vendored
Normal file
11
back-office/test/fixtures/item_groups.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: MyString
|
||||||
|
description: MyText
|
||||||
|
visible: false
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: MyString
|
||||||
|
description: MyText
|
||||||
|
visible: false
|
||||||
11
back-office/test/fixtures/item_in_groups.yml
vendored
Normal file
11
back-office/test/fixtures/item_in_groups.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
item_id: 1
|
||||||
|
item_group_id: 1
|
||||||
|
position: 1
|
||||||
|
|
||||||
|
two:
|
||||||
|
item_id: 1
|
||||||
|
item_group_id: 1
|
||||||
|
position: 1
|
||||||
33
back-office/test/fixtures/link_banners.yml
vendored
Normal file
33
back-office/test/fixtures/link_banners.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
image_url: MyString
|
||||||
|
start_page: false
|
||||||
|
section_id: 1
|
||||||
|
category_id: 1
|
||||||
|
sub_category_id: 1
|
||||||
|
item_id: 1
|
||||||
|
thank_you_page: false
|
||||||
|
search_result_page: false
|
||||||
|
checkout_page: false
|
||||||
|
beginning: 2015-03-22
|
||||||
|
ending: 2015-03-22
|
||||||
|
footer: false
|
||||||
|
header: false
|
||||||
|
link_url: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
image_url: MyString
|
||||||
|
start_page: false
|
||||||
|
section_id: 1
|
||||||
|
category_id: 1
|
||||||
|
sub_category_id: 1
|
||||||
|
item_id: 1
|
||||||
|
thank_you_page: false
|
||||||
|
search_result_page: false
|
||||||
|
checkout_page: false
|
||||||
|
beginning: 2015-03-22
|
||||||
|
ending: 2015-03-22
|
||||||
|
footer: false
|
||||||
|
header: false
|
||||||
|
link_url: MyString
|
||||||
11
back-office/test/fixtures/places.yml
vendored
Normal file
11
back-office/test/fixtures/places.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
postal_code: MyString
|
||||||
|
delivery_price: 9.99
|
||||||
|
name: MyString
|
||||||
|
|
||||||
|
two:
|
||||||
|
postal_code: MyString
|
||||||
|
delivery_price: 9.99
|
||||||
|
name: MyString
|
||||||
21
back-office/test/fixtures/suppliers.yml
vendored
Normal file
21
back-office/test/fixtures/suppliers.yml
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
name: MyString
|
||||||
|
address: MyString
|
||||||
|
postal_code: MyString
|
||||||
|
town: MyString
|
||||||
|
phone: MyString
|
||||||
|
contact_person: MyString
|
||||||
|
email: MyString
|
||||||
|
note: MyText
|
||||||
|
|
||||||
|
two:
|
||||||
|
name: MyString
|
||||||
|
address: MyString
|
||||||
|
postal_code: MyString
|
||||||
|
town: MyString
|
||||||
|
phone: MyString
|
||||||
|
contact_person: MyString
|
||||||
|
email: MyString
|
||||||
|
note: MyText
|
||||||
7
back-office/test/models/delivery_time_estimation_test.rb
Normal file
7
back-office/test/models/delivery_time_estimation_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class DeliveryTimeEstimationTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
back-office/test/models/item_group_test.rb
Normal file
7
back-office/test/models/item_group_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ItemGroupTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
back-office/test/models/item_in_group_test.rb
Normal file
7
back-office/test/models/item_in_group_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class ItemInGroupTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
back-office/test/models/link_banner_test.rb
Normal file
7
back-office/test/models/link_banner_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class LinkBannerTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
back-office/test/models/place_test.rb
Normal file
7
back-office/test/models/place_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class PlaceTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
7
back-office/test/models/supplier_test.rb
Normal file
7
back-office/test/models/supplier_test.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SupplierTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
BIN
front-api/.DS_Store
vendored
BIN
front-api/.DS_Store
vendored
Binary file not shown.
@@ -14,9 +14,10 @@ platform :ruby do
|
|||||||
gem "activerecord"
|
gem "activerecord"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
gem 'elasticsearch'
|
||||||
gem "sinatra"
|
gem "sinatra"
|
||||||
gem "sinatra-activerecord"
|
gem "sinatra-activerecord"
|
||||||
gem "json"
|
gem "json"
|
||||||
gem 'puma'
|
gem 'puma'
|
||||||
gem "sinatra-contrib"
|
gem "sinatra-contrib"
|
||||||
|
gem 'rerun'
|
||||||
|
|||||||
@@ -24,13 +24,34 @@ GEM
|
|||||||
bcrypt (3.1.10)
|
bcrypt (3.1.10)
|
||||||
bcrypt (3.1.10-java)
|
bcrypt (3.1.10-java)
|
||||||
builder (3.2.2)
|
builder (3.2.2)
|
||||||
|
celluloid (0.16.0)
|
||||||
|
timers (~> 4.0.0)
|
||||||
|
elasticsearch (1.0.8)
|
||||||
|
elasticsearch-api (= 1.0.7)
|
||||||
|
elasticsearch-transport (= 1.0.7)
|
||||||
|
elasticsearch-api (1.0.7)
|
||||||
|
multi_json
|
||||||
|
elasticsearch-transport (1.0.7)
|
||||||
|
faraday
|
||||||
|
multi_json
|
||||||
|
faraday (0.9.1)
|
||||||
|
multipart-post (>= 1.2, < 3)
|
||||||
|
ffi (1.9.6)
|
||||||
|
ffi (1.9.6-java)
|
||||||
|
hitimes (1.2.2)
|
||||||
|
hitimes (1.2.2-java)
|
||||||
i18n (0.7.0)
|
i18n (0.7.0)
|
||||||
jdbc-postgres (9.3.1102)
|
jdbc-postgres (9.3.1102)
|
||||||
jruby-openssl (0.9.6-java)
|
jruby-openssl (0.9.6-java)
|
||||||
json (1.8.1)
|
json (1.8.1)
|
||||||
json (1.8.1-java)
|
json (1.8.1-java)
|
||||||
|
listen (2.8.5)
|
||||||
|
celluloid (>= 0.15.2)
|
||||||
|
rb-fsevent (>= 0.9.3)
|
||||||
|
rb-inotify (>= 0.9)
|
||||||
minitest (5.5.0)
|
minitest (5.5.0)
|
||||||
multi_json (1.10.1)
|
multi_json (1.10.1)
|
||||||
|
multipart-post (2.0.0)
|
||||||
pg (0.17.1)
|
pg (0.17.1)
|
||||||
puma (2.10.2)
|
puma (2.10.2)
|
||||||
rack (>= 1.1, < 2.0)
|
rack (>= 1.1, < 2.0)
|
||||||
@@ -41,6 +62,11 @@ GEM
|
|||||||
rack
|
rack
|
||||||
rack-test (0.6.3)
|
rack-test (0.6.3)
|
||||||
rack (>= 1.0)
|
rack (>= 1.0)
|
||||||
|
rb-fsevent (0.9.4)
|
||||||
|
rb-inotify (0.9.5)
|
||||||
|
ffi (>= 0.5.0)
|
||||||
|
rerun (0.10.0)
|
||||||
|
listen (~> 2.7, >= 2.7.3)
|
||||||
sinatra (1.4.5)
|
sinatra (1.4.5)
|
||||||
rack (~> 1.4)
|
rack (~> 1.4)
|
||||||
rack-protection (~> 1.4)
|
rack-protection (~> 1.4)
|
||||||
@@ -58,6 +84,8 @@ GEM
|
|||||||
thread_safe (0.3.4)
|
thread_safe (0.3.4)
|
||||||
thread_safe (0.3.4-java)
|
thread_safe (0.3.4-java)
|
||||||
tilt (1.4.1)
|
tilt (1.4.1)
|
||||||
|
timers (4.0.1)
|
||||||
|
hitimes
|
||||||
tzinfo (1.2.2)
|
tzinfo (1.2.2)
|
||||||
thread_safe (~> 0.1)
|
thread_safe (~> 0.1)
|
||||||
|
|
||||||
@@ -69,10 +97,12 @@ DEPENDENCIES
|
|||||||
activerecord
|
activerecord
|
||||||
activerecord-jdbcpostgresql-adapter
|
activerecord-jdbcpostgresql-adapter
|
||||||
bcrypt (~> 3.1.7)
|
bcrypt (~> 3.1.7)
|
||||||
|
elasticsearch
|
||||||
jruby-openssl
|
jruby-openssl
|
||||||
json
|
json
|
||||||
pg
|
pg
|
||||||
puma
|
puma
|
||||||
|
rerun
|
||||||
sinatra
|
sinatra
|
||||||
sinatra-activerecord
|
sinatra-activerecord
|
||||||
sinatra-contrib
|
sinatra-contrib
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ require 'sinatra/activerecord'
|
|||||||
require './config'
|
require './config'
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'sinatra/cookies'
|
require 'sinatra/cookies'
|
||||||
|
require 'elasticsearch'
|
||||||
|
|
||||||
|
|
||||||
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
|
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
|
||||||
|
|
||||||
|
|||||||
@@ -1,29 +1,23 @@
|
|||||||
|
|
||||||
|
create_the_cart = -> () {
|
||||||
helpers do
|
|
||||||
def anonymous_id
|
|
||||||
auid = cookies[:anonymous_user_id]
|
|
||||||
if auid.nil?
|
|
||||||
auid = AnonymousUser.uid
|
|
||||||
response.set_cookie('anonymous_user_id', :path=> '/', :httponly => true, :value=>auid, :expires=> Time.now + 100.year)
|
|
||||||
end
|
|
||||||
return auid
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/cart' do
|
|
||||||
# -1 is a placeholder for user id when we implement users
|
# -1 is a placeholder for user id when we implement users
|
||||||
# auid will still be used in case user is not logged in
|
# auid will still be used in case user is not logged in
|
||||||
Cart.find_or_create(anonymous_id, -1).to_json
|
Cart.find_or_create(anonymous_id, logged_in_user_id).to_json
|
||||||
|
}
|
||||||
|
post '/cart', &create_the_cart
|
||||||
|
put '/cart', &create_the_cart
|
||||||
|
|
||||||
|
get '/cart' do
|
||||||
|
Cart.just_find(anonymous_id, logged_in_user_id).to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
# gets number of items in cart for every item
|
# gets number of items in cart for every item
|
||||||
get '/cart/item' do
|
get '/cart/item' do
|
||||||
Cart.find_or_create(anonymous_id, -1).item_in_carts.to_json
|
Cart.just_find(anonymous_id, logged_in_user_id).item_in_carts.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
update_cart_item = ->() {
|
update_cart_item = ->() {
|
||||||
cart_id = Cart.find_or_create(anonymous_id, -1).id
|
cart_id = Cart.just_find(anonymous_id, logged_in_user_id).id
|
||||||
item_id = @json_params["item_id"].to_i
|
item_id = @json_params["item_id"].to_i
|
||||||
count = @json_params["count"].to_i
|
count = @json_params["count"].to_i
|
||||||
ItemInCart.update_state(cart_id, item_id, count).to_json
|
ItemInCart.update_state(cart_id, item_id, count).to_json
|
||||||
@@ -33,23 +27,23 @@ post '/cart/item', &update_cart_item
|
|||||||
|
|
||||||
|
|
||||||
# gets list of items in cart without count
|
# gets list of items in cart without count
|
||||||
get '/cart/item/display' do
|
get '/cart/item/display' do
|
||||||
cart = Cart.find_or_create(anonymous_id, -1)
|
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
||||||
item_ids = cart.item_in_carts.map do |x|
|
item_ids = cart.item_in_carts.map do |x|
|
||||||
x.item_id
|
x.item_id
|
||||||
end
|
end
|
||||||
items = []
|
items = []
|
||||||
items = Item.find(item_ids) if cart.item_in_carts.length > 0
|
items = Item.find(item_ids) if cart.item_in_carts.length > 0
|
||||||
prepare_items_for_mass_display(items)
|
prepare_items_for_mass_display(items)
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/cart/delivery_destination' do
|
get '/cart/delivery_destination' do
|
||||||
cart = Cart.find_or_create(anonymous_id, -1)
|
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
||||||
cart.delivery_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
|
cart.delivery_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
|
||||||
end
|
end
|
||||||
|
|
||||||
update_delivery_destination = ->() {
|
update_delivery_destination = ->() {
|
||||||
cart = Cart.find_or_create(anonymous_id, -1)
|
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
||||||
allowed_keys = ["name", "address", "place", "postal_code", "phone", "email", "note"]
|
allowed_keys = ["name", "address", "place", "postal_code", "phone", "email", "note"]
|
||||||
params = @json_params.reject { |key,_| !allowed_keys.include?(key) }
|
params = @json_params.reject { |key,_| !allowed_keys.include?(key) }
|
||||||
cart.delivery_destination.update_attributes(params)
|
cart.delivery_destination.update_attributes(params)
|
||||||
@@ -60,11 +54,15 @@ put '/cart/delivery_destination', &update_delivery_destination
|
|||||||
post '/cart/delivery_destination', &update_delivery_destination
|
post '/cart/delivery_destination', &update_delivery_destination
|
||||||
|
|
||||||
|
|
||||||
post '/cart/confirmation' do
|
post '/cart/confirmation' do
|
||||||
cart = Cart.find_or_create(anonymous_id, -1)
|
anonymous = anonymous_id
|
||||||
|
cart = Cart.just_find(anonymous, logged_in_user_id)
|
||||||
if cart.item_in_carts.length > 0
|
if cart.item_in_carts.length > 0
|
||||||
cart.ordered = true
|
cart.ordered = true
|
||||||
cart.save!
|
cart.save!
|
||||||
end
|
end
|
||||||
|
# since there is no more ordered cart this needs to be done
|
||||||
|
# in order for next call of Cart#just_find to be ready
|
||||||
|
Cart.find_or_create(anonymous, logged_in_user_id)
|
||||||
"OK".to_json
|
"OK".to_json
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
|
|
||||||
get '/category' do
|
get '/category' do
|
||||||
Category.order(:name).all.to_json(:include => [:section, :sub_categories, :filter_criterias =>{:include => :filter_criteria_values} ])
|
Category.eager_load(:sub_categories).order('categories.order, sub_categories.order').all.to_json(:include => [:section, :sub_categories, :filter_criterias =>{:include => :filter_criteria_values} ])
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/category/:id' do
|
get '/category/:id' do
|
||||||
id = params[:id].to_i
|
id = params[:id].to_i
|
||||||
Category.find(id).to_json(:include => [:section, :sub_categories, :filter_criterias =>{:include => :filter_criteria_values}])
|
Category.eager_load(:sub_categories).order('sub_categories.order').find(id).to_json(:include => [:section, :sub_categories, :filter_criterias =>{:include => :filter_criteria_values}])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
def prepare_items_for_mass_display(items)
|
def prepare_items_for_mass_display(items)
|
||||||
items.to_json(
|
items.to_json(
|
||||||
:except => [:created_at, :current_input_price, :stock, :on_display],
|
:except => [:created_at, :current_input_price, :stock, :on_display],
|
||||||
:include => [
|
:include => [
|
||||||
:unit ,
|
:unit ,
|
||||||
:multi_media_descriptions ,
|
:multi_media_descriptions ,
|
||||||
:sub_category
|
:sub_category,
|
||||||
|
:brand
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
# gets single item for detailed display (like comments etc. ) # TODO: change when comments are added
|
# gets single item for detailed display (like comments etc. ) # TODO: change when comments are added
|
||||||
get '/item/:id' do |id_s|
|
get '/item/:id' do |id_s|
|
||||||
item = Item.find(id_s.to_i)
|
item = Item.find(id_s.to_i)
|
||||||
prepare_items_for_mass_display(item)
|
prepare_items_for_mass_display(item)
|
||||||
end
|
end
|
||||||
@@ -31,7 +32,7 @@ end
|
|||||||
get '/item/offset/:offset/limit/:limit' do |offset_s, limit_s|
|
get '/item/offset/:offset/limit/:limit' do |offset_s, limit_s|
|
||||||
offset, limit = mass_to_i(offset_s, limit_s)
|
offset, limit = mass_to_i(offset_s, limit_s)
|
||||||
return [].to_json if offset_and_limit_invalid?(offset,limit)
|
return [].to_json if offset_and_limit_invalid?(offset,limit)
|
||||||
|
|
||||||
items = Item.best_selling(offset,limit)
|
items = Item.best_selling(offset,limit)
|
||||||
prepare_items_for_mass_display(items)
|
prepare_items_for_mass_display(items)
|
||||||
end
|
end
|
||||||
@@ -41,8 +42,8 @@ end
|
|||||||
get '/item/section/:section_id/offset/:offset/limit/:limit' do |section_id_s, offset_s, limit_s|
|
get '/item/section/:section_id/offset/:offset/limit/:limit' do |section_id_s, offset_s, limit_s|
|
||||||
section_id, offset, limit = mass_to_i(section_id_s, offset_s, limit_s)
|
section_id, offset, limit = mass_to_i(section_id_s, offset_s, limit_s)
|
||||||
input_invalid = offset_and_limit_invalid?(offset,limit) or section_id <= 0
|
input_invalid = offset_and_limit_invalid?(offset,limit) or section_id <= 0
|
||||||
return [].to_json if input_invalid
|
return [].to_json if input_invalid
|
||||||
|
|
||||||
items = Item.best_selling_in_section(section_id, offset, limit)
|
items = Item.best_selling_in_section(section_id, offset, limit)
|
||||||
prepare_items_for_mass_display(items)
|
prepare_items_for_mass_display(items)
|
||||||
end
|
end
|
||||||
@@ -52,7 +53,7 @@ end
|
|||||||
get '/item/category/:category_id/offset/:offset/limit/:limit' do |category_id_s, offset_s, limit_s|
|
get '/item/category/:category_id/offset/:offset/limit/:limit' do |category_id_s, offset_s, limit_s|
|
||||||
category_id, offset, limit = mass_to_i(category_id_s, offset_s, limit_s)
|
category_id, offset, limit = mass_to_i(category_id_s, offset_s, limit_s)
|
||||||
input_invalid = offset_and_limit_invalid?(offset,limit) or category_id <= 0
|
input_invalid = offset_and_limit_invalid?(offset,limit) or category_id <= 0
|
||||||
return [].to_json if input_invalid
|
return [].to_json if input_invalid
|
||||||
|
|
||||||
all_in_cat = filter_by_traits(Item.all_in_category(category_id))
|
all_in_cat = filter_by_traits(Item.all_in_category(category_id))
|
||||||
items = Item.best_selling_in_category(category_id, offset,limit)
|
items = Item.best_selling_in_category(category_id, offset,limit)
|
||||||
@@ -65,21 +66,41 @@ end
|
|||||||
|
|
||||||
# gets items in sub category ( useful for page showing single sub_category )
|
# gets items in sub category ( useful for page showing single sub_category )
|
||||||
get '/item/sub_category/:sub_category_id/offset/:offset/limit/:limit' do |sub_category_id_s, offset_s, limit_s|
|
get '/item/sub_category/:sub_category_id/offset/:offset/limit/:limit' do |sub_category_id_s, offset_s, limit_s|
|
||||||
|
|
||||||
sub_category_id, offset, limit = mass_to_i(sub_category_id_s, offset_s, limit_s)
|
sub_category_id, offset, limit = mass_to_i(sub_category_id_s, offset_s, limit_s)
|
||||||
input_invalid = offset_and_limit_invalid?(offset,limit) or sub_category_id <= 0
|
input_invalid = offset_and_limit_invalid?(offset,limit) or sub_category_id <= 0
|
||||||
return [].to_json if input_invalid
|
return [].to_json if input_invalid
|
||||||
|
|
||||||
|
all_in_sub_cat = filter_by_traits(Item.all_in_sub_category(sub_category_id))
|
||||||
|
|
||||||
items = Item.best_selling_in_sub_category(sub_category_id, offset, limit)
|
items = Item.best_selling_in_sub_category(sub_category_id, offset, limit)
|
||||||
|
items = filter_by_traits(items)
|
||||||
|
|
||||||
|
add_total_count_header(all_in_sub_cat.count)
|
||||||
|
|
||||||
prepare_items_for_mass_display(items)
|
prepare_items_for_mass_display(items)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# gets list of items in cart without count
|
# gets list of items in cart without count
|
||||||
get '/cart/item_details' do
|
get '/cart/item_details' do
|
||||||
cart = Cart.find_or_create(anonymous_id, -1)
|
cart = Cart.find_or_create(anonymous_id, -1)
|
||||||
item_ids = cart.item_in_carts.map do |x|
|
item_ids = cart.item_in_carts.map do |x|
|
||||||
x.item_id
|
x.item_id
|
||||||
end
|
end
|
||||||
items = []
|
items = []
|
||||||
items = Item.find(item_ids) if cart.item_in_carts.length > 0
|
items = Item.find(item_ids) if cart.item_in_carts.length > 0
|
||||||
prepare_items_for_mass_display(items)
|
prepare_items_for_mass_display(items)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# gets items in sub category ( useful for page showing single sub_category )
|
||||||
|
get '/item/item_group/:item_group_id/offset/:offset/limit/:limit' do |item_group_id_s, offset_s, limit_s|
|
||||||
|
item_group_id, offset, limit = mass_to_i(item_group_id_s, offset_s, limit_s)
|
||||||
|
input_invalid = offset_and_limit_invalid?(offset,limit) or item_group_id <= 0
|
||||||
|
return [].to_json if input_invalid
|
||||||
|
|
||||||
|
items = ItemGroup.find_by_id(item_group_id)
|
||||||
|
return [].to_json if items.nil?
|
||||||
|
prepare_items_for_mass_display(items.all_items(offset, limit))
|
||||||
|
end
|
||||||
|
|||||||
6
front-api/controllers/link_banner.rb
Normal file
6
front-api/controllers/link_banner.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
get '/link_banner' do
|
||||||
|
LinkBanner.all.to_json
|
||||||
|
end
|
||||||
|
|
||||||
6
front-api/controllers/menu_item.rb
Normal file
6
front-api/controllers/menu_item.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
get '/menuitem' do
|
||||||
|
# list all menu items
|
||||||
|
MenuItem.eager_load(menu_sub_items: :menu_sub_sub_items)
|
||||||
|
.order("menu_items.ordinal, menu_sub_items.ordinal, menu_sub_sub_items.ordinal")
|
||||||
|
.to_json(:include => [:menu_sub_items => {:include => :menu_sub_sub_items}])
|
||||||
|
end
|
||||||
5
front-api/controllers/place.rb
Normal file
5
front-api/controllers/place.rb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
get '/place/:postal_code' do
|
||||||
|
Place.by_code_or_default(params["postal_code"]).to_json
|
||||||
|
end
|
||||||
35
front-api/controllers/search.rb
Normal file
35
front-api/controllers/search.rb
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
get '/search' do
|
||||||
|
es_client = Elasticsearch::Client.new log: true
|
||||||
|
q = params[:q]
|
||||||
|
|
||||||
|
# for now we do the basic query
|
||||||
|
results = es_client.search index: 'ribica', type: 'items', body: { query: { match: { _all: q } } }
|
||||||
|
ids = results["hits"]["hits"].map do |r|
|
||||||
|
r["_id"]
|
||||||
|
end
|
||||||
|
|
||||||
|
ids_with_score = {}
|
||||||
|
results["hits"]["hits"].each do |r|
|
||||||
|
ids_with_score[r["_id"].to_i] = {:score => r["_score"], :item => nil}
|
||||||
|
end
|
||||||
|
|
||||||
|
if ids.length > 0
|
||||||
|
res = Item.where(:id => ids).to_a
|
||||||
|
# make sure we have correct relevance order, since `where in` does not guarantee order
|
||||||
|
res.each do |ii|
|
||||||
|
ids_with_score[ii.id][:item] = ii
|
||||||
|
end
|
||||||
|
final = []
|
||||||
|
ids_with_score.each do |k,v|
|
||||||
|
final << v
|
||||||
|
end
|
||||||
|
final.sort_by! {|v| -v[:score]}
|
||||||
|
|
||||||
|
final = final.map do |f|
|
||||||
|
f[:item]
|
||||||
|
end
|
||||||
|
prepare_items_for_mass_display(final)
|
||||||
|
else
|
||||||
|
[].to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
get '/section' do
|
get '/section' do
|
||||||
Section.order(:name).all.to_json(:include =>
|
Section.eager_load(:categories).order('sections.order, categories.order').to_json(:include => :categories)
|
||||||
[:categories => { :include => :sub_categories }])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/section/:id' do
|
get '/section/:id' do
|
||||||
Section.find(params[:id].to_i).to_json(:include => [
|
Section.eager_load(categories: :sub_categories).order('categories.order, sub_categories.order').find(params[:id].to_i).to_json(:include => [:categories => {:include => :sub_categories}])
|
||||||
:categories => { :include => :sub_categories } ])
|
|
||||||
end
|
end
|
||||||
|
|||||||
18
front-api/controllers/sub_category.rb
Normal file
18
front-api/controllers/sub_category.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
get '/subcategory' do
|
||||||
|
SubCategory
|
||||||
|
.eager_load(category: :section)
|
||||||
|
.order(:order)
|
||||||
|
.all
|
||||||
|
.to_json(:include => [filter_criterias: {include: :filter_criteria_values}, category: {include: :section} ])
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/subcategory/:id' do
|
||||||
|
id = params[:id].to_i
|
||||||
|
|
||||||
|
SubCategory
|
||||||
|
.eager_load(category: :section)
|
||||||
|
.order(:order)
|
||||||
|
.find(id)
|
||||||
|
.to_json(:include => [filter_criterias: {include: :filter_criteria_values}, category: {include: :section} ])
|
||||||
|
end
|
||||||
@@ -1,4 +1,22 @@
|
|||||||
|
|
||||||
|
helpers do
|
||||||
|
def logged_in_user_id
|
||||||
|
auth = cookies['ribica_auth']
|
||||||
|
auth ||= -1
|
||||||
|
return auth.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def anonymous_id
|
||||||
|
auid = cookies[:anonymous_user_id]
|
||||||
|
if auid.nil?
|
||||||
|
auid = AnonymousUser.uid
|
||||||
|
response.set_cookie('anonymous_user_id', :path=> '/', :httponly => true, :value=>auid, :expires=> Time.now + 100.year)
|
||||||
|
end
|
||||||
|
return auid
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
post '/user/logout' do
|
post '/user/logout' do
|
||||||
response.delete_cookie("ribica_auth", :path => "/")
|
response.delete_cookie("ribica_auth", :path => "/")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class CreateItems < ActiveRecord::Migration
|
|||||||
t.integer :stock
|
t.integer :stock
|
||||||
t.boolean :on_display
|
t.boolean :on_display
|
||||||
|
|
||||||
t.timestamps null: false
|
t.timestamps null: false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
11
front-api/db/migrate/20150312073820_create_places.rb
Normal file
11
front-api/db/migrate/20150312073820_create_places.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class CreatePlaces < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :places do |t|
|
||||||
|
t.string :postal_code
|
||||||
|
t.decimal :delivery_price
|
||||||
|
t.string :name
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddPriceToItemInCart < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :item_in_carts, :price, :decimal
|
||||||
|
end
|
||||||
|
end
|
||||||
16
front-api/db/migrate/20150314033113_create_suppliers.rb
Normal file
16
front-api/db/migrate/20150314033113_create_suppliers.rb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
class CreateSuppliers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :suppliers do |t|
|
||||||
|
t.string :name
|
||||||
|
t.string :address
|
||||||
|
t.string :postal_code
|
||||||
|
t.string :town
|
||||||
|
t.string :phone
|
||||||
|
t.string :contact_person
|
||||||
|
t.string :email
|
||||||
|
t.text :note
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddSupplierToItem < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :items, :supplier_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddWeigthToItem < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :items, :weight, :decimal, precision: 5, scale: 3
|
||||||
|
end
|
||||||
|
end
|
||||||
10
front-api/db/migrate/20150315074249_add_flags_to_cart.rb
Normal file
10
front-api/db/migrate/20150315074249_add_flags_to_cart.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class AddFlagsToCart < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :carts, :confirmed, :boolean, default: false
|
||||||
|
add_column :carts, :packed, :boolean, default: false
|
||||||
|
add_column :carts, :canceled_on_check, :boolean, default: false
|
||||||
|
add_column :carts, :canceled_on_delivery, :boolean, default: false
|
||||||
|
add_column :carts, :delivered, :boolean, default: false
|
||||||
|
add_column :carts, :internal_note, :text
|
||||||
|
end
|
||||||
|
end
|
||||||
19
front-api/db/migrate/20150318044804_create_special_offers.rb
Normal file
19
front-api/db/migrate/20150318044804_create_special_offers.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
class CreateSpecialOffers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :special_offers do |t|
|
||||||
|
t.string :image_url
|
||||||
|
t.boolean :start_page
|
||||||
|
t.integer :section_id
|
||||||
|
t.integer :category_id
|
||||||
|
t.integer :sub_category_id
|
||||||
|
t.integer :item_id
|
||||||
|
t.boolean :thank_you_page
|
||||||
|
t.boolean :search_result_page
|
||||||
|
t.boolean :checkout_page
|
||||||
|
t.date :beginning
|
||||||
|
t.date :ending
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddSpecialOfferToItem < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :items, :special_offer_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddOrderToSections < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :sections, :order, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddOrderToCategories < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :categories, :order, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddOrderToSubcategories < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :sub_categories, :order, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
11
front-api/db/migrate/20150319104317_create_children.rb
Normal file
11
front-api/db/migrate/20150319104317_create_children.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class CreateChildren < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :children do |t|
|
||||||
|
t.string :name
|
||||||
|
t.integer :gender
|
||||||
|
t.date :date_of_birth
|
||||||
|
t.integer :user_id
|
||||||
|
t.boolean :on_the_way
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
class CreateDeliveryTimeEstimations < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :delivery_time_estimations do |t|
|
||||||
|
t.string :name
|
||||||
|
t.integer :duration_in_days
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddDeliveryTimeEstimationToItem < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :items, :delivery_time_estimation_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class RemoveSpecialOfferIdFromItem < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
remove_column :items, :special_offer_id
|
||||||
|
end
|
||||||
|
end
|
||||||
25
front-api/db/migrate/20150322043737_create_link_banners.rb
Normal file
25
front-api/db/migrate/20150322043737_create_link_banners.rb
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
class CreateLinkBanners < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :link_banners do |t|
|
||||||
|
t.string :image_url
|
||||||
|
t.boolean :start_page
|
||||||
|
t.integer :section_id
|
||||||
|
t.integer :category_id
|
||||||
|
t.integer :sub_category_id
|
||||||
|
t.integer :item_id
|
||||||
|
t.boolean :thank_you_page
|
||||||
|
t.boolean :search_result_page
|
||||||
|
t.boolean :checkout_page
|
||||||
|
t.date :beginning
|
||||||
|
t.date :ending
|
||||||
|
t.boolean :footer
|
||||||
|
t.boolean :header
|
||||||
|
t.string :link_url
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
drop_table :special_offers
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
13
front-api/db/migrate/20150322044941_create_item_groups.rb
Normal file
13
front-api/db/migrate/20150322044941_create_item_groups.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
class CreateItemGroups < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :item_groups do |t|
|
||||||
|
t.string :name
|
||||||
|
t.text :description
|
||||||
|
t.boolean :visible
|
||||||
|
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
create_join_table :item, :item_groups
|
||||||
|
end
|
||||||
9
front-api/db/migrate/20150324044115_create_menu_items.rb
Normal file
9
front-api/db/migrate/20150324044115_create_menu_items.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class CreateMenuItems < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :menu_items do |t|
|
||||||
|
t.string :title
|
||||||
|
t.string :url
|
||||||
|
t.integer :ordinal
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
10
front-api/db/migrate/20150324044314_create_menu_sub_items.rb
Normal file
10
front-api/db/migrate/20150324044314_create_menu_sub_items.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class CreateMenuSubItems < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :menu_sub_items do |t|
|
||||||
|
t.string :title
|
||||||
|
t.string :url
|
||||||
|
t.integer :ordinal
|
||||||
|
t.integer :menu_item_id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
9
front-api/db/migrate/20150328132019_create_brands.rb
Normal file
9
front-api/db/migrate/20150328132019_create_brands.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class CreateBrands < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :brands do |t|
|
||||||
|
t.string :name
|
||||||
|
end
|
||||||
|
|
||||||
|
add_column :items, :brand_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class ChangeCodeColumnOnItemsTable < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
change_column :items, :code, :string, limit: 30
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class ChangeUnitsInPackColumnOnItems < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
# t.decimal :units_in_pack, precision: 5, scale: 3
|
||||||
|
change_column :items, :units_in_pack, :decimal, precision: 6, scale: 2
|
||||||
|
end
|
||||||
|
end
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user