

INSERT INTO `settings` (`id`, `store_id`, `category_id`, `name`, `code`, `type`, `value`, `default_value`, `description`, `is_active`) VALUES
(NULL, NULL, 6, 'Subcategory Font Size', 'pos_subcategory_font_size', 'number', '16', '16', 'Font size for subcategory text displayed in POS (in pixels, recommended: 14-20)', 1);



DROP TABLE IF EXISTS `zatca_config`;
CREATE TABLE IF NOT EXISTS `zatca_config` (
  `id` int NOT NULL AUTO_INCREMENT,
  `is_enabled` tinyint(1) DEFAULT '0',
  `invoice_format` enum('xml','pdf') DEFAULT 'pdf',
  `qr_code_size` int DEFAULT '150',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------
-- Table structure for table `zatca_invoices`
-- --------------------------------------------------------

DROP TABLE IF EXISTS `zatca_invoices`;
CREATE TABLE IF NOT EXISTS `zatca_invoices` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sale_id` int NOT NULL,
  `invoice_number` varchar(100) NOT NULL,
  `invoice_type` enum('standard','simplified') DEFAULT 'simplified',
  `invoice_date` datetime NOT NULL,
  `seller_vat` varchar(50) DEFAULT NULL,
  `buyer_vat` varchar(50) DEFAULT NULL,
  `buyer_name` varchar(255) DEFAULT NULL,
  `total_amount` decimal(10,2) NOT NULL,
  `tax_amount` decimal(10,2) NOT NULL,
  `amount_excluding_tax` decimal(10,2) NOT NULL,
  `qr_code_data` text,
  `qr_code_image_url` text,
  `invoice_data` text COMMENT 'Stores XML or JSON invoice data for compliance',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `sale_id` (`sale_id`),
  KEY `invoice_number` (`invoice_number`),
  KEY `invoice_date` (`invoice_date`),
  KEY `invoice_type` (`invoice_type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------
-- Add ZATCA Integration to setting_categories
-- --------------------------------------------------------

INSERT INTO `setting_categories` (`name`, `code`) VALUES
('ZATCA Integration', 'zatca_integration')
ON DUPLICATE KEY UPDATE `name` = VALUES(`name`);

-- --------------------------------------------------------
-- Insert default ZATCA configuration
-- --------------------------------------------------------

INSERT INTO `zatca_config` (`is_enabled`, `invoice_format`, `qr_code_size`) VALUES
(0, 'pdf', 150)
ON DUPLICATE KEY UPDATE `updated_at` = CURRENT_TIMESTAMP;
DROP TABLE IF EXISTS `zatca_config`;
CREATE TABLE IF NOT EXISTS `zatca_config` (
  `id` int NOT NULL AUTO_INCREMENT,
  `is_enabled` tinyint(1) DEFAULT '0',
  `invoice_format` enum('xml','pdf') DEFAULT 'pdf',
  `qr_code_size` int DEFAULT '150',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------
-- Table structure for table `zatca_invoices`
-- --------------------------------------------------------

DROP TABLE IF EXISTS `zatca_invoices`;
CREATE TABLE IF NOT EXISTS `zatca_invoices` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sale_id` int NOT NULL,
  `invoice_number` varchar(100) NOT NULL,
  `invoice_type` enum('standard','simplified') DEFAULT 'simplified',
  `invoice_date` datetime NOT NULL,
  `seller_vat` varchar(50) DEFAULT NULL,
  `buyer_vat` varchar(50) DEFAULT NULL,
  `buyer_name` varchar(255) DEFAULT NULL,
  `total_amount` decimal(10,2) NOT NULL,
  `tax_amount` decimal(10,2) NOT NULL,
  `amount_excluding_tax` decimal(10,2) NOT NULL,
  `qr_code_data` text,
  `qr_code_image_url` text,
  `invoice_data` text COMMENT 'Stores XML or JSON invoice data for compliance',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `sale_id` (`sale_id`),
  KEY `invoice_number` (`invoice_number`),
  KEY `invoice_date` (`invoice_date`),
  KEY `invoice_type` (`invoice_type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------
-- Add ZATCA Integration to setting_categories
-- --------------------------------------------------------

INSERT INTO `setting_categories` (`name`, `code`) VALUES
('ZATCA Integration', 'zatca_integration')
ON DUPLICATE KEY UPDATE `name` = VALUES(`name`);

-- --------------------------------------------------------
-- Insert default ZATCA configuration
-- --------------------------------------------------------

INSERT INTO `zatca_config` (`is_enabled`, `invoice_format`, `qr_code_size`) VALUES
(0, 'pdf', 150)
ON DUPLICATE KEY UPDATE `updated_at` = CURRENT_TIMESTAMP;


DROP TABLE IF EXISTS `zatca_config`;
CREATE TABLE IF NOT EXISTS `zatca_config` (
  `id` int NOT NULL AUTO_INCREMENT,
  `is_enabled` tinyint(1) DEFAULT '0',
  `invoice_format` enum('xml','pdf') DEFAULT 'pdf',
  `qr_code_size` int DEFAULT '150',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------
-- Table structure for table `zatca_invoices`
-- --------------------------------------------------------

DROP TABLE IF EXISTS `zatca_invoices`;
CREATE TABLE IF NOT EXISTS `zatca_invoices` (
  `id` int NOT NULL AUTO_INCREMENT,
  `sale_id` int NOT NULL,
  `invoice_number` varchar(100) NOT NULL,
  `invoice_type` enum('standard','simplified') DEFAULT 'simplified',
  `invoice_date` datetime NOT NULL,
  `seller_vat` varchar(50) DEFAULT NULL,
  `buyer_vat` varchar(50) DEFAULT NULL,
  `buyer_name` varchar(255) DEFAULT NULL,
  `total_amount` decimal(10,2) NOT NULL,
  `tax_amount` decimal(10,2) NOT NULL,
  `amount_excluding_tax` decimal(10,2) NOT NULL,
  `qr_code_data` text,
  `qr_code_image_url` text,
  `invoice_data` text COMMENT 'Stores XML or JSON invoice data for compliance',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY `sale_id` (`sale_id`),
  KEY `invoice_number` (`invoice_number`),
  KEY `invoice_date` (`invoice_date`),
  KEY `invoice_type` (`invoice_type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------
-- Add ZATCA Integration to setting_categories
-- --------------------------------------------------------

INSERT INTO `setting_categories` (`name`, `code`) VALUES
('ZATCA Integration', 'zatca_integration')
ON DUPLICATE KEY UPDATE `name` = VALUES(`name`);

-- --------------------------------------------------------
-- Insert default ZATCA configuration
-- --------------------------------------------------------

INSERT INTO `zatca_config` (`is_enabled`, `invoice_format`, `qr_code_size`) VALUES
(0, 'pdf', 150)
ON DUPLICATE KEY UPDATE `updated_at` = CURRENT_TIMESTAMP;

INSERT INTO `rights` (`id`, `name`, `description`, `category`) 
VALUES (52, 'ZATCA Sales Report', 'View ZATCA integrated sales report', 'Reports')
ON DUPLICATE KEY UPDATE 
    `name` = VALUES(`name`),
    `description` = VALUES(`description`),
    `category` = VALUES(`category`);

-- Assign ZATCA Sales Report right to Admin role (role_id = 1)
INSERT INTO `role_rights` (`role_id`, `right_id`) 
VALUES (1, 52)
ON DUPLICATE KEY UPDATE 
    `role_id` = VALUES(`role_id`), 
    `right_id` = VALUES(`right_id`);



ALTER TABLE `journal_entries` 
MODIFY COLUMN `source_type` 
enum('sale','purchase','purchase_return','expense','payment','receipt','adjustment','manual','opening_balance','quick_transaction') 
NOT NULL;


UPDATE `settings` SET `value` = 'www.itresources.com.pk', `default_value` = 'www.itresources.com.pk' WHERE `settings`.`id` = 25;