Yes of course. Here is the blueprint of a shipowners ship. An it’s listing the multiple transportation deals made with that specific ship.
cargo:
type: structure
fields:
cargoamount:
label: Amount
type: number
before: $
cargocharterer:
label: Charterer
type: select
options:
type: query
query: page.parent.children.filterBy('category', 'charterer')
cargobroker:
label: Shipbroker
type: select
options:
type: query
query: page.parent.children.filterBy('category', 'broker')
cargodate:
label: Date
type: date
display: DD.MM.YYYY
On the single ship page there is a list of all deals, and two global totals. one is the total amount of all deals. and the other how many deals were made. Thank works perfectly with this:
$cargodata = $page->cargo()->toStructure();
$cargocount = count($cargodata->pluck('cargoamount', ','));
$cargototal = array_sum($cargodata->pluck('cargoamount', ','));
foreach ($cargodata as $cargo)
On the overview page of all ships (parent page) i want to do the same but for all ships together. So based on the working php on the single ship, i projected it for the overview page. whith your help the list of all deals of all ships is working on the overview:
$ships = $page->children()->listed();
<?php foreach ($ships as $ship): {
$cargodata = $ship->cargo()->toStructure();
}
?>
<?php foreach ($cargodata as $cargo): ?>
<tr>
<td>
<?= $cargo->cargodate()->toDate('%Y-%m-%d') ?>
</td>
<td>
<?php $cargoC = $cargo->cargocharterer()->toPage(); ?>
<?= $cargoC->title()->h()->esc() ?>
</td>
<td>
<?php $cargoB = $cargo->cargobroker()->toPage(); ?>
<?= $cargoB->title()->h()->esc() ?>
</td>
<td>
<?php $cargoA = $cargo->cargoamount()->value(); ?>
$<?php echo number_format( $cargoA, 0, '.', "'"); ?>
</td>
</tr>
<?php endforeach ?>
<?php endforeach ?>
I am struggeling now with the two totals of all deals. One is total amount of all deals made by all ships. And the other is the total amount of all deals by all ships. Following the code on the overview page of all ships:
$ships = $page->children()->listed();
foreach ($ships as $ship) {
$cargodata = $ship->cargo()->toStructure();
$cargocount = count($cargodata->pluck('cargoamount', ','));
$cargototal = array_sum($cargodata->pluck('cargoamount', ','));
var_dump($cargototal);
}
I put the count() and the array_sum() into the loop, but echoing them is not delivering the result, and i dont get an error message. And i dont get it. Thanx for your precious help. Hugs.