# -*- coding:utf-8 -*-
from rh.ac.models import *
from datetime import datetime
from contrib.utils import DateRange, MultipleDateRange
import sys
import os
import time
from standard.models import ClassCode
MONTHS = [6,7,8,9,10,11]
YEAR = 2022
#ABRIR/FECHAR MESES
def open_close_months(close=False):
for month in MONTHS:
print'ABRINDO/FECHANDO MES : {}'.format(month)
MonthActivity.closing_months(month,YEAR,close)
#ATUALIZAR OS CALCS
def update_calcs():
classcode = ClassCode.objects.get(slug='ac-mppi-calculation')
cfgs = Configuration.objects.filter()
for cfg in cfgs:
print 'SALVANDO CFG:',cfg ,classcode
cfg.calculation = classcode
cfg.save()
def update_mas():
mas = MonthActivity.objects.filter(month=6,year=YEAR)
startTime = datetime.now()
total = len(mas)
atual = 0
print '<<< ATUALIZANDO SALDO MONTHACTIVITYS >>>'
for ma in mas:
atual+=1
print_pct(atual,total,datetime.now() - startTime,ma)
# print 'atualizando saldo', ma
ma.save()
def print_pct(atual,total,segundos_gastos,texto=None):
pct = int((float(atual)/float(total)*100))
pct_float = float(atual)/float(total)*100
qnt = pct/2
barra = ''
segundos_gastos = segundos_gastos.seconds
total_segundos = int((float(segundos_gastos) / pct_float)*100)
for q in range(1, qnt, 1):
barra +='|'
for q in range(1, 51 - qnt, 1):
barra += ' '
barra = '['+barra+'] '
sys.stdout.write("\033[F") # Cursor up one line
if texto:
print texto
print barra + str(pct) +' /100%' + ' tempo gasto: '+ time.strftime('%H:%M:%S', time.gmtime(segundos_gastos)) + ' | previsao total : ' + time.strftime('%H:%M:%S', time.gmtime(total_segundos))
def get_balance_zero():
mas = MonthActivity.objects.filter(month=3,year=2023,balance__lt=0)
for ma in mas:
print ma
#ABRINDO OS MESES
open_close_months(False)
update_calcs()
update_mas()