WIP 2025-03-14 Preorder Billing
This commit is contained in:
@@ -37,6 +37,58 @@ class PreorderHistoryModel {
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
public static function getStatusChange($type = "first", $preorder_id, $status_code) {
|
||||
$status = PreorderstatusModel::getFirst(["code" => $status_code]);
|
||||
if(!$status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$status_id = $status->id;
|
||||
$sql = "SELECT * FROM PreorderHistory WHERE preorder_id = $preorder_id AND `key` = 'status_id' AND new_value = $status_id";
|
||||
if($type == "first") {
|
||||
$sql .= " ORDER BY id ASC LIMIT 1";
|
||||
} else {
|
||||
$sql .= " ORDER BY id DESC LIMIT 1";
|
||||
}
|
||||
//mfLoghandler::singleton()->debug($sql);
|
||||
$res = FronkDB::singleton()->query($sql);
|
||||
if(FronkDB::singleton()->num_rows($res)) {
|
||||
$data = FronkDB::singleton()->fetch_object($res);
|
||||
return new PreorderHistory($data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static function getFirstStatusChangeTo($preorder_id, $status_code) {
|
||||
return self::getStatusChange("first", $preorder_id, $status_code);
|
||||
}
|
||||
|
||||
public static function getLastStatusChangeTo($preorder_id, $status_code) {
|
||||
return self::getStatusChange("last", $preorder_id, $status_code);
|
||||
}
|
||||
|
||||
public static function getFirstStatusChangeToOrHigher($preorder_id, $status_code) {
|
||||
foreach(PreorderstatusModel::getAll() as $status) {
|
||||
if($status->code < $status_code) continue;
|
||||
|
||||
$change = self::getStatusChange("first", $preorder_id, $status_code);
|
||||
if($change) return $change;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getLastStatusChangeToOrHigher($preorder_id, $status_code) {
|
||||
foreach(PreorderstatusModel::getAll() as $status) {
|
||||
if($status->code < $status_code) continue;
|
||||
|
||||
$change = self::getStatusChange("last", $preorder_id, $status_code);
|
||||
if($change) return $change;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getFirst($filter = []) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user