示例#1
0
 def createXMLDocument(self, accountRecord, destOKATO):
     doc = CXMLHelper.createDomDocument(rootElementName='ZL_LIST',
                                        encoding=self.encoding)
     rootElement = CXMLHelper.getRootElement(doc)
     self.addHeaderElement(rootElement, destOKATO)
     accountElement = self.addAccountElement(rootElement, accountRecord)
     return doc, accountElement
示例#2
0
 def processReport(self, doc):
     db = QtGui.qApp.db
     rootElement = CXMLHelper.getRootElement(doc)
     reportElement = self.getElement(rootElement, 'REPORT', True)
     reportName = self.getElementValue(reportElement, 'NAME')
     reportId = db.translate('rcReport', 'name', reportName, 'id')
     if reportId:
         msg = QtGui.QMessageBox.warning(
             self._parent._parent, u'Внимание!',
             u"Отчёт с именем '%s' уже существует.\nOk - заменить.\nSave - сохранить с другим именем."
             % reportName, QtGui.QMessageBox.Ok | QtGui.QMessageBox.Save
             | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok)
         if msg == QtGui.QMessageBox.Cancel:
             return
         elif msg == QtGui.QMessageBox.Ok:
             self.deleteReport(reportId)
         elif msg == QtGui.QMessageBox.Save:
             idx = 1
             while db.translate('rcReport', 'name',
                                u'%s_%d' % (reportName, idx), 'id'):
                 idx += 1
             reportName = u'%s_%d' % (reportName, idx)
     self.parceReport(reportElement, reportName)
示例#3
0
    def process(self, accountId):
        self.isAbort = False
        self.phaseReset(11)

        db = QtGui.qApp.db

        tableOrganisation = self._db.table('Organisation')

        tableAccount = self._db.table('Account')
        tableContract = self._db.table('Contract')
        tableContractPayer = tableOrganisation.alias(
            'ContractPayer')  # Сторонний фонд, в который происходит выгрузка
        tableContractRecipient = tableOrganisation.alias(
            'ContractRecipient')  # Текущий фонд, откуда происходит выгрузка

        queryTable = tableAccount.innerJoin(
            tableContract, tableContract['id'].eq(tableAccount['contract_id']))
        queryTable = queryTable.innerJoin(
            tableContractPayer,
            tableContractPayer['id'].eq(tableContract['payer_id']))
        queryTable = queryTable.innerJoin(
            tableContractRecipient,
            tableContractRecipient['id'].eq(tableContract['recipient_id']))

        cols = [
            tableAccount['settleDate'], tableAccount['number'],
            tableAccount['exposeDate'], tableAccount['sum'],
            tableContractPayer['OKATO'].alias('payerOKATO'),
            tableContractPayer['infisCode'].alias('payerInfis'),
            tableContractPayer['area'].alias('payerArea'),
            tableContractRecipient['OKATO'].alias('recipientOKATO'),
            tableContractRecipient['infisCode'].alias('recipientInfis')
        ]

        self.nextPhase(3, u'Загрузка данных по счету')
        accountRecord = self._db.getRecordEx(
            queryTable, cols, where=tableAccount['id'].eq(accountId))

        currentInfis = forceStringEx(accountRecord.value('recipientInfis'))

        insuranceArea = forceStringEx(accountRecord.value('payerArea'))
        insurerFundOKATO = forceStringEx(accountRecord.value('payerOKATO'))
        insurerFundInfis = forceStringEx(accountRecord.value('payerInfis'))

        tableAccount = db.table('Account')
        tableAccountItem = db.table('Account_Item')
        tablePayRefuseType = db.table('rbPayRefuseType')

        tableEvent = db.table('Event')
        tableMedicalAidUnit = db.table('rbMedicalAidUnit')

        tableClientPolicy = db.table('ClientPolicy')
        tablePolicyKind = db.table('rbPolicyKind')

        cols = [  # account
            tableAccount['settleDate'],
            tableAccount['number'],
            tableAccount['exposeDate'],
            tableAccount['sum'],
            tableAccount['payedSum'].alias('summap'),
            tableAccount['refusedSum'].alias('sank_mek'),

            # client
            tableClientPolicy['id'].alias('clientPolicyId'),
            tablePolicyKind['federalCode'].alias('policyKindCode'),
            tableClientPolicy['serial'].alias('policySerial'),
            tableClientPolicy['number'].alias('policyNumber'),

            # event
            tableEvent['id'].alias('eventId'),
            tableEvent['externalId'],
            tableMedicalAidUnit['federalCode'].alias('eventAidUnitCode'),
            tableAccountItem['price'],
            tableAccountItem['sum'].alias('sumv'),
            u'''IF(Account_Item.date IS NULL AND Account_Item.refuseType_id IS NULL, 0,
                       IF(Account_Item.date IS NOT NULL AND Account_Item.refuseType_id IS NULL, 1, 2)) AS oplata''',
            'if(%s IS NULL, Account_Item.sum, 0) AS sump' %
            tablePayRefuseType['id'],
            'if(%s IS NOT NULL, Account_Item.sum, 0) AS sank_it' %
            tablePayRefuseType['id'],

            # sank
            tablePayRefuseType['flatCode'].alias('refuseTypeCode')
        ]

        queryTable = tableAccount.innerJoin(
            tableAccountItem,
            tableAccountItem['master_id'].eq(tableAccount['id']))
        queryTable = queryTable.innerJoin(
            tableEvent, tableEvent['id'].eq(tableAccountItem['event_id']))
        queryTable = queryTable.leftJoin(tableClientPolicy, [
            tableClientPolicy['client_id'].isNotNull(),
            '''ClientPolicy.id = (SELECT MAX(cp.id)
                                                                                   FROM ClientPolicy cp
                                                                                   WHERE cp.client_id = Event.client_id AND cp.deleted = 0)'''
        ])
        queryTable = queryTable.leftJoin(
            tablePolicyKind,
            tablePolicyKind['id'].eq(tableClientPolicy['policyKind_id']))
        queryTable = queryTable.leftJoin(
            tableMedicalAidUnit,
            tableMedicalAidUnit['id'].eq(tableAccountItem['unit_id']))
        queryTable = queryTable.leftJoin(tablePayRefuseType, [
            tablePayRefuseType['id'].eq(tableAccountItem['refuseType_id']),
            tableAccountItem['date'].isNotNull()
        ])

        cond = [
            tableAccount['id'].eq(accountId), tableAccountItem['deleted'].eq(0)
        ]

        self.nextPhaseStep(u'Загрузка данных по счету')
        recordList = self._db.getRecordList(queryTable, cols, where=cond)
        self.nextPhaseStep(u'Загрузка данных завершена')

        self.accCodeToAccountItemId.clear()
        entries = {}
        events = {}
        idCaseCounter = 0
        entryCounter = {}
        sankCounter = {}
        self.orgForDeferredFilling.clear()
        self.personSpecialityForDeferredFilling.clear()
        eventsTotal = {}
        oplataTotal = {}
        sankTotal = {}
        accountTotal = {}
        self.nextPhase(len(recordList), u'Обработка позиций счета')
        for record in recordList:
            if self.isAbort:
                self.onAborted()
                return False

            if not self.fileNames.has_key(insuranceArea):
                self.fileNames[insuranceArea] = (insurerFundInfis,
                                                 currentInfis)

            if not self.documents.has_key(insuranceArea):
                self.documents[insuranceArea] = self.createXMLDocument(
                    accountRecord, insurerFundOKATO)

            doc, accountElement = self.documents[insuranceArea]

            rootElement = CXMLHelper.getRootElement(doc)

            clientPolicyId = forceRef(record.value('clientPolicyId'))
            if not entries.has_key(clientPolicyId):
                entryCounter[insuranceArea] = entryCounter.setdefault(
                    insuranceArea, 0) + 1
                entries[clientPolicyId] = self.addEntryElement(
                    rootElement, record, entryCounter[insuranceArea])

            entryElement, _ = entries[clientPolicyId]

            eventId = forceStringEx(record.value('eventId'))

            if not events.has_key(eventId):
                sankTotal[eventId] = {}
                partsExternalId = forceStringEx(
                    record.value('externalId')).strip().split('#')
                if len(partsExternalId) >= 3:
                    idCaseCounter = max(idCaseCounter, partsExternalId[2])
                events[eventId] = self.addEventElement(
                    entryElement,
                    partsExternalId[2] if len(partsExternalId) >= 3 else None,
                    record)
            eventElement = events[eventId]

            refuseTypeCode = forceStringEx(record.value('refuseTypeCode'))
            if refuseTypeCode:
                if not sankTotal[eventId].has_key(refuseTypeCode):
                    sankCounter[eventId] = sankCounter.setdefault(eventId,
                                                                  0) + 1
                    sankTotal[eventId][refuseTypeCode] = [
                        self.addSankElement(eventElement,
                                            sankCounter[eventId],
                                            record=record), 0
                    ]
                sankTotal[eventId][refuseTypeCode][1] += forceDouble(
                    record.value('sumv'))
            if not eventsTotal.has_key(eventId):
                eventsTotal[eventId] = [0] * 3
                oplataTotal[eventId] = [0, 1]
            eventsTotal[eventId][0] += forceDouble(record.value('sumv'))
            eventsTotal[eventId][1] += forceDouble(record.value('sump'))
            eventsTotal[eventId][2] += forceDouble(record.value('sank_it'))
            oplataTotal[eventId][0] += 1
            oplataTotal[eventId][1] *= forceInt(record.value('oplata'))
            self.nextPhaseStep()

        for elementIdCase in self.notIdCase:
            idCaseCounter = forceInt(idCaseCounter) + 1
            CXMLHelper.setValue(elementIdCase, idCaseCounter)
        self.nextPhase(len(eventsTotal),
                       u'Заполнение данных о стоимости случаев')
        for eventId, total in eventsTotal.iteritems():
            eventElement = events[eventId]
            element = eventElement.firstChildElement('OPLATA')
            CXMLHelper.setValue(
                element, 0 if oplataTotal[eventId][1] == 0 else
                1 if oplataTotal[eventId][1] == 1 else
                2 if oplataTotal[eventId][1] %
                oplataTotal[eventId][0] == 0 else 3)
            if self.isAbort:
                self.onAborted()
                return False
            for index, elemName in enumerate(['SUMV', 'SUMP', 'SANK_IT']):
                element = eventElement.firstChildElement(elemName)
                CXMLHelper.setValue(element, '%.2f' % total[index])
                if not accountTotal.has_key(insuranceArea):
                    accountTotal[insuranceArea] = [0] * 3
                accountTotal[insuranceArea][index] += total[index]
            for refuseTypeCode, total in sankTotal[eventId].iteritems():
                sankElement = sankTotal[eventId][refuseTypeCode][0]
                element = sankElement.firstChildElement('S_SUM')
                CXMLHelper.setValue(element, '%.2f' % total[1])
            self.nextPhaseStep()

        self.nextPhase(len(accountTotal),
                       u'Заполнение данных об общей стоимости счетов')
        for insuranceArea, total in accountTotal.iteritems():
            if self.isAbort:
                self.onAborted()
                return False
            _, accountElement = self.documents[insuranceArea]
            for index, elemName in enumerate(['SUMMAV', 'SUMMAP', 'SANK_MEK']):
                element = accountElement.firstChildElement(elemName)
                CXMLHelper.setValue(element, '%.2f' % total[index])
            self.nextPhaseStep()

        self.logger().info(u'Завершено')
        if self.isAbort:
            self.onAborted()
            return False
        return True
示例#4
0
 def getRBRecordElementList(self, doc):
     rootElement = CXMLHelper.getRootElement(doc)
     rbElement = self.getElement(rootElement, 'REFBOOK', True)
     return self.getElementList(rbElement, 'RECORD')
示例#5
0
 def createXMLDocument(self, title):
     doc = CXMLHelper.createDomDocument(rootElementName='MAIN',
                                        encoding=self.encoding)
     rootElement = CXMLHelper.getRootElement(doc)
     self.addHeaderElement(rootElement)
     return doc, rootElement