/** END * */
 function buildSearchQueryForFieldTypes($uitypes, $value = false)
 {
     global $adb;
     if (!is_array($uitypes)) {
         $uitypes = array($uitypes);
     }
     $module = get_class($this);
     $cachedModuleFields = VTCacheUtils::lookupFieldInfo_Module($module);
     if ($cachedModuleFields === false) {
         getColumnFields($module);
         // This API will initialize the cache as well
         // We will succeed now due to above function call
         $cachedModuleFields = VTCacheUtils::lookupFieldInfo_Module($module);
     }
     $lookuptables = array();
     $lookupcolumns = array();
     foreach ($cachedModuleFields as $fieldinfo) {
         if (in_array($fieldinfo['uitype'], $uitypes)) {
             $lookuptables[] = $fieldinfo['tablename'];
             $lookupcolumns[] = $fieldinfo['columnname'];
         }
     }
     $entityfields = getEntityField($module);
     $querycolumnnames = implode(',', $lookupcolumns);
     $entitycolumnnames = $entityfields['fieldname'];
     $query = "select crmid as id, {$querycolumnnames}, {$entitycolumnnames} as name ";
     $query .= " FROM {$this->table_name} ";
     $query .= " INNER JOIN vtiger_crmentity ON {$this->table_name}.{$this->table_index} = vtiger_crmentity.crmid AND deleted = 0 ";
     //remove the base table
     $LookupTable = array_unique($lookuptables);
     $indexes = array_keys($LookupTable, $this->table_name);
     if (!empty($indexes)) {
         foreach ($indexes as $index) {
             unset($LookupTable[$index]);
         }
     }
     foreach ($LookupTable as $tablename) {
         $query .= " INNER JOIN {$tablename}\n\t\t\t\t\t\ton {$this->table_name}.{$this->table_index} = {$tablename}." . $this->tab_name_index[$tablename];
     }
     if (!empty($lookupcolumns) && $value !== false) {
         $query .= " WHERE ";
         $i = 0;
         $columnCount = count($lookupcolumns);
         foreach ($lookupcolumns as $columnname) {
             if (!empty($columnname)) {
                 if ($i == 0 || $i == $columnCount) {
                     $query .= sprintf("%s = '%s'", $columnname, $value);
                 } else {
                     $query .= sprintf(" OR %s = '%s'", $columnname, $value);
                 }
                 $i++;
             }
         }
     }
     return $query;
 }
Beispiel #2
0
 public function buildSearchQueryWithUIType($uitype, $value, $module)
 {
     if (empty($value)) {
         return false;
     }
     $cachedModuleFields = VTCacheUtils::lookupFieldInfo_Module($module);
     if ($cachedModuleFields === false) {
         getColumnFields($module);
         // This API will initialize the cache as well
         // We will succeed now due to above function call
         $cachedModuleFields = VTCacheUtils::lookupFieldInfo_Module($module);
     }
     $lookuptables = array();
     $lookupcolumns = array();
     foreach ($cachedModuleFields as $fieldinfo) {
         if (in_array($fieldinfo['uitype'], array($uitype))) {
             $lookuptables[] = $fieldinfo['tablename'];
             $lookupcolumns[] = $fieldinfo['columnname'];
         }
     }
     $entityfields = getEntityField($module);
     $querycolumnnames = implode(',', $lookupcolumns);
     $entitycolumnnames = $entityfields['fieldname'];
     $query = "select id as id, {$querycolumnnames}, {$entitycolumnnames} as name ";
     $query .= " FROM vtiger_users";
     if (!empty($lookupcolumns)) {
         $query .= " WHERE deleted=0 AND ";
         $i = 0;
         $columnCount = count($lookupcolumns);
         foreach ($lookupcolumns as $columnname) {
             if (!empty($columnname)) {
                 if ($i == 0 || $i == $columnCount) {
                     $query .= sprintf("%s = '%s'", $columnname, $value);
                 } else {
                     $query .= sprintf(" OR %s = '%s'", $columnname, $value);
                 }
                 $i++;
             }
         }
     }
     return $query;
 }
 /**
  * This function handles the import for uitype 10 fieldtype
  * @param string $module - the current module name
  * @param string fieldname - the related to field name
  */
 function add_related_to($module, $fieldname)
 {
     global $adb, $imported_ids, $current_user;
     $related_to = $this->column_fields[$fieldname];
     if (empty($related_to)) {
         return false;
     }
     //check if the field has module information; if not get the first module
     if (!strpos($related_to, "::::")) {
         $module = getFirstModule($module, $fieldname);
         $value = $related_to;
     } else {
         //check the module of the field
         $arr = array();
         $arr = explode("::::", $related_to);
         $module = $arr[0];
         $value = $arr[1];
     }
     $focus1 = CRMEntity::getInstance($module);
     $entityNameArr = getEntityField($module);
     $entityName = $entityNameArr['fieldname'];
     $query = "SELECT vtiger_crmentity.deleted, {$focus1->table_name}.* \n\t\t\t\t\tFROM {$focus1->table_name}\n\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid={$focus1->table_name}.{$focus1->table_index}\n\t\t\t\t\t\twhere {$entityName}=? and vtiger_crmentity.deleted=0";
     $result = $adb->pquery($query, array($value));
     if (!isset($this->checkFlagArr[$module])) {
         $this->checkFlagArr[$module] = isPermitted($module, 'EditView', '') == 'yes';
     }
     if ($adb->num_rows($result) > 0) {
         //record found
         $focus1->id = $adb->query_result($result, 0, $focus1->table_index);
     } elseif ($this->checkFlagArr[$module]) {
         //record not found; create it
         $focus1->column_fields[$focus1->list_link_field] = $value;
         $focus1->column_fields['assigned_user_id'] = $current_user->id;
         $focus1->column_fields['modified_user_id'] = $current_user->id;
         $focus1->save($module);
         $last_import = new UsersLastImport();
         $last_import->assigned_user_id = $current_user->id;
         $last_import->bean_type = $module;
         $last_import->bean_id = $focus1->id;
         $last_import->save();
     } else {
         //record not found and cannot create
         $this->column_fields[$fieldname] = "";
         return false;
     }
     if (!empty($focus1->id)) {
         $this->column_fields[$fieldname] = $focus1->id;
         return true;
     } else {
         $this->column_fields[$fieldname] = "";
         return false;
     }
 }
function BasicSearch($module, $search_field, $search_string, $input = '')
{
    global $log, $mod_strings, $current_user;
    $log->debug("Entering BasicSearch(" . $module . "," . $search_field . "," . $search_string . ") method ...");
    global $adb;
    $search_string = ltrim(rtrim($adb->sql_escape_string($search_string)));
    global $column_array, $table_col_array;
    if (empty($input)) {
        $input = $_REQUEST;
    }
    if ($search_field == 'crmid') {
        $column_name = 'crmid';
        $table_name = 'vtiger_crmentity';
        $where = "{$table_name}.{$column_name} like '" . formatForSqlLike($search_string) . "'";
    } elseif ($search_field == 'currency_id' && ($module == 'PriceBooks' || $module == 'PurchaseOrder' || $module == 'SalesOrder' || $module == 'Invoice' || $module == 'Quotes')) {
        $column_name = 'currency_name';
        $table_name = 'vtiger_currency_info';
        $where = "{$table_name}.{$column_name} like '" . formatForSqlLike($search_string) . "'";
    } elseif ($search_field == 'folderid' && $module == 'Documents') {
        $column_name = 'foldername';
        $table_name = 'vtiger_attachmentsfolder';
        $where = "{$table_name}.{$column_name} like '" . formatForSqlLike($search_string) . "'";
    } else {
        //Check added for tickets by accounts/contacts in dashboard
        $search_field_first = $search_field;
        if ($module == 'HelpDesk') {
            if ($search_field == 'contactid') {
                $where = "(vtiger_contactdetails.contact_no like '" . formatForSqlLike($search_string) . "')";
                return $where;
            } elseif ($search_field == 'account_id') {
                $search_field = "parent_id";
            }
        }
        //Check ends
        //Added to search contact name by lastname
        if (($module == "Calendar" || $module == "Invoice" || $module == "Documents" || $module == "SalesOrder" || $module == "PurchaseOrder") && $search_field == "contact_id") {
            $module = 'Contacts';
            $search_field = 'lastname';
        }
        if ($search_field == "accountname" && $module != "Accounts") {
            $search_field = "account_id";
        }
        if ($search_field == 'productname' && $module == 'Campaigns') {
            $search_field = "product_id";
        }
        $qry = "select vtiger_field.columnname,tablename from vtiger_tab inner join vtiger_field on vtiger_field.tabid=vtiger_tab.tabid where vtiger_tab.name=? and (fieldname=? or columnname=?)";
        $result = $adb->pquery($qry, array($module, $search_field, $search_field));
        $noofrows = $adb->num_rows($result);
        if ($noofrows != 0) {
            $column_name = $adb->query_result($result, 0, 'columnname');
            //Check added for tickets by accounts/contacts in dashboard
            if ($column_name == 'parent_id') {
                if ($search_field_first == 'account_id') {
                    $search_field_first = 'accountid';
                }
                if ($search_field_first == 'contactid') {
                    $search_field_first = 'contact_id';
                }
                $column_name = $search_field_first;
            }
            //Check ends
            $table_name = $adb->query_result($result, 0, 'tablename');
            $uitype = getUItype($module, $column_name);
            //Added for Member of search in Accounts
            if ($column_name == "parentid" && $module == "Accounts") {
                $table_name = "vtiger_account2";
                $column_name = "accountname";
            }
            if ($column_name == "parentid" && $module == "Products") {
                $table_name = "vtiger_products2";
                $column_name = "productname";
            }
            if ($column_name == "reportsto" && $module == "Contacts") {
                $table_name = "vtiger_contactdetails2";
                $column_name = "lastname";
            }
            if ($column_name == "inventorymanager" && ($module = "Quotes")) {
                $table_name = "vtiger_usersQuotes";
                $column_name = "user_name";
            }
            //Added to support user date format in basic search
            if ($uitype == 5 || $uitype == 6 || $uitype == 23 || $uitype == 70) {
                if ($search_string != '' && $search_string != '0000-00-00') {
                    $date = new DateTimeField($search_string);
                    $value = $date->getDisplayDate();
                    if (strpos($search_string, ' ') > -1) {
                        $value .= ' ' . $date->getDisplayTime();
                    }
                } else {
                    $value = $search_string;
                }
            }
            // Added to fix errors while searching check box type fields(like product active. ie. they store 0 or 1. we search them as yes or no) in basic search.
            if ($uitype == 56) {
                if (strtolower($search_string) == 'yes') {
                    $where = "{$table_name}.{$column_name} = '1'";
                } elseif (strtolower($search_string) == 'no') {
                    $where = "{$table_name}.{$column_name} = '0'";
                } else {
                    $where = "{$table_name}.{$column_name} = '-1'";
                }
            } elseif ($uitype == 15 || $uitype == 16) {
                if (is_uitype($uitype, '_picklist_')) {
                    // Get all the keys for the for the Picklist value
                    $mod_keys = array_keys($mod_strings, $search_string);
                    if (sizeof($mod_keys) >= 1) {
                        // Iterate on the keys, to get the first key which doesn't start with LBL_      (assuming it is not used in PickList)
                        foreach ($mod_keys as $mod_idx => $mod_key) {
                            $stridx = strpos($mod_key, 'LBL_');
                            // Use strict type comparision, refer strpos for more details
                            if ($stridx !== 0) {
                                $search_string = $mod_key;
                                if ($input['operator'] == 'e' && getFieldVisibilityPermission("Calendar", $current_user->id, 'taskstatus') == '0' && ($column_name == "status" || $column_name == "eventstatus")) {
                                    $where = "(vtiger_activity.status ='" . $search_string . "' or vtiger_activity.eventstatus ='" . $search_string . "')";
                                } else {
                                    if (getFieldVisibilityPermission("Calendar", $current_user->id, 'taskstatus') == '0' && ($column_name == "status" || $column_name == "eventstatus")) {
                                        $where = "(vtiger_activity.status like '" . formatForSqlLike($search_string) . "' or vtiger_activity.eventstatus like '" . formatForSqlLike($search_string) . "')";
                                    } else {
                                        $where = "{$table_name}.{$column_name} like '" . formatForSqlLike($search_string) . "'";
                                    }
                                }
                                break;
                            } else {
                                //if the mod strings cointains LBL , just return the original search string. Not the key
                                $where = "{$table_name}.{$column_name} like '" . formatForSqlLike($search_string) . "'";
                            }
                        }
                    } else {
                        if (getFieldVisibilityPermission("Calendar", $current_user->id, 'taskstatus') == '0' && ($table_name == "vtiger_activity" && ($column_name == "status" || $column_name == "eventstatus"))) {
                            $where = "(vtiger_activity.status like '" . formatForSqlLike($search_string) . "' or vtiger_activity.eventstatus like '" . formatForSqlLike($search_string) . "')";
                        } else {
                            $where = "{$table_name}.{$column_name} like '" . formatForSqlLike($search_string) . "'";
                        }
                    }
                }
            } elseif ($table_name == "vtiger_crmentity" && $column_name == "smownerid") {
                $where = get_usersid($table_name, $column_name, $search_string);
            } elseif ($table_name == "vtiger_crmentity" && $column_name == "modifiedby") {
                $concatSql = getSqlForNameInDisplayFormat(array('last_name' => 'vtiger_users2.last_name', 'first_name' => 'vtiger_users2.first_name'), 'Users');
                $where .= "(trim({$concatSql}) like '" . formatForSqlLike($search_string) . "' or vtiger_groups2.groupname like '" . formatForSqlLike($search_string) . "')";
            } else {
                if (in_array($column_name, $column_array)) {
                    $where = getValuesforColumns($column_name, $search_string, 'cts', $input);
                } else {
                    if ($input['type'] == 'entchar') {
                        $where = "{$table_name}.{$column_name} = '" . $search_string . "'";
                    } else {
                        $where = "{$table_name}.{$column_name} like '" . formatForSqlLike($search_string) . "'";
                    }
                }
            }
        }
    }
    if (stristr($where, "like '%%'")) {
        $where_cond0 = str_replace("like '%%'", "like ''", $where);
        $where_cond1 = str_replace("like '%%'", "is NULL", $where);
        if ($module == "Calendar") {
            $where = "(" . $where_cond0 . " and " . $where_cond1 . ")";
        } else {
            $where = "(" . $where_cond0 . " or " . $where_cond1 . ")";
        }
    }
    // commented to support searching "%" with the search string.
    if ($input['type'] == 'alpbt') {
        $where = str_replace_once("%", "", $where);
    }
    //uitype 10 handling
    if ($uitype == 10) {
        $where = array();
        $sql = "select fieldid from vtiger_field where tabid=? and fieldname=?";
        $result = $adb->pquery($sql, array(getTabid($module), $search_field));
        if ($adb->num_rows($result) > 0) {
            $fieldid = $adb->query_result($result, 0, "fieldid");
            $sql = "select * from vtiger_fieldmodulerel where fieldid=?";
            $result = $adb->pquery($sql, array($fieldid));
            $count = $adb->num_rows($result);
            $searchString = formatForSqlLike($search_string);
            for ($i = 0; $i < $count; $i++) {
                $relModule = $adb->query_result($result, $i, "relmodule");
                $relInfo = getEntityField($relModule);
                $relTable = $relInfo["tablename"];
                $relField = $relInfo["fieldname"];
                if (strpos($relField, 'concat') !== false) {
                    $where[] = "{$relField} like '{$searchString}'";
                } else {
                    $where[] = "{$relTable}.{$relField} like '{$searchString}'";
                }
            }
            $where = implode(" or ", $where);
        }
        $where = "({$where}) ";
    }
    $log->debug("Exiting BasicSearch method ...");
    return $where;
}
Beispiel #5
0
/**	function used to save the records into database
 *	@param array $rows - array of total rows of the csv file
 *	@param array $rows1 - rows to be saved
 *	@param object $focus - object of the corresponding import module
 *	@param int $ret_field_count - total number of fields(columns) available in the csv file
 *	@param int $col_pos_to_field - field position in the mapped array
 *	@param int $start - starting row count value to import
 *	@param int $recordcount - count of records to be import ie., number of records to import
 *	@param string $module - import module
 *	@param int $totalnoofrows - total number of rows available
 *	@param int $skip_required_count - number of records skipped
 This function will redirect to the ImportStep3 if the available records is greater than the record count (ie., number of records import in a single loop) otherwise (total records less than 500) then it will be redirected to import step last
 */
function InsertImportRecords($rows, $rows1, $focus, $ret_field_count, $col_pos_to_field, $start, $recordcount, $module, $totalnoofrows, $skip_required_count)
{
    global $current_user;
    global $adb;
    global $mod_strings;
    global $dup_ow_count;
    global $process_fields;
    $acc_config = Accounting::loadConfigParams();
    // MWC ** Getting vtiger_users
    $temp = get_user_array(FALSE);
    foreach ($temp as $key => $data) {
        $users_groups_list[$data] = $key;
    }
    $temp = get_group_array(FALSE);
    foreach ($temp as $key => $data) {
        $users_groups_list[$data] = $key;
    }
    p(print_r(users_groups_list, 1));
    $adb->println("Users List : ");
    $adb->println($users_groups_list);
    $dup_count = 0;
    $count = 0;
    $dup_ow_count = 0;
    $process_fields = 'false';
    if ($start == 0) {
        $_SESSION['totalrows'] = $rows;
        $_SESSION['return_field_count'] = $ret_field_count;
        $_SESSION['column_position_to_field'] = $col_pos_to_field;
    }
    $ii = $start;
    // go thru each row, process and save()
    $lastacc = "";
    $bMultiple = false;
    $rows2 = array();
    $payments = array();
    $sub = 0;
    $ref_idx = "";
    foreach ($col_pos_to_field as $idx => $fld) {
        if ($fld == "accounting_id") {
            $ref_idx = $idx;
            break;
        }
    }
    $ref_idx = 0;
    foreach ($rows1 as $row) {
        if (array_key_exists($row[0], $payments) == false) {
            $bMultiple = false;
        } else {
            $bMultiple = true;
        }
        /*
        		if ($row[0] == $lastacc) {
        			$bMultiple = true;
        		} else {
        			$bMultiple = false;
        		}
        
        		$lastacc = $row[0];
        */
        if ($bMultiple == false) {
            array_push($rows2, $row);
            $payments[$row[0]] = array();
        } else {
            $sub++;
        }
        $idx = 1;
        $paid = $row[$ret_field_count - $idx++];
        if ($acc_config["associnvoice"] == "true") {
            $associnv = $row[$ret_field_count - $idx++];
        }
        $paymentmethod = $row[$ret_field_count - $idx++];
        if ($acc_config["showvat"] == "true") {
            $tax = $row[$ret_field_count - $idx++];
        }
        $amount = $row[$ret_field_count - $idx++];
        $paymentdate = $row[$ret_field_count - $idx++];
        $paymentduedate = $row[$ret_field_count - $idx++];
        $ref = $row[$ret_field_count - $idx++];
        $invid = '';
        $assocmodule = '';
        $assocdisplay = '';
        if ($associnv != "") {
            //check the module of the field
            $arr = array();
            $arr = explode("::::", $associnv);
            $assocmodule = $arr[0];
            $assocdisplay = $arr[1];
            $focus1 = CRMEntity::getInstance($assocmodule);
            $entityNameArr = getEntityField($assocmodule);
            $entityName = $entityNameArr['fieldname'];
            $query = "SELECT vtiger_crmentity.deleted, {$focus1->table_name}.*\n\t\t\t\t\t\tFROM {$focus1->table_name}\n\t\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid={$focus1->table_name}.{$focus1->table_index}\n\t\t\t\t\t\t\twhere {$entityName}=? and vtiger_crmentity.deleted=0";
            $result = $adb->pquery($query, array($assocdisplay));
            $invid = $adb->query_result($result, 0, $focus1->table_index);
        }
        $payment = array('ref' => $ref, 'paymentduedate' => $paymentduedate, 'paymentdate' => $paymentdate, 'amount' => $amount, 'paymenttax' => $tax, 'paymentmethod' => $paymentmethod, 'associnv' => $invid, 'associnv_display' => $assocdisplay, 'paymentassoc_mod' => $assocmodule, 'paid' => $paid);
        array_push($payments[$row[0]], $payment);
    }
    $totalnoofrows -= $sub;
    $rows1 = $rows2;
    $recordcount = count($rows1);
    foreach ($rows1 as $row) {
        $adb->println("Going to Save the row " . $ii . " =====> ");
        $adb->println($row);
        global $mod_strings;
        $do_save = 1;
        //MWC
        $my_userid = $current_user->id;
        //If we want to set default values for some fields for each entity then we have to set here
        if ($module == 'Products' || $module == 'Services') {
            //discontinued is not null. if we unmap active, NULL will be inserted and query will fail
            $focus->column_fields['discontinued'] = 'on';
        }
        for ($field_count = 0; $field_count < $ret_field_count; $field_count++) {
            p("col_pos[" . $field_count . "]=" . $col_pos_to_field[$field_count]);
            if (isset($col_pos_to_field[$field_count])) {
                p("set =" . $field_count);
                if (!isset($row[$field_count])) {
                    continue;
                }
                p("setting");
                // TODO: add check for user input
                // addslashes, striptags, etc..
                $field = $col_pos_to_field[$field_count];
                //picklist function is added to avoid duplicate picklist entries
                $pick_orginal_val = getPicklist($field, $row[$field_count]);
                if ($pick_orginal_val != null) {
                    $focus->column_fields[$field] = $pick_orginal_val;
                } elseif ($field == "assignedto" || $field == "assigned_user_id") {
                    //Here we are assigning the user id in column fields, so in function assign_user (ImportLead.php and ImportProduct.php files) we should use the id instead of user name when query the user
                    //or we can use $focus->column_fields['smownerid'] = $users_groups_list[$row[$field_count]];
                    $imported_user = $current_user->id;
                    $q = "SELECT groupid FROM vtiger_groups WHERE groupname=?";
                    $res = $adb->pquery($q, array(trim($row[$field_count])));
                    if ($adb->num_rows($res) > 0) {
                        $imported_user = $adb->query_result($res, 0, "groupid");
                    } else {
                        $q = "SELECT id FROM vtiger_users WHERE user_name=?";
                        $res = $adb->pquery($q, array(trim($row[$field_count])));
                        if ($adb->num_rows($res) == 0) {
                            $imported_user = $adb->query_result($res, 0, "id");
                        }
                    }
                    $focus->column_fields[$field] = $imported_user;
                    p("setting my_userid={$my_userid} for user="******"Setting " . $field . "=" . $row[$field_count]);
                }
            }
        }
        if ($focus->column_fields['notify_owner'] == '') {
            $focus->column_fields['notify_owner'] = '0';
        }
        if ($focus->column_fields['reference'] == '') {
            $focus->column_fields['reference'] = '0';
        }
        if ($focus->column_fields['emailoptout'] == '') {
            $focus->column_fields['emailoptout'] = '0';
        }
        if ($focus->column_fields['donotcall'] == '') {
            $focus->column_fields['donotcall'] = '0';
        }
        if ($focus->column_fields['discontinued'] == '') {
            $focus->column_fields['discontinued'] = '0';
        }
        if ($focus->column_fields['active'] == '') {
            $focus->column_fields['active'] = '0';
        }
        p("setting done");
        p("do save before req vtiger_fields=" . $do_save);
        $adb->println($focus->required_fields);
        foreach ($focus->required_fields as $field => $notused) {
            $fv = trim($focus->column_fields[$field]);
            if (!isset($fv) || $fv == '') {
                // Leads Import does not allow an empty lastname because the link is created on the lastname
                // Without lastname the Lead could not be opened.
                // But what if the import file has only company and telefone information?
                // It would be stupid to skip all the companies which don't have a contact person yet!
                // So we set lastname ="?????" and the user can later enter a name.
                // So the lastname is still mandatory but may be empty.
                if ($field == 'lastname' && $module == 'Leads') {
                    $focus->column_fields[$field] = '?????';
                } else {
                    p("fv " . $field . " not set");
                    $do_save = 0;
                    $skip_required_count++;
                    break;
                }
            }
        }
        if (!isset($focus->column_fields["assigned_user_id"]) || $focus->column_fields["assigned_user_id"] === '' || $focus->column_fields["assigned_user_id"] === NULL) {
            $focus->column_fields["assigned_user_id"] = $my_userid;
        }
        //added for duplicate handling
        if (is_record_exist($module, $focus)) {
            if ($do_save != 0) {
                $do_save = 0;
                $dup_count++;
            }
        }
        p("do save=" . $do_save);
        if ($do_save) {
            p("saving..");
            if (!isset($focus->column_fields["assigned_user_id"]) || $focus->column_fields["assigned_user_id"] == '') {
                //$focus->column_fields["assigned_user_id"] = $current_user->id;
                //MWC
                $focus->column_fields["assigned_user_id"] = $my_userid;
            }
            //handle uitype 10
            foreach ($focus->importable_fields as $fieldname => $uitype) {
                $uitype = $focus->importable_fields[$fieldname];
                if ($uitype == 10) {
                    //added to handle security permissions for related modules :: for e.g. Accounts/Contacts in Potentials
                    if (method_exists($focus, "add_related_to")) {
                        if (!$focus->add_related_to($module, $fieldname)) {
                            if (array_key_exists($fieldname, $focus->required_fields)) {
                                $do_save = 0;
                                $skip_required_count++;
                                continue 2;
                            }
                        }
                    }
                }
            }
            // now do any special processing for ex., map account with contact and potential
            if ($process_fields == 'false') {
                $focus->process_special_fields();
            }
            $focus->saveentity($module);
            //$focus->saveentity($module);
            $return_id = $focus->id;
            // $focus->column_fields['accounting_id']
            $sql = "INSERT INTO vtiger_accounting_payments (idtransaction, amount," . ($acc_config["showvat"] == "true" ? "tax," : "") . " paymentduedate, paymentdate, paid, ref," . ($acc_config["associnvoice"] == "true" ? "associnv,assoc_display,assoc_mod," : "") . " paymentmethod) VALUES (" . ($acc_config["showvat"] == "true" ? "?," : "") . ($acc_config["associnvoice"] == "true" ? "?,?,?," : "") . "?, ?, ?, ?, ?, ?, ?)";
            foreach ($payments[$row[0]] as $payment) {
                if ($acc_config["associnvoice"] == "true" && $acc_config["showvat"] == "true") {
                    $data_arr = array($return_id, $payment['amount'], $payment['paymenttax'], $payment['paymentduedate'], $payment['paymentdate'], $payment['paid'], $payment['ref'], $payment['associnv'], $payment['associnv_display'], $payment['paymentassoc_mod'], $payment['paymentmethod']);
                } else {
                    if ($acc_config["associnvoice"] == "true" && $acc_config["showvat"] == "false") {
                        $data_arr = array($return_id, $payment['amount'], $payment['paymentduedate'], $payment['paymentdate'], $payment['paid'], $payment['ref'], $payment['associnv'], $payment['associnv_display'], $payment['paymentassoc_mod'], $payment['paymentmethod']);
                    } else {
                        if ($acc_config["associnvoice"] == "false" && $acc_config["showvat"] == "true") {
                            $data_arr = array($return_id, $payment['amount'], $payment['paymenttax'], $payment['paymentduedate'], $payment['paymentdate'], $payment['paid'], $payment['ref'], $payment['paymentmethod']);
                        } else {
                            if ($acc_config["associnvoice"] == "false" && $acc_config["showvat"] == "false") {
                                $data_arr = array($return_id, $payment['amount'], $payment['paymentduedate'], $payment['paymentdate'], $payment['paid'], $payment['ref'], $payment['paymentmethod']);
                            }
                        }
                    }
                }
                foreach ($data_arr as &$param) {
                    if (!isset($param)) {
                        $param = "";
                    }
                }
                $res = $adb->pquery($sql, $data_arr);
            }
            $last_import = new UsersLastImport();
            $last_import->assigned_user_id = $current_user->id;
            $last_import->bean_type = $_REQUEST['module'];
            $last_import->bean_id = $focus->id;
            $last_import->save();
            $count++;
        }
        $ii++;
    }
    $_REQUEST['count'] = $ii;
    if (isset($_REQUEST['module'])) {
        $modulename = vtlib_purify($_REQUEST['module']);
    }
    $end = $start + $recordcount;
    $START = $start + $recordcount;
    $RECORDCOUNT = $recordcount;
    $dup_check_type = $_REQUEST['dup_type'];
    $auto_dup_type = $_REQUEST['auto_type'];
    if ($end >= $totalnoofrows) {
        $module = 'Import';
        //$_REQUEST['module'];
        $action = 'ImportSteplast';
        //exit;
        $imported_records = $totalnoofrows - $skip_required_count;
        if ($imported_records == $totalnoofrows) {
            $skip_required_count = 0;
        }
        if ($dup_check_type == "auto") {
            if ($auto_dup_type == "ignore") {
                $dup_info = $mod_strings['Duplicate_Records_Skipped_Info'] . $dup_count;
                $imported_records -= $dup_count;
            } else {
                if ($auto_dup_type == "overwrite") {
                    $dup_info = $mod_strings['Duplicate_Records_Overwrite_Info'] . $dup_ow_count;
                    $imported_records -= $dup_ow_count;
                }
            }
        } else {
            $dup_info = "";
        }
        if ($imported_records < 0) {
            $imported_records = 0;
        }
        $message = urlencode("<b>" . $mod_strings['LBL_SUCCESS'] . "</b>" . "<br><br>" . $mod_strings['LBL_SUCCESS_1'] . "  {$imported_records} " . $mod_strings['of'] . ' ' . $totalnoofrows . "<br><br>" . $mod_strings['LBL_SKIPPED_1'] . "  {$skip_required_count} <br><br>" . $dup_info);
    } else {
        $module = 'Import';
        $action = 'ImportStep3';
    }
    ?>

<script>
setTimeout("b()",1000);
function b()
{
	document.location.href="index.php?action=<?php 
    echo $action;
    ?>
&module=<?php 
    echo $module;
    ?>
&modulename=<?php 
    echo $modulename;
    ?>
&startval=<?php 
    echo $end;
    ?>
&recordcount=<?php 
    echo $RECORDCOUNT;
    ?>
&noofrows=<?php 
    echo $totalnoofrows;
    ?>
&message=<?php 
    echo $message;
    ?>
&skipped_record_count=<?php 
    echo $skip_required_count;
    ?>
&parenttab=<?php 
    echo vtlib_purify($_SESSION['import_parenttab']);
    ?>
&dup_type=<?php 
    echo $dup_check_type;
    ?>
&auto_type=<?php 
    echo $auto_dup_type;
    ?>
";
}
</script>

<?php 
    $_SESSION['import_display_message'] = '<br>' . $start . ' ' . $mod_strings['to'] . ' ' . $end . ' ' . $mod_strings['of'] . ' ' . $totalnoofrows . ' ' . $mod_strings['are_imported_succesfully'];
    //return $_SESSION['import_display_message'];
}