PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.27
Booktics – Appointment Booking Calendar for Service Businesses v1.0.27
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
← All changes | base/models/order-model.php +67 -1 1.0.2 → 1.0.27 View file →
@@ -25,13 +25,16 @@
25 25 'coupon_code',
26 26 'coupon_discount',
27 27 'subtotal',
28 28 'total',
29 + 'currency',
29 30 'payment_method',
30 31 'payment_intent_id',
31 32 'payment_transaction_id',
32 33 'created_at',
33 - 'updated_at'
34 + 'updated_at',
35 + 'custom_fields',
36 + 'directorist_id',
34 37 ];
35 38
36 39 /**
37 40 * Create a new order record
@@ -59,6 +62,69 @@
59 62 protected function generate_order_no() {
60 63 $randomNum = time();
61 64
62 65 return 'BKNG-' . $randomNum;
66 + }
67 +
68 + /**
69 + * Calculate total revenue for fully paid orders within a date range
70 + * Excludes canceled/cancelled orders
71 + *
72 + * @param string $start_date Start date (Y-m-d format)
73 + * @param string $end_date End date (Y-m-d format)
74 + * @param array $order_ids Optional array of order IDs to filter by
75 + *
76 + * @return float Total revenue
77 + */
78 + public function get_revenue_by_date_range( string $start_date, string $end_date, array $order_ids = array() ) {
79 + $query = $this->query()
80 + ->where( 'payment_status', '=', 'fully_paid' )
81 + ->where( 'status', '!=', 'canceled' )
82 + ->where( 'status', '!=', 'cancelled' )
83 + ->where( 'created_at', '>=', $start_date . ' 00:00:00' )
84 + ->where( 'created_at', '<=', $end_date . ' 23:59:59' );
85 +
86 + if ( ! empty( $order_ids ) ) {
87 + $query->where_in( 'id', $order_ids );
88 + }
89 +
90 + $sum = $query->sum( 'total' );
91 +
92 + // Additional safety check to ensure we always return a valid float
93 + if ( !is_numeric( $sum ) || !is_finite( $sum ) ) {
94 + return 0.0;
95 + }
96 +
97 + return (float) $sum;
98 + }
99 +
100 + /**
101 + * Calculate revenue for a specific date range with custom filters
102 + *
103 + * @param string $start_date Start date (Y-m-d format)
104 + * @param string $end_date End date (Y-m-d format)
105 + * @param callable|null $additional_conditions Callback to add additional conditions to the query
106 + *
107 + * @return float Total revenue
108 + */
109 + public function get_revenue_with_conditions( string $start_date, string $end_date, ?callable $additional_conditions = null ) {
110 + $query = $this->query()
111 + ->where( 'payment_status', '=', 'fully_paid' )
112 + ->where( 'status', '!=', 'canceled' )
113 + ->where( 'status', '!=', 'cancelled' )
114 + ->where( 'created_at', '>=', $start_date . ' 00:00:00' )
115 + ->where( 'created_at', '<=', $end_date . ' 23:59:59' );
116 +
117 + if ( $additional_conditions && is_callable( $additional_conditions ) ) {
118 + $additional_conditions( $query );
119 + }
120 +
121 + $sum = $query->sum( 'total' );
122 +
123 + // Additional safety check to ensure we always return a valid float
124 + if ( !is_numeric( $sum ) || !is_finite( $sum ) ) {
125 + return 0.0;
126 + }
127 +
128 + return (float) $sum;
63 129 }
64 130 }