b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / Mrgig / MV / Helper /
Filename/home/dev2.destoffenstraat.com/app/code/Mrgig/MV/Helper/Data.php
Size7.66 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified23-Mar-2022 11:13
Last accessed22-Aug-2025 19:05
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

namespace Mrgig\MV\Helper;

use Magento\Framework\App\Helper\Context;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Locale\FormatInterface;
use Magento\Framework\Mail\Template\TransportBuilder;
use Mrgig\MV\Model\ResourceModel\Report\History as ReportHistory;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
const XML_PATH_ENABLE = 'mrgigmv/general/enable';

const XML_PATH_ENVIRONMENT = 'mrgigmv/general/environment';

const XML_PATH_API_URL = 'mrgigmv/general/api_url';

const XML_PATH_APP_ID = 'mrgigmv/general/app_id';

const XML_PATH_APP_SECRET = 'mrgigmv/general/app_secret';

const XML_PATH_APP_REDIRECT_URI = 'mrgigmv/general/redirect_uri';

const XML_PATH_APP_JOURNAL_ID = 'mrgigmv/general/journal_id';

const XML_PATH_APP_CUSTOMER_ACCOUNT_CODE = 'mrgigmv/general/customer_account_code';

const XML_PATH_APP_ACCOUNT_CODE = 'mrgigmv/general/account_code';

const XML_PATH_APP_TAX_ID = 'mrgigmv/general/tax_id';

const XML_PATH_APP_DATABASE = 'mrgigmv/general/database';

const XML_PATH_APP_CUSTOMER_GROUP_ID = 'mrgigmv/general/customer_group_id';

const XML_PATH_APP_REFRESH_TOKEN = 'mrgigmv/general/refresh_token';

const XML_PATH_EMAIL_REPORT_ADDRESS = 'mrgigmv/email_report/address';

const XML_PATH_EMAIL_REPORT_EMAIL_TEMPLATE = 'mrgigmv/email_report/email_template';

protected $storeManager;

protected $serializer;

protected $format;

protected $_accountCode;

protected $_taxTd;

public function __construct(
Context $context,
StoreManagerInterface $storeManager,
Json $serializer,
FormatInterface $format,
TransportBuilder $transportBuilder,
ReportHistory $reportHistory,
ResourceConnection $resource
) {
parent::__construct($context);
$this->storeManager = $storeManager;
$this->serializer = $serializer;
$this->format = $format;
$this->transportBuilder = $transportBuilder;
$this->reportHistory = $reportHistory;
$this->resource = $resource;
}

public function getStore()
{
return $this->storeManager->getStore();
}

public function getConfigValue($path, $storeId = null)
{
$storeId = $storeId ? $storeId : $this->getStore()->getStoreId();
return $this->scopeConfig->getValue(
$path,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

public function isEnabled()
{
return $this->getConfigValue(self::XML_PATH_ENABLE);
}

public function getEnvironmentType()
{
return $this->getConfigValue(self::XML_PATH_ENVIRONMENT);
}

public function getApiUrl()
{
return $this->getConfigValue(self::XML_PATH_API_URL);
}

public function getAppId()
{
return $this->getConfigValue(self::XML_PATH_APP_ID);
}

public function getAppSecret()
{
return $this->getConfigValue(self::XML_PATH_APP_SECRET);
}

public function getRedirectUri()
{
return $this->getConfigValue(self::XML_PATH_APP_REDIRECT_URI);
}

public function getJournalId()
{
return $this->getConfigValue(self::XML_PATH_APP_JOURNAL_ID);
}

public function getCustomerAccountCode()
{
return $this->getConfigValue(self::XML_PATH_APP_CUSTOMER_ACCOUNT_CODE);
}

public function getDataBaseCode()
{
return $this->getConfigValue(self::XML_PATH_APP_DATABASE);
}

public function getCustomerGroupId()
{
$customerGroupId = $this->getConfigValue(self::XML_PATH_APP_CUSTOMER_GROUP_ID);
return explode(',', $customerGroupId);
}

public function getRefreshToken()
{
return $this->getConfigValue(self::XML_PATH_APP_REFRESH_TOKEN);
}

public function getEmailTemplate()
{
return $this->getConfigValue(self::XML_PATH_EMAIL_REPORT_EMAIL_TEMPLATE);
}

public function getEmailAddress()
{
return $this->getConfigValue(self::XML_PATH_EMAIL_REPORT_ADDRESS);
}

public function getMapping($config)
{
$data = [];
foreach (array_map('trim', explode("\n", $config)) as $_config) {
$section = array_map('trim', explode('=>', $_config));
if (count($section)!=2) {
continue;
}
$values = explode('#', $section[1]);
if (!$values) {
continue;
}

$data[] = [
'code' => (string)$section[0],
'value' => (string)$section[1],
];
}
return $data;
}

public function getAccountCode()
{
if (!is_array($this->_accountCode)) {
$config = (string)$this->getConfigValue(self::XML_PATH_APP_ACCOUNT_CODE);
$this->_accountCode = $this->getMapping($config);
}
return $this->_accountCode;
}

public function getTaxId()
{
if (!is_array($this->_taxTd)) {
$config = (string)$this->getConfigValue(self::XML_PATH_APP_TAX_ID);
$this->_taxTd = $this->getMapping($config);
}
return $this->_taxTd;
}

public function getAccountCodeArrayMapping($value){
$codes = $this->getAccountCode();
if(!empty($codes) && is_array($codes)){
foreach($codes as $code){
if(isset($code['value']) && $code['value'] == $value){
return $code['code'];
}
}
}
return 0;
}

public function getTaxIdArrayMapping($value){
$taxIds = $this->getTaxId();
if(!empty($taxIds) && is_array($taxIds)){
foreach($taxIds as $taxId){
if(isset($taxId['value']) && $taxId['value'] == $value){
return $taxId['code'];
}
}
}
return 0;
}

public function serialize($data)
{
return $this->serializer->serialize($data);
}

public function unserialize($data)
{
return $this->serializer->unserialize($data);
}

public function getSenderDetail($storeId)
{
$name = $this->getConfigValue(
'trans_email/ident_general/name',
$storeId
);
$email = $this->getConfigValue(
'trans_email/ident_general/email',
$storeId
);

$senderData = ['name' => $name, 'email' => $email];
return $senderData;
}

public function notifyEmail($storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID)
{
$sender = $this->getSenderDetail($storeId);
$addTo = $this->getEmailAddress();
$transport = $this->transportBuilder
->setTemplateIdentifier($this->getEmailTemplate())
->setTemplateOptions(
[
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
'store' => $storeId,
]
)
->setTemplateVars([])
->setFrom($sender)
->addTo($addTo, ScopeInterface::SCOPE_STORE);
$transport = $this->transportBuilder->getTransport();
return $transport->sendMessage();
}

public function getInvoiceIdFormated($incrementId)
{
if (strpos($incrementId, '0000') !== false) {
$newId = substr($incrementId, 5);
return '1'.$newId;
}
return $incrementId;
}

public function addComment($comment, $invoiceId)
{
$data = [
'invoice_id' => $invoiceId,
'comment' => $comment
];
$this->reportHistory->insertData($data);
}

public function updateStatus($status, $invoiceId)
{
$connection = $this->resource->getConnection();
$data = ['is_process' => $status];
$where = ['entity_id = ?' => (int)$invoiceId];

$tableName = $connection->getTableName('sales_invoice');
$connection->update($tableName, $data, $where);
}
}