prefix . 'gstlayer_documents'; } /** * Create or update tables via dbDelta. */ public static function create_tables() { global $wpdb; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $table = self::documents_table(); $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE {$table} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, order_id bigint(20) unsigned NOT NULL, doc_type varchar(20) NOT NULL DEFAULT 'invoice', fy varchar(5) NOT NULL, seq int(11) unsigned NOT NULL, number varchar(32) NOT NULL, issued_at datetime NOT NULL, buyer_gstin varchar(15) DEFAULT NULL, pos_code char(2) NOT NULL DEFAULT '', supply_type varchar(10) NOT NULL DEFAULT '', taxable decimal(14,2) NOT NULL DEFAULT 0, cgst decimal(14,2) NOT NULL DEFAULT 0, sgst decimal(14,2) NOT NULL DEFAULT 0, igst decimal(14,2) NOT NULL DEFAULT 0, cess decimal(14,2) NOT NULL DEFAULT 0, total decimal(14,2) NOT NULL DEFAULT 0, ref_doc_id bigint(20) unsigned DEFAULT NULL, source_id bigint(20) unsigned DEFAULT NULL, created_at datetime NOT NULL, PRIMARY KEY (id), UNIQUE KEY fy_type_seq (fy,doc_type,seq), KEY order_id (order_id), KEY source_id (source_id), KEY issued_at (issued_at) ) {$charset_collate};"; dbDelta( $sql ); } /** * Seed defaults without overwriting existing values. */ private static function set_defaults() { $defaults = array( 'gstlayer_supplier_type' => 'regular', 'gstlayer_pos_basis' => 'shipping', 'gstlayer_slabs' => '0,5,12,18,28', 'gstlayer_shipping_sac' => '996812', 'gstlayer_show_gstin_field' => 'yes', 'gstlayer_show_legal_name_field' => 'yes', 'gstlayer_invoice_prefix' => 'INV/', 'gstlayer_invoice_padding' => '4', 'gstlayer_invoice_fy_reset' => 'yes', 'gstlayer_invoice_issue_statuses' => array( 'processing', 'completed' ), 'gstlayer_remove_data_on_uninstall' => 'no', ); foreach ( $defaults as $key => $value ) { if ( false === get_option( $key, false ) ) { add_option( $key, $value ); } } // Supplier state defaults to the store base state when the store is in India. if ( false === get_option( 'gstlayer_state', false ) && function_exists( 'wc_get_base_location' ) ) { $base = wc_get_base_location(); if ( isset( $base['country'], $base['state'] ) && 'IN' === $base['country'] && '' !== $base['state'] ) { add_option( 'gstlayer_state', $base['state'] ); } } } }