<?php

namespace CarDealerPress\Includes\Database;

use CarDealerPress\includes\functions\Logger;
use CarDealerPress\Includes\Helpers\Option;
use CarDealerPress\Includes\Init\Default_Options;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Alter_Tables {
	use Logger;

	private static $blog;
	public $current_inventory_version;
	public $default_current_company_version;
	public $current_company_version;
	public $initial_company_version;
	public $initial_inventory_version;
	public static $wpdb;
	/**
	 * @var false|mixed|void
	 */
	public $admin_options;
	/**
	 * @var mixed
	 */
	private $default_current_inventory_version;
	// public $logger;
	public $force;

	public function __construct( $args = array() ) {
		global $wpdb;
		self::$wpdb                              = $wpdb;
		self::$blog                              = get_current_blog_id();
		$this->admin_options                     = Option::get_cdp_admin_options();
		$this->current_company_version           = Option::check_for_option( 'cdp_admin_options', array(
			'admin',
			'database',
			'company',
			'current',
		) );
		$this->current_inventory_version         = Option::check_for_option( 'cdp_admin_options', array(
			'admin',
			'database',
			'inventory',
			'current',
		) );
		$this->default_current_company_version   = Default_Options::$default_options_admin['admin']['database']['company']['current'];
		$this->default_current_inventory_version = Default_Options::$default_options_admin['admin']['database']['inventory']['current'];
		$this->force                             = isset( $args['force'] ) ? true : '';
		$this->company_table();
		$this->inventory_table();
		update_option( 'cdp_admin_options', $this->admin_options );
	}

	function company_table() {
		$table_main = CDP_COMPANIES;

		if ( $this->force || ( version_compare( $this->default_current_company_version, $this->current_company_version, '>' ) ) ) {
			if ( $this->force ) {
				$this->append_log( array( 'message' => 'CDP Message: Checking Companies table for changes.' ) );
			} else {
				$this->append_log( array( 'message' => 'CDP Message: Company DB Updated to: ' . $this->default_current_company_version . ' | from: ' . $this->default_current_company_version ) );
			}

			/***
			 * Added 10/2024 drop tables, they were created before  | DB Version 6.6.2410.01
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( "SHOW TABLES LIKE 'cdp_companies'" ) ;
			// @codingStandardsIgnoreEnd
			if ( $exists ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( "DROP TABLE cdp_companies");
				$this->append_log( array( 'message' => 'CDP Message: dropped cdp_companies table, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( "DROP TABLE cdp_data" );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: dropped cdp_data table, ' . $this->return_result( $result ) ) );
			}

			/***
			 * Added 08/31/2018 column: id  | DB Version 4.9.180800
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( "SHOW COLUMNS FROM " . CDP_COMPANIES ." like 'id'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE '. CDP_COMPANIES .' ADD COLUMN id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Company DB Updated added column id, ' . $this->return_result( $result ) ) );
			}

			/***
			 * Added 01/09/2019 column: inventory_api_last_modified  | DB Version 4.9.180800
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( "SHOW COLUMNS FROM " . CDP_COMPANIES . " like 'inventory_api_last_modified'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_COMPANIES . ' ADD COLUMN inventory_api_last_modified int(11) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Company DB Updated added column inventory_api_last_modified, ' . $this->return_result( $result ) ) );
			}

			/***
			 * Added 07/29/2020 field: apikeys (AIS related) | DB Version 5.4.200704
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( "SHOW COLUMNS FROM " . CDP_COMPANIES . " like 'apikeys'" );
			// @codingStandardsIgnoreEnd
			if ( ! empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE '. CDP_COMPANIES .' DROP COLUMN apikeys' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Company DB Updated removed column apikeys, ' . $this->return_result( $result ) ) );
			}

			/***
			 * Added 06/2022 fields: inventory_last_checked, inventory_last_checked_response added 06/2022 | DB Version 6.0.220600
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( "SHOW COLUMNS FROM " . CDP_COMPANIES ." like 'inventory_last_checked'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE '. CDP_COMPANIES .' ADD COLUMN inventory_last_checked int(11) NOT NULL' );
				$this->append_log( array( 'message' => 'CDP Message: Company DB Updated added column inventory_last_checked, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_COMPANIES .' ADD COLUMN inventory_last_checked_response int(11) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Company DB Updated added column inventory_last_checked_response, ' . $this->return_result( $result ) ) );
			}
			/***
			 * Added 09/2022  fields: inventory_last_checked, inventory_last_checked_response | DB Version 6.0.2209.01
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( "SHOW COLUMNS FROM " . CDP_COMPANIES ." like 'seo'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE '. CDP_COMPANIES .' ADD COLUMN seo longtext NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Company DB Updated added column seo, ' . $this->return_result( $result ) ) );
			}

			/***
			 * Added 12/2023 country column refresh  | DB Version 6.4.2312.00
			 * Some sites are not renaming the country column.
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( "SHOW COLUMNS FROM ". CDP_COMPANIES ." like 'country'" );
			// @codingStandardsIgnoreEnd
			if ( $exists ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_COMPANIES .' DROP COLUMN country' );
				$this->append_log( array( 'message' => 'CDP Message: Company DB Updated DROPPED country column, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE '. CDP_COMPANIES .' ADD COLUMN country_code varchar(255) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Company DB Updated ADDED country_code column, ' . $this->return_result( $result ) ) );
			}

			/***
			 * Added 06/25 db column change | DB Version 6.8.2507.00
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( "SHOW COLUMNS FROM ". CDP_COMPANIES ." like 'last_updated'" );
			// @codingStandardsIgnoreEnd
			if ( $exists ) {
				$columns_to_change = array(
					"last_updated",
					"inventory_last_updated",
					"inventory_api_last_modified",
					"inventory_last_checked",
					"inventory_last_checked_response",
				);
				// @codingStandardsIgnoreStart
				$blog_id = get_current_blog_id();
				foreach ( $columns_to_change as $column ) {
					// @codingStandardsIgnoreStart
					$query   = 'Select '. $column . ' from ' . CDP_COMPANIES . ' where blog_id = ' . $blog_id;
					$time = self::$wpdb->get_results( self::$wpdb->prepare( $query, ARRAY_A ))[0];
					$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_COMPANIES . ' MODIFY COLUMN '. $column .' DATETIME NOT NULL' );
					$this->append_log( array( 'message' => 'CDP Message: Company DB Updated ' . $column . ' to DATETIME, ' . $this->return_result( $result ) ) );
					$updated_datetime = wp_date( 'Y-m-d H:i', $time->$column );
					self::$wpdb->update( CDP_COMPANIES, array( $column => $updated_datetime ), array( 'blog_id' => $blog_id ) );
			}
				// @codingStandardsIgnoreEnd
			}

			$this->admin_options['admin']['database']['company']['current'] = $this->default_current_company_version;
		}
	}

	function inventory_table() {

		$table_main   = CDP_INVENTORY_TABLE;
		$table_import = CDP_INVENTORY_IMPORT_TABLE;
		if ( $this->force || ( version_compare( $this->default_current_inventory_version, $this->current_inventory_version, '>' ) ) ) {
			if ( $this->force ) {
				$this->append_log( array( 'message' => 'CDP Message: Checking Inventory table for changes.' ) );
			} else {
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated to: ' . $this->default_current_inventory_version . ' | from: ' . $this->current_inventory_version ) );
			}
			/***
			 * Added 10/2024 rename tables  | DB Version 6.6.2410.01
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( "SHOW TABLES LIKE 'cdp_inventory_".self::$blog."'" ) ;
			// @codingStandardsIgnoreEnd
			if ( $exists ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( "RENAME TABLE cdp_inventory_".self::$blog." TO " . CDP_INVENTORY_TABLE );
				$this->append_log( array( 'message' => 'CDP Message: renamed cdp_inventory_'.self::$blog.' table to '.CDP_INVENTORY_TABLE.',' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( "RENAME TABLE cdp_inventory_import_".self::$blog." TO ". CDP_INVENTORY_IMPORT_TABLE );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: renamed cdp_inventory_import_'.self::$blog.' table to '.CDP_INVENTORY_IMPORT_TABLE.', ' . $this->return_result( $result ) ) );
			}
			/***
			 * Added 02/12/2018 column: pricesort | DB Version 4.9.180200
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( 'SHOW COLUMNS FROM ' . CDP_INVENTORY_IMPORT_TABLE . " like 'pricesort'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' ADD COLUMN pricesort INT DEFAULT 0' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Updated added column pricesort, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' ADD COLUMN pricesort INT DEFAULT 0' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated added column pricesort, ' . $this->return_result( $result ) ) );
			}

			/***
			 * Added 04/17/2018 column: color_map | DB Version 4.9.180400
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( 'SHOW COLUMNS FROM ' . CDP_INVENTORY_IMPORT_TABLE . " like 'color_map'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' ADD COLUMN color_map varchar(255) NOT NULL' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Updated added column color_map, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' ADD COLUMN color_map varchar(255) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated added column color_map, ' . $this->return_result( $result ) ) );
			}
			/***
			 * Update 02/26/2019 column: id data type | DB Version 5.1.190200
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( "SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '" . CDP_INVENTORY_TABLE . "' AND COLUMN_NAME = 'id'" );
			// @codingStandardsIgnoreEnd
			if ( ! empty( $exists ) && $exists == 'mediumint' ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' MODIFY COLUMN id bigint(20) NOT NULL AUTO_INCREMENT' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Updated altered id data type, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' MODIFY COLUMN id bigint(20) NOT NULL AUTO_INCREMENT' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated altered id data type, ' . $this->return_result( $result ) ) );
			}
			/***
			 * Added 04/20/2019 column: color_map_int | DB Version 5.1.190400
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( 'SHOW COLUMNS FROM ' . CDP_INVENTORY_IMPORT_TABLE . " like 'color_map_int'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' ADD COLUMN color_map_int varchar(255) NOT NULL' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Updated added column color_map_int, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' ADD COLUMN color_map_int varchar(255) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated added column color_map_int, ' . $this->return_result( $result ) ) );
			}
			/***
			 * Added 08/28/2019 column: carfax_image_url | DB Version 5.2.190800
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( 'SHOW COLUMNS FROM ' . CDP_INVENTORY_IMPORT_TABLE . " like 'carfax_image_url'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' ADD COLUMN carfax_image_url varchar(255) NOT NULL' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Updated added column carfax_image_url, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' ADD COLUMN carfax_image_url varchar(255) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated added column carfax_image_url, ' . $this->return_result( $result ) ) );
			}
			/***
			 * Added 01/20/2020 column: thumbnail increase varchar | DB Version 5.3.200101
			 * due to stock image url length
			 */
			// @codingStandardsIgnoreStart
			$col_info_thumbnail = self::$wpdb->get_col_length( $table_import, 'thumbnail' );
			// @codingStandardsIgnoreEnd
			if ( 350 < $col_info_thumbnail['length'] ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' MODIFY thumbnail varchar(350) NOT NULL' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Update column thumbnail varchar length, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' MODIFY thumbnail varchar(350) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Update column thumbnail varchar length, ' . $this->return_result( $result ) ) );
			}
			/***
			 * Added 03/03/2022 column: sold_on | DB Version 5.9.2203.00
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( 'SHOW COLUMNS FROM ' . CDP_INVENTORY_IMPORT_TABLE . " like 'sold_on'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . " ADD COLUMN sold_on varchar(10) DEFAULT ''" );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Updated added column sold_on, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . " ADD COLUMN sold_on varchar(10) DEFAULT ''" );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated added column sold_on, ' . $this->return_result( $result ) ) );
			}
			/***
			 * Added 01/25/2023 column: tags increase varchar  | DB Version 6.1.230100
			 */
			// @codingStandardsIgnoreStart
			$col_info_tags = self::$wpdb->get_col_length( $table_import, 'tags' );
			// @codingStandardsIgnoreEnd
			if ( 350 < $col_info_tags['length'] ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' MODIFY tags varchar(350) NOT NULL' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Update column tags varchar length, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' MODIFY tags varchar(350) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Update column tags varchar length, ' . $this->return_result( $result ) ) );
			}
			/***
			 * Added 09/01/2023 column: vehicle_url | DB Version 6.2.2309.00
			 * Due to migration from api to db.
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( 'SHOW COLUMNS FROM ' . CDP_INVENTORY_IMPORT_TABLE . " like 'vehicle_url'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' ADD COLUMN vehicle_url varchar(255) NOT NULL' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Updated added column vehicle_url, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' ADD COLUMN vehicle_url varchar(255) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated added column vehicle_url, ' . $this->return_result( $result ) ) );
			}
			/***
			 * Added 06/10/2024 column: payment | DB Version 6.5.2406.00
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( 'SHOW COLUMNS FROM ' . CDP_INVENTORY_IMPORT_TABLE . " like 'payment'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' ADD COLUMN payment INT DEFAULT 0' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Updated added column payment, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' ADD COLUMN payment INT DEFAULT 0' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated added column payment, ' . $this->return_result( $result ) ) );
			}

			/***
			 * Added 06/10/2024 column: image_medium | DB Version 6.5.2406.00
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( 'SHOW COLUMNS FROM ' . CDP_INVENTORY_IMPORT_TABLE . " like 'image_medium'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' ADD COLUMN image_medium varchar(350) NOT NULL' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Updated added image_medium payment, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' ADD COLUMN image_medium varchar(350) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated added column image_medium, ' . $this->return_result( $result ) ) );
			}

			/***
			 * Added 07/28/2025 column: invoice | DB Version 6.5.2406.00
			 */
			// @codingStandardsIgnoreStart
			$exists = self::$wpdb->get_var( 'SHOW COLUMNS FROM ' . CDP_INVENTORY_IMPORT_TABLE . " like 'invoice'" );
			// @codingStandardsIgnoreEnd
			if ( empty( $exists ) ) {
				// @codingStandardsIgnoreStart
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_IMPORT_TABLE . ' ADD COLUMN invoice decimal(18,0) NOT NULL' );
				$this->append_log( array( 'message' => 'CDP Message: Inventory Import DB Updated added invoice payment, ' . $this->return_result( $result ) ) );
				$result = self::$wpdb->query( 'ALTER TABLE ' . CDP_INVENTORY_TABLE . ' ADD COLUMN invoice decimal(18,0) NOT NULL' );
				// @codingStandardsIgnoreEnd
				$this->append_log( array( 'message' => 'CDP Message: Inventory DB Updated added column invoice, ' . $this->return_result( $result ) ) );
			}

		}
		$this->admin_options['admin']['database']['inventory']['current'] = $this->default_current_inventory_version;
	}


	public function return_result( $result ) {
		return ' result: ' . $result ? 'true' : 'false';
	}
}
