1

I'm using Laravel 5.7 & VueJs 2.5.* ...

I want to display GrandTotal on my view table, but i don't know what i'm doing wrong.

Where i'm displaying GrandTotal:

<tr v-for="ctInvoice in ctInvoices" :key="ctInvoice.id">
  <td>{{ formatPrice(ctInvoice.ct_invoice_grand_total) }}</td>
</tr>

My VueJs data():

data() {
    return {
      ctInvoices: {},
      customers: null,
      form: new Form({
        id: "",
        customer_id: "",
        ct_invoice_no: "",
        ct_invoice_date: "",
        ct_invoice_fares_total: 0,
        ct_invoice_taxes_grand_total: 0,
        ct_invoice_grand_total: 0,

        ctInvoiceItems: [{
          id: "",
          ct_invoice_id: "",
          ct_passenger_name: "",
          ct_fares: 0,
          ct_total_tax_breakup: 0,
          ct_sub_total: 0
        }]
      })
    };

Format Amount with this method():

formatPrice(value) {
  let val = (value / 1).toFixed().replace(".", ".");
  return val.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); //75.674,00
},

Image For Better Understanding: enter image description here

One item output from ctInvoices array

ctInvoices:Array[20] 0:Object created_at:"2018-10-27 15:13:06" ct_Invoice_date:"2018-10-31" ct_Invoice_fares_total:"600.00" ct_Invoice_grand_total:"1000.00" ct_Invoice_grand_total_words:null ct_Invoice_taxes_grand_total:"400.00" ct_Invoice_terms:null ct_invoice_items:Array1 ct_invoice_no:"111-222-333" customer:Object customer_id:3 id:22 updated_at:"2018-10-27 15:13:06"

Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164

2 Answers2

1

You're making a typo, you have a property called ct_Invoice_grand_total in your ctInvoice object with uppercase I and you're calling it with lowercase i, so you should put :

     <tr v-for="ctInvoice in ctInvoices" :key="ctInvoice.id">
       <td>{{ formatPrice(ctInvoice.ct_Invoice_grand_total) }}</td>
     </tr>
Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164
0

What error does your console show?

In your data you are specifing ctInvoices as an object, shouldn't this be an array with ctInvoice objects in it?

Does every ctInvoice in the ctInvoices contain a ct_invoice_grand_total property?

Instead of using a function to format the price, you could use an filter with toLocaleString.

Vue.filter('formatNumber', value => {
    let number = parseFloat(value);
    let options = { minimumFractionDigits: 2, style: 'currency', currency: 'EUR' };

    return number.toLocaleString("nl-NL", options);
});
Thijs
  • 962
  • 6
  • 11