Merge branch 'develop'
paypal, pikpay and gift support
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
|
||||
gem 'rails_admin'
|
||||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
||||
gem 'rails', '4.2.0'
|
||||
@@ -25,8 +24,11 @@ gem 'jbuilder', '~> 2.0'
|
||||
# bundle exec rake doc:rails generates the API under doc/api.
|
||||
gem 'sdoc', '~> 0.4.0', group: :doc
|
||||
|
||||
gem 'tzinfo-data'
|
||||
|
||||
gem "nokogiri", ">= 1.6.6"
|
||||
# great server
|
||||
gem 'puma'
|
||||
gem 'puma', '~> 2.15.3'
|
||||
|
||||
# for uploading images
|
||||
gem 'cloudinary'
|
||||
|
||||
@@ -79,6 +79,7 @@ GEM
|
||||
execjs (2.2.2)
|
||||
faraday (0.9.1)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ffi (1.9.10-x64-mingw32)
|
||||
font-awesome-rails (4.3.0.0)
|
||||
railties (>= 3.2, < 5.0)
|
||||
globalid (0.3.0)
|
||||
@@ -111,11 +112,13 @@ GEM
|
||||
multipart-post (2.0.0)
|
||||
nested_form (0.3.2)
|
||||
netrc (0.10.2)
|
||||
nokogiri (1.6.5)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
nokogiri (1.6.6.2-x64-mingw32)
|
||||
mini_portile (~> 0.6.0)
|
||||
pg (0.18.1)
|
||||
puma (2.10.2)
|
||||
rack (>= 1.1, < 2.0)
|
||||
pg (0.18.1-x64-mingw32)
|
||||
puma (2.15.3)
|
||||
rack (1.6.0)
|
||||
rack-pjax (0.8.0)
|
||||
nokogiri (~> 1.5)
|
||||
@@ -167,6 +170,10 @@ GEM
|
||||
rest-client (1.7.2)
|
||||
mime-types (>= 1.16, < 3.0)
|
||||
netrc (~> 0.7)
|
||||
rest-client (1.7.2-x64-mingw32)
|
||||
ffi (~> 1.9)
|
||||
mime-types (>= 1.16, < 3.0)
|
||||
netrc (~> 0.7)
|
||||
safe_yaml (1.0.4)
|
||||
sass (3.4.9)
|
||||
sass-rails (5.0.1)
|
||||
@@ -199,6 +206,8 @@ GEM
|
||||
coffee-rails
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
tzinfo-data (1.2015.7)
|
||||
tzinfo (>= 1.0.0)
|
||||
uglifier (2.7.0)
|
||||
execjs (>= 0.3.0)
|
||||
json (>= 1.8.0)
|
||||
@@ -210,6 +219,7 @@ GEM
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
x64-mingw32
|
||||
|
||||
DEPENDENCIES
|
||||
active_scaffold!
|
||||
@@ -220,8 +230,9 @@ DEPENDENCIES
|
||||
jbuilder (~> 2.0)
|
||||
jquery-rails
|
||||
jquery-ui-rails
|
||||
nokogiri (>= 1.6.6)
|
||||
pg
|
||||
puma
|
||||
puma (~> 2.15.3)
|
||||
rails (= 4.2.0)
|
||||
rails_admin
|
||||
sass-rails (~> 5.0)
|
||||
@@ -229,8 +240,9 @@ DEPENDENCIES
|
||||
spring
|
||||
tabulous
|
||||
turbolinks
|
||||
tzinfo-data
|
||||
uglifier (>= 1.3.0)
|
||||
web-console (~> 2.0)
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.3
|
||||
1.10.6
|
||||
|
||||
5
back-office/app/constraints/check_items_constraint.rb
Normal file
5
back-office/app/constraints/check_items_constraint.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class CheckItemsConstraint
|
||||
def self.matches?(request)
|
||||
request.params[:commit] == 'Check'
|
||||
end
|
||||
end
|
||||
5
back-office/app/constraints/delete_items_constraint.rb
Normal file
5
back-office/app/constraints/delete_items_constraint.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class DeleteItemsConstraint
|
||||
def self.matches?(request)
|
||||
request.params[:commit] == 'Delete Items'
|
||||
end
|
||||
end
|
||||
@@ -15,4 +15,80 @@ class ItemsController < ApplicationController
|
||||
@missing_from_database = (@codes_to_check_array - items_to_check) || []
|
||||
@missing_from_codes = (items_to_check - @codes_to_check_array) || []
|
||||
end
|
||||
|
||||
def delete_items
|
||||
@suppliers = Supplier.order(:name).all
|
||||
@selected_supplier = Supplier.find_by_id(params[:supplier_id])
|
||||
@items = @selected_supplier.try(:items) || []
|
||||
@codes_to_check = params[:codes] || ""
|
||||
@codes_to_check_array = @codes_to_check.split("\n").reject { |code| code.strip.blank? }.map(&:strip)
|
||||
items_to_check = @items.map { |i| i.code.strip }
|
||||
|
||||
@items_for_delete = items_to_check & @codes_to_check_array
|
||||
Item.where(:code => @items_for_delete).destroy_all
|
||||
|
||||
@not_deleted_items = (@codes_to_check_array - @items_for_delete) || []
|
||||
|
||||
render :template => "items/check_availability"
|
||||
end
|
||||
|
||||
def export_import
|
||||
@tasks = [ ["Validate items", "validate_items"],
|
||||
["Import items", "import_items"],
|
||||
["Update prices", "update_prices"] ]
|
||||
|
||||
@task = "validate_items"
|
||||
end
|
||||
|
||||
def export_import_post
|
||||
@tasks = [ ["Validate items", "validate_items"],
|
||||
["Import items", "import_items"],
|
||||
["Update prices", "update_prices"] ]
|
||||
|
||||
@task = params[:task]
|
||||
|
||||
@csv_content = params[:csv_content]
|
||||
|
||||
@error_message = ""
|
||||
@output = []
|
||||
|
||||
if params[:csv_content] == ""
|
||||
@error_message = "Format of CSV is wrong (CSV content is empty)"
|
||||
else
|
||||
begin
|
||||
csv_parsed = CSV.parse(params[:csv_content])
|
||||
rescue CSV::MalformedCSVError => er
|
||||
@error_message = "Format of CSV is wrong (#{er.message})"
|
||||
end
|
||||
|
||||
unless csv_parsed.nil?
|
||||
csv_file = ItemsHelper::create_csv(csv_parsed)
|
||||
|
||||
begin
|
||||
ENV["INPUT"] = csv_file.path
|
||||
|
||||
case @task
|
||||
when 'validate_items'
|
||||
@output = ItemsHelper::execute_command("rake ribica:validate_items -f #{Rails.root}/Rakefile")
|
||||
@output.collect{|x| x.sub! "\n", "" }
|
||||
when 'import_items'
|
||||
@output = ItemsHelper::execute_command("rake ribica:import_items -f #{Rails.root}/Rakefile")
|
||||
@output.collect{|x| x.sub! "\n", "" }
|
||||
%x(rake ribica:reindex -f #{Rails.root}/Rakefile) unless RakeTasksHelper::is_error_occurred @output
|
||||
when 'update_prices'
|
||||
@output = ItemsHelper::execute_command("rake ribica:update_prices -f #{Rails.root}/Rakefile")
|
||||
%x(rake ribica:reindex -f #{Rails.root}/Rakefile) unless RakeTasksHelper::is_error_occurred @output
|
||||
else
|
||||
@error_message = "There is no such task"
|
||||
end
|
||||
ensure
|
||||
csv_file.unlink
|
||||
end
|
||||
end
|
||||
|
||||
@output = @output.join("<br/>")
|
||||
end
|
||||
|
||||
render :template => "items/export_import"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
module ItemsHelper
|
||||
def self.create_csv(data)
|
||||
file = Tempfile.new([Rails.root.join('tmp/').to_s, ".csv"], "")
|
||||
csv = CSV.new(file)
|
||||
data.each do |row|
|
||||
csv << row
|
||||
end
|
||||
|
||||
file.rewind
|
||||
file.close
|
||||
file
|
||||
end
|
||||
|
||||
def self.execute_command(command)
|
||||
buffer = []
|
||||
Open3.popen3(command) do |stdin, stdout, stderr|
|
||||
begin
|
||||
while line = stdout.readline
|
||||
buffer << line
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
buffer
|
||||
end
|
||||
end
|
||||
|
||||
9
back-office/app/helpers/rake_tasks_helper.rb
Normal file
9
back-office/app/helpers/rake_tasks_helper.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
module RakeTasksHelper
|
||||
def self.task_error_message
|
||||
"Rake task execution error"
|
||||
end
|
||||
|
||||
def self.is_error_occurred(buffer)
|
||||
buffer.include? self.task_error_message
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,9 @@ class Cart < ActiveRecord::Base
|
||||
belongs_to :delivery_destination
|
||||
|
||||
def delivery_cost
|
||||
place = Place.by_code_or_default(delivery_destination.place)
|
||||
place = delivery_destination.gift ? Place.by_code_or_default(delivery_destination.recipient_place)
|
||||
: Place.by_code_or_default(delivery_destination.place)
|
||||
|
||||
if delivery_destination.instant_delivery
|
||||
place.instant_delivery_price
|
||||
else
|
||||
@@ -21,5 +23,4 @@ class Cart < ActiveRecord::Base
|
||||
def confirmed_at
|
||||
delivery_destination.updated_at.in_time_zone('Europe/Sarajevo')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -1,2 +1,14 @@
|
||||
class DeliveryDestination < ActiveRecord::Base
|
||||
class DeliveryDestination < ActiveRecord::Base
|
||||
def get_payment_string
|
||||
case self.payment_method
|
||||
when 'cash_on_delivery'
|
||||
'Prilikom preuzimanja'
|
||||
when 'paypal'
|
||||
'Paypal'
|
||||
when 'pikpay'
|
||||
'Pikpay'
|
||||
else
|
||||
'Nepoznato'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -124,12 +124,13 @@ class Item < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
puts "Nonexistent codes: "
|
||||
puts nonexistent_codes.join("\n")
|
||||
puts "#{nonexistent_codes.join("\n")}"
|
||||
end
|
||||
|
||||
def we_must_earn_money
|
||||
if list_price.to_f <= current_input_price.to_f
|
||||
errors[:list_price] << "#{code} Ulazna cijena veca od izlazne"
|
||||
puts "#{code} Ulazna cijena veca od izlazne"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
.tg td{ }
|
||||
.tg th{ }
|
||||
</style>
|
||||
<%
|
||||
<%
|
||||
dd = @record.delivery_destination
|
||||
c = @record
|
||||
%>
|
||||
<p>
|
||||
<p><strong>Ime:</strong> <%= dd.name %><br /><br /></p>
|
||||
|
||||
<p><strong>Adresa:</strong><br />
|
||||
<p><strong>Adresa:</strong><br />
|
||||
<%= dd.address %><br />
|
||||
<%= dd.place.to_s.strip %> <%= Place.name_from_code(dd.place.to_s) %><br />
|
||||
Bosna i Hercegovina<br /><br />
|
||||
@@ -22,15 +22,27 @@ Bosna i Hercegovina<br /><br />
|
||||
<p><strong>Telefon: </strong> +387 <%= dd.phone %><br /><br />
|
||||
</p>
|
||||
|
||||
<p><strong>Plaćanje: </strong><%= dd.get_payment_string %></p><br />
|
||||
|
||||
<p><strong>Napomena: </strong><br />
|
||||
<%= dd.note %><br /><br />
|
||||
</p>
|
||||
</p>
|
||||
|
||||
<% if dd.gift %>
|
||||
<p><strong>Ovo je poklon</strong><br /><br />
|
||||
<p><strong>Ime primaoca: </strong><%= dd.recipient_name %><br />
|
||||
<p><strong>Adresa primaoca: </strong><%= dd.recipient_address %><br />
|
||||
<p><strong>Postanski broj primaoca: </strong><%= dd.recipient_postal_code %><br />
|
||||
<p><strong>Grad primaoca: </strong><%= dd.recipient_place %><br />
|
||||
<p><strong>Email primaoca: </strong><%= dd.recipient_email %><br />
|
||||
<p><strong>Telefon primaoca: </strong><%= dd.recipient_phone %><br /><br />
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<strong>Naručeno:</strong> <%= c.confirmed_at.in_time_zone("Europe/Sarajevo").strftime("%A %d.%m.%Y. %H:%M") %>
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
<br />
|
||||
</p>
|
||||
<% if dd.instant_delivery %>
|
||||
<p style="font-size: 120%;">
|
||||
@@ -47,7 +59,7 @@ OVO JE NARUDŽBA ZA INSTANT DOSTAVU
|
||||
<th style="text-align: right; ">Total</th>
|
||||
</tr>
|
||||
<% @record.item_in_carts.each do |iic| %>
|
||||
<tr>
|
||||
<tr>
|
||||
<td class="tg-031e"><%= iic.item.code %></td>
|
||||
<td class="tg-031e"><%= iic.item.name %></td>
|
||||
<td style="text-align: right; "><%= iic.count %></td>
|
||||
@@ -70,15 +82,6 @@ OVO JE NARUDŽBA ZA INSTANT DOSTAVU
|
||||
<td style="text-align: right; "><%= money(c.total) %></td>
|
||||
</tr>
|
||||
<tr><td><strong> </strong></td></tr>
|
||||
|
||||
|
||||
</table>
|
||||
<br /><br />
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,33 +2,48 @@
|
||||
<p><label for="supplier_id">Supplier: </label>
|
||||
<%= select_tag "supplier_id", options_from_collection_for_select(@suppliers, "id", "name", @selected_supplier.try(:id)) %></p>
|
||||
|
||||
<p><label for="codes">
|
||||
<p><label for="codes">
|
||||
Codes to check:
|
||||
</label><br />
|
||||
<%= text_area_tag "codes", @codes_to_check, rows: 20, columns: 50 %></p>
|
||||
|
||||
<p><%= submit_tag "Check" %></p>
|
||||
<p><%= submit_tag "Delete Items" %></p>
|
||||
<% end %>
|
||||
|
||||
<div>
|
||||
<h2> In database: <%= @items.length %>, in file: <%= @codes_to_check_array.length %> </h2>
|
||||
</div>
|
||||
<% if controller.action_name == 'delete_items' %>
|
||||
|
||||
<h2> Delete successful </h2>
|
||||
|
||||
<% if @not_deleted_items.length > 0 %>
|
||||
<p>Not deleted items</p>
|
||||
<% @not_deleted_items.each do |code| %>
|
||||
<%= code %><br />
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% else %>
|
||||
|
||||
<div>
|
||||
<h2> In database: <%= @items.length %>, in file: <%= @codes_to_check_array.length %> </h2>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Not in database (<%= @missing_from_database.length %>): </h2>
|
||||
<br />
|
||||
<% @missing_from_database.each do |code| %>
|
||||
<%= code %><br />
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Not in file (<%= @missing_from_codes.length %>): </h2>
|
||||
<br />
|
||||
<% @missing_from_codes.each do |code| %>
|
||||
<%= code %><br />
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Not in database (<%= @missing_from_database.length %>): </h2>
|
||||
<br />
|
||||
<% @missing_from_database.each do |code| %>
|
||||
<%= code %><br />
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2>Not in file (<%= @missing_from_codes.length %>): </h2>
|
||||
<br />
|
||||
<% @missing_from_codes.each do |code| %>
|
||||
<%= code %><br />
|
||||
<% end %>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
21
back-office/app/views/items/export_import.html.erb
Normal file
21
back-office/app/views/items/export_import.html.erb
Normal file
@@ -0,0 +1,21 @@
|
||||
<%= form_tag('./export_import') do %>
|
||||
<p><label for="codes">
|
||||
CSV content goes here:
|
||||
</label><br />
|
||||
<textarea id="csv_content" name="csv_content" rows=20 style="width: 100%"><%= @csv_content %></textarea></p>
|
||||
|
||||
<p><label for="task">Task: </label>
|
||||
<%= select_tag "task", options_for_select(@tasks, @task) %></p>
|
||||
|
||||
<p><%= submit_tag "Run task" %></p>
|
||||
|
||||
<% if !@error_message.nil? && @error_message != "" %>
|
||||
<div>Error message: <span style="color: red"><%= @error_message %></span></div>
|
||||
<% end %>
|
||||
|
||||
<br />
|
||||
<p><label for="output_area">Output area: </label>
|
||||
<div id="output_area" style="width: 100%;height: 14em;outline: 1px solid #A9A9A9; overflow: scroll"><%= unless @output.nil?
|
||||
@output.html_safe end %>
|
||||
</div>
|
||||
<% end %>
|
||||
@@ -1,6 +1,8 @@
|
||||
require File.expand_path('../boot', __FILE__)
|
||||
|
||||
require 'rails/all'
|
||||
require 'rake'
|
||||
require 'open3'
|
||||
|
||||
# Require the gems listed in Gemfile, including any gems
|
||||
# you've limited to :test, :development, or :production.
|
||||
@@ -25,5 +27,3 @@ module Ribicabackoffice
|
||||
config.assets.precompile += %w(*.svg *.eot *.woff *.ttf *.gif *.png *.ico)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ RailsAdmin.config do |config|
|
||||
config.navigation_static_links = {
|
||||
'Orders to Confirm' => './reports/orders_to_confirm',
|
||||
'Items to Order' => './backreports/items_to_order',
|
||||
'Check availability' => './items/check_availability'
|
||||
'Check availability' => './items/check_availability',
|
||||
'Export/import' => './items/export_import'
|
||||
}
|
||||
end
|
||||
|
||||
@@ -15,12 +15,15 @@ Rails.application.routes.draw do
|
||||
resources :multi_media_descriptions do as_routes end
|
||||
resources :sections do as_routes end
|
||||
resources :media_types do as_routes end
|
||||
resources :items do
|
||||
collection do
|
||||
resources :items do
|
||||
collection do
|
||||
get 'check_availability'
|
||||
post 'check_availability'
|
||||
post 'check_availability' => 'items#check_availability', constraints: CheckItemsConstraint
|
||||
post 'check_availability' => 'items#delete_items', constraints: DeleteItemsConstraint
|
||||
get 'export_import'
|
||||
post 'export_import' => 'items#export_import_post'
|
||||
end
|
||||
as_routes
|
||||
as_routes
|
||||
end
|
||||
resources :units do as_routes end
|
||||
resources :sub_categories do as_routes end
|
||||
|
||||
@@ -223,6 +223,7 @@ def import_single_item(row, index, logger)
|
||||
success = true
|
||||
rescue Exception => e
|
||||
logger.error "Could not import item on row number #{index} (#{row[lookup[:name_on_ribica]]}), reason: #{e}"
|
||||
puts "Could not import item on row number #{index} (#{row[lookup[:name_on_ribica]]}), reason: #{e}"
|
||||
success = false
|
||||
end
|
||||
|
||||
@@ -242,14 +243,15 @@ def do_import(validate_only)
|
||||
input_file = ENV['INPUT']
|
||||
if input_file.to_s == ""
|
||||
puts "Input file is missing! Please provide input file in form INPUT=somefile.csv"
|
||||
puts RakeTasksHelper.task_error_message
|
||||
return
|
||||
end
|
||||
|
||||
lookup = get_column_lookup
|
||||
path = Rails.root.join(input_file)
|
||||
|
||||
log_filename = "import.log"
|
||||
log_filename = "import_validate.log" if validate_only
|
||||
log_filename = Rails.root.join("import.log")
|
||||
log_filename = Rails.root.join("import_validate.log") if validate_only
|
||||
|
||||
logger = Logger.new(log_filename)
|
||||
|
||||
@@ -274,6 +276,7 @@ def do_import(validate_only)
|
||||
if should_rollback
|
||||
puts "Import failed, please check the import log file for error details."
|
||||
logger.info "Rolling back because of errors"
|
||||
puts RakeTasksHelper.task_error_message
|
||||
end
|
||||
|
||||
raise ActiveRecord::Rollback
|
||||
@@ -281,8 +284,11 @@ def do_import(validate_only)
|
||||
end
|
||||
rescue Exception => e
|
||||
puts "Import failed, please check the import log file for error details."
|
||||
puts "Error while importing: #{e}"
|
||||
logger.error "Error while importing: #{e}"
|
||||
puts RakeTasksHelper.task_error_message
|
||||
end
|
||||
puts "Import done"
|
||||
logger.info "Import done"
|
||||
end
|
||||
|
||||
@@ -359,7 +365,7 @@ namespace :ribica do
|
||||
begin
|
||||
es_client.indices.delete index: 'ribica'
|
||||
rescue
|
||||
logger.warn "Ribica index could not be deleted. Continuing with indexing operation..."
|
||||
Rails.logger.warn "Ribica index could not be deleted. Continuing with indexing operation..."
|
||||
end
|
||||
|
||||
# now index items
|
||||
|
||||
Reference in New Issue
Block a user