check product sale

This commit is contained in:
phyusin
2018-02-28 16:26:40 +06:30
parent 32818abf49
commit 2f7d9523ec
2 changed files with 25 additions and 22 deletions

View File

@@ -851,18 +851,19 @@ def self.get_menu_item_query(order_by)
query = MenuItem.unscoped.select("acc.id as account_id, query = MenuItem.unscoped.select("acc.id as account_id,
acc.title as account_name, acc.title as account_name,
mii.item_instance_code as item_code, " + mii.item_instance_code as item_code, " +
"(CASE WHEN si.qty > 0 THEN SUM(si.qty) ELSE 0 END) as total_item," + "(CASE WHEN si.qty != '' THEN SUM(si.qty) ELSE 0 END) as total_item," +
"(CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END) as unit_price," + "(CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END) as unit_price," +
"(CASE WHEN (si.qty * si.unit_price) > 0 THEN (si.qty * si.unit_price) ELSE 0 END) as grand_total," + "(CASE WHEN (si.qty * si.unit_price) > 0 THEN (si.qty * si.unit_price) ELSE 0 END) as grand_total," +
"mii.price as unit_price, menu_items.name as product_name, "mii.price as unit_price, mii.item_instance_name as product_name,
mc.name as" + mc.name as" +
" menu_category_name,mc.id as menu_category_id, si.remark as status_type, si.price as price ") " menu_category_name,mc.id as menu_category_id, si.remark as status_type,
si.price as price ")
.joins(" LEFT JOIN menu_item_instances mii ON menu_items.id = mii.menu_item_id" + .joins(" LEFT JOIN menu_item_instances mii ON menu_items.id = mii.menu_item_id" +
" LEFT JOIN menu_categories mc ON mc.id = menu_items.menu_category_id" + " LEFT JOIN menu_categories mc ON mc.id = menu_items.menu_category_id" +
" LEFT JOIN accounts acc ON acc.id = menu_items.account_id" + " LEFT JOIN accounts acc ON acc.id = menu_items.account_id" +
" LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" + " LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" +
" LEFT JOIN sales s ON s.sale_id = si.sale_id") " LEFT JOIN sales s ON s.sale_id = si.sale_id")
.group("si.qty, mc.id, menu_items.name, (CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END)") .group("mc.id, mii.item_instance_name, (CASE WHEN si.unit_price > 0 THEN si.unit_price ELSE mii.price END)")
.order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}") .order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}")
end end
#product sale report query #product sale report query

View File

@@ -47,6 +47,7 @@
<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>
<th><%= t("views.right_panel.detail.remark") %></th>
</tr> </tr>
</thead> </thead>
<tbody id="tbd_data"> <tbody id="tbd_data">
@@ -58,24 +59,25 @@
<% total_qty = 0 %> <% total_qty = 0 %>
<% @sale_data.each do |sale| %> <% @sale_data.each do |sale| %>
<% 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
grand_total += sale.grand_total grand_total += sale.grand_total
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
grand_total += sale.grand_total grand_total += sale.grand_total
end %> end %>
<tr> <tr>
<td>&nbsp;</td> <td>&nbsp;</td>
<td><%= sale.menu_category_name %></td> <td><%= sale.menu_category_name %></td>
<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><%= sale.total_item 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(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %></td>
</tr> <td><%= sale.status_type rescue '' %></td>
</tr>
<!-- sub total --> <!-- sub total -->
<!-- end sub total --> <!-- end sub total -->
<% end %> <% end %>
@@ -84,7 +86,7 @@
<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></td>
<td><strong><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %></strong></td> <td colspan="2"><strong><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-' %></strong></td>
</tr> </tr>
<% end %> <% end %>