add payment method

This commit is contained in:
Roland Schneider 2016-01-17 16:21:37 +01:00
parent abb69ce92d
commit d043759b1d
20 changed files with 751 additions and 168 deletions

View File

@ -76,6 +76,7 @@ class AdminMenuStructure{
$items[] = ['label' => 'Vendégek', 'url' => ['/customer/index'] , 'target_url' => ['/customer/index' ,'/customer/view','/ticket/index-customer'] ];
$items[] = ['label' => 'Bérletkártyák', 'url' => ['/card/index'] ];
$items[] = ['label' => 'Bérletek', 'url' => ['/ticket/index' , 'TicketSearch[start]' =>$today,'TicketSearch[end]' => $tomorrow ] ];
$items[] = ['label' => 'Statisztika', 'url' => ['/ticket/statistics' , 'TicketSearchStatisitcs[start]' =>$today,'TicketSearchStatisitcs[end]' => $tomorrow ] ];
$this->menuItems[] = ['label' => 'Bérletek/Vendégek', 'url' => $this->emptyUrl,
'items' => $items
];
@ -98,7 +99,7 @@ class AdminMenuStructure{
// $items[] = ['label' => 'Bevétel', 'url' => ['/transfer/summary' , 'TransferSummarySearch[start]' =>$today,'TransferSummarySearch[end]' => $tomorrow ] ];
$items[] = ['label' => 'Napi bevételek', 'url' => ['/transfer/list', 'TransferListSearch[start]' =>$todayDatetime,'TransferListSearch[end]' => $tomorrowDatetime ] ];
$items[] = ['label' => 'Kassza müveletek', 'url' => ['/account-state/index'] ];
$items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ];
//$items[] = ['label' => 'Zárások', 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$todayDatetime,'CollectionSearch[end]' => $tomorrowDatetime ] ];
$this->menuItems[] = ['label' => 'Pénzügy', 'url' => $this->emptyUrl,
'items' => $items
];

View File

@ -14,38 +14,47 @@ use common\models\Account;
use common\models\User;
use common\models\Customer;
use common\models\Card;
use backend\models\TicketSearchStatisitcs;
/**
* TicketController implements the CRUD actions for Ticket model.
*/
class TicketController extends \backend\controllers\BackendController
{
public function behaviors()
{
class TicketController extends \backend\controllers\BackendController {
public function behaviors() {
return [
'access' => [
'class' => \yii\filters\AccessControl::className (),
'rules' => [
// allow authenticated users
[
'actions' => ['create','index','view','update','index-customer'],
'actions' => [
'create',
'index',
'view',
'update',
'index-customer',
'statistics'
],
'allow' => true,
'roles' => ['admin','employee','reception'],
],
'roles' => [
'admin',
'employee',
'reception'
]
]
]
// everything else is denied
],
],
]
];
}
/**
* Lists all Ticket models.
*
* @return mixed
*/
public function actionIndex()
{
public function actionIndex() {
$searchModel = new TicketSearch ();
$dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
$searchModel->searchTotals ();
@ -54,26 +63,67 @@ class TicketController extends \backend\controllers\BackendController
$searchModel->accounts = Account::read ();
$searchModel->ticketTypes = TicketType::read ();
return $this->render ( 'index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'dataProvider' => $dataProvider
] );
}
/**
* Lists all Ticket models.
*
* @return mixed
*/
public function actionStatistics() {
$searchModel = new TicketSearchStatisitcs();
$searchModel->search ( Yii::$app->request->queryParams );
$searchModel->searchTotals ();
$searchModel->users = User::read ();
$searchModel->accounts = Account::read ();
$searchModel->ticketTypes = TicketType::read ();
if ($searchModel->output == 'pdf') {
$user = User::findOne ( \Yii::$app->user->id );
$mpdf = new \mPDF ( 'utf-8', 'A4-L' );
$fn = "";
$ov = '_total_content_pdf';
$dt = "_letrehozva_" . date ( "Ymd_His" ) . "_" . $user->username;
$interval = "";
$account = "";
$currentUser = "";
$fn = $fn . $interval . $dt . $account . $currentUser . ".pdf";
$mpdf->useSubstitutions = false;
$mpdf->simpleTables = true;
$mpdf->SetHeader ( \Yii::$app->params ["company_name"] . " - Létrehozva: " . $user->username . ", " . \Yii::$app->formatter->asDatetime ( time () ) );
$mpdf->setFooter ( '{PAGENO} / {nb}' );
$stylesheet = file_get_contents ( \Yii::getAlias ( '@vendor' . '/bower/bootstrap/dist/css/bootstrap.css' ) ); // external css
$mpdf->WriteHTML ( $stylesheet, 1 );
$mpdf->WriteHTML ( $this->renderPartial ( 'statistics_pdf', [
'searchModel' => $searchModel
] ) );
$mpdf->Output ( $fn, 'D' );
exit ();
} else {
return $this->render ( 'statistics', [
'searchModel' => $searchModel
] );
}
}
/**
* Lists all Ticket models.
*
* @return mixed
*/
public function actionIndexCustomer($id)
{
public function actionIndexCustomer($id) {
$customer = Customer::findOne ( $id );
$card = Card::findOne ( $id );
if ($customer == null) {
throw new NotFoundHttpException ( 'The requested page does not exist.' );
}
@ -87,8 +137,6 @@ class TicketController extends \backend\controllers\BackendController
$searchModel->accounts = Account::read ();
$searchModel->ticketTypes = TicketType::read ();
return $this->render ( 'index_customer', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
@ -97,41 +145,42 @@ class TicketController extends \backend\controllers\BackendController
] );
}
/**
* Displays a single Ticket model.
*
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
public function actionView($id) {
return $this->render ( 'view', [
'model' => $this->findModel($id),
'model' => $this->findModel ( $id )
] );
}
/**
* Creates a new Ticket model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return mixed
*/
public function actionCreate()
{
public function actionCreate() {
$model = new Ticket ();
$discounts = Discount::read ();
$ticketTypes = TicketType::read ();
$accounts = Account::readAccounts ();
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
return $this->redirect(['view', 'id' => $model->id_ticket]);
return $this->redirect ( [
'view',
'id' => $model->id_ticket
] );
} else {
return $this->render ( 'create', [
'model' => $model,
'discounts' => $discounts,
'ticketTypes' => $ticketTypes,
'accounts' => $accounts,
'accounts' => $accounts
] );
}
}
@ -139,18 +188,21 @@ class TicketController extends \backend\controllers\BackendController
/**
* Updates an existing Ticket model.
* If update is successful, the browser will be redirected to the 'view' page.
*
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
public function actionUpdate($id) {
$model = $this->findModel ( $id );
if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
return $this->redirect(['view', 'id' => $model->id_ticket]);
return $this->redirect ( [
'view',
'id' => $model->id_ticket
] );
} else {
return $this->render ( 'update', [
'model' => $model,
'model' => $model
] );
}
}
@ -158,25 +210,27 @@ class TicketController extends \backend\controllers\BackendController
/**
* Deletes an existing Ticket model.
* If deletion is successful, the browser will be redirected to the 'index' page.
*
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
public function actionDelete($id) {
$this->findModel ( $id )->delete ();
return $this->redirect(['index']);
return $this->redirect ( [
'index'
] );
}
/**
* 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)
{
protected function findModel($id) {
if (($model = Ticket::findOne ( $id )) !== null) {
return $model;
} else {

View File

@ -0,0 +1,162 @@
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Ticket;
use common\components\Helper;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;
/**
* TicketSearch represents the model behind the search form about `common\models\Ticket`.
*/
class TicketSearchStatisitcs extends Ticket
{
public $timestampStart;
public $timestampEnd;
public $users;
public $accounts;
public $ticketTypes;
public $valid_in_interval;
public $created_in_interval;
public $expire_in_interval;
public $statistics;
public $statisticsTotal;
public $output;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['output'] , 'safe'],
[[ 'id_user', 'id_ticket_type', 'id_account'], 'integer'],
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[['valid_in_interval','created_in_interval','expire_in_interval'],'boolean'] ,
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
public function attributeLabels(){
return ArrayHelper::merge(parent::attributeLabels(), [
'start' => Yii::t('backend/ticket','Start of interval'),
'end' => Yii::t('backend/ticket','End of interval'),
'valid_in_interval' => Yii::t('backend/ticket','Valid in interval'),
'created_in_interval' => Yii::t('backend/ticket','Created in interval'),
'expire_in_interval' => Yii::t('backend/ticket','Expire in interval'),
]);
}
public function afterValidate(){
if ( !isset($this->timestampStart)) {
$this->timestampStart ='1900-01-01';
}
if ( !isset($this->timestampEnd)) {
$this->timestampEnd ='3000-01-01';
}
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$this->load($params);
$this->validate();
}
public function searchTotals(){
$query = Ticket::mkStatisticQuery($this->timestampStart, $this->timestampEnd,$this->id_card);
$this->statistics = $query->all();
$this->statisticsTotal =[
'valid' => 0,
'created' => 0,
'created_at_money' => 0,
'expired' => 0,
];
$this->statisticsTotal['valid'] = array_sum(array_column($this->statistics, 'valid'));
$this->statisticsTotal['created'] = array_sum(array_column($this->statistics, 'created'));
$this->statisticsTotal['created_money'] = array_sum(array_column($this->statistics, 'created_money'));
$this->statisticsTotal['expired'] = array_sum(array_column($this->statistics, 'expired'));
}
public static function mkSearchCondition( $timestampStart, $timestampEnd, $id_user,$id_ticket_tpye,$id_account,$valid_in_interval ,$expire_in_interval,$created_in_interval ){
$query = Ticket::find();
Helper::queryAccountConstraint($query, 'ticket.id_account');
$query->with('ticketType' );
$query->with('user');
$query->with('customer');
$query->andFilterWhere([
'id_user' => $id_user,
'id_ticket_type' => $id_ticket_type,
'id_account' => $id_account,
]);
$all = (!($valid_in_interval) && !($expire_in_interval) && !($created_in_interval) )
||
($valid_in_interval == true && $expire_in_interval == true && $created_in_interval);
$dateConditions = [];
$start = $timestampStart;
$end = $timestampEnd;
if( $all || $created_in_interval ){
$dateConditions[] = Helper::queryInIntervalRule('ticket.created_at', $start, $end);
}
if ( $all || $valid_in_interval ){
$dateConditions[] = Helper::queryValidRule('ticket.start', 'ticket.end', $start, $end);
}
if ( $all || $expire_in_interval ){
$dateConditions[] = Helper::queryExpireRule('ticket.start', 'ticket.end', $start, $end);
}
if ( count($dateConditions) == 1 ){
$query->andWhere($dateConditions[0]);
}else if ( count($dateConditions) > 1 ){
$cond = ['or'];
foreach ($dateConditions as $c){
$cond[] = $c;
}
$query->andWhere($cond);
}
}
}

View File

@ -87,7 +87,7 @@ class TransferSearch extends Transfer
]);
$query->addSelect( ['*' ]);
// $query->addSelect( ['*' ]);
$this->load($params);
@ -103,6 +103,8 @@ class TransferSearch extends Transfer
'transfer.id_user' => $this->id_user,
]);
$query->andFilterWhere(['in' ,'transfer.type', $this->types]);
$created_condition = ['and',[ '>=', 'transfer.created_at', $this->timestampStart ] ,[ '<', 'transfer.created_at', $this->timestampEnd ] ];
$paid_condition = ['and',[ '>=', 'transfer.paid_at', $this->timestampStart ] ,[ '<', 'transfer.paid_at', $this->timestampEnd ] ];

View File

@ -0,0 +1,65 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use kartik\widgets\DatePicker;
/* @var $this yii\web\View */
/* @var $model backend\models\TicketSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<?php
$ticketTypeOptions = ['' => 'Mind'] + ArrayHelper::map($model->ticketTypes, 'id_ticket_type', 'name');
$accountOptions = ['' => 'Mind'] + ArrayHelper::map($model->accounts, 'id_account', 'name');
$userOptions = ['' => 'Mind'] + ArrayHelper::map($model->users, 'id', 'username');
?>
<div class="ticket-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<div class='row'>
<div class='col-md-4'>
<?= $form->field($model, 'id_user')->dropDownList($userOptions) ?>
</div>
<div class='col-md-4'>
<?= $form->field($model, 'id_ticket_type')->dropDownList($ticketTypeOptions) ?>
</div>
<div class='col-md-4'>
<?= $form->field($model, 'id_account')->dropDownList($accountOptions) ?>
</div>
</div>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'start')->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
]
]) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'end') ->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
]
]) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton(Yii::t('common/ticket', 'Search'), ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,88 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use yii\data\ArrayDataProvider;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\TicketSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('common/ticket', 'Statisztika');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="ticket-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php echo $this->render('_search_statistics', ['model' => $searchModel]); ?>
<div class="panel panel-default">
<div class="panel-heading">Bérlet statisztika</div>
<div class="panel-body">
<p>Bérlet statisztika a kiválasztott időszakra</p>
<?php
if ( !isset($searchModel->output) ){
$pdfUrl = Url::current([ Html::getInputName($searchModel, 'output') => 'pdf']);
echo Html::a("PDF letöltése", $pdfUrl,['class' => 'btn btn-primary btn-all' ]);
}
?>
<?php
echo GridView::widget([
'dataProvider' => new ArrayDataProvider([
'allModels' => $searchModel->statistics,
'sort' => false,
'pagination' => false,
]),
'showFooter'=>TRUE,
'footerRowOptions'=>['style'=>'font-weight:bold; '],
'columns' =>[
[
'attribute' => 'name',
'label' => 'Bérlet',
'footer' => 'Összesen'
],
[
'attribute' => 'created',
'label' => 'Kiadva (Db)',
'footer' => $searchModel->statisticsTotal['created']
],
[
'attribute' => 'created_money',
'label' => 'Kiadott érték (Ft)',
'footer' => $searchModel->statisticsTotal['created_money']
],
[
'attribute' => 'valid',
'label' => 'Érvényes (Db)',
'footer' => $searchModel->statisticsTotal['valid']
],
[
'attribute' => 'expired',
'label' => 'Lejár az adott időszakban (Db)',
'footer' => $searchModel->statisticsTotal['expired']
]
]
]);
?>
</div>
</div>
</div>

View File

@ -0,0 +1,89 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use yii\data\ArrayDataProvider;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\TicketSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
?>
<style>
td{
text-align: right;
padding: 3px;
}
th{
text-align: center;
padding: 3px;
}
td.ticket-name{
text-align: left;
}
td.number{
text-align: right;
width: 150px;
}
</style>
<div class="ticket-statistics-pdf">
<h1>Bérlet statisztika a kiválasztott időszakra</h1>
<?php
echo GridView::widget ( [
'dataProvider' => new ArrayDataProvider ( [
'allModels' => $searchModel->statistics,
'sort' => false,
'pagination' => false
] ),
'showFooter' => TRUE,
'footerRowOptions' => [
'style' => 'font-weight:bold; '
],
'columns' => [
[
'attribute' => 'name',
'label' => 'Bérlet',
'footer' => 'Összesen' ,
'contentOptions' => [ 'class' => 'ticket-name']
],
[
'attribute' => 'created',
'label' => 'Kiadva (Db)',
'footer' => $searchModel->statisticsTotal ['created'] ,
'contentOptions' => [ 'class' => 'number']
],
[
'attribute' => 'created_money',
'label' => 'Kiadott érték (Ft)',
'footer' => $searchModel->statisticsTotal ['created_money'],
'contentOptions' => [ 'class' => 'number']
],
[
'attribute' => 'valid',
'label' => 'Érvényes (Db)',
'footer' => $searchModel->statisticsTotal ['valid'],
'contentOptions' => [ 'class' => 'number']
]
,
[
'attribute' => 'expired',
'label' => 'Lejár az adott időszakban (Db)',
'footer' => $searchModel->statisticsTotal ['expired'] ,
'contentOptions' => [ 'class' => 'number']
]
]
] );
?>
</div>

View File

@ -36,6 +36,14 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'id_user',
'value' => $model->userName,
],
[
'attribute' => 'id_discount',
'value' => $model->discountName,
],
[
'attribute' => 'payment_method',
'value' => $model->paymentMethodName,
],
'item_price',
'count',
'money',

View File

@ -75,6 +75,7 @@ class Ticket extends \common\models\BaseFitnessActiveRecord
'updated_at' => Yii::t('common/ticket', 'Updated At'),
'id_card' => Yii::t('backend/ticket','Card'),
'id_customer' => Yii::t('backend/ticket','Customer'),
'payment_method' => Yii::t('common/transfer', 'Fizetési mód'),
];
}

View File

@ -50,6 +50,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
const DIRECTION_OUT = 10;// MONEY GOES OUT FROM ACCOUNT ( COMPANY LOST MONEY )
const DIRECTION_IN = 20;//MONEY GOES IN TO THE ACCOUNT ( COMPANY EARN MONEY )
const PAYMENT_METHOD_CASH = 10;
const PAYMENT_METHOD_TRANSFER = 20;
/**
* @inheritdoc
@ -118,6 +120,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
'types' => Yii::t('common/transfer', 'Types'),
'start' => Yii::t('common/transfer', 'Start'),
'end' => Yii::t('common/transfer', 'End'),
'payment_method' => Yii::t('common/transfer', 'Fizetési mód'),
];
}
@ -457,6 +460,12 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
self::TYPE_TICKET => Yii::t('common/transfer','Ticket'),
];
}
public static function paymentMethods( ) {
return [
self::PAYMENT_METHOD_CASH=> Yii::t('common/transfer','Készpénz'),
self::PAYMENT_METHOD_TRANSFER => Yii::t('common/transfer','Bankkártyás fizetés'),
];
}
public static function statuses( ) {
return [
self::STATUS_NOT_PAID => Yii::t('common/transfer','Nincs fizetve'),
@ -471,6 +480,14 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
}
return $status;
}
public function getPaymentMethodName( ) {
$status = null;
$statuses = self::paymentMethods();
if ( array_key_exists($this->payment_method, $statuses)){
$status = $statuses[$this->payment_method];
}
return $status;
}
public function beforeDelete(){
parent::beforeDelete();
@ -721,6 +738,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
$query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);
$query->andWhere(['account.type' => Account::TYPE_ALL]);
$query->andWhere(['transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH]);
return $query->scalar();
}

View File

@ -254,6 +254,9 @@ class TransferListSearch extends Transfer
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
$query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);
if ( !$this->isModeAdmin()){
$query->andWhere(['transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH]);
}
}
@ -379,6 +382,7 @@ class TransferListSearch extends Transfer
$query->select(['coalesce(sum(transfer.count * GREATEST(( product.sale_price - coalesce(product.purchase_price,0)),0)),0) AS product_money' ]);
$query->from('transfer');
$query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]);
$query->andWhere(['transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH]);
$query->innerJoin("sale", "sale.id_sale = transfer.id_object");
$query->innerJoin("product", "sale.id_product = product.id_product");
$this->addQueryFilters($query);

View File

@ -0,0 +1,30 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160117_122835_alter_table_transfer_add_column_payment_method extends Migration
{
public function up()
{
$this->addColumn("transfer", "payment_method", "int");
$this->execute("update transfer set payment_method = 10");
}
public function down()
{
return true;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -78,14 +78,16 @@ class ProductSaleForm extends Model
public $products;
public $payment_method;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_product','count','id_account'], 'required'],
[['id_product','id_currency','id_account', 'id_discount','count'], 'integer'],
[['id_product','count','id_account','payment_method'], 'required'],
[['id_product','id_currency','id_account', 'id_discount','count','payment_method'], 'integer'],
[['comment'], 'string' ,'max' => 255],
[['cart'], 'string' ,'max' => 20],
[['id_product' ], 'validateProduct'],
@ -108,6 +110,7 @@ class ProductSaleForm extends Model
'id_account' => Yii::t("frontend/product", "Account"),
'id_discount' => Yii::t("frontend/product", "Discount"),
'comment' => Yii::t("frontend/product", "Comment"),
'payment_method' => Yii::t('common/transfer', 'Fizetési mód'),
];
}
@ -199,6 +202,7 @@ class ProductSaleForm extends Model
}
$this->transfer = Transfer::createProductTransfer($this->sale,$this->account, $this->discount, $this->currency, $this->count, $this->product,$status,$customer);
$this->transfer->payment_method = $this->payment_method;
if ( isset($this->comment)){
$this->transfer->comment = $this->comment;
}

View File

@ -32,6 +32,8 @@ class TicketCreate extends Ticket{
public $cart;
public $payment_method;
public function rules()
{
return [
@ -48,6 +50,11 @@ class TicketCreate extends Ticket{
[[ 'id_account'], 'integer'],
[[ 'id_account'], 'validateAccount'],
/////////////////////
//payment_method
/////////////////////
[[ 'payment_method'], 'required'],
[[ 'payment_method'], 'integer'],
/////////////////////
//id_discount
/////////////////////
[[ 'id_discount'], 'integer'],
@ -123,7 +130,7 @@ class TicketCreate extends Ticket{
$transfer->paid_by = \Yii::$app->user->id;
}
$transfer->status = $status;
$transfer->payment_method = $this->payment_method;
if ( isset($this->comment)){
$transfer->comment = $this->comment;

View File

@ -2,6 +2,7 @@
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;
use common\models\Transfer;
/* @var $this yii\web\View */
/* @var $model frontend\models\ProductSaleForm */
@ -94,6 +95,11 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name'
<?php echo $form->field($model,'id_discount')->dropDownList($discountOptions) ?>
</div>
</div>
<div class="row">
<div class='col-md-12'>
<?php echo $form->field($model,'payment_method')->dropDownList(Transfer::paymentMethods()) ?>
</div>
</div>
<div class="row">
<div class='col-md-12'>
<?php echo $form->field( $model,'comment' )->textarea() ?>

View File

@ -5,6 +5,7 @@ use yii\widgets\ActiveForm;
use frontend\components\HtmlHelper;
use kartik\widgets\DatePicker;
use common\models\Account;
use common\models\Transfer;
/* @var $this yii\web\View */
/* @var $model common\models\Ticket */
@ -43,7 +44,9 @@ use common\models\Account;
<?= $form->field($model, 'id_account')->dropDownList($accountOptions) ?>
<?php //echo $form->field($model, 'id_discount')->dropDownList($discountOptions) ?>
<?php echo $form->field($model,'payment_method')->dropDownList(Transfer::paymentMethods()) ?>
<?php echo $form->field($model, 'id_discount')->dropDownList($discountOptions) ?>
<?= $form->field($model, 'start')->widget(DatePicker::classname(), [
'pluginOptions' => [

View File

@ -40,6 +40,15 @@ if ( isset($receptionForm->card) ){
$options['customer_cart'] = $model->customerCart;
}
$discountItems = [];
foreach ($discounts as $d){
$item = [];
$item['id_discount'] = $d->id_discount;
$item['value'] = $d->value;
$discountItems[] = $item;
}
$options['discounts'] = $discountItems;
$this->registerJs ( 'new TicketSell( '. json_encode($options).');' );
?>
<div class="ticket-create">

View File

@ -31,6 +31,9 @@ $formatter = Yii::$app->formatter;
<dt><?php echo $model->getAttributeLabel( 'status') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'statusName') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'payment_method') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'paymentMethodName') ?></dd>
</dl>
</div>
<div class='col-md-4'>

View File

@ -541,7 +541,7 @@ function ProductSell(o){
function normalizePrice( price ){
var result;
// result = hufRound(price);
return result;
return price;
}
function hufRound(x)

View File

@ -21,6 +21,7 @@ function TicketSell(o){
},
],
selector_type: '#ticketcreate-id_ticket_type',
selector_discount: '#ticketcreate-id_discount',
selector_start: '#ticketcreate-start',
selector_end: '#ticketcreate-end',
selector_account: '#ticketcreate-id_account',
@ -47,6 +48,8 @@ function TicketSell(o){
url_pay_user_cart: '',
url_delete_transaction: '',
url_pay_transaction: '',
discounts : [],
discount: null,
};
@ -55,6 +58,7 @@ function TicketSell(o){
function init(){
$.extend(app.defaults, o );
addBehaviourTypeChangedListener();
addBehaviourDiscountChangedListener();
useDefaults();
createCarts();
addPayoutButtons();
@ -187,6 +191,9 @@ function TicketSell(o){
function addBehaviourTypeChangedListener(){
$(app.defaults.selector_type).change(change);
}
function addBehaviourDiscountChangedListener(){
$(app.defaults.selector_discount).change(typeChanged);
}
function change(event){
if ( '#'+event.target.id == app.defaults.selector_type ){
@ -204,6 +211,7 @@ function TicketSell(o){
validateStartDate();
validateEndDate();
validateMaxUsageCount();
validateDiscount();
validatePriceBrutto();
validateAccount();
}
@ -221,6 +229,22 @@ function TicketSell(o){
}
}
function validateDiscount(){
var discount;
discount = +$(app.defaults.selector_discount).val();
app.defaults.discount = null;
console.info( app.defaults.discounts );
for ( var i = 0; i < app.defaults.discounts.length; i++ ){
if ( app.defaults.discounts[i].id_discount == discount){
app.defaults.discount = app.defaults.discounts[i];
break;
}
}
console.info( 'discount found:');
console.info( app.defaults.discount );
}
function validateStartDate(){
app.defaults.start_date = moment( $( app.defaults.selector_start ).val(), app.defaults.date_format_moment) ;
@ -258,6 +282,11 @@ function TicketSell(o){
function validatePriceBrutto(){
app.defaults.price = app.defaults.ticket_type.price_brutto;
if ( app.defaults.discount != null ){
var d = app.defaults.price * app.defaults.discount['value'] /100;
d = Math.floor( d );
app.defaults.price = app.defaults.price - d;
}
}
function validateAccount(){
app.defaults.id_account = $('#ticketcreate-id_account').val();