コード例 #1
0
 public function actionCreate()
 {
     $model = new Proveedores();
     $modelsContactos = [new ProveedoresContacto()];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modelsContactos = Model::createMultiplepcontacto(ProveedoresContacto::classname());
         Model::loadMultiple($modelsContactos, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsContactos), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsContactos, ['nombre', 'apellido', 'celular', 'telefono', 'email']) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelsContactos as $modelsContacto) {
                         $modelsContacto->proveedorid = $model->proveedor_id;
                         if (!($flag = $modelsContacto->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['index']);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         //return $this->redirect(['view', 'id' => $model->proveedor_id]);
     } else {
         return $this->render('create', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ProveedoresContacto()] : $modelsContactos]);
     }
 }
コード例 #2
0
 /**
  * Creates a new Member model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Member();
     $this->setPollAttributes($model);
     $modelContacts = [new Contact()];
     if ($model->load(Yii::$app->request->post())) {
         $modelContacts = Model::createMultiple(Contact::classname());
         Model::loadMultiple($modelContacts, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelContacts), ActiveForm::validate($model));
         }
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelContacts) && $valid;
         if ($valid) {
             $transaction = Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelContacts as $modelContact) {
                         $modelContact->member_id = $model->id;
                         if (!($flag = $modelContact->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     //return $this->redirect(['view', 'id' => $model->id]);
                     return $this->redirect($this->getReturnUrl(['view', 'id' => $model->id]));
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['model' => $model, 'modelContacts' => $modelContacts]);
 }
コード例 #3
0
 /**
  * Creates a new Parameter model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $models = [new Parameter()];
     if (Yii::$app->request->post()) {
         $models = Model::createMultiple(Parameter::classname());
         Model::loadMultiple($models, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validateMultiple($models);
         }
         // validate all models
         $valid = Model::validateMultiple($models);
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 $flag = true;
                 foreach ($models as $model) {
                     if (!($flag = $model->save(false))) {
                         $transaction->rollBack();
                         break;
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-success'], 'body' => Yii::t('backend', 'Your data has been successfully saved')]);
                     return $this->redirect(['index']);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
                 Yii::$app->session->setFlash('alert', ['options' => ['class' => 'alert-danger'], 'body' => Yii::t('backend', 'Your data can\'t be saved')]);
                 return $this->redirect(['index']);
             }
         }
     }
     return $this->render('create', ['models' => empty($models) ? [new Parameter()] : $models]);
 }
コード例 #4
0
ファイル: SiteController.php プロジェクト: vaibhavk01/motor
 /**
  * Updates an existing Dealership model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdatedealer($id)
 {
     $modelDealership = $this->findModel($id);
     $modelsShowroom = $modelDealership->Showroomes;
     if ($modelDealership->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsShowroom, 'id', 'id');
         $modelsShowroom = Model::createMultiple(Showroom::classname(), $modelsShowroom);
         Model::loadMultiple($modelsShowroom, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsShowroom, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsShowroom), ActiveForm::validate($modelDealership));
         }
         // validate all models
         $valid = $modelDealership->validate();
         $valid = $modelDealeraccount->validate();
         $valid = Model::validateMultiple($modelsShowroom) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if (($flag = $modelDealership->save(false)) && ($flag = $modelDealeraccount->save(false))) {
                     if (!empty($deletedIDs)) {
                         Showroom::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsShowroom as $modelShowroom) {
                         $modelShowroom->Dealership_id = $modelDealership->id;
                         if (!($flag = $modelShowroom->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $modelDealership->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['modelDealership' => $modelDealership, 'modelsShowroom' => empty($modelsShowroom) ? [new Showroom()] : $modelsShowroom, 'modelsService' => empty($modelsService) ? [new Service()] : $modelsService]);
 }
コード例 #5
0
 public function actionUpdateD($id)
 {
     $modelTransaksi = $this->findModel($id);
     $modelsTransaksiItem = $modelTransaksi->addresses;
     if ($modelTransaksi->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsTransaksiItem, 'id', 'id');
         $modelsTransaksiItem = Model::createMultiple(TransaksiItem::classname(), $modelsTransaksiItem);
         Model::loadMultiple($modelsTransaksiItem, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsTransaksiItem, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsTransaksiItem), ActiveForm::validate($modelTransaksi));
         }
         // validate all models
         $valid = $modelTransaksi->validate();
         $valid = Model::validateMultiple($modelsTransaksiItem) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $modelTransaksi->save(false)) {
                     if (!empty($deletedIDs)) {
                         TransaksiItem::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsTransaksiItem as $modelAddress) {
                         $modelAddress->customer_id = $modelTransaksi->id;
                         if (!($flag = $modelAddress->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $modelTransaksi->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('_formD', ['modelTransaksi' => $modelTransaksi, 'modelsTransaksiItem' => empty($modelsTransaksiItem) ? [new Address()] : $modelsTransaksiItem]);
 }
コード例 #6
0
 public function actionCreate($tipo)
 {
     $model = new Comunicado();
     $modelsContactos = [new ComunicadosContactos()];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modelsContactos = Model::createMultipleccontacto(ComunicadosContactos::classname());
         Model::loadMultiple($modelsContactos, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsContactos), ActiveForm::validate($model));
         }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsContactos, ['nombre', 'cargo', 'telefono', 'correo']) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelsContactos as $modelsContacto) {
                         $modelsContacto->dependenciaid = $model->dependencia_id;
                         if (!($flag = $modelsContacto->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect([\common\models\Refactor::TipoComunicadobyVista($model->tipocomunicado_id), 'id' => $model->tipocomunicado_id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         return $this->render($tipo, ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new ComunicadosContactos()] : $modelsContactos]);
     }
 }
コード例 #7
0
 /**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $product = $this->findModel($id);
     $product->setScenario('product-update');
     $ingredients = $product->ingredients;
     if ($product->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($ingredients, 'id', 'id');
         $ingredients = Model::createMultiple(Ingredients::classname(), $ingredients);
         Model::loadMultiple($ingredients, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($ingredients, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($ingredients), ActiveForm::validate($product));
         }
         $product->seen = 0;
         $product->sold = 0;
         $product->user_id = 0;
         // change to admin id or user id
         $product->created_by = Yii::$app->user->identity->username;
         $product->created_date = date('Y-m-d h:m:s');
         $product->modified_by = Yii::$app->user->identity->username;
         $product->modified_date = date('Y-m-d h:m:s');
         $product->status = Status::STATUS_ACTIVE;
         // validate all models
         $valid = $product->validate();
         foreach ($ingredients as $detail) {
             $fields = array('ingredient');
             $valid = $detail->validate($fields) && $valid;
         }
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $product->save(false)) {
                     if (!empty($deletedIDs)) {
                         //Ingredients::updateAll(array( 'status' => Status::STATUS_DELETED ), 'id IN ( ' . implode(",", $deletedIDs) .')' );
                         Ingredients::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($ingredients as $ingredient) {
                         $ingredient->created_by = Yii::$app->user->identity->username;
                         $ingredient->created_date = date('Y-m-d h:m:s');
                         $ingredient->modified_by = Yii::$app->user->identity->username;
                         $ingredient->modified_date = date('Y-m-d h:m:s');
                         $ingredient->status = Status::STATUS_ACTIVE;
                         $ingredient->product_id = $product->id;
                         if (!($flag = $ingredient->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                     $product->files = UploadedFile::getInstances($product, 'files');
                     if ($product->files) {
                         foreach ($product->files as $file) {
                             $productPhoto = new ProductPhoto();
                             $imageName = $file->baseName . substr(md5(rand()), 0, 7);
                             $productPhoto->caption = $imageName;
                             $productPhoto->product_id = $product->id;
                             $productPhoto->product_photo_order = 0;
                             $productPhoto->created_by = Yii::$app->user->identity->username;
                             $productPhoto->created_date = date('Y-m-d h:m:s');
                             $productPhoto->modified_by = Yii::$app->user->identity->username;
                             $productPhoto->modified_date = date('Y-m-d h:m:s');
                             $productPhoto->status = Status::STATUS_ACTIVE;
                             $productPhoto->image_path = 'uploads/product/' . $imageName . '.' . $file->extension;
                             if (!($flag = $productPhoto->save(false))) {
                                 $transaction->rollBack();
                                 break;
                             } else {
                                 $file->saveAs('uploads/product/' . $imageName . '.' . $file->extension);
                             }
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $product->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         return $this->render('create', ['product' => $product, 'ingredients' => empty($ingredients) ? [new Ingredients()] : $ingredients]);
     }
 }
コード例 #8
0
 /**
  * Updates an existing MeetingDetails model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelMeetingSchedules = $model->meetingSchedules;
     if ($model->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelMeetingSchedules, 'id', 'id');
         $modelMeetingSchedules = Model::createMultiple(MeetingSchedules::classname(), $modelMeetingSchedules);
         Model::loadMultiple($modelMeetingSchedules, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelMeetingSchedules, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelMeetingSchedules), ActiveForm::validate($model));
         }
         $model->date = \DateTime::createFromFormat('m-d-Y', $model->date)->format('Y-m-d');
         // validate all models
         $valid = $model->validate();
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         MeetingSchedules::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelMeetingSchedules as $modelMeetingSchedule) {
                         if (empty($modelMeetingSchedule->congress_id)) {
                             $modelMeetingSchedule->meeting_id = $model->id;
                             $modelMeetingSchedule->congress_id = $model->congress_id;
                             $modelMeetingSchedule->isNewRecord = true;
                         }
                         if ($modelMeetingSchedule->attendee_id > 0 || $modelMeetingSchedule->ol_attendee_id > 0) {
                             $flag = $modelMeetingSchedule->save(false);
                         }
                     }
                     $postData = \Yii::$app->request->post();
                     $olAttendeeData = isset($postData['OlAttendees']) ? $postData['OlAttendees'] : [];
                     foreach ($olAttendeeData as $olAttendeeInfo) {
                         //   print_r($olAttendeeInfo);
                         if (!empty($olAttendeeInfo['name']) && (!isset($olAttendeeInfo['id']) || empty($olAttendeeInfo['id']))) {
                             $olAttendeeModel = new \backend\models\OlAttendees();
                             $olAttendeeModel->user_type_id = 1;
                             $parts = explode(" ", $olAttendeeInfo['name']);
                             $lastname = array_pop($parts);
                             $firstname = implode(" ", $parts);
                             $olAttendeeModel->first_name = $firstname;
                             $olAttendeeModel->last_name = $lastname;
                             $olAttendeeModel->name = $olAttendeeInfo['name'];
                             $olAttendeeModel->ol_bio = $olAttendeeInfo['ol_bio'];
                             $olAttendeeModel->ol_phone_no = $olAttendeeInfo['ol_phone_no'];
                             $olAttendeeModel->ol_email = $olAttendeeInfo['ol_email'];
                             $olAttendeeModel->is_active = 1;
                             $olAttendeeModel->isNewRecord = true;
                             if ($olAttendeeModel->validate()) {
                                 if ($flag = $olAttendeeModel->save(false)) {
                                     $olAttendeeId = $olAttendeeModel->id;
                                     $meetingScheduleModel = new MeetingSchedules();
                                     $meetingScheduleModel->meeting_id = $model->id;
                                     $meetingScheduleModel->congress_id = $model->congress_id;
                                     $meetingScheduleModel->ol_attendee_id = $olAttendeeId;
                                     $meetingScheduleModel->isNewRecord = true;
                                     $flag = $meetingScheduleModel->save(false);
                                     if (!$flag) {
                                         $transaction->rollBack();
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (\Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         //Meeting date should be between congress start date and end date
         $congressDetail = CongressDetails::findOne($model->congress_id);
         $congressStartDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->start_date)->format('m-d-Y');
         $congressEndDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->end_date)->format('m-d-Y');
         return $this->render('update', ['model' => $model, 'modelMeetingSchedules' => empty($modelMeetingSchedules) ? [new MeetingSchedules()] : $modelMeetingSchedules, 'congressStartDate' => $congressStartDate, 'congressEndDate' => $congressEndDate]);
     }
 }
コード例 #9
0
 public function actionGroupcreate()
 {
     $modelCustomer = new Grade();
     $modelsAddress = [new Grade()];
     if ($modelCustomer->load(Yii::$app->request->post())) {
         $modelsAddress = GroupGrade::createMultiple(Grade::classname());
         GroupGrade::loadMultiple($modelsAddress, Yii::$app->request->post());
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsAddress), ActiveForm::validate($modelCustomer));
         }
         // validate all models
         $valid = $modelCustomer->validate();
         $valid = GroupGrade::validateMultiple($modelsAddress) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 // if($flag = $modelCustomer->save(false)){
                 foreach ($modelsAddress as $modelAddress) {
                     $modelAddress->subject_scholar_scholar_id = $modelCustomer->subject_scholar_scholar_id;
                     $modelAddress->grade_school_year_start = $modelCustomer->grade_school_year_start;
                     $modelAddress->grade_school_year_end = $modelCustomer->grade_school_year_end;
                     $selectSchool = ArrayHelper::map(Scholar::find()->where(['scholar_id' => $modelAddress->subject_scholar_scholar_id])->all(), 'school_school_id', 'school_school_id');
                     $schoolID = array_values($selectSchool)[0];
                     $modelAddress->subject_scholar_school_school_id = $schoolID;
                     if (!($flag = $modelAddress->save(false))) {
                         $transaction->rollBack();
                         break;
                     }
                 }
                 // }
                 if ($flag) {
                     if ($modelCustomer->subject_subject_id == null) {
                         $sql = "DELETE FROM grade WHERE subject_subject_id is null;";
                         Yii::$app->db->createCommand($sql)->execute();
                     }
                     $transaction->commit();
                     return $this->redirect(['index']);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('groupcreate', ['modelCustomer' => $modelCustomer, 'modelsAddress' => empty($modelsAddress) ? [new Grade()] : $modelsAddress]);
 }
コード例 #10
0
 /**
  * Updates an existing Sda model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsSdaSchedules = $model->sdaSchedules;
     if ($model->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsSdaSchedules, 'id', 'id');
         $modelsSdaSchedules = Model::createMultiple(SdaSchedules::classname(), $modelsSdaSchedules);
         Model::loadMultiple($modelsSdaSchedules, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsSdaSchedules, 'id', 'id')));
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validateMultiple($modelsSdaSchedules), ActiveForm::validate($model));
         }
         $model->date = \DateTime::createFromFormat('m-d-Y', $model->date)->format('Y-m-d');
         // validate all models
         $valid = $model->validate();
         if ($valid || !$valid) {
             //change condition for update without being validate
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         SdaSchedules::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsSdaSchedules as $modelSdaSchedule) {
                         if (!empty($modelSdaSchedule->attendee_id)) {
                             if (empty($modelSdaSchedule->congress_id)) {
                                 $modelSdaSchedule->sda_id = $model->id;
                                 $modelSdaSchedule->congress_id = $model->congress_id;
                                 $modelSdaSchedule->assigned = 0;
                                 $modelSdaSchedule->isNewRecord = true;
                             }
                             $flag = $modelSdaSchedule->save(false);
                             if (!$flag) {
                                 $transaction->rollBack();
                                 break;
                             }
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         $congressDetail = CongressDetails::findOne($model->congress_id);
         $congressStartDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->start_date)->format('m-d-Y');
         $congressEndDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->end_date)->format('m-d-Y');
         return $this->render('update', ['model' => $model, 'modelsSdaSchedules' => empty($modelsSdaSchedules) ? [new SdaSchedules()] : $modelsSdaSchedules, 'congressStartDate' => $congressStartDate, 'congressEndDate' => $congressEndDate]);
     }
 }