def populate_comm_list():
    func_type = "remap"
    start = time.time()

    c_csv = csv.reader(open(_DATA_FILE,"rb"))

    count = 0
    _cid = 0
    for col in c_csv:
        #skip the first row
        if count == 0:
            count+= 1
            continue

        ##Initialization of fields
        _cid += 1
        _tid = col[0].strip()
        _dateline = str(int(custom_time.unix_time(col[1].strip())))
        _paytime = str(int(custom_time.unix_time(col[1].strip())))
        _salesperson = col[6]
        _price = col[15]
        _first_tier_name = col[26]
        _first_tier_amount = col[28]
        _second_tier_name = col[29]
        _second_tier_amount = col[31]
        _third_tier_name = col[32]
        _third_tier_amount = col[34]

        ##Creating Commission object and add to list
        c_object = Commission(_cid, _tid,_dateline,_paytime,_salesperson,_price,
                               _first_tier_name,_first_tier_amount, _second_tier_name,
                               _second_tier_amount,_third_tier_name, _third_tier_amount )
        comm_list.append(c_object)
        _cid = c_object.cid + c_object.cid_counter
def populate_ta_list():
	func_type = "remap"
	start = time.time()

	hr_csv = csv.reader(open("HR.csv","rb"));
	t_csv = csv.reader(open(_DATA_FILE,"rb"))

	count = 0
	for row in t_csv:
		#skip the first row
		if count == 0:
			count+= 1
			continue

		##Initialization of fields
		_tid = row[0].strip()
		_dateline = str(int(custom_time.unix_time(row[1].strip())))
		_start_time = str(int(custom_time.unix_time(row[2].strip())))
		_end_time = str(int(custom_time.unix_time(row[3].strip())))
		_type = row[4]
		_option = str(int(custom_time.unix_time(row[5].strip())))
		_salesperson = row[6]
		_block_no = row[7]
		_street_name = row[8]
		_level = ""
		_unit_no = ""
		_zipcode = row[11]
		_client = row[12]
		_cea_no = ""
		_uid = ""

		#Mapping type with their type number
		_type = str(_TYPE_DICT[_type])

		##Mapping name with CEA_NO in HR.CSV
		for inner_row in hr_csv:
			if _salesperson == inner_row[0]:
				_cea_no = inner_row[1]
				break

		##Split Unit and Level by hyphen
		if row[9] != "":
			temp_unit = row[9].split("-")
			if(len(temp_unit) < 2):
				_level = "0"
				_unit_no = "0"
			else:
				_level = temp_unit[0]
				_unit_no = temp_unit[1]

		_uid = str(_get_uid_from_name(_salesperson))


		_commission = row[25]
		_agency = row[16]


		##Creating Transaction object and add to list
		t_object = Transaction(_tid, _start_time, _end_time, _type, _option, _salesperson, _cea_no, _block_no, _street_name, _level, _unit_no, _zipcode, _client, _uid, _commission, _agency)
		ta_list.append(t_object)
def populate_ta_list():
    func_type = "remap"
    start = time.time()

    hr_csv = csv.reader(open("HR.csv","rb"));
    t_csv = csv.reader(open(_DATA_FILE,"rb"))

    count = 0
    for col in t_csv:
        #skip the first row
        if count == 0:
            count+= 1
            continue

        ##Initialization of fields
        _tid = col[0].strip()
        _addtime = str(int(custom_time.unix_time(col[3].strip())))
        _billing_date = str(int(custom_time.unix_time(col[1].strip())))
        _type = str(get_type(col[4],col[46]))
        _option = str(int(custom_time.unix_time(col[5].strip())))
        _salesperson = col[6]
        _block_no = col[7]
        _street_name = col[8]
        _level = ""
        _unit_no = ""
        _zipcode = col[11]
        _client = col[12]
        _cea_no = ""
        _uid = ""
        _license = "L3010008E"
        _cea_no = "sp.cea_no"
        
        ##Split Unit and Level by hyphen
        if col[9] != "":
            temp_unit = col[9].split("-")
            if(len(temp_unit) < 2):
                _level = "0"
                _unit_no = "0"
            else:
                _level = temp_unit[0]
                _unit_no = temp_unit[1]

        ##_uid = str(_get_uid_from_name(_salesperson))
        ## not in use
        _uid = 'user.uid'

        ##CLOSING AGENT($)
        _closing_agent_money = col[25]

        ##Net Amount to Bill
        _received = col[15]
        _agency = col[16]

        ##AMOUNT
        _gross_commission = col[20]

        ##Creating Transaction object and add to list
        t_object = Transaction(_tid, _addtime, _billing_date, _type, _option, _salesperson, _cea_no, _block_no, _street_name, _level,
                               _unit_no, _zipcode, _client, _uid, _received, _agency, _gross_commission, _closing_agent_money, _license)
        ta_list.append(t_object)
def populate_comm_list():
    commission_list = []
    func_type = "remap"
    start = time.time()
    c_csv = csv.reader(open(_DATA_FILE, "rb"))
    count = 0
    _cid = 0
    for col in c_csv:
        # skip the first row
        if count == 0:
            count += 1
            continue

        ##Initialization of fields
        _cid += 1
        _tid = col[0].strip()
        _dateline = str(int(custom_time.unix_time(col[1].strip())))
        _paytime = str(int(custom_time.unix_time(col[1].strip())))
        _salesperson = col[6]
        # amount is closing agent
        _amount = col[25]
        # price is co-broker invoice
        _price = col[19]
        _first_tier_name = col[26]
        _first_tier_amount = col[28]
        _second_tier_name = col[29]
        _second_tier_amount = col[31]
        _third_tier_name = col[32]
        _third_tier_amount = col[34]
        _gm1_value = col[36]
        _gm2_value = col[38]
        _resale_bonus = col[40]
        _project_bonus = col[42]
        _marketing_budget = col[44]

        ##Creating Commission object and add to list
        c_object = Commission(
            _cid,
            _tid,
            _dateline,
            _paytime,
            _salesperson,
            _amount,
            _price,
            _first_tier_name,
            _first_tier_amount,
            _second_tier_name,
            _second_tier_amount,
            _third_tier_name,
            _third_tier_amount,
            _gm1_value,
            _gm2_value,
            _resale_bonus,
            _project_bonus,
            _marketing_budget,
        )
        commission_list.append(c_object)
        _cid = c_object.cid + c_object.cid_counter

    return commission_list
def remap_generate_transaction_script():
    func_type = "remap"
    start = time.time()

    hr_csv = csv.reader(open("HR.csv","rb"));
    t_csv = csv.reader(open(_DATA_FILE,"rb"))
    f = open(_REMAP_EXPORT_FILE,'wb')

    f.write(_use_db(func_type))
    f.write(_create_cdb_transaction_statement(func_type))
    f.write("\n\n")
    f.write(_delete_records_statement())

    count = 0
    for row in t_csv:
        #skip the first row
        if count == 0:
            count+= 1
            continue

        ##Initialization of fields
        temp_string = _get_init_insert_string(_REMAP_FIELD_LIST)
        _tid = row[0]
        _dateline = str(int(custom_time.unix_time(row[1].strip())))
        _addtime = str(int(custom_time.unix_time(row[2].strip())))
        _end_time = str(int(custom_time.unix_time(row[3].strip())))
        _type = row[4]
        _option = str(int(custom_time.unix_time(row[5].strip())))
        _salesperson = row[6]
        _block_no = row[7]
        _street_name = row[8]
        _level = ""
        _unit_no = ""
        _zipcode = row[11]
        _client = row[12]
        _cea_no = ""
        _uid = ""

        #Mapping type with their type number
        _type = str(_TYPE_DICT[_type])

        ##Mapping name with CEA_NO in HR.CSV
        for inner_row in hr_csv:
            if _salesperson == inner_row[0]:
                _cea_no = inner_row[1]
                break

        ##Split Unit and Level by hyphen
        if row[9] != "":
            temp_unit = row[9].split("-")
            if(len(temp_unit) < 2):
                _level = "0"
                _unit_no = "0"
            else:
                _level = temp_unit[0]
                _unit_no = temp_unit[1]


        _uid = str(_get_uid_from_name(_salesperson))
        
        temp_string += '"'+ _tid +'","' + _dateline + '","' + _addtime + '","' + _end_time + '","' + _type + '","' + _option + '","' + _salesperson + '","' + _cea_no + '","' + _block_no + '","' + _street_name + '","' + _level + '","' + _unit_no + '","' + _zipcode + '","'+_client + '","' + _uid + '");\n'
        f.write(temp_string)

    f.close()

    ##f = open(_REMAP_EXPORT_FILE,'r')
    #_print_out(f,_REMAP_EXPORT_FILE)
    
    print "Migration completed.\nOperation took",time.time() - start,"seconds.\nPlease view",_REMAP_EXPORT_FILE
def populate_ta_list():
    func_type = "remap"
    start = time.time()

    hr_csv = csv.reader(open("HR.csv", "rb"))
    t_csv = csv.reader(open(_DATA_FILE, "rb"))

    count = 0
    for row in t_csv:
        # skip the first row
        if count == 0:
            count += 1
            continue

        ##Initialization of fields
        _tid = row[0].strip()
        _addtime = str(int(custom_time.unix_time(row[3].strip())))
        _type = str(get_type(row[4], row[46]))
        _option = str(int(custom_time.unix_time(row[5].strip())))
        _salesperson = row[6]
        _block_no = row[7]
        _street_name = row[8]
        _level = ""
        _unit_no = ""
        _zipcode = row[11]
        _client = row[12]
        _cea_no = ""
        _uid = ""
        _license = "LL3010008H"

        ##Mapping name with CEA_NO in HR.CSV
        ##        for inner_row in hr_csv:
        ##            if _salesperson == inner_row[0]:
        ##                _cea_no = inner_row[1]
        ##                break

        ##Split Unit and Level by hyphen
        if row[9] != "":
            temp_unit = row[9].split("-")
            if len(temp_unit) < 2:
                _level = "0"
                _unit_no = "0"
            else:
                _level = temp_unit[0]
                _unit_no = temp_unit[1]

        ##_uid = str(_get_uid_from_name(_salesperson))
        _uid = "user.uid"

        ##CLOSING AGENT($)
        _received = row[25]
        _agency = row[16]

        ##AMOUNT
        _gross_commission = row[20]

        ##Creating Transaction object and add to list
        t_object = Transaction(
            _tid,
            _addtime,
            _type,
            _option,
            _salesperson,
            _cea_no,
            _block_no,
            _street_name,
            _level,
            _unit_no,
            _zipcode,
            _client,
            _uid,
            _received,
            _agency,
            _gross_commission,
            _license,
        )
        ta_list.append(t_object)