update logo
This commit is contained in:
parent
22ba99cda2
commit
391d782761
@ -559,9 +559,20 @@ function printThermalReceipt() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.onload = function() {
|
let printed = false;
|
||||||
|
function doPrint() {
|
||||||
|
if (printed) return;
|
||||||
|
printed = true;
|
||||||
window.print();
|
window.print();
|
||||||
setTimeout(function() { window.close(); }, 1500);
|
setTimeout(function() { window.close(); }, 500);
|
||||||
|
}
|
||||||
|
var img = document.querySelector('img');
|
||||||
|
if (img && !img.complete) {
|
||||||
|
img.onload = doPrint;
|
||||||
|
img.onerror = doPrint;
|
||||||
|
setTimeout(doPrint, 1500); // Fallback
|
||||||
|
} else {
|
||||||
|
doPrint();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@ -17,16 +17,8 @@ try {
|
|||||||
$timezone = $settings['timezone'] ?? 'UTC';
|
$timezone = $settings['timezone'] ?? 'UTC';
|
||||||
date_default_timezone_set($timezone);
|
date_default_timezone_set($timezone);
|
||||||
|
|
||||||
$currentDate = date('Y-m-d');
|
|
||||||
$currentTime = date('H:i:s');
|
|
||||||
$reportTime = $settings['whatsapp_report_time'];
|
$reportTime = $settings['whatsapp_report_time'];
|
||||||
|
|
||||||
// Check if it's past the report time
|
|
||||||
if ($currentTime < $reportTime) {
|
|
||||||
echo json_encode(['status' => 'skipped', 'reason' => 'Not time yet', 'time' => $currentTime, 'target' => $reportTime]);
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$lastReportFile = __DIR__ . '/../storage/last_daily_report.txt';
|
$lastReportFile = __DIR__ . '/../storage/last_daily_report.txt';
|
||||||
if (!is_dir(dirname($lastReportFile))) {
|
if (!is_dir(dirname($lastReportFile))) {
|
||||||
mkdir(dirname($lastReportFile), 0755, true);
|
mkdir(dirname($lastReportFile), 0755, true);
|
||||||
@ -34,11 +26,28 @@ try {
|
|||||||
|
|
||||||
$lastReportDate = file_exists($lastReportFile) ? trim(file_get_contents($lastReportFile)) : '';
|
$lastReportDate = file_exists($lastReportFile) ? trim(file_get_contents($lastReportFile)) : '';
|
||||||
|
|
||||||
if ($lastReportDate === $currentDate) {
|
$now = time();
|
||||||
echo json_encode(['status' => 'skipped', 'reason' => 'Already sent today']);
|
$todayDate = date('Y-m-d', $now);
|
||||||
|
$targetTodayTime = strtotime($todayDate . ' ' . $reportTime);
|
||||||
|
|
||||||
|
$yesterdayDate = date('Y-m-d', strtotime('-1 day', $now));
|
||||||
|
$targetYesterdayTime = strtotime($yesterdayDate . ' ' . $reportTime);
|
||||||
|
|
||||||
|
$reportDateToRun = null;
|
||||||
|
|
||||||
|
if ($now >= $targetTodayTime && $lastReportDate !== $todayDate) {
|
||||||
|
$reportDateToRun = $todayDate;
|
||||||
|
} elseif ($now >= $targetYesterdayTime && $lastReportDate !== $yesterdayDate && $lastReportDate !== $todayDate) {
|
||||||
|
$reportDateToRun = $yesterdayDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$reportDateToRun) {
|
||||||
|
echo json_encode(['status' => 'skipped', 'reason' => 'No report due or already sent']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$currentDate = $reportDateToRun;
|
||||||
|
|
||||||
// GENERATE REPORT
|
// GENERATE REPORT
|
||||||
$pdo = db();
|
$pdo = db();
|
||||||
|
|
||||||
|
|||||||
@ -981,9 +981,22 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
doc.write(html);
|
doc.write(html);
|
||||||
doc.close();
|
doc.close();
|
||||||
|
|
||||||
// Print immediately without waiting for resources
|
let printed = false;
|
||||||
iframe.contentWindow.focus();
|
function triggerPrint() {
|
||||||
iframe.contentWindow.print();
|
if (printed) return;
|
||||||
|
printed = true;
|
||||||
|
iframe.contentWindow.focus();
|
||||||
|
iframe.contentWindow.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
const img = doc.querySelector('img');
|
||||||
|
if (img && !img.complete) {
|
||||||
|
img.onload = triggerPrint;
|
||||||
|
img.onerror = triggerPrint;
|
||||||
|
setTimeout(triggerPrint, 1500); // Fallback
|
||||||
|
} else {
|
||||||
|
triggerPrint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.printThermalReceipt = printThermalReceipt;
|
window.printThermalReceipt = printThermalReceipt;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user