how to change value change text in laravel - laravel

I want to when change TVA value change text But in the end, the same result
They appear "NET TTC" in both cases
Function :
public function invoice()
{
return $this->belongsTo(Invoice::class, 'invoice_id', 'id');
}
public function tvaText(){
if( $this->TVA_value == 0 ){
$this->tva_text='NET TTC';
}elseif($this->TVA_value != 0){
$this->tva_text='Total TTC';
}
return $this->tva_text;
}
Show :
#foreach($invoice->details as $item)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $item->product_name }}</td>
<td>{{ $item->quantity }}</td>
<td>{{ $item->unit_price }}</td>
<td>{{ $item->row_sub_total }}</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3"></td>
<th colspan="2">TVA value </th>
<td>{{ $invoice->TVA_value }}</td>
</tr>
<tr>
<td colspan="3"></td>
<th colspan="2">sub total</th>
<td>{{ $invoice->sub_total }}</td>
</tr>
<tr>
<td colspan="3"></td>
<th colspan="2">TVA total</th>
<td>{{ $invoice->TVA_total }}</td>
</tr>
<tr>
<td colspan="3"></td>
<th colspan="2">{{ $item->**tvaText()** }}</th>
<td>{{ $invoice->TTC_total }}</td>
</tr>
#endforeach
Please see pictures so that it becomes clear to you what I mean
does anyone know how to change text or any other method to achieve?

You can do it easily on blade.
#if($invoice->TVA_value == 0 )
<td>NET TTC</td>
#else
<td> Total TTC </td>
#endif

Related

Please assist i want to loop through two database tables and view them in a blade.I want records to appear according to dates with in different column

All i want is to show debit and credit according to dates. I want debit to show only if there's new record added and also credit to show only if there's changes in the accounts. I have used observer to check if column is dirty.
here is my blade
<table class="table table-striped">
<thead style="background-color: #0b8a83;color:rgb(0, 0, 0);">
<th>Date</th>
<th>Description</th>
<th>Credit</th>
<th>Debit</th>
<th>Balance</th>
</thead>
#foreach ($monthlyInst as $keyy)
<tr>
<td>{{ date('d/M/y', strtotime($keyy->updated_at)) }}</td>
<td></td>
<td></td>
<td>R {{ $keyy->Installment }}</td>
<td></td>
</tr>
#endforeach
#foreach ($history as $account)
<tr>
<td>{{ date('d/M/y', strtotime($account->updated_at)) }}</td>
<td>{{ $account->accountname }}</td>
<td>R {{ $account->newpaid }}</td>
<td></td>
<td>R {{ $account->newbal }}</td>
</tr>
#endforeach
<tr>
<td></td>
<td>Outstanding Balance</td>
<td></td>
<td></td>
<td><b>R {{ $totalbal }}</b></td>
</tr>
</table>

How to calculate total column value without query by Laravel or php?

Here above I want to Calculate Buying Total and selling Total in the current month . Suppose in November I want to calculate sell row total , buying row total and buying-selling total count. How Can I do that . Please help...
**<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Date</th>
<th>Product Name</th>
<th>Quantity (Stock IN)</th>
<th>Buying Total</th>
<th>Stock</th>
<th>Selling Total</th>
<th>Profit (%)</th>
</tr>
</thead>
<tbody>
#foreach($product_all as $row)
<tr>
<td>{{ $row->buying_date}}</td>
<td>{{ $row->product_name}}</td>
<td>{{ $row->stock_in }}</td>
<td>{{ $row->buying_price*$row->stock_in }}</td> *********
<td>{{ $row->total_stock }}</td>
<td>{{ $row->selling_price*($row->stock_in-$row->total_stock)}}</td> ********
<td>{{ ($row->buying_price*$row->stock_in) - ($row->selling_price*($row->stock_in-$row->total_stock)) }}</td>
</tr>
#endforeach
</tbody>
</table>**
<h4 style="color: #ff3939; text-align: center;">November Total Invest : {{ #### }} <span> Sell : {{ #### }}</span></h4>
There are 2 ways to do:
First: setting parameters
**<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
...
</tr>
</thead>
<tbody>
<?php
$yoursum1 = 0;
$yoursum2 = 0;
foreach($product_all as $row)
echo "<tr>
<td>{{ $row->buying_date}}</td>
<td>{{ $row->product_name}}</td>
<td>{{ $row->stock_in }}</td>
<td>{{ $row->buying_price*$row->stock_in }}</td> *********
<td>{{ $row->total_stock }}</td>
<td>{{ $row->selling_price*($row->stock_in-$row->total_stock)}}</td> ********
<td>{{ ($row->buying_price*$row->stock_in) - ($row->selling_price*($row->stock_in-$row->total_stock)) }}</td>
</tr>"
$yoursum1 += $yourvalue1;
$yoursum2 += $yourvalue2;
endforeach
echo "<tr>
<td></td>
<td>Summary</td>
<td>{{ $yoursum1}}</td>
<td>{{ $yoursum2}}</td> *********
<td>{{ $yoursum3}}</td>
<td>{{ $yoursum4}}</td> ********
<td>{{ $yoursum5 }}</td>
</tr>"
?>
</tbody>
</table>**
<h4 style="color: #ff3939; text-align: center;">November Total Invest : {{ #### }} <span> Sell : {{ #### }}</span></h4>
Second: using query to calculate and insert one row below
#foreach($product_all as $row)
<tr>
<td>{{ $row->buying_date}}</td>
<td>{{ $row->product_name}}</td>
<td>{{ $row->stock_in }}</td>
<td>{{ $row->buying_price*$row->stock_in }}</td> *********
<td>{{ $row->total_stock }}</td>
<td>{{ $row->selling_price*($row->stock_in-$row->total_stock)}}</td> ********
<td>{{ ($row->buying_price*$row->stock_in) - ($row->selling_price*($row->stock_in-$row->total_stock)) }}</td>
</tr>
#endforeach
<tr>
<td></td>
<td>Summary</td>
<td>{{ $value1 }}</td>
<td>{{ $value2 }}</td> *********
<td>{{ $value3 }}</td>
<td>{{ $value4 }}</td> ********
<td>{{ ($value5 }}</td>
</tr>
IT is advisable to keep calculations and processing out of the views. Controllers are meant to be the files where all calculations and data manipulations should be done.
//Say this is inside the controller method from which the view with data is returned as response
public function index(Request $request)
{
$product_all = Product::all();
$groupedByMonth = $product_all->groupBy(function($product) {
return \Illuminate\Support\Carbon::parse($product->date)->format('m');
});
$totals = (object) [
'buying' => $groupedByMonth->map(function($month){
return $month->sum('buying_total');
}),
'selling' => $groupedByMonth->map(function($month){
return $month->sum('selling_total');
}),
];
//Pass $totals to the view where it can be accessed as $totals->buying
}
As such the calculation/manipulation can be done in blade view between #php #endphp

Laravel Blade rendering table inside table with VueJS

I have this scenario working with Laravel blade view:
#foreach($event->drawingrequests as $drawing)
<tr>
<td>{{ $drawing->field1 }}</td>
<td>{{ $drawing->field2 }}</td>
<td>{{ $drawing->field3 }}</td>
<td>{{ $drawing->field4 }}</td>
<td>{{ $drawing->field5 }}</td>
<td>{{ $drawing->field6 }}</td>
<td>{{ $drawing->field7 }}</td>
</tr>
#if(count(drawing->childs) > 0)
<tr><td colspan="7">
<table class="table">
<tbody>
#foreach(drawing->childs as $stage)
<tr>
<td>{{ $stage->field1 }}</td>
<td>{{ $stage->field2 }}</td>
<td>{{ $stage->field3 }}</td>
<td>{{ $stage->field4 }}</td>
<td>{{ $stage->field5 }}</td>
</tr>
#endforeach
</tbody>
</table>
</td></tr>
#endif
#endforeach
I can I do it on VueJS??? The main question here in, on VueJs conditions are always connected to DOM elements.. I need to create other tr when childs > 0. And I need to check this condition on each drawing.
<tr v-for="drawing in eventdetail.event.drawingrequests">
<td>#{{ drawing.field1 }}</td>
<td>#{{ drawing.field2 }}</td>
<td>#{{ drawing.field3 }}</td>
<td>#{{ drawing.field4 }}</td>
<td>#{{ drawing.field5 }}</td>
<td>#{{ drawing.field6 }}</td>
<td>#{{ drawing.field7 }}</td>
</tr>
#if(drawing.childs > 0)
<tr>
<td colspan="7">
<table class="table">
<tbody>
<tr v-for="stage in drawing.childs">
<td>#{{ stage.field1 }}</td>
<td>#{{ stage.field2 }}</td>
<td>#{{ stage.field3 }}</td>
<td>#{{ stage.field4 }}</td>
<td>#{{ stage.field5 }}</td>
</tr>
</tbody>
</table>
</td>
</tr>
#endif
Found the solution:
<template v-for="drawing in eventdetail.event.drawingrequests">
<tr>
<td>#{{ drawing.field1 }}</td>
<td>#{{ drawing.field2 }}</td>
<td>#{{ drawing.field3 }}</td>
<td>#{{ drawing.field4 }}</td>
<td>#{{ drawing.field5 }}</td>
<td>#{{ drawing.field6 }}</td>
<td>#{{ drawing.field7 }}</td>
</tr>
<tr v-if="drawing.childs > 0">
<td colspan="7">
<table class="table">
<tbody>
<tr v-for="stage in drawing.childs">
<td>#{{ stage.field1 }}</td>
<td>#{{ stage.field2 }}</td>
<td>#{{ stage.field3 }}</td>
<td>#{{ stage.field4 }}</td>
<td>#{{ stage.field5 }}</td>
</tr>
</tbody>
</table>
</td>
</tr>
</template>
Reference link:
Vue: Displaying nested data in a table

Laravel Foreach Looping

I need to display the previous value of the iterated array, here is code
<tr>
<th></th>
<th>Customer ID</th>
<th>Customer Name</th>
<th>Delivery Address</th>
<th>Contact No.</th>
<th>Zip Code</th>
<th>Payment Terms</th>
<th>Credit Limit</th>
</tr>
<?php $previousValue = null; ?>
#foreach($customer_count as $key => $value)
<tr>
<td>{{$previousValue=$value->customer_name }}</td>
<td>{{ $value->id }}</td>
<td>{{ $value->customer_name }}</td>
<td>{{ $value->delivery_address }}</td>
<td>{{ $value->contact_number }}</td>
<td>{{ $value->area_id }}</td>
<td>{{ $value->payment_term_id }}</td>
<td>{{ $value->credit_limit }}</td>
</tr>
#endforeach
I need to display the previous name of Customer in the iteration?
Any idea on how to do this?
Set value at the end , I set blank for first
#foreach($customer_count as $key => $value)
<tr>
<td>{{$previousValue or ""}}</td>
.....
.....
</tr>
<?php $previousValue = $value->customer_name ?>
#endforeach
$customer_count[$key - 1]
Of course you'll need to check if that exists or use the null-coalesce operator or something, so:
#php
$previous = $customer_count[$key - 1] ?? false;
#endphp
Then use:
#if( $previous )
... some stuff ...
#endif
wherever you need to inject.
please try this
<td>{{ (!$loop->first) ? $customer_count[$key - 1]->customer_name : '' }}</td>
You can read more about foreach loop here.
At very first set the previous value as blank and then at the bottom set value in $previousValue
<?php $previousValue = '';?>
#foreach($customer_count as $key => $value)
<tr>
<td>{{ $previousValue }}</td>
<td>{{ $value->id }}</td>
<td>{{ $value->customer_name }}</td>
<td>{{ $value->delivery_address }}</td>
<td>{{ $value->contact_number }}</td>
<td>{{ $value->area_id }}</td>
<td>{{ $value->payment_term_id }}</td>
<td>{{ $value->credit_limit }}</td>
</tr>
<?php $previousValue = $value->customer_name; ?>
#endforeach

Laravel 5 unable to render pagination

I'm new to Laravel 5 and I have an issue displaying pagination. I looked in the documentation and just can't get it to work.
usercontroller:
public function getIndex()
{
$users = User::where('active', '=','verified')->simplePaginate(10);
return View::make('User.index')->with('users',$users);
}
index.blade.php:
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>id</th>
<th>username</th>
<th>email</th>
<th>role</th>
<th>created</th>
<th class="actions">Actions</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->username }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->role }}</td>
<td>{{ $user->created_at }}</td>
<td class="actions">
blabla
</td>
</tr>
#endforeach
</tbody>
</table>
{!! $users->render() !!}
for some reason, it was printing an additional /
fix:
{!! str_replace('users/','users',$users->render()) !!}

Resources