Added manual invoice locking cron script
This commit is contained in:
41
scripts/ManualInvoice/lock-invoices.php
Normal file
41
scripts/ManualInvoice/lock-invoices.php
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/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";
|
||||
Reference in New Issue
Block a user