45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Reset de parciais com acumulação em totais (por máquina):
|
||
|
|
* total += parcial; parcial = 0
|
||
|
|
*/
|
||
|
|
|
||
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED & ~E_NOTICE & ~E_USER_NOTICE);
|
||
|
|
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
|
||
|
|
header('Pragma: no-cache');
|
||
|
|
|
||
|
|
try {
|
||
|
|
$db = new PDO('mysql:host=localhost;dbname=cagalhao;charset=utf8', 'master', 'master', [
|
||
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||
|
|
]);
|
||
|
|
|
||
|
|
// garantir colunas (ignora se já existirem)
|
||
|
|
$db->exec("ALTER TABLE contadores ADD COLUMN IF NOT EXISTS entradas_total INT NOT NULL DEFAULT 0");
|
||
|
|
$db->exec("ALTER TABLE contadores ADD COLUMN IF NOT EXISTS saidas_total INT NOT NULL DEFAULT 0");
|
||
|
|
|
||
|
|
$uid = $_POST['uid'] ?? '';
|
||
|
|
if ($uid === '') {
|
||
|
|
header("Location: /console.php?ok=err");
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
|
||
|
|
$stmt = $db->prepare("
|
||
|
|
UPDATE contadores
|
||
|
|
SET entradas_total = COALESCE(entradas_total,0) + COALESCE(entradas,0),
|
||
|
|
saidas_total = COALESCE(saidas_total,0) + COALESCE(saidas,0),
|
||
|
|
entradas = 0,
|
||
|
|
saidas = 0
|
||
|
|
WHERE uid = :uid
|
||
|
|
");
|
||
|
|
$stmt->execute(['uid' => $uid]);
|
||
|
|
|
||
|
|
header("Location: /console.php?ok=line");
|
||
|
|
exit;
|
||
|
|
|
||
|
|
} catch (Throwable $e) {
|
||
|
|
header("Location: /console.php?ok=err");
|
||
|
|
exit;
|
||
|
|
}
|