diff --git a/backend/assets/WasteCreateAsset.php b/backend/assets/WasteCreateAsset.php
new file mode 100644
index 0000000..f9bdac5
--- /dev/null
+++ b/backend/assets/WasteCreateAsset.php
@@ -0,0 +1,31 @@
+
+ * @since 2.0
+ */
+class WasteCreateAsset extends AssetBundle
+{
+ public $basePath = '@webroot';
+ public $baseUrl = '@web';
+ public $css = [
+ ];
+ public $js = [
+ 'js/app.js',
+ 'js/waste.create.js',
+ ];
+ public $depends = [
+ 'backend\assets\AppAsset',
+ 'yii\jui\JuiAsset',
+ 'common\assets\TypeAheadAsset',
+ ];
+}
diff --git a/backend/components/AdminMenuStructure.php b/backend/components/AdminMenuStructure.php
index b53c099..340fba3 100644
--- a/backend/components/AdminMenuStructure.php
+++ b/backend/components/AdminMenuStructure.php
@@ -82,7 +82,7 @@ class AdminMenuStructure{
$items[] = ['label' => 'Kártya csomag RFId hozzárendelés', 'url' => ['/card-package/import' , ] ];
$items[] = ['label' => 'Érvényességek újraszámolása', 'url' => ['/card/recalculate' , ] ];
$this->menuItems[] = ['label' => 'Bérletek/Vendégek', 'url' => $this->emptyUrl,
- 'items' => $items
+ 'items' => $items
];
/////////////////////////////
@@ -91,13 +91,15 @@ class AdminMenuStructure{
$items = [];
$items[] = ['label' => 'Termékek', 'url' => ['/product/index'] ];
$items[] = ['label' => 'Beszerzések', 'url' => ['/procurement/index'] ];
+ $items[] = ['label' => 'Selejt', 'url' => ['/waste/index' ,'WasteSearch[date_start]' =>$today,'WasteSearch[date_end]' => $tomorrow ] ];
$items[] = ['label' => 'Leltár csoport', 'url' => ['/inventory-group/index'] ];
$items[] = ['label' => 'Leltár', 'url' => ['/inventory/index'] ];
$items[] = ['label' => 'Részletes eladások', 'url' => ['/transfer/sale' ,'TransferSaleSearch[start]' =>$todayDatetime,'TransferSaleSearch[end]' => $tomorrowDatetime ] ];
$items[] = ['label' => 'Termék összesítő', 'url' => ['/product/statistics' ,'ProductStatisticsSearch[start]' =>$todayDatetime,'ProductStatisticsSearch[end]' => $tomorrowDatetime ] ];
$this->menuItems[] = ['label' => 'Termékek', 'url' => $this->emptyUrl,
- 'items' => $items
+ 'items' => $items
];
+
/////////////////////////////
// Pénzügy
/////////////////////////////
diff --git a/backend/controllers/WasteController.php b/backend/controllers/WasteController.php
new file mode 100644
index 0000000..83eb57c
--- /dev/null
+++ b/backend/controllers/WasteController.php
@@ -0,0 +1,135 @@
+ [
+ 'class' => VerbFilter::className (),
+ 'actions' => [
+ 'delete' => [
+ 'post'
+ ]
+ ]
+ ]
+ ];
+ }
+
+ /**
+ * Lists all Waste models.
+ *
+ * @return mixed
+ */
+ public function actionIndex() {
+ $searchModel = new WasteSearch ();
+ $dataProvider = $searchModel->search ( Yii::$app->request->queryParams );
+
+ return $this->render ( 'index', [
+ 'searchModel' => $searchModel,
+ 'dataProvider' => $dataProvider
+ ] );
+ }
+
+ /**
+ * Displays a single Waste model.
+ *
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionView($id) {
+ return $this->render ( 'view', [
+ 'model' => $this->findModel ( $id )
+ ] );
+ }
+
+ /**
+ * Creates a new Waste model.
+ * If creation is successful, the browser will be redirected to the 'view' page.
+ *
+ * @return mixed
+ */
+ public function actionCreate() {
+ $model = new WasteCreateForm ();
+
+ $products = Product::find ()->all ();
+ $products = Product::modelToMapIdNameLong ( $products );
+
+ if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) {
+
+ $model->save ( );
+ return $this->redirect ( [
+ 'index'
+ ] );
+ }
+ return $this->render ( 'create', [
+ 'model' => $model,
+ 'products' => $products
+ ] );
+ }
+
+ /**
+ * Updates an existing Waste model.
+ * If update is successful, the browser will be redirected to the 'view' page.
+ *
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionUpdate($id) {
+ $model = $this->findModel ( $id );
+
+ if ($model->load ( Yii::$app->request->post () ) && $model->save ()) {
+ return $this->redirect ( [
+ 'view',
+ 'id' => $model->id_waste
+ ] );
+ } else {
+ return $this->render ( 'update', [
+ 'model' => $model
+ ] );
+ }
+ }
+
+ /**
+ * Deletes an existing Waste model.
+ * If deletion is successful, the browser will be redirected to the 'index' page.
+ *
+ * @param integer $id
+ * @return mixed
+ */
+ public function actionDelete($id) {
+ $this->findModel ( $id )->delete ();
+
+ return $this->redirect ( [
+ 'index'
+ ] );
+ }
+
+ /**
+ * Finds the Waste model based on its primary key value.
+ * If the model is not found, a 404 HTTP exception will be thrown.
+ *
+ * @param integer $id
+ * @return Waste the loaded model
+ * @throws NotFoundHttpException if the model cannot be found
+ */
+ protected function findModel($id) {
+ if (($model = Waste::findOne ( $id )) !== null) {
+ return $model;
+ } else {
+ throw new NotFoundHttpException ( 'The requested page does not exist.' );
+ }
+ }
+}
diff --git a/backend/models/WasteCreateForm.php b/backend/models/WasteCreateForm.php
new file mode 100644
index 0000000..6ebdf78
--- /dev/null
+++ b/backend/models/WasteCreateForm.php
@@ -0,0 +1,102 @@
+ 255],
+ [['productIdentifier'], 'string', 'max' => 128],
+ [['id_product'] ,'validateProduct','skipOnEmpty' => false, 'skipOnError' => false]
+ ];
+ }
+
+ public function validateProduct($attribute,$params){
+ $this->_product = null;
+
+
+ if ( isset($this->productIdentifier)){
+ $this->_product = Product::findOne($this->id_product);
+ }
+
+ if ( $this->_product == null ){
+ $this->addError('productIdentifier' , Yii::t("common/procurement", "Invalid product"));
+ }
+
+ }
+
+ public function attributeLabels( ) {
+ return [
+ 'count' => "Mennyiség",
+ 'comment' => "Megjegyzés"
+ ];
+ }
+
+ public function save(){
+
+ $connection = \Yii::$app->db;
+
+ $transaction = $connection->beginTransaction();
+
+ try {
+
+ $model = new Waste();
+ $model->id_product = $this->id_product;
+ $model->count = $this->count;
+ $model->stock_before = $this->_product->stock;
+ $model->stock_after = $this->_product->stock - $this->count;
+ $model->id_user = \Yii::$app->user->id;
+ $model->comment = $this->comment;
+
+ if ( !$model->save(false)){
+ throw new HttpException("Nem sikerült menteni a selejtet");
+ }
+
+ $product = $this->_product;
+ $product->stock = $product->stock - $this->count;
+
+ if ( !$product->save(false) ){
+ throw new HttpException("Nem sikerült menteni a terméket");
+ }
+
+ Log::log([
+ 'type' =>Log::$TYPE_WASTE,
+ 'message' => "Selejt létrehozva. Termék:".$product->name ." Mennyiség: ". $this->count ,
+ 'id_product' => $product->id_product
+ ]);
+
+ $transaction->commit();
+
+ Helper::flash('success', Yii::t('backend/procurement', 'Selejtezés mentve'));
+
+ } catch (\Exception $e) {
+ $transaction->rollback();
+ throw $e;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/backend/models/WasteSearch.php b/backend/models/WasteSearch.php
new file mode 100644
index 0000000..7f21846
--- /dev/null
+++ b/backend/models/WasteSearch.php
@@ -0,0 +1,117 @@
+ 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
+ [[ 'date_end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
+ ];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function scenarios()
+ {
+ // bypass scenarios() implementation in the parent class
+ return Model::scenarios();
+ }
+
+ /**
+ * Creates data provider instance with search query applied
+ *
+ * @param array $params
+ *
+ * @return ActiveDataProvider
+ */
+ public function search($params)
+ {
+// $query = Waste::find();
+
+ $query = new Query();
+ $query->select([
+ "p.name as product_name",
+ 'w.count as waste_count',
+ 'w.created_at as waste_created_at',
+ 'w.comment as waste_comment',
+ 'w.stock_before as waste_stock_before',
+ 'w.stock_after as waste_stock_after',
+ 'u.username as user_username',
+ ]);
+ $query->from("waste as w");
+ $query->innerJoin("product as p","p.id_product = w.id_product");
+ $query->innerJoin("user as u","u.id = w.id_user");
+
+ $dataProvider = new ActiveDataProvider([
+ 'query' => $query,
+ 'sort' =>[
+ 'defaultOrder' => [
+ 'waste_created_at' => SORT_DESC
+ ],
+ 'attributes' => Helper::mkYiiSortItems([
+ ['product_name'],
+ ['waste_count'],
+ ['waste_created_at'],
+ ['waste_comment'],
+ ['waste_stock_before'],
+ ['waste_stock_after'],
+ ['user_username'],
+
+ ])
+ ]]);
+
+ $this->load($params);
+
+ if (!$this->validate()) {
+ // uncomment the following line if you do not want to return any records when validation fails
+ // $query->where('0=1');
+ return $dataProvider;
+ }
+
+ $query->andFilterWhere([
+ 'w.id_user' => $this->id_user,
+ 'w.id_product' => $this->id_product,
+ ]);
+
+ if ( empty($this->date_start) ){
+ $this->timestampStart = '';
+ }
+ if ( empty($this->date_end) ){
+ $this->timestampEnd = '';
+ }
+
+ $query->andFilterWhere([ '>=', 'w.created_at', $this->timestampStart ] );
+ $query->andFilterWhere([ '<', 'w.created_at', $this->timestampEnd ] );
+
+ $query->andFilterWhere(['like', 'w.comment', $this->comment]);
+
+ return $dataProvider;
+ }
+}
diff --git a/backend/views/procurement/_search.php b/backend/views/procurement/_search.php
index 77846ad..62727f0 100644
--- a/backend/views/procurement/_search.php
+++ b/backend/views/procurement/_search.php
@@ -54,7 +54,7 @@ $warehouses = mkOptions( ArrayHelper::map( $warehouses ,'id_warehouse','name')
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
]
- ]) ?>
+ ])->label("Időintervallum kezdete") ?>
= $form->field($model, 'date_end') ->widget(DatePicker::classname(), [
@@ -62,7 +62,7 @@ $warehouses = mkOptions( ArrayHelper::map( $warehouses ,'id_warehouse','name')
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
]
- ]) ?>
+ ])->label("Időintervallum vége") ?>
diff --git a/backend/views/transfer/view.php b/backend/views/transfer/view.php
index 453e37a..d3c1abf 100644
--- a/backend/views/transfer/view.php
+++ b/backend/views/transfer/view.php
@@ -46,16 +46,32 @@ $this->params ['breadcrumbs'] [] = $this->title;
status == Transfer::STATUS_STORNO) {
- echo Html::a ( "Bérlet fizetetlennek jelölése és vásárló kosarába helyezése", [
- 'transfer/unstorno',
- 'id' => $model->id_transfer
- ], [
- 'class' => 'btn btn-danger',
- 'data-confirm' => "Figyelem, a bérlet fizetetlennek lesz jelölve !!",
- 'data-method' => 'post'
- ] );
+if (RoleDefinition::isAdmin () ) {
+
+ if ( $model->type == Transfer::TYPE_TICKET ){
+
+ if ($model->status == Transfer::STATUS_STORNO || $model->status == Transfer::STATUS_PAID ) {
+
+ ?>
+ Sztornózott vagy fizetett bérlet fizetettlenre állítása:
+
+ - A tranzakció státusza fizetetlen lesz
+ - A bérlet státusza inaktív lesz ( a bérlettel nem lehet bemenni a forgó kapun)
+ - A bérlet a vásárló kosarába kerül
+
+ $model->id_transfer
+ ], [
+ 'class' => 'btn btn-danger',
+ 'data-confirm' => "Figyelem, a bérlet fizetetlennek lesz jelölve !!",
+ 'data-method' => 'post'
+ ] );
+ }
}
+
+
}
?>
diff --git a/backend/views/waste/_form.php b/backend/views/waste/_form.php
new file mode 100644
index 0000000..7dee25b
--- /dev/null
+++ b/backend/views/waste/_form.php
@@ -0,0 +1,30 @@
+
+
+
diff --git a/backend/views/waste/_search.php b/backend/views/waste/_search.php
new file mode 100644
index 0000000..f0b71a8
--- /dev/null
+++ b/backend/views/waste/_search.php
@@ -0,0 +1,69 @@
+
+
+ Yii::t('common/product','All' ) ];
+
+ $o = $all + $options;
+
+ return $o;
+}
+
+$products = mkOptions( ArrayHelper::map( Product::find()->all() ,'id_product','name') );
+$users = mkOptions( ArrayHelper::map( User::find()->all() ,'id','username') );
+?>
+
+
+
+ ['index'],
+ 'method' => 'get',
+ ]); ?>
+
+
+ = $form->field($model, 'id_user')->dropDownList($users) ?>
+
+
+ = $form->field($model, 'id_product')->dropDownList($products) ?>
+
+
+
+
+ = $form->field($model, 'date_start')->widget(DatePicker::classname(), [
+ 'pluginOptions' => [
+ 'autoclose'=>true,
+ 'format' => 'yyyy.mm.dd'
+ ]
+ ])->label("Időintervallum kezdete") ?>
+
+
+ = $form->field($model, 'date_end') ->widget(DatePicker::classname(), [
+ 'pluginOptions' => [
+ 'autoclose'=>true,
+ 'format' => 'yyyy.mm.dd'
+ ]
+ ]) ->label("Időintervallum vége") ?>
+
+
+
+
+ = Html::submitButton(Yii::t('common/waste', 'Keresés'), ['class' => 'btn btn-primary']) ?>
+
+
+
+
+
diff --git a/backend/views/waste/create.php b/backend/views/waste/create.php
new file mode 100644
index 0000000..9fcf4d7
--- /dev/null
+++ b/backend/views/waste/create.php
@@ -0,0 +1,51 @@
+title = Yii::t('common/waste', 'Új selejt');
+$this->params['breadcrumbs'][] = ['label' => Yii::t('common/waste', 'Selejtek'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+
+WasteCreateAsset::register($this);
+
+$options = [];
+$options['products'] = $products;
+$options['url_product_find'] = Url::toRoute(['product/find']);
+
+$this->registerJs(' new WasteCreate( '. json_encode($options) .' );');
+
+?>
+
+
+
= Html::encode($this->title) ?>
+
+
+
+
+
+ | Terméknév |
+ |
+
+
+ | Mennyiség |
+ |
+
+
+ | Termék kategória |
+ |
+
+
+
+
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/views/waste/index.php b/backend/views/waste/index.php
new file mode 100644
index 0000000..9f80dbf
--- /dev/null
+++ b/backend/views/waste/index.php
@@ -0,0 +1,51 @@
+title = Yii::t('common/waste', 'Selejtek');
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+ render('_search', ['model' => $searchModel]); ?>
+
+
+ = Html::a(Yii::t('common/waste', 'Új selejt'), ['create'], ['class' => 'btn btn-success']) ?>
+
+
+ = GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'columns' => [
+
+ [
+ 'attribute' => "waste_created_at",
+ 'label' => "Létrehozva"
+ ],
+ [
+ 'attribute' => "user_username",
+ 'label' => "Felhasználó"
+ ],
+ [
+ 'attribute' => "product_name",
+ 'label' => "Termék"
+ ],
+ [
+ 'attribute' => "waste_count",
+ 'label' => "Mennyiség"
+ ],
+ [
+ 'attribute' => "waste_comment",
+ 'label' => "Megjegyzés"
+ ],
+
+ // ['class' => 'yii\grid\ActionColumn'],
+ ],
+ ]); ?>
+
+
diff --git a/backend/views/waste/update.php b/backend/views/waste/update.php
new file mode 100644
index 0000000..ea0d36f
--- /dev/null
+++ b/backend/views/waste/update.php
@@ -0,0 +1,23 @@
+title = Yii::t('common/waste', 'Update {modelClass}: ', [
+ 'modelClass' => 'Waste',
+]) . ' ' . $model->id_waste;
+$this->params['breadcrumbs'][] = ['label' => Yii::t('common/waste', 'Wastes'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => $model->id_waste, 'url' => ['view', 'id' => $model->id_waste]];
+$this->params['breadcrumbs'][] = Yii::t('common/waste', 'Update');
+?>
+
+
+
= Html::encode($this->title) ?>
+
+ = $this->render('_form', [
+ 'model' => $model,
+ ]) ?>
+
+
diff --git a/backend/views/waste/view.php b/backend/views/waste/view.php
new file mode 100644
index 0000000..7ed047d
--- /dev/null
+++ b/backend/views/waste/view.php
@@ -0,0 +1,43 @@
+title = $model->id_waste;
+$this->params['breadcrumbs'][] = ['label' => Yii::t('common/waste', 'Wastes'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
+
= Html::encode($this->title) ?>
+
+
+ = Html::a(Yii::t('common/waste', 'Update'), ['update', 'id' => $model->id_waste], ['class' => 'btn btn-primary']) ?>
+ = Html::a(Yii::t('common/waste', 'Delete'), ['delete', 'id' => $model->id_waste], [
+ 'class' => 'btn btn-danger',
+ 'data' => [
+ 'confirm' => Yii::t('common/waste', 'Are you sure you want to delete this item?'),
+ 'method' => 'post',
+ ],
+ ]) ?>
+
+
+ = DetailView::widget([
+ 'model' => $model,
+ 'attributes' => [
+ 'id_waste',
+ 'count',
+ 'id_product',
+ 'stock_before',
+ 'stock_after',
+ 'id_user',
+ 'comment',
+ 'created_at',
+ 'updated_at',
+ ],
+ ]) ?>
+
+
diff --git a/backend/web/js/waste.create.js b/backend/web/js/waste.create.js
new file mode 100644
index 0000000..75a339b
--- /dev/null
+++ b/backend/web/js/waste.create.js
@@ -0,0 +1,114 @@
+
+
+function WasteCreate(o){
+
+
+ var defaults = {
+ 'selector_product' : '#wastecreateform-productidentifier',
+ 'url_product_find' : 'product/find',
+ "products" : []
+ };
+
+ var product = null;
+
+ init();
+
+ function init(){
+ defaults = $.extend(defaults,o);
+ addPreventEnterToProduct();
+ initAutocomplete();
+ }
+
+
+ function addPreventEnterToProduct(){
+ doPreventSubmit($(defaults.selector_product));
+ }
+
+
+ function initAutocomplete(){
+// var colors = ["red", "blue", "green", "yellow", "brown", "black"];
+// $('#product_search').typeahead( {source: colors } );
+
+ var $input = $(defaults.selector_product);
+ console.info("len:" + $input.length);
+ console.info('products: ' + defaults.products.length);
+ $input.typeahead({source : defaults.products,
+ autoSelect: true,
+ items: 20,
+ minLength: 3,
+// displayText: function (item){
+// return item.text;
+// }
+
+ });
+ $input.change(function() {
+ var current = $input.typeahead("getActive");
+ $("#filter_text").val('');
+ if (current) {
+ // Some item from your model is active!
+ if (current.name == $input.val()) {
+ // This means the exact match is found. Use toLowerCase() if you want case insensitive match.
+// console.info(current);
+ _findProduct(current.id_product);
+ } else {
+ // This means it is only a partial match, you can either add a new item
+ // or take the active if you don't want new items
+// console.info('partial');
+ product = null;
+ updateTableProduct();
+ }
+ } else {
+ // Nothing is active so it is a new value (or maybe empty value)
+// console.info('incactive');
+ product = null;
+ updateTableProduct();
+ }
+ });
+ }
+
+
+ function _findProduct(id){
+ var data, url;
+
+ url = defaults.url_product_find;
+ data = {
+ 'id' : id,
+ };
+
+ $.ajax({
+ dataType: "json",
+ url: url,
+ data: data,
+ success: onFindProductReady
+ });
+ }
+
+ function clearTableProduct(){
+ $('.product-name').html('');
+ $('.product-stock').html('');
+ $('.product-category').html('');
+ $('#wastecreateform-id_product').val('');
+ }
+
+ function fillTableProduct(){
+ $('.product-name').html(product.name);
+ $('.product-stock').html(product.stock);
+ $('.product-category').html(product.category);
+ $('#wastecreateform-id_product').val(product.id_product);
+ }
+
+ function updateTableProduct(){
+ clearTableProduct();
+ fillTableProduct();
+ }
+
+
+ function onFindProductReady(json){
+ product = json.product;
+ fillTableProduct();
+ }
+
+
+
+
+}
\ No newline at end of file
diff --git a/changelog.txt b/changelog.txt
index b29fc20..a7a8848 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,3 +1,9 @@
+-0.0.70
+ - add make ticket transfer unpaid
+ - add ticket in cart is inactive
+-0.0.69
+ - add waste
+ - add default inactive on ticket sale
-0.0.68
- add multi detsta upload
- add doorlog console changes
diff --git a/common/components/TicketSale.php b/common/components/TicketSale.php
index 27053c7..d5437c0 100644
--- a/common/components/TicketSale.php
+++ b/common/components/TicketSale.php
@@ -2,6 +2,6 @@
use yii\base\Object;
use common\models\TicketType;
use common\models\Transfer;
use common\models\Ticket;
use common\models\Discount;
-class TicketSale extends Object{
/**
* A bérlet típusa. Kötelező
* */
public $ticketType;
/**
* A vendég . Kötelező
* */
public $customer;
/**
* A kassza. Kötelező
* */
public $account;
/**
* A bérletkártya. Kötelező
* */
public $card;
/**
* A kedvezmény. Opcionális
* */
public $discount;
/*
* Bérlet érvényesség első napja. Opcionális.
* Ha nincs megadva, a mai nap
* */
public $start;
/**
* A bérlet érvényességének utolsó napja. OPcionális.
* Ha nincs megadva a bérlet típusból számoljuk ki.
* Ha van megadva megbízás, akkor a megbízásból számoljuk ki
*
* */
public $end;
/**
* A szerződs. Opcionális
* */
public $contract;
/**
* Tranzakció állapota. Default: paid
* */
public $transferStatus = Transfer::STATUS_PAID;
/**
* A fizetési mód. Default : transfer
* */
public $paymentMethod = Transfer::PAYMENT_METHOD_TRANSFER;
/**
* if this is set, money and start date will be read from this object
* */
public $ticketInstallmentRequest;
/**
* A létrehozott bérlet
* */
public $ticket;
/**
* A létrehozott tranzakció
* */
public $transfer;
/**
* A bérlet ára. Opcionális
* Ha nincs megadva a bérlet típusból számoljuk ki
* Ha van megbízás, a megbízásból számoljuk ki
* */
public $money;
public function doSale(){
$this->readMoney();
$this->readStartDate();
$this->readEndDate();
$this->mkTicket();
$this->mkTransfer();
$this->addToCustomerCart();
}
protected function mkTicket( ) {
$this->ticket = new Ticket ();
$this->ticket->id_user = \Yii::$app->user->id;
$this->ticket->id_ticket_type = $this->ticketType->id_ticket_type; // save to contract
$this->ticket->id_account = $this->account->id_account;
$this->ticket->id_discount = isset($this->discount) ? $this->discount->id_discount : null; // contract.id_discount
$this->ticket->start = $this->start;
$this->ticket->end = $this->end;
$this->ticket->max_usage_count = $this->ticketType->max_usage_count;
$this->ticket->usage_count = 0;
$this->ticket->status = Ticket::STATUS_ACTIVE;
$this->ticket->price_brutto = $this->money;
$this->ticket->id_card = $this->card->id_card;
if ( isset( $this->ticketInstallmentRequest ) ){
$this->ticket->part = $this->ticketInstallmentRequest->priority;
}
if (isset($this->contract)){
$this->ticket->id_contract = $this->contract->id_contract;
}
if ( !$this->ticket->save ( false ) ){
\Yii::error("Nem sikerült menteni a bérletet!");
throw new \Exception("Bérlet mentése nem sikerült");
}
\Yii::info("Bérlet elmentve: id=" . $this->ticket->id_ticket);
}
protected function mkTransfer( ) {
$this->transfer = new Transfer ();
$this->transfer->status = $this->transferStatus;
$this->transfer->type = Transfer::TYPE_TICKET;
$this->transfer->direction = Transfer::DIRECTION_IN;
$this->transfer->id_object = $this->ticket->id_ticket;
$this->transfer->item_price = $this->ticketType->price_brutto;
$this->transfer->money = $this->money;
$this->transfer->id_account = $this->account->id_account;
$this->transfer->count = 1;
if ($this->transferStatus == Transfer::STATUS_PAID) {
$this->transfer->paid_at = date ( 'Y-m-d H:i:s' );
$this->transfer->paid_by = \Yii::$app->user->id;
}
$this->transfer->payment_method = $this->paymentMethod;
$this->transfer->comment = "";
if ( isset($this->ticketInstallmentRequest)){
$this->transfer->comment = "Csoportos megbízással";
}
$this->transfer->id_user = \Yii::$app->user->id;
$this->transfer->id_customer = $this->customer->id_customer;
if ( !$this->transfer->save (false) ){
\Yii::error("Nem sikerült menteni a tranzakciót!");
throw new \Exception("Tranzakció mentése nem sikerült");
}
\Yii::info("tranzakció elmentve: id=" . $this->transfer->id_transfer);
}
protected function addToCustomerCart( ) {
}
protected function readMoney(){
if ( !isset($this->money)){
$this->money = $this->ticketType->price_brutto;
if (isset($this->discount)){
$this->money = Discount::applyDiscount($this->money, $this->discount);
}
if ( isset($this->ticketInstallmentRequest)){
$this->money = $this->ticketInstallmentRequest->money;
}
}
}
protected function readStartDate(){
if ( !isset($this->start)){
$this->start = Helper::getDateString();
if ( isset($this->ticketInstallmentRequest)){
$this->start = $this->ticketInstallmentRequest->request_target_time_at;
}
}
}
protected function readEndDate(){
if ( !isset($this->end)){
$unit = "month";
if ( $this->ticketType->time_unit_type == TicketType::TIME_UNIT_DAY ) {
$unit = "day";
}
$count = $this->ticketType->time_unit_count;
$this->end = date( 'Y-m-d', strtotime( $this->start . " +$count $unit -1 day"));
if ( isset($this->ticketInstallmentRequest)){
$this->end = date( 'Y-m-d', strtotime( $this->ticketInstallmentRequest->request_target_time_at . " +1 month -1 day"));
}
}
}
+class TicketSale extends Object{
/**
* A bérlet típusa. Kötelező
* */
public $ticketType;
/**
* A vendég . Kötelező
* */
public $customer;
/**
* A kassza. Kötelező
* */
public $account;
/**
* A bérletkártya. Kötelező
* */
public $card;
/**
* A kedvezmény. Opcionális
* */
public $discount;
/*
* Bérlet érvényesség első napja. Opcionális.
* Ha nincs megadva, a mai nap
* */
public $start;
/**
* A bérlet érvényességének utolsó napja. OPcionális.
* Ha nincs megadva a bérlet típusból számoljuk ki.
* Ha van megadva megbízás, akkor a megbízásból számoljuk ki
*
* */
public $end;
/**
* A szerződs. Opcionális
* */
public $contract;
/**
* Tranzakció állapota. Default: paid
* */
public $transferStatus = Transfer::STATUS_PAID;
/**
* A fizetési mód. Default : transfer
* */
public $paymentMethod = Transfer::PAYMENT_METHOD_TRANSFER;
/**
* if this is set, money and start date will be read from this object
* */
public $ticketInstallmentRequest;
/**
* A létrehozott bérlet
* */
public $ticket;
/**
* A létrehozott tranzakció
* */
public $transfer;
/**
* A bérlet ára. Opcionális
* Ha nincs megadva a bérlet típusból számoljuk ki
* Ha van megbízás, a megbízásból számoljuk ki
* */
public $money;
public function doSale(){
$this->readMoney();
$this->readStartDate();
$this->readEndDate();
$this->mkTicket();
$this->mkTransfer();
$this->addToCustomerCart();
}
protected function mkTicket( ) {
$this->ticket = new Ticket ();
$this->ticket->id_user = \Yii::$app->user->id;
$this->ticket->id_ticket_type = $this->ticketType->id_ticket_type; // save to contract
$this->ticket->id_account = $this->account->id_account;
$this->ticket->id_discount = isset($this->discount) ? $this->discount->id_discount : null; // contract.id_discount
$this->ticket->start = $this->start;
$this->ticket->end = $this->end;
$this->ticket->max_usage_count = $this->ticketType->max_usage_count;
$this->ticket->usage_count = 0;
$this->ticket->status = Ticket::STATUS_ACTIVE;
$this->ticket->price_brutto = $this->money;
$this->ticket->id_card = $this->card->id_card;
if ( isset( $this->ticketInstallmentRequest ) ){
$this->ticket->part = $this->ticketInstallmentRequest->priority;
}
if (isset($this->contract)){
$this->ticket->id_contract = $this->contract->id_contract;
}
if ( !$this->ticket->save ( false ) ){
\Yii::error("Nem sikerült menteni a bérletet!");
throw new \Exception("Bérlet mentése nem sikerült");
}
\Yii::info("Bérlet elmentve: id=" . $this->ticket->id_ticket);
}
protected function mkTransfer( ) {
$this->transfer = new Transfer ();
$this->transfer->status = $this->transferStatus;
$this->transfer->type = Transfer::TYPE_TICKET;
$this->transfer->direction = Transfer::DIRECTION_IN;
$this->transfer->id_object = $this->ticket->id_ticket;
$this->transfer->item_price = $this->ticketType->price_brutto;
$this->transfer->money = $this->money;
$this->transfer->id_account = $this->account->id_account;
$this->transfer->count = 1;
if ($this->transferStatus == Transfer::STATUS_PAID) {
$this->transfer->paid_at = date ( 'Y-m-d H:i:s' );
$this->transfer->paid_by = \Yii::$app->user->id;
}
$this->transfer->payment_method = $this->paymentMethod;
$this->transfer->comment = "";
if ( isset($this->ticketInstallmentRequest)){
$this->transfer->comment = "Csoportos megbízással";
}
$this->transfer->id_user = \Yii::$app->user->id;
$this->transfer->id_customer = $this->customer->id_customer;
if ( !$this->transfer->save (false) ){
\Yii::error("Nem sikerült menteni a tranzakciót!");
throw new \Exception("Tranzakció mentése nem sikerült");
}
\Yii::info("tranzakció elmentve: id=" . $this->transfer->id_transfer);
}
protected function addToCustomerCart( ) {
}
protected function readMoney(){
if ( !isset($this->money)){
$this->money = $this->ticketType->price_brutto;
if (isset($this->discount)){
$this->money = Discount::applyDiscount($this->money, $this->discount);
}
if ( isset($this->ticketInstallmentRequest)){
$this->money = $this->ticketInstallmentRequest->money;
}
}
}
protected function readStartDate(){
if ( !isset($this->start)){
$this->start = Helper::getDateString();
if ( isset($this->ticketInstallmentRequest)){
$this->start = $this->ticketInstallmentRequest->request_target_time_at;
}
}
}
protected function readEndDate(){
if ( !isset($this->end)){
$unit = "month";
if ( $this->ticketType->time_unit_type == TicketType::TIME_UNIT_DAY ) {
$unit = "day";
}
$count = $this->ticketType->time_unit_count;
$this->end = date( 'Y-m-d', strtotime( $this->start . " +$count $unit -1 day"));
if ( isset($this->ticketInstallmentRequest)){
$this->end = date( 'Y-m-d', strtotime( $this->ticketInstallmentRequest->request_target_time_at . " +1 month -1 day"));
}
}
}
}
\ No newline at end of file
diff --git a/common/components/TransferPayout.php b/common/components/TransferPayout.php
index 75dcfcc..5e78160 100644
--- a/common/components/TransferPayout.php
+++ b/common/components/TransferPayout.php
@@ -7,6 +7,7 @@ use common\models\Account;
use yii\base\Exception;
use common\models\ShoppingCart;
use common\models\UserSoldItem;
+use common\models\Ticket;
@@ -104,6 +105,16 @@ class TransferPayout extends \yii\base\Object{
throw new Exception("Tranzakció fizetése sikertelen volt!");
}
+ if ( $transfer->type == Transfer::TYPE_TICKET){
+ $ticket = $transfer->ticket;
+ $ticket->status = Ticket::STATUS_ACTIVE;
+
+ if ( $ticket->save(false) == false ){
+ \Yii::error("Tranzakció kifizetése sikertelen volt: ");
+ throw new Exception("Tranzakció fizetése sikertelen volt!");
+ }
+ }
+
try{
ShoppingCart::deleteAll( ['id_transfer' => $transfer->id_transfer] );
UserSoldItem::deleteAll( ['id_transfer' => $transfer->id_transfer] );
diff --git a/common/config/params.php b/common/config/params.php
index f88d61a..69d0961 100644
--- a/common/config/params.php
+++ b/common/config/params.php
@@ -4,7 +4,7 @@ return [
'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600,
- 'version' => 'v0.0.68',
+ 'version' => 'v0.0.70',
'company' => 'movar',//gyor
'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global
diff --git a/common/models/Log.php b/common/models/Log.php
index de4f143..b6a3e6b 100644
--- a/common/models/Log.php
+++ b/common/models/Log.php
@@ -41,6 +41,7 @@ class Log extends BaseFitnessActiveRecord
public static $TYPE_CREATE_CUSTOMER= 70;
public static $TYPE_PROCUREMENT_UPDATE = 80;
public static $TYPE_TICKET_COUNT_MOVE_OUT = 90;
+ public static $TYPE_WASTE = 100;
/**
* @inheritdoc
*/
diff --git a/common/models/TicketInstallmentRequest.php b/common/models/TicketInstallmentRequest.php
index 2b832de..7c67837 100644
--- a/common/models/TicketInstallmentRequest.php
+++ b/common/models/TicketInstallmentRequest.php
@@ -275,7 +275,6 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord
$request->priority = $index;
$date = \DateTime::createFromFormat("Y.m.d", $contract->started_at, new \DateTimeZone( 'UTC'));
$date->modify("+$index month");
-// $date->modify("-1 day");
$date->setTime(0, 0, 0);
$request->request_target_time_at = $date->format ( 'Y-m-d H:i:s' );
$request->request_processed_at = null;
@@ -295,7 +294,6 @@ class TicketInstallmentRequest extends \yii\db\ActiveRecord
TicketInstallmentRequest::$STATUS_REJECTED=> 'Visszautasítva',
TicketInstallmentRequest::$STATUS_ACCEPTED=> 'Sikeresen beszedés',
TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL=> 'Személyesen fizetve',
-
];
}
diff --git a/common/models/Transfer.php b/common/models/Transfer.php
index 3894daa..add47ae 100644
--- a/common/models/Transfer.php
+++ b/common/models/Transfer.php
@@ -52,7 +52,6 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
const PAYMENT_METHOD_TRANSFER = 30; // ÁTUTALÁS
const PAYMENT_METHOD_CAFETERY = 40; // SZÉCHENYI KÁRTYA
// const PAYMENT_METHOD_DEBIT_MANDATE = 50;//CSOPORTOS BESZEDÉSI MEGBÍZÁS
-
const PAYMENT_METHOD_TRANSFER_LATER = 50;
/**
* @inheritdoc
@@ -199,23 +198,20 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
"id_sale" => "id_object"
] );
}
-
public function getPaidByUser() {
- return $this->hasOne ( User::className (), [
- "id" => "paid_by"
+ return $this->hasOne ( User::className (), [
+ "id" => "paid_by"
] );
}
-
public function getPaidByName() {
$result = "";
$user = $this->paidByUser;
if (isset ( $this->paidByUser )) {
$result = $user->username;
}
-
+
return $result;
}
-
public function getObjectName() {
$result = "";
if ($this->type == Transfer::TYPE_TICKET) {
@@ -431,9 +427,6 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
return $transfer;
}
-
-
-
public static function modelsToArray($transfers, $default = []) {
if ($transfers == null) {
return $default;
@@ -489,10 +482,10 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$transfers = [ ];
$query = Transfer::find ();
- $query->innerJoin("user_sold_item","user_sold_item.id_transfer = transfer.id_transfer");
+ $query->innerJoin ( "user_sold_item", "user_sold_item.id_transfer = transfer.id_transfer" );
-// $query->innerJoinWith ( 'userSoldItem' );
- if ( Helper::isUserCartVisibilityUser()){
+ // $query->innerJoinWith ( 'userSoldItem' );
+ if (Helper::isUserCartVisibilityUser ()) {
$query->andWhere ( [
'user_sold_item.id_user' => $user->id
] );
@@ -527,24 +520,22 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
self::PAYMENT_METHOD_CASH => Yii::t ( 'common/transfer', 'Készpénz' ),
self::PAYMENT_METHOD_BANCCARD => Yii::t ( 'common/transfer', 'Bankkártyás fizetés' ),
self::PAYMENT_METHOD_TRANSFER => Yii::t ( 'common/transfer', 'Átutalás' ),
- self::PAYMENT_METHOD_CAFETERY => Yii::t ( 'common/transfer', 'Széchenyi kártya' ),
+ self::PAYMENT_METHOD_CAFETERY => Yii::t ( 'common/transfer', 'Széchenyi kártya' ),
self::PAYMENT_METHOD_TRANSFER_LATER => Yii::t ( 'common/transfer', 'Átutalás később' )
- ]
+ ];
// self::PAYMENT_METHOD_DEBIT_MANDATE => Yii::t('common/transfer','Csoportos beszedési megbízás'),
- ;
+
}
-
public static function paymentMethodsForProduct() {
return [
self::PAYMENT_METHOD_CASH => Yii::t ( 'common/transfer', 'Készpénz' ),
self::PAYMENT_METHOD_BANCCARD => Yii::t ( 'common/transfer', 'Bankkártyás fizetés' ),
self::PAYMENT_METHOD_TRANSFER => Yii::t ( 'common/transfer', 'Átutalás' ),
- self::PAYMENT_METHOD_CAFETERY => Yii::t ( 'common/transfer', 'Széchenyi kártya' ),
- ]
+ self::PAYMENT_METHOD_CAFETERY => Yii::t ( 'common/transfer', 'Széchenyi kártya' )
+ ];
// self::PAYMENT_METHOD_DEBIT_MANDATE => Yii::t('common/transfer','Csoportos beszedési megbízás'),
- ;
+
}
-
public static function statuses() {
return [
self::STATUS_NOT_PAID => Yii::t ( 'common/transfer', 'Nincs fizetve' ),
@@ -636,8 +627,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$query->addSelect ( [
new Expression ( 'transfer.id_account as account' ),
new Expression ( ' COALESCE(sum( ( case when direction = ' . Transfer::DIRECTION_OUT . ' then -1 else 1 end )* transfer.money ),0) as money /** --' . $mode . '*/' )
- ]
- );
+ ] );
$query->from ( 'transfer' );
if (! RoleDefinition::isAdmin ()) {
@@ -686,11 +676,11 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
self::notInInterval ( $query, 'transfer.created_at', $start, $end );
}
-// echo "start date is: ". $start;
-// echo "start date is: " . gettype( $start );
+ // echo "start date is: ". $start;
+ // echo "start date is: " . gettype( $start );
- if ( !RoleDefinition::isAdmin() ){
- Helper::restrictIfNotAdminTheStartDate($query, $start);
+ if (! RoleDefinition::isAdmin ()) {
+ Helper::restrictIfNotAdminTheStartDate ( $query, $start );
}
$query->groupBy ( 'transfer.id_account' );
@@ -864,11 +854,11 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
* Ezt a függvényt használjuk a zárások összegének kiszámolására!
* A számolás csak a következő feltételekkel bíró tranzakciókat
* tartalmazza:
- * - trazakció típus: common\models\Account::TYPE_ALL
- * - tranzakció fizetési módja: készpénz
- * - tranzakció státusza: fizetve
- * -
- * */
+ * - trazakció típus: common\models\Account::TYPE_ALL
+ * - tranzakció fizetési módja: készpénz
+ * - tranzakció státusza: fizetve
+ * -
+ */
public static function readPaid($start, $end, $idUser) {
$query = (new \yii\db\Query ());
$query->select ( [
@@ -933,7 +923,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$ticket->save ( false );
- if ( $ticket->part == 0 ){
+ if ($ticket->part == 0) {
TicketInstallmentRequest::updateAll ( [
'status' => TicketInstallmentRequest::$STATUS_CANCELED
], [
@@ -941,9 +931,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
] );
}
-
- // storno contract
-
+ // storno contract
} else if ($this->type == Transfer::TYPE_PRODUCT) {
$sale = $this->sale;
$product = $this->sale->product;
@@ -957,14 +945,16 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$mm->save ( false );
}
- ShoppingCart::deleteAll(['id_transfer' => $this->id_transfer]);
- UserSoldItem::deleteAll(['id_transfer' => $this->id_transfer]);
+ ShoppingCart::deleteAll ( [
+ 'id_transfer' => $this->id_transfer
+ ] );
+ UserSoldItem::deleteAll ( [
+ 'id_transfer' => $this->id_transfer
+ ] );
}
-
- public function unstorono(){
-
+ public function unstorono() {
if ($this->type != Transfer::TYPE_TICKET) {
- throw new NotAcceptableHttpException("Csak bérletet lehet visszaállítani");
+ throw new NotAcceptableHttpException ( "Csak bérletet lehet visszaállítani" );
}
$this->status = Transfer::STATUS_NOT_PAID;
@@ -973,25 +963,25 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$this->save ( false );
$ticket = $this->ticket;
- $ticket->status = Ticket::STATUS_ACTIVE;
+ $ticket->status = Ticket::STATUS_INACTIVE;
$ticket->save ( false );
- TicketInstallmentRequest::updateAll ( [
- 'status' => TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL
- ], [
- 'id_ticket' => $ticket->id_ticket
+ TicketInstallmentRequest::updateAll ( [
+ 'status' => TicketInstallmentRequest::$STATUS_ACCEPTED_MANUAL
+ ], [
+ 'id_ticket' => $ticket->id_ticket
] );
-
- $item = new ShoppingCart();
+ $item = new ShoppingCart ();
$item->id_customer = $this->id_customer;
$item->id_transfer = $this->id_transfer;
- $item->save(false);
+ $item->save ( false );
}
+
+
public function payout($id_account = null) {
-
if ($this->status != Transfer::STATUS_NOT_PAID) {
return false;
}
@@ -1000,21 +990,22 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$this->paid_at = Helper::getDateTimeString ();
$this->paid_by = \Yii::$app->user->id;
- if ( isset($id_account)){
+ if (isset ( $id_account )) {
$this->id_account = $id_account;
- }else{
- if( Helper::isUserCartVisibilityAll() ){
- $this->id_account = Account::readDefault();
+ } else {
+ if (Helper::isUserCartVisibilityAll ()) {
+ $this->id_account = Account::readDefault ();
}
}
- ShoppingCart::deleteAll ( [ 'id_transfer' => $this->id_transfer ] );
- UserSoldItem::deleteAll ( [ 'id_transfer' => $this->id_transfer
+ ShoppingCart::deleteAll ( [
+ 'id_transfer' => $this->id_transfer
] );
- return $this->save (false);
+ UserSoldItem::deleteAll ( [
+ 'id_transfer' => $this->id_transfer
+ ] );
+ return $this->save ( false );
}
-
-
public static function payoutAll($id_user, $id_array) {
ShoppingCart::deleteAll ( [
'in',
@@ -1028,27 +1019,37 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
] );
$updateConfig = null;
- if ( Helper::isUserCartVisibilityUser() ){
- $updateConfig = [
- 'status' => Transfer::STATUS_PAID,
- 'paid_at' => Helper::getDateTimeString (),
- 'paid_by' => $id_user
+ if (Helper::isUserCartVisibilityUser ()) {
+ $updateConfig = [
+ 'status' => Transfer::STATUS_PAID,
+ 'paid_at' => Helper::getDateTimeString (),
+ 'paid_by' => $id_user
];
- }else{
- $updateConfig = [
+ } else {
+ $updateConfig = [
'status' => Transfer::STATUS_PAID,
'paid_at' => Helper::getDateTimeString (),
'paid_by' => $id_user,
- 'id_account' => Account::readDefault(),
+ 'id_account' => Account::readDefault ()
];
}
$updateConditions = [
- [ 'in','id_transfer', $id_array ],
- [ 'in', 'status', [ Transfer::STATUS_NOT_PAID ] ]
+ [
+ 'in',
+ 'id_transfer',
+ $id_array
+ ],
+ [
+ 'in',
+ 'status',
+ [
+ Transfer::STATUS_NOT_PAID
+ ]
+ ]
];
- Transfer::updateAll ( $updateConfig , $updateConditions );
+ Transfer::updateAll ( $updateConfig, $updateConditions );
}
/**
@@ -1072,10 +1073,10 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$ticket->id_account = $account->id_account;
$ticket->id_discount = null; // contract.id_discount
$ticket->start = $request->request_target_time_at;
- $ticket->end = date( 'Y-m-d', strtotime( $request->request_target_time_at . " +1 month -1 day"));
+ $ticket->end = date ( 'Y-m-d', strtotime ( $request->request_target_time_at . " +1 month -1 day" ) );
$ticket->max_usage_count = $ticketType->max_usage_count;
$ticket->usage_count = 0;
- $ticket->status = Ticket::STATUS_ACTIVE;
+ $ticket->status = Ticket::STATUS_INACTIVE;
$ticket->price_brutto = $request->money;
$ticket->id_card = $card->id_card;
$ticket->part = $request->priority;
@@ -1103,31 +1104,30 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
$transfer->comment = "Szerződéses bérlet létrehozás";
$transfer->id_user = \Yii::$app->user->id;
$transfer->id_customer = $customer->id_customer;
- $transfer->save (false);
+ $transfer->save ( false );
-
- if ( $addToCustomerCart == true ){
- $cart = new ShoppingCart();
+ if ($addToCustomerCart == true) {
+ $cart = new ShoppingCart ();
$cart->id_customer = $customer->id_customer;
$cart->id_transfer = $transfer->id_transfer;
- $cart->save(false);
+ $cart->save ( false );
}
- return [$transfer,$ticket];
+ return [
+ $transfer,
+ $ticket
+ ];
}
-
public static function canBeAddedToCart($payment_method) {
- if ( $payment_method == Transfer::PAYMENT_METHOD_TRANSFER_LATER){
+ if ($payment_method == Transfer::PAYMENT_METHOD_TRANSFER_LATER) {
return false;
}
return true;
}
-
public static function canMarkPaidByReception($payment_method) {
- if ( $payment_method == Transfer::PAYMENT_METHOD_TRANSFER_LATER){
+ if ($payment_method == Transfer::PAYMENT_METHOD_TRANSFER_LATER) {
return false;
}
return true;
}
-
}
diff --git a/common/models/Waste.php b/common/models/Waste.php
new file mode 100644
index 0000000..d42f9a1
--- /dev/null
+++ b/common/models/Waste.php
@@ -0,0 +1,76 @@
+ TimestampBehavior::className(),
+ 'value' => function(){ return date('Y-m-d H:i:s' ); }
+ ],
+ ], parent::behaviors());
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function rules()
+ {
+ return [
+ [['count', 'id_product', ], 'integer'],
+ [['comment'], 'string', 'max' => 255],
+ [['productIdentifier'], 'string', 'max' => 128],
+ ];
+ }
+
+
+
+ /**
+ * @inheritdoc
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'id_waste' => Yii::t('common/waste', 'Id Waste'),
+ 'count' => Yii::t('common/waste', 'Mennyiség'),
+ 'id_product' => Yii::t('common/waste', 'Termék'),
+ 'stock_before' => Yii::t('common/waste', 'Mennyiség előtte'),
+ 'stock_after' => Yii::t('common/waste', 'Mennyiség utána'),
+ 'id_user' => Yii::t('common/waste', 'Felhasználó'),
+ 'comment' => Yii::t('common/waste', 'Megjegyzés'),
+ 'created_at' => Yii::t('common/waste', 'Létrehozva'),
+ 'updated_at' => Yii::t('common/waste', 'Updated At'),
+ ];
+ }
+}
diff --git a/console/controllers/DetstaConsoleController.php b/console/controllers/DetstaConsoleController.php
new file mode 100644
index 0000000..c458016
--- /dev/null
+++ b/console/controllers/DetstaConsoleController.php
@@ -0,0 +1,43 @@
+ 1,
+ 'idUser' => 1
+ ]
+ );
+
+ $customer = Customer::findOne(5559);
+ $contractForm->customer = $customer;
+ $contractForm->payment_method = Transfer::PAYMENT_METHOD_TRANSFER;
+
+
+ $contractForm->ticketType = TicketType::find()->andWhere(['status' => TicketType::STATUS_ACTIVE ,'installment_enabled' => '1'])->one();
+
+
+ $start = new \DateTime();
+ $startString = $start->format("'Y-m-d");
+
+
+ $contractForm->make();
+
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/console/migrations/m160502_055142_add_table_waste.php b/console/migrations/m160502_055142_add_table_waste.php
new file mode 100644
index 0000000..422ff28
--- /dev/null
+++ b/console/migrations/m160502_055142_add_table_waste.php
@@ -0,0 +1,48 @@
+db->driverName === 'mysql') {
+ // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
+ $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
+ }
+
+ $this->createTable('{{%waste}}', [
+ 'id_waste' => $this->primaryKey(),
+ 'count' => $this->integer(11),
+ 'id_product' => $this->integer(11),
+ 'stock_before' => $this->integer(11),
+ 'stock_after' => $this->integer(11),
+ 'id_user' => $this->integer(11),
+ 'comment' => $this->string(),
+ 'created_at' => $this->dateTime()->notNull(),
+ 'updated_at' => $this->dateTime()->notNull(),
+ ], $tableOptions);
+
+
+ }
+
+ public function down()
+ {
+ echo "m160502_055142_add_table_waste cannot be reverted.\n";
+
+ return false;
+ }
+
+ /*
+ // Use safeUp/safeDown to run migration code within a transaction
+ public function safeUp()
+ {
+ }
+
+ public function safeDown()
+ {
+ }
+ */
+}
diff --git a/frontend/controllers/ContractController.php b/frontend/controllers/ContractController.php
index 6dbec8d..e7d2940 100644
--- a/frontend/controllers/ContractController.php
+++ b/frontend/controllers/ContractController.php
@@ -293,7 +293,9 @@ class ContractController extends Controller {
$model = new ContractForm ( [
- 'customer' => $customer
+ 'customer' => $customer ,
+ 'idUser' => \Yii::$app->user->id,
+ 'idAccount' => Account::readDefault ()
] );
$model->started_at = date(date('Y.m.d'));
diff --git a/frontend/controllers/CustomerController.php b/frontend/controllers/CustomerController.php
index 0d327a0..5388d3b 100644
--- a/frontend/controllers/CustomerController.php
+++ b/frontend/controllers/CustomerController.php
@@ -9,12 +9,10 @@ use frontend\models\CustomerSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
-use yii\base\Object;
use common\models\Card;
use frontend\models\CustomerUpdate;
use frontend\models\CustomerCreate;
use common\models\Image;
-use frontend\models\ContractForm;
use yii\base\Exception;
use common\models\Log;
diff --git a/frontend/controllers/TicketController.php b/frontend/controllers/TicketController.php
index a0ebd98..00a7c3e 100644
--- a/frontend/controllers/TicketController.php
+++ b/frontend/controllers/TicketController.php
@@ -114,7 +114,8 @@ class TicketController extends FrontendController
$model->customer = $receptionForm->customer;
$model->id_user = \Yii::$app->user->id;
- $model->status = Ticket::STATUS_ACTIVE;
+
+
$model->usage_count = 0;
$model->id_card = $receptionForm->card->id_card;
$model->id_account = Account::readDefault();
diff --git a/frontend/models/ContractForm.php b/frontend/models/ContractForm.php
index 9280054..f42f33c 100644
--- a/frontend/models/ContractForm.php
+++ b/frontend/models/ContractForm.php
@@ -36,11 +36,13 @@ class ContractForm extends Model {
private $ticket;
private $transfer;
public $contract;
- private $ticketType;
+ public $ticketType;
private $money;
private $discount;
public $started_at;
public $timestampStart;
+ public $idUser;
+ public $idAccount;
/**
* @inheritdoc
*/
@@ -244,8 +246,9 @@ class ContractForm extends Model {
public function createTicket() {
$ticket = new Ticket ();
- $ticket->id_user = \Yii::$app->user->id;
- $ticket->id_account = Account::readDefault ();
+ $ticket->id_user = $this->getUserId();
+ $ticket->id_account = $this->getAccountId();
+
$ticket->id_discount = $this->id_discount;
$ticket->start = $this->started_at;
$date = new \DateTime ( $this->timestampStart);
@@ -278,9 +281,9 @@ class ContractForm extends Model {
$transfer->item_price = $this->money;
$transfer->count = 1;
$transfer->money = $this->money;
- $transfer->id_user = \Yii::$app->user->id;
+ $transfer->id_user = $this->getUserId();
$transfer->comment = "Szerződéses bérlet";
- $transfer->id_account = Account::readDefault ();
+ $transfer->id_account = $this->getAccountId();
$transfer->direction = Transfer::DIRECTION_IN;
$transfer->id_customer = $this->customer->id_customer;
$transfer->payment_method = $this->payment_method;
@@ -301,7 +304,7 @@ class ContractForm extends Model {
$contract = new Contract ();
$contract->id_customer = $this->customer->id_customer;
- $contract->id_user = \Yii::$app->user->id;
+ $contract->id_user = $this->getUserId();
$contract->status = Contract::$STATUS_PAID;
$contract->flag = Contract::$FLAG_ACTIVE;
$contract->part_count = $this->ticketType->installment_count;
@@ -342,4 +345,21 @@ class ContractForm extends Model {
}
}
+
+
+ protected function getUserId(){
+ if ( isset($this->idUser)){
+ return $this->idUser;
+ }
+ return \Yii::$app->user->id;
+ }
+
+
+ protected function getAccountId(){
+ if ( isset($this->idAccount)){
+ return $this->idAccount;
+ }
+ return Account::readDefault();
+ }
+
}
diff --git a/frontend/models/TicketCreate.php b/frontend/models/TicketCreate.php
index e59e98f..aa7f754 100644
--- a/frontend/models/TicketCreate.php
+++ b/frontend/models/TicketCreate.php
@@ -141,6 +141,13 @@ class TicketCreate extends Ticket{
$result = parent::beforeSave($insert);
if ( $result ){
if ($insert){
+
+ if ( $this->isAppendToCustomerCart() || $this->isAppendToUserCart()){
+ $this->status = Ticket::STATUS_INACTIVE;
+ }else{
+ $this->status = Ticket::STATUS_ACTIVE;
+ }
+
$ticketType = TicketType::findOne($this->id_ticket_type);
if ( isset($ticketType) && $ticketType->isInstallment() ){
$this->part = 0;