Esempio n. 1
1
 /**
  * Updates an existing Po 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);
     $countPoItems = PoItem::find()->where(['po_id' => $id])->count();
     $modelsPoItem = PoItem::find()->where(['po_id' => $id])->all();
     if ($model->load(Yii::$app->request->post())) {
         // $model->save();
         $oldIDs = ArrayHelper::map($modelsPoItem, 'id', 'id');
         $modelsPoItem = Model::createMultiple(PoItem::classname(), $modelsPoItem);
         Model::loadMultiple($modelsPoItem, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItem, 'id', 'id')));
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsPoItem) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         PoItem::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsPoItem as $modelPoItem) {
                         $modelPoItem->po_id = $model->id;
                         if (!($flag = $modelPoItem->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model, 'modelsPoItem' => $modelsPoItem]);
     }
 }
Esempio n. 2
0
 public function actionCreate()
 {
     $model = new Po();
     $modelsPoItem = [new PoItem()];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modelsPoItem = Model::createMultiple(PoItem::classname());
         Model::loadMultiple($modelsPoItem, Yii::$app->request->post());
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsPoItem) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelsPoItem as $modelPoItem) {
                         $modelPoItem->po_id = $model->id;
                         if (!($flag = $modelPoItem->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         return $this->render('create', ['model' => $model, 'modelsPoItem' => empty($modelsPoItem) ? [new PoItem()] : $modelsPoItem]);
     }
 }
Esempio n. 3
0
 /**
  * Creates a new Matricula model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Matricula();
     $modeldetallemat = [new Detallemat()];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modeldetallemat = Model::createMultiple(Detallemat::classname());
         Model::loadMultiple($modeldetallemat, Yii::$app->request->post());
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modeldetallemat) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modeldetallemat as $modeldetallemat) {
                         $modeldetallemat->idMatricula = $model->idMatricula;
                         if (!($flag = $modeldetallemat->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->idMatricula]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         return $this->redirect(['view', 'id' => $model->idMatricula]);
     } else {
         return $this->render('create', ['model' => $model, 'modeldetallemat' => empty($modeldetallemat) ? [new Detallemat()] : $modeldetallemat]);
     }
 }
 /**
  * Creates a new Prerrequisito model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Prerrequisito();
     $modelsDetallepre = [new Detallepre()];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $modelsDetallepre = Model::createMultiple(Detallepre::classname());
         Model::loadMultiple($modelsDetallepre, Yii::$app->request->post());
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsDetallepre) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelsDetallepre as $modelsDetallepre) {
                         $modelsDetallepre->idPrerreq = $model->idPrerreq;
                         if (!($flag = $modelsDetallepre->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->idPrerreq]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         return $this->redirect(['view', 'id' => $model->idPrerreq]);
     } else {
         return $this->render('create', ['model' => $model, 'modelsDetallepre' => empty($modelsDetallepre) ? [new Detallepre()] : $modelsDetallepre]);
     }
 }
 /**
  * Creates a new Po model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Po();
     $modelsPoItem = [new PoItem()];
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $oldIDs = ArrayHelper::map($modelsPoItem, 'id', 'id');
         $modelsPoItem = Model::createMultiple(PoItem::classname(), $modelsPoItem);
         echo PoItem::classname();
         echo '<pre>';
         print_r($modelsPoItem);
         print_r($oldIDs);
         echo '</pre>';
         die;
         Model::loadMultiple($modelsPoItem, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItem, 'id', 'id')));
         // ajax validation
         //             if (Yii::$app->request->isAjax) {
         //                 Yii::$app->response->format = Response::FORMAT_JSON;
         //                 return ArrayHelper::merge(
         //                     ActiveForm::validateMultiple($modelsPoItem),
         //                     ActiveForm::validate($modelCustomer)
         //                 );
         //             }
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsPoItem) && $valid;
         //             echo '<pre>';
         //             print_r($valid);
         //             echo '</pre>';
         //             die();
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         PoItem::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsPoItem as $modelPoItem) {
                         $modelPoItem->po_id = $model->id;
                         if (!($flag = $modelPoItem->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         return $this->render('create', ['model' => $model, 'modelsPoItem' => empty($modelsPoItem) ? [new PoItem()] : $modelsPoItem]);
     }
 }
Esempio n. 6
0
 /**
  * Updates an existing Po 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);
     $modelsPoItem = $model->poItems;
     if ($model->load(Yii::$app->request->post())) {
         $oldIDs = ArrayHelper::map($modelsPoItem, 'id', 'id');
         $modelsPoItem = Model::createMultiple(Address::classname(), $modelsPoItem);
         Model::loadMultiple($modelsPoItem, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsPoItem, 'id', 'id')));
         // ajax validation
         /*if (Yii::$app->request->isAjax) {
               Yii::$app->response->format = Response::FORMAT_JSON;
               return ArrayHelper::merge(
                   ActiveForm::validateMultiple($modelsPoItem),
                   ActiveForm::validate($model)
               );
           }*/
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsPoItem) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         Address::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsPoItem as $modelPoItem) {
                         $modelPoItem->po_id = $model->id;
                         if (!($flag = $modelPoItem->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('update', ['model' => $model, 'modelsPoItem' => empty($modelsPoItem) ? [new PoItem()] : $modelsPoItem]);
 }
 /**
  * Updates an existing Booths 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);
     $modelsBoothSchedules = $model->boothSchedules;
     if ($model->load(Yii::$app->request->post())) {
         //Load data from post
         $oldIDs = ArrayHelper::map($modelsBoothSchedules, 'id', 'id');
         $modelsBoothSchedules = Model::createMultiple(BoothSchedules::classname(), $modelsBoothSchedules);
         Model::loadMultiple($modelsBoothSchedules, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsBoothSchedules, 'id', 'id')));
         $model->date = \DateTime::createFromFormat('m-d-Y', $model->date)->format('Y-m-d');
         // validate all models
         $valid = $model->validate();
         if ($valid || !$valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         BoothSchedules::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsBoothSchedules as $modelBoothSchedule) {
                         if (!empty($modelBoothSchedule->attendee_id)) {
                             $attendeeDetails = $modelBoothSchedule->attendee;
                             if (empty($modelBoothSchedule->booth_id)) {
                                 $modelBoothSchedule->booth_id = $model->id;
                                 //Below two lines can be removed
                                 $modelBoothSchedule->function_id = $attendeeDetails->function_Id;
                                 $modelBoothSchedule->cost_center_id = $attendeeDetails->group_Id;
                                 $modelBoothSchedule->isNewRecord = true;
                             }
                             $flag = $modelBoothSchedule->save(false);
                             if (!$flag) {
                                 //If data is not saved then rollback the transaction and break the loop
                                 $transaction->rollBack();
                                 break;
                             }
                         }
                     }
                 }
                 if ($flag) {
                     //If data is not saved then rollback the transaction  and redirect to view page
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (\Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         //Booth 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, 'modelsBoothSchedules' => empty($modelsBoothSchedules) ? [new BoothSchedules()] : $modelsBoothSchedules, 'congressStartDate' => $congressStartDate, 'congressEndDate' => $congressEndDate]);
     }
 }
 /**
  * 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]);
     }
 }
 /**
  * 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]);
     }
 }
Esempio n. 10
0
 /**
  * Updates an existing Cuentas 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);
     $modelsContactos = $model->contactos;
     $vista = \common\models\Refactor::TipoCuentabyVista($model->tipocuenta_id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         // Lista todos los contactos
         $oldIDs = ArrayHelper::map($modelsContactos, 'contactosid', 'contactosid');
         $modelsContactos = Model::createMultiple(Contactos::classname(), $modelsContactos);
         Model::loadMultiple($modelsContactos, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsContactos, 'contactosid', 'contactosid')));
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsContactos) && $valid;
         // Obteniendo el archivo que se subió.
         /* FUNCIONA CORRECTAMENTE PERO ES PARA MOSTRAR Y GUARDAR UN SOLO ARCHIVO, EL CODIGO UTILIZADO ES PARA VARIOS ARCHIVOS
            $model->archivo = UploadedFile::getInstance($model, 'archivo');
            if ($model->archivo && $model->validate()) {
                if ($model->docto_propuesta && file_exists(Yii::$app->basePath.'/web/'.$model->docto_propuesta)) {
                    unlink(Yii::$app->basePath.'/web/'.$model->docto_propuesta);
                }
                $nombreImagen = $model->cuenta .'-'.date('Ymd-His');
                // Guardando la direccion en la BD
                $model->docto_propuesta = 'doctos/' .$nombreImagen. '.' .$model->archivo->extension;
                $model->save();
                $model->archivo->saveAs('doctos/'.$nombreImagen.'.'.$model->archivo->extension );
            }
            */
         // Obteniendo el archivo que se subió.
         $model->archivo = UploadedFile::getInstance($model, 'archivo');
         if ($model->archivo && $model->validate()) {
             $archivo = $model->archivo->name;
             echo $model->docto_propuesta;
             // Desserializando los valores de la BD
             $dato_inicial = unserialize($model->docto_propuesta);
             // Obteniendo el nuevo archivo del formulario
             //$nombreImagen = $model->cuenta .'-'.date('Ymd-His');
             //$dato_nuevo = 'doctos/' .$nombreImagen. '.' .$model->archivo->extension;
             $dato_nuevo = 'doctos/' . $archivo;
             // Serializando los nuevos datos
             if (!is_array($dato_inicial)) {
                 $dato_inicial = explode("\n", $dato_inicial);
             }
             $temporal[0] = $dato_nuevo;
             $i = 1;
             foreach ($dato_inicial as $valor) {
                 $temporal[$i] = $dato_inicial[$i - 1];
                 $i++;
             }
             // Guardando en la BD
             $model->docto_propuesta = serialize($temporal);
             $model->save();
             //$model->archivo->saveAs('doctos/'.$nombreImagen.'.'.$model->archivo->extension );
             $model->archivo->saveAs('doctos/' . $archivo);
         }
         // Modificando los contactos
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         Contactos::deleteAll(['contactosid' => $deletedIDs]);
                     }
                     foreach ($modelsContactos as $modelContacto) {
                         $modelContacto->cuenta_id = $model->cuentasid;
                         if (!($flag = $modelContacto->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     $transaction->commit();
                     //return $this->redirect([$vista, 'id' => $model->cuentasid]);
                     return $this->redirect(Yii::$app->session->get('regresa_anterior'));
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
         //return $this->redirect([$vista, 'id' => $model->cuentasid]);
     } else {
         Yii::$app->session->set('regresa_anterior', Yii::$app->request->referrer);
         if ($vista == 'estatales') {
             return $this->render('update_estatal', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]);
         } elseif ($vista == 'gdf') {
             return $this->render('update_gdf', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]);
         } elseif ($vista == 'gobierno-federal') {
             return $this->render('update_gobiernofederal', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]);
         } elseif ($vista == 'iniciativa-privada') {
             return $this->render('update_ip', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]);
         } elseif ($vista == 'partidos') {
             return $this->render('update_partidos', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]);
         } elseif ($vista == 'delegacion') {
             return $this->render('update_delegacion', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]);
         } elseif ($vista == 'intercambio') {
             return $this->render('update_intercambio', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]);
         } elseif ($vista == 'fundacion') {
             return $this->render('update_fundacion', ['model' => $model, 'modelsContactos' => empty($modelsContactos) ? [new Contactos()] : $modelsContactos]);
         }
     }
 }
Esempio n. 11
0
 /**
  * Creates a new Arqueo model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     // Comprobando que se haya echo el conteodiario antes de iniciar el arqueo
     $conteofinalizado = Conteodiario::find()->select(['id'])->where(['is not', 'montoapertura', null])->andWhere(['is not', 'montocierre', null])->andWhere(['is', 'arqueo_id', null])->andWhere(['username' => Yii::$app->user->identity->username])->exists();
     if (!$conteofinalizado) {
         Yii::$app->getSession()->addFlash('warning', 'Realiza la apertura y cierre primero');
         return Yii::$app->getResponse()->redirect(array('caja/conteodiario/index'));
     }
     // En caso de que el arqueo ya se haya realizado hacer esto
     $arqueo_cerrado_id = Arqueo::find()->select(['id'])->where(['username' => Yii::$app->user->identity->username, 'cerrado' => 0])->one();
     if ($arqueo_cerrado_id) {
         return $this->redirect(['view', 'id' => $arqueo_cerrado_id->id]);
     }
     //echo $apertura->createCommand()->sql;
     //echo $apertura->createCommand()->getRawSql();
     $model = new Arqueo();
     $modelsNotas = [new Conteonotas()];
     $ingresoegreso = Tipoingresoegreso::find()->all();
     if ($model->load(Yii::$app->request->post())) {
         $modelsNotas = Model::createMultiple(Conteonotas::className());
         Model::loadMultiple($modelsNotas, Yii::$app->request->post());
         // validate all models
         $valid = $model->validate();
         $valid = Model::validateMultiple($modelsNotas) && $valid;
         if ($valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     foreach ($modelsNotas as $modelNotas) {
                         $modelNotas->arqueo_id = $model->id;
                         if (!($flag = $modelNotas->save(false))) {
                             $transaction->rollBack();
                             break;
                         }
                     }
                 }
                 if ($flag) {
                     // Obteniendo la info de la apertura
                     $apertura = Conteodiario::find()->select(['montoapertura', 'montocierre'])->where(['arqueo_id' => null, 'username' => Yii::$app->user->identity->username])->one();
                     // Cantidad que se conto de dinero con que se aperturo la caja
                     $model->efectivoapertura = $apertura->montoapertura;
                     // Cantidad que se conto de dinero con el que se cerro la caja
                     $model->efectivocierre = $apertura->montocierre;
                     // Ventas en efectivo reportadas por el SoftRestaurant -- Efectivo Real - Lo que dice la máquina que vendió
                     $model->efectivosistema = Conteonotas::find()->select(['cantidad'])->where(['arqueo_id' => $model->id, 'tipo' => 'INGRESO EFECTIVO'])->asArray()->sum('cantidad');
                     // Compras realizadas con Tarjeta de Debido o Credito
                     $model->dineroelectronico = Conteonotas::find()->select(['cantidad'])->where(['arqueo_id' => $model->id, 'tipo' => 'INGRESO ELECTRONICO'])->asArray()->sum('cantidad');
                     // Dinero que se deposito de forma adicional ( de compras u otra cosa que se retiro y no se deposito nuevamente )
                     $model->efectivoadeudoanterior = Conteonotas::find()->select(['cantidad'])->where(['arqueo_id' => $model->id, 'tipo' => 'INGRESO ADEUDOS ANTERIORES'])->asArray()->sum('cantidad');
                     // Dinero que deposita la empresa para agregar flujo de efectivo ( Cuando se queda sin dinero o cambio la caja)
                     $model->depositoempresa = Conteonotas::find()->select(['cantidad'])->where(['arqueo_id' => $model->id, 'tipo' => 'INGRESO EMPRESA'])->asArray()->sum('cantidad');
                     // Dinero que se retira de la caja por exceso de efectivo por seguridad
                     $model->retiroempresa = Conteonotas::find()->select(['cantidad'])->where(['arqueo_id' => $model->id, 'tipo' => 'RETIRO EMPRESA'])->asArray()->sum('cantidad');
                     // Compras realizadas con dinero de la caja
                     $model->egresocompras = Conteonotas::find()->select(['cantidad'])->where(['arqueo_id' => $model->id, 'tipo' => 'EGRESO COMPRA'])->asArray()->sum('cantidad');
                     // Pagos de servicios con dinero de la caja
                     $model->egresocomprasservicio = Conteonotas::find()->select(['cantidad'])->where(['arqueo_id' => $model->id, 'tipo' => 'EGRESO SERVICIO'])->asArray()->sum('cantidad');
                     // Efectivo que debe de existir en la caja; debe ser igual a lo que reporto el SoftRestaurant
                     $model->efectivofisico = $model->efectivoapertura + $model->efectivosistema + $model->depositoempresa + $model->efectivoadeudoanterior + $model->depositoempresa - $model->egresocompras - $model->egresocomprasservicio - $model->retiroempresa;
                     $adeudoanterior = Arqueo::find()->select(['adeudoactual'])->where(['username' => Yii::$app->user->identity->username, 'cerrado' => true])->orderBy(['id' => SORT_ASC])->one();
                     // Cuanto quedo a deber el cajero el día anterior
                     $model->adeudoanterior = empty($adeudoanterior->adeudoactual) ? 0 : $adeudoanterior->adeudoactual;
                     // Dinero que quedo a deber el cajero
                     $model->adeudoactual = $model->efectivocierre - $model->efectivofisico + $model->adeudoanterior - $model->efectivoadeudoanterior;
                     // Cuanto se vendio en el turno
                     $model->ventaturno = $model->efectivosistema + $model->dineroelectronico;
                     // Cuando se gasto en el turno
                     $model->egresoturno = $model->egresocompras + $model->egresocomprasservicio;
                     // Nuevas claves temporales
                     $model->clave1 = Arqueo::getClave(5);
                     $model->clave2 = Arqueo::getClave(6);
                     $model->save(false);
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (Exception $e) {
                 $transaction->rollBack();
             }
         }
     }
     return $this->render('create', ['model' => $model, 'modelsNotas' => empty($modelsNotas) ? [new Conteonotas()] : $modelsNotas, 'ingresoegreso' => $ingresoegreso]);
 }