public function edit(Branch $model) { if (isset($_POST['Branch']) && $_POST['Branch']) { $model->attributes = $_POST['Branch']; if ($model->save()) { $params = ['id' => $model->bra_id]; $params['close'] = false; if (isset($_POST['close'])) { $params['close'] = true; } if (isset($_GET['callback']) && $_GET['callback']) { Yii::app()->user->setFlash('branch-callback', true); $params['callback'] = $_GET['callback']; } Yii::app()->user->setFlash('branch-update-success', 'Branch info updated'); $this->redirect($this->createUrl('Update', $params)); } } if (Yii::app()->user->getFlash('branch-callback')) { $callback = new PopupCallback($_GET['callback']); $callback->run([$model->bra_id], isset($_GET['close']) && $_GET['close']); } elseif (isset($_GET['close']) && $_GET['close']) { echo '<script>window.close();</script>'; } $this->render('edit', array('model' => $model)); }
public static function add($data) { $Branch = new Branch(); foreach ($data as $field => $value) { $Branch->{$field} = $value; } return $Branch->save(); }
/** * Store a newly created branch in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Branch::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $branch = new Branch(); $branch->name = Input::get('name'); $branch->save(); return Redirect::route('branches.index'); }
/** * Создает новую модель Филиала. * Если создание прошло успешно - перенаправляет на просмотр. * * @return void */ public function actionCreate() { $model = new Branch(); if (Yii::app()->getRequest()->getPost('Branch') !== null) { $model->setAttributes(Yii::app()->getRequest()->getPost('Branch')); if ($model->save()) { Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('BranchModule.branch', 'Запись добавлена!')); $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['update', 'id' => $model->id])); } } $this->render('create', ['model' => $model]); }
public function run() { DB::table('branchs')->truncate(); $branch = new Branch(); $branch->name = "Giày dép"; $branch->save(); $branch = new Branch(); $branch->name = "Áo quần"; $branch->save(); $branch = new Branch(); $branch->name = "Phụ kiện"; $branch->save(); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->asfGuardUser !== null) { if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) { $affectedRows += $this->asfGuardUser->save($con); } $this->setsfGuardUser($this->asfGuardUser); } if ($this->aRepository !== null) { if ($this->aRepository->isModified() || $this->aRepository->isNew()) { $affectedRows += $this->aRepository->save($con); } $this->setRepository($this->aRepository); } if ($this->aBranch !== null) { if ($this->aBranch->isModified() || $this->aBranch->isNew()) { $affectedRows += $this->aBranch->save($con); } $this->setBranch($this->aBranch); } if ($this->aFile !== null) { if ($this->aFile->isModified() || $this->aFile->isNew()) { $affectedRows += $this->aFile->save($con); } $this->setFile($this->aFile); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } $this->alreadyInSave = false; } return $affectedRows; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Branch(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Branch'])) { $model->attributes = $_POST['Branch']; $model->created_by = Yii::app()->session->get('user_id'); $model->created_on = date('Y-m-d H:i:s'); $model->modified_by = Yii::app()->session->get('user_id'); $model->modified_on = date('Y-m-d H:i:s'); if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
/** * Создает новую модель Филиала. * Если создание прошло успешно - перенаправляет на просмотр. * * @return void */ public function actionCreate() { $roles = ['1']; $role = \Yii::app()->user->role; if (array_intersect($role, $roles)) { $model = new Branch(); if (Yii::app()->getRequest()->getPost('Branch') !== null) { $model->setAttributes(Yii::app()->getRequest()->getPost('Branch')); if ($model->save()) { Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('BranchModule.branch', 'Запись добавлена!')); $this->redirect((array) Yii::app()->getRequest()->getPost('submit-type', ['update', 'id' => $model->id])); } } $this->render('create', ['model' => $model]); } else { throw new CHttpException(403, 'Ошибка прав доступа.'); } }
public function postAdd() { $validator = Validator::make(Input::all(), Branch::$rules); if ($validator->fails()) { return Redirect::to('branch/add')->withErrors($validator)->withInput(); } $branch = new Branch(); $branch->name = Input::get('name'); $branch->type_id = Input::get('type_id'); $branch->area_id = Input::get('area_id'); $branch->line_id = Input::get('line_id'); $branch->user_id = Input::get('user_id'); $branch->contact = Input::get('contact'); $branch->mobile = Input::get('mobile'); $type = Type::find(Input::get('type_id')); $area = Area::find(Input::get('area_id')); $line = Line::find(Input::get('line_id')); $branch->day = $type->day; $sourceNumber = DB::table('branch')->max('id'); $newNumber = $this->__codeNumber($sourceNumber); if (Input::get('stock') > 0) { $branch->stock = Input::get('stock'); } $branch->code = $type->code . $area->code . $line->code . $newNumber; $branch->address = $area->name . $line->name . Input::get('address'); $branch->last_visit_at = $branch->last_ship_at = $this->__time(); $branch->check = '1'; $branch->save(); // if (Input::get('stock') > 0) // { // $branch_good = new BranchGood(); // $branch_good->branch_id = $branch->id; // $branch_good->pay_status = '0'; // $branch_good->stock = Input::get('stock'); // $branch_good->memo = Input::get('memo'); // $branch_good->save(); // } return Redirect::to('branch')->with('success', '网点添加成功!'); }
public function executeBulkupload() { if ($this->getRequest()->getFileName('csvfile')) { $fileName = md5($this->getRequest()->getFileName('csvfile') . time() . rand(0, 99999)); $ext = $this->getRequest()->getFileExtension('csvfile'); $this->getRequest()->moveFile('csvfile', sfConfig::get('sf_upload_dir') . "//csvfiles//" . $fileName . ".csv"); $fullname = $fileName . ".csv"; //$fullpath = '/uploads/csvfiles/'.$fullname; $fp = sfConfig::get('sf_upload_dir') . "//csvfiles//" . $fileName . ".csv"; $reader = new sfCsvReader($fp, ',', '"'); $reader->open(); $i = 1; $exist; $ignore; $log; $ignoreflag = 0; $success = 0; while ($data = $reader->read()) { $name[] = array(); $name = explode(' ', $data[0]); $roll = $data[1]; $enrol = $data[2]; $branch = $data[3]; $degree = $data[4]; $year = $data[5]; $c = new Criteria(); $c->add(UserPeer::ENROLMENT, $enrol); $user = UserPeer::doSelectOne($c); if (!$user) { $c = new Criteria(); $c->add(BranchPeer::CODE, $branch); $br = BranchPeer::doSelectOne($c); if (!$br) { $br = new Branch(); $br->setName($branch); $br->setCode($branch); $br->save(); } $c = new Criteria(); $c->add(DegreePeer::NAME, $degree); $dg = DegreePeer::doSelectOne($c); if (!$dg) { $dg = new Degree(); $dg->setName($degree); $dg->save(); } $user = new User(); if ($roll) { $user->setRoll($roll); $user->setRollflag(sfConfig::get('app_defaultprivacy_roll')); } if ($enrol) { $user->setEnrolment($enrol); $user->setEnrolflag(sfConfig::get('app_defaultprivacy_enrol')); } else { $ignoreflag = 1; } if ($year) { $user->setGraduationyear($year); $user->setGraduationyearflag(sfConfig::get('app_defaultprivacy_year')); } $user->setBranchId($br->getId()); $user->setBranchflag(sfConfig::get('app_defaultprivacy_branch')); $user->setDegreeId($dg->getId()); $user->setDegreeflag(sfConfig::get('app_defaultprivacy_degree')); $user->setIslocked(sfConfig::get('app_islocked_unclaimed')); $user->setUsertype(sfConfig::get('app_usertypecode_Alumni')); $lastname = ''; $personal = new Personal(); $name[0] = str_replace('.', '', $name[0]); $personal->setFirstname($name[0]); if ($name[3]) { $name[1] = str_replace('.', '', $name[1]); $name[2] = str_replace('.', '', $name[2]); $name[3] = str_replace('.', '', $name[3]); $midname = $name[1] . " " . $name[2]; $personal->setMiddlename($midname); $personal->setLastname($name[3]); $lastname = $name[3]; } elseif ($name[2]) { $name[1] = str_replace('.', '', $name[1]); $name[2] = str_replace('.', '', $name[2]); $personal->setMiddlename($name[1]); $personal->setLastname($name[2]); $lastname = $name[2]; } elseif ($name[1]) { $name[1] = str_replace('.', '', $name[1]); $personal->setLastname($name[1]); $lastname = $name[1]; } $uname_suffix = $branch . substr($year, -2); if ($lastname) { $username = $name[0] . '.' . $lastname . '@'; } else { $username = $name[0] . '@'; } $temp = 1; $tempusername = $username; while ($this->uniqueuser($tempusername . $uname_suffix)) { $tempusername = $username . $temp; $temp++; } $tempusername = $tempusername . $uname_suffix; $user->setUsername($tempusername); if ($ignoreflag == 0) { $e = $user->save(); $personal->setUserId($user->getId()); $personal->save(); $success++; $log[$i][0] = $e == 1 ? "{$i}) Uploaded Successfully" : $e; $log[$i][1] = $data[0]; } else { $ignore[] = $i; $ignoreflag = 0; $log[$i][0] = "{$i}) NO enrolment number"; $log[$i][1] = $data[0]; } } else { $exist[] = $i; $log[$i][0] = "{$i}) In Database as " . $user->getFullname() . ", " . $user->getBranchname() . " " . $user->getGraduationyear(); $log[$i][1] = $data[0]; } $i++; } // while ($data = $reader->read()) ends here $reader->close(); $this->log = $log; $this->success = $success; $this->ignored = $ignore; $this->exists = $exist; } }
public function run() { $branch = new Branch(); $branch->name = 'Head Office'; $branch->save(); $currency = new Currency(); $currency->name = 'Kenyan Shillings'; $currency->shortname = 'KES'; $currency->save(); $organization = new Organization(); $organization->name = 'Lixnet Technologies'; $organization->save(); $share = new Share(); $share->value = 0; $share->transfer_charge = 0; $share->charged_on = 'donor'; $share->save(); $perm = new Permission(); $perm->name = 'create_employee'; $perm->display_name = 'Create employee'; $perm->category = 'Employee'; $perm->save(); $perm = new Permission(); $perm->name = 'update_employee'; $perm->display_name = 'Update employee'; $perm->category = 'Employee'; $perm->save(); $perm = new Permission(); $perm->name = 'delete_employee'; $perm->display_name = 'Deactivate employee'; $perm->category = 'Employee'; $perm->save(); $perm = new Permission(); $perm->name = 'view_employee'; $perm->display_name = 'View employee'; $perm->category = 'Employee'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_earning'; $perm->display_name = 'Manage earnings'; $perm->category = 'Payroll'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_deduction'; $perm->display_name = 'Manage deductions'; $perm->category = 'Payroll'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_allowance'; $perm->display_name = 'Manage allowance'; $perm->category = 'Payroll'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_relief'; $perm->display_name = 'Manage releif'; $perm->category = 'Payroll'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_benefit'; $perm->display_name = 'Manage benefits'; $perm->category = 'Payroll'; $perm->save(); $perm = new Permission(); $perm->name = 'process_payroll'; $perm->display_name = 'Process payroll'; $perm->category = 'Payroll'; $perm->save(); $perm = new Permission(); $perm->name = 'view_payroll_report'; $perm->display_name = 'View reports'; $perm->category = 'Payroll'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_settings'; $perm->display_name = 'Manage settings'; $perm->category = 'Payroll'; $perm->save(); $perm = new Permission(); $perm->name = 'view_application'; $perm->display_name = 'View applications'; $perm->category = 'Leave'; $perm->save(); $perm = new Permission(); $perm->name = 'amend_application'; $perm->display_name = 'Amend applications'; $perm->category = 'Leave'; $perm->save(); $perm = new Permission(); $perm->name = 'approve_application'; $perm->display_name = 'Approve applications'; $perm->category = 'Leave'; $perm->save(); $perm = new Permission(); $perm->name = 'reject_application'; $perm->display_name = 'Reject applications'; $perm->category = 'Leave'; $perm->save(); $perm = new Permission(); $perm->name = 'cancel_application'; $perm->display_name = 'Cancel applications'; $perm->category = 'Leave'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_type'; $perm->display_name = 'Manage leave types'; $perm->category = 'Leave'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_holiday'; $perm->display_name = 'Manage holidays'; $perm->category = 'Leave'; $perm->save(); $perm = new Permission(); $perm->name = 'view_leave_report'; $perm->display_name = 'View reports'; $perm->category = 'Leave'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_organization'; $perm->display_name = 'manage organization'; $perm->category = 'Organization'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_branch'; $perm->display_name = 'manage branches'; $perm->category = 'Organization'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_group'; $perm->display_name = 'manage groups'; $perm->category = 'Organization'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_organization_settings'; $perm->display_name = 'manage settings'; $perm->category = 'Organization'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_user'; $perm->display_name = 'manage users'; $perm->category = 'System'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_role'; $perm->display_name = 'manage roles'; $perm->category = 'System'; $perm->save(); $perm = new Permission(); $perm->name = 'manage_audit'; $perm->display_name = 'manage audits'; $perm->category = 'System'; $perm->save(); $perms = Permission::all(); $pers = array(); foreach ($perms as $p) { $pers[] = $p->id; } $role = new Role(); $role->name = 'superadmin'; $role->save(); $role->perms()->sync($pers); $data = array('username' => 'superadmin', 'email' => '*****@*****.**', 'password' => 'superadmin', 'password_confirmation' => 'superadmin', 'user_type' => 'admin', 'organization_id' => 1); $repo = App::make('UserRepository'); $user = $repo->register($data); $user->attachRole($role); /* $perm = new Permission; $perm->name = 'view_loan_product'; $perm->display_name = 'view loan products'; $perm->category = 'Loanproduct'; $perm->save(); $perm = new Permission; $perm->name = 'delete_loan_product'; $perm->display_name = 'delete loan products'; $perm->category = 'Loanproduct'; $perm->save(); $perm = new Permission; $perm->name = 'create_loan_account'; $perm->display_name = 'create loan account'; $perm->category = 'Loanaccount'; $perm->save(); $perm = new Permission; $perm->name = 'view_loan_account'; $perm->display_name = 'view loan account'; $perm->category = 'Loanaccount'; $perm->save(); $perm = new Permission; $perm->name = 'approve_loan_account'; $perm->display_name = 'approve loan'; $perm->category = 'Loanaccount'; $perm->save(); $perm = new Permission; $perm->name = 'disburse_loan'; $perm->display_name = 'disburse loan'; $perm->category = 'Loanaccount'; $perm->save(); $perm = new Permission; $perm->name = 'view_savings_account'; $perm->display_name = 'view savings account'; $perm->category = 'Savingaccount'; $perm->save(); $perm = new Permission; $perm->name = 'open_saving_account'; $perm->display_name = 'Open savings account'; $perm->category = 'Savingaccount'; $perm->save(); */ }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aBranch !== null) { if ($this->aBranch->isModified() || $this->aBranch->isNew()) { $affectedRows += $this->aBranch->save($con); } $this->setBranch($this->aBranch); } if ($this->asfGuardUser !== null) { if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) { $affectedRows += $this->asfGuardUser->save($con); } $this->setsfGuardUser($this->asfGuardUser); } if ($this->isNew() || $this->isModified()) { // persist changes if ($this->isNew()) { $this->doInsert($con); } else { $this->doUpdate($con); } $affectedRows += 1; $this->resetModified(); } if ($this->commentsScheduledForDeletion !== null) { if (!$this->commentsScheduledForDeletion->isEmpty()) { CommentQuery::create()->filterByPrimaryKeys($this->commentsScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->commentsScheduledForDeletion = null; } } if ($this->collComments !== null) { foreach ($this->collComments as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } if ($this->statusActionsScheduledForDeletion !== null) { if (!$this->statusActionsScheduledForDeletion->isEmpty()) { StatusActionQuery::create()->filterByPrimaryKeys($this->statusActionsScheduledForDeletion->getPrimaryKeys(false))->delete($con); $this->statusActionsScheduledForDeletion = null; } } if ($this->collStatusActions !== null) { foreach ($this->collStatusActions as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
function save() { $this->filter_access('Branch', 'roled_add', 'branches/index'); $branch = new Branch(); $branch->branch_name = $this->input->post('branch_name'); if ($branch->save()) { $this->session->set_flashdata('message', 'Branch successfully created!'); redirect('branches/'); } else { // Failed $branch->error_message('custom', 'Branch Name required'); $msg = $branch->error->custom; $this->session->set_flashdata('message', $msg); redirect('branches/add'); } }