Exemple #1
0
def companyIndex(request):
    json_data=None
    rolePermission=utilb.userRolePermission(request.user.company.id,request.user.user_id)
    dashboard=AvMasterDashboard.objects.values('id','short_name').filter(active_flag='Y').order_by('id')

    if request.method == "POST":
        if request.POST['short_name']!='' and request.POST['full_name']!='' and request.POST['address1']!='':

            if 'file' in request.FILES and request.FILES['file']!=[]:
                file_name = str(int(round(time.time() * 1000)))+'-'+str(request.FILES['file'])
                path = default_storage.save('static/uploaded/'+file_name, ContentFile(request.FILES['file'].read()))
            else:
                file_name=request.POST['edit_pic_name']

            if request.POST['company_id']=='':
                chk=AvMasterCompany.objects.filter(short_name=request.POST['short_name'].strip())
                if  len(chk)==0:
                    rp=AvMasterCompany(short_name=request.POST['short_name'].strip(), full_name=request.POST['full_name'], address1=request.POST['address1'],logo=file_name,active_flag=request.POST['active_flag'],address2=request.POST['address2'],city=request.POST['city'],state=request.POST['state'],country=request.POST['country'],zip_code=request.POST['zip_code'],primary_contact_name=request.POST['primary_contact_name'],primary_contact_email=request.POST['primary_contact_email'],primary_contact_phone=request.POST['primary_contact_phone'],secondary_contact_name=request.POST['secondary_contact_name'],secondary_contact_email=request.POST['secondary_contact_email'],secondary_contact_phone=request.POST['secondary_contact_phone'],landing_page_text=request.POST['landing_page_text'],single_sign_on_flag=request.POST['single_sign_on_flag'],last_updated_by=request.user.user_id,last_updated_date=datetime.now())
                    rp.save()
                    insert_process_in_company(rp.id,request.user.user_id)
                    json_data = json.dumps( { 'company': get_company() , 'status': 'success'} )
                else:
                    json_data = json.dumps( { 'status': 'danger'} )
            else:
                chk=AvMasterCompany.objects.filter(short_name=request.POST['short_name'].strip()).exclude(id=request.POST['company_id'])
                if  len(chk)==0:
                    AvMasterCompany.objects.filter(id=request.POST['company_id']).update(short_name=request.POST['short_name'].strip(), full_name=request.POST['full_name'], address1=request.POST['address1'],logo=file_name,active_flag=request.POST['active_flag'],address2=request.POST['address2'],city=request.POST['city'],state=request.POST['state'],country=request.POST['country'],zip_code=request.POST['zip_code'],primary_contact_name=request.POST['primary_contact_name'],primary_contact_email=request.POST['primary_contact_email'],primary_contact_phone=request.POST['primary_contact_phone'],secondary_contact_name=request.POST['secondary_contact_name'],secondary_contact_email=request.POST['secondary_contact_email'],secondary_contact_phone=request.POST['secondary_contact_phone'],landing_page_text=request.POST['landing_page_text'],single_sign_on_flag=request.POST['single_sign_on_flag'],last_updated_by=request.user.user_id,last_updated_date=datetime.now())
                    json_data = json.dumps( { 'company': get_company() , 'status': 'success'} )
                else:
                    json_data = json.dumps( { 'status': 'danger'} )

    else:
        json_data = json.dumps( { 'company': get_company(), 'dashboard': 'list(dashboard)' , 'rolePermission':rolePermission } )

    return HttpResponse( json_data , content_type='application/json')
Exemple #2
0
def dashboard_edit(request):
    dashboard_id=list(request.POST)
    dashboard_id=int(''.join(map(str,dashboard_id)))

    dash=AvMasterDashboard.objects.filter(id=dashboard_id)
    dash_json = serializers.serialize('json', dash )
    Data_dash_json = json.loads( dash_json )

    rolePermission=utilb.userRolePermission(request.user.company.id,request.user.user_id)

    process=AvMasterProcess.objects.values('id','short_name').filter(active_flag='Y').order_by('id')
    user_process=AvMasterProcessDashboards.objects.values('dashboard_id','process_id').filter(dashboard_id=dashboard_id)

    user_added_process=[]
    userP=[]
    for user_perm in user_process:
        proc=AvMasterProcess.objects.values('short_name').filter(id=user_perm['process_id'])
        userP.append(user_perm['process_id'])
        user_added_process.append([user_perm['process_id'],proc[0]['short_name']])

    processP = []
    for master_perm in process:
        if master_perm['id'] not in userP:
            processP.append([master_perm['id'],master_perm['short_name']])

    json_data = json.dumps( {'status': 'success' , 'dashboard':Data_dash_json, 'user_added_process': list(user_added_process) , 'processP':processP , 'rolePermission':rolePermission} )
    return HttpResponse( json_data , content_type='application/json' )
Exemple #3
0
def role_edit(request):
    role_id=list(request.POST)
    role_id=int(''.join(map(str,role_id)))
    role=AvMasterRoles.objects.filter(id=role_id)
    role_json = serializers.serialize('json', role )
    Data_role_json = json.loads( role_json )

    rolePermission=utilb.userRolePermission(request.user.company.id,request.user.user_id)
    permissions=''
    if 'Manage Restricted Role' in rolePermission:
        permissions=AvMasterPermissions.objects.values('id','permission').filter(active_flag='Y').order_by('id')
    else:
        permissions=AvMasterPermissions.objects.values('id','permission').filter(active_flag='Y').exclude(permission='Manage Restricted Role').order_by('id')

    user_permission=AvMasterRolePermissions.objects.values('permission_id','comments').filter(role_id=role_id)

    userP=[]
    for user_perm in user_permission:
        userP.append(user_perm['permission_id'])

    permissionsP = []
    for master_perm in permissions:
        if master_perm['id'] not in userP:
            permissionsP.append([master_perm['id'],master_perm['permission']])

    json_data = json.dumps( {'status': 'success' , 'role':Data_role_json, 'user_permission': list(user_permission) , 'permissions':permissionsP , 'rolePermission':rolePermission} )
    return HttpResponse( json_data , content_type='application/json' )
Exemple #4
0
def userIndex(request):
    from bson import json_util
    json_data=None
    rolePermission=utilb.userRolePermission(request.user.company.id,request.user.user_id)
    compData=''
    if 'View All Companies' in rolePermission:
        compData=AvMasterCompany.objects.values('id','short_name').filter(active_flag='Y').order_by('short_name')
    elif 'View Company' in rolePermisn:
        compData=AvMasterCompany.objects.values('id','short_name').filter(id=request.user.company.id).order_by('short_name')

    if request.method == "POST":
        if request.POST['company_id']!='' and request.POST['user_name']!='':
            if request.POST['user_id']=='':
                chk=AvMasterCompanyUsers.objects.filter(user_id=request.POST['user_name'].strip())
                if  len(chk)==0:
                    last_id = AvMasterCompanyUsers.objects.last()
                    passwd = handler.encrypt(request.POST['password'].strip())
                    rp=AvMasterCompanyUsers(id=last_id.id+1,user_id=request.POST['user_name'].strip(), company_id=request.POST['company_id'], password=passwd, first_name=request.POST['fisrt_name'],last_name=request.POST['last_name'],nick_name=request.POST['nice_name'],email_address=request.POST['email'],employee_number='0',active_flag=request.POST['active_flag'],last_updated_by=request.user.user_id,last_updated_date=datetime.now())
                    rp.save()
                    json_data = json.dumps( { 'users': get_user() , 'status': 'success'} , default=json_util.default )
                else:
                    json_data = json.dumps( { 'status': 'danger'} )
            else:
                chk=AvMasterCompanyUsers.objects.filter(user_id=request.POST['user_name'].strip()).exclude(id=request.POST['user_id'])
                if  len(chk)==0:
                    AvMasterCompanyUsers.objects.filter(id=request.POST['user_id']).update(user_id=request.POST['user_name'].strip(), company_id=request.POST['company_id'], first_name=request.POST['fisrt_name'],last_name=request.POST['last_name'],nick_name=request.POST['nice_name'],email_address=request.POST['email'],active_flag=request.POST['active_flag'],last_updated_by=request.user.user_id,last_updated_date=datetime.now())
                    json_data = json.dumps( { 'users': get_user() , 'status': 'success'} , default=json_util.default )
                else:
                    json_data = json.dumps( { 'status': 'danger'} )
    else:
        json_data = json.dumps( { 'users': get_user(), 'compData':list(compData), 'UserCompId':request.user.company.id , 'rolePermission':rolePermission } , default=json_util.default )

    return HttpResponse( json_data , content_type='application/json')
Exemple #5
0
def roleIndex(request):
    json_data=None
    rolePermission=utilb.userRolePermission(request.user.company.id,request.user.user_id)

    permission=''
    if 'Manage Restricted Role' in rolePermission:
        permission=AvMasterPermissions.objects.values('id','permission').filter(active_flag='Y').order_by('id')
    else:
        permission=AvMasterPermissions.objects.values('id','permission').filter(active_flag='Y').exclude(permission='Manage Restricted Role').order_by('id')

    if request.method == "POST":
        if request.POST['role_name']!='' and request.POST['role_description']!='' and 'assign_permission' in request.POST and  request.POST['assign_permission']!=['']:
            if 'role_active' in request.POST:
                role_act = 'Y'
            else:
                role_act = 'N'

            if 'role_restricted' in request.POST:
                role_restric = 'Y'
            else:
                role_restric = 'N'

            assign_permission=dict(request.POST)

            if request.POST['role_id']=='':
                chk=AvMasterRoles.objects.filter(role_name=request.POST['role_name'].strip())
                if  len(chk)==0:
                    rp=AvMasterRoles(role_name=request.POST['role_name'].strip(), description=request.POST['role_description'], restricted_flag=role_restric,active_flag=role_act,last_updated_by=request.user.user_id,last_updated_date=datetime.now())
                    rp.save()
                    add_permission_in_role(assign_permission['assign_permission'],rp.id,request.user.user_id)
                    json_data = json.dumps( { 'dataRole': get_roles() , 'status': 'success'} )
                else:
                    json_data = json.dumps( { 'status': 'danger'} )
            else:
                chk=AvMasterRoles.objects.filter(role_name=request.POST['role_name'].strip()).exclude(id=request.POST['role_id'])
                if  len(chk)==0:
                    AvMasterRoles.objects.filter(id=request.POST['role_id']).update(role_name=request.POST['role_name'].strip(), description=request.POST['role_description'], restricted_flag=role_restric,active_flag=role_act,last_updated_by=request.user.user_id,last_updated_date=datetime.now())
                    add_permission_in_role(assign_permission['assign_permission'],request.POST['role_id'],request.user.user_id)
                    json_data = json.dumps( { 'dataRole': get_roles() , 'status': 'success'} )
                else:
                    json_data = json.dumps( { 'status': 'danger'} )

    else:
        json_data = json.dumps( { 'dataRole': get_roles() ,'permission': list(permission), 'rolePermission':rolePermission } )

    return HttpResponse( json_data , content_type='application/json')
Exemple #6
0
def dashboardIndex(request):
    json_data=None
    rolePermission=utilb.userRolePermission(request.user.company.id,request.user.user_id)
    process=AvMasterProcess.objects.values('id','short_name').filter(active_flag='Y').order_by('id')

    if request.method == "POST":
        if request.POST['dashboard_name']!='' and request.POST['long_name']!='' and request.POST['help_text']!='' and request.POST['dashboard_version']!='' and 'assign_process' in request.POST and  request.POST['assign_process']!=['']:
            if 'dashboard_active' in request.POST:
                role_act = 'Y'
            else:
                role_act = 'N'

            assign_process=dict(request.POST)

            if 'file' in request.FILES and request.FILES['file']!=[]:
                file_name = str(int(round(time.time() * 1000)))+'-'+str(request.FILES['file'])
                path = default_storage.save('static/uploaded/'+file_name, ContentFile(request.FILES['file'].read()))
            else:
                file_name=request.POST['edit_pic_name']

            if request.POST['dashboard_id']=='':
                chk=AvMasterDashboard.objects.filter(short_name=request.POST['dashboard_name'].strip())
                if  len(chk)==0:
                    rp=AvMasterDashboard(short_name=request.POST['dashboard_name'].strip(), long_name=request.POST['long_name'], version=request.POST['dashboard_version'],description=request.POST['help_text'],dashboard_image=file_name,active_flag=role_act,last_updated_by=request.user.user_id,last_updated_date=datetime.now())
                    rp.save()
                    add_process_in_dashboard(assign_process['assign_process'],rp.id,request.user.user_id)
                    json_data = json.dumps( { 'dashboard': get_dashboard() , 'status': 'success'} )
                else:
                    json_data = json.dumps( { 'status': 'danger'} )
            else:
                chk=AvMasterDashboard.objects.filter(short_name=request.POST['dashboard_name'].strip()).exclude(id=request.POST['dashboard_id'])
                if  len(chk)==0:
                    AvMasterDashboard.objects.filter(id=request.POST['dashboard_id']).update(short_name=request.POST['dashboard_name'].strip(), long_name=request.POST['long_name'], version=request.POST['dashboard_version'],description=request.POST['help_text'],dashboard_image=file_name,active_flag=role_act,last_updated_by=request.user.user_id,last_updated_date=datetime.now())
                    add_process_in_dashboard(assign_process['assign_process'],request.POST['dashboard_id'],request.user.user_id)
                    json_data = json.dumps( { 'dashboard': get_dashboard() , 'status': 'success'} )
                else:
                    json_data = json.dumps( { 'status': 'danger'} )

    else:
        json_data = json.dumps( { 'dashboard': get_dashboard(), 'process':list(process),'rolePermission':rolePermission } )

    return HttpResponse( json_data , content_type='application/json')
Exemple #7
0
def role_edit(request):
    role_id = list(request.POST)
    role_id = int(''.join(map(str, role_id)))
    role = AvMasterRoles.objects.filter(id=role_id)
    role_json = serializers.serialize('json', role)
    Data_role_json = json.loads(role_json)

    rolePermission = utilb.userRolePermission(request.user.company.id,
                                              request.user.user_id)
    permissions = ''
    if 'Manage Restricted Role' in rolePermission:
        permissions = AvMasterPermissions.objects.values(
            'id', 'permission').filter(active_flag='Y').order_by('id')
    else:
        permissions = AvMasterPermissions.objects.values(
            'id', 'permission').filter(active_flag='Y').exclude(
                permission='Manage Restricted Role').order_by('id')

    user_permission = AvMasterRolePermissions.objects.values(
        'permission_id', 'comments').filter(role_id=role_id)

    userP = []
    for user_perm in user_permission:
        userP.append(user_perm['permission_id'])

    permissionsP = []
    for master_perm in permissions:
        if master_perm['id'] not in userP:
            permissionsP.append([master_perm['id'], master_perm['permission']])

    json_data = json.dumps({
        'status': 'success',
        'role': Data_role_json,
        'user_permission': list(user_permission),
        'permissions': permissionsP,
        'rolePermission': rolePermission
    })
    return HttpResponse(json_data, content_type='application/json')
Exemple #8
0
def dashboard_edit(request):
    dashboard_id = list(request.POST)
    dashboard_id = int(''.join(map(str, dashboard_id)))

    dash = AvMasterDashboard.objects.filter(id=dashboard_id)
    dash_json = serializers.serialize('json', dash)
    Data_dash_json = json.loads(dash_json)

    rolePermission = utilb.userRolePermission(request.user.company.id,
                                              request.user.user_id)

    process = AvMasterProcess.objects.values(
        'id', 'short_name').filter(active_flag='Y').order_by('id')
    user_process = AvMasterProcessDashboards.objects.values(
        'dashboard_id', 'process_id').filter(dashboard_id=dashboard_id)

    user_added_process = []
    userP = []
    for user_perm in user_process:
        proc = AvMasterProcess.objects.values('short_name').filter(
            id=user_perm['process_id'])
        userP.append(user_perm['process_id'])
        user_added_process.append(
            [user_perm['process_id'], proc[0]['short_name']])

    processP = []
    for master_perm in process:
        if master_perm['id'] not in userP:
            processP.append([master_perm['id'], master_perm['short_name']])

    json_data = json.dumps({
        'status': 'success',
        'dashboard': Data_dash_json,
        'user_added_process': list(user_added_process),
        'processP': processP,
        'rolePermission': rolePermission
    })
    return HttpResponse(json_data, content_type='application/json')
Exemple #9
0
def uploadEmployeeData(request):
    json_data=None
    DataType=AvMasterUploadDataType.objects.order_by('data_type')
    DataType_json = serializers.serialize('json', DataType )
    DataType_json_list = json.loads( DataType_json )
    cursor = connection.cursor()
    
    rolePermisn=utilb.userRolePermission(request.user.company.id,request.user.user_id)
    compData=''

    if 'View All Companies' in rolePermisn:
        compData=AvMasterCompany.objects.values('id','short_name').order_by('short_name')
    elif 'View Company' in rolePermisn:
        compData=AvMasterCompany.objects.values('id','short_name').filter(id=request.user.company.id).order_by('short_name')

    if request.method == "POST":
        data=request.FILES['file']
        path = default_storage.save('tmp/import.xls', ContentFile(data.read()))
        tmp_file = os.path.join(settings.MEDIA_ROOT, path)
        records = pe.get_records(file_name=tmp_file)
        req=request.POST

        cursor.execute("SELECT nextval('av_log_data_upload_id_seq')")
        upload_id=cursor.fetchone()
        cursor.close()
        uploadID=int(''.join(map(str,upload_id)))

        c=AvLogDataUploads(data_upload_id=uploadID,company_id=request.user.company.id,company_name=request.user.company.short_name,data_type=req['data_type'],uploaded_by=request.user.user_id,uploaded_date=datetime.now(),no_of_records='0',status='1 of 6 - File Upload',upload_or_rollback='File Upload')
        c.save()

        json_data = json.dumps( { 'status':'success','message':'File uploaded successfully.', 'file_name':tmp_file, 'upload_id':uploadID ,'logData': getLogData(request.user.company.id) } )
        utilb.logManage(request.user.company.id,request.user.company.short_name,datetime.now(),'Data Load','Load Start','Information','File Uploaded',request.user.user_id,uploadID,'uploadData')

    else:
        json_data = json.dumps( { 'DataType':DataType_json_list, 'compData':list(compData) ,'UserCompId':request.user.company.id, 'logData': getLogData(request.user.company.id), 'rolePermission':utilb.userRolePermission(request.user.company.id,request.user.user_id)} )

    return HttpResponse( json_data , content_type='application/json')
Exemple #10
0
def dashboardIndex(request):
    json_data = None
    rolePermission = utilb.userRolePermission(request.user.company.id,
                                              request.user.user_id)
    process = AvMasterProcess.objects.values(
        'id', 'short_name').filter(active_flag='Y').order_by('id')

    if request.method == "POST":
        if request.POST['dashboard_name'] != '' and request.POST[
                'long_name'] != '' and request.POST['help_text'] != '' and request.POST[
                    'dashboard_version'] != '' and 'assign_process' in request.POST and request.POST[
                        'assign_process'] != ['']:
            if 'dashboard_active' in request.POST:
                role_act = 'Y'
            else:
                role_act = 'N'

            assign_process = dict(request.POST)

            if 'file' in request.FILES and request.FILES['file'] != []:
                file_name = str(int(round(time.time() * 1000))) + '-' + str(
                    request.FILES['file'])
                path = default_storage.save(
                    'static/uploaded/' + file_name,
                    ContentFile(request.FILES['file'].read()))
            else:
                file_name = request.POST['edit_pic_name']

            if request.POST['dashboard_id'] == '':
                chk = AvMasterDashboard.objects.filter(
                    short_name=request.POST['dashboard_name'].strip())
                if len(chk) == 0:
                    rp = AvMasterDashboard(
                        short_name=request.POST['dashboard_name'].strip(),
                        long_name=request.POST['long_name'],
                        version=request.POST['dashboard_version'],
                        description=request.POST['help_text'],
                        dashboard_image=file_name,
                        active_flag=role_act,
                        last_updated_by=request.user.user_id,
                        last_updated_date=datetime.now())
                    rp.save()
                    add_process_in_dashboard(assign_process['assign_process'],
                                             rp.id, request.user.user_id)
                    json_data = json.dumps({
                        'dashboard': get_dashboard(),
                        'status': 'success'
                    })
                else:
                    json_data = json.dumps({'status': 'danger'})
            else:
                chk = AvMasterDashboard.objects.filter(
                    short_name=request.POST['dashboard_name'].strip()).exclude(
                        id=request.POST['dashboard_id'])
                if len(chk) == 0:
                    AvMasterDashboard.objects.filter(
                        id=request.POST['dashboard_id']).update(
                            short_name=request.POST['dashboard_name'].strip(),
                            long_name=request.POST['long_name'],
                            version=request.POST['dashboard_version'],
                            description=request.POST['help_text'],
                            dashboard_image=file_name,
                            active_flag=role_act,
                            last_updated_by=request.user.user_id,
                            last_updated_date=datetime.now())
                    add_process_in_dashboard(assign_process['assign_process'],
                                             request.POST['dashboard_id'],
                                             request.user.user_id)
                    json_data = json.dumps({
                        'dashboard': get_dashboard(),
                        'status': 'success'
                    })
                else:
                    json_data = json.dumps({'status': 'danger'})

    else:
        json_data = json.dumps({
            'dashboard': get_dashboard(),
            'process': list(process),
            'rolePermission': rolePermission
        })

    return HttpResponse(json_data, content_type='application/json')
Exemple #11
0
def admin_home(request):
    current_user = request.user
    userLeftPanel = defaultdict(list)
    userDashboardACL={}
    dash=utilb.userProcessDashboard(request.user.company.id,current_user.user_id)
    for result in dash:
        userLeftPanel[result[5]].append({'dashboardName':result[6],'dashboardId':result[3]})

    datDic=dict(userLeftPanel)
    if len(datDic) >0:
        dataLeft=OrderedDict(sorted(datDic.items(), key=lambda t: t[0]))
    else:
        dataLeft=datDic

    #utilb.logManage(request.user.company.id,request.user.company.short_name,datetime.now(),'User Activity','Home','Information','Home',request.user.user_id,'1','Home')
    return render_to_response('admin/index.html', {'user': current_user, 'leftPanel':dataLeft , 'rolePermission':utilb.userRolePermission(request.user.company.id,request.user.user_id),'test':'userDashboardACL'} )
Exemple #12
0
def getSearchSummary(request):
    json_data=None
    if request.method == "POST":
        #reqdata=json.loads(request.body)
        reqdata=dict(request.POST)

        if 'countryItem' or 'QuarterItem' or 'categoryItem' or 'subCategoryItem' or 'paymentItem' or 'functionItem' or 'employeeItem' or 'thresholdItem'  in reqdata and (reqdata['countryItem']!=[''] or reqdata['QuarterItem']!=[''] or reqdata['categoryItem']!=[''] or reqdata['subCategoryItem']!=[''] or reqdata['paymentItem']!=[''] or reqdata['functionItem']!=[''] or reqdata['employeeItem']!=[''] or reqdata['thresholdItem']!=[''] ):
            SqlQuery=Q(company_id=request.user.company_id)

            if 'QuarterItem' in reqdata and reqdata['QuarterItem']!=['']:
                SqlQuery &= Q(c_fiscal_quarter__in=reqdata['QuarterItem'] )

            if 'countryItem' in reqdata and reqdata['countryItem']!=['']:
                SqlQuery &= Q(location_country__in=reqdata['countryItem'] )

            if 'categoryItem' in reqdata and reqdata['categoryItem']!=['']:
                SqlQuery &= Q(expense_type_name__in=reqdata['categoryItem'] )

            if 'subCategoryItem' in reqdata and reqdata['subCategoryItem']!=['']:
                SqlQuery &= Q(spend_category_name__in=reqdata['subCategoryItem'] )

            if 'paymentItem' in reqdata and reqdata['paymentItem']!=['']:
                SqlQuery &= Q(payment_type_name__in=reqdata['paymentItem'] )

            if 'functionItem' in reqdata and reqdata['functionItem']!=['']:
                SqlQuery &= Q(e_function_name__in=reqdata['functionItem'] )

            if 'employeeItem' in reqdata and reqdata['employeeItem']!=['']:
                employeeItem=''.join(map(str, reqdata['employeeItem']))
                SqlQuery &= Q(e_employee_name__icontains=employeeItem.strip())

            if 'thresholdItem' in reqdata and reqdata['thresholdItem']!=['']:
                thresholdItem=int(''.join(map(str,reqdata['thresholdItem'])))
                SqlQuery &= Q(transaction_amount__gte= thresholdItem )

            if 'start_date' and 'end_date' in reqdata and (reqdata['start_date']!=[''] and reqdata['end_date']!=['']):
                start_date=''.join(map(str, reqdata['start_date']))
                end_date=''.join(map(str, reqdata['end_date']))
                SqlQuery &= Q(transaction_date__range=[start_date,end_date] )

            if 'start_date' in reqdata and reqdata['start_date']!=[''] and reqdata['end_date']==['']:
                start_date=''.join(map(str, reqdata['start_date']))
                SqlQuery &= Q(transaction_date=start_date)


            PDid=utilb.getUserProcessDashboardId(request,'Summary')
            Dashboard=utilb.userDashboard(request.user.company_id,request.user.user_id, PDid[0], PDid[1])
            ScopeData=AvMasterUserDatascope.objects.values('data_scope_type','company_id', 'process_id').filter(user_id=request.user.user_id, company_id=request.user.company.id , process_id = PDid[0] ).annotate( Count('company_id',distinct=True), Count('process_id',distinct=True), Count('data_scope_type',distinct=True))
            data_scope_flag=str(Dashboard[4])
            rolePerm=utilb.userRolePermission(request.user.company.id,request.user.user_id)

            
            if 'View All Records' in rolePerm:
                print 'View All Records'

            elif 'View Company Records' in rolePerm:
                if len(Dashboard) >0:
                    if data_scope_flag=='Y':
                        for scope in ScopeData:
                            if scope['data_scope_type']=='Country':
                                SqlQuery &= Q(location_country__in= utilb.getDataScope(request,PDid[0],'Country') )

                            if scope['data_scope_type']=='Hierarchy':
                                 SqlQuery &= Q(e_employee_number__in= utilb.getDataScope(request,PDid[0],'Hierarchy') )

                    else:
                        SqlQuery &= Q(e_employee_number__in= utilb.getDataScope(request,PDid[0],'N') )


            SqlQuery &= Q(process_id=PDid[0], dashboard_id=PDid[1])

            if 'viewBy':
                if 'viewBy' in reqdata and reqdata['viewBy']!=[]:
                    viewBy=''.join(map(str, reqdata['viewBy']))
                    if viewBy=='transaction_amount':
                        minsql=Sum('transaction_amount')
                    else:
                        minsql=Count('report_line_id')
                else:
                    minsql=Sum('transaction_amount')



            Employee = AvOutExpDashSummary.objects.values('e_employee_name').filter( SqlQuery ).annotate(amount=Sum('transaction_amount'), expenses=Count('report_line_id')).order_by("e_employee_name")

            Department = AvOutExpDashSummary.objects.values('company_id', 'dashboard_id', 'e_department_name', 'location_country').filter( SqlQuery ).annotate(amount=Sum('transaction_amount'), expenses=Count('report_line_id')).order_by("e_department_name")
            #GraphMonth = AvOutExpDashSummary.objects.values('c_month_name').filter( SqlQuery ).annotate(amount=minsql).order_by("c_month_id")
            GraphPaymentType = AvOutExpDashSummary.objects.values('c_month_name','payment_type_name','c_month_id').filter( SqlQuery ).annotate(amount=minsql).order_by("c_month_id")
            payment = defaultdict(list)
            for res in GraphPaymentType:
                payment[res['payment_type_name']].append([res['amount']])

            payment_month = defaultdict(list)
            for res in GraphPaymentType:
                payment_month[res['c_month_id']].append([res['amount']])

            Categories = AvOutExpDashSummary.objects.values('expense_type_name').filter( SqlQuery ).annotate(category=Count('expense_type_name'),amount=minsql).order_by('expense_type_name')
            GraphCategories = AvOutExpDashSummary.objects.values('spend_category_name').filter( SqlQuery ).annotate(amount=minsql).order_by("spend_category_name")
            GraphCountries = AvOutExpDashSummary.objects.values('location_country').filter( SqlQuery ).annotate(amount=minsql).order_by("location_country")
            SearchQuery = AvOutExpDashSummary.objects.values('company_id','job_id','dashboard_id').filter( SqlQuery ).annotate( total_amount=Sum('transaction_amount'),no_of_exp_reports=Count('report_id',distinct=True), no_of_exp_lines=Count('report_line_id',distinct=True), no_of_employees=Count('report_owner_id',distinct=True), avg_exp_per_report=Sum('transaction_amount')/Count('report_id',distinct=True), avg_exp_per_employee=Sum('transaction_amount')/Count('report_owner_id',distinct=True) )
            BucketAnalysis = AvOutExpDashSummary.objects.values('job_id','company_id','dashboard_id','c_amount_bucket').filter( SqlQuery ).filter(company_id=request.user.company_id).annotate(expenses=minsql).order_by("expenses")

            QuarterItems = AvOutExpDashSummary.objects.values('c_fiscal_quarter').filter( SqlQuery ).annotate(category=Count('c_fiscal_quarter')).order_by('c_fiscal_quarter')
            functionItems = AvOutExpDashSummary.objects.values('e_function_name').filter( SqlQuery ).annotate(category=Count('e_function_name')).order_by('e_function_name')
            json_data = json.dumps( { 'BucketAnalysis':list(BucketAnalysis),'Employee':list(Employee), 'Department':list(Department) , 'GraphMonth':payment , 'PaymentMonth':payment_month, 'GraphCategories':list(GraphCategories) ,'Categories_list':list(Categories), 'GraphCountries':list(GraphCountries) ,'JobStatistics':list(SearchQuery) ,'QuarterItems':list(QuarterItems),'functionItems':list(functionItems), 'DataType':'search'} )

            utilb.logManage(request.user.company.id,request.user.company.short_name,datetime.now(),'User Activity','Filter','Information','Filter',request.user.user_id,'','Expense Summary')

        else:
            json_data=getSummary(request)
    else:
        json_data=getSummary(request)

    return HttpResponse( json_data , content_type='application/json')
Exemple #13
0
def getSummary(dat):
    PDid=utilb.getUserProcessDashboardId(dat,'Summary')
    Dashboard=utilb.userDashboard(dat.user.company_id,dat.user.user_id, PDid[0], PDid[1])
    ScopeData=AvMasterUserDatascope.objects.values('data_scope_type','company_id', 'process_id').filter(user_id=dat.user.user_id, company_id=dat.user.company.id , process_id = PDid[0] ).annotate( Count('company_id',distinct=True), Count('process_id',distinct=True), Count('data_scope_type',distinct=True))
    rolePerm=utilb.userRolePermission(dat.user.company.id,dat.user.user_id)

    SqlQuery=Q(company_id=dat.user.company_id,process_id=PDid[0], dashboard_id=PDid[1])
    data_scope_flag=str(Dashboard[4])


    if "View Company Records" not in rolePerm and "View All Records" not in rolePerm:
        SqlQuery &= Q(company_id= '00')


    if 'View All Records' in rolePerm:
        print 'View All Records'

    elif 'View Company Records' in rolePerm:
        if len(Dashboard) >0:
            if data_scope_flag=='Y':
                for scope in ScopeData:
                    if scope['data_scope_type']=='Country':
                        SqlQuery &= Q(location_country__in= utilb.getDataScope(dat,PDid[0],'Country') )

                    if scope['data_scope_type']=='Hierarchy':
                        SqlQuery &= Q(e_employee_number__in= utilb.getDataScope(dat,PDid[0],'Hierarchy') )

            else:
                SqlQuery &= Q(e_employee_number__in= utilb.getDataScope(dat,PDid[0],'N') )



    JobStatistics = AvOutExpDashSummary.objects.values('company_id','job_id','dashboard_id').filter( SqlQuery ).annotate( total_amount=Sum('transaction_amount'),no_of_exp_reports=Count('report_id',distinct=True), no_of_exp_lines=Count('report_line_id',distinct=True), no_of_employees=Count('report_owner_id',distinct=True), avg_exp_per_report=Sum('transaction_amount')/Count('report_id',distinct=True), avg_exp_per_employee=Sum('transaction_amount')/Count('report_owner_id',distinct=True) )
    Categories = AvOutExpDashSummary.objects.values('expense_type_name').filter( SqlQuery ).annotate(category=Count('expense_type_name'),amount=Sum('transaction_amount')).order_by('expense_type_name')
    QuarterItems = AvOutExpDashSummary.objects.values('c_fiscal_quarter').filter( SqlQuery ).annotate(category=Count('c_fiscal_quarter')).order_by('c_fiscal_quarter')
    functionItems = AvOutExpDashSummary.objects.values('e_function_name').filter( SqlQuery ).annotate(category=Count('e_function_name')).order_by('e_function_name')
    paymentType = AvOutExpDashSummary.objects.values('payment_type_name').filter( SqlQuery ).annotate(paymentType=Count('payment_type_name')).order_by('payment_type_name')

    Employee = AvOutExpDashSummary.objects.values('e_employee_name').filter( SqlQuery ).annotate(amount=Sum('transaction_amount'), expenses=Count('report_line_id')).order_by("e_employee_name")
    Department = AvOutExpDashSummary.objects.values('company_id', 'dashboard_id', 'e_department_name', 'location_country').filter( SqlQuery ).annotate(amount=Sum('transaction_amount'), expenses=Count('report_line_id')).order_by("e_department_name")
    #GraphMonth = AvOutExpDashSummary.objects.values('c_month_name').filter( SqlQuery ).annotate(amount=Sum('transaction_amount')).order_by("c_month_id")
    GraphPaymentType = AvOutExpDashSummary.objects.values('c_month_name','payment_type_name','c_month_id').filter( SqlQuery ).annotate(amount=Sum('transaction_amount')).order_by("c_month_id")

    payment = defaultdict(list)
    for res in GraphPaymentType:
        payment[res['payment_type_name']].append([res['amount']])

    payment_month = defaultdict(list)
    for res in GraphPaymentType:
        payment_month[res['c_month_id']].append([res['amount']])

    GraphCategories = AvOutExpDashSummary.objects.values('spend_category_name').filter( SqlQuery ).annotate(amount=Sum('transaction_amount')).order_by("spend_category_name")
    GraphCountries = AvOutExpDashSummary.objects.values('location_country').filter( SqlQuery ).annotate(amount=Sum('transaction_amount')).order_by("location_country")
    BucketAnalysis=AvOutExpDashSummary.objects.values('job_id','company_id','dashboard_id','c_amount_bucket').filter( SqlQuery ).annotate(expenses=Sum('transaction_amount')).order_by("expenses")

    # sql_string = 'SELECT company_id, dashboard_id, amount_bucket, expenses FROM av_engine.av_out_exp_buckets_summary_v WHERE company_id=%s order by expenses DESC' %dat.user.company_id
    # cursor.execute(sql_string)
    # result = cursor.fetchall()

    dat=json_data = json.dumps( {'BucketAnalysis':list(BucketAnalysis),'JobStatistics':list(JobStatistics), 'Categories_list':list(Categories),'QuarterItems':list(QuarterItems),'functionItems':list(functionItems) , 'paymentType':list(paymentType) , 'Employee':list(Employee) , 'Department':list(Department) , 'GraphMonth':payment , 'PaymentMonth':payment_month, 'GraphCategories':list(GraphCategories) , 'GraphCountries':list(GraphCountries) ,'Type':'normal' } )
    return dat
Exemple #14
0
def roleIndex(request):
    json_data = None
    rolePermission = utilb.userRolePermission(request.user.company.id,
                                              request.user.user_id)

    permission = ''
    if 'Manage Restricted Role' in rolePermission:
        permission = AvMasterPermissions.objects.values(
            'id', 'permission').filter(active_flag='Y').order_by('id')
    else:
        permission = AvMasterPermissions.objects.values(
            'id', 'permission').filter(active_flag='Y').exclude(
                permission='Manage Restricted Role').order_by('id')

    if request.method == "POST":
        if request.POST['role_name'] != '' and request.POST[
                'role_description'] != '' and 'assign_permission' in request.POST and request.POST[
                    'assign_permission'] != ['']:
            if 'role_active' in request.POST:
                role_act = 'Y'
            else:
                role_act = 'N'

            if 'role_restricted' in request.POST:
                role_restric = 'Y'
            else:
                role_restric = 'N'

            assign_permission = dict(request.POST)

            if request.POST['role_id'] == '':
                chk = AvMasterRoles.objects.filter(
                    role_name=request.POST['role_name'].strip())
                if len(chk) == 0:
                    rp = AvMasterRoles(
                        role_name=request.POST['role_name'].strip(),
                        description=request.POST['role_description'],
                        restricted_flag=role_restric,
                        active_flag=role_act,
                        last_updated_by=request.user.user_id,
                        last_updated_date=datetime.now())
                    rp.save()
                    add_permission_in_role(
                        assign_permission['assign_permission'], rp.id,
                        request.user.user_id)
                    json_data = json.dumps({
                        'dataRole': get_roles(),
                        'status': 'success'
                    })
                else:
                    json_data = json.dumps({'status': 'danger'})
            else:
                chk = AvMasterRoles.objects.filter(
                    role_name=request.POST['role_name'].strip()).exclude(
                        id=request.POST['role_id'])
                if len(chk) == 0:
                    AvMasterRoles.objects.filter(
                        id=request.POST['role_id']).update(
                            role_name=request.POST['role_name'].strip(),
                            description=request.POST['role_description'],
                            restricted_flag=role_restric,
                            active_flag=role_act,
                            last_updated_by=request.user.user_id,
                            last_updated_date=datetime.now())
                    add_permission_in_role(
                        assign_permission['assign_permission'],
                        request.POST['role_id'], request.user.user_id)
                    json_data = json.dumps({
                        'dataRole': get_roles(),
                        'status': 'success'
                    })
                else:
                    json_data = json.dumps({'status': 'danger'})

    else:
        json_data = json.dumps({
            'dataRole': get_roles(),
            'permission': list(permission),
            'rolePermission': rolePermission
        })

    return HttpResponse(json_data, content_type='application/json')
Exemple #15
0
def uploadEmployeeData(request):
    json_data = None
    DataType = AvMasterUploadDataType.objects.order_by('data_type')
    DataType_json = serializers.serialize('json', DataType)
    DataType_json_list = json.loads(DataType_json)
    cursor = connection.cursor()

    rolePermisn = utilb.userRolePermission(request.user.company.id,
                                           request.user.user_id)
    compData = ''

    if 'View All Companies' in rolePermisn:
        compData = AvMasterCompany.objects.values(
            'id', 'short_name').order_by('short_name')
    elif 'View Company' in rolePermisn:
        compData = AvMasterCompany.objects.values('id', 'short_name').filter(
            id=request.user.company.id).order_by('short_name')

    if request.method == "POST":
        data = request.FILES['file']
        path = default_storage.save('tmp/import.xls', ContentFile(data.read()))
        tmp_file = os.path.join(settings.MEDIA_ROOT, path)
        records = pe.get_records(file_name=tmp_file)
        req = request.POST

        cursor.execute("SELECT nextval('av_log_data_upload_id_seq')")
        upload_id = cursor.fetchone()
        cursor.close()
        uploadID = int(''.join(map(str, upload_id)))

        c = AvLogDataUploads(data_upload_id=uploadID,
                             company_id=request.user.company.id,
                             company_name=request.user.company.short_name,
                             data_type=req['data_type'],
                             uploaded_by=request.user.user_id,
                             uploaded_date=datetime.now(),
                             no_of_records='0',
                             status='1 of 6 - File Upload',
                             upload_or_rollback='File Upload')
        c.save()

        json_data = json.dumps({
            'status': 'success',
            'message': 'File uploaded successfully.',
            'file_name': tmp_file,
            'upload_id': uploadID,
            'logData': getLogData(request.user.company.id)
        })
        utilb.logManage(request.user.company.id,
                        request.user.company.short_name, datetime.now(),
                        'Data Load', 'Load Start', 'Information',
                        'File Uploaded', request.user.user_id, uploadID,
                        'uploadData')

    else:
        json_data = json.dumps({
            'DataType':
            DataType_json_list,
            'compData':
            list(compData),
            'UserCompId':
            request.user.company.id,
            'logData':
            getLogData(request.user.company.id),
            'rolePermission':
            utilb.userRolePermission(request.user.company.id,
                                     request.user.user_id)
        })

    return HttpResponse(json_data, content_type='application/json')
Exemple #16
0
def auditlog(request):
    json_data = None
    if request.method == "POST":
        reqdata = dict(request.POST)
        if 'comp_name' or 'event_category' or 'user' or 'start_date' or 'event_sub_category' or 'keyword' or 'end_date' or 'event_type' in reqdata and (
                reqdata['comp_name'] != ['']
                or reqdata['event_category'] != ['']
                or reqdata['user'] != [''] or reqdata['start_date'] != ['']
                or reqdata['event_sub_category'] != ['']
                or reqdata['keyword'] != [''] or reqdata['end_date'] != ['']
                or reqdata['event_type'] != ['']):

            if 'comp_name' in reqdata and reqdata['comp_name'] != ['']:
                compID = int(''.join(map(str, reqdata['comp_name'])))
                SqlQuery = Q(company_id=compID)

            if 'event_category' in reqdata and reqdata['event_category'] != [
                    ''
            ]:
                SqlQuery &= Q(event_category__in=reqdata['event_category'])

            if 'user' in reqdata and reqdata['user'] != ['']:
                userName = ''.join(map(str, reqdata['user']))
                SqlQuery &= Q(event_user__icontains=userName.strip())

            if 'start_date' and 'end_date' in reqdata and (
                    reqdata['start_date'] != ['']
                    and reqdata['end_date'] != ['']):
                start_date = ''.join(map(str, reqdata['start_date']))
                end_date = ''.join(map(str, reqdata['end_date']))
                SqlQuery &= Q(event_date__range=[start_date, end_date])

            if 'start_date' in reqdata and reqdata['start_date'] != [
                    ''
            ] and reqdata['end_date'] == ['']:
                start_date = ''.join(map(str, reqdata['start_date']))
                SqlQuery &= Q(event_date__date=start_date)

            if 'event_sub_category' in reqdata and reqdata[
                    'event_sub_category'] != ['']:
                SqlQuery &= Q(
                    event_sub_category__in=reqdata['event_sub_category'])

            if 'event_type' in reqdata and reqdata['event_type'] != ['']:
                SqlQuery &= Q(event_type__in=reqdata['event_type'])

            # if 'keyword' in reqdata and reqdata['keyword']!=['']:
            #     dta_keyword=''.join(map(str, reqdata['keyword']))
            #     SqlQuery &= Q(event_user__icontains=dta_keyword.strip())

            LogData = AvLogAuditTrail.objects.filter(SqlQuery).order_by(
                "-event_date")
            expt_file_name = utilb.export_auditlog(LogData)
            LogData_json = serializers.serialize('json', LogData)
            LogData_json_list = json.loads(LogData_json)
            json_data = json.dumps({
                'logData': LogData_json_list,
                'expt_file_name': expt_file_name
            })
            utilb.logManage(request.user.company.id,
                            request.user.company.short_name, datetime.now(),
                            'User Activity', 'Audit Log', 'Information',
                            'Audit Log', request.user.user_id, '1',
                            'Search data')

        else:
            print 'No- data'

    else:
        rolePermisn = utilb.userRolePermission(request.user.company.id,
                                               request.user.user_id)
        compData = ''
        if 'View All Companies' in rolePermisn:
            compData = AvMasterCompany.objects.values(
                'id', 'short_name').order_by('short_name')
        elif 'View Company' in rolePermisn:
            compData = AvMasterCompany.objects.values(
                'id', 'short_name').filter(
                    id=request.user.company.id).order_by('short_name')

        eventCategory = AvMasterEvents.objects.values(
            'event_category').annotate(event_category_name=Count(
                'event_category')).order_by('event_category')
        eventType = AvMasterEvents.objects.values('event_type').annotate(
            event_type_name=Count('event_type')).order_by('event_type')

        json_data = json.dumps({
            'compData':
            list(compData),
            'UserCompId':
            request.user.company.id,
            'eventCategory':
            list(eventCategory),
            'eventSubCategory':
            '',
            'eventType':
            list(eventType),
            'rolePermission':
            utilb.userRolePermission(request.user.company.id,
                                     request.user.user_id)
        })
        utilb.logManage(request.user.company.id,
                        request.user.company.short_name, datetime.now(),
                        'User Activity', 'Audit Log', 'Information',
                        'Audit Log', request.user.user_id, '1',
                        'Visiting on page')
    return HttpResponse(json_data, content_type='application/json')
Exemple #17
0
def auditlog(request):
    json_data=None
    if request.method == "POST":
        reqdata=dict(request.POST)
        if 'comp_name' or 'event_category' or 'user' or 'start_date' or 'event_sub_category' or 'keyword' or 'end_date' or 'event_type'  in reqdata and (reqdata['comp_name']!=[''] or reqdata['event_category']!=[''] or reqdata['user']!=[''] or reqdata['start_date']!=[''] or reqdata['event_sub_category']!=[''] or reqdata['keyword']!=[''] or reqdata['end_date']!=[''] or reqdata['event_type']!=[''] ):

            if 'comp_name' in reqdata and reqdata['comp_name']!=['']:
                compID=int(''.join(map(str,reqdata['comp_name'])))
                SqlQuery=Q(company_id=compID )

            if 'event_category' in reqdata and reqdata['event_category']!=['']:
                SqlQuery &= Q(event_category__in=reqdata['event_category'] )

            if 'user' in reqdata and reqdata['user']!=['']:
                userName=''.join(map(str, reqdata['user']))
                SqlQuery &= Q(event_user__icontains=userName.strip())

            if 'start_date' and 'end_date' in reqdata and (reqdata['start_date']!=[''] and reqdata['end_date']!=['']):
                start_date=''.join(map(str, reqdata['start_date']))
                end_date=''.join(map(str, reqdata['end_date']))
                SqlQuery &= Q(event_date__range=[start_date,end_date] )


            if 'start_date' in reqdata and reqdata['start_date']!=[''] and reqdata['end_date']==['']:
                start_date=''.join(map(str, reqdata['start_date']))
                SqlQuery &= Q(event_date__date=start_date)


            if 'event_sub_category' in reqdata and reqdata['event_sub_category']!=['']:
                SqlQuery &= Q(event_sub_category__in=reqdata['event_sub_category'] )

            if 'event_type' in reqdata and reqdata['event_type']!=['']:
                SqlQuery &= Q(event_type__in=reqdata['event_type'] )

            # if 'keyword' in reqdata and reqdata['keyword']!=['']:
            #     dta_keyword=''.join(map(str, reqdata['keyword']))
            #     SqlQuery &= Q(event_user__icontains=dta_keyword.strip())


            LogData = AvLogAuditTrail.objects.filter( SqlQuery ).order_by("-event_date")
            expt_file_name=utilb.export_auditlog(LogData)
            LogData_json = serializers.serialize('json', LogData )
            LogData_json_list = json.loads( LogData_json )
            json_data = json.dumps( { 'logData':LogData_json_list, 'expt_file_name':expt_file_name } )
            utilb.logManage(request.user.company.id,request.user.company.short_name,datetime.now(),'User Activity','Audit Log','Information','Audit Log',request.user.user_id,'1','Search data')

        else:
            print 'No- data'

    else:
        rolePermisn=utilb.userRolePermission(request.user.company.id,request.user.user_id)
        compData=''
        if 'View All Companies' in rolePermisn:
            compData=AvMasterCompany.objects.values('id','short_name').order_by('short_name')
        elif 'View Company' in rolePermisn:
            compData=AvMasterCompany.objects.values('id','short_name').filter(id=request.user.company.id).order_by('short_name')


        eventCategory=AvMasterEvents.objects.values('event_category').annotate(event_category_name=Count('event_category')).order_by('event_category')
        eventType=AvMasterEvents.objects.values('event_type').annotate(event_type_name=Count('event_type')).order_by('event_type')

        json_data = json.dumps( { 'compData':list(compData) ,'UserCompId':request.user.company.id, 'eventCategory':list(eventCategory) , 'eventSubCategory':'', 'eventType': list(eventType), 'rolePermission':utilb.userRolePermission(request.user.company.id,request.user.user_id)} )
        utilb.logManage(request.user.company.id,request.user.company.short_name,datetime.now(),'User Activity','Audit Log','Information','Audit Log',request.user.user_id,'1','Visiting on page')
    return HttpResponse( json_data , content_type='application/json')
Exemple #18
0
def userIndex(request):
    from bson import json_util
    json_data = None
    rolePermission = utilb.userRolePermission(request.user.company.id,
                                              request.user.user_id)
    compData = ''
    if 'View All Companies' in rolePermission:
        compData = AvMasterCompany.objects.values(
            'id', 'short_name').filter(active_flag='Y').order_by('short_name')
    elif 'View Company' in rolePermisn:
        compData = AvMasterCompany.objects.values('id', 'short_name').filter(
            id=request.user.company.id).order_by('short_name')

    if request.method == "POST":
        if request.POST['company_id'] != '' and request.POST['user_name'] != '':
            if request.POST['user_id'] == '':
                chk = AvMasterCompanyUsers.objects.filter(
                    user_id=request.POST['user_name'].strip())
                if len(chk) == 0:
                    last_id = AvMasterCompanyUsers.objects.last()
                    passwd = handler.encrypt(request.POST['password'].strip())
                    rp = AvMasterCompanyUsers(
                        id=last_id.id + 1,
                        user_id=request.POST['user_name'].strip(),
                        company_id=request.POST['company_id'],
                        password=passwd,
                        first_name=request.POST['fisrt_name'],
                        last_name=request.POST['last_name'],
                        nick_name=request.POST['nice_name'],
                        email_address=request.POST['email'],
                        employee_number='0',
                        active_flag=request.POST['active_flag'],
                        last_updated_by=request.user.user_id,
                        last_updated_date=datetime.now())
                    rp.save()
                    json_data = json.dumps(
                        {
                            'users': get_user(),
                            'status': 'success'
                        },
                        default=json_util.default)
                else:
                    json_data = json.dumps({'status': 'danger'})
            else:
                chk = AvMasterCompanyUsers.objects.filter(
                    user_id=request.POST['user_name'].strip()).exclude(
                        id=request.POST['user_id'])
                if len(chk) == 0:
                    AvMasterCompanyUsers.objects.filter(
                        id=request.POST['user_id']).update(
                            user_id=request.POST['user_name'].strip(),
                            company_id=request.POST['company_id'],
                            first_name=request.POST['fisrt_name'],
                            last_name=request.POST['last_name'],
                            nick_name=request.POST['nice_name'],
                            email_address=request.POST['email'],
                            active_flag=request.POST['active_flag'],
                            last_updated_by=request.user.user_id,
                            last_updated_date=datetime.now())
                    json_data = json.dumps(
                        {
                            'users': get_user(),
                            'status': 'success'
                        },
                        default=json_util.default)
                else:
                    json_data = json.dumps({'status': 'danger'})
    else:
        json_data = json.dumps(
            {
                'users': get_user(),
                'compData': list(compData),
                'UserCompId': request.user.company.id,
                'rolePermission': rolePermission
            },
            default=json_util.default)

    return HttpResponse(json_data, content_type='application/json')
Exemple #19
0
def companyIndex(request):
    json_data = None
    rolePermission = utilb.userRolePermission(request.user.company.id,
                                              request.user.user_id)
    dashboard = AvMasterDashboard.objects.values(
        'id', 'short_name').filter(active_flag='Y').order_by('id')

    if request.method == "POST":
        if request.POST['short_name'] != '' and request.POST[
                'full_name'] != '' and request.POST['address1'] != '':

            if 'file' in request.FILES and request.FILES['file'] != []:
                file_name = str(int(round(time.time() * 1000))) + '-' + str(
                    request.FILES['file'])
                path = default_storage.save(
                    'static/uploaded/' + file_name,
                    ContentFile(request.FILES['file'].read()))
            else:
                file_name = request.POST['edit_pic_name']

            if request.POST['company_id'] == '':
                chk = AvMasterCompany.objects.filter(
                    short_name=request.POST['short_name'].strip())
                if len(chk) == 0:
                    rp = AvMasterCompany(
                        short_name=request.POST['short_name'].strip(),
                        full_name=request.POST['full_name'],
                        address1=request.POST['address1'],
                        logo=file_name,
                        active_flag=request.POST['active_flag'],
                        address2=request.POST['address2'],
                        city=request.POST['city'],
                        state=request.POST['state'],
                        country=request.POST['country'],
                        zip_code=request.POST['zip_code'],
                        primary_contact_name=request.
                        POST['primary_contact_name'],
                        primary_contact_email=request.
                        POST['primary_contact_email'],
                        primary_contact_phone=request.
                        POST['primary_contact_phone'],
                        secondary_contact_name=request.
                        POST['secondary_contact_name'],
                        secondary_contact_email=request.
                        POST['secondary_contact_email'],
                        secondary_contact_phone=request.
                        POST['secondary_contact_phone'],
                        landing_page_text=request.POST['landing_page_text'],
                        single_sign_on_flag=request.
                        POST['single_sign_on_flag'],
                        last_updated_by=request.user.user_id,
                        last_updated_date=datetime.now())
                    rp.save()
                    insert_process_in_company(rp.id, request.user.user_id)
                    json_data = json.dumps({
                        'company': get_company(),
                        'status': 'success'
                    })
                else:
                    json_data = json.dumps({'status': 'danger'})
            else:
                chk = AvMasterCompany.objects.filter(
                    short_name=request.POST['short_name'].strip()).exclude(
                        id=request.POST['company_id'])
                if len(chk) == 0:
                    AvMasterCompany.objects.filter(
                        id=request.POST['company_id']
                    ).update(
                        short_name=request.POST['short_name'].strip(),
                        full_name=request.POST['full_name'],
                        address1=request.POST['address1'],
                        logo=file_name,
                        active_flag=request.POST['active_flag'],
                        address2=request.POST['address2'],
                        city=request.POST['city'],
                        state=request.POST['state'],
                        country=request.POST['country'],
                        zip_code=request.POST['zip_code'],
                        primary_contact_name=request.
                        POST['primary_contact_name'],
                        primary_contact_email=request.
                        POST['primary_contact_email'],
                        primary_contact_phone=request.
                        POST['primary_contact_phone'],
                        secondary_contact_name=request.
                        POST['secondary_contact_name'],
                        secondary_contact_email=request.
                        POST['secondary_contact_email'],
                        secondary_contact_phone=request.
                        POST['secondary_contact_phone'],
                        landing_page_text=request.POST['landing_page_text'],
                        single_sign_on_flag=request.
                        POST['single_sign_on_flag'],
                        last_updated_by=request.user.user_id,
                        last_updated_date=datetime.now())
                    json_data = json.dumps({
                        'company': get_company(),
                        'status': 'success'
                    })
                else:
                    json_data = json.dumps({'status': 'danger'})

    else:
        json_data = json.dumps({
            'company': get_company(),
            'dashboard': 'list(dashboard)',
            'rolePermission': rolePermission
        })

    return HttpResponse(json_data, content_type='application/json')