added order report to back office
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
class CartsController < ApplicationController
|
class CartsController < ApplicationController
|
||||||
active_scaffold :"cart" do |conf|
|
active_scaffold :"cart" do |conf|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
module CartsHelper
|
module CartsHelper
|
||||||
|
|
||||||
|
def money(amount)
|
||||||
|
sprintf('%.2f KM', amount.to_f)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -4,7 +4,22 @@ class Cart < ActiveRecord::Base
|
|||||||
belongs_to :user
|
belongs_to :user
|
||||||
belongs_to :delivery_destination
|
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
|
end
|
||||||
|
|||||||
@@ -521,4 +521,13 @@ class Place < ActiveRecord::Base
|
|||||||
|
|
||||||
return "<nepoznato mjesto>";
|
return "<nepoznato mjesto>";
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
84
back-office/app/views/carts/_show.html.erb
Normal file
84
back-office/app/views/carts/_show.html.erb
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<style type="text/css">
|
||||||
|
.tg { }
|
||||||
|
.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 />
|
||||||
|
<%= dd.address %><br />
|
||||||
|
<%= dd.place.to_s.strip %> <%= Place.name_from_code(dd.place.to_s) %><br />
|
||||||
|
Bosna i Hercegovina<br /><br />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
<p><strong>Email: </strong><%= dd.email %><br />
|
||||||
|
</p>
|
||||||
|
<p><strong>Telefon: </strong> +387 <%= dd.phone %><br /><br />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p><strong>Napomena: </strong><br />
|
||||||
|
<%= dd.note %><br /><br />
|
||||||
|
</p>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Naručeno:</strong> <%= c.confirmed_at.strftime("%A %d.%m.%Y. %H:%M") %>
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
</p>
|
||||||
|
<% if dd.instant_delivery %>
|
||||||
|
<p style="font-size: 120%;">
|
||||||
|
OVO JE NARUDŽBA ZA INSTANT DOSTAVU
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<table class="tg">
|
||||||
|
<tr>
|
||||||
|
<th class="tg-031e">Code</th>
|
||||||
|
<th class="tg-031e">Item name</th>
|
||||||
|
<th style="text-align: right; ">Amount</th>
|
||||||
|
<th style="text-align: right; ">Price</th>
|
||||||
|
<th style="text-align: right; ">Total</th>
|
||||||
|
</tr>
|
||||||
|
<% @record.item_in_carts.each do |iic| %>
|
||||||
|
<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>
|
||||||
|
<td style="text-align: right; "><%= money(iic.price) %></td>
|
||||||
|
<td style="text-align: right; "><%= money(iic.count * iic.price) %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
<tr>
|
||||||
|
<td class="tg-031e"></td>
|
||||||
|
<td class="tg-031e">Dostava</td>
|
||||||
|
<td style="text-align: right; ">1</td>
|
||||||
|
<td style="text-align: right; "><%= money(c.delivery_cost) %></td>
|
||||||
|
<td style="text-align: right; "><%= money(c.delivery_cost) %></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="tg-031e"><strong>UKUPNO:</strong></td>
|
||||||
|
<td class="tg-031e"></td>
|
||||||
|
<td style="text-align: right; "></td>
|
||||||
|
<td style="text-align: right; "></td>
|
||||||
|
<td style="text-align: right; "><%= money(c.total) %></td>
|
||||||
|
</tr>
|
||||||
|
<tr><td><strong> </strong></td></tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<br /><br />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user