/** * Store a newly created resource in storage. * POST /debtors * * @return Response */ public function store() { $contact = new Contact(); $contact->name = Input::get('contact_person'); $contact->email = Input::get('email'); $contact->phone = Input::get('phone'); $contact->mobile = Input::get('mobile'); $contact->web = Input::get('web'); $contact->fax = Input::get('fax'); $contact->save(); $contact_id = $contact->id; $company = new Company(); $company->name = Input::get('company_name'); $company->contact_id = $contact_id; $company->address = Input::get('address'); $company->postal_code = Input::get('postal_code'); $company->city = Input::get('city'); $company->country = Input::get('country'); $company->vat = Input::get('vat'); $company->coc = Input::get('coc'); $company->save(); $company_id = $company->id; //Billing $contact_billing = new Contact(); $contact_billing->name = Input::get('billing_contact_person'); $contact_billing->billing = 'true'; $contact_billing->save(); $contact_billing_id = $contact_billing->id; $company_billing = new Company(); $company_billing->name = Input::get('billing_company_name'); $company_billing->contact_id = $contact_billing_id; $company_billing->address = Input::get('billing_address'); $company_billing->postal_code = Input::get('billing_postal_code'); $company_billing->city = Input::get('billing_city'); $company_billing->country = Input::get('billing_country'); $contact_billing->billing = 'true'; $company_billing->save(); $company_billing_id = $contact_billing->id; $bank = new Bank(); $bank->name = Input::get('bank'); $bank->bic = Input::get('bic'); $bank->save(); $bank_id = $bank->id; $account = new Account(); $account->iban = Input::get('iban'); $account->name = Input::get('account_name'); $account->bank_id = $bank_id; $account->save(); $account_id = $account->id; //Debtor Save $debtor = new Debtor(); $debtor->no = Input::get('debtor_number'); $debtor->legal = Input::get('legal'); $debtor->company_id = $company_id; $debtor->billing_company_id = $company_billing_id; $debtor->account_id = $account_id; $debtor->group_id = Input::get('group'); $debtor->save(); return $this->index(); }
protected function _createNewBank($bank) { $model = new Bank(); $model->title = $bank['title']; $model->position = $bank['pos']; $model->license = $bank['license']; $model->save(); }
/** * Store a newly created resource in storage. * POST /banks * * @return Response */ public function store($companies) { $name = Input::get('name'); $bank = new Bank(); $bank->name = $name; $bank->company_id = $companies; $bank->save(); return $bank; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Bank(); if (isset($_POST['Bank'])) { $model->attributes = $_POST['Bank']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Store a newly created branch in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Bank::$rules, Bank::$messages); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $bank = new Bank(); $bank->bank_name = Input::get('name'); $bank->organization_id = '1'; $bank->save(); return Redirect::route('banks.index'); }
public function save() { foreach ($this->banks as $key => $bankInfo) { $bank = False; $bankResource = BankResources::model()->getBankResource($this->sourceType, $key)->find(); if ($bankResource) { $bank = Bank::model()->findByPk($bankResource->bank_id); } if (!$bank) { $bank = new Bank(); } foreach ($bankInfo as $sum => $info) { if (!$bank->id) { // $bank->phone = $info['info']['tel']; $bank->address = $info['info']['address']; $bank->name = $info['name']; $bank->save(); $bankResource = new BankResources(); $bankResource->bank_id = $bank->id; $bankResource->source_id = $this->sourceType; $bankResource->source_alias = $key; $bankResource->save(); $newBranch = new BankBranches(); $newBranch->address = $info['info']['address']; $yandexGeoDecode = @file_get_contents('http://geocode-maps.yandex.ru/1.x/?format=json&results=1&geocode=город Москва, ' . $newBranch->address); if ($yandexGeoDecode) { $answer = json_decode($yandexGeoDecode, True); if (!isset($answer['response']) && count($answer['response']['GeoObjectCollection']['featureMember']) == 0) { continue; } $pos = $answer['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['Point']['pos']; $pos = explode(' ', $pos); $newBranch->latitude = $pos[1]; $newBranch->longtitude = $pos[0]; $newBranch->preparePhone($info['info']['tel']); $newBranch->save(); $newBranch->bank_id = $bank->id; $newBranch->save(); } } if ($bank->id) { $cur = new BankCourses(); $cur->bank_id = $bank->id; $cur->buy = $info['pok']; $cur->sale = $info['prod']; $cur->sum = $sum; $cur->currency = $this->siteCurrencyType; $cur->save(); } } } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Bank(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Bank'])) { $model->attributes = $_POST['Bank']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
private function updatebank($client, $grid, $tt = 1) { $it = TmpXml::model()->findAll("ctype=:ctype AND ckey=:ckey AND user=:user", array(':ctype' => $tt == 1 ? 12 : 13, ':ckey' => $client, ':user' => Yii::app()->user->uid)); if (!($it === null)) { $new_bank = false; $bank_ps = array(); foreach ($it as $valu) { if ($valu->cname == 'id') { $bank_id = $valu->lname; $bank = Bank::model()->find("longname=:longname", array(':longname' => $bank_id)); if ($bank === null) { $new_bank = true; $bank = new Bank(); $bank->type_id = $tt; $bank->department_id = $grid; $bank->longname = $bank_id; $bank->name = $bank_id; $bank->save(); } } elseif ($valu->cname == 'host') { } else { $bank_ps[$valu->cname] = $valu->lname; } } if ($new_bank) { foreach ($bank_ps as $key => $valu) { $prop = new BankProp(); $prop->id = $bank->id; $prop->_key = $key; $prop->_value = $valu; $prop->save(); } } else { foreach ($bank_ps as $key => $valu) { if (!($prop = BankProp::model()->findByPk(array('id' => $bank->id, '_key' => $key)))) { $prop = new BankProp(); } $prop->id = $bank->id; $prop->_key = $key; $prop->_value = $valu; $prop->save(); } } } }
public function run($args) { $mem_start = memory_get_usage(); $url = 'http://www.banki.ru/api/'; $data = array('id' => '1', 'method' => 'bankInfo/getBankList', 'jsonrpc' => '2.0', 'params' => array('region_id' => array(4), 'show_on_banki' => array(0, 1, 2))); $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => json_encode($data))); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); $banks = json_decode($result, True); if (isset($banks['error'])) { print $banks['error']; die; } $banksData = array(); $bankNewId = array(); foreach ($banks['result']['data'] as $bankInfo) { switch ($bankInfo['region']) { case 'Москва': $source_bank_id = $bankInfo['bank_id']; $bank = Bank::model()->getBankResource(Yii::app()->params['sourceId']['bankiRu'], $source_bank_id)->find(); if (!$bank) { $bank = new Bank(); $bank->name = $bankInfo['bank_name']; $bank->source_id = Yii::app()->params['sourceId']['bankiRu']; $bank->source_alias = $source_bank_id; $bank->save(); } $bankNewId[$source_bank_id] = $bank->id; $banksData[$bank->id] = $bank; break; default: break; } } $data = array('id' => '2', 'method' => 'bankGeo/getObjectsByFilter', 'jsonrpc' => '2.0', 'params' => array('bank_id' => array_keys($bankNewId), 'limit' => 100000000, 'region_id' => array(4), 'type' => array('office', 'branch', 'cash'), 'with_empty_coordinates' => true)); $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => json_encode($data))); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); $branchData = json_decode($result, True); if (isset($branchData['error'])) { print_r($branchData['error']); die; } foreach ($branchData['result']['data'] as $branch) { $newBranch = BankBranches::model()->getBranchesResource(Yii::app()->params['sourceId']['bankiRu'], $branch['id'])->find(); if (!$newBranch) { $newBranch = new BankBranches(); $newBranch->address = $branch['address']; $data = array('id' => '3', 'method' => 'bank/getBankObjectsData', 'jsonrpc' => '2.0', 'params' => array('id_list' => array($branch['id']))); $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => json_encode($data))); $context = stream_context_create($options); $result = json_decode(file_get_contents($url, false, $context), true); $newBranch->latitude = $branch['latitude']; $newBranch->longtitude = $branch['longitude']; $newBranch->bank_id = $bankNewId[$branch['bank_id']]; if (!isset($result['error'])) { $ph = $newBranch->preparePhone($result['result']['data'][0]['phone']); if ($result['result']['data'][0]['is_main_office'] == 1) { if (isset($banksData[$bankNewId[$branch['bank_id']]])) { $b = $banksData[$bankNewId[$branch['bank_id']]]; $b->phone = $ph; $b->save(); } } } $newBranch->save(); } } echo memory_get_usage() - $mem_start; }
}); /* #################### IMPORT BANKS ################################## */ Route::post('import/banks', function () { if (Input::hasFile('banks')) { $destination = public_path() . '/migrations/'; $filename = str_random(12); $ext = Input::file('banks')->getClientOriginalExtension(); $file = $filename . '.' . $ext; Input::file('banks')->move($destination, $file); Excel::selectSheetsByIndex(0)->load(public_path() . '/migrations/' . $file, function ($reader) { $results = $reader->get(); foreach ($results as $result) { $bank = new Bank(); $bank->bank_name = $result->bank_name; $bank->organization_id = $result->organization_id; $bank->save(); } }); } return Redirect::back()->with('notice', 'banks have been succefully imported'); }); /* * ##################################################################################################################### */ /* * banks routes */ Route::resource('banks', 'BanksController'); Route::post('banks/update/{id}', 'BanksController@update'); Route::get('banks/delete/{id}', 'BanksController@destroy'); Route::get('banks/edit/{id}', 'BanksController@edit');
public function actionUpload() { parent::actionUpload(); $folder = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->request->baseUrl . '/upload/'; // folder for uploaded files $file = $folder . basename($_FILES['uploadfile']['name']); if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { $row = 0; if (($handle = fopen($file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { if ($row > 0) { $model = Bank::model()->findByPk((int) $data[0]); if ($model === null) { $model = new Bank(); } $model->addressbookid = (int) $data[0]; $model->fullname = $data[1]; $model->isbank = 1; $model->recordstatus = (int) $data[2]; try { if (!$model->save()) { $this->messages = $this->messages . Catalogsys::model()->getcatalog(' upload error at ' . $data[0]); } } catch (Exception $e) { $this->messages = $this->messages . $e->getMessage(); } } $row++; } } else { $this->messages = $this->messages . ' memory or harddisk full'; } fclose($handle); } else { $this->messages = $this->messages . ' check your directory permission'; } if ($this->messages == '') { $this->messages = 'success'; } echo $this->messages; }