diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php deleted file mode 100644 index 8a8cbc00..00000000 --- a/Setup/InstallSchema.php +++ /dev/null @@ -1,442 +0,0 @@ -startSetup(); - - /** - * Create table 'avatax_log' - */ - $table = $installer->getConnection(self::$connectionName) - ->newTable( - $installer->getTable('avatax_log') - ) - ->addColumn( - 'log_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'Log ID' - ) - ->addColumn( - 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], - 'Log Time' - ) - ->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false], - 'Store ID' - ) - ->addColumn( - 'level', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 20, - [], - 'Log Level' - ) - ->addColumn( - 'message', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [], - 'Message Being Logged' - ) - ->addColumn( - 'source', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [], - 'Code Source Reference' - ) - ->addColumn( - 'request', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '64k', - [], - 'Request' - ) - ->addColumn( - 'result', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '64k', - [], - 'Result' - ) - ->addColumn( - 'additional', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - '64k', - [], - 'Additional' - ) - ->addIndex( - $installer->getIdxName( - 'avatax_log', - ['created_at'], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX - ), - ['created_at'], - ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX] - ) - ->addIndex( - $installer->getIdxName( - 'avatax_log', - [ - 'level', - 'created_at' - ], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX - ), - [ - 'level', - 'created_at' - ], - ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX] - ) - ->setComment('AvaTax Log Table'); - $installer->getConnection(self::$connectionName)->createTable($table); - - /** - * Create table 'avatax_queue' - */ - $table = $installer->getConnection(self::$connectionName) - ->newTable( - $installer->getTable('avatax_queue') - ) - ->addColumn( - 'queue_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'Queue ID' - ) - ->addColumn( - 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], - 'Queue Time' - ) - ->addColumn( - 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - ['nullable' => true], - 'Updated Time' - ) - ->addColumn( - 'store_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false], - 'Store ID' - ) - ->addColumn( - 'entity_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false], - 'Entity Type ID' - ) - ->addColumn( - 'entity_type_code', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 50, - [], - 'Entity Type Code' - ) - ->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false], - 'Entity ID' - ) - ->addColumn( - 'increment_id', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 50, - [], - 'Increment ID' - ) - ->addColumn( - 'queue_status', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 50, - [], - 'Queue Status' - ) - ->addColumn( - 'attempts', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['nullable' => false, 'default' => 0], - 'Processing Attempts' - ) - ->addColumn( - 'message', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [], - 'Message' - ) - ->addIndex( - $installer->getIdxName( - 'avatax_queue', - [ - 'queue_status', - 'created_at', - 'updated_at' - ], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX - ), - [ - 'queue_status', - 'created_at', - 'updated_at' - ], - ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX] - ) - ->addIndex( - $installer->getIdxName( - 'avatax_log', - ['updated_at'], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX - ), - ['updated_at'], - ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX] - ) - ->addIndex( - $installer->getIdxName( - 'avatax_queue', - [ - 'entity_type_id', - 'entity_id' - ], - AdapterInterface::INDEX_TYPE_UNIQUE - ), - [ - 'entity_type_id', - 'entity_id' - ], - [ - 'type' => AdapterInterface::INDEX_TYPE_UNIQUE - ] - ) - ->setComment('AvaTax Queue Table'); - $installer->getConnection(self::$connectionName)->createTable($table); - - /** - * Create table 'avatax_sales_invoice' - */ - $table = $setup->getConnection(self::$connectionName) - ->newTable( - $setup->getTable('avatax_sales_invoice') - ) - ->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'Entity ID' - ) - ->addColumn( - 'parent_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 10, - [ - 'nullable' => false, - 'unsigned' => true, - ], - 'Sales Invoice ID' - ) - ->addColumn( - 'is_unbalanced', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - 1, - [ - 'nullable' => true, - 'default' => null, - 'unsigned' => true, - ], - 'Is Unbalanced In Relation To AvaTax Calculated Tax Amount' - ) - ->addColumn( - 'base_avatax_tax_amount', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - [ - 'nullable' => true, - 'default' => null, - 'unsigned' => false, - ], - 'Base AvaTax Calculated Tax Amount' - ) - ->addIndex( - $setup->getIdxName( - 'avatax_sales_invoice', - [ - 'entity_id', - 'parent_id' - ], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX - ), - [ - 'entity_id', - 'parent_id' - ], - ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX] - ) - ->addForeignKey( - $setup->getFkName( - 'avatax_sales_invoice_parent_id_sales_invoice_entity_id', - 'parent_id', - 'sales_invoice', - 'entity_id' - ), - 'parent_id', - $setup->getTable('sales_invoice'), - 'entity_id', - Table::ACTION_CASCADE - ) - ->setComment('AvaTax Sales Invoice Table'); - $setup->getConnection(self::$connectionName)->createTable($table); - - /** - * Create table 'avatax_sales_creditmemo' - */ - $table = $setup->getConnection(self::$connectionName) - ->newTable( - $setup->getTable('avatax_sales_creditmemo') - ) - ->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'Entity ID' - ) - ->addColumn( - 'parent_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 10, - [ - 'nullable' => false, - 'unsigned' => true, - ], - 'Sales Credit Memo ID' - ) - ->addColumn( - 'is_unbalanced', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - 1, - [ - 'nullable' => true, - 'default' => null, - 'unsigned' => true, - ], - 'Is Unbalanced In Relation To AvaTax Calculated Tax Amount' - ) - ->addColumn( - 'base_avatax_tax_amount', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - [ - 'nullable' => true, - 'default' => null, - 'unsigned' => false, - ], - 'Base AvaTax Calculated Tax Amount' - ) - ->addIndex( - $setup->getIdxName( - 'avatax_sales_creditmemo', - [ - 'entity_id', - 'parent_id' - ], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX - ), - [ - 'entity_id', - 'parent_id' - ], - ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX] - ) - ->addForeignKey( - $setup->getFkName( - 'avatax_sales_creditmemo_parent_id_sales_creditmemo_entity_id', - 'parent_id', - 'sales_creditmemo', - 'entity_id' - ), - 'parent_id', - $setup->getTable('sales_creditmemo'), - 'entity_id', - Table::ACTION_CASCADE - ) - ->setComment('AvaTax Sales Credit Memo Table'); - $setup->getConnection(self::$connectionName)->createTable($table); - - $installer->endSetup(); - } -} diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php deleted file mode 100644 index 71840638..00000000 --- a/Setup/UpgradeData.php +++ /dev/null @@ -1,259 +0,0 @@ -eavSetupFactory = $eavSetupFactory; - $this->customerSetupFactory = $customerSetupFactory; - $this->attributeSetFactory = $attributeSetupFactory; - } - - /** - * Upgrade scripts - * - * @param ModuleDataSetupInterface $setup - * @param ModuleContextInterface $context - * - * @throws \Exception - */ - public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) - { - $setup->startSetup(); - - /** - * \Magento\Eav\Setup\EavSetup $eavSetup - */ - $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); - - if (version_compare($context->getVersion(), '1.0.0', '<')) { - - // Only copy data and drop columns from "sales_invoice" if the columns exist - $tableName = $setup->getTable('sales_invoice'); - if ( - $setup->getConnection(self::$connectionName) - ->tableColumnExists($tableName, 'avatax_is_unbalanced') - && $setup->getConnection(self::$connectionName) - ->tableColumnExists($tableName, 'base_avatax_tax_amount') - ) { - // Copy any existing AvaTax data from core Invoice table into new AvaTax Invoice table - $select = $setup->getConnection(self::$connectionName)->select() - ->from( - $setup->getTable('sales_invoice'), - [ - 'entity_id', - 'avatax_is_unbalanced', - 'base_avatax_tax_amount' - ]) - ->where('base_avatax_tax_amount IS NOT NULL OR avatax_is_unbalanced IS NOT NULL'); - $select = $setup->getConnection(self::$connectionName)->insertFromSelect( - $select, - $setup->getTable('avatax_sales_invoice'), - [ - 'parent_id', - 'is_unbalanced', - 'base_avatax_tax_amount' - ] - ); - $setup->getConnection(self::$connectionName)->query($select); - - // Drop "avatax_is_unbalanced" column from "sales_invoice" table - $setup->getConnection(self::$connectionName) - ->dropColumn( - $setup->getTable('sales_invoice'), - 'avatax_is_unbalanced' - ); - - // Drop "base_avatax_tax_amount" column from "sales_invoice" table - $setup->getConnection(self::$connectionName) - ->dropColumn( - $setup->getTable('sales_invoice'), - 'base_avatax_tax_amount' - ); - } - - // Only copy data and drop columns from "sales_creditmemo" if the columns exist - $tableName = $setup->getTable('sales_creditmemo'); - if ( - $setup->getConnection(self::$connectionName) - ->tableColumnExists($tableName, 'avatax_is_unbalanced') - && $setup->getConnection(self::$connectionName) - ->tableColumnExists($tableName, 'base_avatax_tax_amount') - ) { - // Copy any existing AvaTax data from core Credit Memo table into new AvaTax Credit Memo table - $select = $setup->getConnection(self::$connectionName)->select() - ->from( - $setup->getTable('sales_creditmemo'), - [ - 'entity_id', - 'avatax_is_unbalanced', - 'base_avatax_tax_amount' - ]) - ->where('base_avatax_tax_amount IS NOT NULL OR avatax_is_unbalanced IS NOT NULL'); - $select = $setup->getConnection(self::$connectionName)->insertFromSelect( - $select, - $setup->getTable('avatax_sales_creditmemo'), - [ - 'parent_id', - 'is_unbalanced', - 'base_avatax_tax_amount' - ] - ); - $setup->getConnection(self::$connectionName)->query($select); - - // Drop "avatax_is_unbalanced" column from "sales_creditmemo" table - $setup->getConnection(self::$connectionName) - ->dropColumn( - $setup->getTable('sales_creditmemo'), - 'avatax_is_unbalanced' - ); - - // Drop "base_avatax_tax_amount" column from "sales_creditmemo" table - $setup->getConnection(self::$connectionName) - ->dropColumn( - $setup->getTable('sales_creditmemo'), - 'base_avatax_tax_amount' - ); - } - } - - /** - * For conversion to REST, initially disable module and delete pre-existing credentials - */ - if (version_compare($context->getVersion(), '2.0.0', '<')) { - $connection = $setup->getConnection(); - - /** @var \Magento\Framework\DB\Select $select */ - $select = $connection->select() - ->from(['main' => $setup->getTable('core_config_data')]) - ->where('main.path IN (?)', [ - 'tax/avatax/enabled', - 'tax/avatax/production_account_number', - 'tax/avatax/production_license_key', - 'tax/avatax/production_company_code', - 'tax/avatax/development_account_number', - 'tax/avatax/development_license_key', - 'tax/avatax/development_company_code', - ]); - $sql = $select->deleteFromSelect('main'); - $connection->query($sql); - } - - /** - * Create cross border type product attribute - */ - if (version_compare($context->getVersion(), '2.0.2', '<')) { - $eavSetup->addAttribute( - \Magento\Catalog\Model\Product::ENTITY, - strtolower(\ClassyLlama\AvaTax\Helper\CustomsConfig::PRODUCT_ATTR_CROSS_BORDER_TYPE), - [ - 'group' => 'AvaTax', - 'type' => 'int', - 'label' => 'AvaTax Cross Border Type', - 'input' => 'text', - // TODO: Update input type and add source model once Cross Border Type entity is available - 'sort_order' => 10, - 'required' => false, - 'global' => ScopedAttributeInterface::SCOPE_STORE, - ] - ); - } - - /** - * Create Importer of Record Override Option - */ - if (version_compare($context->getVersion(), '2.0.5', '<')) { - - /** @var CustomerSetup $customerSetup */ - $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]); - $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer'); - $attributeSetId = $customerEntity->getDefaultAttributeSetId(); - - /** @var AttributeSet $attributeSet */ - $attributeSet = $this->attributeSetFactory->create(); - $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); - $customerSetup->addAttribute( - Customer::ENTITY, - CustomsConfig::CUSTOMER_IMPORTER_OF_RECORD_ATTRIBUTE, - [ - 'type' => 'text', - 'label' => 'Override Avatax "Is Seller Importer of Record" setting', - 'input' => 'select', - 'note' => 'Overrides Importer of Record. Select "Use Default" to keep the Avatax setting, "Override ' - . - 'to Yes" to set Customer as Importer of record, "Override to No" to set the Customer as ' . - 'not the Importer of Record.', - 'visible' => true, - 'user_defined' => 0, - 'required' => false, - 'sort_order' => 999, - 'position' => 999, - 'system' => 0, - 'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend', - 'source' => \ClassyLlama\AvaTax\Model\Config\Source\CrossBorderClass\Customer\ImporterOfRecord::class - ] - ); - $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, - CustomsConfig::CUSTOMER_IMPORTER_OF_RECORD_ATTRIBUTE - )->addData([ - 'attribute_set_id' => $attributeSetId, - 'attribute_group_id' => $attributeGroupId, - 'used_in_forms' => ['adminhtml_customer'], - ]); - - $attribute->save(); - } - - $setup->endSetup(); - } -} diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php deleted file mode 100644 index 659dda5f..00000000 --- a/Setup/UpgradeSchema.php +++ /dev/null @@ -1,766 +0,0 @@ -startSetup(); - if (version_compare($context->getVersion(), '0.1.4', '<')) { - /** - * Add "avatax_code" column to tax_class table - */ - $setup->getConnection() - ->addColumn( - $setup->getTable('tax_class'), - 'avatax_code', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'default' => null, - 'comment' => 'AvaTax Code' - ] - ); - } - - if (version_compare($context->getVersion(), '1.0.0', '<')) { - /** As a part of the upgrade process for this revision, data is migrated from the sales_invoice and - * sales_creditmemo tables into the newly created tables above. After the data migration, the previously - * mentioned tables are altered to drop the now-unused columns in each (base_avatax_tax_amount and - * avatax_is_unbalanced). @see \ClassyLlama\AvaTax\Setup\UpgradeData for this logic. - */ - - /** - * Create table 'avatax_sales_invoice' - */ - $table = $setup->getConnection(self::$connectionName) - ->newTable( - $setup->getTable('avatax_sales_invoice') - ) - ->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'Entity ID' - ) - ->addColumn( - 'parent_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 10, - [ - 'nullable' => false, - 'unsigned' => true, - ], - 'Sales Invoice ID' - ) - ->addColumn( - 'is_unbalanced', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - 1, - [ - 'nullable' => true, - 'default' => null, - 'unsigned' => true, - ], - 'Is Unbalanced In Relation To AvaTax Calculated Tax Amount' - ) - ->addColumn( - 'base_avatax_tax_amount', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - [ - 'nullable' => true, - 'default' => null, - 'unsigned' => false, - ], - 'Base AvaTax Calculated Tax Amount' - ) - ->addIndex( - $setup->getIdxName( - 'avatax_sales_invoice', - [ - 'entity_id', - 'parent_id' - ], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX - ), - [ - 'entity_id', - 'parent_id' - ], - ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX] - ) - ->addForeignKey( - $setup->getFkName( - 'avatax_sales_invoice_parent_id_sales_invoice_entity_id', - 'parent_id', - 'sales_invoice', - 'entity_id' - ), - 'parent_id', - $setup->getTable('sales_invoice'), - 'entity_id', - Table::ACTION_CASCADE - ) - ->setComment('AvaTax Sales Invoice Table'); - $setup->getConnection(self::$connectionName)->createTable($table); - - /** - * Create table 'avatax_sales_creditmemo' - */ - $table = $setup->getConnection(self::$connectionName) - ->newTable( - $setup->getTable('avatax_sales_creditmemo') - ) - ->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'Entity ID' - ) - ->addColumn( - 'parent_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 10, - [ - 'nullable' => false, - 'unsigned' => true, - ], - 'Sales Credit Memo ID' - ) - ->addColumn( - 'is_unbalanced', - \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT, - 1, - [ - 'nullable' => true, - 'default' => null, - 'unsigned' => true, - ], - 'Is Unbalanced In Relation To AvaTax Calculated Tax Amount' - ) - ->addColumn( - 'base_avatax_tax_amount', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - [ - 'nullable' => true, - 'default' => null, - 'unsigned' => false, - ], - 'Base AvaTax Calculated Tax Amount' - ) - ->addIndex( - $setup->getIdxName( - 'avatax_sales_creditmemo', - [ - 'entity_id', - 'parent_id' - ], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX - ), - [ - 'entity_id', - 'parent_id' - ], - ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_INDEX] - ) - ->addForeignKey( - $setup->getFkName( - 'avatax_sales_creditmemo_parent_id_sales_creditmemo_entity_id', - 'parent_id', - 'sales_creditmemo', - 'entity_id' - ), - 'parent_id', - $setup->getTable('sales_creditmemo'), - 'entity_id', - Table::ACTION_CASCADE - ) - ->setComment('AvaTax Sales Credit Memo Table'); - $setup->getConnection(self::$connectionName)->createTable($table); - } - - if (version_compare($context->getVersion(), '2.0.1', '<')) { - /** - * Create table 'avatax_cross_border_class' - */ - $table = $setup->getConnection() - ->newTable( - $setup->getTable('avatax_cross_border_class') - ) - ->addColumn( - 'class_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'Class ID' - ) - ->addColumn( - 'cross_border_type_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 11, - [ - 'nullable' => true, - ], - 'Cross Border Type Id' - ) - ->addColumn( - 'hs_code', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [ - 'nullable' => false, - 'default' => '', - ], - 'HS Code' - ) - ->addColumn( - 'unit_name', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [ - 'nullable' => true, - ], - 'Unit Name' - ) - ->addColumn( - 'unit_amount_product_attr', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [ - 'nullable' => true, - ], - 'Unit Amount Product Attribute' - ) - ->addColumn( - 'pref_program_indicator', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [ - 'nullable' => true, - ], - 'Pref. Program Indicator' - ) - ->setComment('Cross Border Class'); - - $setup->getConnection()->createTable($table); - - - /** - * Create table 'avatax_cross_border_class_country' - */ - $table = $setup->getConnection() - ->newTable( - $setup->getTable('avatax_cross_border_class_country') - ) - ->addColumn( - 'link_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'Link ID' - ) - ->addColumn( - 'class_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - ], - 'Class ID' - ) - ->addColumn( - 'country_id', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 2, - [ - 'nullable' => false, - ], - 'Country ID' - ) - ->addIndex( - $setup->getIdxName( - 'avatax_cross_border_class_country', - ['class_id', 'country_id'], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - ['class_id', 'country_id'], - ['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE] - ) - ->addForeignKey( - $setup->getFkName( - 'avatax_cross_border_class_country', - 'class_id', - 'avatax_cross_border_class', - 'class_id' - ), - 'class_id', - $setup->getTable('avatax_cross_border_class'), - 'class_id', - Table::ACTION_CASCADE - ) - ->addForeignKey( - $setup->getFkName( - 'avatax_cross_border_class_country', - 'country_id', - 'directory_country', - 'country_id' - ), - 'country_id', - $setup->getTable('directory_country'), - 'country_id', - Table::ACTION_CASCADE - ) - ->setComment('AvaTax Sales Credit Memo Table'); - - $setup->getConnection()->createTable($table); - } - - // TODO: Consolidate with initial table creation above - - if (version_compare($context->getVersion(), '2.0.4', '<')) { - $installer = $setup; - $installer->startSetup(); - - $table_classyllama_avatax_crossbordertype = $setup->getConnection() - ->newTable($setup->getTable('classyllama_avatax_crossbordertype')); - - - $table_classyllama_avatax_crossbordertype->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - ['identity' => true, 'nullable' => false, 'primary' => true, 'unsigned' => true,], - 'Entity ID' - ); - - - $table_classyllama_avatax_crossbordertype->addColumn( - 'type', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - null, - ['nullable' => false], - 'type' - ); - - - $setup->getConnection()->createTable($table_classyllama_avatax_crossbordertype); - - $setup->endSetup(); - } - - // TODO: Add foreign key on avatax_cross_border_class.cross_border_type - - $extensionTables = [ - 'avatax_quote_item' => [ - 'id_field' => 'quote_item_id', - 'id_field_label' => 'Quote Item ID', - 'foreign_table' => 'quote_item', - 'foreign_field' => 'item_id', - 'comment' => 'AvaTax Quote Item Extension', - 'connection' => self::$checkoutConnectionName, - ], - 'avatax_sales_order_item' => [ - 'id_field' => 'order_item_id', - 'id_field_label' => 'Order Item ID', - 'foreign_table' => 'sales_order_item', - 'foreign_field' => 'item_id', - 'comment' => 'AvaTax Order Item Extension', - 'connection' => self::$connectionName, - ], - 'avatax_sales_invoice_item' => [ - 'id_field' => 'invoice_item_id', - 'id_field_label' => 'Invoice Item ID', - 'foreign_table' => 'sales_invoice_item', - 'foreign_field' => 'entity_id', - 'comment' => 'AvaTax Invoice Item Extension', - 'connection' => self::$connectionName, - ], - 'avatax_sales_creditmemo_item' => [ - 'id_field' => 'creditmemo_item_id', - 'id_field_label' => 'Credit Memo Item ID', - 'foreign_table' => 'sales_creditmemo_item', - 'foreign_field' => 'entity_id', - 'comment' => 'AvaTax Credit Memo Item Extension', - 'connection' => self::$connectionName, - ], - ]; - - if (version_compare($context->getVersion(), '2.0.4', '<')) { - foreach ($extensionTables as $tableName => $tableInfo) { - $table = $setup->getConnection($tableInfo['connection']) - ->newTable( - $setup->getTable($tableName) - ) - ->addColumn( - 'id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'ID' - ) - ->addColumn( - $tableInfo['id_field'], - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 10, - [ - 'nullable' => false, - 'unsigned' => true, - ], - $tableInfo['id_field_label'] - ) - ->addColumn( - 'hs_code', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [ - 'nullable' => true, - ], - 'HS Code' - ) - ->addColumn( - 'unit_name', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [ - 'nullable' => true, - ], - 'Unit Name' - ) - ->addColumn( - 'unit_amount', - \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL, - '12,4', - [ - 'nullable' => true, - ], - 'Unit Amount' - ) - ->addColumn( - 'pref_program_indicator', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [ - 'nullable' => true, - ], - 'Pref. Program Indicator' - ) - ->setComment($tableInfo['comment']); - - if (isset($tableInfo['foreign_table']) && !empty($tableInfo['foreign_table'])) { - $table->addForeignKey( - $setup->getFkName( - $tableName, - $tableInfo['id_field'], - $tableInfo['foreign_table'], - $tableInfo['foreign_field'] - ), - $tableInfo['id_field'], - $setup->getTable($tableInfo['foreign_table']), - $tableInfo['foreign_field'], - Table::ACTION_CASCADE - ); - } - - $setup->getConnection($tableInfo['connection'])->createTable($table); - } - } - - if (version_compare($context->getVersion(), '2.0.5', '<')) { - foreach ($extensionTables as $tableName => $tableInfo) { - $setup->getConnection($tableInfo['connection']) - ->addIndex( - $setup->getTable($tableName), - $setup->getIdxName( - $tableName, - [$tableInfo['id_field']], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ), - [$tableInfo['id_field']], - \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE - ); - } - } - - if (version_compare($context->getVersion(), '2.0.7', '<')) { - $setup->getConnection(self::$connectionName) - ->addColumn( - $setup->getTable('avatax_sales_invoice'), - 'avatax_response', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => null, - 'nullable' => true, - 'default' => null, - 'comment' => 'AvaTax Response' - ] - ); - - $setup->getConnection(self::$connectionName) - ->addColumn( - $setup->getTable('avatax_sales_creditmemo'), - 'avatax_response', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => null, - 'nullable' => true, - 'default' => null, - 'comment' => 'AvaTax Response' - ] - ); - - $table = $setup->getConnection(self::$connectionName) - ->newTable( - $setup->getTable('avatax_sales_order') - ) - ->addColumn( - 'id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'ID' - ) - ->addColumn( - 'order_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 10, - [ - 'nullable' => false, - 'unsigned' => true, - ], - 'Order id' - ) - ->addColumn( - 'avatax_response', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - null, - [ - 'nullable' => true, - ], - 'HS Code' - ) - ->addForeignKey( - $setup->getFkName( - 'avatax_sales_order', - 'order_id', - 'sales_order', - 'entity_id' - ), - 'order_id', - $setup->getTable('sales_order'), - 'entity_id', - Table::ACTION_CASCADE - ) - ->setComment('AvaTax Sales Order'); - - $setup->getConnection(self::$connectionName)->createTable($table); - } - - if (version_compare($context->getVersion(), '2.0.8', '<')) { - $setup->getConnection(self::$checkoutConnectionName) - ->addColumn( - $setup->getTable('quote_address'), - 'avatax_messages', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => null, - 'nullable' => true, - 'default' => null, - 'comment' => 'AvaTax Messages' - ] - ); - } - - if (version_compare($context->getVersion(), '2.1.6', '<')) { - $this->createQueueBatchTransactionsTable($setup); - } - - if (version_compare($context->getVersion(), '2.2.4.1', '<')) { - $setup->getConnection(self::$connectionName) - ->addIndex( - $setup->getTable('avatax_sales_order'), - $setup->getIdxName( - $setup->getTable('avatax_sales_order'), - ['order_id'], - AdapterInterface::INDEX_TYPE_UNIQUE - ), - ['order_id'], - AdapterInterface::INDEX_TYPE_UNIQUE - ); - } - - $setup->endSetup(); - } - - private function createQueueBatchTransactionsTable(SchemaSetupInterface $setup) - { - $table = $setup->getConnection() - ->newTable( - $setup->getTable('avatax_batch_queue') - ) - ->addColumn( - 'entity_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - null, - [ - 'nullable' => false, - 'identity' => true, - 'primary' => true - ], - 'Entity Id' - ) - ->addColumn( - 'batch_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 10, - [ - 'nullable' => false, - 'unsigned' => true, - ], - 'Batch Id' - ) - ->addColumn( - 'name', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [ - 'nullable' => false, - ], - 'Batch Name' - ) - ->addColumn( - 'company_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 10, - [ - 'nullable' => false, - 'unsigned' => true, - ], - 'Company Id' - ) - ->addColumn( - 'status', - \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 255, - [ - 'nullable' => false, - ], - 'Status' - ) - ->addColumn( - 'record_count', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 10, - [ - 'nullable' => false, - 'unsigned' => true, - ], - 'Status' - ) - ->addColumn( - 'input_file_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 20, - [ - 'nullable' => true, - ], - 'Input File Id' - ) - ->addColumn( - 'result_file_id', - \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER, - 20, - [ - 'nullable' => true, - ], - 'Result File Id' - ) - ->addColumn( - 'created_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT], - 'Queue Time' - ) - ->addColumn( - 'updated_at', - \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP, - null, - ['nullable' => true], - 'Updated Time' - ); - - $setup->getConnection()->createTable($table); - } -}