#!/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";