promotion add in report

This commit is contained in:
Aung Myo
2018-06-21 14:39:34 +06:30
parent e45e17968f
commit ad4bf1451b
5 changed files with 69 additions and 10 deletions

View File

@@ -165,6 +165,7 @@ class Promotion < ApplicationRecord
sale_item = SaleItem.new sale_item = SaleItem.new
sale_item.product_code = item.item_code sale_item.product_code = item.item_code
sale_item.item_instance_code = item.item_instance_code
sale_item.product_name = item.item_name + "(promotion)" sale_item.product_name = item.item_name + "(promotion)"
sale_item.product_alt_name = item.alt_name sale_item.product_alt_name = item.alt_name
sale_item.account_id = item.account_id sale_item.account_id = item.account_id

View File

@@ -878,13 +878,16 @@ def self.get_item_query(type)
sale_type = "i.status = 'void' and i.item_instance_code IS NOT NULL and i.qty > 0" sale_type = "i.status = 'void' and i.item_instance_code IS NOT NULL and i.qty > 0"
elsif type == "other" elsif type == "other"
sale_type = "i.item_instance_code IS NULL" sale_type = "i.item_instance_code IS NULL"
elsif type == "promotion"
sale_type = "i.status = 'promotion'"
end end
query = Sale.select("acc.title as account_name,mi.account_id, query = Sale.select("acc.title as account_name,mi.account_id,
i.item_instance_code as item_code,i.account_id as account_id, " + i.item_instance_code as item_code,i.account_id as account_id, " +
"SUM(i.qty * i.unit_price) as grand_total, "SUM(i.qty * i.unit_price) as grand_total,
SUM(i.qty) as total_item,i.qty as qty," + SUM(i.qty) as total_item,i.qty as qty," +
"i.status as status_type,"+ "i.status as status_type,i.remark as remark,"+
"i.unit_price,i.price as price,i.product_name as product_name,mc.name as " +"menu_category_name,mc.id as menu_category_id ") "i.unit_price,i.price as price,i.product_name as product_name,mc.name as " +
"menu_category_name,mc.id as menu_category_id ")
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" +
" JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" + " JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" +
@@ -901,7 +904,7 @@ end
def self.get_other_charges() def self.get_other_charges()
query = Sale.select("i.account_id as account_id, " + query = Sale.select("i.account_id as account_id, " +
"SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," +
"i.status as status_type,"+ "i.status as status_type,i.remark as remark,"+
" i.unit_price as unit_price,i.product_name as product_name") " i.unit_price as unit_price,i.product_name as product_name")
query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id")
query = query.where("i.item_instance_code IS NULL AND i.product_code = 'Other Charges'") query = query.where("i.item_instance_code IS NULL AND i.product_code = 'Other Charges'")

View File

@@ -28,6 +28,7 @@
<option value="discount">Discount Only</option> <option value="discount">Discount Only</option>
<option value="void">Void Only</option> <option value="void">Void Only</option>
<option value="foc">Foc Only</option> <option value="foc">Foc Only</option>
<option value="promotion">Promotion Only</option>
<option value="other">Other Amount Only</option> <option value="other">Other Amount Only</option>
</select> </select>
</div> </div>

View File

@@ -79,7 +79,7 @@
<% @sale_data.each do |sale| %> <% @sale_data.each do |sale| %>
<!-- all total qty sum --> <!-- all total qty sum -->
<% if sale.status_type != "Discount" && sale.status_type != "foc" <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion"
total_qty += sale.total_item total_qty += sale.total_item
end %> end %>
<% if sale.status_type == "foc" && sale.price > 0 <% if sale.status_type == "foc" && sale.price > 0
@@ -88,6 +88,9 @@
<% if sale.status_type == "Discount" <% if sale.status_type == "Discount"
total_qty += sale.total_item*(-1) total_qty += sale.total_item*(-1)
end %> end %>
<% if sale.remark =="promotion"
total_qty += sale.total_item
end %>
<!-- end all total qty --> <!-- end all total qty -->
<% if sale.status_type == "foc" && sale.grand_total < 0 <% if sale.status_type == "foc" && sale.grand_total < 0
@@ -140,12 +143,16 @@
<% count = count + 1 %> <% count = count + 1 %>
<% sub_total += sale.grand_total %> <% sub_total += sale.grand_total %>
<% #sub_qty += sale.total_item %> <% #sub_qty += sale.total_item %>
<% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion"
sub_qty += sale.total_item sub_qty += sale.total_item
end %> end %>
<% if sale.status_type =="Discount" <% if sale.status_type =="Discount"
sub_qty += sale.total_item*(-1) sub_qty += sale.total_item*(-1)
end %> end %>
<% if sale.remark == "promotion"
sub_qty += sale.total_item
end %>
<% if count == value %> <% if count == value %>
<tr> <tr>
<td colspan="3">&nbsp;</td> <td colspan="3">&nbsp;</td>

View File

@@ -48,10 +48,11 @@
%> %>
<% acc_arr = Array.new %> <% acc_arr = Array.new %>
<% cate_arr = Array.new %> <% cate_arr = Array.new %>
<% p_qty = 0 %>
<% sub_qty = 0 %> <% sub_qty = 0 %>
<% sub_total = 0 %> <% sub_total = 0 %>
<% other_sub_total = 0 %> <% other_sub_total = 0 %>
<% product_sub_total = 0 %>
<% count = 0 %> <% count = 0 %>
<% total_price = 0 %> <% total_price = 0 %>
<% cate_count = 0 %> <% cate_count = 0 %>
@@ -67,7 +68,7 @@
<% @sale_data.each do |sale| %> <% @sale_data.each do |sale| %>
<!-- all total qty sum --> <!-- all total qty sum -->
<% if sale.status_type != "Discount" && sale.status_type != "foc" <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion"
total_qty += sale.total_item total_qty += sale.total_item
end %> end %>
<% if sale.status_type == "foc" && sale.price > 0 <% if sale.status_type == "foc" && sale.price > 0
@@ -76,6 +77,9 @@
<% if sale.status_type == "Discount" <% if sale.status_type == "Discount"
total_qty += sale.total_item*(-1) total_qty += sale.total_item*(-1)
end %> end %>
<% if sale.remark =="promotion"
total_qty += sale.total_item
end %>
<!-- end all total qty --> <!-- end all total qty -->
<% if sale.status_type == "foc" && sale.grand_total < 0 <% if sale.status_type == "foc" && sale.grand_total < 0
@@ -128,12 +132,16 @@
<% count = count + 1 %> <% count = count + 1 %>
<% sub_total += sale.grand_total %> <% sub_total += sale.grand_total %>
<% #sub_qty += sale.total_item %> <% #sub_qty += sale.total_item %>
<% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion"
sub_qty += sale.total_item sub_qty += sale.total_item
end %> end %>
<% if sale.status_type =="Discount" <% if sale.status_type =="Discount"
sub_qty += sale.total_item*(-1) sub_qty += sale.total_item*(-1)
end %> end %>
<% if sale.remark == "promotion"
sub_qty += sale.total_item
end %>
<% if count == value %> <% if count == value %>
<tr> <tr>
<td colspan="3">&nbsp;</td> <td colspan="3">&nbsp;</td>
@@ -150,8 +158,47 @@
<% end %> <% end %>
<!-- end sub total --> <!-- end sub total -->
<% end %> <% end %>
<!--Product Sale -->
<% if @product.present?%>
<tr>
<td><b>Product</b></td>
<td colspan="4">&nbsp;</td>
<td></td>
</tr>
<% @product.each do |product| %>
<% if product.total_item > 0
total_qty += product.total_item
end %>
<% grand_total +=product.grand_total
p_qty += product.total_item%>
<tr>
<td>&nbsp;</td>
<td>Product</td>
<td><%= product.product_code rescue '-' %></td>
<td><%= product.product_name rescue '-' %></td>
<td><%= product.total_item rescue '-' %></td>
<td> <%= number_with_precision(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
<td> <%= number_with_precision(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td>
</tr>
<!-- sub total -->
<% product_sub_total += product.grand_total %>
<!-- end sub total -->
<% end %>
<tr>
<td colspan="3">&nbsp;</td>
<td><b>Total Product Qty </b> </td>
<td><b><%= p_qty %></b></td>
<td><%= t("views.right_panel.detail.sub_total") %></td>
<td ><span><%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%></span></td>
</tr>
<%end%>
<!-- End Product Sale -->
<!--Other Charges --> <!--Other Charges -->
<% if @type == "other"%> <% if @type == "other" || @other_charges.present?%>
<tr> <tr>
<td><b>Other Charges</b></td> <td><b>Other Charges</b></td>
@@ -205,7 +252,7 @@
end %> end %>
<% grand_total +=other.grand_total%> <% grand_total +=other.grand_total%>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td>Other Charges</td> <td>Other Charges</td>
<td><%= other.item_code rescue '-' %></td> <td><%= other.item_code rescue '-' %></td>
<td><%= other.product_name rescue '-' %></td> <td><%= other.product_name rescue '-' %></td>