Files
thetool/scripts/ManualInvoice/lock-invoices.php
2026-01-20 21:20:36 +01:00

42 lines
1.3 KiB
PHP

#!/usr/bin/php
<?php
require("../../config/config.php");
define('FRONKDB_SQLDEBUG', false);
error_reporting(E_ALL & ~(E_NOTICE | E_STRICT | E_DEPRECATED));
require_once(LIBDIR."/mvcfronk/mfRouter/mfRouter.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseModel.php");
require_once(LIBDIR."/mvcfronk/mfBase/mfBaseController.php");
$layout = \Layout::singleton();
$me = new User(1);
define("INTERNAL_USER_ID", $me->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";