Ignore:
Timestamp:
Feb 23, 2016, 4:44:03 PM (9 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/UpdateTrace.php

    r801 r802  
    18261826{
    18271827  $Manager->Execute('CREATE TABLE IF NOT EXISTS `StockItemHistory` (
    1828     `Id` int(11) NOT NULL,
     1828    `Id` int(11) NOT NULL AUTO_INCREMENT,
    18291829    `StockSerialNumber` int(11) NOT NULL,
    18301830    `Time` datetime NOT NULL,
     
    18381838    '"" AS `Time`, `Info` AS `Text` FROM `StockSerialNumber` WHERE `Info` != "")');
    18391839  $Manager->Execute('ALTER TABLE `StockSerialNumber` DROP `Info`;');
     1840}
     1841
     1842function UpdateTo802($Manager)
     1843{
     1844  $Manager->Execute('CREATE TABLE IF NOT EXISTS `StockMoveGroup` (
     1845  `Id` int(11) NOT NULL AUTO_INCREMENT,
     1846  `Name` varchar(255) NOT NULL,
     1847  `DocumentLine` int(11) NOT NULL,
     1848  `ValueSign` int(11) NOT NULL,
     1849  `Direction` int(11) NOT NULL,
     1850  PRIMARY KEY (`Id`),
     1851  KEY `DocumentLine` (`DocumentLine`)
     1852) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
     1853  $Manager->Execute('ALTER TABLE `StockMoveGroup` ADD FOREIGN KEY (`DocumentLine`) '.
     1854    'REFERENCES `DocumentLine`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
     1855  $Manager->Execute('INSERT INTO `StockMoveGroup` (`Id`, `Name`, `DocumentLine`, '.
     1856    '`ValueSign`, `Direction`) VALUES (NULL, "Příjem", 8, 1, 0), (NULL, "Výdej", 7, -1, 1);');
     1857
     1858  $Manager->Execute('ALTER TABLE `StockMove` ADD `Group` INT NOT NULL AFTER `File`, ADD INDEX (`Group`);');
     1859  $Manager->Execute('ALTER TABLE `StockMove` ADD `Stock` INT NOT NULL AFTER `Time`, ADD INDEX (`Stock`);');
     1860  $Manager->Execute('ALTER TABLE `StockMove` ADD FOREIGN KEY (`Group`) REFERENCES `StockMoveGroup`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
     1861  $Manager->Execute('UPDATE `StockMove` SET `Group`=(SELECT `Id` FROM `StockMoveGroup` WHERE `StockMoveGroup`.`DocumentLine` = `StockMove`.`DocumentLine`)');
     1862  $Manager->Execute('UPDATE `StockMove` SET `Stock`= `StockFrom` WHERE `DocumentLine` = 7');
     1863  $Manager->Execute('UPDATE `StockMove` SET `Stock`= `StockTo` WHERE `DocumentLine` = 8');
     1864  $Manager->Execute('ALTER TABLE `StockMove` DROP FOREIGN KEY StockMove_ibfk_2;');
     1865  $Manager->Execute('ALTER TABLE `StockMove` DROP FOREIGN KEY StockMove_ibfk_1;');
     1866  $Manager->Execute('ALTER TABLE `StockMove` DROP FOREIGN KEY StockMove_ibfk_3;');
     1867  $Manager->Execute('ALTER TABLE `StockMove` DROP `StockFrom`, DROP `StockTo`, DROP `DocumentLine`;');
     1868  $Manager->Execute('ALTER TABLE `StockMove` ADD FOREIGN KEY (`Stock`) REFERENCES `Stock`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
     1869 
     1870  // Make BillCode as reference to DocumentLineCode table
     1871  $Manager->Execute('ALTER TABLE `StockMove` CHANGE `BillCode` `BillCodeText` VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL');
     1872  $Manager->Execute('ALTER TABLE `StockMove` ADD `BillCode` INT NULL AFTER `BillCodeText`, ADD INDEX (`BillCode`)');
     1873  $Manager->Execute('ALTER TABLE `StockMove` ADD FOREIGN KEY (`BillCode`) REFERENCES `DocumentLineCode`(`Id`) ON DELETE RESTRICT ON UPDATE RESTRICT;');
     1874
     1875  $DbResult = $Manager->Execute('SELECT `StockMove`.`Id`, `StockMove`.`BillCodeText`, `StockMoveGroup`.`DocumentLine` '.
     1876    'FROM `StockMove` '.
     1877    'LEFT JOIN `StockMoveGroup` ON `StockMoveGroup`.`Id` = `StockMove`.`Group` '.
     1878    'WHERE `StockMove`.`BillCodeText`!=""');
     1879  while($DbRow = $DbResult->fetch_assoc())
     1880  {
     1881   if($DbRow['DocumentLine'] == '') $DbRow['DocumentLine'] = 'NULL';
     1882   $Manager->Execute('INSERT INTO `DocumentLineCode` (`Id` ,`DocumentLine` ,`Name`) '.
     1883     'VALUES (NULL , '.$DbRow['DocumentLine'].', "'.$DbRow['BillCodeText'].'");');
     1884   $CodeId = $Manager->Database->insert_id;
     1885   $Manager->Execute('UPDATE `StockMove` SET `BillCode`='.$CodeId.' WHERE `Id`='.$DbRow['Id']);
     1886  }
     1887  $Manager->Execute('ALTER TABLE `StockMove` DROP `BillCodeText`;');
     1888  $Manager->Execute('ALTER TABLE `StockMoveItem` DROP `Text`;');
    18401889}
    18411890
     
    19241973      786 => array('Revision' => 792, 'Function' => 'UpdateTo792'),
    19251974      792 => array('Revision' => 800, 'Function' => 'UpdateTo800'),
     1975      800 => array('Revision' => 802, 'Function' => 'UpdateTo802'),
    19261976    ));
    19271977  }
Note: See TracChangeset for help on using the changeset viewer.