public function actionIndex() { // master value $fmShortDatePhp = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_PHP, null); $fmShortDateJui = DateTimeUtils::getDateFormat(DateTimeUtils::FM_KEY_JUI, null); $arrNetCustomer = ModelUtils::getArrData(NetCustomer::find()->select(['id', 'name'])->where(['delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE, 'status' => MasterValueUtils::MV_NET_CUSTOMER_STATUS_ON])->orderBy('order_num'), 'id', 'name'); NetPayment::$_PHP_FM_SHORTDATE = $fmShortDatePhp; $searchModel = new NetPayment(); // submit data $postData = Yii::$app->request->post(); // populate model attributes with user inputs $searchModel->load($postData); // init value if (Yii::$app->request->getIsGet()) { $today = DateTimeUtils::getNow(); $tdInfo = getdate($today->getTimestamp()); $searchModel->entry_date_to = $today->format($fmShortDatePhp); $searchModel->entry_date_from = DateTimeUtils::parse($tdInfo[DateTimeUtils::FN_KEY_GETDATE_YEAR] - 1 . '0101', DateTimeUtils::FM_DEV_DATE, $fmShortDatePhp); } $searchModel->scenario = MasterValueUtils::SCENARIO_LIST; // sum Debit Amount & Credit Amount $sumEntryValue = false; // query for dataprovider $dataQuery = null; if ($searchModel->validate()) { $dataQuery = NetPayment::find()->select('t1.*, t2.bill_date')->from('net_payment t1')->leftJoin('net_bill t2', 't1.order_id = t2.id')->where(['=', 't1.delete_flag', MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]); $sumEntryQuery = (new Query())->select(['SUM(credit) AS credit, SUM(debit) AS debit'])->from('net_payment')->where(['=', 'delete_flag', MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]); if (!empty($searchModel->entry_date_from)) { $searchDate = DateTimeUtils::parse($searchModel->entry_date_from, $fmShortDatePhp, DateTimeUtils::FM_DB_DATE); $dataQuery->andWhere(['>=', 't1.entry_date', $searchDate]); $sumEntryQuery->andWhere(['>=', 'entry_date', $searchDate]); } if (!empty($searchModel->bill_date_to)) { $searchDate = DateTimeUtils::parse($searchModel->entry_date_to, $fmShortDatePhp, DateTimeUtils::FM_DB_DATE); $dataQuery->andWhere(['<=', 't1.entry_date', $searchDate]); $sumEntryQuery->andWhere(['<=', 'entry_date', $searchDate]); } if ($searchModel->customer_id > 0) { $dataQuery->andWhere(['=', 't1.customer_id', $searchModel->customer_id]); $sumEntryQuery->andWhere(['=', 'customer_id', $searchModel->customer_id]); } $dataQuery->orderBy('entry_date DESC, update_date DESC'); $sumEntryValue = $sumEntryQuery->createCommand()->queryOne(); } else { $dataQuery = NetPayment::find()->where(['customer_id' => -1]); } // render GUI $renderData = ['searchModel' => $searchModel, 'fmShortDateJui' => $fmShortDateJui, 'arrNetCustomer' => $arrNetCustomer, 'dataQuery' => $dataQuery, 'sumEntryValue' => $sumEntryValue]; return $this->render('index', $renderData); }
public function actionView($id) { $this->objectId = $id; $model = NetCustomer::findOne(['id' => $id, 'delete_flag' => MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]); $renderView = 'view'; if (is_null($model)) { $model = false; $renderData = ['model' => $model]; Yii::$app->session->setFlash(MasterValueUtils::FLASH_ERROR, Yii::t('common', 'The requested {record} does not exist.', ['record' => Yii::t('fin.models', 'Customer')])); } else { // master value $arrCustomerStatus = MasterValueUtils::getArrData('net_customer_status'); $dataPaymentQuery = NetPayment::find()->select('t1.*, t2.bill_date')->from('net_payment t1')->leftJoin('net_bill t2', 't1.order_id = t2.id')->where(['=', 't1.delete_flag', MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]); $sumPaymentQuery = (new Query())->select(['SUM(credit) AS credit, SUM(debit) AS debit'])->from('net_payment')->where(['=', 'delete_flag', MasterValueUtils::MV_FIN_FLG_DELETE_FALSE]); $dataPaymentQuery->andWhere(['=', 't1.customer_id', $model->id]); $sumPaymentQuery->andWhere(['=', 'customer_id', $model->id]); $dataPaymentQuery->orderBy('entry_date DESC, update_date DESC'); $sumPaymentValue = $sumPaymentQuery->createCommand()->queryOne(); // data for rendering $renderData = ['model' => $model, 'arrCustomerStatus' => $arrCustomerStatus, 'dataPaymentQuery' => $dataPaymentQuery, 'sumPaymentValue' => $sumPaymentValue]; } // render GUI return $this->render($renderView, $renderData); }