Parcourir la source

Separate USD and MXN purchases in report

Jacqueline Maldonado il y a 7 ans
Parent
commit
61d3b4021a

+ 1 - 1
app/controllers/purchases_controller.rb

@@ -70,7 +70,7 @@ class PurchasesController < ApplicationController
     @pre_purchases = PrePurchase.where(user_id: current_user.id)
 
     respond_to do |format|
-      message = "compra #{@purchase.purchase_code} por #{@purchase.total} creada."
+      message = "Compra #{@purchase.purchase_code} por $ #{@purchase.total} #{@purchase.exchange.present? ? "USD" : "MXN"} creada."
       @purchase.audit_comment = message
       if @purchase.save
         @pre_purchases.each do |pre_purchase|

+ 8 - 0
app/controllers/reports_controller.rb

@@ -45,8 +45,16 @@ class ReportsController < ApplicationController
           end
       end
       @total_prods = 0
+      @total_purchased = 0
+      @total_dollars = 0
       @purchases.each do |purchase|
+        next if purchase.cancelled?
         @total_prods += purchase.purchase_details.sum(:quantity)
+        if purchase.exchange.present?
+          @total_dollars += purchase.total
+        else
+          @total_purchased += purchase.total
+        end
       end
       respond_to do |format|
         format.js

+ 1 - 1
app/views/purchases/_form.html.erb

@@ -83,7 +83,7 @@
 						data: {
 							on_color: "success",
 							off_color: "warning",
-							on_text: "Dolares",
+							on_text: "Dólares",
 							off_text: "Pesos"
 						}
 					},

+ 1 - 1
app/views/reports/_report_purchase.html.erb

@@ -9,5 +9,5 @@
   <td><%= purchase_status(purchase) %></td>
   <td><%= number_to_currency(purchase.amount.round(2), precision: 2) %></td>
   <td><%= number_to_currency(purchase.tax.round(2), precision: 2) %></td>
-  <td><%= number_to_currency(purchase.total.round(2), precision: 2) %></td>
+  <td><% total = number_to_currency(purchase.total.round(2), precision: 2) %><%= purchase.exchange.present? ? total.to_s + " USD" : total.to_s + " MXN" %></td>
 </tr>

+ 6 - 3
app/views/reports/purchases_per_month.html.erb

@@ -110,13 +110,15 @@
                   <div class="col-md-3 col-sm-3 col-xs-6">
                     <div class="text-center well" style="margin-bottom: 0px">
                       <div class="font-grey-mint font-sm">Total comprado contado </div>
-                      <div class="uppercase font-hg font-blue-sharp" id="cash_purchases_total"> $0.00</div>
+                      <div class="uppercase font-hg font-blue-sharp"><span id="cash_purchases_total"> $0.00</span> MXN</div>
+                      <div class="uppercase font-hg font-blue-sharp"><span id="cash_purchases_total_dollars"> $0.00</span> USD</div>
                     </div>
                   </div>
                   <div class="col-md-3 col-sm-3 col-xs-6">
                     <div class="text-center well hidden" style="margin-bottom: 0px">
                       <div class="font-grey-mint font-sm">Total comprado crédito </div>
-                      <div class="uppercase font-hg font-blue-sharp" id="credit_purchases_total"> $0.00</div>
+                      <div class="uppercase font-hg font-blue-sharp"><span id="credit_purchases_total"> $0.00</span> MXN</div>
+                      <div class="uppercase font-hg font-blue-sharp"><span id="credit_purchases_total_dollars"> $0.00</span> USD</div>
                     </div>
                   </div>
                 </div>
@@ -130,7 +132,8 @@
                   <div class="col-xs-3">
                     <div class="text-center well" style="margin-bottom: 0px">
                       <div class="font-grey-mint font-sm">TOTAL COMPRADO</div>
-                      <div class="uppercase font-hg font-green" id="purchases_total">$0.00</div>
+                      <div class="uppercase font-hg font-green"><span id="purchases_total">$0.00</span> MXN</div>
+                      <div class="uppercase font-hg font-green"><span id="purchases_total_dollars">$0.00</span> USD</div>
                     </div>
                   </div>
                 </div>

+ 4 - 2
app/views/reports/purchases_per_month.js.erb

@@ -20,7 +20,9 @@ $('#note_info').removeClass('hidden');
 $('#prods_total').html('<%= @total_prods %>');
 $('#purchases_quantity').html('<%= @purchases.count %>');
 
-$('#cash_purchases_total').html(accounting.formatMoney('<%= @purchases.sum(:total).round(2) %>'));
+$('#cash_purchases_total').html(accounting.formatMoney('<%= @total_purchased.round(2) %>'));
+$('#cash_purchases_total_dollars').html(accounting.formatMoney('<%= @total_dollars.round(2) %>'));
 // $('#credit_purchases_total').html(accounting.formatMoney('< %= @purchases.sum(:total).round(2) %>'));
 $('#expenses_total').html(accounting.formatMoney('<%= @expenses.sum(:quantity).round(2) %>'));
-$('#purchases_total').html(accounting.formatMoney('<%= @purchases.sum(:total).round(2) %>'));
+$('#purchases_total').html(accounting.formatMoney('<%= @total_purchased.round(2) %>'));
+$('#purchases_total_dollars').html(accounting.formatMoney('<%= @total_dollars.round(2) %>'));