| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yatra\Database\Tables; |
| 4 |
|
| 5 |
/** |
| 6 |
* Discounts Table Class |
| 7 |
* |
| 8 |
* Represents the discounts table (wp_yatra_discounts) containing comprehensive |
| 9 |
* discount management data including promo codes, group discounts, |
| 10 |
* usage tracking, and advanced discount configurations. |
| 11 |
* |
| 12 |
* This table follows the new simplified pattern with only two static methods: |
| 13 |
* - getTableName(): Returns the prefixed table name |
| 14 |
* - getSchema(): Returns the complete CREATE TABLE SQL statement |
| 15 |
* |
| 16 |
* Usage: |
| 17 |
* DiscountsTable::getTableName() // Returns 'wp_yatra_discounts' |
| 18 |
* DiscountsTable::getSchema() // Returns complete SQL schema |
| 19 |
* |
| 20 |
* @package Yatra\Database\Tables |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
class DiscountsTable extends BaseTable |
| 24 |
{ |
| 25 |
/** |
| 26 |
* Table name without prefix |
| 27 |
* |
| 28 |
* @var string The base table name without WordPress prefix |
| 29 |
*/ |
| 30 |
protected static string $table = 'yatra_new_discounts'; |
| 31 |
|
| 32 |
/** |
| 33 |
* Get the complete table schema as raw SQL CREATE TABLE statement |
| 34 |
* |
| 35 |
* Returns the full SQL schema for the discounts table using heredoc syntax |
| 36 |
* for proper IDE syntax highlighting. Includes all columns, indexes, |
| 37 |
* and constraints from the original Database.php schema. |
| 38 |
* |
| 39 |
* @return string Complete CREATE TABLE SQL statement |
| 40 |
*/ |
| 41 |
public static function getSchema(): string |
| 42 |
{ |
| 43 |
$tableName = static::getTableName(); |
| 44 |
$charsetCollate = static::getCharsetCollate(); |
| 45 |
|
| 46 |
return <<<SQL |
| 47 |
CREATE TABLE IF NOT EXISTS `{$tableName}` ( |
| 48 |
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, |
| 49 |
`code` varchar(100) NOT NULL, |
| 50 |
`description` text, |
| 51 |
`type` varchar(20) NOT NULL DEFAULT 'percentage', |
| 52 |
`amount` decimal(10,2) NOT NULL DEFAULT 0.00, |
| 53 |
`max_discount_amount` decimal(10,2) DEFAULT NULL, |
| 54 |
`usage_limit` int(11) NOT NULL DEFAULT 0, |
| 55 |
`usage_limit_per_customer` int(11) DEFAULT 0, |
| 56 |
`usage_count` int(11) NOT NULL DEFAULT 0, |
| 57 |
`valid_from` datetime DEFAULT NULL, |
| 58 |
`expiry_date` datetime DEFAULT NULL, |
| 59 |
`status` varchar(20) DEFAULT 'draft', |
| 60 |
`applicable_to` varchar(20) DEFAULT 'all', |
| 61 |
`trip_ids` text DEFAULT NULL, |
| 62 |
`min_amount` decimal(10,2) DEFAULT NULL, |
| 63 |
`first_time_customer_only` tinyint(1) DEFAULT 0, |
| 64 |
`is_group_discount` tinyint(1) DEFAULT 0, |
| 65 |
`discount_mode` varchar(20) DEFAULT 'both' COMMENT 'promo, group, or both', |
| 66 |
`min_group_size` int(11) DEFAULT NULL, |
| 67 |
`max_group_size` int(11) DEFAULT NULL, |
| 68 |
`group_discount_type` varchar(20) DEFAULT 'percentage', |
| 69 |
`group_discount_amount` decimal(10,2) DEFAULT NULL, |
| 70 |
`group_discount_mode` varchar(20) DEFAULT 'total', |
| 71 |
`group_discount_ranges` longtext DEFAULT NULL, |
| 72 |
`category_discounts` longtext DEFAULT NULL, |
| 73 |
`created_at` datetime DEFAULT CURRENT_TIMESTAMP, |
| 74 |
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, |
| 75 |
`created_by` bigint(20) UNSIGNED NOT NULL DEFAULT 0, |
| 76 |
`updated_by` bigint(20) UNSIGNED NOT NULL DEFAULT 0, |
| 77 |
|
| 78 |
PRIMARY KEY (`id`), |
| 79 |
UNIQUE KEY `code` (`code`), |
| 80 |
KEY `type` (`type`), |
| 81 |
KEY `status` (`status`), |
| 82 |
KEY `valid_from` (`valid_from`), |
| 83 |
KEY `expiry_date` (`expiry_date`), |
| 84 |
KEY `created_by` (`created_by`) |
| 85 |
) {$charsetCollate} COMMENT='Discount codes and group discounts'; |
| 86 |
SQL; |
| 87 |
} |
| 88 |
} |
| 89 |
|