# booktics/1.0.1/base/models/order-model.php

Booktics – Appointment Booking Calendar for Service Businesses, version 1.0.1. 64 lines.

- Page: https://pluginprobe.com/plugins/booktics/1.0.1/code/base/models/order-model.php
- Raw: https://pluginprobe.com/plugins/booktics/1.0.1/raw/base/models/order-model.php
- Modified: 2025-07-09T06:46:52+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/booktics/1.0.1/code/base/models/order-model.php#L10-L20`.

```php
<?php

namespace Booktics\Models;

use Booktics\Abstracts\Model;

/**
 * Class Order_Model
 *
 * Handles database operations for orders in the Booktics system.
 *
 * @package Booktics\Models
 */
class Order_Model extends Model {
    protected $table = 'booktics_orders';
    protected $fillable = [
        'id',
        'order_no',
        'customer_id',
        'customer_note',
        'status',
        'payment_status',
        'price_breakdown',
        'tax_total',
        'coupon_code',
        'coupon_discount',
        'subtotal',
        'total',
        'payment_method',
        'payment_intent_id',
        'payment_transaction_id',
        'created_at',
        'updated_at'
    ];

    /**
     * Create a new order record
     *
     * @param array $data Order data to be created
     *
     * @return mixed The created order record
     */
    public function create( array $data ) {
        if ( empty( $data['order_no'] ) ) {
            $data['order_no'] = $this->generate_order_no();
        }

        $data['price_breakdown'] = wp_json_encode( $data['price_breakdown'] );

        return parent::create( $data );
    }


    /**
     * Generate a unique order number
     *
     * @return string
     */
    protected function generate_order_no() {
        $randomNum = time();

        return 'BKNG-' . $randomNum;
    }
}
```
