Changeset 802


Ignore:
Timestamp:
Feb 23, 2016, 4:44:03 PM (9 years ago)
Author:
chronos
Message:
Location:
trunk
Files:
4 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  }
  • trunk/Application/Version.php

    r801 r802  
    11<?php
    22
    3 $Revision = 801; // Subversion revision
    4 $DatabaseRevision = 800; // SQL structure revision
    5 $ReleaseTime = strtotime('2016-02-22');
     3$Revision = 802; // Subversion revision
     4$DatabaseRevision = 802; // SQL structure revision
     5$ReleaseTime = strtotime('2016-02-23');
  • trunk/Modules/Finance/Finance.php

    r793 r802  
    621621  function BeforeInsertFinanceInvoice($Form)
    622622  {
     623    // Get new DocumentLineCode by selected invoice Group
    623624    if(array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']);
    624625      else $Year = date("Y", $Form->Values['ValidFrom']);
    625     $FinanceGroup = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
    626     $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($FinanceGroup['DocumentLine'], $Year);
     626    $Group = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'FinanceInvoiceGroup');
     627    $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($Group['DocumentLine'], $Year);
    627628    return($Form->Values);
    628629  }
  • trunk/Modules/Stock/Stock.php

    r800 r802  
    1616  function DoStart()
    1717  {
     18    global $Config;
     19   
    1820    $this->System->FormManager->RegisterClass('Product', array(
    1921      'Title' => 'Produkty',
     
    2123      'DefaultSortColumn' => 'Name',
    2224      'Items' => array(
     25        'Manufacturer' => array('Type' => 'TSubject', 'Caption' => 'Výrobce', 'Default' => '', 'Null' => true),
     26        'Code' => array('Type' => 'String', 'Caption' => 'Kód', 'Default' => ''),
    2327        'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
    2428        'SellPrice' => array('Type' => 'Integer', 'Caption' => 'Prodejní cena', 'Default' => '0', 'Suffix' => 'Kč'),
     
    2731        'Consumption' => array('Type' => 'Integer', 'Caption' => 'Spotřeba', 'Default' => '', 'Suffix' => 'Watt'),
    2832        'Supplier' => array('Type' => 'TSubject', 'Caption' => 'Dodavatel', 'Default' => '', 'Null' => true),
    29         'Manufacturer' => array('Type' => 'TSubject', 'Caption' => 'Výrobce', 'Default' => '', 'Null' => true),
    30         'Code' => array('Type' => 'String', 'Caption' => 'Kód', 'Default' => ''),
    3133        'UnitOfMeasure' => array('Type' => 'TUnitOfMeasure', 'Caption' => 'Měrná jednotka', 'Default' => '', 'Null' => true),
    3234        'StockSerialNumbers' => array('Type' => 'TStockSerialNumberListProduct', 'Caption' => 'Položky na skladě', 'Default' => '', 'Suffix' => 'ks'),
     
    7981      'DefaultSortColumn' => 'Time',
    8082      'Items' => array(
    81         'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
    82         'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''),
     83        'Group' => array('Type' => 'TStockMoveGroup', 'Caption' => 'Skupina', 'Default' => ''),
     84        'BillCode' => array('Type' => 'TDocumentLineCode', 'Caption' => 'Označení', 'Default' => '', 'ReadOnly' => true),
    8385        'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => ''),
    84         'StockFrom' => array('Type' => 'TStock', 'Caption' => 'Zdrojový sklad', 'Default' => '', 'Null' => true),
    85         'StockTo' => array('Type' => 'TStock', 'Caption' => 'Cílový sklad', 'Default' => '', 'Null' => true),
     86        'Stock' => array('Type' => 'TStock', 'Caption' => 'Sklad', 'Default' => '', 'Null' => true),
    8687        'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
    8788        'Price' => array('Type' => 'Float', 'Caption' => 'Cena', 'Default' => '',
     
    9192      ),
    9293      'BeforeInsert' => array($this, 'BeforeInsertStockMove'),
    93     ));
    94     $this->System->FormManager->RegisterClass('StockMoveUnion', array(
    95       'Title' => 'Skladový pohyb',
    96       'BaseTable' => 'StockMove',
    97       'DefaultSortColumn' => 'Time',
    98       'SQL' => '(SELECT *, -1 AS `Direction`, `StockFrom` AS `Stock`, `StockTo` AS `StockOther` FROM `StockMove`) '.
    99         'UNION (SELECT *, 1 AS `Direction`, `StockTo` AS `Stock`, `StockFrom` AS `StockOther` FROM `StockMove`)',
    100       'Items' => array(
    101         'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => ''),
    102         'BillCode' => array('Type' => 'String', 'Caption' => 'Označení', 'Default' => ''),
    103         'Time' => array('Type' => 'DateTime', 'Caption' => 'Čas', 'Default' => ''),
    104         'Stock' => array('Type' => 'TStock', 'Caption' => 'První sklad', 'Default' => '', 'Null' => true),
    105         'StockOther' => array('Type' => 'TStock', 'Caption' => 'Druhý sklad', 'Default' => '', 'Null' => true),
    106         'File' => array('Type' => 'TFile', 'Caption' => 'Doklad', 'Default' => '', 'Null' => true),
    107         'Price' => array('Type' => 'Float', 'Caption' => 'Cena', 'Default' => '',
    108           'ReadOnly' => true, 'Suffix' => 'Kč', 'SQL' => '(SELECT `TX`.`Direction` * SUM(`StockMoveItem`.`UnitPrice` * `StockMoveItem`.`Amount`) FROM `StockMoveItem` '.
    109           'WHERE `StockMoveItem`.`StockMove`=#Id)'),
    110         'Items' => array('Type' => 'TStockMoveItemListStockMove', 'Caption' => 'Položky', 'Default' => ''),
    111       ),
    112       'BeforeInsert' => array($this, 'BeforeInsertStockMove'),
     94      //'AfterInsert' => array($this, 'AfterInsertStockMove'),
     95      //'BeforeModify' => array($this, 'BeforeModifyStockMove'),
    11396    ));
    11497    $this->System->FormManager->RegisterClass('StockMoveItem', array(
    11598      'Title' => 'Položka skladového pohybu',
    11699      'Table' => 'StockMoveItem',
    117       'DefaultSortColumn' => 'Text',
     100      'DefaultSortColumn' => 'Product',
    118101      'Items' => array(
    119102        'StockMove' => array('Type' => 'TStockMove', 'Caption' => 'Skladový pohyb', 'Default' => ''),
    120103        'Product' => array('Type' => 'TProduct', 'Caption' => 'Produkt', 'Default' => ''),
     104        'UnitPrice' => array('Type' => 'Integer', 'Caption' => 'Jednotková cena', 'Default' => '0', 'Suffix' => 'Kč'),
    121105        'Amount' => array('Type' => 'Integer', 'Caption' => 'Množství', 'Default' => '1'),
    122         'Text' => array('Type' => 'String', 'Caption' => 'Text', 'Default' => ''),
    123         'UnitPrice' => array('Type' => 'Integer', 'Caption' => 'Jednotková cena', 'Default' => '0', 'Suffix' => 'Kč'),
     106        'Total' => array('Type' => 'Integer', 'Caption' => 'Celkem', 'Default' => '', 'Suffix' => 'Kč',
     107          'ReadOnly' => true, 'SQL' => 'ROUND(`UnitPrice` * `Amount`, '.$Config['Finance']['Rounding'].')'),
     108      ),
     109    ));
     110    $this->System->FormManager->RegisterClass('StockMoveGroup', array(
     111      'Title' => 'Skupina skladových pohybů',
     112      'Table' => 'StockMoveGroup',
     113      'Items' => array(
     114        'Name' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => '0'),
     115        'DocumentLine' => array('Type' => 'TDocumentLine', 'Caption' => 'Dokladová řada', 'Default' => '0'),
     116        'ValueSign' => array('Type' => 'TFinanceValueSign', 'Caption' => 'Znaménko hodnoty', 'Default' => '0'),
     117        'Direction' => array('Type' => 'TFinanceDirection', 'Caption' => 'Směr', 'Default' => '0'),
     118        'Items' => array('Type' => 'TStockMoveListGroup', 'Caption' => 'Operace', 'Default' => ''),
    124119      ),
    125120    ));
     
    148143      'Filter' => '1',
    149144    ));
     145    $this->System->FormManager->RegisterFormType('TStockMoveListGroup', array(
     146      'Type' => 'ManyToOne',
     147      'Table' => 'StockMove',
     148      'Id' => 'Id',
     149      'Ref' => 'Group',
     150      'Filter' => '1',
     151    ));
    150152    $this->System->FormManager->RegisterFormType('TStockMoveStock', array(
    151153      'Type' => 'ManyToOne',
    152       'Table' => 'StockMoveUnion',
     154      'Table' => 'StockMove',
    153155      'Id' => 'Id',
    154156      'Ref' => 'Stock',
     
    159161      'Table' => 'StockMove',
    160162      'Id' => 'Id',
    161       'Name' => 'BillCode',
     163      'Name' => '(SELECT `DocumentLineCode`.`Name` FROM `DocumentLineCode` WHERE `Id`=`StockMove`.`BillCode`)',
    162164      'Filter' => '1',
    163165    ));
     
    172174      'Type' => 'Reference',
    173175      'Table' => 'Stock',
     176      'Id' => 'Id',
     177      'Name' => 'Name',
     178      'Filter' => '1',
     179    ));
     180    $this->System->FormManager->RegisterFormType('TStockMoveGroup', array(
     181      'Type' => 'Reference',
     182      'Table' => 'StockMoveGroup',
    174183      'Id' => 'Id',
    175184      'Name' => 'Name',
     
    196205    if(array_key_exists('Time', $Form->Values)) $Year = date("Y", $Form->Values['Time']);
    197206      else $Year = date("Y", $Form->Values['ValidFrom']);
    198     $DocumentLine = $Form->Values['DocumentLine'];
    199     $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumber($DocumentLine, $Year);
     207    $Group = $this->System->Modules['Finance']->GetFinanceGroupById($Form->Values['Group'], 'StockMoveGroup');
     208    $Form->Values['BillCode'] = $this->System->Modules['Finance']->GetNextDocumentLineNumberId($Group['DocumentLine'], $Year);
    200209    return($Form->Values);
    201210  }
Note: See TracChangeset for help on using the changeset viewer.