backend/controllers/TransaksiController.php
/**
     * Creates a new Transaksi model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Transaksi model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Transaksi model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new Transaksi();
        $data_mobil = ArrayHelper::map(
            Mobil::find()->where(['status'=>1])->all(),
            'id_mobil', function($mobil){
                return $mobil['merk'] . ' ' . $mobil['harga_sewa'];
            }
        );
        $customer=new Customer();
        $data_customer = ArrayHelper::map(
            Customer::find()->all(),
            'id_customer',function($customer){
                return $customer['nama'];
            }
        );
        $model->denda=0;
        if ($model->load(Yii::$app->request->post()))
         { 
           $mobil= Mobil::find()->where(['id_mobil'=>$model->id_mobil])->one();  
           $mobil->status=2;
           $mobil->save(false);
           $model->harga= $mobil->harga_sewa;
           $model->total=$model->harga+$model->denda;
           $model->save();
            Yii::$app->session->setFlash('success', 'Disimpan');
           return $this->redirect(['view', 'id' => $model->id_transaksi]);
        }
        return $this->renderAjax('create', [
            'model' => $model,
            'data_mobil' => $data_mobil,
            'data_customer' => $data_customer
        ]);
    }
public function actionCreate ( ) { $ model = new Transaksi ( ) ; $ data_mobil = ArrayHelper :: map ( Mobil :: find ( ) -> where ( [ 'status' => 1 ] ) -> all ( ) , 'id_mobil' , function ( $ mobil ) { return $ mobil [ 'merk' ] . ' ' . $ mobil [ 'harga_sewa' ] ; } ) ; $ customer = new Customer ( ) ; $ data_customer = ArrayHelper :: map ( Customer :: find ( ) -> all ( ) , 'id_customer' , function ( $ customer ) { return $ customer [ 'nama' ] ; } ) ; $ model -> denda = 0 ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ mobil = Mobil :: find ( ) -> where ( [ 'id_mobil' => $ model -> id_mobil ] ) -> one ( ) ; $ mobil -> status = 2 ; $ mobil -> save ( false ) ; $ model -> harga = $ mobil -> harga_sewa ; $ model -> total = $ model -> harga + $ model -> denda ; $ model -> save ( ) ; Yii :: $ app -> session -> setFlash ( 'success' , 'Disimpan' ) ; return $ this -> redirect ( [ 'view' , 'id' => $ model -> id_transaksi ] ) ; } return $ this -> renderAjax ( 'create' , [ 'model' => $ model , 'data_mobil' => $ data_mobil , 'data_customer' => $ data_customer ] ) ; }
Creates a new Transaksi model.
Creates a new Transaksi model .
// $mobil = Mobil::findOne($model->id_mobil);