add reception global word listener,allow delete transactions, allow delete account_state

This commit is contained in:
Schneider Roland 2015-12-31 15:42:28 +01:00
parent f59eadd8cc
commit 0b58f628ed
13 changed files with 178 additions and 9 deletions

View File

@ -471,6 +471,32 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
return $status; return $status;
} }
public function beforeDelete(){
parent::beforeDelete();
if ( $this->type == Transfer::TYPE_TICKET){
$ticket = $this->ticket;
if ( $ticket != null ){
$ticket->delete();
}
}else if ($this->type == Transfer::TYPE_MONEY_MOVEMENT_OUT){
$mm = $this->moneyMovement;
$mm->delete();
}else if ($this->type == Transfer::TYPE_PRODUCT){
$sale = $this->sale;
$product = $this->product;
$product->stock = $product->stock + $this->count;
$product->save();
$sale->delete();
}
ShoppingCart::deleteAll(['id_transfer' =>$this->id_transfer]);
UserSoldItem::deleteAll(['id_transfer' =>$this->id_transfer]);
return true;
}
/** /**
* @param string $mode The mode to load * @param string $mode The mode to load
* Available modes * Available modes

View File

@ -21,7 +21,7 @@ class AppAsset extends AssetBundle
'css/site.css', 'css/site.css',
]; ];
public $js = [ public $js = [
'js/app.js',
]; ];
public $depends = [ public $depends = [
'yii\web\YiiAsset', 'yii\web\YiiAsset',

View File

@ -8,11 +8,13 @@ use yii\widgets\DetailView;
use yii\grid\GridView; use yii\grid\GridView;
use yii\base\Object; use yii\base\Object;
use yii\data\ArrayDataProvider; use yii\data\ArrayDataProvider;
use yii\helpers\Url;
class AccountStateBanknoteCountWidget extends Widget{ class AccountStateBanknoteCountWidget extends Widget{
public $model; public $model;
public $layout; public $layout;
public $index;
public function run(){ public function run(){
@ -77,6 +79,21 @@ class AccountStateBanknoteCountWidget extends Widget{
} }
$s .= $this->generateComment(); $s .= $this->generateComment();
$s .= Html::beginTag("div", ['class' => 'row', 'style' => 'margin-top: 6px;']);
$s .= Html::beginTag("div", ['class' => 'col-md-12 text-right']);
$s .= Html::a('<span class="glyphicon glyphicon-trash"></span>Törlés', Url::toRoute(['delete','id' =>$this->model->id_account_state]), [
'title' => \Yii::t('yii', 'Delete'),
'data-confirm' =>\Yii::t('yii', 'Are you sure to delete this item?'),
'data-method' => 'post',
'class' => 'btn btn-danger',
'style' =>'margin-bottom: 12px;'
]);
$s .= Html::endTag("div");//end col
$s .= Html::endTag("div");//end row
$s .= Html::endTag("div"); $s .= Html::endTag("div");
$s .= Html::endTag("div"); $s .= Html::endTag("div");

View File

@ -163,13 +163,13 @@ class AccountStateController extends Controller
* If deletion is successful, the browser will be redirected to the 'index' page. * If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id * @param integer $id
* @return mixed * @return mixed
*/
public function actionDelete($id) public function actionDelete($id)
{ {
$this->findModel($id)->delete(); $this->findModel($id)->delete();
\Yii::$app->session->setFlash( 'success','Kassza művelet törölve' );
return $this->redirect(['index']); return $this->redirect(Yii::$app->request->referrer);
} }
*/
/** /**
* Displays a single AccountState model. * Displays a single AccountState model.
* @param integer $id * @param integer $id

View File

@ -159,11 +159,26 @@ class TransferController extends Controller
* If deletion is successful, the browser will be redirected to the 'index' page. * If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id * @param integer $id
* @return mixed * @return mixed
*/
public function actionDelete($id) public function actionDelete($id)
{ {
$this->findModel($id)->delete(); $transfer = $this->findModel($id);
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
if ( $transfer->delete() ){
\Yii::$app->session->setFlash( 'success','Tranzakció törölve' );
$transaction->commit();
}else{
throw new \Exception("Failed to save");
}
} catch(Exception $e) {
$transaction->rollback();
\Yii::$app->session->setFlash( 'danger','Tranzakció törlése nem sikerült' );
}
return $this->redirect(['index']);
return $this->redirect(Yii::$app->request->referrer);
} }
*/
} }

View File

@ -42,7 +42,9 @@ class ReceptionForm extends Model
public function readCard(){ public function readCard(){
$this->card = Card::find()->andWhere(['or',[ 'in','number' , [$this->number]],['in','rfid_key' ,[ $this->number]]])->one(); $this->number = str_replace("ö", "0", $this->number);
$this->card = Card::find()->andWhere(['or',[ 'in','number' , [$this->number]], ['in','rfid_key' ,[ $this->number]]])->one();
if ( $this->card != null ){ if ( $this->card != null ){
$this->customer = $this->card->customer; $this->customer = $this->card->customer;
$this->readValidTickets(); $this->readValidTickets();

View File

@ -1,13 +1,29 @@
<?php <?php
use frontend\components\AccountStateBanknoteCountWidget; use frontend\components\AccountStateBanknoteCountWidget;
use yii\base\Widget; use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Url;
?> ?>
<?php <?php
echo AccountStateBanknoteCountWidget::widget([ echo AccountStateBanknoteCountWidget::widget([
'model' => $model, 'model' => $model,
'index' => $index
]); ]);
if ( $index == 0){
?>
<div class="row">
<div class="col-md-12 text-right">
<?php ?>
</div>
</div>
<?php
}
?> ?>

View File

@ -12,6 +12,7 @@ use common\widgets\Alert;
use common\components\FrotnendMenuStructure; use common\components\FrotnendMenuStructure;
use frontend\components\FrontendMenuStructure; use frontend\components\FrontendMenuStructure;
use kartik\widgets\AlertBlock; use kartik\widgets\AlertBlock;
use yii\helpers\Url;
AppAsset::register($this); AppAsset::register($this);
?> ?>
@ -23,6 +24,9 @@ AppAsset::register($this);
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?> <?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title> <title><?= Html::encode($this->title) ?></title>
<script>
var reception_card_url = '<?php echo Url::toRoute('customer/reception');?>';
</script>
<?php $this->head() ?> <?php $this->head() ?>
</head> </head>
<body> <body>

View File

@ -37,4 +37,7 @@ use yii\bootstrap\Html;
<div class='col-md-3 '> <div class='col-md-3 '>
<?php echo Html::a(Yii::t('frontend/product', "Paid"),null,[ 'id' => 'btn_pay_customer_cart', 'class' => 'btn btn-primary btn-block' , 'name' => 'payout_customer_cart']) ?> <?php echo Html::a(Yii::t('frontend/product', "Paid"),null,[ 'id' => 'btn_pay_customer_cart', 'class' => 'btn btn-primary btn-block' , 'name' => 'payout_customer_cart']) ?>
</div> </div>
<div class='col-md-3 '>
<?php echo Html::a(Yii::t('frontend/product', "Frissít"),null,[ 'class' => 'btn btn-primary btn-block' , 'onclick' => 'location.reload();']) ?>
</div>
</div> </div>

View File

@ -40,4 +40,7 @@ use kartik\widgets\ActiveForm;
<?php echo Html::submitButton( Yii::t('frontend/product', "Paid"), [ 'id' => 'btn_pay_user_cart', 'class' => 'btn btn-primary btn-block' , 'name' => 'payout_user_cart']) ?> <?php echo Html::submitButton( Yii::t('frontend/product', "Paid"), [ 'id' => 'btn_pay_user_cart', 'class' => 'btn btn-primary btn-block' , 'name' => 'payout_user_cart']) ?>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>
</div> </div>
<div class='col-md-3 '>
<?php echo Html::a(Yii::t('frontend/product', "Frissít"),null,[ 'class' => 'btn btn-primary btn-block' , 'onclick' => 'location.reload();']) ?>
</div>
</div> </div>

View File

@ -2,6 +2,7 @@
use yii\helpers\Html; use yii\helpers\Html;
use common\models\Transfer; use common\models\Transfer;
use yii\helpers\Url;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
@ -63,6 +64,17 @@ $formatter = Yii::$app->formatter;
</dl> </dl>
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-11 text-right">
<?php echo Html::a('<span class="glyphicon glyphicon-trash"></span>Törlés', Url::toRoute(['delete','id' =>$model->id_transfer]), [
'title' => Yii::t('yii', 'Delete'),
'data-confirm' => Yii::t('yii', 'Are you sure to delete this item?'),
'data-method' => 'post',
'class' => 'btn btn-danger',
// 'style' =>'margin-right: 12px;'
]);?>
</div>
</div>
</div> </div>
</div> </div>

71
frontend/web/js/app.js Normal file
View File

@ -0,0 +1,71 @@
var enterPressed;
var keyDate;
var seq = '';
$(document).ready(
function(){
$("input[name='number']").on('focus', function (e) {
$(this)
.one('mouseup', function () {
$(this).select();
return false;
})
.select();
});
addDocumentKeypressedListener();
}
);
function addDocumentKeypressedListener(){
$( document ).keypress(function( event ) {
var tag = event.target.tagName.toLowerCase();
if ( tag != 'input' && tag != 'textarea' && tag != 'select') {
resetSequenceIfToMuchTimePassedOrEnterWasPressed(event);
if ( event.which == 13 ) {
enterPressed = 1;
if ( seq ){
$( document ).trigger( "wordtyped", [ { originalEvent: event, 'word': seq } ] );
}
}else {
appendCharToSeq(event);
}
}
});
$( document ).on( "wordtyped", function( event, data ) {
var word;
word = data.word;
if ( word && word.length > 0){
location.href= reception_card_url +'&number=' + word;
}
});
function resetSequenceIfToMuchTimePassedOrEnterWasPressed(){
var prevDate, timePassed;
prevDate= keyDate;
keyDate = new Date().getTime();
timePassed = keyDate - prevDate;
if ( enterPressed > 0 || timePassed > 2000 ){
seq = '';
enterPressed = 0;
}
}
function appendCharToSeq(event){
var code,s;
code = event.which;
if ( code ){
s = String.fromCharCode(code);
if ( s )
seq += s;
}
}
}

View File

@ -52,7 +52,7 @@ function ProductSell(o){
addPayoutButtons(); addPayoutButtons();
productChanged(); productChanged();
addDocumentKeypressedListener(); // addDocumentKeypressedListener();
initAutocomplete(); initAutocomplete();
} }