change product sale report

This commit is contained in:
phyusin
2018-03-29 19:39:29 +06:30
parent 4c9f451e73
commit 75f3377d75
2 changed files with 50 additions and 18 deletions

38
app/views/reports/product_sale/index.html.erb Executable file → Normal file
View File

@@ -45,41 +45,58 @@
<th><%= t("views.right_panel.detail.code") %></th> <th><%= t("views.right_panel.detail.code") %></th>
<th><%= t("views.right_panel.detail.product") %></th> <th><%= t("views.right_panel.detail.product") %></th>
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></th> <th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></th>
<th><%= t("views.right_panel.detail.unit_price") %></th> <!-- <th><%= t("views.right_panel.detail.unit_price") %></th> -->
<th><%= t("views.right_panel.detail.total") %></th> <th><%= t("views.right_panel.detail.total") %></th>
</tr> </tr>
</thead> </thead>
<tbody id="tbd_data"> <tbody id="tbd_data">
<% unless @sale_data.blank? %> <% unless @sale_data.blank? %>
<% acc_arr = Array.new %> <% acc_arr = Array.new %>
<% cate_arr = Array.new %> <% cate_arr = Array.new %>
<% grand_total = 0 %> <% grand_total = 0 %>
<% total_qty = 0 %> <% total_qty = 0 %>
<% total_item = {} %>
<% total_data = {} %>
<% @sale_data.each do |sale|
if !total_item.has_key?(sale.item_code)
total_item[sale.item_code] = sale.total_item
total_data[sale.item_code] = sale.grand_total
else
if sale.status_type == "void"
total_item[sale.item_code] += sale.total_item
end
if sale.status_type == "void" || sale.status_type == "Discount" || sale.status_type == "foc"
total_data[sale.item_code] += sale.grand_total
end
end
end %>
<% @sale_data.each do |sale| %> <% @sale_data.each do |sale| %>
<% grand_total += sale.grand_total %> <% grand_total += sale.grand_total %>
<% if sale.status_type != "Discount" && sale.status_type != "foc" <% if sale.status_type != "Discount" && sale.status_type != "foc"
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
total_qty += sale.total_item total_qty += sale.total_item
end %> end %>
<% if !sale.status_type %>
<% if sale.status_type != "Discount" && sale.price.to_f >= 0 %>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<% if !cate_arr.include?(sale.menu_category_id) %> <% if !cate_arr.include?(sale.menu_category_id) %>
<td><%= sale.menu_category_name %></td> <td><%= sale.menu_category_name %></td>
<% cate_arr.push(sale.menu_category_id) %> <% cate_arr.push(sale.menu_category_id) %>
<% else %> <% else %>
<% cate_arr = Array.new %> <% if sale.total_item > 0 %>
<% cate_arr = Array.new %>
<% end %>
<td>&nbsp;</td> <td>&nbsp;</td>
<% end %> <% end %>
<td><%= sale.item_code rescue '-' %></td> <td><%= sale.item_code rescue '-' %></td>
<td><%= sale.product_name rescue '-' %></td> <td><%= sale.product_name rescue '-' %></td>
<td><%= sale.total_item rescue '-' %></td> <td><%= total_item[sale.item_code] rescue '-' %></td>
<td><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> <!-- <td><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%></td> -->
<td><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %></td> <td><%= number_with_precision(total_data[sale.item_code] , precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
</tr> </tr>
<!-- sub total --> <!-- sub total -->
<!-- end sub total --> <!-- end sub total -->
@@ -89,7 +106,6 @@
<td colspan="3"></td> <td colspan="3"></td>
<td><strong>Total</strong></td> <td><strong>Total</strong></td>
<td><strong><%= total_qty %></strong></td> <td><strong><%= total_qty %></strong></td>
<td></td>
<td><strong><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %></strong></td> <td><strong><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %></strong></td>
</tr> </tr>

30
app/views/reports/product_sale/index.xls.erb Executable file → Normal file
View File

@@ -11,7 +11,7 @@
<th><%= t("views.right_panel.detail.code") %></th> <th><%= t("views.right_panel.detail.code") %></th>
<th><%= t("views.right_panel.detail.product") %></th> <th><%= t("views.right_panel.detail.product") %></th>
<th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></th> <th><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %></th>
<th><%= t("views.right_panel.detail.unit_price") %></th> <!-- <th><%= t("views.right_panel.detail.unit_price") %></th> -->
<th><%= t("views.right_panel.detail.total") %></th> <th><%= t("views.right_panel.detail.total") %></th>
</tr> </tr>
</thead> </thead>
@@ -21,6 +21,21 @@
<% cate_arr = Array.new %> <% cate_arr = Array.new %>
<% grand_total = 0 %> <% grand_total = 0 %>
<% total_qty = 0 %> <% total_qty = 0 %>
<% total_item = {} %>
<% total_data = {} %>
<% @sale_data.each do |sale|
if !total_item.has_key?(sale.item_code)
total_item[sale.item_code] = sale.total_item
total_data[sale.item_code] = sale.grand_total
else
if sale.status_type == "void"
total_item[sale.item_code] += sale.total_item
end
if sale.status_type == "void" || sale.status_type == "Discount" || sale.status_type == "foc"
total_data[sale.item_code] += sale.grand_total
end
end
end %>
<% @sale_data.each do |sale| %> <% @sale_data.each do |sale| %>
<% grand_total += sale.grand_total %> <% grand_total += sale.grand_total %>
@@ -31,21 +46,23 @@
total_qty += sale.total_item total_qty += sale.total_item
end %> end %>
<% if !sale.status_type %> <% if sale.status_type != "Discount" && sale.price.to_f >= 0 %>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<% if !cate_arr.include?(sale.menu_category_id) %> <% if !cate_arr.include?(sale.menu_category_id) %>
<td><%= sale.menu_category_name %></td> <td><%= sale.menu_category_name %></td>
<% cate_arr.push(sale.menu_category_id) %> <% cate_arr.push(sale.menu_category_id) %>
<% else %> <% else %>
<% cate_arr = Array.new %> <% if sale.total_item > 0 %>
<% cate_arr = Array.new %>
<% end %>
<td>&nbsp;</td> <td>&nbsp;</td>
<% end %> <% end %>
<td><%= sale.item_code rescue '-' %></td> <td><%= sale.item_code rescue '-' %></td>
<td><%= sale.product_name rescue '-' %></td> <td><%= sale.product_name rescue '-' %></td>
<td><%= sale.total_item rescue ' ' %></td> <td><%= total_item[sale.item_code] rescue ' ' %></td>
<td><%= sale.unit_price rescue ' ' %></td> <!-- <td><%= sale.unit_price rescue ' ' %></td> -->
<td><%= sale.grand_total rescue ' ' %></td> <td><%= total_data[sale.item_code] rescue ' ' %></td>
</tr> </tr>
<!-- sub total --> <!-- sub total -->
<!-- end sub total --> <!-- end sub total -->
@@ -55,7 +72,6 @@
<td colspan="3"></td> <td colspan="3"></td>
<td><strong>Total</strong></td> <td><strong>Total</strong></td>
<td><strong><%= total_qty rescue ' ' %></strong></td> <td><strong><%= total_qty rescue ' ' %></strong></td>
<td></td>
<td><strong><%= grand_total rescue ' ' %></strong></td> <td><strong><%= grand_total rescue ' ' %></strong></td>
</tr> </tr>
<% end %> <% end %>