/**
  * Initialize partial payment related totals (if exist).
  *
  * @return $this
  */
 public function initTotals()
 {
     /** @var \Magento\Sales\Block\Adminhtml\Order\Totals $parent */
     $parent = $this->getParentBlock();
     /** @var \Magento\Sales\Model\Order $order */
     $order = $parent->getOrder();
     $orderId = $order->getId();
     $found = $this->repoPartialSale->getById($orderId);
     if ($found) {
         $baseAmount = $found->getBasePartialAmount();
         $amount = $found->getPartialAmount();
         $total = new \Magento\Framework\DataObject(['code' => 'praxigento_wallet', 'strong' => true, 'base_value' => $baseAmount, 'value' => $amount, 'label' => __('Paid by eWallet'), 'area' => 'footer', 'is_formated' => false]);
         $parent->addTotal($total);
         /* MOBI-497: fix 'due' amount */
         $totalDue = $parent->getTotal('due');
         if ($totalDue) {
             $due = $totalDue->getData('value');
             $dueBase = $totalDue->getData('base_value');
             $dueFixed = $due - $amount;
             $dueFixedBase = $dueBase - $baseAmount;
             $totalDue->setData('value', $dueFixed);
             $totalDue->setData('base_value', $dueFixedBase);
         }
     }
     return $this;
 }
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     parent::collect($invoice);
     $orderId = $invoice->getOrderId();
     $found = $this->repoPartialSale->getById($orderId);
     if ($found) {
         $partial = $found->getPartialAmount();
         $partialBase = $found->getBasePartialAmount();
         $grand = $invoice->getGrandTotal();
         $grandBase = $invoice->getBaseGrandTotal();
         $grandFixed = $grand - $partial;
         $grandFixedBase = $grandBase - $partialBase;
         $invoice->setGrandTotal($grandFixed);
         $invoice->setBaseGrandTotal($grandFixedBase);
         $invoice->setData(Cfg::CODE_TOTAL_PARTIAL_AMOUNT, $partial);
         $invoice->setData(Cfg::CODE_TOTAL_PARTIAL_AMOUNT_BASE, $partialBase);
     }
     return $this;
 }