public function rollback() { $this->assertFinished(); $this->finished = true; if (!$this->savepointName) { $this->db->rollback(); } else { $this->db->savepointRollback($this->savepointName); } }
function changeEmail() { $validator = new Validate(); $validated = $validator->validateNewEmail(); $user = \Auth::user(); $email = $user->email; if ($validated->fails()) { return \View::make('accounts.email')->withErrors($validated)->withEmail($email); } if (\Auth::check()) { $id = \Auth::user()->user_id; \DB::beginTransaction(); try { $statement = \User::find($id); $statement->email = \Input::get('email'); $statement->save(); } catch (ValidationException $e) { DB::rollback(); throw $e; } \DB::commit(); return \Redirect::to('admin/account/edit/email')->with('message', '<p class="alert alert-dismissible alert-success alert-link">Email address updated. </p>')->withEmail($email); } return \Redirect::to('admin/account/edit/email')->with('message', '<p class="alert alert-dismissible alert-success alert-link">Email address updated. </p>')->withEmail($email); }
/** * Execute the job. * * @return void */ public function handle() { try { //dd($this->req); \DB::begintransaction(); $me = \Me::data()->id_karyawan; // Create PO $po = data_po::create(['id_sph' => $this->req['id'], 'id_vendor' => $this->req['vendor'], 'deadline' => $this->req['deadline'], 'id_pembuat' => $me, 'id_acc' => 0, 'adjustment' => $this->req['adjustment'], 'diskon' => $this->req['gdiskon'], 'ppn' => $this->req['gppn'], 'keterangan' => $this->req['ket'], 'titipan' => $this->req['titipan']]); foreach ($this->req['id_barang'] as $i => $id_barang) { data_po_item::create(['id_po' => $po->id_po, 'id_item' => $id_barang, 'req_qty' => $this->req['qty'][$i], 'qty' => $this->req['qty'][$i], 'harga' => $this->req['harga'][$i], 'diskon' => $this->req['diskon'][$i], 'keterangan' => $this->req['kets'][$i], 'id_satuan' => $this->req['satuan'][$i], 'id_prq' => $this->req['id_prq'][$i]]); data_prq::find($this->req['id_prq'][$i])->update(['status' => 2]); // update Harga data_barang::find($id_barang)->update(['harga_beli' => $this->req['harga'][$i]]); // Update Log harga data_harga::create(['id_barang' => $id_barang, 'harga' => $this->req['harga'][$i], 'keterangan' => 'Update berdasarkan PO', 'id_po' => $po->id_po, 'id_karyawan' => $me, 'tipe' => 1]); data_prq_item::find($this->req['id_prq_item'][$i])->update(['status' => 2]); } $format = 'PO-'; $po->no_po = $format . \Format::code($po->id_po); $po->save(); \Loguser::create('Membuat PO dengan No. PO ' . $po->no_po); \DB::commit(); return ['result' => true, 'err' => 'PO berhasil dibuat dengan No. ' . $po->no_po]; } catch (\Exception $e) { \DB::rollback(); return ['result' => false, 'err' => $e->getMessage()]; } }
/** * Store a newly created resource in storage. * * @return Response */ public function store($quiz_id) { try { DB::beginTransaction(); $quiz = Quiz::find($quiz_id); foreach (Input::get('question') as $input_question) { $question_params = array("name" => $input_question['name']); $question_validator = Question::validate($question_params); if ($question_validator->fails()) { throw new Exception("Question can't be saved"); } $question = new Question($question_params); $question = $quiz->questions()->save($question); foreach ($input_question['options'] as $value) { $option_params = array("name" => $value['name'], "is_correct" => array_key_exists("is_correct", $value) ? true : false); $option_validator = Option::validate($option_params); if ($option_validator->fails()) { throw new Exception("Option can't be saved"); } $option = new Option($option_params); $option = $question->options()->save($option); } } DB::commit(); return Redirect::to("quizzes/" . $quiz->id . '/questions'); } catch (Exception $e) { DB::rollback(); //throw new Exception($e); return Redirect::to('quizzes/' . $quiz->id . '/questions/create'); } }
/** * Execute the job. * * @return void */ public function handle() { try { \DB::begintransaction(); $sph = data_sph::find($this->id); $grup = data_sph_grup::whereId_sph_grup($sph->id_sph_grup)->select('status')->first(); if ($grup->status == 2) { throw new \Exception("Maaf SPH No. " . $sph->no_sph_item . " sudah kadaluarsa!", 1); } $nsph = data_sph::create(['id_sph_grup' => $sph->id_sph_grup, 'id_vendor' => $sph->id_vendor, 'deadline' => $sph->deadline, 'id_pembuat' => \Me::data()->id_karyawan, 'id_acc' => $sph->id_acc, 'diskon' => $sph->diskon, 'ppn' => $sph->ppn, 'pph' => $sph->pph, 'adjustment' => $sph->adjustment]); $items = data_sph_item::whereId_sph($this->id)->get(); foreach ($items as $item) { data_sph_item::create(['id_sph' => $nsph->id_sph, 'id_prq' => $item->id_prq, 'id_item' => $item->id_item, 'qty' => $item->qty, 'harga' => $item->harga, 'diskon' => $item->diskon, 'ppn' => $item->ppn, 'pph' => $item->pph, 'id_satuan' => $item->id_satuan]); } $fo = 'ISPH/'; $nsph->no_sph_item = $fo . \Format::code($nsph->id_sph); $nsph->save(); \Loguser::create('Menduplikasi data SPH dari No. ' . $sph->no_sph_item); \DB::commit(); return ['err' => 'SPH berhasil di duplikasi dengan No. ' . $nsph->no_sph_item]; } catch (\Exception $e) { \DB::rollback(); return ['err' => $e->getMessage()]; } }
/** * Execute the job. * * @return void */ public function handle() { try { \DB::begintransaction(); /* KREDIT */ data_jurnal::create(['id_faktur' => $this->req['id_faktur'], 'id_coa_ledger' => $this->req['id_coa_ledger'], 'tanggal' => date('Y-m-d', strtotime($this->req['tanggal'])), 'deskripsi' => $this->req['deskripsi'], 'id_payment_methode' => $this->req['id_payment_methode'], 'tipe' => 2, 'total' => $this->req['total']]); /* DEBET */ data_jurnal::create(['id_faktur' => $this->req['id_faktur'], 'id_coa_ledger' => $this->req['perkiraan'], 'tanggal' => date('Y-m-d', strtotime($this->req['tanggal'])), 'deskripsi' => $this->req['deskripsi'], 'id_payment_methode' => $this->req['id_payment_methode'], 'tipe' => 1, 'total' => $this->req['total']]); $faktur = data_faktur::find($this->req['id_faktur']); if ($this->req['total'] == $this->req['total_old']) { $faktur->status = 2; } else { $faktur->status = 1; } $faktur->amount_due = $faktur->amount_due + $this->req['total']; $faktur->save(); /* KREDIT */ $coa = ref_coa_ledger::find($this->req['id_coa_ledger']); $coa->balance = $coa->balance + $this->req['total']; $coa->save(); /* DEBET */ $kira = ref_coa_ledger::find($this->req['perkiraan']); $kira->balance = $kira->balance + $this->req['total']; $kira->save(); \DB::commit(); return ['label' => 'success', 'err' => 'Payment berhasil dilakukan']; } catch (\Exception $e) { \DB::rollback(); return ['label' => 'danger', 'err' => $e->getMessage()]; } }
public function rebuild($start_date = null, $end_date = null) { if (!$start_date) { $start_date = config_option('last_sharing_table_rebuild'); } if ($start_date instanceof DateTimeValue) { $start_date = $start_date->toMySQL(); } if ($end_date instanceof DateTimeValue) { $end_date = $end_date->toMySQL(); } if ($end_date) { $end_cond = "AND updated_on <= '{$end_date}'"; } try { $object_ids = Objects::instance()->findAll(array('id' => true, "conditions" => "updated_on >= '{$start_date}' {$end_cond}")); $obj_count = 0; DB::beginWork(); foreach ($object_ids as $id) { $obj = Objects::findObject($id); if ($obj instanceof ContentDataObject) { $obj->addToSharingTable(); $obj_count++; } } set_config_option('last_sharing_table_rebuild', DateTimeValueLib::now()->toMySQL()); DB::commit(); } catch (Exception $e) { DB::rollback(); Logger::log("Failed to rebuild sharing table: " . $e->getMessage() . "\nTrace: " . $e->getTraceAsString()); } return $obj_count; }
public static function codigoAutorizacion($pago) { $sql = "\n Update parametros_tarjeta \n Set ultimo_nro_autorizacion = IsNull( ultimo_nro_autorizacion, 0 ) + 1 \n Where parametros_tarjeta.numero_orden = 1 "; $actualizar = DB::update($sql); if ($actualizar != 1) { DB::rollback(); return 'error'; } //--- Tomar último nro de autorización $sql = "\n Select parametros_tarjeta.ultimo_nro_autorizacion\n From parametros_tarjeta \n Where parametros_tarjeta.numero_orden = 1 "; $ultimo_nro_autorizacion = DB::select($sql)[0]->ultimo_nro_autorizacion * 1; /* // Armar el código de autorizacion // an_consumo_ticket = 2 // an_codigo_consumo = 0-contado 3-cuotas */ //$consumo_ticket = 2; if ($pago == 'cuotas') { $pago = 3; } if ($pago == 'contado') { $pago = 0; } return $ultimo_nro_autorizacion . '/2' . $pago; }
public function postAdminSettings() { $title = Input::get('title'); $about = Input::get('about'); $address = Input::get('address'); $phone = Input::get('phone'); $email = Input::get('email'); $location = Input::get('location'); $file = Input::file('file'); $destinationPath = 'uploads'; $filename = DB::table('settings')->first()->logo; // If the uploads fail due to file system, you can try doing public_path().'/uploads' if ($file) { $filename = time() . $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $upload_success = Input::file('file')->move($destinationPath, $filename); } DB::beginTransaction(); try { DB::table('settings')->where('id', 1)->update(array('title' => $title, 'logo' => $filename, 'about' => $about, 'address' => $address, 'phone' => $phone, 'email' => $email, 'location' => $location)); DB::commit(); return Redirect::route('getAdminSettings')->with(array('status' => 'success')); } catch (\Exception $e) { DB::rollback(); return Redirect::route('getAdminSettings')->with(array('status' => 'error')); } }
function add() { $pt = DB::escape(array_var($_GET, 'pt')); $t = DB::escape(array_var($_GET, 't')); $dep = ProjectTaskDependencies::findOne(array('conditions' => "`previous_task_id` = {$pt} AND `task_id` = {$t}")); if (!$dep instanceof ProjectTaskDependency) { try { DB::beginWork(); $dep = new ProjectTaskDependency(); $dep->setPreviousTaskId(array_var($_GET, 'pt')); $dep->setTaskId(array_var($_GET, 't')); $dep->save(); DB::commit(); } catch (Exception $e) { flash_error($e->getMessage()); DB::rollback(); } } flash_success(lang('success add task dependency')); $reload = array_var($_GET, 'reload', true); if ($reload) { ajx_current("reload"); } else { ajx_current("empty"); } }
function purge_trash() { Env::useHelper("permissions"); $days = config_option("days_on_trash", 0); $count = 0; if ($days > 0) { $date = DateTimeValueLib::now()->add("d", -$days); $objects = Objects::findAll(array("conditions" => array("`trashed_by_id` > 0 AND `trashed_on` < ?", $date), "limit" => 100)); foreach ($objects as $object) { $concrete_object = Objects::findObject($object->getId()); if (!$concrete_object instanceof ContentDataObject) { continue; } if ($concrete_object instanceof MailContent && $concrete_object->getIsDeleted() > 0) { continue; } try { DB::beginWork(); if ($concrete_object instanceof MailContent) { $concrete_object->delete(false); } else { $concrete_object->delete(); } ApplicationLogs::createLog($concrete_object, ApplicationLogs::ACTION_DELETE); DB::commit(); $count++; } catch (Exception $e) { DB::rollback(); Logger::log("Error delting object in purge_trash: " . $e->getMessage(), Logger::ERROR); } } } return $count; }
public function criar(array $dados) { \DB::beginTransaction(); try { $dados['status'] = 0; if (isset($dados['codigo_cupom'])) { $cupom = $this->cupomRepository->findByField('codigo', $dados['codigo_cupom'])->first(); $dados['cupom_id'] = $cupom->id; $cupom->used = 1; $cupom->save(); unset($dados['codigo_cupom']); } $items = $dados['items']; unset($dados['items']); $pedido = $this->repository->create($dados); $total = 0; foreach ($items as $item) { $item['preco'] = $this->produtoRepository->find($item['produto_id'])->preco; $pedido->items()->create($item); $total += $item['preco'] * $item['quantidade']; } $pedido->total = $total; if (isset($cupom)) { $pedido->total = $total - $cupom->valor; } $pedido->save(); \DB::commit(); return $pedido; } catch (\Exception $e) { DB::rollback(); throw $e; } }
public function saveBook(Request $request) { \DB::beginTransaction(); $this->cover = $this->upload($request); $this->title = $request->input('title'); $this->author = $request->input('author'); $this->translator = $request->input('translator'); $this->synopsis = $request->input('synopsis'); $this->origin = $request->input('origin'); $this->publishing_companies_id = $request->input('publishing_companies_id'); $this->language = $request->input('language'); $this->edition = $request->input('edition'); $this->year = $request->input('year'); $this->bar_code = $request->input('bar_code'); $this->isbn = $request->input('isbn'); $this->binding = $request->input('binding'); $this->height = floatval(str_replace(',', '.', $request->input('height'))); $this->width = floatval(str_replace(',', '.', $request->input('width'))); $this->length = floatval(str_replace(',', '.', $request->input('length'))); $this->weight = floatval(str_replace(',', '.', $request->input('weight'))); $this->number_pages = $request->input('number_pages'); if ($this->save()) { $this->genus()->sync($request->input('genus')); $success = true; } if ($success) { \DB::commit(); return true; } else { \DB::rollback(); return false; } }
public function postRegister(Request $request) { $dataClient = $request->only('name', 'last_name', 'phone', 'email'); $dataUser = $request->only('email', 'password'); $dataClientAddress = $request->only('id_city', 'address', 'latitude', 'longitude'); $validator = \Validator::make($dataClient, $this->rulesClient); if ($validator->passes()) { try { \DB::beginTransaction(); $dataUser['name'] = $dataClient['name'] . ' ' . $dataClient['last_name']; $dataUser['type'] = 'client'; $user = $this->userRepo->create($dataUser); $dataClient['id_user'] = $user->id; $client = $this->clientRepo->create($dataClient); $dataClientAddress['id_client'] = $client->id; $clientAddress = $this->clientAddressRepo->create($dataClientAddress); $code = 201; $message = "Cliente Registrado Corectamente"; $success = true; \DB::commit(); return response()->json(compact('success', 'message', 'client'), $code); } catch (\Exception $e) { \DB::rollback(); $code = 500; $success = false; $message = 'Error al registrar'; return response()->json(compact('success', 'message'), $code); } } else { $success = false; $message = $validator->messages(); $code = 400; return response()->json(compact('success', 'message'), $code); } }
public function updateBroadcasterProfile($request) { if ($request->hasFile('logo')) { $file = $request->file('logo'); $logo = time() . "-" . $file->getClientOriginalName(); $file->move(public_path() . \Config::get('site.broadcasterLogoPath'), $logo); $this->currentBroadcaster->logo = $logo; } $success = false; \DB::beginTransaction(); try { $this->currentUser->name = $request->get('name'); if ($request->get('changepass')) { $this->currentUser->password = \Hash::make(trim($request->get('password'))); } $this->currentUser->save(); $this->currentBroadcaster->display_name = $request->get('display_name'); $this->currentBroadcaster->company_name = $request->get('company_name'); $this->currentBroadcaster->save(); $success = true; } catch (\Exception $e) { \DB::rollback(); } if ($success) { \DB::commit(); } }
/** * Execute the job. * * @return void */ public function handle() { try { //dd($this->req); \DB::begintransaction(); $me = \Me::data()->id_karyawan; // Create PO $po = data_po::find($this->req['id']); $po->update(['id_vendor' => $this->req['vendor'], 'deadline' => $this->req['deadline'], 'adjustment' => $this->req['adjustment'], 'diskon' => $this->req['gdiskon'], 'ppn' => $this->req['gppn'], 'keterangan' => $this->req['ket']]); data_po_item::whereId_po($this->req['id'])->delete(); foreach ($this->req['id_barang'] as $i => $id_barang) { data_po_item::create(['id_po' => $po->id_po, 'id_item' => $id_barang, 'req_qty' => $this->req['qty'][$i], 'qty' => $this->req['qty'][$i], 'harga' => $this->req['harga'][$i], 'diskon' => $this->req['diskon'][$i], 'keterangan' => $this->req['kets'][$i], 'id_satuan' => $this->req['satuan'][$i]]); // update Harga data_barang::find($id_barang)->update(['harga_beli' => $this->req['harga'][$i]]); // Update Log harga data_harga::create(['id_barang' => $id_barang, 'harga_beli' => $this->req['harga'][$i], 'keterangan' => 'Update berdasarkan pembaharuan PO', 'id_po' => $po->id_po, 'id_karyawan' => $me]); } \Loguser::create('Melakukan perubahan data PO No. ' . $po->no_po); \DB::commit(); return ['result' => true, 'err' => 'PO berhasil diperbaharui']; } catch (\Exception $e) { \DB::rollback(); return ['result' => false, 'err' => $e->getMessage()]; } }
function console_create_user($args) { $fname = array_shift($args); $lname = array_shift($args); $email = array_shift($args); $admin = array_shift($args) == 'true'; if (is_null($fname) || is_null($lname) || is_null($email)) { throw new Exception('create_user: Missing arguments. Expected: (fname, lname, email, admin)'); } $display_name = $fname . " " . $lname; $username = str_replace(" ", "_", strtolower($display_name)); $user_data = array('username' => $username, 'display_name' => $display_name, 'email' => $email, 'password_generator' => 'random', 'timezone' => 0, 'autodetect_time_zone' => 1, 'create_contact' => false, 'company_id' => owner_company()->getId(), 'send_email_notification' => true, 'personal_project' => 0); // array try { DB::beginWork(); $user = create_user($user_data, $admin, ''); if (!$user->getContact() instanceof Contact) { $contact = new Contact(); $contact->setFirstName($fname); $contact->setLastName($lname); $contact->setEmail($email); $contact->setUserId($user->getId()); $contact->save(); } DB::commit(); } catch (Exception $e) { DB::rollback(); throw $e; } }
public function updateRestaurantInfo() { $user = \Auth::user(); $id = $user->user_id; $restaurant = \Restaurant::all(); foreach ($restaurant as $rest) { $restaurant_name = $rest->restaurant_name; $restaurant_street_1 = $rest->restaurant_street_1; $restaurant_street_2 = $rest->restaurant_street_2; $restaurant_phone = $rest->restaurant_phone; $restaurant_email = $rest->restaurant_email; $restaurant_id = $rest->restaurant_info_id; } \DB::beginTransaction(); try { $statement = \Restaurant::find($restaurant_id); $statement->restaurant_name = \Input::get('name'); $statement->restaurant_street_1 = \Input::get('address1'); $statement->restaurant_street_2 = \Input::get('address2'); $statement->restaurant_email = \Input::get('email'); $statement->restaurant_phone = \Input::get('phone'); $statement->user_id_fk = $id; $statement->save(); } catch (ValidationException $e) { DB::rollback(); throw $e; } \DB::commit(); return \Redirect::to('admin/account/edit/restaurant')->withRestaurantName($restaurant_name)->withRestaurantStreet_1($restaurant_street_1)->withRestaurantStreet_2($restaurant_street_2)->withRestaurantPhone($restaurant_phone)->withRestaurantEmail($restaurant_email)->with('message', '<p class="alert alert-dismissible alert-success alert-link">Saved!' . '</p>'); }
/** * Execute the job. * * @return void */ public function handle() { //dd($this->req); try { \DB::begintransaction(); $parent_id = empty($this->req['parent_id']) ? 0 : $this->req['parent_id']; $file = ''; if (!empty($_FILES['feed_file']['tmp_name'])) { $base_name = date('d_m_Y_') . md5($_FILES['feed_file']['name']) . rand(11111, 99999) . time(); $fl_name = $base_name . '.png'; $fl = file_get_contents($_FILES['feed_file']['tmp_name']); \Image::make($fl)->save($this->path . $fl_name); $file = $fl_name; } $feed = data_feedback::create(['title' => $this->req['feed_title'], 'ask' => $this->req['feed_ask'], 'link' => $this->req['feed_link'], 'parent_id' => $parent_id, 'file' => $file, 'id_karyawan' => \Me::data()->id_karyawan]); $kode = \Format::code($feed->id_feedback); $feed->kode = $kode; $feed->save(); if ($parent_id > 0) { $up = data_feedback::find($parent_id); $up->notif = $up->notif + 1; $up->save(); } \Loguser::create('Megisi form feedback Kode. #' . $kode); \DB::commit(); return ['label' => 'success', 'err' => 'Feedback berhasil terkirim dengan Kode. ' . $feed->kode]; } catch (\Exception $e) { \DB::rollback(); if (file_exists($this->path . $file)) { @unlink($this->path . $file); } return ['label' => 'danger', 'err' => $e->getMessage()]; } }
public function newCategory() { $validate = new Validate(); $validated = $validate->Validate_Category(); $nameToSlug = $this->nameToSlug($validated); if (\Auth::check()) { if ($validated->passes() && $nameToSlug === true) { $slug = \Input::get('name'); $slug = preg_replace('#[ -]+#', '-', $slug); $slug = strtolower($slug); \DB::beginTransaction(); try { $item = new \MenuCategory(); $item->menu_category_name = \Input::get('name'); $item->menu_category_slug = $slug; $item->save(); } catch (ValidationException $e) { DB::rollback(); throw $e; } \DB::commit(); return \Redirect::to('admin/category/edit/' . $slug)->with('message', '<div class="alert alert-dismissible alert-success alert-link"><button type="button" class="close" data-dismiss="alert">×</button>Saved!</p></div>'); } if ($nameToSlug === false) { return \View::make('categories.new')->withErrors($validated)->withInput(array('name'))->with('message', '<p class="alert alert-dismissible alert-danger alert-link">That category already exists!'); } return \View::make('categories.new')->withErrors($validated)->withInput(array('name')); } return \Redirect::to('admin'); }
/** * Execute the job. * * @return void */ public function handle() { try { \DB::begintransaction(); $me = \Me::data()->id_karyawan; $retur = data_retur::create(['tipe' => 2, 'id_po' => $this->req['id_po'], 'id_vendor' => $this->req['id_vendor'], 'id_karyawan' => $me]); data_po::find($this->req['id_po'])->update(['status' => 2]); foreach ($this->req['id_barang'] as $i => $id_barang) { if (!empty($this->req['qty'][$i])) { data_retur_item::create(['id_retur' => $retur->id_retur, 'id_barang' => $id_barang, 'id_satuan' => $this->req['id_satuan'][$i], 'qty' => $this->req['qty'][$i], 'qty_lg' => $this->req['qty'][$i]]); // Log Stok data_log_barang::create(['id_barang' => $id_barang, 'qty' => $this->req['qty'][$i], 'id_gudang' => 0, 'kondisi' => 2, 'tipe' => 5, 'id_parent' => $retur->id_retur, 'id_karyawan' => $me]); // Update stok $barang = data_barang::find($id_barang); $barang->out = $barang->out + $this->req['qty'][$i]; $barang->save(); // Update data PO items $itm = data_po_item::where('id_po', $this->req['id_po'])->where('id_item', $id_barang)->first(); $qpo = $itm->qty + $this->req['qty'][$i]; data_po_item::where('id_po', $this->req['id_po'])->where('id_item', $id_barang)->update(['qty' => $qpo, 'status' => 1]); } } $format = 'EX-RTN-'; $kode = $format . \Format::code($retur->id_retur); $retur->no_retur = $kode; $retur->save(); \Loguser::create('Membuat Retur Pembelian dengan No. ' . $kode); \DB::commit(); return ['result' => true, 'label' => 'success', 'err' => 'Return Pembelian berhasil dibuat dengan No. ' . $kode]; } catch (\Exception $e) { \DB::rollback(); return ['result' => false, 'label' => 'danger', 'err' => $e->getMessage()]; } }
public function deleteCategoryInfo($slug) { $results = \MenuCategory::where('menu_category_slug', '=', $slug)->get(); foreach ($results as $result) { $id = $result->menu_category_id; } $items_using_cat = \MenuItem::where('menu_item_category_fk', '=', $id)->get(); foreach ($items_using_cat as $item_using_cat) { if ($item_using_cat) { return \Redirect::to("admin/category/edit/{$slug}")->with('message', '<div class="alert alert-dismissible alert-danger alert-link">Unable to delete category. Please make sure no items are using this category.</p></div>'); } } //if an item exists that has this cat's fk, reload the page with an error if (\Auth::check()) { \DB::beginTransaction(); try { $statement = \MenuCategory::find($id); $statement->delete(); } catch (ValidationException $e) { DB::rollback(); throw $e; } \DB::commit(); return \Redirect::to('admin')->with('message', '<div class="alert alert-dismissible alert-success alert-link">Category has been deleted</p></div>'); } return \Redirect::to('admin'); }
function changePassword() { $validator = new Validate(); $validated = $validator->validateNewPassword(); if ($validated->fails()) { return \View::make('accounts.password')->withErrors($validated); } if (\Auth::check()) { $hashed = \Hash::make(\Input::get('password')); $id = \Auth::user()->user_id; \DB::beginTransaction(); try { $statement = \User::find($id); $statement->password = $hashed; $statement->save(); } catch (ValidationException $e) { DB::rollback(); throw $e; } \DB::commit(); \Auth::logout(); return \Redirect::to('admin/logout')->with('message', '<div class="alert alert-dismissible alert-success alert-link"> <button type="button" class="close" data-dismiss="alert">×</button> Password changed. Please log in. </div>'); } return \Redirect::to('admin')->with('message', '<div class="alert alert-dismissible alert-success alert-link"> <button type="button" class="close" data-dismiss="alert">×</button> Password changed. Please log in. </div>'); }
public function postRegistroEmpresas() { DB::beginTransaction(); try { $empresa = new LandingEmpresa(); $empresa->razon_social = ucwords(strtolower(Input::get('empresa_razonsocial'))); $empresa->ruc = Input::get('empresa_ruc'); $empresa->inscritos = Input::get('empresa_inscritos'); $empresa->domicilio = Input::get('empresa_domicilio'); $empresa->email = Input::get('empresa_email'); $empresa->telefono = Input::get('empresa_telefono'); $empresa->celular = Input::get('empresa_celular'); $empresa->curso = Input::get('empresa_curso'); $empresa->comentario = Input::get('empresa_comentario'); $empresa->recibir_noticias = Input::get('empresa_informacion'); $empresa->ip = Request::getClientIp(true); $empresa->save(); $respuesta = array('status' => 'ok'); DB::commit(); } catch (\Exception $e) { DB::rollback(); $respuesta = array('status' => 'error', 'messages' => 'Exception with msg: ' . $e->getMessage()); } return Response::json($respuesta, 200); }
public function postSchimbaStadiu($id_livrabil) { $actualizare_ore = Input::get('ore_lucrate') > 0; $is_stadiu = Input::get('stadiu_selectionat') != null && Input::get('stadiu_selectionat') > 0; $array_update = array(); if ($is_stadiu) { //Face insert in tabela de istoric de stadii //Actualizeaza stadiul livrabilului $array_update = array_add($array_update, 'id_stadiu', Input::get('stadiu_selectionat')); } if ($actualizare_ore) { //Actualizeaza numarul de ore lucrate la acest livrabil $array_update = array_add($array_update, 'ore_lucrate', Input::get('ore_lucrate')); } // Start transaction! DB::beginTransaction(); if ($is_stadiu) { try { DB::table('istoric_stadii_livrabil')->insertGetId(array('id_livrabil_etapa' => Input::get('id_livrabil_etapa'), 'id_stadiu' => Input::get('stadiu_selectionat'), 'id_user' => Entrust::user()->id)); } catch (Exception $e) { DB::rollback(); return Redirect::back()->with('message', 'Eroare salvare date: ' . $e); } } if ($is_stadiu || $actualizare_ore) { try { DB::table('livrabile_etapa')->where('id', Input::get('id_livrabil_etapa'))->update($array_update); } catch (Exception $e) { DB::rollback(); return Redirect::back()->with('message', 'Eroare salvare date: ' . $e); } } DB::commit(); return Redirect::back()->with('message', 'Actualizare realizata cu succes!')->withInput(); }
public function storage() { $token = \Input::get('_token'); if (\Session::token() === $token) { $data = array('ten_vi' => Input::get('ten_vi'), 'hienthi' => Input::has('hienthi'), 'parent' => Input::get('category'), 'slug_vi' => \Str::slug(Input::get('ten_vi'), '-'), 'title_seo_vi' => Input::get('title_seo_vi'), 'desc_seo_vi' => Input::get('desc_seo_vi'), 'keyword_seo_vi' => Input::get('keyword_seo_vi')); \DB::beginTransaction(); try { $result = $this->danhmuc->create($data); $t = $this->danhmuc->find($result->id); if (Input::hasFile('photo')) { // LAY TEN FILE $filename = \Str::random(20) . '_' . Input::file('photo')->getClientOriginalName(); // THU MUC UPLOAD TIN TUC $directory = \Config::get('detr.danhmuc_upload'); $upload_status = Input::file('photo')->move(public_path() . $directory, $filename); chmod(public_path() . $directory . $filename, 0755); if ($upload_status) { $t->photo = $directory . $filename; $thumb = \Illuminage::image($directory . $filename)->thumbnail(200, 200)->getRelativePath(); $t->thumb = $thumb; chmod(public_path() . '/' . $thumb, 0755); } $t->save(); } } catch (\Exception $e) { \DB::rollback(); return \Redirect::back()->with('success', 'Thêm thất bại - thử lại!'); } \DB::commit(); return \Redirect::to('/quanly/dmsp'); } else { return \Redirect::back()->withInput()->with('success', 'Thêm mới thất bại, Token hết hiệu lực'); } }
public function create(array $data) { DB::beginTransaction(); try { $data['status'] = 0; if (isset($data['cupom_code'])) { $cupom = $this->cupomRepository->findByField('code', $data['cupom_code'])->first(); $data['cupom'] = $cupom->id; $cupom->used = 1; $cupom->save(); unset($data['cupom_code']); } $items = $data['items']; unset($data['items']); $order = $this->orderRepository->create($data); $total = 0; foreach ($items as $item) { $item['price'] = $this->productRepository->find($item['product_id'])->price; $order->items()->create($item); $total += $item['price'] * $item['qtd']; } $order->total = $total; if (isset($cupom)) { $order->total = $total - $cupom->value; } $order->save(); \DB::commit(); } catch (\Exception $e) { \DB::rollback(); throw $e; } }
public static function ingresoCtaCte($ctacte_id) { DB::begintransaction(); try { $CC = Ctacte::findOrFail($ctacte_id); $data = array("caja_id" => $CC->caja_id, "importe" => 0, "ingreso_egreso" => "I", "fecha" => date("Y-m-d"), "hora" => date("H:i:s"), "user_id" => Auth::user()->id, "tipo_mov_caja_id" => 2, "medios_pago_caja_id" => NULL, "ctacte_id" => $CC->id); $lineas_rec = $CC->lineas_recibo()->get(); //dd($lineas_rec->toArray()); foreach ($lineas_rec as $pago) { $MC = new MovimientoCaja(); $data_pago = $data; $data_pago["importe"] = $pago->importe; $query = MedioPagoCaja::where('tipo', '=', $pago->tipo); if ($pago->tipo_cambio > 0) { $query->where('moneda', '=', 'DOL'); } else { $query->where('moneda', '=', 'ARS'); } $MP = $query->first(); $data_pago["medios_pago_caja_id"] = $MP->id; $MC->fill($data_pago); if (!$MC->save()) { DB::rollback(); return false; } } DB::commit(); return true; } catch (Exception $e) { DB::rollback(); return Response::json(array('error' => true, 'mensaje' => $e->getMessage()), 200); } }
/** * Execute the job. * * @return void */ public function handle() { try { \DB::begintransaction(); if ($this->req['id'] < 1) { $group = data_sph_grup::create(['id_pembuat' => \Me::data()->id_karyawan]); } else { $group = data_sph_grup::find($this->req['id']); \Loguser::create('Menambahkan Pengajuan pada SPH No. ' . $group->no_sph); } $sph = data_sph::create(['id_sph_grup' => $group->id_sph_grup, 'id_vendor' => $this->req['vendor'], 'deadline' => $this->req['deadline'], 'id_pembuat' => \Me::data()->id_karyawan, 'id_acc' => 0, 'diskon' => $this->req['gdiskon'], 'ppn' => $this->req['gppn'], 'adjustment' => $this->req['adjustment'], 'keterangan' => $this->req['ket']]); foreach ($this->req['id_prq_item'] as $i => $id_prq_item) { data_sph_item::create(['id_sph' => $sph->id_sph, 'id_prq' => $this->req['id_prq'][$i], 'id_item' => $this->req['id_barang'][$i], 'qty' => $this->req['qty'][$i], 'harga' => $this->req['harga'][$i], 'diskon' => $this->req['diskon'][$i], 'keterangan' => $this->req['kets'][$i], 'id_satuan' => $this->req['satuan'][$i]]); data_prq::find($this->req['id_prq'][$i])->update(['status' => 2]); } if ($this->req['id'] < 1) { $format = 'G-SPH/'; $group->no_sph = $format . \Format::code($group->id_sph_grup); $group->save(); \Loguser::create('Membuat Surat Pengajuan Harga dengan No. ' . $group->no_sph); } $fo = 'SPH/'; $sph->no_sph_item = $fo . \Format::code($sph->id_sph); $sph->save(); \DB::commit(); return ['status' => true, 'err' => $group]; } catch (\Exception $e) { \DB::rollback(); return ['status' => false, 'err' => $e->getMessage()]; } }
/** * Execute the job. * * @return void */ public function handle() { //dd($this->req); try { \DB::begintransaction(); $parent_id = empty($this->req['parent_id']) ? 0 : $this->req['parent_id']; $file = $this->req['file']; if (!empty($_FILES['feed_file']['tmp_name'])) { $base_name = date('d_m_Y_') . md5($_FILES['feed_file']['name']) . rand(11111, 99999) . time(); $fl_name = $base_name . '.png'; $fl = file_get_contents($_FILES['feed_file']['tmp_name']); \Image::make($fl)->save($this->path . $fl_name); $file = $fl_name; if (file_exists($this->path . $this->req['file'])) { @unlink($this->path . $this->req['file']); } } $title = empty($this->req['feed_title']) ? '' : $this->req['feed_title']; $link = empty($this->req['feed_link']) ? '' : $this->req['feed_link']; $feed = data_feedback::find($this->req['id']); $feed->update(['title' => $title, 'ask' => $this->req['feed_ask'], 'link' => $link, 'file' => $file]); \Loguser::create('Memperbaharui feedback Kode. ' . $feed->kode); \DB::commit(); return ['label' => 'success', 'err' => 'Feedback berhasil terkirim dengan Kode. ' . $feed->kode]; } catch (\Exception $e) { \DB::rollback(); if (file_exists($this->path . $file)) { @unlink($this->path . $file); } return ['label' => 'danger', 'err' => $e->getMessage()]; } }