/** * Creates a new Vehicle model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Vehicle(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store($caseId) { $case = DataCase::find($caseId); if ($case) { $vechicle = new Vehicle(); $vechicle->fill(Input::all()); $vechicle->datacase()->associate($case); $vechicle->save(); } else { return null; } }
/** * Store a newly created resource in storage. * * @return Response */ public function store($personId) { $person = GuestHistory::find($personId); if ($person) { $vehicle = new Vehicle(); $vehicle->fill(Input::all()); $vehicle->guesthistory()->associate($person); $vehicle->save(); } else { return null; } return $person; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // return Input::all(); $datacase = new DataCase(); $datacase->fill(Input::except(["weapon", "vehicle"])); $datacase->save(); $data_vehicle = Input::get('vehicle'); $data_weapon = Input::get('weapon'); foreach ($data_vehicle as $datavehicle) { $vechicle = new Vehicle(); $vechicle->fill($datavehicle); $vechicle->datacase()->associate($datacase); $vechicle->save(); } foreach ($data_weapon as $dataweapon) { $weapom = new Weapon(); $weapom->fill($dataweapon); $weapom->datacase()->associate($datacase); $weapom->save(); } return $datacase; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // return Input::all(); $name_father = Input::get('datafather.father_name'); $surname_father = Input::get('datafather.father_surname'); $name_mother = Input::get('datamother.mother_name'); $surname_mother = Input::get('datamother.mother_surname'); $name_spouse = Input::get('dataspouse.spouse_name'); $surname_spouse = Input::get('dataspouse.spouse_surname'); $present_address = Input::get('addresspresent.present_address'); $original_address = Input::get('addressoriginal.original_address'); if (Auth::check()) { $IdPolice = Auth::user()->id; } if ($present_address != null) { $addresspresent = new AddressPresent(); $addresspresent->fill(Input::get('addresspresent')); $addresspresent->save(); } if ($original_address != null) { $addressoriginal = new AddressOriginal(); $addressoriginal->fill(Input::get('addressoriginal')); $addressoriginal->save(); } if ($name_mother != null || $surname_mother != null) { $datamother = new DataMother(); $datamother->fill(Input::get('datamother')); $datamother->save(); } if ($name_father != null || $surname_father != null) { $datafather = new DataFather(); $datafather->fill(Input::get('datafather')); $datafather->save(); } if ($name_spouse != null || $surname_spouse != null) { $dataspouse = new DataSpouse(); $dataspouse->fill(Input::get('dataspouse')); $dataspouse->save(); } $guesthistory = new GuestHistory(); $guesthistory->fill(Input::except(["addressoffice", "child", "employee", "family", "vehicle", "datamother", "dataspouse", "addressoriginal", "addresspresent", "datafather"])); if ($datamother != null) { $guesthistory->datamother()->associate($datamother); } if ($datafather != null) { $guesthistory->datafather()->associate($datafather); } if ($dataspouse != null) { $guesthistory->dataspouse()->associate($dataspouse); } if ($addressoriginal != null) { $guesthistory->addressoriginal()->associate($addressoriginal); } if ($addresspresent != null) { $guesthistory->addresspresent()->associate($addresspresent); } if ($IdPolice != null) { $police = Policeimmigration::find($IdPolice); $guesthistory->policeimmigration()->associate($police); } $guesthistory->save(); $address_office = Input::get('addressoffice'); $data_child = Input::get('datachild'); $data_employee = Input::get('employee'); $person_family = Input::get('personfamily'); $data_vehicle = Input::get('vehicle'); foreach ($data_employee as $dataemployee) { $employee = new \App\Models\Employee(); $employee->fill($dataemployee); $employee->guesthistory()->associate($guesthistory); $employee->save(); } foreach ($person_family as $datafamily) { $personfamily = new PersonFamily(); $personfamily->fill($datafamily); $personfamily->guesthistory()->associate($guesthistory); $personfamily->save(); } foreach ($data_vehicle as $datavehicle) { $vechicle = new \App\Models\Vehicle(); $vechicle->fill($datavehicle); $vechicle->guesthistory()->associate($guesthistory); $vechicle->save(); } foreach ($data_child as $child) { $datachild = new DataChild(); $datachild->fill($child); $datachild->guesthistory()->associate($guesthistory); $datachild->save(); } foreach ($address_office as $data_office) { $addressoffice = new AddressOffice(); $addressoffice->fill($data_office); $addressoffice->guesthistory()->associate($guesthistory); $addressoffice->save(); } Event::fire(new AddDataPersonGeneralEvent($guesthistory)); return $guesthistory; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { // return Input::all(); $caseFile = Input::get('caseFile'); $person = Input::get('person'); $name_father = Input::get('person.datafather.father_name'); $surname_father = Input::get('person.datafather.father_surname'); $name_mother = Input::get('person.datamother.mother_name'); $surname_mother = Input::get('person.datamother.mother_surname'); $name_spouse = Input::get('person.dataspouse.spouse_name'); $surname_spouse = Input::get('person.dataspouse.spouse_surname'); $present_address = Input::get('person.addresspresent.present_address'); $original_address = Input::get('person.addressoriginal.original_address'); if ($present_address != null) { $addresspresent = new AddressPresent(); $addresspresent->fill(Input::get('person.addresspresent')); $addresspresent->save(); } if ($original_address != null) { $addressoriginal = new AddressOriginal(); $addressoriginal->fill(Input::get('person.addressoriginal')); $addressoriginal->save(); } if ($name_mother != null || $surname_mother != null) { $datamother = new DataMother(); $datamother->fill(Input::get('person.datamother')); $datamother->save(); } if ($name_father != null || $surname_father != null) { $datafather = new DataFather(); $datafather->fill(Input::get('person.datafather')); $datafather->save(); } if ($name_spouse != null || $surname_spouse != null) { $dataspouse = new DataSpouse(); $dataspouse->fill(Input::get('person.dataspouse')); if (Input::has('person.dataspouse.nametitle.id')) { $nametitle = NameTitle::find(Input::get('person.dataspouse.nametitle.id')); $dataspouse->nametitle()->associate($nametitle); } $dataspouse->save(); } $criminalhistory = new CriminalHistory(); //$criminalhistory->fill(Input::except(["person.data_casefile","person.addressoffice","person.datachild"])); $criminalhistory->fill($person); if ($datamother != null) { $criminalhistory->datamother()->associate($datamother); } if ($datafather != null) { $criminalhistory->datafather()->associate($datafather); } if ($dataspouse != null) { $criminalhistory->dataspouse()->associate($dataspouse); } if ($addressoriginal != null) { $criminalhistory->addressoriginal()->associate($addressoriginal); } if ($addresspresent != null) { $criminalhistory->addresspresent()->associate($addresspresent); } if (Input::has('person.nametitle.id')) { $nametitle = NameTitle::find(Input::get('person.nametitle.id')); $criminalhistory->nametitle()->associate($nametitle); } $criminalhistory->save(); $addressoffice = Input::get('person.addressoffice'); $datachild = Input::get('person.datachild'); foreach ($addressoffice as $data_office) { $office = new AddressOffice(); $office->fill($data_office); $office->criminalhistory()->associate($criminalhistory); $office->save(); } foreach ($datachild as $data_child) { $child = new DataChild(); $child->fill($data_child); $child->criminalhistory()->associate($criminalhistory); $child->save(); } $name_case = Input::get('caseFile.name_case'); $circumstances_case = Input::get('caseFile.circumstances_case'); if ($name_case != null || $circumstances_case != null) { $datacase = new DataCase(); $datacase->fill($caseFile); $datacase->save(); $datacase->criminalhistory()->attach($criminalhistory); $data_vehicle = Input::get('caseFile.vehicle'); $data_weapon = Input::get('caseFile.weapon'); foreach ($data_vehicle as $datavehicle) { $vechicle = new Vehicle(); $vechicle->fill($datavehicle); $vechicle->datacase()->associate($datacase); $vechicle->save(); } foreach ($data_weapon as $dataweapon) { $weapom = new Weapon(); $weapom->fill($dataweapon); $weapom->datacase()->associate($datacase); $weapom->save(); } } Event::fire(new AddDataPersonCrimeEvent($criminalhistory)); return $criminalhistory; }
/** * Creates a new Bill model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Bill(); if (Yii::$app->session['carPartTotal'] <= 0.0) { return; } if (isset($_POST['mode'], $_POST['discount'])) { $result = []; if ($_POST['mode'] == 0 || $_POST['mode'] == 1) { $transaction = $model->getDb()->beginTransaction(); try { $discount = (double) $_POST['discount']; if ($discount > Yii::$app->session['carPartTotal']) { $discount = 0.0; } $modelPrice = new Price(); $modelPrice->price = (double) Yii::$app->session['carPartTotal'] - (double) $discount; $modelPrice->calculate(); if (!$modelPrice->save(false)) { throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($modelPrice->tableName())), 'msj' => print_r($modelPrice->getErrors(), true)]), 500); } $model->price_id = $modelPrice->id; $model->discount = $discount; if (isset($_POST['draft']) && !empty($_POST['draft'])) { $model->draft = 1; } if (isset($_POST['Vehicle'])) { $vehicle = new Vehicle(); $vehicle->attributes = $_POST['Vehicle']; if (!empty($vehicle->brand) || !empty($vehicle->model) || !empty($vehicle->color) || !empty($vehicle->plaque)) { if (!$vehicle->save(false)) { throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($vehicle->tableName())), 'msj' => print_r($vehicle->getErrors(), true)]), 500); } $model->vehicle_id = $vehicle->id; } } if (isset($_POST['Customer'])) { $customer = new Customer(); $customer->attributes = $_POST['Customer']; if (!empty($customer->name) || !empty($customer->serial)) { if (!$customer->save(false)) { throw new Exception(Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($customer->tableName())), 'msj' => print_r($customer->getErrors(), true)]), 500); } $model->customer_id = $customer->id; } } if ($model->save()) { $result['message'] = Yii::t('app', '{modelClass} saved', ['modelClass' => Yii::t('app', ucfirst($model->tableName()))]); } else { $result['message'] = Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($model->tableName())), 'msj' => print_r($model->errors, true)]); } $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); $result['message'] = Yii::t('app', 'Error saving {model}: {msj}', ['model' => Yii::t('app', ucfirst($model->tableName())), 'msj' => $e]); } } echo json_encode($result); } else { if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } }