Your IP : 216.73.216.170
<?
define("NOT_CHECK_PERMISSIONS", true);
if (!$_SERVER["DOCUMENT_ROOT"]) {
$_SERVER["DOCUMENT_ROOT"] = realpath(__DIR__ . '/');
} else {
// die ('Script for console only');
}
require_once $_SERVER["DOCUMENT_ROOT"] . '/local/composer/vendor/autoload.php';
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
use Bitrix\Main\Type\DateTime;
use Bitrix\Main\Loader;
use Bitrix\Highloadblock\HighloadBlockTable as HLBT;
use Bitrix\Disk\Security\DiskSecurityContext;
use Bitrix\Disk\Security\SecurityContext;
use Bitrix\Disk\Storage;
use Bitrix\Main\Localization\Loc;
use duzun\hQuery;
use Bitrix\Main\IO\File;
$APPLICATION->SetTitle("Тест ФНС");
//
$baseDir = $_SERVER['DOCUMENT_ROOT'] . '/fns_count_data/';
$subDir = 'incomes';
$currentDir = $baseDir . $subDir . '/';
$helper = new HighloadBlockHelper(24);
$allXmls = glob($currentDir . '*.xml');
$list = $helper->getList(['filter' => [], 'select' => ['ID', 'UF_INN']]);
$existing = $newValues = [];
while ($item = $list->fetch()) {
$existing[$item['UF_INN']] = $item['ID'];
}
$counter = 0;
foreach ($allXmls as $currentXml) {
$sxe = new SimpleXMLElement(File::getFileContents($currentXml));
// okp($currentXml);
foreach ($sxe->{'Документ'} as $document) {
// okp($document);
// break;
$inn = (string)$document->{'СведНП'}['ИННЮЛ'];
$incomes = (string)$document->{'СведДохРасх'}['СумДоход'];
$expenses = (string)$document->{'СведДохРасх'}['СумРасход'];
$revenue = $incomes - $expenses;
$id = $existing[$inn];
$fields = [
'UF_INCOME' => $incomes,
'UF_EXPENSES' => $expenses,
'UF_REVENUE' => $revenue,
];
// okp($fields);
// break;
if (!$id) {
continue;
} else {
$newValues[$id] = $fields;
// okp($id . ': ' . $workers);
// $helper->update($id, $fields);
// ++$counter;
}
}
}
$counter = 0;
foreach ($newValues as $id => $fields) {
$helper->update($id, $fields);
if (++$counter % 10000 == 0) {
oklog($counter, '__incomes_update');
}
}
//oklog($newValues, '___new_values');
/*
$baseDir = $_SERVER['DOCUMENT_ROOT'] . '/fns_count_data/';
$subDir = 'rmsp';
$currentDir = $baseDir . $subDir . '/';
$helper = new HighloadBlockHelper(24);
$allXmls = glob($currentDir . '*.xml');
$counter = 0;
foreach ($allXmls as $currentXml) {
$sxe = new SimpleXMLElement(File::getFileContents($currentXml));
okp($currentXml);
foreach ($sxe->{'Документ'} as $document) {
$inn = (string)$document->{'ОргВклМСП'}['ИННЮЛ'];
$ipInn = (string)$document->{'ИПВклМСП'}['ИННФЛ'];
if ($ipInn) {
continue;
}
$region = (string)$document->{'СведМН'}->{'Регион'}['Наим'] . ' ' . (string)$document->{'СведМН'}->{'Регион'}['Тип'];
$name = (string)$document->{'ОргВклМСП'}['НаимОрг'];
$okveds = $document->{'СвОКВЭД'};
$mainOkved = mb_substr((string)$okveds->{'СвОКВЭДОсн'}['КодОКВЭД'], 0, 3);
$okvedArray = [];
foreach ($okveds->{'СвОКВЭДДоп'} as $subOkved) {
$okvedArray[] = mb_substr((string)$subOkved['КодОКВЭД'], 0, 3);
}
if (!in_array('63.', $okvedArray)) {
continue;
}
$fields = [
'UF_INN' => $inn,
'UF_REGION' => $region,
'UF_NAME' => $name,
];
$helper->add($fields);
}
}
*/?>