Skip to content

Commit

Permalink
Merge pull request #30 from mageplaza/2.3-develop
Browse files Browse the repository at this point in the history
2.3-develop
  • Loading branch information
Shinichi69 authored May 26, 2021
2 parents 29208ec + 1d25c69 commit 74a9393
Show file tree
Hide file tree
Showing 4 changed files with 274 additions and 233 deletions.
23 changes: 14 additions & 9 deletions Block/Dashboard/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ class Tax extends AbstractClass
*/
public function getTotal($includeContainer = true)
{
$total = 0;
$date = $this->_helperData->getDateRange();
$totals = $this->_helperData->getTotalsByDateRange($date[0], $date[1]);

return $this->getBaseCurrency()->format($totals->getTax() ?: 0, [], $includeContainer);
foreach ($totals->getItems() as $item) {
$total += $item->getTaxBaseAmountSum();
}

return $this->getBaseCurrency()->format($total, [], $includeContainer);
}

/**
Expand All @@ -62,19 +67,19 @@ public function getTotal($includeContainer = true)
public function getRate()
{
$dates = $this->_helperData->getDateRange();
$totals = $this->_helperData->getTotalsByDateRange($dates[0], $dates[1]);
$compareTotals = $this->_helperData->getTotalsByDateRange($dates[2], $dates[3]);
if ((int) $totals->getTax() === 0 && (int) $compareTotals->getTax() === 0) {
$totals = $this->_helperData->getTotalsByDateRange($dates[0], $dates[1])->getFirstItem();
$compareTotals = $this->_helperData->getTotalsByDateRange($dates[2], $dates[3])->getFirstItem();
if ((int) $totals->getTaxBaseAmountSum() === 0 && (int) $compareTotals->getTaxBaseAmountSum() === 0) {
return 0;
}
if ((int) $compareTotals->getTax() === 0) {
if ((int) $compareTotals->getTaxBaseAmountSum() === 0) {
return 100;
}
if ((int) $totals->getTax() === 0) {
if ((int) $totals->getTaxBaseAmountSum() === 0) {
return -100;
}

return round((($totals->getTax() - $compareTotals->getTax()) / $compareTotals->getTax()) * 100, 2);
return round((($totals->getTaxBaseAmountSum() - $compareTotals->getTaxBaseAmountSum()) / $compareTotals->getTaxBaseAmountSum()) * 100, 2);
}

/**
Expand All @@ -86,9 +91,9 @@ public function getRate()
*/
protected function getDataByDate($date, $endDate = null)
{
$totals = $this->_helperData->getTotalsByDateRange($date, $endDate);
$totals = $this->_helperData->getTotalsByDateRange($date, $endDate)->getFirstItem();

return round($totals->getTax() ?: 0, 2);
return round($totals->getTaxBaseAmountSum() ?: 0, 2);
}

/**
Expand Down
27 changes: 22 additions & 5 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Magento\Reports\Model\ResourceModel\Order\CollectionFactory;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Tax\Model\ResourceModel\Report\Collection as TaxCollection;
use Mageplaza\Core\Helper\AbstractData;

/**
Expand Down Expand Up @@ -252,6 +253,12 @@ public function addTimeFilter($collection, $startDate, $endDate = null)
{
[$startDate, $endDate] = $this->getDateTimeRangeFormat($startDate, $endDate, 1);

if ($this->_request->getParam('card_id') === 'tax') {
return $collection
->addFieldToFilter('period', ['gteq' => $startDate])
->addFieldToFilter('period', ['lteq' => $endDate]);
}

return $collection
->addFieldToFilter('created_at', ['gteq' => $startDate])
->addFieldToFilter('created_at', ['lteq' => $endDate]);
Expand Down Expand Up @@ -401,10 +408,16 @@ public function getTotalsByDateRange($startDate, $endDate)
|| $this->_request->getParam('website')
|| $this->_request->getParam('group');

/* @var $collection Collection */
$collection = $this->_orderCollectionFactory->create();
$collection = $this->addTimeFilter($collection, $startDate, $endDate);
$collection->checkIsLive('')->calculateTotals($isFilter);
if ($this->_request->getParam('card_id') === 'tax') {
/** @var TaxCollection $collection */
$collection = $this->createObject(TaxCollection::class);
$collection = $this->addTimeFilter($collection, $startDate, $endDate);
} else {
/* @var $collection Collection */
$collection = $this->_orderCollectionFactory->create();
$collection = $this->addTimeFilter($collection, $startDate, $endDate);
$collection->checkIsLive('')->calculateTotals($isFilter);
}

if ($this->_request->getParam('store')) {
$collection->addFieldToFilter('store_id', $this->_request->getParam('store'));
Expand All @@ -414,7 +427,7 @@ public function getTotalsByDateRange($startDate, $endDate)
} elseif ($this->_request->getParam('group')) {
$storeIds = $this->storeManager->getGroup($this->_request->getParam('group'))->getStoreIds();
$collection->addFieldToFilter('store_id', ['in' => $storeIds]);
} elseif (!$collection->isLive()) {
} elseif (method_exists($collection, 'isLive') && !$collection->isLive()) {
$collection->addFieldToFilter(
'store_id',
['eq' => $this->storeManager->getStore(Store::ADMIN_CODE)->getId()]
Expand All @@ -423,6 +436,10 @@ public function getTotalsByDateRange($startDate, $endDate)

$collection->load();

if ($this->_request->getParam('card_id') === 'tax') {
return $collection;
}

return $collection->getFirstItem();
}

Expand Down
52 changes: 26 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"name": "mageplaza/module-reports",
"description": "Magento 2 Reports Extension",
"require": {
"mageplaza/module-core": "^1.4.5"
},
"type": "magento2-module",
"version": "1.3.4",
"license": "proprietary",
"authors": [
{
"name": "Mageplaza",
"email": "[email protected]",
"homepage": "https://www.mageplaza.com",
"role": "Technical Support"
}
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Mageplaza\\Reports\\": ""
}
}
}
{
"name": "mageplaza/module-reports",
"description": "Magento 2 Reports Extension",
"require": {
"mageplaza/module-core": "^1.4.5"
},
"type": "magento2-module",
"version": "1.4.0",
"license": "proprietary",
"authors": [
{
"name": "Mageplaza",
"email": "[email protected]",
"homepage": "https://www.mageplaza.com",
"role": "Technical Support"
}
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Mageplaza\\Reports\\": ""
}
}
}
Loading

0 comments on commit 74a9393

Please sign in to comment.