<?php
class echoSignM extends CFormModel 
{	
	public $sign;
	
	// ibagreement / trader_agreement
	//public $email;
	public $name;
	public $nameTwo;
	public $comName;
	
	// withdrawal
	public $account;
	public $reason;
	public $amount;
	public $currency;
	public $printName;
		
		public $beneficiary;
		public $bankName;
		public $bankAdress;
		public $bankAccount;
		public $address;
		public $swift;
		public $reference;
		public $intermBankName;
		public $iban;
        public $agree;
		
		public $purseNumer;
		public $accName;

		public $accNameWebNtlr;
		public $accEmailNtlr;

		public $accNameWeb;
		public $accEmail;

		public $accNameWebGlobe;
		public $accEmailGlobe;

        public $accEmailCashu;
        public $accNameWebCashu;

        public $usdtTrcAddress;

		public $email;		
	
	public $es_img;
	public $traderId;
	public $date;
	
	public $phone;
	public $repName;
	public $repEmail;
	public $repAddress;
	public $nationaly;
	public $closeTrAcc;
	
	public $docFullNames; 
	public $sendViaMail; 
	public $finishTexts; 
	
	public $MinAmountForWithdrawals; 
	public $MinAmmountForIbAccountWithdrwal; 
	
	public $recv_bank_code;
	public $branch_name;
	public $recv_province;
	public $recv_city;
	public $recv_name;
	public $recv_name_en;
	public $recv_accno;
	public $recv_accno2;

	public $tran_amount;

    public $ddbil_recv_bank_code;
	public $ddbil_branch_name;
	public $ddbil_recv_province;
	public $ddbil_recv_city;
	public $ddbil_recv_name;
	public $ddbil_recv_name_en;
	public $ddbil_recv_accno;
	public $ddbil_recv_accno2;

	public $to_acc_name;
	public $to_acc_name_en;
	public $to_acc_no;
	public $to_acc_no2;
	public $to_bank_name;
	public $to_pro_name;
	public $to_city_name;
	public $to_acc_dept;

	public $din_name;
	public $din_bank;
	public $din_branch;
	public $din_account;
	public $din_account2;

    public $cc_holder_name;
    public $cc_holder_address;
    public $cc_card_number;
    public $cc_reference;

    public $pep = 'No';
    public $sourceOfFunds;
    public $sourceOfFundsOther;

    public $branchAddress;
    public $bank_cc_card_number;
    public $ewallet;

    public $customer_name;
    public $customer_name_sign;
    public $customer_sign;
    public $customer_date;
    public $joint_customer_name;
    public $joint_customer_sign;
    public $joint_customer_date;

    public $userCount = 1;

    public $customerBankAccountName;
    public $customerBankAccountNumber;
    public $customerBankCode;
    public $customerBankRoutingNumber;
    public $customerEmail;
    public $customerFirstName;
    public $customerLastName;


		
	public function rules(){
		$model=new Registration('registration');
		$DinPay = new dinPay();
		$Account = new Account();
		$info = $Account->getInfo();


        $conditionArray = array();

		if(isset($info) && $this->getScenario() == 'bfopay_withdrawal' || $this->getScenario() == 'withdrawal' || $this->getScenario() == 'withdrawal_cn'){
			// bfopay withdrawal
			if(($info->Type == 6 && $info->GroupType == 2) || ($info->Type == 4 && $info->GroupType == 2)){
				$conditionArray = array(
					array('to_acc_name, to_acc_name_en, to_acc_no, to_acc_no2, to_bank_name, to_pro_name, to_city_name, to_acc_dept', 'required', 'message'=> Yii::t("main","36_cannot_be_blank"), 'on'=>'bfopay_withdrawal'),
					array('to_acc_name, to_acc_name_en, to_acc_no, to_acc_no2, to_bank_name, to_pro_name, to_city_name, to_acc_dept', 'length', 'min'=>0, 'max'=>256,'allowEmpty'=>true, 'on'=>'bfopay_withdrawal, withdrawal'),
				);
			}else{
				$conditionArray = array(
					array('to_acc_name, to_acc_name_en, to_acc_no, to_acc_no2, to_bank_name', 'required', 'message'=> Yii::t("main","36_cannot_be_blank"), 'on'=>'bfopay_withdrawal'),
					array('to_acc_name, to_acc_name_en, to_acc_no, to_acc_no2, to_bank_name', 'length', 'min'=>0, 'max'=>256, 'allowEmpty'=>true, 'on'=>'bfopay_withdrawal, withdrawal'),
					array('to_acc_name', 'checkAccNo', 'on'=>'bfopay_withdrawal'),
				);
			}

		}else{
			$conditionArray = array();
		}



		if($this->getScenario() == 'withdrawal' || $this->getScenario() == 'bank_withdrawal'){
            if(wlParams::get('officeCode') == 61){
                array_push($conditionArray,
                    // bank withdrawal
                    array('beneficiary, bankName, bankAdress, bankAccount, address, swift', 'required', 'on'=>'bank_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),	// , reference
                    array('bank_cc_card_number', 'safe', 'on'=>'bank_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),
                    array('amount, currency', 'checkAmount', 'on'=>'bank_withdrawal, withdrawal')
                );

            }elseif(Yii::app()->params['type'] == 'eforex' || Yii::app()->params['type'] == 'eforex_global'){
                $ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];

                array_push($conditionArray,
                    // bank withdrawal
                    array('bankName, bankAdress, bankAccount, swift', 'required', 'on'=>'bank_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),	// , reference
                   // array('branchAddress' /*, bank_cc_card_number*/, 'required', 'on'=>'bank_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),
                    array('ewallet, bank_cc_card_number', 'safe', 'on'=>'bank_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),
                    array('amount, currency', 'checkAmount', 'on'=>'bank_withdrawal, withdrawal')
                );
            }else{
                $conditionArray[] = array('beneficiary, bankName, bankAdress, bankAccount, address, swift', 'required', 'on'=>'bank_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank"));	// , referenc
                $conditionArray[] = array('iban', 'safe', 'on'=>'bank_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank"));	// , referenc
                // bank withdrawal
            }
        }

        if($this->getScenario() == 'withdrawal_cn' || $this->getScenario() == 'withdrawal' || $this->getScenario() == 'bank_withdrawal'){
            if(wlParams::get('officeCode') == 60){
                array_push($conditionArray,
                    array('iban', 'required', 'on'=>'withdrawal_cn, withdrawal, bank_withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank"))
                );
            }
        }



		/*if(wlParams::get('officeCode') == 32 && $this->getScenario() == 'withdrawal'){
            $conditionArray[] = array('agree', 'required', 'message'=> Yii::t("main","36_cannot_be_blank"), 'on'=>'withdrawal, bank_withdrawal');
            $conditionArray[] = array('agree', 'compare', 'compareValue' => 1, 'message' => Yii::t("funds","628_with_bank_agree_error"));
        }*/

        /*if ($_SERVER['REMOTE_ADDR'] == '77.222.143.18' || $_SERVER['REMOTE_ADDR'] == '46.98.252.74') {
            var_dump($conditionArray);die();
        }*/
		
		$array = array(
			array('sign', 'required', 'except'=>'partners', 'message'=> Yii::t("main","36_cannot_be_blank")),
			array('sign', 'required', 'except'=>'partners', 'message'=> Yii::t("main","36_cannot_be_blank")),

			// ibagreement

			array('name, comName', 'required', 'on'=>'ibagreement, noor_ibagreement, swissfssa_ibagreement, au_ibagreement, swissprime_ibagreement, swisscapital_ibagreement, bmfpro_dubai_ibagreement, swissfs_ibagreement', 'message'=> Yii::t("main","36_cannot_be_blank")),
			//array('email' , 'email', 'on'=>'ibagreement, noor_ibagreement','message' => Yii::t("main","22_this_email_address_is_not_a_valid")),
			array('name, comName', 'match','pattern' => '/^[a-z0-9`~!"@№%#\$;:\?\/\\&\*\+-_\(\)=\{\}\[\]\'|\<\>\s]*$/i','message' => Yii::t("main","34_only_latin_characters_allowed_for"), 'on'=>'ibagreement, noor_ibagreement, swissfssa_ibagreement, au_ibagreement, swissprime_ibagreement, swisscapital_ibagreement, bmfpro_dubai_ibagreement, swissfs_ibagreement'),
			array('name', 'match','pattern' => '/^[a-z0-9`"-_\(\)\'\s]*$/i','message' => Yii::t("main","34_only_latin_characters_allowed_for"), 'on'=>'handWriteCheck'),

			array('comName','match','pattern' => '/^\D*$/','message' => Yii::t("main","33_numbers_are_not_allowed_in"), 'on'=>'ibagreement, noor_ibagreement, swissfssa_ibagreement, au_ibagreement, swissprime_ibagreement, swisscapital_ibagreement, bmfpro_dubai_ibagreement, swissfs_ibagreement'),

			// trader_agreement
			array('name', 'required', 'on'=>'trader_agreement, noor_trader_agreement, swissfssa_trader_agreement, swisscapital_trader_agreement, swissfs_trader_agreement, bmfpro_dubai_trader_agreement, pfx_trader_agreement, marketis_trader_agreement', 'message'=> Yii::t("main","36_cannot_be_blank")),
			//array('email' , 'email', 'on'=>'trader_agreement, noor_trader_agreement, swissfssa_trader_agreement', 'message' => Yii::t("main","22_this_email_address_is_not_a_valid")),
			array('name', 'match', 'pattern' => '/^[a-z0-9`~!"@№%#\$;:\?\/\\&\*\+-_\(\)=\{\}\[\]\'|\<\>\s]*$/i','message' => Yii::t("main","34_only_latin_characters_allowed_for"), 'on'=>'trader_agreement, noor_trader_agreement, swissfssa_trader_agreement, swisscapital_trader_agreement, swissfs_trader_agreement, bmfpro_dubai_trader_agreement, pfx_trader_agreement, marketis_trader_agreement'),

            array('pep', 'required', 'on'=>'trader_agreement, ibagreement', 'message'=> Yii::t("main","36_cannot_be_blank")),
            array('sourceOfFundsOther', 'whenOther', 'on'=>'trader_agreement, ibagreement'),

			// withdrawal
			array('account', 'checkIfWithAllowed', 'on'=>'withdrawal, cc_withdrawal, bank_withdrawal, skrill_withdrawal, nowpay_withdrawal, usdt_withdrawal, neteller_withdrawal, cashu_withdrawal, globe_withdrawal, zotapay_withdrawal, webmoney_withdrawal, bfopay_withdrawal, dinpay_withdrawal, dinpay_withdrawal_auto, ddbil_withdrawal_auto', 'message'=>Yii::t("main","36_cannot_be_blank")),

			array('account, name, reason, amount, currency, printName, email', 'required', 'on'=>'withdrawal, cc_withdrawal, bank_withdrawal, skrill_withdrawal, nowpay_withdrawal, usdt_withdrawal, neteller_withdrawal, cashu_withdrawal, globe_withdrawal, zotapay_withdrawal, webmoney_withdrawal, bfopay_withdrawal, dinpay_withdrawal, dinpay_withdrawal_auto, ddbil_withdrawal_auto', 'message'=>Yii::t("main","36_cannot_be_blank")),
			array('account, name, amount, currency, printName, email', 'required', 'on'=>'withdrawal_cn', 'message'=>Yii::t("main","36_cannot_be_blank")),
			array('account, name, amount, currency, printName, email, beneficiary, bankName, bankAdress, bankAccount, branchAddress, address, swift, reference, purseNumer, accName, accNameWebNtlr, accEmailNtlr, accEmailCashu, accNameWebCashu, accEmailNtlr, accNameWebGlobe, accEmailGlobe, accEmail, accNameWeb, usdtTrcAddress, intermBankName', 'match', 'pattern' => '/^[a-z0-9`~!"@№%#\$;:\?\/\\&\*\+-_\(\)=\{\}\[\]\'|\<\>\s]*$/i','message' => Yii::t("main","34_only_latin_characters_allowed_for"), 'on'=>'withdrawal_cn, bank_withdrawal, skrill_withdrawal, nowpay_withdrawal,  usdt_withdrawal, neteller_withdrawal, cashu_withdrawal, globe_withdrawal, webmoney_withdrawal'),
			array('account, name, reason, amount, currency, printName, email, beneficiary, bankName, bankAdress, bankAccount, branchAddress, address, swift, reference, purseNumer, accName, accNameWebNtlr, accEmailNtlr, accEmailCashu, accNameWebCashu, accNameWebGlobe, accEmailGlobe, accEmail, accNameWeb, usdtTrcAddress, intermBankName, cc_holder_name, cc_holder_address, cc_card_number, cc_reference', 'match', 'pattern' => '/^[a-z0-9`~!"@№%#\$;:\?\/\\&\*\+-_\(\)=\{\}\[\]\'|\<\>\s]*$/i','message' => Yii::t("main","34_only_latin_characters_allowed_for"), 'on'=>'withdrawal, bank_withdrawal, cc_withdrawal, skrill_withdrawal, nowpay_withdrawal, usdt_withdrawal, neteller_withdrawal, cashu_withdrawal, globe_withdrawal, webmoney_withdrawal'),

            //array('cc_holder_name, cc_holder_address, cc_card_number, cc_reference', 'match', 'pattern' => '/^[a-z0-9`~!"@№%#\$;:\?\/\\&\*\+-_\(\)=\{\}\[\]\'|\<\>\s]*$/i','message' => Yii::t("main","34_only_latin_characters_allowed_for"), 'on'=>'withdrawal, cc_withdrawal'),

			array('account', 'numerical', 'integerOnly'=>true, 'on'=>'withdrawal, withdrawal_cn, cc_withdrawal, bank_withdrawal, skrill_withdrawal, nowpay_withdrawal, usdt_withdrawal, neteller_withdrawal, cashu_withdrawal, globe_withdrawal, zotapay_withdrawal, webmoney_withdrawal, dinpay_withdrawal, dinpay_withdrawal_auto, ddbil_withdrawal_auto, bfopay_withdrawal', 'message' => Yii::t("main","371_numbers_allowed")),
			array('amount', 'numerical', 'integerOnly'=>false, /*'max'=>10000,*/ 'on'=>'withdrawal, withdrawal_cn, cc_withdrawal, bank_withdrawal, skrill_withdrawal, nowpay_withdrawal, usdt_withdrawal, neteller_withdrawal, cashu_withdrawal, globe_withdrawal, zotapay_withdrawal, webmoney_withdrawal, dinpay_withdrawal, dinpay_withdrawal_auto, ddbil_withdrawal_auto, bfopay_withdrawal', 'message' => Yii::t("main","371_numbers_allowed")),
			array('amount, account', 'checkAmount', 'on'=>'withdrawal, withdrawal_cn, cc_withdrawal, bank_withdrawal, skrill_withdrawal, nowpay_withdrawal, usdt_withdrawal, neteller_withdrawal, cashu_withdrawal, globe_withdrawal, zotapay_withdrawal, webmoney_withdrawal, dinpay_withdrawal, dinpay_withdrawal_auto, ddbil_withdrawal_auto, bfopay_withdrawal'),

				//dinpay withdrawal
				array('din_name, din_bank, din_branch, din_account', 'required', 'on'=>'dinpay_withdrawal', 'message'=> Yii::t("main","36_cannot_be_blank")),
				array('din_name, din_bank, din_branch, din_account', 'length', 'min'=>0, 'max'=>256, 'allowEmpty'=>true, 'on'=>'dinpay_withdrawal, withdrawal'),
				array('din_account, din_account2', 'checkAccNoDinPay', 'on'=>'dinpay_withdrawal'),

				// dinpay auto withdrawal
				array('recv_accno, recv_accno2, recv_name, recv_name_en, recv_bank_code, recv_province, recv_city, branch_name', 'required', 'on'=>'dinpay_withdrawal_auto, withdrawal', 'message'=> Yii::t("main","36_cannot_be_blank")),
				array('recv_accno, recv_accno2, recv_name, recv_name_en, branch_name', 'length', 'min'=>1, 'max'=>30,'allowEmpty'=>true, 'on'=>'dinpay_withdrawal_auto, withdrawal'),
				array('recv_bank_code', 'in', 'range' => array_keys($DinPay->getBankCodes()), 'on'=>'dinpay_withdrawal_auto, withdrawal'),
				array('recv_province', 'in', 'range' => array_keys($DinPay->getProvinceCodes()), 'on'=>'dinpay_withdrawal_auto, withdrawal'),
				array('recv_city', 'in', 'range' => array_keys($DinPay->getCitiesCodes()), 'on'=>'dinpay_withdrawal_auto, withdrawal'),

                // ddbil auto withdrawal
				array('ddbil_recv_accno, ddbil_recv_accno2, ddbil_recv_name, ddbil_recv_name_en, ddbil_recv_bank_code, ddbil_recv_province, ddbil_recv_city, ddbil_branch_name', 'required', 'on'=>'ddbil_withdrawal_auto, withdrawal', 'message'=> Yii::t("main","36_cannot_be_blank")),
				array('ddbil_recv_accno, ddbil_recv_accno2, ddbil_recv_name, ddbil_recv_name_en, ddbil_branch_name', 'length', 'min'=>1, 'max'=>30,'allowEmpty'=>true, 'on'=>'ddbil_withdrawal_auto, withdrawal'),
				array('ddbil_recv_bank_code', 'in', 'range' => array_keys($DinPay->getBankCodes()), 'on'=>'ddbil_withdrawal_auto, withdrawal'),
				array('ddbil_recv_province', 'in', 'range' => array_keys($DinPay->getProvinceCodes()), 'on'=>'ddbil_withdrawal_auto, withdrawal'),
				array('ddbil_recv_city', 'in', 'range' => array_keys($DinPay->getCitiesCodes()), 'on'=>'ddbil_withdrawal_auto, withdrawal'),


				//array('reference', 'required', 'skipOnEmpty'=>true,  'on'=>'bank_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),	// , reference

				// webmoney withdrawal
				array('purseNumer, accName', 'required', 'on'=>'skrill_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),

                // nowpay withdrawal
				array('accNameWeb', 'required', 'on'=>'nowpay_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),

                // usdt withdrawal
				array('usdtTrcAddress', 'required', 'on'=>'usdt_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),


                // credit card withdrawal
				array('cc_holder_name, cc_holder_address, cc_card_number, cc_reference', 'required', 'on'=>'cc_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),

				// skrill withdrawal
				array('accEmail, accNameWeb', 'required', 'on'=>'webmoney_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),
				array('accEmail' , 'email', 'on'=>'webmoney_withdrawal, withdrawal', 'message' => Yii::t("main","22_this_email_address_is_not_a_valid")),

                // neteller withdrawal
				array('accNameWebNtlr, accEmailNtlr', 'required', 'on'=>'neteller_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),
				array('accEmailNtlr' , 'email', 'on'=>'neteller_withdrawal, withdrawal', 'message' => Yii::t("main","22_this_email_address_is_not_a_valid")),


                // cashu withdrawal
				array('accEmailCashu, accNameWebCashu', 'required', 'on'=>'cashu_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),
				array('accEmailCashu' , 'email', 'on'=>'cashu_withdrawal, withdrawal', 'message' => Yii::t("main","22_this_email_address_is_not_a_valid")),

                // globepay withdrawal
				array('accNameWebGlobe, accEmailGlobe', 'required', 'on'=>'globe_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),
				array('accEmailGlobe' , 'email', 'on'=>'globe_withdrawal, withdrawal', 'message' => Yii::t("main","22_this_email_address_is_not_a_valid")),

            // zotapay withdrawal
            array('customerBankAccountName, customerBankAccountNumber, customerBankCode, customerBankRoutingNumber, customerEmail, customerFirstName, customerLastName', 'required', 'on'=>'zotapay_withdrawal, withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),
            array('customerEmail' , 'email', 'on'=>'zotapay_withdrawal, withdrawal', 'message' => Yii::t("main","22_this_email_address_is_not_a_valid")),


			array('name', 'match','pattern' => '/^[a-z0-9`"-_\(\)\'\s]*$/i','message' => Yii::t("main","34_only_latin_characters_allowed_for"), 'on'=>'partners'),
			//array('date, name', 'required', 'on'=>'partners', 'message'=> Yii::t("main","36_cannot_be_blank")),

			//eu_withdrawal
			array('account, name, reason, amount, currency, printName, beneficiary, bankName, bankAdress, bankAccount, intermBankName, address, swift, reference, repAddress, nationaly, traderId, email', 'required', 'on'=>'eu_withdrawal, eu_withdrawal_corp', 'message'=>Yii::t("main","36_cannot_be_blank")),
			array('account, name, reason, amount, currency, printName, beneficiary, bankName, bankAdress, bankAccount, intermBankName, address, swift, reference, repAddress, nationaly, traderId', 'match','pattern' => '/^[a-z0-9`~!"@№%#\$;:\?\/\\&\*\+-_\(\)=\{\}\[\]\'|\<\>\s]*$/i','message' => Yii::t("main","34_only_latin_characters_allowed_for"), 'on'=>'eu_withdrawal, eu_withdrawal_corp'),
			array('email' , 'email', 'on'=>'eu_withdrawal, eu_withdrawal_corp', 'message' => Yii::t("main","22_this_email_address_is_not_a_valid")),
			array('closeTrAcc', 'required', 'on'=>'eu_withdrawal', 'message'=>Yii::t("main","959_choose_the_answer")),
			array('repName', 'required', 'on'=>'eu_withdrawal_corp', 'message'=>Yii::t("main","36_cannot_be_blank")),
			array('closeTrAcc', 'in', 'on'=>'eu_withdrawal, eu_withdrawal_corp', 'range' => array('Yes', 'No')),
			array('nationaly', 'in', 'on'=>'eu_withdrawal, eu_withdrawal_corp', 'range' => $model->GetCountry()),
			array('account', 'numerical', 'integerOnly'=>true, 'on'=>'eu_withdrawal, eu_withdrawal_corp','message' => Yii::t("main","371_numbers_allowed")),
			array('amount', 'numerical', 'integerOnly'=>false, 'on'=>'eu_withdrawal, eu_withdrawal_corp','message' => Yii::t("main","371_numbers_allowed")),
			array('amount, account', 'checkAmount', 'on'=>'eu_withdrawal, eu_withdrawal_corp'),


			//noor ibagreement
			//array('name, nameTwo, email, phone, bankName, swift, beneficiary, intermBankName, bankAccount, repName, repEmail', 'required', 'on'=>'noor_ibagreement', 'message'=> Yii::t("main","36_cannot_be_blank")),
			//array('name, nameTwo, email, phone, bankName, swift, beneficiary, intermBankName, bankAccount, repName, repEmail', 'match', 'pattern' => '/^[a-z0-9`~!"@№%#\$;:\?\/\\&\*\+-_\(\)=\{\}\[\]\'|\<\>\s]*$/i','message' => Yii::t("main","34_only_latin_characters_allowed_for"), 'on'=>'noor_ibagreement'),
			//array('email, repEmail' , 'email', 'on'=>'noor_ibagreement', 'message' => Yii::t("main","22_this_email_address_is_not_a_valid")),

			//noor withdrawal
			array('account, name, reason, amount, currency, bankAccount, bankName, bankAdress, swift, intermBankName, printName, email', 'required', 'on'=>'noor_withdrawal', 'message'=>Yii::t("main","36_cannot_be_blank")),
			array('account, name, reason, amount, currency, bankAccount, bankName, bankAdress, swift, intermBankName, printName, email', 'match','pattern' => '/^[a-z0-9`~!"@№%#\$;:\?\/\\&\*\+-_\(\)=\{\}\[\]\'|\<\>\s]*$/i','message' => Yii::t("main","34_only_latin_characters_allowed_for"), 'on'=>'noor_withdrawal'),
			array('amount, account', 'checkAmount', 'on'=>'noor_withdrawal'),



			array('customer_name, customer_name_sign, sign,' /*joint_customer_name, joint_customer_sign, customer_date,  joint_customer_date'*/, 'required', 'on'=>'interestFree, tradedu_interestFree', 'message'=> Yii::t("main","36_cannot_be_blank")),
            array('joint_customer_name, joint_customer_sign', 'safe', 'on'=>'interestFree, tradedu_interestFree', 'message'=> Yii::t("main","36_cannot_be_blank")),

            array('customer_name_sign, sign', 'required', 'on'=>'payment_policy', 'message'=> Yii::t("main","36_cannot_be_blank")),
            array('joint_customer_sign', 'safe', 'on'=>'payment_policy', 'message'=> Yii::t("main","36_cannot_be_blank"))
		);

        /*$ipx = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
        if ($ipx == '77.222.143.18' || $ipx == '46.98.252.74') {
            if(wlParams::get('officeCode') == 60){


                array_push($conditionArray,
                    array('intermBankName', 'required', 'on'=>'withdrawal_cn', 'message'=> Yii::t("main","36_cannot_be_blank"))
                );
            }
        } */

		return array_merge($array, $conditionArray);
	}

	public function init()
	{
        /*if ($_SERVER['REMOTE_ADDR'] == '77.222.143.18' || $_SERVER['REMOTE_ADDR'] == '46.98.252.74') {
            var_dump($this->getScenario());die();
        }*/
		$this->docFullNames = array('ibagreement'=>Yii::t("main","759_ibagreement"), 'trader_agreement'=>Yii::t("main","760_trader_agreement"), 'withdrawal'=>Yii::t("main","761_trader_agreement"));
		$this->sendViaMail= array('ibagreement'=>true, 'trader_agreement'=>true, 'withdrawal'=>false);
		$this->finishTexts = array('ibagreement'=>Yii::t("main","763_ibagreement_finish_text"));


		if($this->getScenario() != 'notLogin'){
			$account = new Account();
			$info = $account->GetInfo();
            $parentInfo = $account->getParentContacts();

			$this->date = time();

            // Arsen ask to set 50 static 3/26/2021
			// $MinAmountForWithdrawals = $account->GetSetting('MinAmountForWithdrawals');
            if(in_array(wlParams::get('officeCode'), [63])){
                $MinAmountForWithdrawals = 10;
            }else{
                $MinAmountForWithdrawals = 50;
            }

			$MinAmmountForIbAccountWithdrwal = $account->GetSetting('MinAmmountForIbAccountWithdrwal');


            if($parentInfo["Code"] == '16769' || $info->Login == '1000156546'){
                $MinAmountForWithdrawals = $MinAmmountForIbAccountWithdrwal = 250;
            }

            /*if ($_SERVER['REMOTE_ADDR'] == '77.222.143.18' || $_SERVER['REMOTE_ADDR'] == '46.98.252.74') {
            var_dump($parentInfo, $MinAmountForWithdrawals, $MinAmmountForIbAccountWithdrwal);die();
            }*/


			$this->MinAmountForWithdrawals = (is_numeric($MinAmountForWithdrawals)) ? $MinAmountForWithdrawals : 0;
			$this->MinAmmountForIbAccountWithdrwal = (is_numeric($MinAmmountForIbAccountWithdrwal)) ? $MinAmmountForIbAccountWithdrwal : 10000000;


            if(in_array(wlParams::get('officeCode'), [44, 60, 62])){
                $this->MinAmountForWithdrawals = 100;
            }

            /*$ipx = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
            if ($ipx == '77.222.143.18' || $ipx == '46.98.252.74') {
                $this->MinAmountForWithdrawals = 10;
            }*/




            /*if(Yii::app()->params['type'] == 'eforex' && in_array($this->getScenario(), ['bank_withdrawal', 'withdrawal']) && $this->currency == 'VND'){
                $this->MinAmountForWithdrawals = 100000;
            }*/


            /*if ($_SERVER['REMOTE_ADDR'] == '77.222.143.18' || $_SERVER['REMOTE_ADDR'] == '46.98.252.74') {
                var_dump($this->MinAmountForWithdrawals, $this->getScenario());die();
            }*/


            /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
            if ($ip == '162.13.154.241') {
                var_dump($this->getScenario());die();
            }*/

			if($this->getScenario() == 'ibagreement' || $this->getScenario() == 'noor_ibagreement' || $this->getScenario() == 'swissprime_ibagreement' || $this->getScenario() == 'swissfssa_ibagreement'  || $this->getScenario() == 'swisscapital_ibagreement' || $this->getScenario() == 'bmfpro_dubai_ibagreement' || $this->getScenario() == 'blademarkets_ibagreement'){
				if($info->Type==4 && $info->GroupType==2){
					$Registration = new RegistrationCompany();
					$Registration->initCompany();
					$this->name = $this->comName = $Registration->company_name;
				}else{
					$Registration = new Registration();
					$Registration->initIndv();
					//$this->email = $Registration->email;
					$this->name = $this->comName = $Registration->firstName.' '.$Registration->lastName;				
				}
			}/* elseif($this->getScenario() == 'noor_ibagreement'){
				$Registration = new Registration();
				$Registration->initIndv();
				if($info->Type==4 && $info->GroupType==2){
					$RegistrationCom = new RegistrationCompany();
					$RegistrationCom->initCompany();
					$this->email = $this->repEmail = $Registration->email;
					$this->phone = $Registration->phone;
					$this->name = $this->nameTwo = $this->repName = $RegistrationCom->company_name;
				}else{
					$this->email = $this->repEmail = $Registration->email;
					$this->phone = $Registration->phone;
					$this->name = $this->nameTwo = $this->repName = $Registration->firstName.' '.$Registration->lastName;					
				}
			} */elseif($this->getScenario() == 'trader_agreement' || $this->getScenario() == 'noor_trader_agreement'){
				$Registration = new Registration();
				$Registration->initIndv();
				//$this->email = $Registration->email;
				$this->name =  $Registration->firstName.' '.$Registration->lastName;
			}elseif($this->getScenario() == 'withdrawal' || $this->getScenario() == 'withdrawal_cn' || $this->getScenario() == 'bank_withdrawal' || $this->getScenario() == 'skrill_withdrawal' || $this->getScenario() == 'nowpay_withdrawal' || $this->getScenario() == 'neteller_withdrawal' || $this->getScenario() == 'cashu_withdrawal' || $this->getScenario() == 'globe_withdrawal' || $this->getScenario() == 'zotapay_withdrawal' || $this->getScenario() == 'webmoney_withdrawal' || $this->getScenario() == 'bfopay_withdrawal'){
				$Registration = new Registration();
				$Registration->initIndv();
                $this->customerEmail = $this->email = $Registration->email;
				/*if($info->Type==6 && $info->GroupType==2){



					$Registration = new RegistrationCompany();
					$Registration->initCompany();
					$this->to_acc_name_en = $this->recv_name_en = $this->ddbil_recv_name_en = $this->name = $this->printName = $Registration->company_name;
				}else{*/
					$this->to_acc_name_en = $this->recv_name_en = $this->ddbil_recv_name_en = $this->name = $this->printName = $Registration->firstName.' '.$Registration->lastName;
				//}


                /*$ipx = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
                if ($ipx == '77.222.143.18' || $ipx == '46.98.252.74') {
                    var_dump($Registration);die();
                }*/
                $this->customerFirstName =  $Registration->firstName;
                $this->customerLastName =  $Registration->lastName;
				
			}elseif($this->getScenario() == 'eu_withdrawal'){
				$Registration = new Registration();
				$Registration->initIndv();
				
				if(($info->Type==4 && $info->GroupType==2)){
					$Registration = new RegistrationCompany();
					$Registration->initCompany();
					$this->name = $this->printName = $this->beneficiary = $Registration->company_name;
				}elseif($info->Type==6 && $info->GroupType==2){
					$Registration = new RegistrationTrader('Corporate');
					$Registration->initTrader();
					$this->name = $this->printName = $this->beneficiary = $Registration->firstName;
				}else{
					$this->name = $this->printName = $this->beneficiary = $Registration->firstName.' '.$Registration->lastName;
					
					$this->nationaly = $Registration->country;
					$this->traderId = $Registration->idNum;
					$this->repAddress = $Registration->address;
				}
				$this->email = $Registration->email;				
			}elseif($this->getScenario() == 'noor_withdrawal' ){
				$Registration = new Registration();
				$Registration->initIndv();
				$this->email = $Registration->email;
				
				if(($info->Type==4 && $info->GroupType==2)){
					$Registration = new RegistrationCompany();
					$Registration->initCompany();
					$this->name = $this->printName =  $Registration->company_name;
				}elseif($info->Type==6 && $info->GroupType==2){
					$Registration = new RegistrationTrader('Corporate');
					$Registration->initTrader();
					$this->name = $this->printName = $Registration->firstName;
				}else{
					$this->name = $this->printName = $Registration->firstName.' '.$Registration->lastName;
				} 			
			}elseif($this->getScenario() == 'interestFree' || $this->getScenario() == 'payment_policy') {
                $Registration = new Registration();
                $Registration->initIndv();

                if (($info->Type == 4 && $info->GroupType == 2)) {
                    $Registration = new RegistrationCompany();
                    $Registration->initCompany();
                    $this->customer_name = $this->customer_name_sign = $Registration->company_name;
                } elseif ($info->Type == 6 && $info->GroupType == 2) {
                    $Registration = new RegistrationTrader('Corporate');
                    $Registration->initTrader();
                    $this->customer_name = $this->customer_name_sign = $Registration->firstName;
                } elseif ($info->Type == 6 && $info->GroupType == 3) {
                    /*$tmpRegist = new RegistrationTrader;
                    $partners = $tmpRegist->initPartner();*/

                    /*$ipx = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
                    if ($ipx == '77.222.143.18' || $ipx == '46.98.252.74') {
                        $first = array_shift($partners);
                        $this->customer_name = $this->customer_name_sign = $first->firstName.' '.$first->lastName;

                        $last = array_pop($partners);
                        $this->joint_customer_name = $last->firstName.' '.$last->lastName;
                    }*/

                    $this->customer_name = $this->customer_name_sign = $Registration->firstName . ' ' . $Registration->lastName;
                    $this->userCount = 2; //count($partners);
                } else {
                    $this->customer_name = $this->customer_name_sign = $Registration->firstName . ' ' . $Registration->lastName;
                }
            }/*elseif($this->getScenario() == 'zotapay_withdrawal'){
                $Registration = new Registration();
                $Registration->initIndv();

                $this->customerEmail =  $Registration->email;
                $this->customerFirstName =  $Registration->firstName;
                $this->customerLastName =  $Registration->lastName;

                $ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
                if ($ip == '77.222.143.18' || $ip == '46.98.252.74' || $ip == '46.98.20.51') {
                    var_dump($this->attributes);die();
                }


            }*/


		}
	}
	
	public function attributeLabels()
	{
		$scenarionLabels = array();
		$commonLabels = array(
			'sign'=>Yii::t("funds","531_echo_sign"),
		);
		 switch($this->getScenario())
		{
			case 'ibagreement':
				$scenarionLabels = array(				
					'email' => Yii::t("funds",'530_echo_email'),
					'name' => Yii::t("funds","533_name_company"),
					'comName' => Yii::t("funds","533_name_company"),
				);
			break;
			
			case 'trader_agreement':
				$scenarionLabels = array(				
					'email' => Yii::t("funds",'530_echo_email'),
					'name' => Yii::t("funds","533_name_company"),
				);
			break;
			
			case 'withdrawal':
			case 'withdrawal_cn':
			case 'bank_withdrawal':
			case 'skrill_withdrawal':
			case 'nowpay_withdrawal':
			case 'neteller_withdrawal':
			case 'cashu_withdrawal':
			case 'globe_withdrawal':
			case 'zotapay_withdrawal':
			case 'webmoney_withdrawal':
			case 'bfopay_withdrawal':
			case 'dinpay_withdrawal':
			case 'dinpay_withdrawal_auto':
			case 'ddbil_withdrawal_auto':
			case 'cc_withdrawal':
				$scenarionLabels = array(				
					'account' => Yii::t("funds",'535_wth_echo_cust_acc'),
					'name' => Yii::t("funds","534_wth_echo_cust_name"),
					'reason' => Yii::t("funds","537_wth_echo_reason"),
					'amount' => Yii::t("funds","536_wth_echo_amount"),
					'currency' => Yii::t("funds","538_wth_echo_curr"),
					'printName' => Yii::t("funds","551_wth_echo_print_name"),
					'email' => Yii::t("funds","530_echo_email"),
					
					'beneficiary' => Yii::t("funds","539_wth_echo_benific"),
					'bankName' => Yii::t("funds","540_wth_echo_bank_name"),
					'bankAdress' => Yii::t("funds","541_wth_echo_bank_adr"),
					'bankAccount' => Yii::t("funds","542_wth_echo_bank_acc"),
					'address' => Yii::t("funds","543_wth_echo_oter_adr"),
					'swift' => Yii::t("funds","545_wth_echo_swift"),
					'reference' => Yii::t("funds","546_wth_echo_ref"),
					'intermBankName' => Yii::t("funds","544_wth_echo_name_intrm_bank"),
					'iban' => Yii::t("funds","581_iban"),
					'agree' => Yii::t("funds","627_with_bank_agree"),

					'purseNumer' => Yii::t("funds","549_wth_echo_webmoney_purse"),
					'accName' => Yii::t("funds","550_wth_echo_webmoney_acc_name"),

                    'accEmailNtlr' => Yii::t("funds","549_wth_echo_webmoney_purse"),
					'accNameWebNtlr' => Yii::t("funds","550_wth_echo_webmoney_acc_name"),

                    'accEmailCashu' => Yii::t("funds","549_wth_echo_webmoney_purse"),
					'accNameWebCashu' => Yii::t("funds","550_wth_echo_webmoney_acc_name"),
					
					'accNameWeb' => Yii::t("funds","550_wth_echo_webmoney_acc_name"),
					'usdtTrcAddress' => Yii::t("funds","550_wth_echo_webmoney_acc_name"),
					'accEmail' => Yii::t("funds","547_wth_echo_skril_email"),
					'traderId'=>Yii::t("main","211_passport"),
					'repAddress'=>Yii::t("main","133_address"),
					'nationaly'=>Yii::t("main","958_nationaly"),
					'repName'=>Yii::t("main","957_rep_name"),

					'to_acc_name' => Yii::t("funds","591_recipient"),
					'to_acc_name_en' => Yii::t("funds","593_recipient_en"),
					'to_acc_no' => Yii::t("main","741_bank_account"),
					'to_acc_no2' => Yii::t("funds","594_reenter_bank_acc"),
					'to_bank_name' => Yii::t("funds","12_bank_name"),
					'to_pro_name' => Yii::t("funds","589_province_code"),
					'to_city_name' => Yii::t("funds","15_city"),
					'to_acc_dept' => Yii::t("funds","592_branch_bank_name"),
					
					'din_name' => Yii::t("funds","593_recipient_en"),
					'din_bank' => Yii::t("funds","12_bank_name"),
					'din_branch' => Yii::t("funds","592_branch_bank_name"),
					'din_account' => Yii::t("main","741_bank_account"),
					'din_account2' => Yii::t("funds","594_reenter_bank_acc"),
					
					'recv_accno' => Yii::t("main","741_bank_account"),
					'recv_accno2' => Yii::t("funds","594_reenter_bank_acc"),
					'recv_name' => Yii::t("funds","591_recipient"),
					'recv_name_en' => Yii::t("funds","593_recipient_en"),
					'recv_province' => Yii::t("funds","589_province_code"),
					'recv_city' => Yii::t("funds","590_city_code"),
					'recv_bank_code' => Yii::t("funds","12_bank_name"),
					'branch_name' => Yii::t("funds","592_branch_bank_name"),

                    'cc_holder_name' => Yii::t("funds",'490_name_of_card_holder'),
                    'cc_holder_address' => Yii::t("funds","621_addr_city_state_zip"),
                    'cc_card_number' => Yii::t("funds","532_credit_card_number"),
                    'cc_reference' => Yii::t("funds","546_wth_echo_ref"),
				);

                 if(in_array(wlParams::get('officeCode'), [63])){
                     $scenarionLabels['accNameWeb'] = Yii::t("funds","648_wallet_address");
                 }
             //$scenarionLabels

			break;
			
			
			/* case 'bfopay_withdrawal':
				$scenarionLabels = array(				
					'account' => Yii::t("main",'403_account_number'),
					'name' => Yii::t("funds","582_acc_name"),
					'reason' => Yii::t("funds","583_the_sum"),
					'amount' => Yii::t("funds","536_wth_echo_amount"),
					'currency' => Yii::t("funds","538_wth_echo_curr"),
					'printName' => Yii::t("funds","551_wth_echo_print_name"),
					'email' => Yii::t("funds","530_echo_email"),
					
					'to_acc_name' => Yii::t("funds","591_recipient"),
					'to_acc_no' => Yii::t("main","741_bank_account"),
					'to_bank_name' => Yii::t("funds","12_bank_name"),
					'to_pro_name' => Yii::t("funds","589_province_code"),
					'to_city_name' => Yii::t("funds","15_city"),
					'to_acc_dept' => Yii::t("funds","592_branch_bank_name"),
				); */
			
			
			case 'noor_withdrawal':
				$scenarionLabels = array(				
					'account' => Yii::t("main",'403_account_number'),
					'name' => Yii::t("funds","582_acc_name"),
					'reason' => Yii::t("funds","583_the_sum"),
					'amount' => Yii::t("funds","536_wth_echo_amount"),
					'currency' => Yii::t("funds","538_wth_echo_curr"),
					'printName' => Yii::t("funds","551_wth_echo_print_name"),
					'email' => Yii::t("funds","530_echo_email"),
					
					'bankAccount' => Yii::t("funds","17_account_"),
					'bankName' => Yii::t("funds","12_bank_name"),
					'bankAdress' => Yii::t("funds","541_wth_echo_bank_adr"),
					'swift' => Yii::t("funds","117_swift_code"),
					//'intermBankName' => Yii::t("funds","581_iban"),
				);
			break;

            /*case 'cc_withdrawal':
				$scenarionLabels = array(
					'cc_holder_name' => Yii::t("funds",'490_name_of_card_holder'),
					'cc_holder_address' => Yii::t("funds","621_addr_city_state_zip"),
					'cc_card_number' => Yii::t("funds","532_credit_card_number"),
					'cc_reference' => Yii::t("funds","546_wth_echo_ref"),
				);
			break;*/
		}
		
		return array_merge($commonLabels, $scenarionLabels);
	}
	
	public function checkAccNo($attribute,$params){
		if(!empty($this->to_acc_no) && !empty($this->to_acc_no2)){
			if($this->to_acc_no != $this->to_acc_no2){
				$this->addError('to_acc_no2', Yii::t("funds","595_account_numbers_dont_match"));
			}
		}
	}
	
	public function checkAccNoDinPay($attribute,$params){
		if(!empty($this->din_account) && !empty($this->din_account2)){
			//var_dump('2222');die();
			if($this->din_account != $this->din_account2){
				$this->addError('din_account2', Yii::t("funds","595_account_numbers_dont_match"));
			}
		}
	}
	
	public function checkAmount($attribute,$params){

        if(Yii::app()->params['type'] == 'eforex' && !empty($this->currency) && !empty($this->amount)){
            if($this->currency == 'VND' && (float)$this->amount < 1200000){
                $this->MinAmountForWithdrawals = 1200000;
                $this->clearErrors('amount');
                $this->addError('amount', Yii::t("funds","79_amount_cant_be_null", array('{min}'=>1200000)));
            }

        }


		if(!empty($this->account) && !empty($this->amount)){
			$Account = new Account();
			$info = $Account->getInfo();
			$accounts = $Account->GetAccount(array('live'));
			if($info->Type == 4){
				$sysAccounts = $Account->GetSysAccount();
				$accounts = array_merge($sysAccounts, $accounts);
				
				$isSys = false;
				foreach($sysAccounts as $sys){
					if($sys->AccountNum == abs($this->account)){
						$isSys = true;
						break;
					}
				}
				
				if($this->MinAmmountForIbAccountWithdrwal != '' && $this->amount < $this->MinAmmountForIbAccountWithdrwal && $isSys){
                    $this->clearErrors('amount');
					$this->addError('amount', Yii::t("funds","79_amount_cant_be_null", array('{min}'=>$this->MinAmmountForIbAccountWithdrwal)));
				}
			}



			foreach($accounts as $acc){

			    /*if($this->currency == 'INR'){
                    $this->MinAmountForWithdrawals = 3500;
                }*/

				if(abs($this->account) == abs($acc->AccountNum)){
					if($this->currency == $acc->Currency){
						$curAmount = $this->amount;

                        /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
                        if ($ip == '77.222.143.18' || $ip == '46.98.252.74' || $ip == '46.98.20.51') {
                            var_dump('222', $curAmount)     ;die();
                        }*/
					}else{
					    //var_dump('2222');die();
						$curAmount = stFunctions::currConv($this->currency, $acc->Currency, $this->amount);
                        /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
                        if ($ip == '77.222.143.18' || $ip == '46.98.252.74' || $ip == '46.98.20.51') {
                            var_dump('111', $curAmount, $this->currency, $acc->Currency, $this->amount)     ;die();
                        }*/
                    }



                    //if(Yii::app()->params['type'] != 'eforex'){
                        if((float)$acc->Balance < (float)$curAmount){
                            $this->clearErrors('amount');
                            $this->addError('amount', Yii::t("funds","572_you_dont_have_enough_funds_for_with"));
                        }

                        if(($this->MinAmountForWithdrawals != '' && $curAmount < $this->MinAmountForWithdrawals) ){
                            $this->clearErrors('amount');
                            $this->addError('amount', Yii::t("funds","79_amount_cant_be_null", array('{min}'=>$this->MinAmountForWithdrawals)));
                        }
                    //}

				}
			}
		}



		
		if($attribute == 'amount' && $this->amount == 0){
            $this->clearErrors('amount');
			$this->addError('amount', Yii::t("funds","567_AmountMustBeGreaterThanZero"));
		}
	}
	
	public function sendEchoRequest($fileType, $json, $url){

        if($url == 'https://my.sifxmarkets.sa.com/pdf/syncPdfGenerator.pdf' && $fileType != 1){
            $url = 'https://my.sifxmarkets.sa.com/pdf/syncPdfGenerator.pdf';
        }

            if($fileType == 42 || $fileType == 44 ){ // interestFree
                $data = json_decode($json, true);
                $fields = [
                    'customer_name' => ['FieldType' => 2, 'FieldKey' => 'customer_name', 'FieldValue' => '', 'Page' => 1],
                    'customer_name_sign' => ['FieldType' => 2, 'FieldKey' => 'customer_name_sign', 'FieldValue' => '', 'Page' => 1],
                    'sign' => ['FieldType' => 0, 'FieldKey' => 'customer_sign', 'FieldValue' => '', 'Page' => 1, 'XCoordinate' => 95,  'YCoordinate' => 65],
                    'customer_date' => ['FieldType' => 2, 'FieldKey' => 'customer_date', 'FieldValue' => '', 'Page' => 1],
                    'joint_customer_name' => ['FieldType' => 2, 'FieldKey' => 'joint_customer_name', 'FieldValue' => '', 'Page' => 1],
                    'joint_customer_sign' => ['FieldType' => 0, 'FieldKey' => 'joint_customer_sign', 'FieldValue' => '', 'Page' => 1, 'XCoordinate' => 350,  'YCoordinate' => 65],
                    'joint_customer_date' => ['FieldType' => 2, 'FieldKey' => 'joint_customer_date', 'FieldValue' => '', 'Page' => 1],
                ];
                $finalFields = [];
                foreach($data['formData'] as $key => $value){
                    if(isset($fields[$key])){
                        //var_dump('---'.$key.'---', $fields[$key]);
                        $fields[$key]['FieldValue'] = $value;
                        $finalFields[] = $fields[$key];
                    }
                }

                $finalFields[] = ['FieldType' => 2, 'FieldKey' => 'customer_date', 'FieldValue' => date("M j, Y"), 'Page' => 1, 'XCoordinate' => 500,  'YCoordinate' => 170];


                if(!empty($data['formData']['joint_customer_sign'])){
                    $finalFields[] = ['FieldType' => 2, 'FieldKey' => 'joint_customer_date', 'FieldValue' => date("M j, Y"), 'Page' => 1, 'XCoordinate' => 500,  'YCoordinate' => 170];
                }else{
                    $finalFields[] = ['FieldType' => 2, 'FieldKey' => 'joint_customer_date', 'FieldValue' => '', 'Page' => 1, 'XCoordinate' => 500,  'YCoordinate' => 170];
                }

                $data['formData'] = $finalFields;


                $json = json_encode($data);
            }
    //    }


        /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
        if ($ip == '162.13.154.241') {
            var_dump($fileType, $json, $url);die();
        }*/

        $Info = Yii::app()->curl->get(Yii::app()->params['json_server'].'/API/Registration/SaveEchoSignRequest?guid='.Yii::app()->user->id.'&fileType='.$fileType.'&json='.rawurlencode($json).'&url='.$url);

        /*$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
        if ($ip == '162.13.154.241') {
         var_dump($Info, Yii::app()->params['json_server'].'/API/Registration/SaveEchoSignRequest?guid='.Yii::app()->user->id.'&fileType='.$fileType.'&json='.rawurlencode($json).'&url='.$url);die();
        }*/

        $account = new Account();
        $info2 = $account->GetInfo();

		$f = fopen($_SERVER["DOCUMENT_ROOT"].'/protected/runtime/log/sendEchoRequest.txt',"a");
			fwrite($f, 'sendEchoRequest - '.Yii::app()->params['json_server'].'/API/Registration/SaveEchoSignRequest?guid='.Yii::app()->user->id.'&fileType='.$fileType.'&json='.rawurlencode($json).'&url='.$url.' | '.$info2->Login.' | '.Yii::app()->controller->id.' |'.json_encode($Info).'<br/>\n
			');
			
		/* if($_SERVER['REMOTE_ADDR'] == '46.98.252.74'){
			var_dump(Yii::app()->params['json_server'].'/API/Registration/SaveEchoSignRequest?guid='.Yii::app()->user->id.'&fileType='.$fileType.'&json='.rawurlencode($json).'&url='.$url, $Info);
		} */


        /*if($_SERVER['REMOTE_ADDR'] == '77.222.143.18' || $_SERVER['REMOTE_ADDR'] == '46.98.252.74'){

        }*/


		return $Info;
	}

    public function checkIfWithAllowed($attribute,$params)
    {
        if(!in_array(wlParams::get('officeCode'), [28, 29])){
            if(isset($this->account) && !empty($this->account)){
                $Info = Yii::app()->curl->get(Yii::app()->params['json_server'].'/API/Transactions/CanMakeWithdrawal?guid='.Yii::app()->user->id.'&accountId='.$this->account);
                if(is_string($Info) && $Info == 'WithdrawalAlreadyExist'){
                    $this->addError('account', Yii::t("funds","625_with_already_exists"));
                }
            }
        }
	}

    public function whenOther()
    {
        if($this->sourceOfFunds == 'Other' && empty($this->sourceOfFundsOther)){
            $this->addError('sourceOfFundsOther', str_replace('{attribute}', $this->getAttributeLabel('sourceOfFundsOther'), Yii::t("main","36_cannot_be_blank")));
        }
    }



}
