예제 #1
0
    def val_litro(self, update, context):
        user = update.message.from_user

        try:
            if (float(update.message.text) < 0):
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text=
                    'Valor do litro inválido. Por favor, informe novamente!')
                return VAL_LITRO
        except:
            replaced = str(update.message.text).replace(',', '.')
            try:
                if (float(replaced) < 0):
                    context.bot.send_message(
                        chat_id=update.effective_chat.id,
                        text=
                        'Valor do litro inválido. Por favor, informe novamente!'
                    )
                    return VAL_LITRO
            except:
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text=
                    'Formato invalido de valor do litro. Por favor, informe novamente!'
                )
                return VAL_LITRO

        if (float(update.message.text.replace(',', '.')) > 10):
            context.bot.send_message(
                chat_id=update.effective_chat.id,
                text=
                'O valor do litro inserido é muito grande (limite de R$ 10,00). Por favor, informe novamente!\n Lembre-se de enviar o valor com vírgula ou ponto, ex: 3,65 no lugar de 365'
            )
            return VAL_LITRO

        replaced = str(update.message.text).replace('.', ',')

        listUtils.searchAndUpdate(buff, update.message.from_user.username,
                                  update.message.chat.id, 'val_litro',
                                  replaced)

        self.logger.info('Valor do litro informado por %s: %s',
                         user.first_name, update.message.text)

        # update.message.reply_text(
        #     'Valor do litro informado: '+update.message.text+'\n'
        #     'Agora informe o valor total:')

        reply_keyboard = [['DIESEL COMUM', 'DIESEL S-10'],
                          ['GASOLINA ADITIVIDADA', 'GASOLINA COMUM']]

        update.message.reply_text(
            'Valor do litro informado: ' + update.message.text + '\n'
            'Agora informe o tipo de combustivel:',
            reply_markup=ReplyKeyboardMarkup(reply_keyboard,
                                             one_time_keyboard=True))

        # return VAL_TOTAL
        return TP_COMBUSTIVEL
예제 #2
0
    def qnt_litro(self, update, context):
        user = update.message.from_user

        try:
            if (float(update.message.text) < 0):
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text=
                    'Quantidade de litros inválidos. Por favor, informe novamente!'
                )
                return QNT_LITRO
        except:
            replaced = str(update.message.text).replace(',', '.')
            try:
                if (float(replaced) < 0):
                    context.bot.send_message(
                        chat_id=update.effective_chat.id,
                        text=
                        'Quantidade de litros inválidos. Por favor, informe novamente!'
                    )
                    return QNT_LITRO
            except:
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text=
                    'Formato invalido de quantidade de litros. Por favor, informe novamente!'
                )
                return QNT_LITRO

        if (float(update.message.text.replace(',', '.')) > 200):
            context.bot.send_message(
                chat_id=update.effective_chat.id,
                text=
                'A quantidade do litros abastecidos inserida é muito grande (limite de 200L). Por favor, informe novamente o valor correto!\n Lembre-se de enviar o valor com vírgula ou ponto, ex: 3,65 no lugar de 365'
            )
            return QNT_LITRO

        replaced = str(update.message.text).replace('.', ',')

        listUtils.searchAndUpdate(buff, update.message.from_user.username,
                                  update.message.chat.id, 'qnt_litro',
                                  replaced)

        self.logger.info('Quantidade de litros informada por %s: %s',
                         user.first_name, update.message.text)
        update.message.reply_text('Quantidade de litros informados: ' +
                                  update.message.text + '\n'
                                  'Agora informe o valor do litro:')

        return VAL_LITRO
예제 #3
0
    def tp_combustivel(self, update, context):
        user = update.message.from_user

        reply_keyboard = [['DIESEL COMUM', 'DIESEL S-10'],
                          ['GASOLINA ADITIVIDADA', 'GASOLINA COMUM']]

        if not update.message.text in [
                'DIESEL COMUM', 'DIESEL S-10', 'GASOLINA ADITIVIDADA',
                'GASOLINA COMUM'
        ]:
            update.message.reply_text(
                'Combustível inválido, por favor informe o tipo correto de combustivel.',
                reply_markup=ReplyKeyboardMarkup(reply_keyboard,
                                                 one_time_keyboard=True))

            return TP_COMBUSTIVEL

        listUtils.searchAndUpdate(buff, update.message.from_user.username,
                                  update.message.chat.id, 'tp_combustivel',
                                  update.message.text)

        self.logger.info('Combustivel informado por %s: %s', user.first_name,
                         update.message.text)

        reply_keyboard = [['MARLIN', 'LIDER'], ['OURO NEGRO', 'RIO NEGRO'],
                          ['DAMIANI', 'JR / DALLAS'],
                          ['TIMBOZAO / TREMENDAO', 'RAIZ'],
                          ['TANGUA', 'TREVÃO'], ['CAJU', 'TICKTLOG'],
                          ['NOSSA SENHORA DE FATIMA', 'SÃO CRISTOVÃO'],
                          ['GUARAVE', 'GUARAVE FILIAL'],
                          ['CARAVELA',
                           'POSTO DINO'], ['SANTA AMÉLIA', 'TULIPA'],
                          ['GOODCARD', 'REEMBOLSO']]

        update.message.reply_text(
            'Combustível informado: ' + update.message.text + '\n'
            'Agora informe o posto:',
            reply_markup=ReplyKeyboardMarkup(reply_keyboard,
                                             one_time_keyboard=True))

        return POSTO
예제 #4
0
    def quilometragem(self, update, context):
        user = update.message.from_user

        try:
            if (float(update.message.text) < 0):
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text='Quilometragem inválida. Por favor, informe novamente!'
                )
                return QUILOMETRAGEM
        except:
            replaced = str(update.message.text).replace(',', '.')
            try:
                if (float(replaced) < 0):
                    context.bot.send_message(
                        chat_id=update.effective_chat.id,
                        text=
                        'Quilometragem inválida. Por favor, informe novamente!'
                    )
                    return QUILOMETRAGEM
            except:
                context.bot.send_message(
                    chat_id=update.effective_chat.id,
                    text=
                    'Formato invalido de quilometragem. Por favor, informe novamente!'
                )
                return QUILOMETRAGEM

        replaced = str(update.message.text).replace('.', ',')

        listUtils.searchAndUpdate(buff, update.message.from_user.username,
                                  update.message.chat.id, 'quilometragem',
                                  replaced)

        self.logger.info('Quilometragem informada por %s: %s', user.first_name,
                         update.message.text)
        update.message.reply_text(
            'Quilometragem informada: ' + update.message.text + '\n'
            'Agora nos informe a quantidade de litros abastecidos')

        return QNT_LITRO
예제 #5
0
    def posto(self, update, context):
        user = update.message.from_user

        reply_keyboard = [['MARLIN', 'LIDER'], ['OURO NEGRO', 'RIO NEGRO'],
                          ['DAMIANI', 'JR / DALLAS'],
                          ['TIMBOZAO / TREMENDAO', 'RAIZ'],
                          ['TANGUA', 'TREVÃO'], ['CAJU', 'TICKTLOG'],
                          ['NOSSA SENHORA DE FATIMA', 'SÃO CRISTOVÃO'],
                          ['GUARAVE', 'GUARAVE FILIAL'],
                          ['CARAVELA',
                           'POSTO DINO'], ['SANTA AMÉLIA', 'TULIPA'],
                          ['GOODCARD', 'REEMBOLSO']]

        if not update.message.text in [
                'MARLIN', 'LIDER', 'OURO NEGRO', 'RIO NEGRO', 'DAMIANI',
                'JR / DALLAS', 'TIMBOZAO / TREMENDAO', 'RAIZ', 'CAJU',
                'TICKTLOG', 'NOSSA SENHORA DE FATIMA', 'SÃO CRISTOVÃO',
                'GUARAVE', 'GUARAVE FILIAL', 'CARAVELA', 'SANTA AMÉLIA',
                'TULIPA', 'POSTO DINO', 'GOODCARD', 'REEMBOLSO', 'TANGUA',
                'TREVÃO'
        ]:
            update.message.reply_text(
                'Posto inválido, por favor informe o posto correto.',
                reply_markup=ReplyKeyboardMarkup(reply_keyboard,
                                                 one_time_keyboard=True))

            return POSTO

        listUtils.searchAndUpdate(buff, update.message.from_user.username,
                                  update.message.chat.id, 'posto',
                                  update.message.text)

        self.logger.info('Posto informado por %s: %s', user.first_name,
                         update.message.text)

        update.message.reply_text(
            "Agora envie a foto da bomba antes do abastecimento.")

        return BOMBAINICIO
예제 #6
0
    def placa(self, update, context):
        user = update.message.from_user

        Session = Database.Session
        session = Session()

        placa = session.query(Veiculos).filter_by(
            placa=update.message.text).first()

        if placa is None:
            placas = []
            veiculos = session.query(Veiculos).order_by(Veiculos.placa.asc())

            for veiculo in veiculos:
                placas.append([veiculo.placa])

            update.message.reply_text(
                'Placa ' + update.message.text +
                ' inválida ou não encontrada na base de dados. ' +
                'Por favor, informe novamente a placa do veículo.',
                reply_markup=ReplyKeyboardMarkup(placas,
                                                 one_time_keyboard=True))
            session.close()
            return PLACA

        session.close()

        listUtils.searchAndUpdate(buff, update.message.from_user.username,
                                  update.message.chat.id, 'placa',
                                  update.message.text)

        self.logger.info("Placa informada por %s: %s", user.first_name,
                         update.message.text)
        update.message.reply_text('Placa informada: ' + update.message.text +
                                  '\n'
                                  'Agora nos informe a quilometragem atual.')

        return QUILOMETRAGEM
예제 #7
0
    def reabertura(self, update, context):
        item = listUtils.searchAndGetItem(buff,
                                          update.message.from_user.username,
                                          update.message.chat.id)

        if (update.message.text == 'Sim, confirmar'):
            listUtils.searchAndUpdate(
                buff, update.message.from_user.username,
                update.message.chat.id, 'fim_intervalo',
                datetime.now(timezone('America/Sao_Paulo')).replace(
                    second=0, microsecond=0))

            context.bot.send_message(chat_id=update.effective_chat.id,
                                     text='Salvando dados...')

            try:
                Session = Database.Session
                session = Session()

                if item.role == 'motorista':
                    motorista = session.query(Motorista).filter_by(
                        telegram_user=item.username).first()

                    pontoDb = session.query(PontosMotorista).filter_by(
                        motorista_id=motorista.id).order_by(
                            PontosMotorista.id.desc()).first()

                    intervalo = IntervalosDePontoMotorista(
                        pontoDb, pontoDb.saida, item.fim_intervalo)
                else:
                    administrativo = session.query(Administrativo).filter_by(
                        telegram_user=item.username).first()

                    pontoDb = session.query(PontosAdministrativo).filter_by(
                        administrativo_id=administrativo.id).order_by(
                            PontosAdministrativo.id.desc()).first()

                    intervalo = IntervalosDePontoAdministrativo(
                        pontoDb, pontoDb.saida, item.fim_intervalo)

                pontoDb.saida = None

                session.add(intervalo)
                session.add(pontoDb)
                session.commit()

                if item.role == 'motorista':
                    intervalos = session.query(
                        IntervalosDePontoMotorista).filter_by(
                            ponto_motorista_id=pontoDb.id)
                else:
                    intervalos = session.query(
                        IntervalosDePontoAdministrativo).filter_by(
                            ponto_administrativo_id=pontoDb.id)

                item.intervalos = intervalos

                session.close()
            except Exception as e:
                update.message.reply_text(
                    'Houve um erro ao tentar salvar! ' +
                    'O erro foi reportado, tente novamente mais tarde.',
                    reply_markup=ReplyKeyboardRemove())
                print(e)
                buff.pop(buff.index(item))
                return ConversationHandler.END

            buff.pop(buff.index(item))
            item.saida = None

            update.message.reply_text(
                'Dados enviados com sucesso! Caso haja alguma inconsistência favor informar para @renanmgomes ou @igorpittol.',
                reply_markup=ReplyKeyboardRemove())

            context.bot.send_message(chat_id=update.effective_chat.id,
                                     text=item.stringData(),
                                     parse_mode=ParseMode.MARKDOWN)

            return ConversationHandler.END
        elif (update.message.text == 'Não, finalizar'):
            context.bot.send_message(chat_id=update.effective_chat.id,
                                     text='Operação cancelada!',
                                     reply_markup=ReplyKeyboardRemove())

            buff.pop(buff.index(item))

            return ConversationHandler.END
        else:
            context.bot.send_message(
                chat_id=update.effective_chat.id,
                text='Resposta inválida, por favor, responda apenas com: ' +
                '"Sim, confirmar" ou "Não, finalizar"')

            update.message.reply_text(
                'Deseja confirmar a reabertura de expediente?',
                reply_markup=ReplyKeyboardMarkup(
                    [['Sim, confirmar'], ['Não, finalizar']],
                    one_time_keyboard=True))

            return REABERTURA