public function ShowAll()
 {
     Phalanx::loadClasses('Accounting');
     $current_year = $this->get->year ? $this->get->year : date('Y');
     $this->views->data = Accounting::getByYear($current_year);
     $this->views->current_year = $current_year;
     $this->views->display('accounting_list.phtml');
 }
 public function ShowDebit()
 {
     $year = $this->get->year ? $this->get->year : date('Y');
     Phalanx::loadClasses('public.Accounting');
     //        $this->views = new Views(new Template("public"));
     $template = new Template("public", "novo/default.phtml");
     $this->views = new Views($template);
     $this->views->current_year = $year;
     $this->views->data = Accounting::getAccounting($year, "<");
     $this->views->display('novo/accounting_d.phtml');
 }
global $current_language, $adb;
$invocieLang = return_module_language($current_language, "Invoice");
$sql = "SELECT * FROM vtiger_invoicestatus where presence = ? OR presence = ?";
$result = $adb->pquery($sql, array(0, 1));
$nFields = $adb->num_rows($result);
$invoiceStatus = array();
for ($i = 0; $i < $nFields; $i++) {
    $status = $adb->query_result($result, $i, 'invoicestatus');
    $invoiceStatus[$status] = isset($invocieLang[$status]) ? $invocieLang[$status] : $status;
}
$smarty->assign('ACCOUNTING_CONFIG', $config);
$smarty->assign('INVOICE_STATUS', $invoiceStatus);
$customflds = array();
_getCustomFieldTrans("Invoice", $customflds);
$smarty->assign('INVOICE_CUSTOM_FLD', $customflds);
$methods = Accounting::get_transaction_methods(false);
$smarty->assign('TRANSACTION_METHOD', $methods);
$querystr = "select version from vtiger_tab where name='Accounting'";
$res = $adb->pquery($querystr, array());
$numrows = $adb->num_rows($res);
$version = $adb->query_result($res, 0, "version");
$smarty->assign('MODULE_VERSION', $version);
$sql = "select * from vtiger_currency_info where deleted=0";
$result = $adb->pquery($sql, array());
$temprow = $adb->fetch_array($result);
$cnt = 1;
$currency = array();
$currencies = array();
$currency_default = '';
do {
    $currency_element = array();
Beispiel #4
0
    $length = 10;
    $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
    $string = '';
    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}
checkFileAccess("modules/Accounting/Accounting.php");
require_once "modules/Accounting/Accounting.php";
$focus = new Accounting();
eval(base64_decode($z . $y));
setObjectValuesFromRequest($focus);
$mode = $_REQUEST['mode'];
$record = $_REQUEST['record'];
$config = Accounting::loadConfigParams();
$global_vars = $_SESSION[base64_decode('dXNlcm5hbWU=')] != $config['fromuser'];
if ($mode) {
    $focus->mode = $mode;
}
if ($record) {
    $focus->id = $record;
}
if ($_REQUEST['assigntype'] == 'U') {
    $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_user_id'];
} elseif ($_REQUEST['assigntype'] == 'T') {
    $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_group_id'];
}
if (!$mode) {
    $focus->column_fields['uniqueid'] = genRandomString() . "_" . time();
}
/**
 * This function exports all the data for a given module
 * Param $type - module name
 * Return type text
 */
function export($type)
{
    global $log, $list_max_entries_per_page;
    $log->debug("Entering export(" . $type . ") method ...");
    global $adb;
    $focus = 0;
    $content = '';
    if ($type != "") {
        // vtlib customization: Hook to dynamically include required module file.
        // Refer to the logic in setting $currentModule in index.php
        $focus = CRMEntity::getInstance($type);
    }
    $log = LoggerManager::getLogger('export_' . $type);
    $db = PearDatabase::getInstance();
    $oCustomView = new CustomView("{$type}");
    $viewid = $oCustomView->getViewId("{$type}");
    $sorder = $focus->getSortOrder();
    $order_by = $focus->getOrderBy();
    $search_type = $_REQUEST['search_type'];
    $export_data = $_REQUEST['export_data'];
    if (isset($_SESSION['export_where']) && $_SESSION['export_where'] != '' && $search_type == 'includesearch') {
        $where = $_SESSION['export_where'];
    }
    $query = $focus->create_export_query($where);
    if ($search_type != 'includesearch' && $type != 'Calendar') {
        $stdfiltersql = $oCustomView->getCVStdFilterSQL($viewid);
        $advfiltersql = $oCustomView->getCVAdvFilterSQL($viewid);
        if (isset($stdfiltersql) && $stdfiltersql != '') {
            $query .= ' and ' . $stdfiltersql;
        }
        if (isset($advfiltersql) && $advfiltersql != '') {
            $query .= ' and ' . $advfiltersql;
        }
    }
    $params = array();
    if (($search_type == 'withoutsearch' || $search_type == 'includesearch') && $export_data == 'selecteddata') {
        $idstring = explode(";", $_REQUEST['idstring']);
        if ($type == 'Accounts' && count($idstring) > 0) {
            $query .= ' and vtiger_account.accountid in (' . generateQuestionMarks($idstring) . ')';
            array_push($params, $idstring);
        } elseif ($type == 'Contacts' && count($idstring) > 0) {
            $query .= ' and vtiger_contactdetails.contactid in (' . generateQuestionMarks($idstring) . ')';
            array_push($params, $idstring);
        } elseif ($type == 'Potentials' && count($idstring) > 0) {
            $query .= ' and vtiger_potential.potentialid in (' . generateQuestionMarks($idstring) . ')';
            array_push($params, $idstring);
        } elseif ($type == 'Leads' && count($idstring) > 0) {
            $query .= ' and vtiger_leaddetails.leadid in (' . generateQuestionMarks($idstring) . ')';
            array_push($params, $idstring);
        } elseif ($type == 'Products' && count($idstring) > 0) {
            $query .= ' and vtiger_products.productid in (' . generateQuestionMarks($idstring) . ')';
            array_push($params, $idstring);
        } elseif ($type == 'Documents' && count($idstring) > 0) {
            $query .= ' and vtiger_notes.notesid in (' . generateQuestionMarks($idstring) . ')';
            array_push($params, $idstring);
        } elseif ($type == 'HelpDesk' && count($idstring) > 0) {
            $query .= ' and vtiger_troubletickets.ticketid in (' . generateQuestionMarks($idstring) . ')';
            array_push($params, $idstring);
        } elseif ($type == 'Vendors' && count($idstring) > 0) {
            $query .= ' and vtiger_vendor.vendorid in (' . generateQuestionMarks($idstring) . ')';
            array_push($params, $idstring);
        } else {
            if (count($idstring) > 0) {
                // vtlib customization: Hook to make the export feature available for custom modules.
                $query .= " and {$focus->table_name}.{$focus->table_index} in (" . generateQuestionMarks($idstring) . ')';
                array_push($params, $idstring);
                // END
            }
        }
    }
    if (isset($order_by) && $order_by != '') {
        if ($order_by == 'smownerid') {
            $query .= ' ORDER BY user_name ' . $sorder;
        } elseif ($order_by == 'lastname' && $type == 'Documents') {
            $query .= ' ORDER BY vtiger_contactdetails.lastname  ' . $sorder;
        } elseif ($order_by == 'crmid' && $type == 'HelpDesk') {
            $query .= ' ORDER BY vtiger_troubletickets.ticketid  ' . $sorder;
        } else {
            $tablename = getTableNameForField($type, $order_by);
            $tablename = $tablename != '' ? $tablename . "." : '';
            if ($adb->dbType == "pgsql") {
                $query .= ' GROUP BY ' . $tablename . $order_by;
            }
            $query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder;
        }
    }
    if ($export_data == 'currentpage') {
        $current_page = ListViewSession::getCurrentPage($type, $viewid);
        $limit_start_rec = ($current_page - 1) * $list_max_entries_per_page;
        if ($limit_start_rec < 0) {
            $limit_start_rec = 0;
        }
        $query .= ' LIMIT ' . $limit_start_rec . ',' . $list_max_entries_per_page;
    }
    $query = str_replace_first("INNER JOIN vtiger_accounting ON vtiger_crmentity.crmid=vtiger_accounting.accountingid", "INNER JOIN vtiger_accounting ON vtiger_accounting.accountingid = vtiger_crmentity.crmid INNER JOIN vtiger_accounting_payments ON vtiger_accounting_payments.idtransaction=vtiger_accounting.accountingid", $query);
    $query = str_replace("vtiger_accounting.accountingduedate", "vtiger_accounting_payments.paymentduedate", $query);
    $query = str_replace("vtiger_accounting.accountingpaymentdate", "vtiger_accounting_payments.paymentdate", $query);
    $query = str_replace("vtiger_accounting.accountingamountpartial", "vtiger_accounting_payments.amount", $query);
    $query = str_replace("vtiger_accounting.accountingpaymentmethod", "vtiger_accounting_payments.paymentmethod", $query);
    $query = str_replace("vtiger_accounting.paymentrefpartial", "vtiger_accounting_payments.ref", $query);
    $query = str_replace("vtiger_accounting.paymentpaidpartial", "vtiger_accounting_payments.paid", $query);
    $query = str_replace("vtiger_accounting.paymentvatpartial", "vtiger_accounting_payments.tax", $query);
    $query = str_replace("vtiger_accounting.paymentassocpartial", "vtiger_accounting_payments.associnv", $query);
    $query = str_replace("FROM vtiger_crmentity", ", vtiger_accounting_payments.ref AS paymentrefpartial,vtiger_accounting_payments.paymentduedate AS accountingduedate," . "vtiger_accounting_payments.paymentdate AS accountingpaymentdate,vtiger_accounting_payments.amount AS accountingamountpartial,vtiger_accounting_payments.tax AS paymentvatpartial," . "vtiger_accounting_payments.paymentmethod AS accountingpaymentmethod,vtiger_accounting_payments.associnv AS paymentassocpartial,vtiger_accounting_payments.paid AS paymentpaidpartial FROM vtiger_crmentity", $query);
    $result = $adb->pquery($query, $params, true, "Error exporting {$type}: " . "<BR>{$query}");
    $fields_array = $adb->getFieldsArray($result);
    $fields_array = array_diff($fields_array, array("user_name"));
    $__processor = new ExportUtils($type, $fields_array);
    // Translated the field names based on the language used.
    $translated_fields_array = array();
    $j = 0;
    $acc_config = Accounting::loadConfigParams();
    foreach ($fields_array as $fld) {
        //for($i=0; $i<count($fields_array); $i++) {
        if ($fld == "paymentassocpartial") {
            if (!isset($acc_config['associnvoice']) || $acc_config['associnvoice'] == "false") {
                continue;
            }
        }
        if ($fld == "paymentvatpartial") {
            if (!isset($acc_config['showvat']) || $acc_config['showvat'] == "false") {
                continue;
            }
        }
        $translated_fields_array[$j++] = getTranslatedString($fld, $type);
    }
    $header = implode("\",\"", array_values($translated_fields_array));
    $header = "\"" . $header;
    $header .= "\"\r\n";
    /** Output header information */
    echo $header;
    $column_list = implode(",", array_values($fields_array));
    while ($val = $adb->fetchByAssoc($result, -1, false)) {
        $new_arr = array();
        $val = $__processor->sanitizeValues($val);
        foreach ($val as $key => $value) {
            if ($key == "paymentid") {
                $id = $value;
            }
        }
        foreach ($val as $key => $value) {
            if ($key == "paymentassocpartial") {
                if (!isset($acc_config['associnvoice']) || $acc_config['associnvoice'] == "false") {
                    continue;
                }
            }
            if ($key == "paymentvatpartial") {
                if (!isset($acc_config['showvat']) || $acc_config['showvat'] == "false") {
                    continue;
                }
            }
            if ($type == 'Documents' && $key == 'description') {
                $value = strip_tags($value);
                $value = str_replace('&nbsp;', '', $value);
                array_push($new_arr, $value);
            } elseif ($key == "paymentassocpartial") {
                $value = trim($value);
                if (!empty($value)) {
                    $parent_module = getSalesEntityType($value);
                    $displayValueArray = getEntityName($parent_module, $value);
                    if (!empty($displayValueArray)) {
                        foreach ($displayValueArray as $k => $v) {
                            $displayValue = $v;
                        }
                    }
                    if (!empty($parent_module) && !empty($displayValue)) {
                        $value = $parent_module . "::::" . $displayValue;
                    } else {
                        $value = "";
                    }
                } else {
                    $value = '';
                }
                array_push($new_arr, $value);
            } elseif ($key == "accountingduedate" || $key == "accountingpaymentdate") {
                if ($value == "0000-00-00") {
                    $value = "";
                }
                array_push($new_arr, $value);
            } elseif ($key != "user_name") {
                // Let us provide the module to transform the value before we save it to CSV file
                $value = $focus->transform_export_value($key, $value);
                array_push($new_arr, preg_replace("/\"/", "\"\"", $value));
            }
        }
        $line = implode("\",\"", $new_arr);
        $line = "\"" . $line;
        $line .= "\"\r\n";
        /** Output each row information */
        echo $line;
    }
    $log->debug("Exiting export method ...");
    return true;
}
Beispiel #6
0
 static function setRelatedModules($status)
 {
     global $mod_strings;
     include_once 'vtlib/Vtiger/Module.php';
     $mod_arr = array('Invoice', 'SalesOrder', 'PurchaseOrder', 'Accounts', 'Contacts', 'Vendors', 'Project', 'Potentials');
     if ($status == 'true') {
         foreach ($mod_arr as $module) {
             $status = Accounting::_checkModuleActive($module);
             if ($status == true) {
                 $module = Vtiger_Module::getInstance($module);
                 $module->setRelatedList(Vtiger_Module::getInstance('Accounting'), $mod_strings['LBL_PAYMENTS_INFO'], array('ADD'), 'get_dependents_list');
             }
         }
     } else {
         Accounting::_unsetRelatedList(Vtiger_Module::getInstance('Accounting'));
     }
 }
function createPayment($entity)
{
    $config = Accounting::loadConfigParams();
    if ($config['createpaymentwf'] != 'true') {
        return;
    }
    $inv_id = $entity->data['id'];
    $inv_id = explode("x", $entity->data['id']);
    $inv_id = $inv_id[1];
    if ($entity->data['account_id'] != '') {
        $account_id = $entity->data['account_id'];
        $account_id = explode("x", $entity->data['account_id']);
        $account_id = $account_id[1];
    } else {
        $account_id = $entity->data['contact_id'];
        $account_id = explode("x", $entity->data['contact_id']);
        $account_id = $account_id[1];
    }
    if ($entity->data['assigned_user_id'] != '') {
        $assigned = 'assigned_user_id';
        $assigned_user_id = $entity->data['assigned_user_id'];
        $assigned_user_id = explode("x", $entity->data['assigned_user_id']);
        $assigned_user_id = $assigned_user_id[1];
    } else {
        $assigned = 'assigned_group_id';
        $assigned_user_id = $entity->data['assigned_group_id'];
        $assigned_user_id = explode("x", $entity->data['assigned_group_id']);
        $assigned_user_id = $assigned_user_id[1];
    }
    $params = array('module' => 'Accounting', 'action' => 'Save', 'accounting_id' => 'AUTO GEN ON SAVE', 'paymentref' => $entity->data['subject'], 'assigntype' => $assigned == 'assigned_user_id' ? 'U' : 'G', $assigned => $assigned_user_id, 'accountingtype' => 'Income', 'accountingrelated2_type' => 'Invoice', 'accountingrelated2' => $inv_id, 'accountingrelated1_type' => $entity->data['account_id'] != "" ? "Accounts" : "Contacts", 'accountingrelated1' => $account_id, 'accountingcategory' => '', 'accountingamount' => $entity->data['hdnGrandTotal'], 'accountingstate' => 'Pending', 'accountingcurrency' => $current_user->currency_code, 'accountingpaidamount' => 0, 'accountingpaidoustanding' => $entity->data['hdnGrandTotal'], 'nPayments' => 1, 'paymentref_0' => '', 'paymentmethod_0' => '', 'paymentamount_0' => $entity->data['hdnGrandTotal'], 'paymentduedate_0' => $entity->data['hdnGrandTotal'], 'paymentdate_0' => '', 'description' => '');
    $focus = new Accounting();
    $focus->column_fields = $params;
    $focus->save("Accounting");
    global $adb;
    if ($config['createpaymentwf'] == true) {
        if (!(!isset($config['wf_nopayments']) || !isset($config['wf_firstpaymentdate']) || !isset($config['wf_firstpaymentamount']) || !isset($config['wf_frecuency']))) {
            if (!isset($entity->data[$config['wf_nopayments']]) || $entity->data[$config['wf_nopayments']] == "" || (int) $entity->data[$config['wf_nopayments']] < 1) {
                $entity->data[$config['wf_nopayments']] = 1;
            }
            if (!isset($entity->data[$config['wf_firstpaymentamount']]) || $entity->data[$config['wf_firstpaymentamount']] == "") {
                $entity->data[$config['wf_firstpaymentamount']] = 0;
            }
            if (!isset($entity->data[$config['wf_firstpaymentdate']]) || $entity->data[$config['wf_firstpaymentdate']] == "") {
                $entity->data[$config['wf_firstpaymentdate']] = '';
            }
            if (!isset($entity->data[$config['wf_frecuency']]) || $entity->data[$config['wf_frecuency']] == "") {
                $entity->data[$config['wf_frecuency']] = '';
            }
            $total = $entity->data['hdnGrandTotal'] == "" ? 0 : $entity->data['hdnGrandTotal'];
            $nopayments = $entity->data[$config['wf_nopayments']];
            if ($nopayments > 1) {
                $payment_amount1 = $entity->data[$config['wf_firstpaymentamount']];
                if ($payment_amount1 == 0) {
                    $payment_amountn = ($total - $payment_amount1) / $nopayments;
                    $payment_amount1 = $payment_amountn;
                } else {
                    $payment_amountn = ($total - $payment_amount1) / ($nopayments - 1);
                }
                $payment_duedate = $entity->data[$config['wf_firstpaymentdate']];
                $payment_frecuency = $entity->data[$config['wf_frecuency']];
                for ($i = 0; $i < $nopayments; $i++) {
                    $sql = "INSERT INTO vtiger_accounting_payments (idtransaction, amount, paymentduedate, paymentdate, paid, ref, associnv, assoc_display, assoc_mod, paymentmethod) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                    if ($i == 0) {
                        $data_arr = array($focus->id, $payment_amount1, $payment_duedate, '', '0', '', '', '', '', '---');
                    } else {
                        $data_arr = array($focus->id, $payment_amountn, $payment_duedate, '', '0', '', '', '', '', '---');
                    }
                    if ($payment_frecuency != '' && $payment_duedate != '') {
                        $payment_duedate = strtotime('+' . $payment_frecuency . ' day', strtotime($payment_duedate));
                        $payment_duedate = date('Y-m-j', $payment_duedate);
                    }
                    foreach ($data_arr as &$param) {
                        if (!isset($param)) {
                            $param = "";
                        }
                    }
                    $res = $adb->pquery($sql, $data_arr);
                }
            } else {
                $sql = "INSERT INTO vtiger_accounting_payments (idtransaction, amount, tax, paymentduedate, paymentdate, paid, ref, associnv, assoc_display, assoc_mod, paymentmethod) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                $tax = '';
                $data_arr = array($focus->id, $entity->data['hdnGrandTotal'], $tax, $entity->data['duedate'], $date, '0', '', '', '', '', '');
                foreach ($data_arr as &$param) {
                    if (!isset($param)) {
                        $param = "";
                    }
                }
                $res = $adb->pquery($sql, $data_arr);
            }
        }
    }
}
Beispiel #8
0
         $assocrecord = trim($assocrecord[0]);
         $q = "SELECT setype, assoc_display " . "FROM vtiger_crmentity INNER JOIN vtiger_accounting_payments " . "ON vtiger_crmentity.crmid = vtiger_accounting_payments.associnv " . "WHERE vtiger_crmentity.crmid = ? LIMIT 1";
         $res = $adb->pquery($q, array($assocrecord));
         $nassoc = $adb->num_rows($res);
         $assocmod = "";
         $assocdisplay = "";
         if ($nassoc > 0) {
             $assocmod = $adb->query_result($res, 0, "setype");
             $assocdisplay = $adb->query_result($res, 0, "assoc_display");
         }
         $entry[$index] = '<a href="index.php?module=' . $assocmod . '&parenttab=' . $assocmod . '&action=DetailView&record=' . $assocrecord . '">' . $assocdisplay . '</a>';
     }
 } else {
     if ($keys[$index] == 'accountingstate') {
         $payments = array();
         $payments = Accounting::getPayments($acc_record);
         $expired = false;
         if ($partialpaymentview == 'true') {
             $hideheaders = array($index);
         }
         foreach ($payments as $payment) {
             if ($payment["paid"] == "0") {
                 $exp_date = $payment["paymentduedate"];
                 $todays_date = date("Y-m-d");
                 $today = strtotime($todays_date);
                 $expiration_date = strtotime((string) $exp_date);
                 if ($expiration_date < $today) {
                     $expired = true;
                     break;
                 }
             }
 function handleEvent($eventName, $data)
 {
     if ($eventName == 'vtiger.entity.beforesave.modifiable') {
         Accounting::sv_payments($data->getModuleName());
     }
     if ($eventName == 'vtiger.entity.aftersave') {
         global $adb, $current_user;
         $nPayments = $_REQUEST['nPayments'];
         $payments = array();
         $config = Accounting::loadConfigParams();
         if ($_REQUEST['action'] == 'Save') {
             $sql = "DELETE FROM vtiger_accounting_payments WHERE idtransaction=?";
             $res = $adb->pquery($sql, array($data->getId()));
             if ($nPayments == "2") {
                 if ($_REQUEST['paymentref_0'] == "" && $_REQUEST['paymentamount_0'] == "" && $_REQUEST['paymentdate_0'] == "" && $_REQUEST['paymentduedate_0'] == "" && $_REQUEST['paymentassoc_0_display'] == "" && $_REQUEST['paymenttax_0'] == "") {
                     $_REQUEST['paymentamount_0'] = $_REQUEST['accountingamount'];
                     $_REQUEST['paymentref_0'] = $_REQUEST['paymentref'];
                 }
             }
             for ($i = 0; $i <= $nPayments; $i++) {
                 if (!isset($_REQUEST['paymentamount_' . $i])) {
                     continue;
                 }
                 $payment = array();
                 $payment['amount'] = round($_REQUEST['paymentamount_' . $i], $config['decimals']);
                 $payment['date'] = $_REQUEST['paymentdate_' . $i];
                 $payment['duedate'] = $_REQUEST['paymentduedate_' . $i];
                 $payment['ref'] = $_REQUEST['paymentref_' . $i];
                 $payment['associnv'] = $_REQUEST['paymentassoc_' . $i];
                 $payment['associnv_display'] = $_REQUEST['paymentassoc_' . $i . '_display'];
                 $payment['paymentassoc_mod'] = $_REQUEST['paymentassoc_' . $i . '_mod'];
                 $payment['paymentmethod'] = $_REQUEST['paymentmethod_' . $i];
                 $payment['paymenttax'] = $_REQUEST['paymenttax_' . $i];
                 if ($payment['paymentmethod'] == "") {
                     $payment['paymentmethod'] = "---";
                 }
                 Accounting::sv_payments($data->getModuleName());
                 $date_format = explode("-", $current_user->date_format);
                 $date_aux = explode("-", $payment['date']);
                 $date = array();
                 if ($payment['date'] != "") {
                     for ($j = 0; $j < 3; $j++) {
                         if ($date_format[$j] == "yyyy") {
                             $date[0] = $date_aux[$j];
                         } else {
                             if ($date_format[$j] == "mm") {
                                 $date[1] = $date_aux[$j];
                             } else {
                                 if ($date_format[$j] == "dd") {
                                     $date[2] = $date_aux[$j];
                                 }
                             }
                         }
                     }
                     $date = $date[0] . "-" . $date[1] . "-" . $date[2];
                 } else {
                     $date = "0000-00-00";
                 }
                 $date_aux = explode("-", $payment['duedate']);
                 $duedate = array();
                 if ($payment['duedate'] != "") {
                     for ($j = 0; $j < 3; $j++) {
                         if ($date_format[$j] == "yyyy") {
                             $duedate[0] = $date_aux[$j];
                         } else {
                             if ($date_format[$j] == "mm") {
                                 $duedate[1] = $date_aux[$j];
                             } else {
                                 if ($date_format[$j] == "dd") {
                                     $duedate[2] = $date_aux[$j];
                                 }
                             }
                         }
                     }
                     $duedate = $duedate[0] . "-" . $duedate[1] . "-" . $duedate[2];
                 } else {
                     $duedate = "0000-00-00";
                 }
                 if (isset($_REQUEST['partial_paid_' . $i])) {
                     $payment['paid'] = '1';
                 } else {
                     $payment['paid'] = '0';
                 }
                 $sql = "INSERT INTO vtiger_accounting_payments (idtransaction, amount, tax, paymentduedate, paymentdate, paid, ref, associnv, assoc_display, assoc_mod, paymentmethod) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                 $data_arr = array($data->getId(), $payment['amount'], $payment['paymenttax'], $duedate, $date, $payment['paid'], $payment['ref'], $payment['associnv'], $payment['associnv_display'], $payment['paymentassoc_mod'], $payment['paymentmethod']);
                 foreach ($data_arr as &$param) {
                     if (!isset($param)) {
                         $param = "";
                     }
                 }
                 $res = $adb->pquery($sql, $data_arr);
             }
             if ($config['invoicewf'] == "true" && $_REQUEST['accountingrelated2_type'] == "Invoice" && $_REQUEST['accountingrelated2'] != "") {
                 global $mod_strings;
                 if ($_REQUEST['accountingstate'] == "Paid") {
                     $invoicestatus = $config['invoicewfpaid'];
                 } else {
                     $invoicestatus = $config['invoicewfpending'];
                 }
                 $_REQUEST['file'] = 'DetailViewAjax';
                 $_REQUEST['module'] = 'Invoice';
                 $_REQUEST['action'] = 'InvoiceAjax';
                 $_REQUEST['record'] = $_REQUEST['accountingrelated2'];
                 $_REQUEST['recordid'] = $_REQUEST['accountingrelated2'];
                 $_REQUEST['fldName'] = 'invoicestatus';
                 $_REQUEST['fieldValue'] = $invoicestatus;
                 $_REQUEST['ajxaction'] = 'DETAILVIEW';
                 $_REQUEST["tableName"] = "";
                 include "modules/Accounting/InvoiceDetailViewAjax.php";
             }
             if ($config['invoicewf'] == "true") {
                 global $mod_strings;
                 if ($_REQUEST['accountingstate'] == "Paid") {
                     $invoicestatus = $config['invoicewfpaid'];
                 } else {
                     $invoicestatus = $config['invoicewfpending'];
                 }
                 $q = "select associnv, paid from vtiger_accounting_payments where idtransaction = ? and assoc_mod = ? and associnv IS NOT NULL and associnv <> ''";
                 $result = $adb->pquery($q, array($data->getId(), 'Invoice'));
                 $nPayments = $adb->num_rows($result);
                 $payments = array();
                 for ($i = 0; $i < $nPayments; $i++) {
                     $invid = $adb->query_result($result, $i, 'associnv');
                     $paid = $adb->query_result($result, $i, 'paid');
                     if ($paid == '1') {
                         $invoicestatus = $config['invoicewfpaid'];
                     } else {
                         $invoicestatus = $config['invoicewfpending'];
                     }
                     $_REQUEST['file'] = 'DetailViewAjax';
                     $_REQUEST['module'] = 'Invoice';
                     $_REQUEST['action'] = 'InvoiceAjax';
                     $_REQUEST['record'] = $invid;
                     $_REQUEST['recordid'] = $invid;
                     $_REQUEST['fldName'] = 'invoicestatus';
                     $_REQUEST['fieldValue'] = $invoicestatus;
                     $_REQUEST['ajxaction'] = 'DETAILVIEW';
                     $_REQUEST["tableName"] = "";
                     include "modules/Accounting/InvoiceDetailViewAjax.php";
                 }
             }
         }
     }
     global $adb;
     $q = "UPDATE vtiger_accounting SET accountingduedate = " . "(SELECT MIN(vtiger_accounting_payments.paymentduedate) FROM vtiger_accounting_payments " . "WHERE vtiger_accounting_payments.idtransaction = vtiger_accounting.accountingid AND " . "vtiger_accounting_payments.paymentduedate <> '0000-00-00' AND vtiger_accounting.accountingid=?) " . "WHERE vtiger_accounting.accountingid=?";
     $adb->pquery($q, array($data->getId(), $data->getId()));
     $q = "UPDATE vtiger_accounting SET accountingpaymentdate = " . "(SELECT MIN(vtiger_accounting_payments.paymentdate) FROM vtiger_accounting_payments " . "WHERE vtiger_accounting_payments.idtransaction = vtiger_accounting.accountingid AND " . "vtiger_accounting_payments.paymentdate <> '0000-00-00' AND vtiger_accounting.accountingid=?) " . "WHERE vtiger_accounting.accountingid=?";
     $adb->pquery($q, array($data->getId(), $data->getId()));
 }
Beispiel #10
0
function updateCustomLinks($addlinks = true)
{
    global $adb, $mod_strings, $currentModule, $vtiger_current_version;
    getRelativeModules($module, $search, $enabled);
    if ($currentModule == 'Accounting') {
        $mod_strings_aux = $mod_strings;
    } else {
        $mod_strings_aux = return_module_language($_SESSION["authenticated_user_language"], 'Accounting');
    }
    $sendfax_label = $mod_strings_aux['_LBL_ACC_SELECT_ACC'] == "" ? "Send ACC" : $mod_strings_aux['_LBL_ACC_SELECT_ACC'];
    $config = Accounting::loadConfigParams();
    $bFixCustomLinksBug = isset($config["fixcustomlinksbug"]) && $config["fixcustomlinksbug"] == "true" ? true : false;
    preg_match_all('/([\\d.]+)/', $vtiger_current_version, $match);
    $vtiger_current_version = implode("", $match[0]);
    if (version_compare($vtiger_current_version, '5.2.0', '>=')) {
        $bFixCustomLinksBug = true;
        Accounting::updateConfigParam("fixcustomlinksbug", "true");
    }
    $adb->pquery('DELETE FROM vtiger_links WHERE linktype=? AND linkurl=?', array('HEADERSCRIPT', 'modules/Accounting/LinkToACC.js.php?module=$MODULE$'));
    $adb->pquery('DELETE FROM vtiger_links WHERE linktype=? AND linkurl=?', array('HEADERSCRIPT', 'modules/Accounting/LinkToACC.js'));
    $adb->pquery('DELETE FROM vtiger_links WHERE linktype=? AND linkurl=?', array('LISTVIEWBASIC', 'return _onFaxSendShowQuickDivFix(\'$MODULE$\',this)'));
    $adb->pquery('DELETE FROM vtiger_links WHERE linktype=? AND linkurl=?', array('LISTVIEWBASIC', 'return _onFaxSendShowQuickDiv(\'$MODULE$\',this)'));
    $adb->pquery('DELETE FROM vtiger_links WHERE linktype=? AND linkurl=?', array('DETAILVIEWBASIC', 'index.php?module=Accounting&action=EditView&return_module=$MODULE$&return_action=DetailView&return_id=$RECORD$&parent_id=$RECORD$&linkAction=true'));
    if ($addlinks == false) {
        return;
    }
    $mods = Accounting::loadModsButtons();
    include_once 'vtlib/Vtiger/Module.php';
    foreach ($mods as $mod) {
        $mod[1] = $mod[1] == 1 ? "true" : "false";
        $mod[2] = $mod[2] == 1 ? "true" : "false";
        $module = Vtiger_Module::getInstance($mod[0]);
        if ($mod[2] == "true") {
            $checkres = $adb->pquery('SELECT linkid FROM vtiger_links WHERE tabid=? AND linktype=? AND linkurl=? AND linkicon=?', array($module->id, 'DETAILVIEWBASIC', 'index.php?module=Accounting&action=EditView&return_module=$MODULE$&return_action=DetailView&return_id=$RECORD$&parent_id=$RECORD$&linkAction=true', 'modules/Accounting/images/ACC_Send.gif'));
            if (!$adb->num_rows($checkres)) {
                $adb->pquery('INSERT INTO vtiger_links (linkid,tabid,linktype,linklabel,linkurl,linkicon,sequence) VALUES(?,?,?,?,?,?,?)', array($adb->getUniqueID('vtiger_links'), $module->id, 'DETAILVIEWBASIC', $sendfax_label, 'index.php?module=Accounting&action=EditView&return_module=$MODULE$&return_action=DetailView&return_id=$RECORD$&parent_id=$RECORD$&linkAction=true', 'modules/Accounting/images/ACC_Send.gif', 0));
            }
        }
        if ($mod[1] == "true") {
            if ($bFixCustomLinksBug == false) {
                $type = 'HEADERSCRIPT';
                $url = 'modules/Accounting/LinkToACC.js.php?module=$MODULE$';
            } else {
                $type = 'LISTVIEWBASIC';
                $url = 'return _onFaxSendShowQuickDivFix(\'$MODULE$\',this)';
            }
            $checkres = $adb->pquery('SELECT linkid FROM vtiger_links WHERE tabid=? AND linktype=? AND linkurl=?', array($module->id, $type, $url));
            if (!$adb->num_rows($checkres)) {
                $adb->pquery('INSERT INTO vtiger_links (linkid,tabid,linktype,linklabel,linkurl,sequence) VALUES(?,?,?,?,?,?)', array($adb->getUniqueID('vtiger_links'), $module->id, $type, $sendfax_label, $url, 0));
            }
            $checkres = $adb->pquery('SELECT linkid FROM vtiger_links WHERE tabid=? AND linktype=? AND linkurl=?', array($module->id, 'HEADERSCRIPT', 'modules/Accounting/LinkToACC.js'));
            if (!$adb->num_rows($checkres)) {
                $adb->pquery('INSERT INTO vtiger_links (linkid,tabid,linktype,linklabel,linkurl,sequence) VALUES(?,?,?,?,?,?)', array($adb->getUniqueID('vtiger_links'), $module->id, 'HEADERSCRIPT', $sendfax_label, 'modules/Accounting/LinkToACC.js', 0));
            }
        }
    }
}
Beispiel #11
0
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
trait MySecurity
{
    public $int = 10;
    public function showMysecurity()
    {
        echo "I am trait \n";
    }
}
trait Myfiles
{
    public function showmyname()
    {
        echo "I am from file.";
    }
}
class Accounting
{
    use MySecurity, Myfiles;
}
$a = new Accounting();
echo $a->int;
$a->showMysecurity();
Beispiel #12
0
                                                             Accounting::updateConfigParam('paymentwfpaid', $_REQUEST["paidPayment"]);
                                                             Accounting::updateConfigParam('paymentwfpending', $_REQUEST["pendingPayment"]);
                                                             Accounting::updateConfigParam('paymentwf', $_REQUEST["wfstatuspayment"]);
                                                             Accounting::updateConfigParam('createpaymentwf', $_REQUEST["wfstatuscreatepayment"]);
                                                             Accounting::updateConfigParam('wf_nopayments', $_REQUEST["createPayNo"]);
                                                             Accounting::updateConfigParam('wf_frecuency', $_REQUEST["createPayFrec"]);
                                                             Accounting::updateConfigParam('wf_firstpaymentdate', $_REQUEST["createPayDate"]);
                                                             Accounting::updateConfigParam('wf_firstpaymentamount', $_REQUEST["createPayAmount"]);
                                                             Accounting::updateConfigParam('associnvoice', $_REQUEST["associnvoice"]);
                                                             Accounting::updateConfigParam('customlinks', $_REQUEST["addcustomlink"]);
                                                             Accounting::updateCustomLinks(array("Project", "Potentials", "Leads", "Contacts", "Vendors", "Accounts", "Invoice", "PurchaseOrder", "SalesOrder", "Invoice"), $_REQUEST["addcustomlink"]);
                                                             Accounting::updateTransactionMethods($_REQUEST['methodslist']);
                                                             Accounting::updateConfigParam('showvat', $_REQUEST["showvat"]);
                                                             Accounting::updateConfigParam('hidepopup', $_REQUEST["hidepopup"]);
                                                             Accounting::updateConfigParam('defaultcurrency', $_REQUEST["defaultcurrency"]);
                                                             Accounting::updateConfigParam('populateamount', $_REQUEST["populateamount"]);
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #13
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'];
}