<?php
/** @var \Magento\Sales\Block\Adminhtml\Order\Invoice\Totals $block */


$priceHelper = $this->helper('Magento\Framework\Pricing\Helper\Data');
/** @var \Magetop\Advancepreview\Helper\OrderHelper $previewOrderHelper */
$previewOrderHelper = $this->helper('\Magetop\Advancepreview\Helper\OrderHelper');
$invoice = $block->getSource();
?>
<?php if($invoice && $invoice->getId()) : ?>
<?php
$order = $invoice->getOrder();
$priceItem = 0;
if($order && $order->getItems()) {
    $items = $order->getItems();
    foreach ($items as $item) {
        if(!$previewOrderHelper->checkIncoiceAndItemId($invoice->getId(), $item->getId())) {
            continue;
        }
        $infoRequest = $previewOrderHelper->getPreviewOrderItemDetail($item);
        if (isset($infoRequest['txt_project_final_price'])) {
            $priceItem += round($infoRequest['txt_project_final_price'],2);
        }
    }
}

$_totals = $block->getTotals('footer')
?>
<table class="data-table admin__table-secondary order-subtotal-table">
    <?php if ($_totals) : ?>
        <tbody>
        <tr>
            <td>
                <?php echo __('Grand Total') ?>
            </td>
            <td>
                <b><?php echo $priceHelper->currency($priceItem,true, false); ?></b>
            </td>
        </tr>
        </tbody>
    <?php endif; ?>
</table>

<?php endif; ?>
