<commit_before>#!/bin/env python
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
# Name:         magazz/provage/dbtables.py
# Author:       <NAME> <<EMAIL>>
# Copyright:    (C) 2011 <NAME>.l. <NAME>, 122 18038 Sanremo (IM)
# ------------------------------------------------------------------------------
# This file is part of X4GA
# 
# X4GA is free software: you can redistribute it and/or modify
# it under the terms of the Affero GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# X4GA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with X4GA.  If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------------


import Env
bt = Env.Azienda.BaseTab

import stormdb as adb


class ProvvigAgentiDetTable(adb.DbTable):
    
    def __init__(self):
        adb.DbTable.__init__(self, bt.TABNAME_MOVMAG_B, 'mov', fields=None)
        tpm = self.AddJoin(bt.TABNAME_CFGMAGMOV, 'tipmov', idLeft='id_tipmov', fields=None)
        pro = self.AddJoin(bt.TABNAME_PROD,      'prod', idLeft='id_prod', fields=None, join=adb.JOIN_LEFT)
        iva = self.AddJoin(bt.TABNAME_ALIQIVA,   'aliqiva', idLeft='id_aliqiva', fields=None)
        doc = self.AddJoin(bt.TABNAME_MOVMAG_H,  'doc', idLeft='id_doc', fields=None)
        tpd = doc.AddJoin(bt.TABNAME_CFGMAGDOC,  'tipdoc', idLeft='id_tipdoc', fields=None)
        age = doc.AddJoin(bt.TABNAME_AGENTI,     'age', idLeft='id_agente', fields=None)
        pdc = doc.AddJoin(bt.TABNAME_PDC,        'pdc', idLeft='id_pdc', fields=None)
        dst = doc.AddJoin(bt.TABNAME_DESTIN,     'dest', idLeft='id_dest', fields=None, join=adb.JOIN_LEFT)
        sca = doc.AddJoin(bt.TABNAME_CONTAB_S,   'sca', idLeft='id_reg', idRight='id_reg', fields=None, join=adb.JOIN_LEFT)
        pcf = sca.AddJoin(bt.TABNAME_PCF,        'pcf', idLeft='id_pcf', fields=None, join=adb.JOIN_LEFT)
        
        self._AddGroups()
        
        self.AddTotalOf('mov.importo*(tipdoc.provvig)',                'vendita')
        self.AddAverageOf('mov.perpro',                                'perpro')
        self.AddTotalOf('mov.importo*mov.perpro*(tipdoc.provvig)/100', 'provvig')
        self.AddTotalOf('pcf.imptot-pcf.imppar',                       'saldo')
        
        self.AddBaseFilter('tipdoc.provvig IN (1, -1)')
        self.AddBaseFilter('tipmov.noprovvig IS NULL OR tipmov.noprovvig<>1')
        self.AddBaseFilter('age.noprovvig IS NULL OR age.noprovvig<>1')
        
        self._AddOrders()
        self.Reset()
    
    def _AddGroups(self):
        self.AddGroupOn('mov.id',          'mov_id')
        self.AddGroupOn('mov.id_doc',      'mov_id_doc')
        self.AddGroupOn('doc.datreg',      'doc_datreg')
        self.AddGroupOn('doc.datdoc',      'doc_datdoc')
        self.AddGroupOn('doc.numdoc',      'doc_numdoc')
        self.AddGroupOn('doc.id_agente',   'age_id')
        self.AddGroupOn('age.codice',      'age_codice')
        self.AddGroupOn('age.descriz',     'age_descriz')
        self.AddGroupOn('pdc.id',          'pdc_id')
        self.AddGroupOn('pdc.codice',      'pdc_codice')<commit_msg>calcolo provvigioni agente: se percentuale di calcolo non è impostata sulla riga del documento, viene presa dal prodotto relativo<commit_after>#!/bin/env python
# -*- coding: utf-8 -*-
# ------------------------------------------------------------------------------
# Name:         magazz/provage/dbtables.py
# Author:       <NAME> <<EMAIL>>
# Copyright:    (C) 2011 Astra S.r.l. <NAME>, 122 18038 Sanremo (IM)
# ------------------------------------------------------------------------------
# This file is part of X4GA
# 
# X4GA is free software: you can redistribute it and/or modify
# it under the terms of the Affero GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# X4GA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with X4GA.  If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------------


import Env
bt = Env.Azienda.BaseTab

import stormdb as adb


class ProvvigAgentiDetTable(adb.DbTable):
    
    def __init__(self):
        adb.DbTable.__init__(self, bt.TABNAME_MOVMAG_B, 'mov', fields=None)
        tpm = self.AddJoin(bt.TABNAME_CFGMAGMOV, 'tipmov', idLeft='id_tipmov', fields=None)
        pro = self.AddJoin(bt.TABNAME_PROD,      'prod', idLeft='id_prod', fields=None, join=adb.JOIN_LEFT)
        iva = self.AddJoin(bt.TABNAME_ALIQIVA,   'aliqiva', idLeft='id_aliqiva', fields=None)
        doc = self.AddJoin(bt.TABNAME_MOVMAG_H,  'doc', idLeft='id_doc', fields=None)
        tpd = doc.AddJoin(bt.TABNAME_CFGMAGDOC,  'tipdoc', idLeft='id_tipdoc', fields=None)
        age = doc.AddJoin(bt.TABNAME_AGENTI,     'age', idLeft='id_agente', fields=None)
        pdc = doc.AddJoin(bt.TABNAME_PDC,        'pdc', idLeft='id_pdc', fields=None)
        dst = doc.AddJoin(bt.TABNAME_DESTIN,     'dest', idLeft='id_dest', fields=None, join=adb.JOIN_LEFT)
        sca = doc.AddJoin(bt.TABNAME_CONTAB_S,   'sca', idLeft='id_reg', idRight='id_reg', fields=None, join=adb.JOIN_LEFT)
        pcf = sca.AddJoin(bt.TABNAME_PCF,        'pcf', idLeft='id_pcf', fields=None, join=adb.JOIN_LEFT)
        
        self._AddGroups()
        
        self.AddTotalOf('mov.importo*(tipdoc.provvig)', 'vendita')
        self.AddAverageOf('IF(mov.perpro IS NULL, prod.perpro, mov.perpro)', 'perpro')
        self.AddTotalOf('mov.importo*IF(mov.perpro IS NULL, prod.perpro, mov.perpro)*(tipdoc.provvig)/100', 'provvig')
        self.AddTotalOf('pcf.imptot-pcf.imppar', 'saldo')
        
        self.AddBaseFilter('tipdoc.provvig IN (1, -1)')
        self.AddBaseFilter('tipmov.noprovvig IS NULL OR tipmov.noprovvig<>1')
        self.AddBaseFilter('age.noprovvig IS NULL OR age.noprovvig<>1')
        
        self._AddOrders()
        self.Reset()
    
    def _AddGroups(self):
        self.AddGroupOn('mov.id',          'mov_id')
        self.AddGroupOn('mov.id_doc',      'mov_id_doc')
        self.AddGroupOn('doc.datreg',      'doc_datreg')
        self.AddGroupOn('doc.datdoc',      'doc_datdoc')
        self.AddGroupOn('doc.numdoc',      'doc_numdoc')
        self.AddGroupOn('doc.id_agente',   'age_id')
        self.AddGroupOn('age.codice',      'age_codice')
        self.AddGroupOn('age.descriz',     'age_descriz')
        self.AddGroupOn('pdc.id',          'pdc_id')
        self.AddGroupOn('pdc.codice',      'pdc_codice')
{'fraction_non_alphanumeric': 0.1889708954184654, 'fraction_numerical': 0.006962818548948615, 'mean_word_length': 2.3389121338912133, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6026232', 'n_tokens_mistral': 2454, 'n_tokens_neox': 2374, 'n_words': 504}