From cd158dae5fa01a25d9d85e1689d137980aecaa87 Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Tue, 20 Jan 2026 21:20:36 +0100 Subject: [PATCH] Added manual invoice locking cron script --- scripts/ManualInvoice/lock-invoices.php | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 scripts/ManualInvoice/lock-invoices.php diff --git a/scripts/ManualInvoice/lock-invoices.php b/scripts/ManualInvoice/lock-invoices.php new file mode 100644 index 000000000..45c195b97 --- /dev/null +++ b/scripts/ManualInvoice/lock-invoices.php @@ -0,0 +1,41 @@ +#!/usr/bin/php +id); +define("INTERNAL_USER_USERNAME", $me->username); + +// 05:30 11:30 17:30 + +$invoice_lock_days = TT_MANUALINVOICE_LOCK_DAYS; +$lock_treshold = date('U') - (86400*$invoice_lock_days); + +$invoices = ManualInvoiceModel::getAll(["lock" => 0, "create" => ["to" => $lock_treshold]]); +foreach($invoices as $invoice) { + /*echo "{$invoice->id}\t{$invoice->invoice_number}:\t"; + echo date("Y-m-d", $invoice->create); + echo "\n";*/ + + // unnessecary redundant date check + if($invoice->create > $lock_treshold) { + die(__FILE__.": Invoice {$invoice->invoice_number} ({$invoice->id}) has create date (".date("Y-m-d", $invoice->create).") after $invoice_lock_days days threshold.\n"); + } + + $invoice->lock = 1; + if(!$invoice->save()) { + die(__FILE__.": Error saving invoice.\n"); + } + +} + +echo "total ".count($invoices)." invoices locked with threshold date ".date("Y-m-d", $lock_treshold)."\n";