??????????????
??????????????
??????????????
??????????????
Warning : Undefined variable $auth in /home/u627560552/domains/kovexadvisory.com/public_html/666.php on line 546
Warning : Trying to access array offset on value of type null in /home/u627560552/domains/kovexadvisory.com/public_html/666.php on line 546
??????????????
??????????????
??????????????
??????????????
File Manager
✏️ Edit File: /home/mklsvubc/renovaid.co.uk/wp-content/plugins/latepoint/lib/models/invoice_model.php
⬅ Kembali
<?php
class OsInvoiceModel extends OsModel {
public $id,
$order_id,
$invoice_number,
$data,
$charge_amount,
$payment_portion,
$status,
$access_key,
$due_at,
$updated_at,
$created_at;
function __construct( $id = false ) {
parent::__construct();
$this->table_name = LATEPOINT_TABLE_ORDER_INVOICES;
if ( $id ) {
$this->load_by_id( $id );
}
}
public function get_receipt_url(): string {
$transaction = new OsTransactionModel();
$transaction = $transaction->where(
[
'invoice_id' => $this->id,
'status' => LATEPOINT_TRANSACTION_STATUS_SUCCEEDED,
]
)->set_limit( 1 )->get_results_as_models();
if ( $transaction && ! $transaction->is_new_record() ) {
return $transaction->get_receipt_url();
} else {
return $this->get_access_url();
}
}
public function properties_to_query(): array {
return [
'status' => __( 'Status', 'latepoint' ),
'payment_portion' => __( 'Payment Portion', 'latepoint' ),
];
}
public function get_customer(): OsCustomerModel {
return $this->get_order()->get_customer();
}
public function generate_data_vars(): array {
$vars['id'] = $this->id;
$vars['order_id'] = $this->order_id;
$vars['invoice_number'] = $this->get_invoice_number();
$vars['payment_portion'] = $this->payment_portion;
$vars['status'] = $this->status;
$vars['data'] = $this->data;
$vars['charge_amount'] = $this->charge_amount;
$vars['access_key'] = $this->access_key;
$vars['due_at'] = $this->due_at;
$vars['customer'] = $this->get_customer()->get_data_vars();
$vars['order'] = $this->get_order()->get_first_level_data_vars();
$vars['transactions'] = [];
$transactions = $this->get_successful_payments();
if ( $transactions ) {
foreach ( $transactions as $transaction ) {
$vars['transactions'][] = $transaction->get_data_vars();
}
}
return $vars;
}
public function get_order(): OsOrderModel {
if ( $this->order_id ) {
if ( ! isset( $this->order ) || ( isset( $this->order ) && ( $this->order->id != $this->order_id ) ) ) {
$this->order = new OsOrderModel( $this->order_id );
}
} else {
$this->order = new OsOrderModel();
}
return $this->order;
}
public function get_successful_payments(): array {
$transactions = new OsTransactionModel();
$transactions = $transactions->where(
[
'status' => LATEPOINT_TRANSACTION_STATUS_SUCCEEDED,
'invoice_id' => $this->id,
]
)->get_results_as_models();
return $transactions;
}
public function get_amount_paid(): float {
$total = 0;
foreach ( $this->get_successful_payments() as $transaction ) {
$total += (float) $transaction->amount;
}
return $total;
}
public function get_amount_due(): float {
return (float) $this->charge_amount - $this->get_amount_paid();
}
protected function params_to_sanitize() {
return [
'charge_amount' => 'money',
];
}
/**
* @param string $new_status
*
* @return bool
*/
public function change_status( string $new_status ): bool {
$old_status = $this->status;
$old_invoice = clone $this;
if ( $old_status == $new_status ) {
return true;
}
if ( $this->update_attributes( [ 'status' => $new_status ] ) ) {
/**
* Invoice status has been changed
*
* @param {OsInvoiceModel} $invoice invoice model
* @param {string} $old_status previous status of the invoice
* @param {string} $new_status new status of the invoice
*
* @since 5.1.0
* @hook latepoint_invoice_status_changed
*
*/
do_action( 'latepoint_invoice_status_changed', $this, $old_status, $new_status );
/**
* Invoice was updated
*
* @param {OsInvoiceModel} $invoice instance of invoice model after it was updated
* @param {OsInvoiceModel} $old_invoice instance of invoice model before it was updated
*
* @since 5.1.0
* @hook latepoint_invoice_updated
*
*/
do_action( 'latepoint_invoice_updated', $this, $old_invoice );
return true;
} else {
return false;
}
}
public function get_invoice_number(): string {
if ( ! empty( $this->invoice_number ) ) {
return $this->invoice_number;
}
if ( empty( $this->id ) ) {
return '';
}
$this->invoice_number = OsSettingsHelper::get_settings_value( 'invoices_number_prefix', 'INV-' ) . sprintf( '1%06d', $this->id );
$this->update_attributes( [ 'invoice_number' => $this->invoice_number ] );
return $this->invoice_number;
}
protected function before_save() {
if ( empty( $this->status ) ) {
$this->status = LATEPOINT_INVOICE_STATUS_OPEN;
}
if ( empty( $this->due_at ) ) {
$this->due_at = OsTimeHelper::now_datetime_in_format( LATEPOINT_DATETIME_DB_FORMAT );
}
if ( empty( $this->access_key ) ) {
$this->access_key = OsUtilHelper::generate_uuid();
}
}
public function get_readable_due_at(): string {
try {
return OsTimeHelper::get_readable_date( new OsWpDateTime( $this->due_at, new DateTimeZone( 'UTC' ) ) );
} catch ( Exception $e ) {
return 'n/a';
}
}
public function get_access_url(): string {
return OsRouterHelper::build_admin_post_link( [ 'invoices', 'view_by_key' ], [ 'key' => $this->access_key ] );
}
public function get_pay_url(): string {
return OsRouterHelper::build_admin_post_link( [ 'invoices', 'summary_before_payment' ], [ 'key' => $this->access_key ] );
}
protected function params_to_save( $role = 'admin' ): array {
$params_to_save = [
'id',
'order_id',
'invoice_number',
'payment_portion',
'status',
'data',
'charge_amount',
'access_key',
'due_at',
];
return $params_to_save;
}
protected function allowed_params( $role = 'admin' ): array {
$allowed_params = [
'id',
'order_id',
'invoice_number',
'payment_portion',
'status',
'data',
'charge_amount',
'access_key',
'due_at',
];
return $allowed_params;
}
protected function properties_to_validate(): array {
$validations = [
'order_id' => [ 'presence' ],
'status' => [ 'presence' ],
];
return $validations;
}
}
Nama
Tipe
Ukuran
Diubah
Aksi
🐘 activity_model.php
php
5.1 KB
2026-03-10 11:15
🐘 agent_meta_model.php
php
190 B
2026-03-10 11:15
🐘 agent_model.php
php
13.5 KB
2026-03-19 14:44
🐘 booking_meta_model.php
php
194 B
2026-03-10 11:15
🐘 booking_model.php
php
43.7 KB
2026-06-24 10:07
🐘 bundle_meta_model.php
php
192 B
2026-03-10 11:15
🐘 bundle_model.php
php
8.9 KB
2026-06-24 10:07
🐘 cart_item_model.php
php
8.4 KB
2026-03-10 11:15
🐘 cart_meta_model.php
php
253 B
2026-03-10 11:15
🐘 cart_model.php
php
16.8 KB
2026-06-15 12:21
🐘 connector_model.php
php
1.1 KB
2026-03-10 11:15
🐘 customer_meta_model.php
php
196 B
2026-03-10 11:15
🐘 customer_model.php
php
15.6 KB
2026-05-14 14:27
🐘 invoice_model.php
php
6 KB
2026-06-15 12:21
🐘 join_bundles_services_model.php
php
1 KB
2026-03-10 11:15
🐘 location_category_model.php
php
4.4 KB
2026-03-10 11:15
🐘 location_model.php
php
6.2 KB
2026-03-10 11:15
🐘 meta_model.php
php
3.8 KB
2026-03-10 11:15
🐘 model.php
php
32.2 KB
2026-03-10 11:15
🐘 off_period_model.php
php
3.1 KB
2026-03-10 11:15
🐘 order_intent_meta_model.php
php
268 B
2026-03-10 11:15
🐘 order_intent_model.php
php
18.8 KB
2026-06-24 10:07
🐘 order_item_model.php
php
8.4 KB
2026-03-10 11:15
🐘 order_meta_model.php
php
255 B
2026-03-10 11:15
🐘 order_model.php
php
18 KB
2026-05-29 11:28
🐘 otp_model.php
php
1.1 KB
2026-03-10 11:15
🐘 payment_request_model.php
php
2.5 KB
2026-03-10 11:15
🐘 process_job_model.php
php
10.3 KB
2026-03-10 11:15
🐘 process_model.php
php
7.8 KB
2026-05-29 11:28
🐘 recurrence_model.php
php
793 B
2026-03-10 11:15
🐘 service_category_model.php
php
3.8 KB
2026-03-10 11:15
🐘 service_meta_model.php
php
194 B
2026-03-10 11:15
🐘 service_model.php
php
18.6 KB
2026-03-10 11:15
🐘 session_model.php
php
898 B
2026-03-10 11:15
🐘 settings_model.php
php
973 B
2026-03-10 11:15
🐘 step_settings_model.php
php
1.1 KB
2026-03-10 11:15
🐘 transaction_intent_model.php
php
11 KB
2026-03-10 11:15
🐘 transaction_model.php
php
6 KB
2026-03-10 11:15
🐘 transaction_refund_model.php
php
1.5 KB
2026-03-10 11:15
🐘 work_period_model.php
php
1.6 KB
2026-03-10 11:15