From 8b6a62b7e794b92b9b24f606b96958fb8e4a636b Mon Sep 17 00:00:00 2001
From: Senad Uka
Date: Sun, 9 Aug 2015 10:17:52 +0200
Subject: [PATCH] added order report to back office
---
.../app/controllers/carts_controller.rb | 1 +
back-office/app/helpers/carts_helper.rb | 4 +
back-office/app/models/cart.rb | 17 +++-
back-office/app/models/place.rb | 9 ++
back-office/app/views/carts/_show.html.erb | 84 +++++++++++++++++++
5 files changed, 114 insertions(+), 1 deletion(-)
create mode 100644 back-office/app/views/carts/_show.html.erb
diff --git a/back-office/app/controllers/carts_controller.rb b/back-office/app/controllers/carts_controller.rb
index 3cc7ee2..b09386b 100644
--- a/back-office/app/controllers/carts_controller.rb
+++ b/back-office/app/controllers/carts_controller.rb
@@ -1,4 +1,5 @@
class CartsController < ApplicationController
active_scaffold :"cart" do |conf|
end
+
end
diff --git a/back-office/app/helpers/carts_helper.rb b/back-office/app/helpers/carts_helper.rb
index d0fea14..ee41104 100644
--- a/back-office/app/helpers/carts_helper.rb
+++ b/back-office/app/helpers/carts_helper.rb
@@ -1,2 +1,6 @@
module CartsHelper
+
+ def money(amount)
+ sprintf('%.2f KM', amount.to_f)
+ end
end
\ No newline at end of file
diff --git a/back-office/app/models/cart.rb b/back-office/app/models/cart.rb
index fc67258..299a08a 100644
--- a/back-office/app/models/cart.rb
+++ b/back-office/app/models/cart.rb
@@ -4,7 +4,22 @@ class Cart < ActiveRecord::Base
belongs_to :user
belongs_to :delivery_destination
+ def delivery_cost
+ place = Place.by_code_or_default(delivery_destination.place)
+ if delivery_destination.instant_delivery
+ place.instant_delivery_price
+ else
+ place.delivery_price
+ end
+ end
-
+ def total
+ sum = item_in_carts.inject (0) { |sum, iic| sum + (iic.price * iic.count) }
+ sum += delivery_cost
+ end
+
+ def confirmed_at
+ delivery_destination.updated_at.in_time_zone('Europe/Sarajevo')
+ end
end
diff --git a/back-office/app/models/place.rb b/back-office/app/models/place.rb
index 28f3f80..b92e8f9 100644
--- a/back-office/app/models/place.rb
+++ b/back-office/app/models/place.rb
@@ -521,4 +521,13 @@ class Place < ActiveRecord::Base
return "";
end
+
+ def self.by_code_or_default(code)
+ # removes garbage and converts whitespace prefixed codes correctly - like " 71000" -> 71000
+ valid_code = code.to_i.to_s
+ place = Place.where(postal_code: valid_code).first
+ place ||= Place.where("postal_code is null or postal_code = ''").first
+ return place
+ end
+
end
diff --git a/back-office/app/views/carts/_show.html.erb b/back-office/app/views/carts/_show.html.erb
new file mode 100644
index 0000000..64f61b6
--- /dev/null
+++ b/back-office/app/views/carts/_show.html.erb
@@ -0,0 +1,84 @@
+
+<%
+ dd = @record.delivery_destination
+ c = @record
+%>
+
+
Ime: <%= dd.name %>
+
+Adresa:
+<%= dd.address %>
+<%= dd.place.to_s.strip %> <%= Place.name_from_code(dd.place.to_s) %>
+Bosna i Hercegovina
+
+
+
+Email: <%= dd.email %>
+
+Telefon: +387 <%= dd.phone %>
+
+
+Napomena:
+<%= dd.note %>
+
+
+
+
+Naručeno: <%= c.confirmed_at.strftime("%A %d.%m.%Y. %H:%M") %>
+
+
+
+<% if dd.instant_delivery %>
+
+OVO JE NARUDŽBA ZA INSTANT DOSTAVU
+
+<% end %>
+
+
+
+ | Code |
+ Item name |
+ Amount |
+ Price |
+ Total |
+
+ <% @record.item_in_carts.each do |iic| %>
+
+ | <%= iic.item.code %> |
+ <%= iic.item.name %> |
+ <%= iic.count %> |
+ <%= money(iic.price) %> |
+ <%= money(iic.count * iic.price) %> |
+
+ <% end %>
+
+ |
+ Dostava |
+ 1 |
+ <%= money(c.delivery_cost) %> |
+ <%= money(c.delivery_cost) %> |
+
+
+ | UKUPNO: |
+ |
+ |
+ |
+ <%= money(c.total) %> |
+
+ | |
+
+
+
+
+
+
+
+
+
+
+
+