update
This commit is contained in:
54
__tmp_diag.php
Normal file
54
__tmp_diag.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
require 'autoload/class.Env.php';
|
||||
Env::load('.env');
|
||||
$domain = Env::get('FAKTUROWNIA_API_DOMAIN');
|
||||
$token = Env::get('FAKTUROWNIA_API_TOKEN');
|
||||
$start = Env::get('FAKTUROWNIA_START_DATE');
|
||||
$base = strpos($domain, 'http') === 0 ? $domain : 'https://' . $domain;
|
||||
|
||||
function fetchAll($urlBase) {
|
||||
$all = [];
|
||||
for ($page = 1; $page <= 50; $page++) {
|
||||
$url = $urlBase . '&page=' . $page . '&per_page=100';
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
$body = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$arr = json_decode((string)$body, true);
|
||||
if (!is_array($arr) || count($arr) === 0) break;
|
||||
foreach ($arr as $row) $all[] = $row;
|
||||
if (count($arr) < 100) break;
|
||||
}
|
||||
return $all;
|
||||
}
|
||||
|
||||
$sales = fetchAll($base . '/invoices.json?api_token=' . urlencode($token));
|
||||
$costs = fetchAll($base . '/invoices.json?api_token=' . urlencode($token) . '&income=no');
|
||||
|
||||
$sf = [];
|
||||
foreach ($sales as $doc) {
|
||||
$date = isset($doc['sell_date']) && $doc['sell_date'] ? $doc['sell_date'] : (isset($doc['issue_date']) ? $doc['issue_date'] : '');
|
||||
if ($date && strtotime(substr($date,0,10)) >= strtotime($start)) $sf[] = $doc;
|
||||
}
|
||||
|
||||
$cf = [];
|
||||
foreach ($costs as $doc) {
|
||||
$date = isset($doc['sell_date']) && $doc['sell_date'] ? $doc['sell_date'] : (isset($doc['issue_date']) ? $doc['issue_date'] : '');
|
||||
if ($date && strtotime(substr($date,0,10)) >= strtotime($start)) $cf[] = $doc;
|
||||
}
|
||||
|
||||
echo 'sales_all=' . count($sales) . PHP_EOL;
|
||||
echo 'costs_all=' . count($costs) . PHP_EOL;
|
||||
echo 'sales_from_start=' . count($sf) . PHP_EOL;
|
||||
echo 'costs_from_start=' . count($cf) . PHP_EOL;
|
||||
|
||||
echo "-- sales_from_start --" . PHP_EOL;
|
||||
foreach ($sf as $d) {
|
||||
echo $d['id'] . ' | ' . ($d['number'] ?? '-') . ' | ' . ($d['sell_date'] ?? '-') . ' | ' . ($d['issue_date'] ?? '-') . PHP_EOL;
|
||||
}
|
||||
|
||||
echo "-- costs_from_start --" . PHP_EOL;
|
||||
foreach ($cf as $d) {
|
||||
echo $d['id'] . ' | ' . ($d['number'] ?? '-') . ' | ' . ($d['sell_date'] ?? '-') . ' | ' . ($d['issue_date'] ?? '-') . PHP_EOL;
|
||||
}
|
||||
Reference in New Issue
Block a user