<div id="recipes-inputs-colheader" style="display: grid; gap: 1rem; grid-template-columns:repeat(3,1fr);">
    <div class="recipes-input-inputname">Product Name</div>
    <div class="recipes-input-qty">Pack Qty<br />Grams or Ea</div>
    <div class="recipes-input-qty">Total Required<br />Kg or Ea</div>
</div>

<?php $inputcss = 'recipes-inputs-odd'; ?>
<div id="recipes-inputs-data" style="display: grid; row-gap: 1rem; grid-template-columns:repeat(3,1fr);">
    <?php $currentinputtypeid = 0; ?>
    <?php
    $decplaces = 0;
    // 0.002 * 1000 = 2.0  2.0 - 2 = 0.0  == 0  3 dec places
    // 0.243 * 1000 = 243 243 - 243 = 0.0 == 0 3 dec places
    // 0.27 * 1000 = 270  270 / 270 = 0.0 == 0  3 dec places
    foreach ($recipeinputs as $recipeinput) {
        // if($recipeinput->IsCoffee){
        //     echo "$recipeinput->TotalQty * 1000 - (int)($recipeinput->TotalQty * 1000) ".$recipeinput->TotalQty * 1000 ." - ". (int)($recipeinput->TotalQty * 1000)."=".$recipeinput->TotalQty * 1000 - (int)($recipeinput->TotalQty * 1000) ."<br/>";
        // }
        if ($recipeinput->IsCoffee and $decplaces == 0 and $recipeinput->TotalQty * 1000 - (int)($recipeinput->TotalQty * 1000) == 0.0) {
            $decplaces = 3;
        }
    }
    //echo $decplaces."<br/>";
    if ($decplaces > 0) {
        // 0.002 * 100 = 0.2 0.2 - 0 = 0.2 > 0
        // 0.243 * 100 = 24.3 24.3 - 24 = 0.3 > 0
        // 0.27 * 100 = 27    27 - 27 = 0.0  == 0  2 decplaces
        foreach ($recipeinputs as $recipeinput) {
            // if($recipeinput->IsCoffee){
            //     echo "$recipeinput->TotalQty * 100 - (int)($recipeinput->TotalQty * 100) ".$recipeinput->TotalQty * 100 ." - ". (int)($recipeinput->TotalQty * 100)."=".$recipeinput->TotalQty * 100 - (int)($recipeinput->TotalQty * 100) ."<br/>";
            // }
            if ($recipeinput->IsCoffee and $decplaces == 3 and  $recipeinput->TotalQty * 100 - (int)($recipeinput->TotalQty * 100) == 0.0) {
                $decplaces = 2;
            }
        }
    }
    //echo $decplaces."<br/>";
    if ($decplaces > 0) {
        // 0.002
        // 0.243
        // 0.27
        foreach ($recipeinputs as $recipeinput) {
            // 0.002 * 10 = 0.02  0.02 - 0 = 0.02 > 0.0
            // 0.243 * 10 = 2.43  2.43 - 2 = 0.43 > 0.0
            // 0.27 * 10  = 2.7  2.7 - 2 = 0.7 > 0.0
            // if($recipeinput->IsCoffee){
            //     echo "$recipeinput->TotalQty * 10 - (int)($recipeinput->TotalQty * 10) ".$recipeinput->TotalQty * 10 ." - ". (int)($recipeinput->TotalQty * 10)."=".$recipeinput->TotalQty * 10 - (int)($recipeinput->TotalQty * 10) ."<br/>";
            // }
            if ($recipeinput->IsCoffee and $decplaces == 2 and $recipeinput->TotalQty * 10 - (int)($recipeinput->TotalQty * 10) == 0.0) {
                $decplaces = 1;
            }
        }
    }
    //echo $decplaces."<br/>";
    if ($decplaces > 0) {
        // 0.002
        // 0.243
        // 0.27
        foreach ($recipeinputs as $recipeinput) {
            // 0.002 * 10 = 0.02  0.02 - 0 = 0.02 > 0.0
            // 0.243 * 10 = 2.43  2.43 - 2 = 0.43 > 0.0
            // 0.27 * 10  = 2.7  2.7 - 2 = 0.7 > 0.0
            // if($recipeinput->IsCoffee){
            //     echo "$recipeinput->TotalQty * 1 - (int)($recipeinput->TotalQty * 1) ".$recipeinput->TotalQty * 1 ." - ". (int)($recipeinput->TotalQty * 1)."=".$recipeinput->TotalQty * 1 - (int)($recipeinput->TotalQty * 1) ."<br/>";
            // }
            if ($recipeinput->IsCoffee and $decplaces == 1 and $recipeinput->TotalQty * 1 - (int)($recipeinput->TotalQty * 1) == 0.0) {
                $decplaces = 0;
            }
        }
    }
    //echo $decplaces."<br/>";

    ?>
    <?php foreach ($recipeinputs as $recipeinput): ?>
        <?php
        if ($recipeinput->InputTypeID != $currentinputtypeid) {
            $currentinputtypeid = $recipeinput->InputTypeID;
            echo "<div class='recipes-inputtypes' style='grid-column: 1 / span 3;
                    background-color:$recipe->BodyColour; border-style:solid; 
                    border-color:$recipe->HeaderColour; border-width:0.5px;'>$recipeinput->InputType</div>";
        }
        ?>
        <div class="<?= $inputcss ?> recipes-input-inputname">
            <?= $recipeinput->InputName ?>
        </div>
        <div class="<?= $inputcss ?> recipes-input-qty">
            <?= $recipeinput->IsCoffee ? number_format($recipeinput->Qty, 0)." g" : number_format($recipeinput->Qty, 0)  ?>
        </div>
        <div class="<?= $inputcss ?> recipes-input-qty">
            <?= $recipeinput->IsCoffee ? number_format($recipeinput->TotalQty, $decplaces)." Kg" : number_format($recipeinput->TotalQty, 0) ?>
        </div>
        <?php $inputcss == 'recipes-inputs-odd' ? $inputcss = 'recipes-inputs-even' : $inputcss = 'recipes-inputs-odd'; ?>
    <?php endforeach; ?>
</div>
<div id="recipes-summary" style="display: grid; gap: 1rem; grid-template-columns:30px repeat(5,1fr); background-color:<?= $recipe->FooterColour ?>">

</div>