if not os.path.isfile(ftpLocalUrl): user_info = list(_mongodb.get(MONGO_COLLECTION=common.getSubUser(subUserType, 'User'), SELECT={'extension'})) user = common.array_column(user_info, 'extension') notification = { 'title' : f'Import {fileName} error', 'active' : True, 'icon' : 'fa fa-exclamation-triangle', 'color' : 'text-warning', 'content' : f'Không có file import đầu ngày <b style="font-size: 15px">{ftpLocalUrl}</b>. Xin vui lòng thông báo cho bộ phận IT', 'link' : '/manage/data/import_file', 'to' : list(user), 'notifyDate': datetime.utcnow(), 'createdBy' : 'System', 'createdAt' : time.time() } mongodb.insert(MONGO_COLLECTION=common.getSubUser(subUserType, 'Notification'), insert_data=notification) sys.exit() importLogInfo = { 'collection' : collection, 'begin_import' : time.time(), 'file_name' : fileName, 'file_path' : ftpLocalUrl, 'source' : 'ftp', 'status' : 2, 'command' : '/usr/local/bin/python3.6 ' + base_url + "cronjob/python/Loan/importLNJC05Yesterday.py > /dev/null &", 'created_by' : 'system' } importLogId = mongodb.insert(MONGO_COLLECTION=common.getSubUser(subUserType, 'Import'), insert_data=importLogInfo) models = _mongodb.get(MONGO_COLLECTION='Model', WHERE={'collection': modelCollection}, SORT=[('index', 1)], SELECT=['index', 'collection', 'field', 'type', 'sub_type'])
if not os.path.isfile(ftpLocalUrl): sys.exit() importLogInfo = { 'collection': collection, 'begin_import': time.time(), 'file_name': fileName, 'file_path': ftpLocalUrl, 'source': 'ftp', 'status': 2, 'command': '/usr/local/bin/python3.6 ' + base_url + "cronjob/python/Loan/importLawsuit.py > /dev/null &", 'created_by': 'system' } importLogId = mongodb.insert(MONGO_COLLECTION=common.getSubUser( subUserType, 'Import'), insert_data=importLogInfo) models = _mongodb.get( MONGO_COLLECTION='Model', WHERE={'collection': collection}, SORT=[('index', 1)], SELECT=['index', 'collection', 'field', 'type', 'sub_type']) for model in models: if 'sub_type' in model.keys() and model['sub_type'] not in ['', ' ']: modelColumns.append(model['field']) modelConverters[model['field']] = model['type'] modelConverters1.append(model['type']) subtype = json.loads(model['sub_type']) if 'format' in subtype.keys():
# log.write(str(extensions)) now = datetime.now() log.write(now.strftime("%d/%m/%Y, %H:%M:%S") + ': Start Log' + '\n') mongodb.update(MONGO_COLLECTION='TS_Import', WHERE={'_id': ObjectId(importLogId)}, VALUE={'assign': int(-1)}) assign_log = mongodb.getOne(MONGO_COLLECTION='TS_Assign_log') if assign_log == None: users = _mongodb.get(MONGO_COLLECTION='TS_User', WHERE=None, SELECT=['extension', 'agentname'], SORT=([('id', 1)])) users = list(users) # log.write(str(users)) arrayCMND = {} assign_log = {} for user in users: arrayCMND[user['extension']] = [] assign_log[user['extension']] = [] assign_log['_id'] = mongodb.insert('TS_Assign_log', arrayCMND) array_cmnd = [] for u,extension in enumerate(extensions): user = _mongodb.getOne(MONGO_COLLECTION='TS_User', WHERE={'extension': str(extension)}, SELECT=['extension', 'agentname']) assign_name = user['agentname'] random = randoms[u] if extension in assign_log.keys(): array_cmnd = assign_log[extension] else: array_cmnd = [] quotient = int(random)/10000 mod = int(random)%10000 dem = 0 if quotient != 0: for x in range(int(quotient)):
}) target = targetInfo['target'] temp['tar_amt'] = (target * temp['inci_amt']) / 100 temp['tar_per'] = target / 100 if debtGroupCell[0:1] == 'A' or debtGroupCell[ 0:1] == 'B' or debtGroupCell[0:1] == 'C': temp['tar_gap'] = temp['tar_amt'] - temp['payment_amt'] else: temp['tar_gap'] = temp['tar_amt'] - temp['col_amt'] temp['createdAt'] = todayTimeStamp temp['createdBy'] = 'system' temp['for_month'] = str(month) mongodb.insert(MONGO_COLLECTION=collection, insert_data=temp) if debtGroupCell[0:1] is not 'F' and debtGroupCell[0:1] is not 'A': dueDayOfMonth = mongodb.getOne( MONGO_COLLECTION=report_due_date_collection, WHERE={ 'for_month': str(month), 'debt_group': debtGroupCell[1:3] }) for groupProduct in list(listGroupProduct): groupInfoByDueDate = mongodb.get( MONGO_COLLECTION=group_collection, WHERE={ 'name': { "$regex": groupProduct['text'] + '/Group ' +
if exists_amount == 0 : mongodb.insert(MONGO_COLLECTION=collection_amount_report, insert_data={ 'partner': row_partner, 'outsoucing' : { 'account' : { 'before' : { 'l30' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p30' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p60' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p90' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p180' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'subtotal':{ 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, }, 'writeof':{ 'p360':{ 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, } }, 'amount':{ 'before' : { 'l30' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p30' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p60' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p90' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p180' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'subtotal': { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, }, 'writeof' : { 'p360' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, } } }, 'collected' : { 'account' : { 'before' : { 'l30' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p30' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p60' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p90' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p180' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'subtotal' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, }, 'writeof' : { 'p360' : { 'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, } }, 'amount' : { 'before' : { 'l30' : {'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p30' : {'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p60' : {'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p90' : {'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'p180' : {'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, 'subtotal':{'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, }, 'writeof' : { 'p360' : {'T1':0,'T2':0,'T3':0,'T4':0,'T5':0,'T6':0,'T7':0,'T8':0,'T9':0,'T10':0,'T11':0,'T12':0}, } } }, 'year' : str(year) })
}] sbvInfo = mongodb.aggregate_pipeline( MONGO_COLLECTION=common.getSubUser( subUserType, 'SBV'), aggregate_pipeline=aggregate_sbv) if sbvInfo is not None: for sbv in sbvInfo: temp['ob_principal_total'] = float( sbv['sale_total']) + float( sbv['cash_total']) temp['created_at'] = time.time() temp['created_by'] = 'system' temp['for_month'] = str(month) mongodb.insert(MONGO_COLLECTION=common.getSubUser( subUserType, 'Due_date_next_date'), insert_data=temp) groupInfo = mongodb.get(MONGO_COLLECTION=common.getSubUser( subUserType, 'Group'), WHERE={ 'name': { "$regex": 'WO' }, 'debt_groups': { '$exists': 'true' } }) if groupInfo is not None: for groupCell in groupInfo: temp = {
temp['group'] = '4' if zaccf['_id'] == 'E': temp['group'] = '5' temp['count_data'] = zaccf['count_data'] temp['total_org'] = zaccf['total_org'] temp['ratio'] = temp['total_org'] / sum_org if sum_org != 0 else 0 temp['year'] = str(year) temp['month'] = month temp['weekday'] = weekday temp['day'] = yesterdayString temp['weekOfMonth'] = weekOfMonth temp['type'] = 'sibs' temp['createdBy'] = 'system' temp['createdAt'] = todayTimeStamp mongodb.insert(MONGO_COLLECTION=collection, insert_data=temp) insertTotal = { 'year': str(year), 'month': month, 'weekday': weekday, 'day': yesterdayString, 'weekOfMonth': weekOfMonth, 'type': 'sibs', 'createdBy': 'system', 'createdAt': todayTimeStamp } insertTotalG2 = { 'year': str(year), 'month': month, 'weekday': weekday,
todayIndex] updateDataYesterday[ 'updated_at'] = time.time() # pprint(temp) mongodb.update( MONGO_COLLECTION=common.getSubUser( subUserType, 'Daily_prod_working_day'), WHERE={ 'team_id': str(groupCell['_id']), 'day_code': key, 'updated_at': { '$gte': yesterday_starttime, '$lte': yesterday_endtime } }, VALUE=updateDataYesterday) else: pprint(temp) mongodb.insert( MONGO_COLLECTION=common.getSubUser( subUserType, 'Daily_prod_working_day'), insert_data=temp) # checkYesterdayExist = print('DONE') except Exception as e: # log.write(now.strftime("%d/%m/%Y, %H:%M:%S") + ': ' + str(e) + '\n') pprint(str(e))
oldReportData = mongodb.get( MONGO_COLLECTION=collection, WHERE={ 'team_id': str(groupCell['_id']), 'due_date_code': debtGroupCell[1:3], 'month': str(oldMonth) }) if oldReportData != None: for oldReportDt in oldReportData: temp_old['pay_amt'] += oldReportDt[ 'pay_amt'] temp_old['createdAt'] = time.time() temp_old['createdBy'] = 'system' mongodb.insert(MONGO_COLLECTION=collection, insert_data=temp_old) tempOldTotal['tar_acc'] += temp_old['tar_acc'] tempOldTotal['tar_amt'] += temp_old['tar_amt'] tempOldTotal['col'] += temp_old['col'] tempOldTotal['total_amt'] += temp_old[ 'total_amt'] tempOldTotal['paid_acc'] += temp_old[ 'paid_acc'] tempOldTotal['paid_amt'] += temp_old[ 'paid_amt'] tempOldTotal['pay_amt'] += temp_old['pay_amt'] if groupProduct['value'] == 'SIBS': lead = ['JIVF00' + groupCell['lead'] ] if 'lead' in groupCell.keys() else []