-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b30e571
commit 3793ae3
Showing
8 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace Ibertrand\BankSync\Block\Adminhtml; | ||
|
||
use Magento\Backend\Block\Widget\Container; | ||
use Magento\Backend\Block\Widget\Context; | ||
use Magento\Framework\Registry; | ||
use Magento\Sales\Model\EntityInterface; | ||
use Magento\Sales\Model\Order\Invoice; | ||
|
||
class DunningBlockButton extends Container | ||
{ | ||
/** | ||
* Core registry | ||
* | ||
* @var Registry | ||
*/ | ||
protected Registry $coreRegistry; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Registry $registry | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Registry $registry, | ||
array $data = [], | ||
) { | ||
$this->coreRegistry = $registry; | ||
parent::__construct($context, $data); | ||
} | ||
|
||
protected function _construct() | ||
{ | ||
$this->addButton( | ||
'banksync_block_dunning_button', | ||
[ | ||
'label' => $this->getLabel(), | ||
'class' => 'dunning_block', | ||
'onclick' => "setLocation('{$this->getTargetUrl()}')", | ||
] | ||
); | ||
|
||
parent::_construct(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getLabel(): string | ||
{ | ||
return __( | ||
$this->invoiceIsBlocked() ? 'Remove dunning block' : 'Dunning block' | ||
); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
protected function invoiceIsBlocked(): bool | ||
{ | ||
return !empty($this->getInvoice()->getBanksyncDunningBlockedAt()); | ||
} | ||
|
||
/** | ||
* @return Invoice | ||
*/ | ||
protected function getInvoice(): EntityInterface | ||
{ | ||
return $this->coreRegistry->registry('current_invoice'); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getTargetUrl(): string | ||
{ | ||
$setBlocked = $this->invoiceIsBlocked() ? 0 : 1; | ||
return $this->getUrl("banksync/dunning/block", ['invoice_id' => $this->getInvoiceId(), 'set_blocked' => $setBlocked]); | ||
} | ||
|
||
/** | ||
* @return integer | ||
*/ | ||
protected function getInvoiceId(): int | ||
{ | ||
return $this->getInvoice()->getId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Ibertrand\BankSync\Controller\Adminhtml\Dunning; | ||
|
||
use Ibertrand\BankSync\Logger\Logger; | ||
use Magento\Backend\App\Action; | ||
use Magento\Backend\App\Action\Context; | ||
use Magento\Framework\Controller\Result\Redirect; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Framework\Exception\InputException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Sales\Model\Order\InvoiceRepository; | ||
|
||
class Block extends Action | ||
{ | ||
const ADMIN_RESOURCE = 'Ibertrand_BankSync::sub_menu_dunnings'; | ||
private InvoiceRepository $invoiceRepository; | ||
private Logger $logger; | ||
|
||
/** | ||
* @param Context $context | ||
* @param InvoiceRepository $invoiceRepository | ||
* @param Logger $logger | ||
*/ | ||
public function __construct(Context $context, InvoiceRepository $invoiceRepository, Logger $logger) | ||
{ | ||
parent::__construct($context); | ||
$this->invoiceRepository = $invoiceRepository; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @return Redirect | ||
* @throws NoSuchEntityException | ||
* @throws InputException | ||
*/ | ||
public function execute() | ||
{ | ||
$invoiceId = $this->getRequest()->getParam('invoice_id'); | ||
$setBlocked = !empty($this->getRequest()->getParam('set_blocked')); | ||
|
||
$invoice = $this->invoiceRepository->get($invoiceId); | ||
if ($setBlocked) { | ||
$this->logger->info('Invoice ' . $invoice->getIncrementId() . ' blocked for dunning'); | ||
$invoice->setBanksyncDunningBlockedAt(date('Y-m-d H:i:s')); | ||
} else { | ||
$this->logger->info('Invoice ' . $invoice->getIncrementId() . ' unblocked for dunning'); | ||
$invoice->setBanksyncDunningBlockedAt(null); | ||
} | ||
$this->invoiceRepository->save($invoice); | ||
|
||
$redirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); | ||
$redirect->setPath('sales/invoice/view', ['invoice_id' => $invoiceId]); | ||
|
||
return $redirect; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> | ||
<module name="Ibertrand_BankSync" setup_version="0.0.20"> | ||
<module name="Ibertrand_BankSync" setup_version="0.0.21"> | ||
</module> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceBlock name="page.actions.toolbar"> | ||
<block class="Ibertrand\BankSync\Block\Adminhtml\DunningBlockButton" as="banksync_block_dunning_button"/> | ||
</referenceBlock> | ||
</body> | ||
</page> |