Skip to content

Commit

Permalink
tweak(Sales Debitor) migration sets debitor number to customer number
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmhh committed Jan 12, 2024
1 parent d01e429 commit f7023fb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tine20/Sales/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ class Sales_Model_Address extends Tinebase_Record_NewAbstract
self::QUERY_FILTER => TRUE,
self::NULLABLE => TRUE,
],
// we should drop this column, be aware of upgrade path though!
// if you remove it here, Setup/Update/17.php ::update001 will remove it! though it is accessed by later update functions!!!
self::FLD_CUSTOM1 => [
self::LABEL => 'Number Debit', //_('Number Debit')
self::TYPE => self::TYPE_STRING,
self::NULLABLE => TRUE,
self::QUERY_FILTER => TRUE
],
self::FLD_TYPE => [
self::TYPE => self::TYPE_STRING,
Expand Down
2 changes: 1 addition & 1 deletion tine20/Sales/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @subpackage Model
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Alexander Stintzing <a.stintzing@metaways.de>
* @copyright Copyright (c) 2013-2023 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2013-2024 Metaways Infosystems GmbH (http://www.metaways.de)
*/

/**
Expand Down
26 changes: 26 additions & 0 deletions tine20/Sales/Setup/Update/17.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Sales_Setup_Update_17 extends Setup_Update_Abstract
const RELEASE017_UPDATE008 = __CLASS__ . '::update008';
const RELEASE017_UPDATE009 = __CLASS__ . '::update009';
const RELEASE017_UPDATE010 = __CLASS__ . '::update010';
const RELEASE017_UPDATE011 = __CLASS__ . '::update011';

static protected $_allUpdates = [
self::PRIO_TINEBASE_BEFORE_STRUCT => [
Expand Down Expand Up @@ -58,6 +59,10 @@ class Sales_Setup_Update_17 extends Setup_Update_Abstract
self::CLASS_CONST => self::class,
self::FUNCTION_CONST => 'update005',
],
self::RELEASE017_UPDATE011 => [
self::CLASS_CONST => self::class,
self::FUNCTION_CONST => 'update011',
],
],
self::PRIO_NORMAL_APP_STRUCTURE => [
self::RELEASE017_UPDATE009 => [
Expand Down Expand Up @@ -401,4 +406,25 @@ public function update010()

$this->addApplicationUpdate(Sales_Config::APP_NAME, '17.10', self::RELEASE017_UPDATE010);
}

public function update011()
{
$this->_db->query('UPDATE ' . SQL_TABLE_PREFIX . Sales_Model_Debitor::TABLE_NAME . ' as a JOIN '
. SQL_TABLE_PREFIX . Sales_Model_Customer::TABLE_NAME .' AS b ON a.' . Sales_Model_Debitor::FLD_CUSTOMER_ID . ' = b.id SET a.number = b.number');

$this->_db->query('UPDATE ' . SQL_TABLE_PREFIX . Sales_Model_Debitor::TABLE_NAME . ' as d JOIN '
. SQL_TABLE_PREFIX . Sales_Model_Address::TABLE_NAME . ' AS a ON a.' . Sales_Model_Address::FLD_DEBITOR_ID
. ' = d.id SET d.number = a.' . Sales_Model_Address::FLD_CUSTOM1 . ' WHERE a.' . Sales_Model_Address::FLD_CUSTOM1 . ' IS NOT NULL AND a.' . Sales_Model_Address::FLD_CUSTOM1 . ' <> ""');

$this->_db->query('UPDATE ' . SQL_TABLE_PREFIX . Sales_Model_Debitor::TABLE_NAME . ' as d JOIN '
. SQL_TABLE_PREFIX . Sales_Model_Customer::TABLE_NAME .' AS c ON d.' . Sales_Model_Debitor::FLD_CUSTOMER_ID
. ' = c.id JOIN ' . SQL_TABLE_PREFIX . Sales_Model_Address::TABLE_NAME . ' AS a ON a.' . Sales_Model_Address::FLD_CUSTOMER_ID
. ' = c.id SET d.number = a.' . Sales_Model_Address::FLD_CUSTOM1 . ' WHERE a.' . Sales_Model_Address::FLD_CUSTOM1 . ' IS NOT NULL AND a.' . Sales_Model_Address::FLD_CUSTOM1 . ' <> ""');

$bucket = Sales_Model_Debitor::class . '#' . Sales_Model_Debitor::FLD_NUMBER . '#' . Sales_Config::getInstance()->{Sales_Config::DEFAULT_DIVISION};
$this->getDb()->query('DELETE FROM ' . SQL_TABLE_PREFIX . 'numberable WHERE bucket = "'. $bucket . '"');
$this->getDb()->query('INSERT INTO ' . SQL_TABLE_PREFIX . 'numberable (bucket, number) SELECT "' . $bucket . '", ' . Sales_Model_Debitor::FLD_NUMBER . ' FROM ' . SQL_TABLE_PREFIX . Sales_Model_Debitor::TABLE_NAME);

$this->addApplicationUpdate(Sales_Config::APP_NAME, '17.11', self::RELEASE017_UPDATE011);
}
}

0 comments on commit f7023fb

Please sign in to comment.