add display money to account state close, delete ticket on customer tickets
This commit is contained in:
@@ -12,6 +12,8 @@ use common\models\Account;
|
||||
use common\components\DailyListing;
|
||||
use common\models\User;
|
||||
use common\components\accountstate\AccountStateMail;
|
||||
use common\models\Transfer;
|
||||
use common\components\Helper;
|
||||
|
||||
/**
|
||||
* AccountStateController implements the CRUD actions for AccountState model.
|
||||
@@ -111,6 +113,17 @@ class AccountStateController extends Controller {
|
||||
$model->type = AccountState::TYPE_CLOSE;
|
||||
$model->id_user = Yii::$app->user->id;
|
||||
$model->id_account = Account::readDefault ();
|
||||
|
||||
$lastCassaState = AccountState::readLast(null,null, Account::readDefault());
|
||||
|
||||
|
||||
|
||||
|
||||
if ( Helper::isAccountStateClosePreloadMoney()){
|
||||
$model->money = $this->readCassaClose();
|
||||
}
|
||||
|
||||
|
||||
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
|
||||
|
||||
|
||||
@@ -128,11 +141,22 @@ class AccountStateController extends Controller {
|
||||
return $this->render ( 'close', [
|
||||
'model' => $model,
|
||||
'accounts' => $accounts,
|
||||
'lastStates' => $lastStates
|
||||
'lastStates' => $lastStates ,
|
||||
'lastCassaState' => $lastCassaState,
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
protected function readCassaClose(){
|
||||
$total = 0;
|
||||
$cassaOpen = AccountState::readLast(AccountState::TYPE_OPEN,null, Account::readDefault());
|
||||
if ( isset($cassaOpen )){
|
||||
$total += $cassaOpen->money;
|
||||
}
|
||||
$total += Transfer::readPaid($cassaOpen->created_at, date('Y-d-m h:i:s'), \Yii::$app->user->id);
|
||||
return $total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the AccountState model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
|
||||
@@ -126,5 +126,54 @@ class TicketController extends FrontendController
|
||||
'receptionForm' => $receptionForm,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Transfer model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionDelete($id)
|
||||
{
|
||||
$ticket = $this->findModel($id);
|
||||
$transfer = Transfer::find()->andWhere(['transfer.type' => Transfer::TYPE_TICKET])
|
||||
->andWhere(['transfer.id_object' => $ticket->id_ticket])
|
||||
->one();
|
||||
$connection = \Yii::$app->db;
|
||||
$transaction = $connection->beginTransaction();
|
||||
try {
|
||||
ShoppingCart::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
|
||||
UserSoldItem::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
|
||||
if ( $transfer->delete() ){
|
||||
\Yii::$app->session->setFlash( 'success','Bérlet törölve' );
|
||||
$transaction->commit();
|
||||
}else{
|
||||
throw new \Exception("Failed to save");
|
||||
}
|
||||
|
||||
} catch(Exception $e) {
|
||||
$transaction->rollback();
|
||||
\Yii::$app->session->setFlash( 'danger','Bérlet törlése nem sikerült' );
|
||||
}
|
||||
|
||||
|
||||
return $this->redirect(Yii::$app->request->referrer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Ticket model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return Ticket the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Ticket::findOne($id)) !== null) {
|
||||
return $model;
|
||||
} else {
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user