def save_file_storage(db, request, session_user):
    client_id = request.client_id
    legal_entity_id = request.legal_entity_id
    machine_id = request.machine_id
    #
    #  To save file storage configuration
    #  Parameters : Client id, Legal entity id, Clietn server id
    #  Return : Returns last inserted id
    #
    result = db.call_update_proc(
        "sp_clientfilestorage_save",
        (client_id, legal_entity_id, machine_id)
    )
    if result:
        #
        #  To get legal entity name by it's id to save activity
        #  Parameters : legal entity id
        #  Return : Returns legal entity name
        #
        data = db.call_proc("sp_legal_entity_name_by_id", (legal_entity_id,))
        action = "Configured file storage for %s " % (
            data[0]["legal_entity_name"])
        db.save_activity(session_user, frmConfigureFileStorage, action)
    else:
        raise process_error("E077")
Exemplo n.º 2
0
def save_statutory_compliances(db, client_id, legal_entity_id, domain_id, data,
                               unit_id, status, user_id, csid):
    value_list = []
    for r in data:
        if r.unit_id == unit_id:
            remarks = r.remarks
            if remarks is None:
                remarks = ''
            value_list.append(
                (csid, client_id, legal_entity_id, unit_id, domain_id,
                 r.level_1_id, r.status, str(remarks),
                 r.compliance_id, r.compliance_status, status, user_id,
                 get_date_time(), status))

    table = "tbl_client_compliances"
    column = [
        "client_statutory_id", "client_id", "legal_entity_id", "unit_id",
        "domain_id", "statutory_id", "statutory_applicable_status", "remarks",
        "compliance_id", "compliance_applicable_status", "is_saved",
        "saved_by", "saved_on", "is_approved"
    ]
    update_column = [
        "statutory_id", "statutory_applicable_status", "remarks",
        "compliance_id", "compliance_applicable_status", "is_saved",
        "saved_by", "saved_on", "is_approved"
    ]

    result = db.on_duplicate_key_update(table, ",".join(column), value_list,
                                        update_column)
    if result is False:
        raise process_error("E088")
Exemplo n.º 3
0
 def process_save_token(self):
     try:
         print self._host, self._port, self._db_username, self._db_password, self._db_name
         self.get_client_connect(self._host, self._port, self._db_username,
                                 self._db_password, self._db_name)
         # self._k_db.begin()
         self._k_db._cursor = self._k_db._connection.cursor()
         self._save_token()
         self._k_db._cursor.close()
         self._k_db._connection.commit()
         self._k_db._connection.close()
     except Exception, e:
         print e
         if self._k_db is None:
             return
         self._k_db._cursor.close()
         self._k_db._connection.rollback()
         self._k_db._connection.close()
         raise process_error("E090")
Exemplo n.º 4
0
    def save_client_statutories_data(self, cl_id, u_id, d_id, user_id,
                                     is_rejected):
        created_on = get_date_time()
        status = 3
        if is_rejected is True:
            status = 4

        client_statutory_value = [
            int(cl_id),
            int(u_id),
            int(d_id), status,
            int(user_id),
            str(created_on)
        ]
        q = "INSERT INTO tbl_client_statutories (client_id, unit_id, " + \
            " domain_id, status, approved_by, approved_on) values " + \
            " (%s, %s, %s, %s, %s, %s)"
        client_statutory_id = self._source_db.execute_insert(
            q, client_statutory_value)

        if client_statutory_id is False:
            raise process_error("E018")
        return client_statutory_id
def get_assigned_statutory_wizard_two_data(db, client_id, busienss_group_id,
                                           legal_entity_id, division_id,
                                           category_id, domain_id, unit_ids):
    (unit_loc_details, unit_org_details) = db.call_proc_with_multiresult_set(
        "sp_unit_unit_organiation_details",
        (",".join(str(x) for x in unit_ids), ), 2)
    country_count_map = {}
    domain_count_map = {}
    geo_count_map = {}
    org_count_map = {}

    unit_count = len(unit_ids)  # Unit count

    # To separate country wise units and geo wise units
    for unit in unit_loc_details:
        country_id = unit["country_id"]
        geography_id = unit["geography_id"]
        if country_id not in country_count_map:
            country_count_map[country_id] = []
        if geography_id not in geo_count_map:
            geo_count_map[geography_id] = []
        country_count_map[country_id].append(unit["unit_id"])
        geo_count_map[geography_id].append(unit["unit_id"])

    # To separate domain wise and org wise units
    for unit in unit_org_details:
        domain_id = unit["domain_id"]
        org_id = unit["organisation_id"]
        unit_id = unit["unit_id"]
        if domain_id not in domain_count_map:
            domain_count_map[domain_id] = []
        if org_id not in org_count_map:
            org_count_map[org_id] = []
        domain_count_map[domain_id].append(unit_id)
        org_count_map[org_id].append(unit_id)

    common_countries = []
    common_geographies = []
    common_domains = []
    common_orgs = []
    for country_id in country_count_map:
        unit_ids = country_count_map[country_id]
        if len(unit_ids) >= unit_count:
            common_countries.append(country_id)

    for geography_id in geo_count_map:
        unit_ids = geo_count_map[geography_id]
        if len(unit_ids) >= unit_count:
            common_geographies.append(geography_id)

    for domain_id in domain_count_map:
        unit_ids = domain_count_map[domain_id]
        if len(unit_ids) >= unit_count:
            common_domains.append(domain_id)

    for org_id in org_count_map:
        unit_ids = org_count_map[org_id]
        if len(unit_ids) >= unit_count:
            common_orgs.append(org_id)

    if (len(common_countries) <= 0):
        raise process_error("EO83")
    elif (len(common_geographies) <= 0):
        raise process_error("E084")
    elif (len(common_domains) <= 0):
        raise process_error("E085")
    elif (len(common_orgs) <= 0):
        raise process_error("E086")

    (statutories, level_1_statutories, mapping_orgs,
     mapping_locations) = db.call_proc_with_multiresult_set(
         "sp_compliances_by_unit_details", (
             ",".join(str(x) for x in common_domains),
             ",".join(str(x) for x in common_countries),
             ",".join(str(x) for x in common_geographies),
             ",".join(str(x) for x in common_orgs),
         ), 4)
    return return_wizard_two_data(statutories, level_1_statutories,
                                  mapping_orgs, mapping_locations)
Exemplo n.º 6
0
def approve_client_group(db, request, session_user):
    client_group_approval_details = request.client_group_approval_details
    current_time_stamp = get_date_time()
    columns = ["is_approved", "reason", "approved_by", "approved_on"]
    values = []
    conditions = []
    client_ids = []
    le_ids = []
    approval_status = False
    approved_entity = ''
    rejected_entity = ''
    text = ''
    old_client_id = 0
    techno_manager_id = []
    group_name = ''

    console_users_id = []
    res = db.call_proc("sp_users_under_user_category", (2, ))
    for user in res:
        console_users_id.append(user["user_id"])

    for detail in client_group_approval_details:
        client_id = detail.client_id
        entity_id = detail.entity_id
        entity_name = detail.entity_name
        approval_status = detail.approval_status
        reason = detail.reason
        le_ids.append(entity_id)

        if old_client_id != client_id:
            client_ids.append(client_id)
            old_client_id = client_id
            group_name = get_group_by_id(db, client_id)
            rows = db.call_proc("sp_get_techno_manager_id_by_client",
                                (client_id, ))
            for r in rows:
                techno_manager_id.append(int(r["user_id"]))

        value_tuple = (1 if approval_status is True else 2, reason,
                       session_user, current_time_stamp)
        values.append(value_tuple)
        condition = "legal_entity_id=%s" % (entity_id)
        conditions.append(condition)
        if (approval_status is True):
            approved_entity = approved_entity + entity_name + ' '
            if len(console_users_id) > 0:
                db.save_toast_messages(
                    2, "Approve Client Group", entity_name +
                    " for the Group \"" + group_name + "\" has been approved",
                    None, console_users_id, session_user)
            if len(techno_manager_id) > 0:
                db.save_toast_messages(
                    5, "Approve Client Group", entity_name +
                    " for the Group \"" + group_name + "\" has been approved",
                    None, techno_manager_id, session_user)
        else:
            rejected_entity = rejected_entity + entity_name + ' '
            if len(techno_manager_id) > 0:
                db.save_toast_messages(
                    5, "Approve Client Group",
                    entity_name + " for the Group \"" + group_name +
                    "\" has been rejected for the reason \"" + reason + "\"",
                    None, techno_manager_id, session_user)

    result = db.bulk_update("tbl_legal_entities", columns, values, conditions)

    for le_id in le_ids:
        db.call_update_proc("sp_legal_entity_contract_history_delete",
                            (le_id, ))
        db.call_update_proc("sp_legal_entity_domain_history_delete", (le_id, ))

    for client_id in client_ids:
        db.call_update_proc("sp_client_group_history_delete", (client_id, ))

    if approved_entity != '':
        text = approved_entity + " has been Approved. "

    if rejected_entity != '':
        text = approved_entity + rejected_entity + "has been Rejected."

    #
    # sp_activity_log_save
    # Arguments : user id, form id, action, time of action
    # Results : Returns activity log id
    #
    if result:
        db.call_insert_proc(
            "sp_activity_log_save",
            (session_user, frmApproveClientGroup, text, current_time_stamp))
        return result
    else:
        db.call_insert_proc(
            "sp_activity_log_save",
            (session_user, frmApproveClientGroup,
             return_Knowledge_message("E072"), current_time_stamp))
        raise process_error("E072")
Exemplo n.º 7
0
def approve_unit(db, request, session_user):
    unit_approval_details = request.unit_approval_details
    legal_entity_name = None
    current_time_stamp = get_date_time()
    columns = [
        "is_approved", "approved_by", "approved_on", "remarks", "updated_by",
        "updated_on"
    ]
    values = []
    conditions = []

    admin_users_id = []
    res = db.call_proc("sp_users_under_user_category", (1, ))
    for user in res:
        admin_users_id.append(user["user_id"])

    for detail in unit_approval_details:
        legal_entity_name = detail.legal_entity_name
        unit_id = detail.unit_id
        approval_status = detail.approval_status
        reason = detail.reason
        value_tuple = (1 if approval_status is True else 2, session_user,
                       current_time_stamp, reason, session_user,
                       current_time_stamp)
        values.append(value_tuple)
        condition = "unit_id=%s" % (unit_id)
        conditions.append(condition)

        u_name_rows = db.call_proc("sp_unitname_by_id", [unit_id])
        u_name = u_name_rows[0]["unit_name"]

        techno_executive_id = []
        techno_exe_rows = db.call_proc("sp_get_techno_executive_id_by_unit",
                                       (unit_id, ))
        for r in techno_exe_rows:
            techno_executive_id.append(int(r["user_id"]))

        if (approval_status is True):
            if len(admin_users_id) > 0:
                # db.save_toast_messages(1, "Approve Client Unit", u_name + " for the Group \""+ group_name + "\" in " + legal_entity_name +"has been approved", None, admin_users_id, session_user)
                db.save_toast_messages(
                    1, "Approve Client Unit",
                    u_name + " for the Legal entity \"" + legal_entity_name +
                    "\" has been approved", None, admin_users_id, session_user)
            if len(techno_executive_id) > 0:
                db.save_toast_messages(
                    6, "Approve Client Unit",
                    u_name + " for the Legal entity \"" + legal_entity_name +
                    "\" has been approved", None, techno_executive_id,
                    session_user)
        else:
            if len(admin_users_id) > 0:
                # db.save_toast_messages(1, "Approve Client Unit", u_name + " for the Group \""+ group_name + "\" in " + legal_entity_name +"has been rejected", None, admin_users_id, session_user)
                db.save_toast_messages(
                    1, "Approve Client Unit",
                    u_name + " for the Legal entity \"" + legal_entity_name +
                    "\" has been rejected", None, admin_users_id, session_user)
            if len(techno_executive_id) > 0:
                db.save_toast_messages(
                    6, "Approve Client Unit",
                    u_name + " for the Legal entity \"" + legal_entity_name +
                    "\" has been rejected", None, techno_executive_id,
                    session_user)

    result = db.bulk_update(tblUnits, columns, values, conditions)

    #
    # sp_activity_log_save
    # Arguments : user id, form id, action, time of action
    # Results : Returns activity log id
    #
    if result:
        db.call_insert_proc(
            "sp_activity_log_save",
            (session_user, frmClientUnitApproval, "Approved Unit" if
             (approval_status is True) else "Rejected Unit",
             current_time_stamp))

        return result
    else:
        db.call_insert_proc(
            "sp_activity_log_save",
            (session_user, frmClientUnitApproval,
             return_Knowledge_message("E072"), current_time_stamp))
        raise process_error("E072")
def save_ip_setting_details(db, request, session_user):
    ip_setting_details = request.group_ips_list
    insert_columns = [
        "client_id", "form_id", "ips"
    ]
    insert_values = []
    client_id = None
    for detail in ip_setting_details:
        #unit_ids.append(detail.unit_id)
        client_id = detail.client_id
        insert_values.append(
            (
                detail.client_id, detail.form_id,
                detail.ip
            )
        )
    #
    #  To delete all ip setting details under the legal entity
    #  Parameters : client id
    #  Return : True on successfull deletion otherwise returns False
    #
    db.call_update_proc("sp_ip_settings_delete", (client_id,))
    result = db.bulk_insert(
        tblIPSettings, insert_columns, insert_values
    )
    if result:
        #
        #  To get legal entity name by it's id to save activity
        #  Parameters : legal entity id
        #  Return : Returns legal entity name
        #
        data = db.call_proc("sp_group_name_by_id", (client_id,))
        action = "Configured ip settings for %s " % (
            data[0]["group_name"])
        db.save_activity(session_user, frmIPSettings, action)

        admin_users_id = []
        rows = db.call_proc("sp_users_under_user_category", (1,))
        for r in rows:
            admin_users_id.append(r["user_id"])

        techno_manager_id = []
        rows = db.call_proc("sp_get_techno_manager_id_by_client", (client_id,))
        for r in rows:
            techno_manager_id.append(int(r["user_id"]))

        domain_manager_id = []
        rows = db.call_proc("sp_get_domain_manager_id_by_legalentity", (client_id, None))
        for r in rows:
            domain_manager_id.append(int(r["user_id"]))

        msg_text = "IP level restrictions has been enabled for \""+ data[0]["group_name"] + "\" "

        if len(admin_users_id) > 0:
            db.save_toast_messages(1, "Form Authorization-IP Setting", msg_text, None, admin_users_id, session_user)

        if len(techno_manager_id) > 0:
            db.save_toast_messages(5, "Form Authorization-IP Setting", msg_text, None, techno_manager_id, session_user)

        if len(domain_manager_id) > 0:
            db.save_toast_messages(7, "Form Authorization-IP Setting", msg_text, None, domain_manager_id, session_user)

    else:
        raise process_error("E078")
def save_auto_deletion_details(db, request, session_user):
    auto_deletion_details = request.auto_deletion_details
    unit_ids = []
    insert_columns = [
        "client_id", "legal_entity_id", "unit_id", "deletion_period"
    ]
    insert_values = []
    legal_entity_id = None
    client_id = None
    for detail in auto_deletion_details:
        unit_ids.append(detail.unit_id)
        legal_entity_id = detail.legal_entity_id
        client_id = detail.client_id
        insert_values.append(
            (
                detail.client_id, detail.legal_entity_id,
                detail.unit_id, detail.deletion_period
            )
        )
    #
    #  To delete all auto deletion details under the legal entity
    #  Parameters : Legal entity id
    #  Return : True on successfull deletion otherwise returns False
    #

    result = db.call_proc("sp_check_auto_deletion", (legal_entity_id,))
    cnt = int(result[0]["cnt"])
    if cnt > 0:
        db.call_update_proc("sp_unitautodeletion_delete", (legal_entity_id,))

    result = db.bulk_insert(
        tblAutoDeletion, insert_columns, insert_values
    )
    if result:
        #
        #  To get legal entity name by it's id to save activity
        #  Parameters : legal entity id
        #  Return : Returns legal entity name
        #
        data = db.call_proc("sp_legal_entity_name_by_id", (legal_entity_id,))
        action = "Configured auto deletion for %s " % (
            data[0]["legal_entity_name"])
        db.save_activity(session_user, frmAutoDeletion, action)

        group_data = db.call_proc("sp_group_name_by_id", (client_id,))

        if cnt > 0:
            msg_text = "Auto Deletion for the Group \""+ data[0]["legal_entity_name"] +" / "+ group_data[0]["group_name"] + "\" has been modified"
        else:
            msg_text = "Auto Deletion for the Group \""+ data[0]["legal_entity_name"] +" / "+ group_data[0]["group_name"] + "\" has been added"

        admin_users_id = []
        rows = db.call_proc("sp_users_under_user_category", (1,))
        for r in rows:
            admin_users_id.append(r["user_id"])

        techno_manager_id = []
        rows = db.call_proc("sp_get_techno_manager_id_by_client", (client_id,))
        for r in rows:
            techno_manager_id.append(int(r["user_id"]))

        domain_manager_id = []
        rows = db.call_proc("sp_get_domain_manager_id_by_legalentity", (client_id, legal_entity_id))
        for r in rows:
            domain_manager_id.append(int(r["user_id"]))

        if len(admin_users_id) > 0:
            db.save_toast_messages(1, "Auto Deletion", msg_text , None, admin_users_id, session_user)

        if len(techno_manager_id) > 0:
            db.save_toast_messages(5, "Auto Deletion", msg_text, None, techno_manager_id, session_user)

        if len(domain_manager_id) > 0:
            db.save_toast_messages(7, "Auto Deletion", msg_text, None, domain_manager_id, session_user)

    else:
        raise process_error("E078")
def process_approve_assigned_statutory(db, request, user_id):
    data = save_approve_statutories(db, request, user_id)
    if data is True:
        return domaintransactionprotocol.ApproveAssignedStatutorySuccess()
    else:
        raise process_error("E088")
Exemplo n.º 11
0
def save_client_statutories(db, request, user_id):
    status = request.submission_type
    client_id = request.client_id
    legal_entity_id = request.legal_entity_id
    domain_name = request.domain_name
    domain_id = request.domain_id
    unit_ids = request.unit_ids
    le_name = request.legal_entity_name
    bg_name = request.b_grp_name

    group_name = get_group_by_id(db, client_id)
    admin_users_id = []
    res = db.call_proc("sp_users_under_user_category", (1, ))
    for user in res:
        admin_users_id.append(user["user_id"])

    extra_text = ''
    if bg_name is not None:
        extra_text = group_name + ' group, ' + bg_name + ' business group, ' + le_name + ' legal entity, '
    else:
        extra_text = group_name + ' group, ' + le_name + ' legal entity, '

    is_update = True
    comps = request.compliances_applicablity_status
    q = "INSERT INTO tbl_client_statutories(client_id, unit_id, domain_id, status)" + \
        " values (%s, %s, %s, %s)"

    saved_unit = []
    for c in comps:
        # print c.client_statutory_id

        if c.unit_id in saved_unit:
            continue

        if c.client_statutory_id is None:
            is_update = False
            csid = db.execute_insert(q,
                                     [client_id, c.unit_id, domain_id, status])
            if csid is False:
                raise process_error("E088")
        else:
            # db.execute(q1_update, [status, c.client_statutory_id])
            csid = c.client_statutory_id

        saved_unit.append(c.unit_id)
        save_statutory_compliances(db, client_id, legal_entity_id, domain_id,
                                   comps, c.unit_id, status, user_id, csid)
        unit_name = c.unit_name

        if status == 2:
            domain_users_id = []
            res = db.call_proc("sp_user_by_unit_id", (7, c.unit_id))
            for user in res:
                domain_users_id.append(user["user_id"])

            if is_update == True:
                msg = "Statutes are updated for the Unit %s in %s %s domain " % (
                    unit_name, extra_text, domain_name)
            else:
                msg = "Statutes are assigned for the Unit %s in %s %s domain " % (
                    unit_name, extra_text, domain_name)

            if len(domain_users_id) > 0:
                db.save_toast_messages(7, "Assign Statutory", msg, None,
                                       domain_users_id, user_id)
            if len(admin_users_id) > 0:
                db.save_toast_messages(1, "Assign Statutory", msg, None,
                                       admin_users_id, user_id)
            db.save_activity(user_id, frmAssignStatutory, msg)

    if status == 1:
        for u in unit_ids:
            q1_cs_update = "UPDATE tbl_client_statutories set status = %s where " + \
                " client_statutory_id in ( select client_statutory_id from tbl_client_compliances " + \
                "  where unit_id = %s and domain_id = %s )"
            db.execute(q1_cs_update, [status, u, domain_id])

    if status == 2:
        for u in unit_ids:
            q1_cs_update = "UPDATE tbl_client_statutories set status = %s where " + \
                " client_statutory_id in ( select client_statutory_id from tbl_client_compliances " + \
                "  where unit_id = %s and domain_id = %s )"
            db.execute(q1_cs_update, [status, u, domain_id])

            q1_cc_update = "UPDATE tbl_client_compliances set is_approved = %s, submitted_by = %s, submitted_on = %s where is_approved NOT IN (3, 5) and unit_id = %s and domain_id = %s"
            db.execute(q1_cc_update,
                       [status, user_id,
                        get_date_time(), u, domain_id])

    return True