3namespace Bitrix\Catalog\Integration\Report\Handler\StoreProfit;
5use Bitrix\Catalog\Integration\Report\Filter\StoreStockFilter;
6use Bitrix\Catalog\Integration\Report\Handler\BaseHandler;
7use Bitrix\Catalog\Integration\Report\StoreStock\StoreStockSale;
8use Bitrix\Currency\CurrencyManager;
13 private function getPriceAmounts():
array
28 foreach (
$fields as $key => $value)
30 $fields[$key] = \CCurrencyRates::convertCurrency($value,
$currency, $reportCurrency);
44 return \CCurrencyRates::convertCurrency($value,
$currency, $reportCurrency);
49 if (!Loader::includeModule(
'currency'))
54 return CurrencyManager::getBaseCurrency();
59 $storeTotals = parent::getStoreTotals();
60 if (empty($storeTotals))
65 $priceAmounts = $this->getPriceAmounts();
67 $formattedTotalsByPrices = $storeTotals;
68 foreach ($storeTotals as $storeId => $storeTotal)
72 'TOTAL_COST_PRICE' => 0
74 $storeTotal[
'TOTALS'] ??= [];
75 foreach ($storeTotal[
'TOTALS'] as $measureId =>
$fields)
77 foreach (
$fields as $fieldId => $value)
79 $total[$fieldId][$measureId] = $value;
83 $priceAmounts[$storeId] ??= [];
87 $total[
'TOTAL_SOLD'] ??= 0;
88 $total[
'TOTAL_SOLD'] +=
$fields[
'TOTAL_SOLD'];
89 $total[
'TOTAL_COST_PRICE'] ??= 0;
90 $total[
'TOTAL_COST_PRICE'] +=
$fields[
'COST_PRICE'];
93 $total[
'PROFIT'] = $total[
'TOTAL_SOLD'] - $total[
'TOTAL_COST_PRICE'];
94 $total[
'PROFITABILITY'] = $this->
calculateProfitability((
float)$total[
'TOTAL_COST_PRICE'], (
float)$total[
'PROFIT']);
95 $formattedTotalsByPrices[$storeId][
'TOTALS'] = $total;
98 return $formattedTotalsByPrices;
104 'STARTING_QUANTITY' => [],
105 'RECEIVED_QUANTITY' => [],
107 'QUANTITY_RESERVED_SUM' => [],
111 'TOTAL_COST_PRICE' => 0,
113 'PROFITABILITY' => 0,
116 foreach ($storeTotals as $storeTotalEntry)
118 foreach ($storeTotalEntry[
'TOTALS'] as $fieldName => $value)
120 if ($value && is_array($value))
122 $overallTotals[$fieldName] ??= [];
123 foreach ($value as $measureId => $measureItemValue)
125 $overallTotals[$fieldName][$measureId] ??= 0.0;
126 $overallTotals[$fieldName][$measureId] += $measureItemValue;
131 $overallTotals[$fieldName] ??= 0.0;
132 $overallTotals[$fieldName] += (float)$value;
137 $overallTotals[
'PROFITABILITY'] = $this->
calculateProfitability($overallTotals[
'TOTAL_COST_PRICE'], $overallTotals[
'PROFIT']);
139 return $overallTotals;
144 if ($costPrice <= 0 && $profit <= 0)
151 ? round($profit / $costPrice, 4)
155 return $profitability * 100;
160 return [
'=PRODUCT_ID' => StoreStockFilter::prepareProductFilter($productFilter)];
preparePrice(float $value, string $currency)
prepareOverallTotals(array $storeTotals)
preparePriceFields(array $fields, string $currency)
getProductFilter(array $productFilter)
calculateProfitability(float $costPrice, float $profit)
static getProductsSoldPricesForStores(array $filter=[])
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)