Fix display of supplier products and offerings - wasnt including all services

This commit is contained in:
Deon George 2023-03-15 15:34:28 +11:00
parent b719efb58c
commit a6f01d0864
5 changed files with 14 additions and 16 deletions

View File

@ -4,7 +4,6 @@ namespace App\Http\Controllers;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use App\Http\Requests\{SupplierAddEdit,SupplierProductAddEdit};
use App\Models\{Cost,Supplier,SupplierDetail};

View File

@ -6,7 +6,7 @@ use Illuminate\Support\Collection;
interface ProductItem
{
public function product();
public function products();
public function supplied();

View File

@ -20,11 +20,11 @@ abstract class Type extends Model
/**
* The product that sells this type
*
* @return \Illuminate\Database\Eloquent\Relations\MorphOne
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
*/
public function product()
public function products()
{
return $this->morphOne(Product::class, null,'model','model_id');
return $this->morphMany(Product::class, null,'model','model_id');
}
/**

View File

@ -33,17 +33,17 @@
</thead>
<tbody>
@foreach($xx=$offering->items->with(['products.product.services'])->get() as $oo)
@foreach($xx=$offering->items->with(['products.products.services'])->get() as $oo)
<tr>
<td>{{ $oo->id }}</td>
<td>{{ $oo->name_short }}</td>
<td>{{ $oo->name_detail }}</td>
<td>{{ $oo->name }}</td>
<td>{{ $oo->name_long }}</td>
<td class="text-right">{{ $oo->active ? 'YES' : 'NO' }}</td>
<td class="text-right">{{ number_format($oo->setup_cost_taxable,2) }}</td>
<td class="text-right">{{ number_format($oo->base_cost_taxable,2) }}</td>
<td class="text-right">{{ number_format($oo->products->count()) }}</td>
<td class="text-right">{{ number_format($oo->products->pluck('product')->filter()->count()) }}</td>
<td class="text-right">{{ number_format(($x=$oo->products->pluck('product.services')->flatten()->filter())->count()) }}</td>
<td class="text-right">{{ number_format($oo->products->pluck('products')->filter()->count()) }}</td>
<td class="text-right">{{ number_format(($x=$oo->products->pluck('products')->flatten()->pluck('services')->flatten()->filter())->count()) }}</td>
<td class="text-right">{{ number_format($x->where('active')->count()) }}</td>
</tr>
@endforeach
@ -54,8 +54,8 @@
<th colspan="3">TOTALS</th>
<td class="text-right" colspan="3">{{ $xx->where('active',TRUE)->count() }}</td>
<td class="text-right">{{ number_format(($x=$xx->pluck('products')->flatten()->filter())->count()) }}</td>
<td class="text-right">{{ number_format($x->pluck('product')->filter()->count()) }}</td>
<td class="text-right">{{ number_format(($xxx=$x->pluck('product.services')->flatten()->filter())->count()) }}</td>
<td class="text-right">{{ number_format($x->pluck('products')->filter()->count()) }}</td>
<td class="text-right">{{ number_format(($xxx=$x->pluck('products')->flatten()->pluck('services')->flatten()->filter())->count()) }}</td>
<td class="text-right">{{ number_format($xxx->where('active')->count()) }}</td>
</tr>
</tfoot>

View File

@ -34,9 +34,8 @@
</thead>
<tbody>
@foreach($xx=$offering->items->with(['products.product.services','products.product.type.supplied','products.product.description'])->get() as $oo)
@foreach($oo->products->pluck('product')->filter() as $po)
@foreach($xx=$offering->items->with(['products.products.services','products.products.type.supplied','products.products.translate'])->get() as $oo)
@foreach($oo->products->pluck('products')->flatten()->filter() as $po)
<tr>
<td><a href="{{ url('a/supplier/product/addedit',[$po->supplier->id,$po->supplied->id,$po->supplied->category]) }}">{{ $po->lid }}</a></td>
<td>{{ $po->name_short }}</td>
@ -59,7 +58,7 @@
<th colspan="3">TOTALS</th>
<td class="text-right">{{ $xx->where('active',TRUE)->count() }}</td>
<th colspan="5">&nbsp;</th>
<td class="text-right">{{ number_format(($xxx=$xx->pluck('products')->flatten()->pluck('product.services')->flatten()->filter())->count()) }}</td>
<td class="text-right">{{ number_format(($xxx=$xx->pluck('products')->flatten()->pluck('products')->flatten()->pluck('services')->flatten()->filter())->count()) }}</td>
<td class="text-right">{{ number_format($xxx->where('active')->count()) }}</td>
</tr>
</tfoot>