push final pentru astazi

This commit is contained in:
2025-12-12 09:36:20 +00:00
parent 85b8c1cdb5
commit 8d6ef37d52
30 changed files with 51 additions and 242 deletions

View File

@@ -1,45 +0,0 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
/**
* Rulare:
* php script.php --name=Daniel --amount=125.50
*/
function usage(): void {
echo "Usage: php script.php --name=NAME --amount=NUMBER\n";
exit(1);
}
$options = getopt("", ["name:", "amount:"]);
$name = $options["name"] ?? null;
$amount = $options["amount"] ?? null;
if ($name === null || $amount === null) {
usage();
}
if (!is_numeric($amount)) {
fwrite(STDERR, "Error: --amount must be numeric.\n");
exit(1);
}
$amount = (float)$amount;
$vatRate = 0.19; // TVA 19%
$vat = round($amount * $vatRate, 2);
$total = round($amount + $vat, 2);
$result = [
"name" => $name,
"amount" => $amount,
"vat" => $vat,
"total" => $total,
"time" => date("c"),
];
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . PHP_EOL;
// scrie și un log local
$logLine = $result["time"] . " | {$name} | amount={$amount} | vat={$vat} | total={$total}\n";
file_put_contents(__DIR__ . "/script.log", $logLine, FILE_APPEND);