update logo
This commit is contained in:
parent
22ba99cda2
commit
391d782761
@ -559,9 +559,20 @@ function printThermalReceipt() {
|
||||
</div>
|
||||
|
||||
<script>
|
||||
window.onload = function() {
|
||||
let printed = false;
|
||||
function doPrint() {
|
||||
if (printed) return;
|
||||
printed = true;
|
||||
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>
|
||||
</body>
|
||||
|
||||
@ -17,16 +17,8 @@ try {
|
||||
$timezone = $settings['timezone'] ?? 'UTC';
|
||||
date_default_timezone_set($timezone);
|
||||
|
||||
$currentDate = date('Y-m-d');
|
||||
$currentTime = date('H:i:s');
|
||||
$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';
|
||||
if (!is_dir(dirname($lastReportFile))) {
|
||||
mkdir(dirname($lastReportFile), 0755, true);
|
||||
@ -34,11 +26,28 @@ try {
|
||||
|
||||
$lastReportDate = file_exists($lastReportFile) ? trim(file_get_contents($lastReportFile)) : '';
|
||||
|
||||
if ($lastReportDate === $currentDate) {
|
||||
echo json_encode(['status' => 'skipped', 'reason' => 'Already sent today']);
|
||||
$now = time();
|
||||
$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;
|
||||
}
|
||||
|
||||
$currentDate = $reportDateToRun;
|
||||
|
||||
// GENERATE REPORT
|
||||
$pdo = db();
|
||||
|
||||
|
||||
@ -981,9 +981,22 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
doc.write(html);
|
||||
doc.close();
|
||||
|
||||
// Print immediately without waiting for resources
|
||||
iframe.contentWindow.focus();
|
||||
iframe.contentWindow.print();
|
||||
let printed = false;
|
||||
function triggerPrint() {
|
||||
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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user