public static function deal($uid, $data) { $loanSketch = LoanSketch::findByUid($uid); if (!$loanSketch) { return false; } $loan = Loan::findFirst("uid={$uid}"); if (!$loan) { $loan = new Loan(); $loan->addtime = time(); } $loan->uptime = time(); $loan->gps = 0; $loan->contract = 0; $loan->car_key = 0; $loan->pledge_notary = 0; $loan->remit_certify = 0; $loan->bank = ''; $loan->bank_card = ''; $data = array_merge($loanSketch, $data); $fields = ['uid', 'oid', 'amount', 'loan_type', 'deadline', 'repay_method', 'loan_type', 'use_type', 'use_type_info', 'deadline_type', 'days', 'apr', 'repay_source', 'description', 'reason', 'remark', 'status']; foreach ($data as $field => $value) { if (in_array($field, $fields)) { $loan->{$field} = $value; } } if ($loan->save()) { return true; } $loan->outputErrors($loan); return false; }
public function actionEmi() { $emi = ''; $loan = new Loan(); $emiData = array('amount' => '', 'interest' => '', 'year' => '', 'month' => '', 'type' => ''); if (isset($_POST['emi'])) { $year = ''; $months = ''; $amount = $_POST['amt']; $interest = $_POST['interest']; $year = $_POST['years']; $month = $year * 12; $interest_div = $interest / 1200; $top = $amount * $interest_div * pow(1 + $interest_div, $month); $bottom = pow(1 + $interest_div, $month) - 1; $emi = $top / $bottom; $emi = round($emi, 2); if ($_POST['type'] == 'years') { $emi = 12 * $emi; } $emiData = array('amount' => $amount, 'interest' => $interest, 'year' => $year, 'type' => $_POST['type']); } if (isset($_POST['loan'])) { $loan->attributes = $_POST['Loan']; if ($loan->validate()) { if ($loan->save()) { Yii::app()->user->setFlash('success', 'Your Request For Loan has been submitted'); $this->redirect('/emi'); } else { Yii::app()->user->setFlash('error', 'Your Request For Loan not submitted.Please <a href="/emi">retry</a>'); } } } $this->render('emi', array('emi' => $emi, 'loan' => $loan, 'emiData' => $emiData)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Loan(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Loan'])) { $model->attributes = $_POST['Loan']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Store a newly created resource in storage. * * @return [Response] */ public function store() { // Check for Borrower Name and 1 file $validator = Validator::make(Input::all(), array('last_name' => 'required', 'first_name' => 'required', 'documents.0' => 'required'), array('documents.0.required' => 'Please attach at least one document.')); if ($validator->fails()) { return Redirect::back()->withInput()->withErrors($validator); } // Create and Store the Loan try { // Save Loan $loan = new Loan(); $loan->borrower_last_name = Input::get('last_name'); $loan->borrower_first_name = Input::get('first_name'); $loan->user_id = $this->user->id; $loan->status_id = '1'; $loan->active = '1'; $loan->save(); // Save Transaction $transaction = new Transaction(); $transaction->loan_id = $loan->id; $transaction->user_id = $this->user->id; $transaction->transaction_type_id = "1"; $transaction->updated_item_id = $loan->id; $transaction->transaction_description = "Loan Created"; $transaction->save(); } catch (\RuntimeException $e) { Session::flash('alert_danger', 'Failed to create loan.'); return Redirect::back()->withInput(); } // Create and Store the Documents try { if (Input::hasFile('documents')) { // Get documents $files = Input::file('documents'); foreach ($files as $file) { $file_name = $file->getClientOriginalName(); $file_ext = $file->getClientOriginalExtension(); // Save Documents $document = new Document(); $document->loan_id = $loan->id; $document->filename = $file_name; $document->save(); // Save to filesystem with appropriate naming convention $directory = __DIR__ . '/../../../files/' . $this->user->id . '/' . $loan->id . '/'; $file = $file->move($directory, $file_name); // Save Transaction $transaction = new Transaction(); $transaction->loan_id = $loan->id; $transaction->user_id = $this->user->id; $transaction->transaction_type_id = "5"; $transaction->updated_item_id = $document->id; $transaction->transaction_description = "Document Created: " . $file_name; $transaction->save(); } } else { Session::flash('alert_warning', 'No documents were added. Please try again.'); return Redirect::back()->withInput(); } } catch (\RuntimeException $e) { Session::flash('alert_danger', 'Failed to create documents.'); return Redirect::back()->withInput(); } // On success, redirect to show Loan Session::flash('alert_success', 'Created loan successfully.'); return Redirect::to('loan/' . $loan->id); }
$transfer = Transfer::find_by_sql("SELECT * FROM transfers WHERE player = {$_GET['id']} AND returned = 0 ORDER BY start DESC"); if (isset($transfer[0])) { $transfer[0]->returned = time(); $transfer[0]->save(); } } if (isset($_POST['contFrom']) && isset($_POST['contTo'])) { $newCont = new Contract(); $newCont->set($_GET['id'], $_POST['team'], strtotime($_POST['contFrom']), strtotime($_POST['contTo'])); $newCont->save(); } if (isset($_POST['loanFrom']) && isset($_POST['loanTo'])) { $contractTeam = $player->find_contract_team(); $newLoan = new Loan(); $newLoan->set($_GET['id'], $contractTeam->id, $_POST['toteam'], strtotime($_POST['loanFrom']), strtotime($_POST['loanTo'])); $newLoan->save(); } if (isset($_POST['insTo'])) { $newIns = new Insurance(); $newIns->set($_GET['id'], strtotime($_POST['insTo'])); $newIns->save(); } if (isset($_POST['visaTo'])) { $newVisa = new Visa(); $newVisa->set($_GET['id'], strtotime($_POST['visaTo'])); $newVisa->save(); } if (isset($_POST['transFrom'])) { $newTrans = new Transfer(); $newTrans->set($_GET['id'], $_POST['assoc'], strtotime($_POST['transFrom'])); $newTrans->save();