Re: [Сценарий] Сервис УФНС России - Проверка кассового чека
Добавлено: Вт мар 29, 2022 2:28 pm
Обсуждение проекта
http://mjdm.ru/forum/
Код: Выделить всё
function printValues($arr) {
global $count;
global $values;
global $Obj;
global $DateTime;
global $Name;
global $Price;
global $Quantity;
global $Sum;
global $RetailPlace;
global $RetailPlaceAddress;
global $User;
global $Operator;
global $ShiftNumber;
if(!is_array($arr)){
die("ERROR: Input is not an array");
}
foreach($arr as $key=>$value){
if(is_array($value)){
printValues($value);
} else{
switch ($key) {
case "_id":
addClassObject("Purchases", $value);
$Obj=$value;
break;
case "dateTime":
sg($Obj . ".DateTime", $value);
break;
case "name":
sg($Obj . ".Name", $value);
break;
case "price":
sg($Obj . ".Price", substr_replace($value, '.', -2, 0));
break;
case "quantity":
sg($Obj . ".Quantity", $value);
break;
case "sum":
sg($Obj . ".Sum", substr_replace($value, '.', -2, 0));
break;
case "retailPlace":
sg($Obj . ".RetailPlace", $value);
break;
case "retailPlaceAddress":
sg($Obj . ".RetailPlaceAddress", $value);
break;
case "user":
sg($Obj . ".User", $value);
break;
case "shiftNumber":
sg($Obj . ".ShiftNumber", $value);
break;
case "operator":
sg($Obj . ".Operator", $value);
break;
}
$values[] = $value;
$count++;
}
}
return array('total' => $count, 'values' => $values);
};
$json = file_get_contents('Checks.json');
$arr = json_decode($json, true);
$result = printValues($arr);
Код: Выделить всё
$json = file_get_contents('31_12_2023_06_29_441000534495.json');
$json= substr($json, 0, -1);
$json= substr($json, 1);
$data = json_decode($json, true);
$purchaseInfo = [
$Obj = $data['_id'],
$BuyerPhoneOrAddress = $data['ticket']['document']['receipt']['buyerPhoneOrAddress'],
$CashTotalSum = substr_replace($data['ticket']['document']['receipt']['cashTotalSum'], '.', -2, 0),
$ECashTotalSum = substr_replace($data['ticket']['document']['receipt']['ecashTotalSum'], '.', -2, 0),
$Date = substr($data['ticket']['document']['receipt']['dateTime'], 8, 2) . "." . substr($data['ticket']['document']['receipt']['dateTime'], 5, 2) . "." . substr($data['ticket']['document']['receipt']['dateTime'], 0, 4),
$Time = substr($data['ticket']['document']['receipt']['dateTime'], -8, 8),
$RetailPlace = $data['ticket']['document']['receipt']['retailPlace'],
$RetailPlaceAddress = $data['ticket']['document']['receipt']['retailPlaceAddress'],
$User = $data['ticket']['document']['receipt']['user'],
$ShiftNumber = $data['ticket']['document']['receipt']['shiftNumber'],
$Operator = $data['ticket']['document']['receipt']['operator']
];
addClassObject("Purchases", $Obj);
sg($Obj . ".Date", $Date);
echo "Дата: " . $Date . "<br>";
sg($Obj . ".Time", $Time);
echo "Время: " . $Time . "<br>";
echo "Чек: " . $Obj . "<br>";
sg($Obj . ".BuyerPhoneOrAddress", $BuyerPhoneOrAddress);
echo "Покупатель: " . $BuyerPhoneOrAddress . "<br>";
sg($Obj . ".CashTotalSum", $CashTotalSum);
echo "Сумма: " . $CashTotalSum . "<br>";
sg($Obj . ".ECashTotalSum", $ECashTotalSum);
echo "Эл. сумма: " . $ECashTotalSum . "<br>";
sg($Obj . ".DateTime", $DateTime);
echo "Дата: " . $DateTime . "<br>";
sg($Obj . ".Operator", $Operator);
echo "Оператор: " . $Operator . "<br>";
sg($Obj . ".RetailPlace", $RetailPlace);
echo "Место покупки: " . $RetailPlace . "<br>";
sg($Obj . ".RetailPlaceAddress", $RetailPlaceAddress);
echo "Адрес магазина: " . $RetailPlaceAddress . "<br>";
$i = 1;
$Name = "";
$Price = "";
$Quantity = "";
$Sum = "";
foreach ($data['ticket']['document']['receipt']['items'] as $index => $item) {
$purchaseInfo['items'][$index] = [
$Tovar= $item['name'],
$Tsena= substr_replace($item['price'], '.', -2, 0),
$Kolichestvo = $item['quantity'],
$Summa = substr_replace($item['sum'], '.', -2, 0)
];
echo "<hr>";
$Name = "Name" . $i;
sg($Obj . "." . $Name, $Tovar);
echo "Товар-" . $i . ": " . $Tovar . "<br>";
$Price = "Price" . $i;
sg($Obj . "." . $Price, $Tsena);
echo "Цена-" . $i . ": " . $Tsena . "<br>";
$Quantity = "Quantity" . $i;
sg($Obj . "." . $Quantity, $Kolichestvo);
echo "Количество-" . $i . ": " . $Kolichestvo . "<br>";
$Sum = "Sum" . $i;
sg($Obj . "." . $Sum, $Summa);
echo "Стоимость-" . $i . ": " . $Summa . "<br>";
$i = $i + 1;
}