Merge branch 'develop'
paypal, pikpay and gift support
This commit is contained in:
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 %>
|
||||
Reference in New Issue
Block a user