change dashboard query

This commit is contained in:
phyusin
2018-02-22 10:10:20 +06:30
parent eafbb80f51
commit 2cb13f9a62
2 changed files with 8 additions and 8 deletions

View File

@@ -1375,7 +1375,7 @@ end
if payment_method == 'card' if payment_method == 'card'
query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to) query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
else else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to)
end end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else else
@@ -1384,7 +1384,7 @@ end
if payment_method == 'card' if payment_method == 'card'
query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to) query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to)
else else
query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to)
end end
query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first()
else else

View File

@@ -165,19 +165,19 @@
</tr> </tr>
<tr> <tr>
<td><%= t("views.right_panel.detail.total") %> <%= t :sale %> : </td> <td><%= t("views.right_panel.detail.total") %> <%= t :sale %> : </td>
<td align="right"><%= number_with_precision( @summ_sale.total_amount, precision: precision.to_i ,delimiter: delimiter) %></td> <td align="right"><%= number_with_precision( @summ_sale.total_amount, precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %></td>
</tr> </tr>
<tr> <tr>
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : </td> <td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : </td>
<td align="right"><%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %></td> <td align="right"><%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %></td>
</tr> </tr>
<tr> <tr>
<td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : </td> <td><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : </td>
<td align="right"><%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%></td> <td align="right"><%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %></td>
</tr> </tr>
<tr> <tr>
<td><%= t("views.right_panel.detail.grand_total") %> : </td> <td><%= t("views.right_panel.detail.grand_total") %> : </td>
<td align="right"><%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%></td> <td align="right"><%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %></td>
</tr> </tr>
</table> </table>
<table class="table"> <table class="table">
@@ -190,7 +190,7 @@
<td align="right"> <td align="right">
<% @sale_data.each do |data| %> <% @sale_data.each do |data| %>
<% pay_mth = payment.payment_method %> <% pay_mth = payment.payment_method %>
<%= data[""+pay_mth+""] %> <%= number_with_precision(data[""+pay_mth+""], precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
<% end %> <% end %>
</td> </td>
</tr> </tr>
@@ -203,7 +203,7 @@
<tr> <tr>
<td><%= t("views.right_panel.detail.card_sale") %> : </td> <td><%= t("views.right_panel.detail.card_sale") %> : </td>
<td align="right"> <td align="right">
<%= total_card["card"].to_f %> <%= number_with_precision(total_card["card"], precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %>
</td> </td>
</tr> </tr>
<% end %> <% end %>