403Webshell
Server IP : 103.234.187.230  /  Your IP : 216.73.216.216
Web Server : Apache
System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/b2bzend/application/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/b2bzend/application/models/TblVisa.php
<?php

require_once('BaseModel.php');

class Travel_Model_TblVisa extends BaseModel {

    protected $db = NULL;
    public $intId = NULL;
    public $strCondition = NULL;
    public $searchArr = NULL;
    public $searchActivitiesArr = NULL;
    public $baseUrl;

    /*     * ************************************ */

    public function __construct() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $this->baseUrl = $request->getScheme() . '://' . $request->getHttpHost();
        $this->db = Zend_Db_Table::getDefaultAdapter();
    }

    public function __destruct() {
        $this->db->closeConnection();
    }

    public function addVisa($ICSourceSysId) {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            $post = $request->getPost();

            $CreateDate = date('Y-m-d H:i:s');
            $countries_covered = isset($post['countries_covered']) && !empty($post['countries_covered']) ? $post['countries_covered'] : '';
            $visa_name = isset($post['visa_name']) && !empty($post['visa_name']) ? $post['visa_name'] : '';
            $visa_required = isset($post['visa_required']) && !empty($post['visa_required']) ? $post['visa_required'] : '';
            $visa_category = isset($post['visa_category']) && !empty($post['visa_category']) ? $post['visa_category'] : '0';
            $visa_type = isset($post['visa_type']) && !empty($post['visa_type']) ? $post['visa_type'] : '0';
            $validity = isset($post['validity']) && !empty($post['validity']) ? $post['validity'] : '0';
            $duration = isset($post['duration']) && !empty($post['duration']) ? $post['duration'] : '0';
            $adult = isset($post['adult']) && !empty($post['adult']) ? $post['adult'] : '0';
            $child = isset($post['child']) && !empty($post['child']) ? $post['child'] : '0';
            $infant = isset($post['infant']) && !empty($post['infant']) ? $post['infant'] : '0';
            $familyOf4 = isset($post['familyOf4']) && !empty($post['familyOf4']) ? $post['familyOf4'] : '0';
            $VisaRatesSysId = isset($post['VisaRatesSysId']) && !empty($post['VisaRatesSysId']) ? $post['VisaRatesSysId'] : '';
            $visa_id = isset($post['visa_id']) && !empty($post['visa_id']) ? $post['visa_id'] : '';

            try {
                if ($countries_covered) { //country cover loop start;
                    foreach ($countries_covered as $ky => $vl) {
                        if ($visa_name) {
                            foreach ($visa_name as $key => $value) {
                                $insert = array(
                                    'ICSourceSysId' => $ICSourceSysId,
                                    'IsAgentSpec' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? $ICSourceSysId : '0',
                                    'NationalitySysId' => $post['selectNationality'],
                                    'CountriesCoveredSysId' => $countries_covered[$ky],
                                    'VisaName' => $value,
                                    'VisaRequired' => $visa_required[$key],
                                    'VisaCategory' => $visa_category[$key],
                                    'VisaType' => $visa_type[$key],
                                    'VisaValidity' => $validity[$key],
                                    'VisaDuration' => $duration[$key],
                                    'VisaAdultRates' => $adult[$key],
                                    'VisaChildRates' => $child[$key],
                                    'VisaInfantRates' => $infant[$key],
                                    'VisaFamilyOfRates' => $familyOf4[$key],
                                    'CreateDate' => $CreateDate,
                                    'UpdateDate' => $CreateDate,
                                    'ApproveDate' => $CreateDate,
                                    'IsActive' => 1,
                                    'IsApproved' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? 0 : 1,
                                    'IsMarkForDel' => 0
                                );

                                if (!empty($VisaRatesSysId) && array_key_exists($key, $VisaRatesSysId)) {
                                    $where = array('VisaSysId = ? ' => $VisaRatesSysId[$key]);
                                    $this->db->update('TB_IC_Visa', $insert, $where);
                                } else {
                                    $this->db->insert('TB_IC_Visa', $insert);
                                    //$this->db->insert('TB_MP_Inventory_Visa', $insert);
                                }
                            }
                        }
                    }
                }//country cover loop end;
                return true;
            } catch (Exception $e) {
                die('There has been an error. ' . $e->getMessage());
            }
            return 0;
            //echo '<pre>';print_r($post);
        }
    }

    public function addVisaAgent($ICSourceSysId) {
        $TblAgency = new Travel_Model_TblAgency();
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            $post = $request->getPost();
//            echo "<pre>";print_r($post);exit;
            $countries_covered = isset($post['countries_covered']) && !empty($post['countries_covered']) ? $post['countries_covered'] : '';

            $CreateDate = date('Y-m-d H:i:s');
            $visa_name = isset($post['visa_name']) && !empty($post['visa_name']) ? $post['visa_name'] : '';
            $visa_required = isset($post['visa_required']) && !empty($post['visa_required']) ? $post['visa_required'] : '';
            $visa_category = isset($post['visa_category']) && !empty($post['visa_category']) ? $post['visa_category'] : '0';
            $visa_type = isset($post['visa_type']) && !empty($post['visa_type']) ? $post['visa_type'] : '0';
            $precessing_time = isset($post['precessing_time']) && !empty($post['precessing_time']) ? $post['precessing_time'] : '';
            $passport_expire_days = isset($post['passport_expire']) && !empty($post['passport_expire']) ? $post['passport_expire'] : '';
            $validity = isset($post['validity']) && !empty($post['validity']) ? $post['validity'] : '0';
            $duration = isset($post['duration']) && !empty($post['duration']) ? $post['duration'] : '0';
            $adult = isset($post['adult']) && !empty($post['adult']) ? $post['adult'] : '0';
            $CurrencyTypeMarkup = isset($post['markup_currency_typeid']) && !empty($post['markup_currency_typeid']) ? $post['markup_currency_typeid'] : '';
            $child = isset($post['child']) && !empty($post['child']) ? $post['child'] : '0';
            $childAge = isset($post['child']) && !empty($post['childAge']) ? $post['childAge'] : '0';
            $childFamily = isset($post['childFamily']) && !empty($post['childFamily'] && $countries_covered[0] == '228' && count($countries_covered) == 1) ? $post['childFamily'] : array();
            $infant = isset($post['infant']) && !empty($post['infant']) ? $post['infant'] : '0';
            $familyOf4 = isset($post['familyOf4']) && !empty($post['familyOf4']) ? $post['familyOf4'] : '0';
            $InvnVisaAllSysId = isset($post['InvnVisaAllSysId']) && !empty($post['InvnVisaAllSysId']) ? $post['InvnVisaAllSysId'] : '';
            $visa_id = isset($post['visa_id']) && !empty($post['visa_id']) ? $post['visa_id'] : '';
            $AgentSysId = isset($post['AgentSysId']) && !empty($post['AgentSysId']) ? $post['AgentSysId'] : 0;
            $AgencySysId = $ICSourceSysId;
            $SupplierSysId = isset($post['supplierSysId']) && !empty($post['supplierSysId']) ? $post['supplierSysId'] : 0;
            $CurrencyType = isset($post['currency_type']) && !empty($post['currency_type']) ? $post['currency_type'] : '';
            $DocsRequiredText = isset($post['docs_message']) && !empty($post['docs_message']) ? $post['docs_message'] : '';
            $basic_requirementsText = isset($post['basic_requirements']) && !empty($post['basic_requirements']) ? $post['basic_requirements'] : '';
            $embassy_addressText = isset($post['embassy_address']) && !empty($post['embassy_address']) ? $post['embassy_address'] : '';
            $docs_name1 = isset($post['docs_name_1']) && !empty($post['docs_name_1']) ? $post['docs_name_1'] : '';
            $docs_name2 = isset($post['docs_name_2']) && !empty($post['docs_name_2']) ? $post['docs_name_2'] : '';
            $docs_name3 = isset($post['docs_name_3']) && !empty($post['docs_name_3']) ? $post['docs_name_3'] : '';
            $docs_name4 = isset($post['docs_name_4']) && !empty($post['docs_name_4']) ? $post['docs_name_4'] : '';
            $docs_name5 = isset($post['docs_name_5']) && !empty($post['docs_name_5']) ? $post['docs_name_5'] : '';
            $docs_name6 = isset($post['docs_name_6']) && !empty($post['docs_name_6']) ? $post['docs_name_6'] : '';
            $file1 = isset($_FILES['docs_data_1']) && !empty($_FILES['docs_data_1']) ? $_FILES['docs_data_1'] : '';
            $file2 = isset($_FILES['docs_data_2']) && !empty($_FILES['docs_data_2']) ? $_FILES['docs_data_2'] : '';
            $file3 = isset($_FILES['docs_data_3']) && !empty($_FILES['docs_data_3']) ? $_FILES['docs_data_3'] : '';
            $file4 = isset($_FILES['docs_data_4']) && !empty($_FILES['docs_data_4']) ? $_FILES['docs_data_4'] : '';
            $file5 = isset($_FILES['docs_data_5']) && !empty($_FILES['docs_data_5']) ? $_FILES['docs_data_5'] : '';
            $file6 = isset($_FILES['docs_data_6']) && !empty($_FILES['docs_data_6']) ? $_FILES['docs_data_6'] : '';
            $IsActive = isset($post['status']) ? $post['status'] : 1;
            $docs_file_delete_1 = isset($post['docs_file_delete_1']) && !empty($post['docs_file_delete_1']) ? $post['docs_file_delete_1'] : 0;
            $docs_file_delete_2 = isset($post['docs_file_delete_2']) && !empty($post['docs_file_delete_2']) ? $post['docs_file_delete_2'] : 0;
            $docs_file_delete_3 = isset($post['docs_file_delete_3']) && !empty($post['docs_file_delete_3']) ? $post['docs_file_delete_3'] : 0;
            $docs_file_delete_4 = isset($post['docs_file_delete_4']) && !empty($post['docs_file_delete_4']) ? $post['docs_file_delete_4'] : 0;
            $docs_file_delete_5 = isset($post['docs_file_delete_5']) && !empty($post['docs_file_delete_5']) ? $post['docs_file_delete_5'] : 0;
            $docs_file_delete_6 = isset($post['docs_file_delete_6']) && !empty($post['docs_file_delete_6']) ? $post['docs_file_delete_6'] : 0;
            $DocumentSubmission = isset($post['DocumentSubmission']) && !empty($post['DocumentSubmission']) ? $post['DocumentSubmission'] : 0;
            $PhysicalInterview = isset($post['PhysicalInterview']) && !empty($post['PhysicalInterview']) ? $post['PhysicalInterview'] : 0;
            //echo "<pre>";print_r($_FILES);die;
            try {
                if ($countries_covered) { //country cover loop start;
                    foreach ($countries_covered as $ky => $vl) {
                        if ($visa_name) {
                            $count = 1;
                            $folder = USER_FILE_UPLOAD_PATH . 'agency/' . $AgencySysId . "/";
                            foreach ($visa_name as $key => $value) {
                                $service_provider_title = isset($post['service_provider_title_' . ($key + 1)]) && !empty($post['service_provider_title_' . ($key + 1)]) ? json_decode($post['service_provider_title_' . ($key + 1)], 1) : '';
                                $service_provider_fees = isset($post['service_provider_fees_' . ($key + 1)]) && !empty($post['service_provider_fees_' . ($key + 1)]) ? json_decode($post['service_provider_fees_' . ($key + 1)], 1) : '';
                                $service_provider_currency_type = isset($post['service_provider_currency_type_' . ($key + 1)]) && !empty($post['service_provider_currency_type_' . ($key + 1)]) ? json_decode($post['service_provider_currency_type_' . ($key + 1)], 1) : '';
                                $service_provider_IsTaxable = isset($post['service_provider_IsTaxable_' . ($key + 1)]) && !empty($post['service_provider_IsTaxable_' . ($key + 1)]) ? json_decode($post['service_provider_IsTaxable_' . ($key + 1)], 1) : '';
                                $service_provider_IsDisplay = isset($post['service_provider_IsDisplay_' . ($key + 1)]) && !empty($post['service_provider_IsDisplay_' . ($key + 1)]) ? json_decode($post['service_provider_IsDisplay_' . ($key + 1)], 1) : '';
                                $service_provider_MarkUp = isset($post['service_provider_MarkUp_' . ($key + 1)]) && !empty($post['service_provider_MarkUp_' . ($key + 1)]) ? json_decode($post['service_provider_MarkUp_' . ($key + 1)], 1) : '';

                                $insert = array(
                                    'ICSourceSysId' => $ICSourceSysId,
                                    'AgentSysId' => $AgentSysId,
                                    'IsAgentSpec' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? $ICSourceSysId : '0',
                                    'NationalitySysId' => 0,
                                    'CountriesCoveredSysId' => $countries_covered[$ky],
                                    'VisaName' => $value,
                                    'VisaRequired' => $visa_required[$key],
                                    'VisaCategory' => $visa_category[$key],
                                    'VisaType' => $visa_type[$key],
                                    'VisaValidity' => $validity[$key],
                                    'VisaDuration' => $duration[$key],
                                    'VisaAdultRates' => (int) $adult[$key],
                                    'VisaChildRates' => (int) $child[$key],
                                    'childAge' => (int) $childAge[$key],
                                    'VisaChildFamilyRates' => (int) $childFamily[$key],
                                    'VisaInfantRates' => (int) $infant[$key],
                                    'VisaFamilyOfRates' => $familyOf4[$key],
                                    'SupplierSysId' => $SupplierSysId,
                                    'CurrencyType' => $CurrencyTypeMarkup[$key],
                                    'DocsRequiredText' => ($DocsRequiredText[$key]),
                                    'DocName1' => $docs_name1[$key],
                                    //'DocFileName1' => $newFileName1,
                                    'DocName2' => $docs_name2[$key],
                                    //'DocFileName2' => $newFileName2,
                                    'DocName3' => $docs_name3[$key],
                                    'DocName4' => $docs_name4[$key],
                                    'DocName5' => $docs_name5[$key],
                                    'DocName6' => $docs_name6[$key],
                                    'CreateDate' => $CreateDate,
                                    'UpdateDate' => $CreateDate,
                                    'ApproveDate' => $CreateDate,
                                    'IsActive' => $IsActive,
                                    'IsApproved' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? 0 : 1,
                                    'IsMarkForDel' => 0,
                                    'PrecessingTime' => $precessing_time[$key],
                                    'PassportExpiryDays' => $passport_expire_days[$key],
                                    'BasicRequirementsText' => ($basic_requirementsText[$key]),
                                    'EmbassyAddressText' => ($embassy_addressText[$key]),
                                    'DocumentSubmission' => $DocumentSubmission,
                                    'PhysicalInterview' => $PhysicalInterview,
                                );
//                                echo "<pre>";print_r($insert);die;
                                if (!empty($InvnVisaAllSysId) && array_key_exists($key, $InvnVisaAllSysId)) {
                                    $where = array('InvnVisaAllSysId = ? ' => $InvnVisaAllSysId[$key]);
                                    $this->db->update('TB_MP_Inventory_Visa', $insert, $where);
                                    $lastInsertId = $InvnVisaAllSysId[$key];
                                    $this->db->update('TB_MP_Inventory_Visa_Country', array('IsMarkForDel' => 1), array('VisaInvnId = ? ' => $lastInsertId));
                                } else {
                                    $this->db->insert('TB_MP_Inventory_Visa', $insert);
                                    $lastInsertId = $this->db->lastInsertId('TB_MP_Inventory_Visa');
                                }

                                $selectNationality = isset($post['selectNationality']) ? $post['selectNationality'] : array();
                                $insertNationality = array();
                                if (!empty($selectNationality)) {
                                    foreach ($selectNationality as $snKey => $snVal) {
                                        $insertNationality = [
                                            'VisaInvnId' => $lastInsertId,
                                            'NationalitySysId' => $snVal,
                                            'IsActive' => 1,
                                            'IsMarkForDel' => 0,
                                        ];

                                        $this->db->insert('TB_MP_Inventory_Visa_Country', $insertNationality);
                                    }
                                }
                                //upload file
                                $visaDetails = $this->VisaInventoryDetailById($lastInsertId);
                                if ($docs_file_delete_1[$key] == 0) {
                                    $tmpFilePath1 = isset($file1['tmp_name'][0]) ? $file1['tmp_name'][0] : '';
                                    $fileName1 = isset($file1['name'][0]) ? $file1['name'][0] : '';
                                    //$newFileName1 = 'visa_file_1_' . $lastInsertId;

                                    $file_parts1 = !empty($fileName1) ? pathinfo($fileName1) : '';
                                    //print_r($file_parts1);die;
                                    $ext1 = isset($file_parts1['extension']) ? strtolower($file_parts1['extension']) : '';
                                    $newFileName1 = 'visa_document_1_' . $lastInsertId;
                                    if ($ext1 == 'pdf' || $ext1 == 'doc' || $ext1 == 'docx') {
                                        $newFileName1 = $newFileName1 . '.' . $ext1;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName1;
                                        $visaFile = array(
                                            'name' => $file1['name'][0],
                                            'type' => $file1['type'][0],
                                            'tmp_name' => $file1['tmp_name'][0],
                                            'error' => $file1['error'][0],
                                            'size' => $file1['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName1,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName1,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName1 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName1, $newFileName1, $tmpFilePath1, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName1' => $newFileName1,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName1' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    //echo $folder.$visaDetails['DocFileName1'];die;
                                    if ($visaDetails['DocFileName1'] != '') {
                                        unlink($folder . $visaDetails['DocFileName1']);
                                    }
                                }

                                if ($docs_file_delete_2[$key] == 0) {
                                    $tmpFilePath2 = isset($file2['tmp_name'][0]) ? $file2['tmp_name'][0] : '';
                                    $fileName2 = isset($file2['name'][0]) ? $file2['name'][0] : '';
                                    //$newFileName2 = 'visa_file_2_' . $lastInsertId;
                                    //$newFileName2 = $fileName2.'_2_' . $lastInsertId;
                                    $file_parts2 = isset($fileName2) ? pathinfo($fileName2) : '';
                                    $ext2 = isset($file_parts2['extension']) ? strtolower($file_parts2['extension']) : '';
                                    $newFileName2 = 'visa_document_2_' . $lastInsertId;
                                    if ($ext2 == 'pdf' || $ext2 == 'doc' || $ext2 == 'docx') {
                                        $newFileName2 = $newFileName2 . '.' . $ext3;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName2;
                                        $visaFile = array(
                                            'name' => $file2['name'][0],
                                            'type' => $file2['type'][0],
                                            'tmp_name' => $file2['tmp_name'][0],
                                            'error' => $file2['error'][0],
                                            'size' => $file2['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName2,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName2,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName2 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName2, $newFileName2, $tmpFilePath2, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName2' => $newFileName2,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName2' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    if ($visaDetails['DocFileName2'] != '') {
                                        unlink($folder . $visaDetails['DocFileName2']);
                                    }
                                }

                                if ($docs_file_delete_3[$key] == 0) {
                                    $tmpFilePath3 = isset($file3['tmp_name'][0]) ? $file3['tmp_name'][0] : '';
                                    $fileName3 = isset($file3['name'][0]) ? $file3['name'][0] : '';
                                    //$newFileName2 = 'visa_file_2_' . $lastInsertId;
                                    //$newFileName3 = $fileName3.'_3_' . $lastInsertId;
                                    $file_parts3 = !empty($fileName3) ? pathinfo($fileName3) : '';
                                    $ext3 = isset($file_parts3['extension']) ? strtolower($file_parts3['extension']) : '';
                                    $newFileName3 = 'visa_document_3_' . $lastInsertId;
                                    if ($ext3 == 'pdf' || $ext3 == 'doc' || $ext3 == 'docx') {
                                        $newFileName3 = $newFileName3 . '.' . $ext3;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName3;
                                        $visaFile = array(
                                            'name' => $file3['name'][0],
                                            'type' => $file3['type'][0],
                                            'tmp_name' => $file3['tmp_name'][0],
                                            'error' => $file3['error'][0],
                                            'size' => $file3['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName3,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName3,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName3 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName3, $newFileName3, $tmpFilePath3, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName3' => $newFileName3,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName3' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    if ($visaDetails['DocFileName3'] != '') {
                                        unlink($folder . $visaDetails['DocFileName3']);
                                    }
                                }



                                if ($docs_file_delete_4[$key] == 0) {
                                    $tmpFilePath4 = isset($file4['tmp_name'][0]) ? $file4['tmp_name'][0] : '';
                                    $fileName4 = isset($file4['name'][0]) ? $file4['name'][0] : '';
                                    //$newFileName2 = 'visa_file_2_' . $lastInsertId;
                                    //$newFileName3 = $fileName3.'_3_' . $lastInsertId;
                                    $file_parts4 = !empty($fileName4) ? pathinfo($fileName4) : '';
                                    $ext4 = isset($file_parts4['extension']) ? strtolower($file_parts4['extension']) : '';
                                    $newFileName4 = 'visa_document_4_' . $lastInsertId;
                                    if ($ext4 == 'pdf' || $ext4 == 'doc' || $ext4 == 'docx') {
                                        $newFileName4 = $newFileName4 . '.' . $ext4;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName4;
                                        $visaFile = array(
                                            'name' => $file4['name'][0],
                                            'type' => $file4['type'][0],
                                            'tmp_name' => $file4['tmp_name'][0],
                                            'error' => $file4['error'][0],
                                            'size' => $file4['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName4,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName4,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName4 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName4, $newFileName4, $tmpFilePath4, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName4' => $newFileName4,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName4' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    if ($visaDetails['DocFileName4'] != '') {
                                        unlink($folder . $visaDetails['DocFileName4']);
                                    }
                                }


                                if ($docs_file_delete_5[$key] == 0) {
                                    $tmpFilePath5 = isset($file5['tmp_name'][0]) ? $file5['tmp_name'][0] : '';
                                    $fileName5 = isset($file5['name'][0]) ? $file5['name'][0] : '';
                                    //$newFileName2 = 'visa_file_2_' . $lastInsertId;
                                    //$newFileName3 = $fileName3.'_3_' . $lastInsertId;
                                    $file_parts5 = !empty($fileName5) ? pathinfo($fileName5) : '';
                                    $ext5 = isset($file_parts5['extension']) ? strtolower($file_parts5['extension']) : '';

                                    $newFileName5 = 'visa_document_5_' . $lastInsertId;
                                    if ($ext5 == 'pdf' || $ext5 == 'doc' || $ext5 == 'docx') {
                                        $newFileName5 = $newFileName5 . '.' . $ext5;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName5;
                                        $visaFile = array(
                                            'name' => $file5['name'][0],
                                            'type' => $file5['type'][0],
                                            'tmp_name' => $file5['tmp_name'][0],
                                            'error' => $file5['error'][0],
                                            'size' => $file5['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName5,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName5,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName5 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName5, $newFileName5, $tmpFilePath5, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName5' => $newFileName5,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName5' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    if ($visaDetails['DocFileName5'] != '') {
                                        unlink($folder . $visaDetails['DocFileName5']);
                                    }
                                }




                                if ($docs_file_delete_6[$key] == 0) {
                                    $tmpFilePath6 = isset($file6['tmp_name']) ? $file6['tmp_name'][0] : '';
                                    $fileName6 = isset($file6['name']) ? $file6['name'][0] : '';
                                    //$newFileName2 = 'visa_file_2_' . $lastInsertId;
                                    //$newFileName3 = $fileName3.'_3_' . $lastInsertId;
                                    $file_parts6 = !empty($fileName6) ? pathinfo($fileName6) : '';
                                    $ext6 = isset($file_parts6['extension']) ? strtolower($file_parts6['extension']) : '';
                                    $newFileName6 = 'visa_document_6_' . $lastInsertId;
                                    if ($ext6 == 'pdf' || $ext6 == 'doc' || $ext6 == 'docx') {
                                        $newFileName6 = $newFileName6 . '.' . $ext6;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName6;
                                        $visaFile = array(
                                            'name' => $file6['name'][0],
                                            'type' => $file6['type'][0],
                                            'tmp_name' => $file6['tmp_name'][0],
                                            'error' => $file6['error'][0],
                                            'size' => $file6['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName6,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName6,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName6 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName6, $newFileName6, $tmpFilePath6, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName6' => $newFileName6,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName6' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    if ($visaDetails['DocFileName6'] != '') {
                                        unlink($folder . $visaDetails['DocFileName6']);
                                    }
                                }
                                $insertArray = array();
                                $this->db->update('TB_MP_Inventory_Visa_Doc', array('IsMarkForDel' => 1), array('VisaInvnId = ? ' => $lastInsertId));
                                $DocsRequiredList = isset($post['DocsRequiredList' . ($key + 1)]) && !empty($post['DocsRequiredList' . ($key + 1)]) ? $post['DocsRequiredList' . ($key + 1)] : '';
                                $MandatoryDocsList = isset($post['MandatoryDocsList' . ($key + 1)]) && !empty($post['MandatoryDocsList' . ($key + 1)]) ? $post['MandatoryDocsList' . ($key + 1)] : '';

                                if (!empty($DocsRequiredList)) {
                                    foreach ($DocsRequiredList as $dKey => $dVal) {
                                        $insertArray = [
                                            'VisaInvnId' => $lastInsertId,
                                            'DocumentSysId' => (int) $dVal,
                                            'IsMandatory' => isset($MandatoryDocsList[$dVal]) && ($MandatoryDocsList[$dVal] == 1) ? $MandatoryDocsList[$dVal] : 0,
                                            'IsActive' => 1,
                                            'IsMarkForDel' => 0,
                                        ];
                                        $this->db->insert('TB_MP_Inventory_Visa_Doc', $insertArray);
                                    }
                                }
                                /* $updateData=array(
                                  'DocFileName1' => $newFileName1,
                                  'DocFileName2' => $newFileName2,
                                  );
                                  $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                  $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData); */
                                //#end of upload file

                                $ServiceProviderFeeT = 0;
                                $this->db->delete('TB_MP_StdServiceProvider_Visa', array('InvnVisaSysId = ? ' => $lastInsertId));
//                                echo"<pre>";print_r($service_provider_IsTaxable);die('data');
                                if ($service_provider_title) {
                                    foreach ($service_provider_title as $spk => $spval) {
                                        if ($spval != '') {
                                            $ServiceProviderFee = isset($service_provider_fees[$spk]) ? (float) $service_provider_fees[$spk] : 0;
                                            $insert_M = array(
                                                'ICSourceSysId' => $ICSourceSysId,
                                                'AgentSysId' => $AgentSysId,
                                                'IsAgentSpec' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? $ICSourceSysId : '0',
                                                'InvnVisaSysId' => $lastInsertId,
                                                'ServiceProviderTitle' => $spval,
                                                'ServiceProviderFee' => (float) $ServiceProviderFee,
                                                'ServiceProviderFeeCurrencyType' => isset($service_provider_currency_type[$spk]) ? (int) $service_provider_currency_type[$spk] : 0,
                                                'IsTaxable' => isset($service_provider_IsTaxable[$spk]) ? (int) $service_provider_IsTaxable[$spk] : 0,
                                                'MarkUp' => isset($service_provider_MarkUp[$spk]) ? (int) $service_provider_MarkUp[$spk] : 0,
                                                'IsDisplay' => isset($service_provider_IsDisplay[$spk]) ? (int) $service_provider_IsDisplay[$spk] : 0,
                                                'CreateDate' => $CreateDate,
                                                'UpdateDate' => $CreateDate,
                                                'IsActive' => 1,
                                                'IsMarkForDel' => 0,
                                            );
                                            $this->db->insert('TB_MP_StdServiceProvider_Visa', $insert_M);
                                            $ServiceProviderFeeT += $ServiceProviderFee;
                                        }
                                    }
                                }

                                $visa_markup_adult = isset($post['visa_markup_adult_' . $count]) && !empty($post['visa_markup_adult_' . $count]) ? $post['visa_markup_adult_' . $count] : array();
                                $visa_markup_child = isset($post['visa_markup_child_' . $count]) && !empty($post['visa_markup_child_' . $count]) ? $post['visa_markup_child_' . $count] : array();
                                $visa_markup_childfamily = isset($post['visa_markup_childfamily_' . $count]) && !empty($post['visa_markup_childfamily_' . $count] && $countries_covered[0] == '228' && count($countries_covered) == 1) ? $post['visa_markup_childfamily_' . $count] : array();
                                $visa_markup_infant = isset($post['visa_markup_infant_' . $count]) && !empty($post['visa_markup_infant_' . $count]) ? $post['visa_markup_infant_' . $count] : array();
                                $markup_id = isset($post['markup_id_' . $count]) && !empty($post['markup_id_' . $count]) ? $post['markup_id_' . $count] : array();
                                $MarkUpType = isset($post['markup_type_' . $count]) && !empty($post['markup_type_' . $count]) ? $post['markup_type_' . $count] : array();
                                $MarkUpCurrencyType = isset($post['markup_currency_type_' . $count]) && !empty($post['markup_currency_type_' . $count]) ? $post['markup_currency_type_' . $count] : array();
                                $VisaMrkSysId = isset($post['VisaMrkSysId_' . $count]) && !empty($post['VisaMrkSysId_' . $count]) ? $post['VisaMrkSysId_' . $count] : array();
                                //echo "<pre>";print_r($visa_markup);exit;
                                if ($visa_markup_adult) {
                                    foreach ($visa_markup_adult as $k => $val) {
                                        $insert_M = array(
                                            'ICSourceSysId' => $ICSourceSysId,
                                            'AgentSysId' => $AgentSysId,
                                            'IsAgentSpec' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? $ICSourceSysId : '0',
                                            'InvnVisaSysId' => $lastInsertId,
                                            'MPType' => $markup_id[$k],
                                            'MarkUpType' => $MarkUpType[$k],
                                            'CurrencyType' => $MarkUpCurrencyType[$k],
                                            'MarkUp' => (float) $visa_markup_adult[$k],
                                            'MarkUpChild' => (float) $visa_markup_child[$k],
                                            'MarkUpChildFamily' => (float) $visa_markup_childfamily[$k],
                                            'MarkUpInfant' => (float) $visa_markup_infant[$k],
                                            'CreateDate' => $CreateDate,
                                            'UpdateDate' => $CreateDate,
                                            'ApproveDate' => $CreateDate,
                                            'IsActive' => 1,
                                            'IsApproved' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? 0 : 1,
                                            'IsMarkForDel' => 0,
                                            'ServiceProviderFee' => (float) $ServiceProviderFeeT,
                                            'ServiceProviderFeeCurrencyType' => isset($service_provider_currency_type[0]) ? (int) $service_provider_currency_type[0] : 0,
                                        );
//                                        echo '<pre>';
//                                        print_r($insert_M); die;
                                        if (!empty($VisaMrkSysId) && array_key_exists($k, $VisaMrkSysId)) {
                                            $where = array('VisaMrkSysId = ? ' => $VisaMrkSysId[$k]);
                                            $this->db->update('TB_MP_StdMarkup_Visa', $insert_M, $where);
                                        } else {
                                            $TblAgency->insertData('TB_MP_StdMarkup_Visa', $insert_M);
                                            //$this->db->insert('TB_MP_StdMarkup_Visa', $insert_M);
                                        }
                                    }
                                }

                                $count++;
                            }
                        }
                    }
                }//country cover loop end;

                return true;
            } catch (Exception $e) {
                die('There has been an error. ' . $e->getMessage());
            }
            return 0;
            //echo '<pre>';print_r($post);
        }
    }

    public function VisaDetails($VisaSysId, $ICSourceSysId = null) {
        $select = $this->db->select();
        $selectarray = array('VisaSysId', 'ICSourceSysId', 'NationalitySysId', 'CountriesCoveredSysId', 'VisaName', 'VisaRequired', 'VisaCategory', 'VisaType', 'VisaValidity', 'VisaDuration', 'VisaAdultRates', 'VisaChildRates', 'VisaInfantRates', 'VisaFamilyOfRates', 'IsActive');
        $select->from(array('tb1' => "TB_IC_Visa"), $selectarray);
        $select->where("tb1.VisaSysId =?", $VisaSysId);
        //$select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
        $select->where("tb1.IsMarkForDel =?", 0);
        $select->order(array('VisaSysId ASC'));
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function VisaInventoryDeList($InvnVisaAllSysId, $ICSourceSysId) {
        $select = $this->db->select();
        $selectarray = array('Iswebsite', 'InvnVisaAllSysId', 'ICSourceSysId', 'NationalitySysId', 'CountriesCoveredSysId', 'VisaName', 'VisaRequired', 'VisaCategory', 'VisaType', 'VisaValidity', 'VisaDuration', 'VisaAdultRates', 'VisaChildRates', 'VisaChildFamilyRates', 'VisaInfantRates', 'VisaFamilyOfRates', 'IsActive', 'SupplierSysId', 'CurrencyType', 'DocsRequiredText', 'DocName1', 'DocFileName1', 'DocName2', 'DocFileName2', 'DocName3', 'DocFileName3', 'DocName4', 'DocFileName4', 'DocName5', 'DocFileName5', 'DocName6', 'DocFileName6', 'PrecessingTime', 'BasicRequirementsText', 'EmbassyAddressText', 'DocumentSubmission', 'PhysicalInterview', 'PassportExpiryDays', 'ChildAge');
        $supplierarray = array('SupplierName');
        $select->from(array('tb1' => "TB_MP_Inventory_Visa"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_IC_Supplier"), "tb1.SupplierSysId = tb2.SupplierSysId", $supplierarray);
        $select->where("tb1.InvnVisaAllSysId =?", $InvnVisaAllSysId);
        $select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
        $select->where("tb1.IsMarkForDel =?", 0);
        $select->order(array('InvnVisaAllSysId ASC'));
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function VisaInventoryVisaNationalityDeList($VisaInvnId, $Nationality = 0) {
        $select = $this->db->select();
        $select->from(array('tb1' => "TB_MP_Inventory_Visa_Country"));
        $select->where("tb1.VisaInvnId =?", $VisaInvnId);
        if ($Nationality > 0) {
            $select->where("tb1.NationalitySysId =?", $Nationality);
        }
        $select->where("tb1.IsMarkForDel =?", 0);
        $select->order(array('VisaContMapSysId ASC'));
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function VisaInventoryVisaDocumentDeList($VisaInvnId) {
        $select = $this->db->select();
        $select->from(array('tb1' => "TB_MP_Inventory_Visa_Doc"));
        $select->where("tb1.VisaInvnId =?", $VisaInvnId);
        $select->where("tb1.IsMarkForDel =?", 0);
        $select->order(array('DocVisaSysId ASC'));
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function VisaInventoryVisaDocumentList($VisaInvnId, $AgencySysId) {
        $result = array();
        if ($AgencySysId > 0) {
            $select = $this->db->select();
            $select->from(array('tb1' => "TB_MP_Inventory_Visa_Doc"), array("DocVisaSysId", "IsMandatory"));
            $select->joinLeft(array('tb2' => "TB_Master_VisaDocument"), "tb1.DocumentSysId = tb2.DocSysId", array("Title", "Description", "Label", "FieldType", "Options"));
//            $select->joinLeft(array('tb3' => "TB_Agency_Visa_Document"),"tb2.DocSysId = tb3.DocSysId AND tb3.AgencySysId = $AgencySysId AND tb3.IsMarkForDel = '0'",array("IsMandatory"));
            $select->where("tb1.VisaInvnId =?", $VisaInvnId);
            $select->where("tb1.IsMarkForDel =?", 0);
            $select->order(array('DocVisaSysId ASC'));
            //echo $select; exit;
            $result = $this->db->fetchAll($select);
        }
        return $result;
    }

    public function MarketPlace() {
        $select = $this->db->select();
        $selectarray = array('MPType', 'Title');
        $select->from(array('tb1' => "TB_Master_MPType"), $selectarray);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function MarkupVisaList($InvnVisaSysId, $ICSourceSysId) {
        $select = $this->db->select();
        $selectarray = array('VisaMrkSysId', 'MPType', 'MarkUpType', 'MarkUp', 'MarkUpChild', 'MarkUpChildFamily', 'MarkUpInfant', 'ICSourceSysId', 'CurrencyType', 'ServiceProviderFeeCurrencyType', 'ServiceProviderFee');
        $select->from(array('tb1' => "TB_MP_StdMarkup_Visa"), $selectarray);
        $select->where("tb1.InvnVisaSysId =?", $InvnVisaSysId);
        $select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function ServiceProviderVisaList($InvnVisaSysId, $ICSourceSysId) {
        $select = $this->db->select();
        $selectarray = array('ServiceProviderTitle', 'ServiceProviderFeeCurrencyType', 'ServiceProviderFee', 'IsTaxable', 'MarkUp', 'IsDisplay');
        $select->from(array('tb1' => "TB_MP_StdServiceProvider_Visa"), $selectarray);
        $select->where("tb1.InvnVisaSysId =?", $InvnVisaSysId);
        $select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function VisaRatesList($ICSourceSysId) {
        $select = $this->db->select();
        $selectarray = array('VisaSysId', 'NationalitySysId', 'CountriesCoveredSysId', 'ICSourceSysId', 'VisaName', 'VisaRequired', 'VisaCategory', 'VisaType', 'VisaValidity', 'VisaDuration', 'VisaAdultRates', 'VisaChildRates', 'VisaInfantRates', 'VisaFamilyOfRates', 'IsActive', 'IsApproved');

        $countryarray = array('ContId', 'Title as Count_title');
        $select->from(array('tb1' => "TB_IC_Visa"), $selectarray);
        $select->joinLeft(array('tb3' => "TB_Master_Geo_Country"), "tb1.NationalitySysId = tb3.ContId", $countryarray);
        if (!empty($ICSourceSysId) && $ICSourceSysId > 0) {
            $select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
        }
        $select->where("tb1.IsMarkForDel =?", 0);
        $select->order(array('VisaSysId DESC'));
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function VisaInventoryList($ICSourceSysId, $searchArr = array()) {
        $select = $this->db->select();
        $selectarray = array('Iswebsite', 'InvnVisaAllSysId', 'NationalitySysId', 'CountriesCoveredSysId', 'ICSourceSysId', 'VisaName', 'VisaRequired', 'VisaCategory', 'VisaType', 'VisaValidity', 'VisaDuration', 'VisaAdultRates', 'VisaChildRates', 'VisaInfantRates', 'VisaFamilyOfRates', 'IsActive', 'IsApproved', 'PrecessingTime', 'CurrencyType', 'PassportExpiryDays');

        $countryarray = array('ContId', 'Title as Count_title');
        $select->from(array('tb1' => "TB_MP_Inventory_Visa"), $selectarray);
        $select->joinLeft(array('tb2' => "TB_MP_Inventory_Visa_Country"), "tb1.InvnVisaAllSysId = tb2.VisaInvnId", array('IsMarkForDel as visaCountryIsMarkForDel'));
        $select->joinLeft(array('tb3' => "TB_Master_Geo_Country"), "tb2.NationalitySysId = tb3.ContId", $countryarray);
        if (!empty($ICSourceSysId) && $ICSourceSysId > 0) {
            $select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
        }
        if (count($searchArr) > 0) {
            if (!empty($searchArr['ContId'])) {
                $select->where("tb1.CountriesCoveredSysId =?", trim($searchArr['ContId']));
            }
            if (!empty($searchArr['VisaName'])) {
                $select->where("tb1.VisaName like '%" . trim($searchArr['VisaName']) . "%'");
            }
            if (!empty($searchArr['VisaType'])) {
                $select->where("tb1.VisaType =?", trim($searchArr['VisaType']));
            }
        }
        $select->where("tb1.IsMarkForDel =?", 0);
        $select->order(array('InvnVisaAllSysId DESC'));
        $result = $this->db->fetchAll($select);
        return $result;
    }

    public function SearchVisaDetails($selectNationality, $countries_covered) {
        $select = $this->db->select();
        $selectarray = array('InvnVisaAllSysId', 'NationalitySysId', 'CountriesCoveredSysId');
        $select->from(array('tb1' => "TB_MP_Inventory_Visa"), $selectarray);
        $select->where("tb1.NationalitySysId =?", $selectNationality);
        $select->where('tb1.CountriesCoveredSysId IN(?)', array($countries_covered));
        //$select->where("tb1.IsApproved =?", 1);
        $select->where("tb1.IsActive =?", 1);
        $select->where("tb1.IsMarkForDel =?", 0);
        $result = $this->db->fetchRow($select);
        return $result;
    }

//    public function SearchVisaDetails($selectNationality,$countries_covered) {
//        $select = $this->db->select();
//            $selectarray = array('VisaSysId','NationalitySysId','CountriesCoveredSysId');
//            $select->from(array('tb1' => "TB_IC_Visa"), $selectarray);
//            $select->where("tb1.NationalitySysId =?", $selectNationality);
//            $select->where('tb1.CountriesCoveredSysId IN(?)', array($countries_covered));
//            $select->where("tb1.IsApproved =?", 1);
//            $select->where("tb1.IsActive =?", 1);
//            $select->where("tb1.IsMarkForDel =?", 0);
//            $result = $this->db->fetchRow($select);
//        return $result;
//    }
//    public function GetVisaDetails() {
//        $select = $this->db->select();
//            $selectarray = array('VisaSysId','NationalitySysId','CountriesCoveredSysId');
//            $select->from(array('tb1' => "TB_IC_Visa"), $selectarray);
//            $select->where("tb1.IsApproved =?", 1);
//            $select->where("tb1.IsActive =?", 1);
//            $select->where("tb1.IsMarkForDel =?", 0);
//            $result = $this->db->fetchAll($select);
//        return $result;
//    }
    public function DeleteVisa() {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $post = $request->getPost();
        try {
            $this->db->beginTransaction();
            $insert = array(
                'IsMarkForDel' => '1'
            );
            $where = array('VisaSysId =?' => $post['DeleteId']);
            $this->db->update('TB_IC_Visa', $insert, $where);
            $this->db->commit();
            return true;
        } catch (Exception $ex) {
            die($ex->getMessage());
        }
    }

    public function setApproveDisapprove($whereCondition, $tableName, $updateArr) {
        try {
            $isChanged = $this->db->update($tableName, $updateArr, $whereCondition);
        } catch (Exception $e) {
            die('There has been an error. ' . $e->getMessage());
        }
        return @$isChanged ? $isChanged : 0;
    }

    public function setActiveDeactive($whereCondition, $tableName, $updateArr) {
        try {
            $isChanged = $this->db->update($tableName, $updateArr, $whereCondition);
        } catch (Exception $e) {
            die('There has been an error. ' . $e->getMessage());
        }
        return @$isChanged ? $isChanged : 0;
    }

    public function updateVisa($ActivitySysId, $insert) {
        $where = array('VisaSysId = ? ' => $ActivitySysId);
        return $this->db->update('TB_IC_Visa', $insert, $where);
    }

    public function VisaInventoryDetailById($InvnVisaAllSysId) {
        $select = $this->db->select();
        $selectarray = array('InvnVisaAllSysId', 'ICSourceSysId', 'NationalitySysId', 'CountriesCoveredSysId', 'VisaName', 'VisaRequired', 'VisaCategory', 'VisaType', 'VisaValidity', 'VisaDuration', 'VisaAdultRates', 'VisaChildRates', 'VisaInfantRates', 'VisaFamilyOfRates', 'IsActive', 'SupplierSysId', 'CurrencyType', 'DocsRequiredText', 'DocName1', 'DocFileName1', 'DocName2', 'DocFileName2', 'DocName3', 'DocFileName3', 'DocName4', 'DocFileName4', 'DocName5', 'DocFileName5', 'DocName6', 'DocFileName6');
        $select->from(array('tb1' => "TB_MP_Inventory_Visa"), $selectarray);
        $select->where("tb1.InvnVisaAllSysId =?", $InvnVisaAllSysId);
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function updateTable($table, $editData, $where) {
        $dbtable = new Zend_Db_Table("$table");
        $dbtable->update($editData, $where);
    }

    public function checkVisaFinalDocument($TPSysId, $TPPaxSysId = null) {
        $select = $this->db->select();
        $select->from(array('tb1' => "TB_Agency_Customer_TravelPlan_Visa_Final_Document"));
        $select->where("tb1.TPSysId =?", $TPSysId);
        if ($TPPaxSysId) {
            $select->where("tb1.TPPaxSysId =?", $TPPaxSysId);
        }
        $result = $this->db->fetchRow($select);
        return $result;
    }

    public function checkUpdatePaxVisaStatusVisaDoc($TPSysId, $TPPaxSysId) {
        $select = $this->db->select();
        $select->from(array('tb1' => "TB_Agency_Customer_TravelPlan_Visa_Document"));
        $select->where("tb1.TPSysId =?", $TPSysId);
        $select->where("tb1.IsMandatory =?", 1);
        $select->where("tb1.TPPaxSysId =?", $TPPaxSysId);
        $result = $this->db->fetchAll($select);
        $totalDocument = count($result);
        $status = false;
        $returnStatus = 0;
        if (!empty($result)) {
            $finalStatusArray = array(
                0 => 0,
                1 => 0,
                2 => 0,
                3 => 0,
            );
            $finalStatus = $finalStatusP = 0;
            foreach ($result as $key => $value) {
                if ($value['Status'] == 0) {
                    $finalStatusArray[0]++;
                } else if ($value['Status'] == 1) {
                    $finalStatusArray[1]++;
                } else if ($value['Status'] == 2) {
                    $finalStatusArray[2]++;
                } else if ($value['Status'] == 3) {
                    $finalStatusArray[3]++;
                }
            }
            if ($finalStatusArray[0] == $totalDocument) {
                $finalStatus = 108;  //Visa - Docs Pending
            } else if ($finalStatusArray[1] == $totalDocument) {
                $finalStatus = 106;  //Visa - Docs Received
            } else if ($finalStatusArray[2] == $totalDocument) {
                $finalStatus = 158;  //Visa Docs Approved
            } else if ($finalStatusArray[3] == $totalDocument) {
                $finalStatus = 151;  //Visa Docs Rejected
            }
            if ($finalStatus == 0) {
                if (!isset($_SESSION['sessionLogin_user']['intLoggedinUserAgencySysId'])) {
                    $finalStatus = 150;
                } else {
                    if ((int) $finalStatusArray[3] > 0) {
                        $finalStatus = 152;  //Visa Docs Rejected Partial
                    } else if ((int) $finalStatusArray[2] > 0) {
                        $finalStatus = 154;  //Visa  Docs Approved Partial
                    } else if ((int) $finalStatusArray[1] > 0) {
                        $finalStatus = 150;  //Visa Partial Docs Received
                    }
                }
            }
            //echo $finalStatus;die;
            if ($finalStatus > 0) {
                $checkVisaFinalDocument = $this->checkVisaFinalDocument($TPSysId, $TPPaxSysId);
                if (in_array($checkVisaFinalDocument['Status'], array(0, 108, 106, 158, 151, 152, 154, 150))) {
                    $updateData['Status'] = $finalStatus;
                    $updateData['UpdateDate'] = date('Y-m-d H:i');
                    $whereData = array('TPSysId = ? ' => $TPSysId, 'TPPaxSysId = ? ' => $TPPaxSysId);
                    $this->db->update('TB_Agency_Customer_TravelPlan_Visa_Final_Document', $updateData, $whereData);

                    $historyData = array(
                        'AgencySysId' => $_SESSION['sessionLogin_user']['intLoggedinUserAgencySysId'],
                        'CustomerSysId' => 0,
                        'TPSysId' => $TPSysId,
                        'PlanType' => 6,
                        'TPPaxSysId' => $TPPaxSysId,
                        'DocId' => 0,
                        'UserSysId' => $_SESSION['sessionLogin_user']['intLoggedinUserId'],
                        'Remark' => 'Visa Status Updated',
                        'IsManualAdded' => 1,
                        'Status' => (int) $finalStatus,
                    );
                    $this->addUpdateTravelPlanHistory($historyData);

                    $this->checkUpdateVisaStatus($TPSysId, $TPPaxSysId);
                    $status = true;
                    $returnStatus = $finalStatus;
                }
            } else {
                $status = false;
            }
        }
        return array('status' => $status, 'finalStatus' => $returnStatus);
    }

    public function checkUpdateVisaStatus($TPSysId, $TPPaxSysId) {

        $SequenceWiseStatus = array(108, 150, 106, 154, 158, 152, 151, 110, 128, 112, 114, 116, 133, 118, 132);
        $SequenceWiseStatusPartial = array(
            108 => 150,
            150 => 150,
            106 => 150,
            158 => 154,
            154 => 154,
            151 => 152,
            152 => 152,
            110 => 110,
            128 => 128,
            112 => 156,
            133 => 155,
            114 => 114,
            116 => 116,
            133 => 155,
            118 => 118,
            132 => 157,
        );
        $select = $this->db->select();
        $select->from(array('tb1' => "TB_Agency_Customer_TravelPlan_Visa_Final_Document"));
        $select->joinLeft(array('tb2' => "TB_Agency_Customer_TravelPlan"), "tb1.TPSysId = tb2.TPSysId", array('MasterTPSysId', 'AgencySysId'));
        $select->where("tb1.TPSysId =?", $TPSysId);
        $result = $this->db->fetchAll($select);
        $MasterTPSysId = $result[0]['MasterTPSysId'];
        $AgencySysId = $result[0]['AgencySysId'];
        $totalDocument = count($result);
        $finalStatus = $finalStatusP = 0;
        $status = false;

        if (!empty($result)) {
            $finalStatusArray = array();
            foreach ($result as $key => $value) {
                $finalStatusArray[$value['Status']]++;
            }
            $lastStatus = 0;

//            echo "<pre>";print_r($finalStatusArray); 
//            echo "<pre>";print_r($SequenceWiseStatus); 
//            echo "<pre>";print_r($SequenceWiseStatusPartial); 
            if (!empty($finalStatusArray)) {
                foreach ($SequenceWiseStatus as $sKey => $sVal) {
                    if (isset($finalStatusArray[$sVal]) && (int) $finalStatusArray[$sVal] > 0) {
                        if ($finalStatusArray[$sVal] == $totalDocument) {
                            $finalStatus = $sVal;
                        }
                        $lastStatus = $sVal;
                    }
                }
            }
            //echo  '-S-'.$lastStatus; 
            if ($finalStatus == 0 && isset($SequenceWiseStatusPartial[$lastStatus])) {
                $finalStatus = $SequenceWiseStatusPartial[$lastStatus];
            }
            //echo  '-H-'.$finalStatus;die;
            if ($finalStatus > 0 && $MasterTPSysId > 0) {
                //$checkVisaFinalDocument = $this->checkVisaFinalDocument($TPSysId, $TPPaxSysId);
                //if(in_array($checkVisaFinalDocument['Status'],array(0,151,158,108,106))){
                $updateData['BookingStatus'] = $finalStatus;
                $updateData['UpdateDate'] = date('Y-m-d H:i');
                $whereData = array('TPSysId = ? ' => $MasterTPSysId);
                $this->db->update('TB_Agency_Customer_TravelPlan_Query', $updateData, $whereData);
                $status = true;
                $historyData = array(
                    'AgencySysId' => $AgencySysId,
                    'CustomerSysId' => 0,
                    'TPSysId' => $TPSysId,
                    'PlanType' => 6,
                    'TPPaxSysId' => 0,
                    'DocId' => 0,
                    'UserSysId' => $_SESSION['sessionLogin_user']['intLoggedinUserId'],
                    'Remark' => 'Booking Status Updated',
                    'IsManualAdded' => 1,
                    'Status' => (int) $finalStatus,
                );
                $this->addUpdateTravelPlanHistory($historyData);
                //}
            }
        }
        return $status;
    }

    public function addUpdateTravelPlanHistory($historyData) {
        $TblAgency = new Travel_Model_TblAgency();
        $travelplanHistory = array(
            'AgencySysId' => (int) $historyData['AgencySysId'],
            'CustomerSysId' => (int) $historyData['CustomerSysId'],
            'TPSysId' => (int) $historyData['TPSysId'],
            'PlanType' => (int) $historyData['PlanType'],
            'TPPaxSysId' => (int) $historyData['TPPaxSysId'],
            'DocId' => (int) $historyData['DocId'],
            'UserSysId' => (int) $historyData['UserSysId'],
            'Remark' => $historyData['Remark'],
            'IsManualAdded' => (int) $historyData['IsManualAdded'],
            'Status' => (int) $historyData['Status'],
            'CreateDate' => date('Y-m-d H:i'),
            'IsActive' => 1,
            'IsMarkForDelete' => 0
        );
        $return = $TblAgency->insertData('TB_Agency_Customer_TravelPlan_History', $travelplanHistory);
        return $return;
    }

    public function ServiceProviderVisaListAll($InvnVisaSysId, $ICSourceSysId) {
        if ($InvnVisaSysId != "") {
            $select = $this->db->select();
            $selectarray = array('ServiceProviderTitle', 'ServiceProviderFeeCurrencyType', 'ServiceProviderFee', 'IsTaxable', 'MarkUp', 'IsDisplay', 'InvnVisaSysId');
            $select->from(array('tb1' => "TB_MP_StdServiceProvider_Visa"), $selectarray);
            $select->where("tb1.InvnVisaSysId IN  ($InvnVisaSysId)");
            $select->where("tb1.ICSourceSysId =?", $ICSourceSysId);
            $result = $this->db->fetchAll($select);
            return $result;
        } else {
            return array();
        }
    }
     public function addVisaAgentNew($ICSourceSysId) {
        $TblAgency = new Travel_Model_TblAgency();
        $request = Zend_Controller_Front::getInstance()->getRequest();
        if ($request->isPost()) {
            $post = $request->getPost();
//            echo "<pre>";print_r($post);exit;
            $countries_covered = isset($post['countries_covered']) && !empty($post['countries_covered']) ? $post['countries_covered'] : '';

            $CreateDate = date('Y-m-d H:i:s');
            $visa_name = isset($post['visa_name']) && !empty($post['visa_name']) ? $post['visa_name'] : '';
            $visa_required = isset($post['visa_required']) && !empty($post['visa_required']) ? $post['visa_required'] : '';
            $visa_category = isset($post['visa_category']) && !empty($post['visa_category']) ? $post['visa_category'] : '0';
            $visa_type = isset($post['visa_type']) && !empty($post['visa_type']) ? $post['visa_type'] : '0';
            $precessing_time = isset($post['precessing_time']) && !empty($post['precessing_time']) ? $post['precessing_time'] : '';
            $passport_expire_days = isset($post['passport_expire']) && !empty($post['passport_expire']) ? $post['passport_expire'] : '';
            $validity = isset($post['validity']) && !empty($post['validity']) ? $post['validity'] : '0';
            $duration = isset($post['duration']) && !empty($post['duration']) ? $post['duration'] : '0';
            $adult = isset($post['adult']) && !empty($post['adult']) ? $post['adult'] : '0';
            $CurrencyTypeMarkup = isset($post['markup_currency_typeid']) && !empty($post['markup_currency_typeid']) ? $post['markup_currency_typeid'] : '';
            $child = isset($post['child']) && !empty($post['child']) ? $post['child'] : '0';
            $childAge = isset($post['child']) && !empty($post['childAge']) ? $post['childAge'] : '0';
            $childFamily = isset($post['childFamily']) && !empty($post['childFamily'] && $countries_covered[0] == '228' && count($countries_covered) == 1) ? $post['childFamily'] : array();
            $infant = isset($post['infant']) && !empty($post['infant']) ? $post['infant'] : '0';
            $familyOf4 = isset($post['familyOf4']) && !empty($post['familyOf4']) ? $post['familyOf4'] : '0';
            $InvnVisaAllSysId = isset($post['InvnVisaAllSysId']) && !empty($post['InvnVisaAllSysId']) ? $post['InvnVisaAllSysId'] : '';
            $visa_id = isset($post['visa_id']) && !empty($post['visa_id']) ? $post['visa_id'] : '';
            $AgentSysId = isset($post['AgentSysId']) && !empty($post['AgentSysId']) ? $post['AgentSysId'] : 0;
            $AgencySysId = $ICSourceSysId;
            $SupplierSysId = isset($post['supplierSysId']) && !empty($post['supplierSysId']) ? $post['supplierSysId'] : 0;
            $CurrencyType = isset($post['currency_type']) && !empty($post['currency_type']) ? $post['currency_type'] : '';
            $DocsRequiredText = isset($post['docs_message']) && !empty($post['docs_message']) ? $post['docs_message'] : '';
            $basic_requirementsText = isset($post['basic_requirements']) && !empty($post['basic_requirements']) ? $post['basic_requirements'] : '';
            $embassy_addressText = isset($post['embassy_address']) && !empty($post['embassy_address']) ? $post['embassy_address'] : '';
            $docs_name1 = isset($post['docs_name_1']) && !empty($post['docs_name_1']) ? $post['docs_name_1'] : '';
            $docs_name2 = isset($post['docs_name_2']) && !empty($post['docs_name_2']) ? $post['docs_name_2'] : '';
            $docs_name3 = isset($post['docs_name_3']) && !empty($post['docs_name_3']) ? $post['docs_name_3'] : '';
            $docs_name4 = isset($post['docs_name_4']) && !empty($post['docs_name_4']) ? $post['docs_name_4'] : '';
            $docs_name5 = isset($post['docs_name_5']) && !empty($post['docs_name_5']) ? $post['docs_name_5'] : '';
            $docs_name6 = isset($post['docs_name_6']) && !empty($post['docs_name_6']) ? $post['docs_name_6'] : '';
            $file1 = isset($_FILES['docs_data_1']) && !empty($_FILES['docs_data_1']) ? $_FILES['docs_data_1'] : '';
            $file2 = isset($_FILES['docs_data_2']) && !empty($_FILES['docs_data_2']) ? $_FILES['docs_data_2'] : '';
            $file3 = isset($_FILES['docs_data_3']) && !empty($_FILES['docs_data_3']) ? $_FILES['docs_data_3'] : '';
            $file4 = isset($_FILES['docs_data_4']) && !empty($_FILES['docs_data_4']) ? $_FILES['docs_data_4'] : '';
            $file5 = isset($_FILES['docs_data_5']) && !empty($_FILES['docs_data_5']) ? $_FILES['docs_data_5'] : '';
            $file6 = isset($_FILES['docs_data_6']) && !empty($_FILES['docs_data_6']) ? $_FILES['docs_data_6'] : '';
            $IsActive = isset($post['status']) ? $post['status'] : 1;
            $docs_file_delete_1 = isset($post['docs_file_delete_1']) && !empty($post['docs_file_delete_1']) ? $post['docs_file_delete_1'] : 0;
            $docs_file_delete_2 = isset($post['docs_file_delete_2']) && !empty($post['docs_file_delete_2']) ? $post['docs_file_delete_2'] : 0;
            $docs_file_delete_3 = isset($post['docs_file_delete_3']) && !empty($post['docs_file_delete_3']) ? $post['docs_file_delete_3'] : 0;
            $docs_file_delete_4 = isset($post['docs_file_delete_4']) && !empty($post['docs_file_delete_4']) ? $post['docs_file_delete_4'] : 0;
            $docs_file_delete_5 = isset($post['docs_file_delete_5']) && !empty($post['docs_file_delete_5']) ? $post['docs_file_delete_5'] : 0;
            $docs_file_delete_6 = isset($post['docs_file_delete_6']) && !empty($post['docs_file_delete_6']) ? $post['docs_file_delete_6'] : 0;
            $DocumentSubmission = isset($post['DocumentSubmission']) && !empty($post['DocumentSubmission']) ? $post['DocumentSubmission'] : 0;
            $PhysicalInterview = isset($post['PhysicalInterview']) && !empty($post['PhysicalInterview']) ? $post['PhysicalInterview'] : 0;
            //echo "<pre>";print_r($_FILES);die;
            try {
                if ($countries_covered) { //country cover loop start;
                    foreach ($countries_covered as $ky => $vl) {
                        if ($visa_name) {
                            $count = 1;
                            $folder = USER_FILE_UPLOAD_PATH . 'agency/' . $AgencySysId . "/";
                            foreach ($visa_name as $key => $value) {
                              
                                $insert = array(
                                    'ICSourceSysId' => $ICSourceSysId,
                                    'AgentSysId' => $AgentSysId,
                                    'IsAgentSpec' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? $ICSourceSysId : '0',
                                    'NationalitySysId' => 0,
                                    'CountriesCoveredSysId' => $countries_covered[$ky],
                                    'VisaName' => $value,
                                    'VisaRequired' => $visa_required[$key],
                                    'VisaCategory' => $visa_category[$key],
                                    'VisaType' => $visa_type[$key],
                                    'VisaValidity' => $validity[$key],
                                    'VisaDuration' => $duration[$key],
                                    'VisaAdultRates' => (int) $adult[$key],
                                    'VisaChildRates' => (int) $child[$key],
                                    'childAge' => (int) $childAge[$key],
                                    'VisaChildFamilyRates' => (int) $childFamily[$key],
                                    'VisaInfantRates' => (int) $infant[$key],
                                    'VisaFamilyOfRates' => $familyOf4[$key],
                                    'SupplierSysId' => $SupplierSysId,
                                    'CurrencyType' => $CurrencyType,
                                    'DocsRequiredText' => ($DocsRequiredText[$key]),
                                    'DocName1' => $docs_name1[$key],
                                    //'DocFileName1' => $newFileName1,
                                    'DocName2' => $docs_name2[$key],
                                    //'DocFileName2' => $newFileName2,
                                    'DocName3' => $docs_name3[$key],
                                    'DocName4' => $docs_name4[$key],
                                    'DocName5' => $docs_name5[$key],
                                    'DocName6' => $docs_name6[$key],
                                    'CreateDate' => $CreateDate,
                                    'UpdateDate' => $CreateDate,
                                    'ApproveDate' => $CreateDate,
                                    'IsActive' => $IsActive,
                                    'IsApproved' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? 0 : 1,
                                    'IsMarkForDel' => 0,
                                    'PrecessingTime' => $precessing_time[$key],
                                    'PassportExpiryDays' => $passport_expire_days[$key],
                                    'BasicRequirementsText' => ($basic_requirementsText[$key]),
                                    'EmbassyAddressText' => ($embassy_addressText[$key]),
                                    'DocumentSubmission' => $DocumentSubmission,
                                    'PhysicalInterview' => $PhysicalInterview,
                                );
                                
                                if (!empty($InvnVisaAllSysId) && !empty($InvnVisaAllSysId[$key]) && array_key_exists($key, $InvnVisaAllSysId)) {
                                    $where = array('InvnVisaAllSysId = ? ' => $InvnVisaAllSysId[$key]);
                                    $this->db->update('TB_MP_Inventory_Visa', $insert, $where);
                                    $lastInsertId = $InvnVisaAllSysId[$key];
                                    $this->db->update('TB_MP_Inventory_Visa_Country', array('IsMarkForDel' => 1), array('VisaInvnId = ? ' => $lastInsertId));
                                } else {
                                    $this->db->insert('TB_MP_Inventory_Visa', $insert);
                                    $lastInsertId = $this->db->lastInsertId('TB_MP_Inventory_Visa');
                                }

                                $selectNationality = isset($post['selectNationality']) ? $post['selectNationality'] : array();
                                $insertNationality = array();
                                if (!empty($selectNationality)) {
                                    foreach ($selectNationality as $snKey => $snVal) {
                                        $insertNationality = [
                                            'VisaInvnId' => $lastInsertId,
                                            'NationalitySysId' => $snVal,
                                            'IsActive' => 1,
                                            'IsMarkForDel' => 0,
                                        ];

                                        $this->db->insert('TB_MP_Inventory_Visa_Country', $insertNationality);
                                    }
                                }
                                //upload file
                                $visaDetails = $this->VisaInventoryDetailById($lastInsertId);
                                if ($docs_file_delete_1[$key] == 0) {
                                    $tmpFilePath1 = isset($file1['tmp_name'][0]) ? $file1['tmp_name'][0] : '';
                                    $fileName1 = isset($file1['name'][0]) ? $file1['name'][0] : '';
                                    //$newFileName1 = 'visa_file_1_' . $lastInsertId;

                                    $file_parts1 = !empty($fileName1) ? pathinfo($fileName1) : '';
                                    //print_r($file_parts1);die;
                                    $ext1 = isset($file_parts1['extension']) ? strtolower($file_parts1['extension']) : '';
                                    $newFileName1 = 'visa_document_1_' . $lastInsertId;
                                    if ($ext1 == 'pdf' || $ext1 == 'doc' || $ext1 == 'docx') {
                                        $newFileName1 = $newFileName1 . '.' . $ext1;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName1;
                                        $visaFile = array(
                                            'name' => $file1['name'][0],
                                            'type' => $file1['type'][0],
                                            'tmp_name' => $file1['tmp_name'][0],
                                            'error' => $file1['error'][0],
                                            'size' => $file1['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName1,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName1,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName1 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName1, $newFileName1, $tmpFilePath1, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName1' => $newFileName1,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName1' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    //echo $folder.$visaDetails['DocFileName1'];die;
                                    if ($visaDetails['DocFileName1'] != '') {
                                        unlink($folder . $visaDetails['DocFileName1']);
                                    }
                                }

                                if ($docs_file_delete_2[$key] == 0) {
                                    $tmpFilePath2 = isset($file2['tmp_name'][0]) ? $file2['tmp_name'][0] : '';
                                    $fileName2 = isset($file2['name'][0]) ? $file2['name'][0] : '';
                                    //$newFileName2 = 'visa_file_2_' . $lastInsertId;
                                    //$newFileName2 = $fileName2.'_2_' . $lastInsertId;
                                    $file_parts2 = isset($fileName2) ? pathinfo($fileName2) : '';
                                    $ext2 = isset($file_parts2['extension']) ? strtolower($file_parts2['extension']) : '';
                                    $newFileName2 = 'visa_document_2_' . $lastInsertId;
                                    if ($ext2 == 'pdf' || $ext2 == 'doc' || $ext2 == 'docx') {
                                        $newFileName2 = $newFileName2 . '.' . $ext3;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName2;
                                        $visaFile = array(
                                            'name' => $file2['name'][0],
                                            'type' => $file2['type'][0],
                                            'tmp_name' => $file2['tmp_name'][0],
                                            'error' => $file2['error'][0],
                                            'size' => $file2['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName2,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName2,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName2 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName2, $newFileName2, $tmpFilePath2, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName2' => $newFileName2,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName2' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    if ($visaDetails['DocFileName2'] != '') {
                                        unlink($folder . $visaDetails['DocFileName2']);
                                    }
                                }

                                if ($docs_file_delete_3[$key] == 0) {
                                    $tmpFilePath3 = isset($file3['tmp_name'][0]) ? $file3['tmp_name'][0] : '';
                                    $fileName3 = isset($file3['name'][0]) ? $file3['name'][0] : '';
                                    //$newFileName2 = 'visa_file_2_' . $lastInsertId;
                                    //$newFileName3 = $fileName3.'_3_' . $lastInsertId;
                                    $file_parts3 = !empty($fileName3) ? pathinfo($fileName3) : '';
                                    $ext3 = isset($file_parts3['extension']) ? strtolower($file_parts3['extension']) : '';
                                    $newFileName3 = 'visa_document_3_' . $lastInsertId;
                                    if ($ext3 == 'pdf' || $ext3 == 'doc' || $ext3 == 'docx') {
                                        $newFileName3 = $newFileName3 . '.' . $ext3;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName3;
                                        $visaFile = array(
                                            'name' => $file3['name'][0],
                                            'type' => $file3['type'][0],
                                            'tmp_name' => $file3['tmp_name'][0],
                                            'error' => $file3['error'][0],
                                            'size' => $file3['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName3,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName3,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName3 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName3, $newFileName3, $tmpFilePath3, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName3' => $newFileName3,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName3' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    if ($visaDetails['DocFileName3'] != '') {
                                        unlink($folder . $visaDetails['DocFileName3']);
                                    }
                                }



                                if ($docs_file_delete_4[$key] == 0) {
                                    $tmpFilePath4 = isset($file4['tmp_name'][0]) ? $file4['tmp_name'][0] : '';
                                    $fileName4 = isset($file4['name'][0]) ? $file4['name'][0] : '';
                                    //$newFileName2 = 'visa_file_2_' . $lastInsertId;
                                    //$newFileName3 = $fileName3.'_3_' . $lastInsertId;
                                    $file_parts4 = !empty($fileName4) ? pathinfo($fileName4) : '';
                                    $ext4 = isset($file_parts4['extension']) ? strtolower($file_parts4['extension']) : '';
                                    $newFileName4 = 'visa_document_4_' . $lastInsertId;
                                    if ($ext4 == 'pdf' || $ext4 == 'doc' || $ext4 == 'docx') {
                                        $newFileName4 = $newFileName4 . '.' . $ext4;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName4;
                                        $visaFile = array(
                                            'name' => $file4['name'][0],
                                            'type' => $file4['type'][0],
                                            'tmp_name' => $file4['tmp_name'][0],
                                            'error' => $file4['error'][0],
                                            'size' => $file4['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName4,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName4,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName4 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName4, $newFileName4, $tmpFilePath4, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName4' => $newFileName4,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName4' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    if ($visaDetails['DocFileName4'] != '') {
                                        unlink($folder . $visaDetails['DocFileName4']);
                                    }
                                }


                                if ($docs_file_delete_5[$key] == 0) {
                                    $tmpFilePath5 = isset($file5['tmp_name'][0]) ? $file5['tmp_name'][0] : '';
                                    $fileName5 = isset($file5['name'][0]) ? $file5['name'][0] : '';
                                    //$newFileName2 = 'visa_file_2_' . $lastInsertId;
                                    //$newFileName3 = $fileName3.'_3_' . $lastInsertId;
                                    $file_parts5 = !empty($fileName5) ? pathinfo($fileName5) : '';
                                    $ext5 = isset($file_parts5['extension']) ? strtolower($file_parts5['extension']) : '';

                                    $newFileName5 = 'visa_document_5_' . $lastInsertId;
                                    if ($ext5 == 'pdf' || $ext5 == 'doc' || $ext5 == 'docx') {
                                        $newFileName5 = $newFileName5 . '.' . $ext5;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName5;
                                        $visaFile = array(
                                            'name' => $file5['name'][0],
                                            'type' => $file5['type'][0],
                                            'tmp_name' => $file5['tmp_name'][0],
                                            'error' => $file5['error'][0],
                                            'size' => $file5['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName5,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName5,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName5 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName5, $newFileName5, $tmpFilePath5, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName5' => $newFileName5,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName5' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    if ($visaDetails['DocFileName5'] != '') {
                                        unlink($folder . $visaDetails['DocFileName5']);
                                    }
                                }




                                if ($docs_file_delete_6[$key] == 0) {
                                    $tmpFilePath6 = isset($file6['tmp_name']) ? $file6['tmp_name'][0] : '';
                                    $fileName6 = isset($file6['name']) ? $file6['name'][0] : '';
                                    //$newFileName2 = 'visa_file_2_' . $lastInsertId;
                                    //$newFileName3 = $fileName3.'_3_' . $lastInsertId;
                                    $file_parts6 = !empty($fileName6) ? pathinfo($fileName6) : '';
                                    $ext6 = isset($file_parts6['extension']) ? strtolower($file_parts6['extension']) : '';
                                    $newFileName6 = 'visa_document_6_' . $lastInsertId;
                                    if ($ext6 == 'pdf' || $ext6 == 'doc' || $ext6 == 'docx') {
                                        $newFileName6 = $newFileName6 . '.' . $ext6;
                                        $image_path = 'doc/' . $AgencySysId . '/visa/document';
                                        $DetailImg = IMAGE_PATH_URL_AWS . $image_path . '/' . $newFileName6;
                                        $visaFile = array(
                                            'name' => $file6['name'][0],
                                            'type' => $file6['type'][0],
                                            'tmp_name' => $file6['tmp_name'][0],
                                            'error' => $file6['error'][0],
                                            'size' => $file6['size'][0],
                                        );
                                        $data = array(
                                            'AgencySysId' => $AgencySysId,
                                            'image_path' => $image_path,
                                            'tags' => 'visa,visa document',
                                            'title' => $newFileName6,
                                            'FILES' => $visaFile,
                                            'fileName' => $newFileName6,
                                        );
                                        //echo "<pre>";print_r($data);die;
                                        $toupload = Zend_Controller_Action_HelperBroker::getStaticHelper('FileUpload')->uploadToAWS($data);
                                        //$newFileName6 = Zend_Controller_Action_HelperBroker::getStaticHelper('General')->fileUpload($fileName6, $newFileName6, $tmpFilePath6, $folder);
                                        if ($toupload['status'] == true) {
                                            $updateData = array(
                                                'DocFileName6' => $newFileName6,
                                                'UpdateDate' => $CreateDate,
                                            );
                                            $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                            $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                        }
                                    }
                                } else {
                                    $updateData = array(
                                        'DocFileName6' => '',
                                        'UpdateDate' => $CreateDate,
                                    );
                                    $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                    $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData);
                                    if ($visaDetails['DocFileName6'] != '') {
                                        unlink($folder . $visaDetails['DocFileName6']);
                                    }
                                }
                                $insertArray = array();
                                $this->db->update('TB_MP_Inventory_Visa_Doc', array('IsMarkForDel' => 1), array('VisaInvnId = ? ' => $lastInsertId));
                                $DocsRequiredList = isset($post['DocsRequiredList' . ($key + 1)]) && !empty($post['DocsRequiredList' . ($key + 1)]) ? $post['DocsRequiredList' . ($key + 1)] : '';
                                $MandatoryDocsList = isset($post['MandatoryDocsList' . ($key + 1)]) && !empty($post['MandatoryDocsList' . ($key + 1)]) ? $post['MandatoryDocsList' . ($key + 1)] : '';

                                if (!empty($DocsRequiredList)) {
                                    foreach ($DocsRequiredList as $dKey => $dVal) {
                                        $insertArray = [
                                            'VisaInvnId' => $lastInsertId,
                                            'DocumentSysId' => (int) $dVal,
                                            'IsMandatory' => isset($MandatoryDocsList[$dVal]) && ($MandatoryDocsList[$dVal] == 1) ? $MandatoryDocsList[$dVal] : 0,
                                            'IsActive' => 1,
                                            'IsMarkForDel' => 0,
                                        ];
                                        $this->db->insert('TB_MP_Inventory_Visa_Doc', $insertArray);
                                    }
                                }
                                /* $updateData=array(
                                  'DocFileName1' => $newFileName1,
                                  'DocFileName2' => $newFileName2,
                                  );
                                  $whereData = array('InvnVisaAllSysId = ? ' => $lastInsertId);
                                  $this->db->update('TB_MP_Inventory_Visa', $updateData, $whereData); */
                                //#end of upload file

                                $ServiceProviderFeeT = 0;
                                $this->db->delete('TB_MP_StdServiceProvider_Visa', array('InvnVisaSysId = ? ' => $lastInsertId));
                                  $service_provider_title = isset($post['service_provider_title']) && !empty($post['service_provider_title']) ? $post['service_provider_title'] : array();
                                $service_provider_fees = isset($post['service_provider_fees']) && !empty($post['service_provider_fees']) ? $post['service_provider_fees'] : array();
                                $service_provider_currency_type = isset($post['service_provider_currency_type']) && !empty($post['service_provider_currency_type']) ? $post['service_provider_currency_type'] : [];
                                $service_provider_IsTaxable = isset($post['service_provider_IsTaxable_' . ($key + 1)]) && !empty($post['service_provider_IsTaxable_' . ($key + 1)]) ? json_decode($post['service_provider_IsTaxable_' . ($key + 1)], 1) : '';
                                $service_provider_IsDisplay = isset($post['service_provider_IsDisplay_' . ($key + 1)]) && !empty($post['service_provider_IsDisplay_' . ($key + 1)]) ? json_decode($post['service_provider_IsDisplay_' . ($key + 1)], 1) : '';
                                $service_provider_MarkUp = isset($post['service_provider_MarkUp']) && !empty($post['service_provider_MarkUp']) ? $post['service_provider_MarkUp'] : [];

//                                echo"<pre>";print_r($service_provider_IsTaxable);die('data');
                                
                                if ($service_provider_title) {
                                    foreach ($service_provider_title as $spk => $spval) {
                                        if ($spval != '') {
                                            $ServiceProviderFee = isset($service_provider_fees[$spk]) ? (float) $service_provider_fees[$spk] : 0;
                                            $insert_M = array(
                                                'ICSourceSysId' => $ICSourceSysId,
                                                'AgentSysId' => $AgentSysId,
                                                'IsAgentSpec' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? $ICSourceSysId : '0',
                                                'InvnVisaSysId' => $lastInsertId,
                                                'ServiceProviderTitle' => $spval,
                                                'ServiceProviderFee' => (float) $ServiceProviderFee,
                                                'ServiceProviderFeeCurrencyType' => isset($service_provider_currency_type[$spk]) ? (int) $service_provider_currency_type[$spk] : 0,
                                                'IsTaxable' => isset($service_provider_IsTaxable[$spk]) ? (int) $service_provider_IsTaxable[$spk] : 0,
                                                'MarkUp' => isset($service_provider_MarkUp[$spk]) ? (int) $service_provider_MarkUp[$spk] : 0,
                                                'IsDisplay' => isset($service_provider_IsDisplay[$spk]) ? (int) $service_provider_IsDisplay[$spk] : 0,
                                                'CreateDate' => $CreateDate,
                                                'UpdateDate' => $CreateDate,
                                                'IsActive' => 1,
                                                'IsMarkForDel' => 0,
                                            );
                                            $this->db->insert('TB_MP_StdServiceProvider_Visa', $insert_M);
                                            $ServiceProviderFeeT += $ServiceProviderFee;
                                        }
                                    }
                                }

                                $visa_markup_adult = isset($post['visa_markup_adult_' . $count]) && !empty($post['visa_markup_adult_' . $count]) ? $post['visa_markup_adult_' . $count] : array();
                                $visa_markup_child = isset($post['visa_markup_child_' . $count]) && !empty($post['visa_markup_child_' . $count]) ? $post['visa_markup_child_' . $count] : array();
                                $visa_markup_childfamily = isset($post['visa_markup_childfamily_' . $count]) && !empty($post['visa_markup_childfamily_' . $count] && $countries_covered[0] == '228' && count($countries_covered) == 1) ? $post['visa_markup_childfamily_' . $count] : array();
                                $visa_markup_infant = isset($post['visa_markup_infant_' . $count]) && !empty($post['visa_markup_infant_' . $count]) ? $post['visa_markup_infant_' . $count] : array();
                                $markup_id = isset($post['markup_id_' . $count]) && !empty($post['markup_id_' . $count]) ? $post['markup_id_' . $count] : array();
                                $MarkUpType = isset($post['markup_type_' . $count]) && !empty($post['markup_type_' . $count]) ? $post['markup_type_' . $count] : array();
                                $MarkUpCurrencyType = isset($post['markup_currency_type_' . $count]) && !empty($post['markup_currency_type_' . $count]) ? $post['markup_currency_type_' . $count] : array();
                                $VisaMrkSysId = isset($post['VisaMrkSysId_' . $count]) && !empty($post['VisaMrkSysId_' . $count]) ? $post['VisaMrkSysId_' . $count] : array();
                                //echo "<pre>";print_r($visa_markup);exit;
                                if ($visa_markup_adult) {
                                    foreach ($visa_markup_adult as $k => $val) {
                                        $insert_M = array(
                                            'ICSourceSysId' => $ICSourceSysId,
                                            'AgentSysId' => $AgentSysId,
                                            'IsAgentSpec' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? $ICSourceSysId : '0',
                                            'InvnVisaSysId' => $lastInsertId,
                                            'MPType' => $markup_id[$k],
                                            'MarkUpType' => $MarkUpType[$k],
                                            'CurrencyType' => $MarkUpCurrencyType[$k],
                                            'MarkUp' => (float) $visa_markup_adult[$k],
                                            'MarkUpChild' => (float) $visa_markup_child[$k],
                                            'MarkUpChildFamily' => (float) $visa_markup_childfamily[$k],
                                            'MarkUpInfant' => (float) $visa_markup_infant[$k],
                                            'CreateDate' => $CreateDate,
                                            'UpdateDate' => $CreateDate,
                                            'ApproveDate' => $CreateDate,
                                            'IsActive' => 1,
                                            'IsApproved' => !empty($ICSourceSysId && $ICSourceSysId > 0) ? 0 : 1,
                                            'IsMarkForDel' => 0,
                                            'ServiceProviderFee' => (float) $ServiceProviderFeeT,
                                            'ServiceProviderFeeCurrencyType' => isset($service_provider_currency_type[0]) ? (int) $service_provider_currency_type[0] : 0,
                                        );
//                                        echo '<pre>';
//                                        print_r($insert_M); die;
                                        if (!empty($VisaMrkSysId) && !empty($VisaMrkSysId[$k]) && array_key_exists($k, $VisaMrkSysId)) {
                                            $where = array('VisaMrkSysId = ? ' => $VisaMrkSysId[$k]);
                                            $this->db->update('TB_MP_StdMarkup_Visa', $insert_M, $where);
                                        } else {
                                            $TblAgency->insertData('TB_MP_StdMarkup_Visa', $insert_M);
                                            //$this->db->insert('TB_MP_StdMarkup_Visa', $insert_M);
                                        }
                                    }
                                }

                                $count++;
                            }
                        }
                    }
                }//country cover loop end;

                return true;
            } catch (Exception $e) {
                die('There has been an error. ' . $e->getMessage());
            }
            return 0;
            //echo '<pre>';print_r($post);
        }
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit