# -*- coding: utf-8 -*-
from ppms.migration import ChangeDTPPacket, SQLPacket, PacketCategory, MaxVersionDependency, VersionType
from ppms.constants import *
class SetFilterForChartDisplaying(ChangeDTPPacket, SQLPacket):
    '''set filter from and filter to in DA 045074 in MOD 009A52 for running Cost and Effort Charts for new released Statusreports.
    These Changes only required for ORACLE because MSSQL charts are correct without these filter values.'''
    
    wi_number = 14695  # The workitem number this packet belongs to. Only relevant for packets by PLANTA
    version = 1
    done_after_success = True  # Sets the "Erledigt" flag after running successfully
    run_on_startup = True  # Runs this migration packet when the server is started in migration mode
    category = PacketCategory.CATEGORY_MANDATORY  # Categorizes the packet
    
    def get_dependencies(self):
        return MaxVersionDependency(version='39.4', version_type=VersionType.CUSTOMIZING)
        
    def fix(self, runner):

        if self.DBMS == DBMS_MSSQL:
            self.log("Only required for systems running on ORACLE Server.")
            return self.success()
        
        OLD_VALUE = ''
        NEW_VALUE = '0.1'
    
        record = self.get_record(411, ['046074',714074], ['filter_from'])
        if not self.change_value(record, 'filter_from', OLD_VALUE, NEW_VALUE):
            return self.fail()

        
        OLD_VALUE = ''
        NEW_VALUE = '99999999999999'
        
        record = self.get_record(411, ['046074',714074], ['filter_to'])
        if not self.change_value(record, 'filter_to', OLD_VALUE, NEW_VALUE):
            return self.fail()

    
        
        OLD_VALUE = ''
        NEW_VALUE = '0.1'
    
        record = self.get_record(411, ['046074',714075], ['filter_from'])
        if not self.change_value(record, 'filter_from', OLD_VALUE, NEW_VALUE):
            return self.fail()

       
        
        OLD_VALUE = ''
        NEW_VALUE = '99999999999999'
        
        record = self.get_record(411, ['046074',714075], ['filter_to'])
        if not self.change_value(record, 'filter_to', OLD_VALUE, NEW_VALUE):
            return self.fail()

     
        
        OLD_VALUE = ''
        NEW_VALUE = '0.1'
    
        record = self.get_record(411, ['046074',714077], ['filter_from'])
        if not self.change_value(record, 'filter_from', OLD_VALUE, NEW_VALUE):
            return self.fail()

      
        
        OLD_VALUE = ''
        NEW_VALUE = '99999999999999'
        
        record = self.get_record(411, ['046074',714077], ['filter_to'])
        if not self.change_value(record, 'filter_to', OLD_VALUE, NEW_VALUE):
            return self.fail()

      
        
        OLD_VALUE = ''
        NEW_VALUE = '0.1'
    
        record = self.get_record(411, ['046074',714078], ['filter_from'])
        if not self.change_value(record, 'filter_from', OLD_VALUE, NEW_VALUE):
            return self.fail()

 
        
        OLD_VALUE = ''
        NEW_VALUE = '99999999999999'
        
        record = self.get_record(411, ['046074',714078], ['filter_to'])
        if not self.change_value(record, 'filter_to', OLD_VALUE, NEW_VALUE):
            return self.fail()

        return self.success()