public function actionPrint($id) { $card = Card::findOne($id); $type = Ref::getDesc('ctype', $card->type); $this->genBarCode($card->no); $content = $this->renderPartial('print', ['no' => $card->no, 'type' => $type]); $pdf = new Pdf(['content' => $content, 'orientation' => Pdf::ORIENT_PORTRAIT, 'cssFile' => 'css/card.css', 'marginLeft' => 5, 'marginRight' => 5]); $pdf->render(); }
public function actionDelete() { $id = (int) Yii::$app->request->post('id'); /** @var Card $card */ $card = Card::findOne(['id' => $id]); $result = $card ? $card->delete() : false; Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['result' => (bool) $result]; }
public function afterSave($insert, $changedAttributes) { /** * @var Card $card ; */ $card = Card::findOne(['no' => $this->card]); $card->activity_date = Yii::$app->formatter->asDatetime(new \DateTime(), 'Y-MM-d HH:i:s'); $card->save(); }
/** * Deletes an existing Sales model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param string $id * @return mixed */ public function actionDelete($id) { /** * @var Sales $sale * @var Card $card */ $sale = Sales::findOne(['id', $id]); $card = Card::findOne(['no', $sale->card]); $card->sum = intval($card->sum) + intval($sale->sum); $card->save(); $this->findModel($id)->delete(); return $this->redirect(['index']); }
/** * Finds the Card model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Card the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Card::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionGenerate() { $number = rand(4000000000000000.0, 1.0E+16); if (Card::findOne(['number' => $number]) == null) { $card = new Card(); $card->number = $number; $card->amount = 10000; $card->issue_date = date('Y-m-d H:i'); $card->expiration_date = date(date('Y') + 1 . '-m-d H:i'); $card->use_date = date('Y-m-d H:i'); $card->serial = 'Master card'; $card->status = 1; $card->save(); $this->redirect('/card'); } }