change cart to plain post from ajax

This commit is contained in:
Roland Schneider 2016-01-04 22:02:59 +01:00
parent 2d9b527909
commit 1e206011d0
27 changed files with 622 additions and 349 deletions

View File

@ -60,16 +60,24 @@ class ProductSearch extends Product
// $query->where('0=1');
return $dataProvider;
}
if ( !empty($this->barcode)){
$this->barcode = strtolower($this->barcode);
}
if ( !empty($this->product_number)){
$this->product_number = strtolower($this->product_number);
}
$query->andFilterWhere([
'product.id_product_category' => $this->id_product_category,
'product.id_account' => $this->id_account,
'product.status' => $this->status,
'lower(product.product_number)' => $this->product_number,
'lower(product.barcode)' => $this->barcode,
]);
$query->andFilterWhere(['like', 'product_number', $this->product_number])
->andFilterWhere(['like', 'barcode', $this->barcode])
->andFilterWhere(['like', 'name', $this->name]);
$query->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}

View File

@ -85,5 +85,11 @@ class Helper
}
public static function fixAsciiChars($in){
$out = str_replace("ö", "0", $in);
$out = str_replace("Ö", "0", $in);
return $out;
}
}

View File

@ -3,6 +3,7 @@
namespace common\models;
use Yii;
use common\components\Helper;
/**
* This is the model class for table "card".
@ -67,7 +68,7 @@ class Card extends \common\models\BaseFitnessActiveRecord
public function validateAscii($attribute,$params){
if ( !$this->hasErrors($this->$attribute)){
$this->$attribute = str_replace("ö", "0", $this->$attribute);
$this->attribute = Helper::fixAsciiChars($this->attributes);
}
}

View File

@ -4,6 +4,7 @@ namespace common\models;
use Yii;
use yii\helpers\ArrayHelper;
use common\components\Helper;
/**
* This is the model class for table "product".
@ -51,6 +52,12 @@ class Product extends \common\models\BaseFitnessActiveRecord {
[['barcode'], 'unique' ],
];
}
public function validateAscii($attribute,$params){
if ( !$this->hasErrors($this->$attribute)){
$this->attribute = Helper::fixAsciiChars($this->attributes);
}
}
/**
* @inheritdoc

View File

@ -63,19 +63,26 @@ class ShoppingCart extends \yii\db\ActiveRecord
return $transfers;
}
public static function payout( $customer) {
public static function payout( $customer, $idTransfers) {
//apply transfer object
//delete cart
$sql = "UPDATE transfer AS t
INNER JOIN shopping_cart AS s ON t.id_transfer = s.id_transfer
SET t.status = " . Transfer::STATUS_PAID . ", t.paid_at = '" . date('Y-m-d H:i:s' ) ."'"
SET t.paid_by = ".\Yii::$app->user->id.", t.status = " . Transfer::STATUS_PAID . ", t.paid_at = '" . date('Y-m-d H:i:s' ) ."'"
. " WHERE t.status = " . Transfer::STATUS_NOT_PAID
. " and s.id_customer = " . $customer->id_customer ;
. " and s.id_customer = " . $customer->id_customer
. " and t.id_transfer in ( '" . implode("','", $idTransfers )."' )";
$q1 = Yii::$app->db->createCommand($sql);
$q1->execute();
ShoppingCart::deleteAll(['id_customer' => $customer->id_customer]);
// ShoppingCart::deleteAll(['id_customer' => $customer->id_customer]);
if ( isset($idTransfers) ){
ShoppingCart::deleteAll(['and' ,['id_customer' => $customer->id_customer] ,['in','id_transfer',$idTransfers] ]);
}else{
ShoppingCart::deleteAll(['id_customer' => $customer->id_customer]);
}
}

View File

@ -541,7 +541,10 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
if ( !RoleDefinition::isAdmin() ){
$query->innerJoin("user_account_assignment", 'transfer.id_account = user_account_assignment.id_account' );
$query->andWhere(['user_account_assignment.id_user' => Yii::$app->user->id ]);
}
$query->innerJoin("account", 'transfer.id_account = account.id_account' );
$query->andWhere(['account.type' => Account::TYPE_ALL]);
$query->andFilterWhere([
'transfer.id_account' => $idAccount,

View File

@ -89,19 +89,27 @@ class UserSoldItem extends \yii\db\ActiveRecord
/**
* @param common\models\User $user
* */
public static function payout( $user ) {
public static function payout( $user, $idTransfers = null ) {
//apply transfer object
//delete cart
$sql = "UPDATE transfer AS t
INNER JOIN user_sold_item AS s ON t.id_transfer = s.id_transfer
SET t.status = " . Transfer::STATUS_PAID . ", t.paid_at = '" . date('Y-m-d H:i:s' ) ."'"
SET t.paid_by = ".$user->id.", t.status = " . Transfer::STATUS_PAID . ", t.paid_at = '" . date('Y-m-d H:i:s' ) ."'"
. " WHERE t.status = " . Transfer::STATUS_NOT_PAID
. " and s.id_user =" . $user->id ;
if ( isset($idTransfers)){
$sql .= " and t.id_transfer in ( '" . implode("','", $idTransfers )."' )";
}
$q1 = Yii::$app->db->createCommand($sql);
$q1->execute();
UserSoldItem::deleteAll(['id_user' => Yii::$app->user->id]);
if ( isset($idTransfers) ){
UserSoldItem::deleteAll(['and' ,['id_user' => Yii::$app->user->id] ,['in','id_transfer',$idTransfers] ]);
}else{
UserSoldItem::deleteAll(['id_user' => Yii::$app->user->id]);
}
}

View File

@ -0,0 +1,31 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m160104_155510_alter__table__transaction__add__column__paid_by extends Migration
{
public function up()
{
$this->addColumn("transfer", "paid_by", "int");
$this->execute("update transfer set paid_by = id_user where paid_at is not null");
}
public function down()
{
echo "m160104_155510_alter__table__transaction__add__column__paid_by cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -8,6 +8,7 @@ use common\models\MoneyMovement;
use yii\db\Query;
use common\models\AccountState;
use backend\models\AccountSearch;
use common\models\Account;
class FrontendMenuStructure{
@ -68,13 +69,13 @@ class FrontendMenuStructure{
['label' => Yii::t('frontend/account-state','Open account state'), 'url' => ['/account-state/open'] ],
['label' => Yii::t('frontend/account-state','Close account state'), 'url' => ['/account-state/close'] ],
['label' => Yii::t('frontend/money-movement','Money movements'), 'url' => [ '/money-movement/index', 'MoneyMovementSearch[start]' => $this->start, 'MoneyMovementSearch[end]' => $this->tomorrow ] ],
['label' => Yii::t('frontend/transfer','Daily transfers'), 'url' => [ '/transfer/list', 'TransferListSearch[start]' => $this->start, 'TransferListSearch[end]' => $this->tomorrow ] ],
['label' => Yii::t('frontend/transfer','Sales detailed'), 'url' => [ '/transfer/sale', 'TransferSaleSearch[start]' => $this->start, 'TransferSaleSearch[end]' => $this->tomorrow ] ],
['label' => Yii::t('frontend/transfer','Ticket sale detailed'), 'url' => [ '/transfer/tickets', 'TransferTicketSearch[start]' => $this->start, 'TransferTicketSearch[end]' => $this->tomorrow ] ],
['label' => Yii::t('frontend/transfer','Daily transfers'), 'url' => [ '/transfer/list', 'TransferListSearch[id_account]' => Account::readDefault(), 'TransferListSearch[start]' => $this->start, 'TransferListSearch[end]' => $this->tomorrow ] ],
['label' => Yii::t('frontend/transfer','Sales detailed'), 'url' => [ '/transfer/sale', 'TransferSaleSearch[id_user]' =>\Yii::$app->user->id, 'TransferSaleSearch[id_account]' => Account::readDefault(), 'TransferSaleSearch[start]' => $this->start, 'TransferSaleSearch[end]' => $this->tomorrow ] ],
['label' => Yii::t('frontend/transfer','Ticket sale detailed'), 'url' => [ '/transfer/tickets','TransferTicketSearch[id_user]' =>\Yii::$app->user->id, 'TransferTicketSearch[id_account]' => Account::readDefault(), 'TransferTicketSearch[start]' => $this->start, 'TransferTicketSearch[end]' => $this->tomorrow ] ],
];
if ( $isadmin || Yii::$app->user->can('reception.transfers') ){
$items[] = ['label' => Yii::t('frontend/transfer','Transfers'), 'url' => ['/transfer/index', 'TransferSearch[start]' => $this->start, 'TransferSearch[end]' => $this->tomorrow ] ];
$items[] = ['label' => Yii::t('frontend/transfer','Transfers'), 'url' => ['/transfer/index', 'TransferSearch[id_user]' =>\Yii::$app->user->id, 'TransferSearch[id_account]' => Account::readDefault(), 'TransferSearch[start]' => $this->start, 'TransferSearch[end]' => $this->tomorrow ] ];
}
$items[] = ['label' => Yii::t('frontend/collection','Collections'), 'url' => ['/collection/index' , 'CollectionSearch[start]' =>$this->start,'CollectionSearch[end]' => $this->tomorrow ] ];

View File

@ -63,6 +63,7 @@ class AccountStateController extends Controller
$model = new AccountState();
$model->type = AccountState::TYPE_OPEN;
$model->id_user = Yii::$app->user->id;
$model->id_account = Account::readDefault();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
// return $this->redirect(['view', 'id' => $model->id_account_state]);
return $this->redirect(['index' ]);
@ -89,6 +90,7 @@ class AccountStateController extends Controller
$model = new AccountState();
$model->type = AccountState::TYPE_CLOSE;
$model->id_user = Yii::$app->user->id;
$model->id_account = Account::readDefault();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['index' ]);
// return $this->redirect(['view', 'id' => $model->id_account_state]);

View File

@ -22,321 +22,366 @@ use common\models\User;
use common\models\UserSoldItem;
use common\models\ShoppingCart;
use frontend\models\ReceptionForm;
use frontend\models\CustomerCartPayoutForm;
use frontend\models\UserCartPayoutForm;
/**
* ProductController implements the CRUD actions for Product model.
*/
class ProductController extends Controller
{
class ProductController extends Controller {
protected $card;
protected $customer;
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className (),
'actions' => [
'delete' => [
'post'
]
]
],
'access' => [
'class' => \yii\filters\AccessControl::className (),
'only' => [
'sale',
'payout-customer-cart',
'payout-user-cart',
'lookup',
'find'
],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => [
'@'
]
]
]
// everything else is denied
]
];
}
public function actionSale($number = null) {
// $this->findByNumber($number);
$receptionForm = new ReceptionForm ();
$receptionForm->number = $number;
$receptionForm->readCard ();
$this->card = $receptionForm->card;
$this->customer = $receptionForm->customer;
$model = new ProductSaleForm ();
$lookupModel = new ProductLookupForm ();
$currencies = Currency::find ()->all ();
$accounts = Account::read ();
$discounts = Discount::read ();
$user = User::findOne ( Yii::$app->user->id );
$model->customer = $this->customer;
$model->card = $this->card;
$products = Product::readForDefaultAccount ();
$products = Product::modelToMapIdName ( $products );
$model->products = $products;
if (Yii::$app->request->isAjax) {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$model->currencies = $currencies;
$model->accounts = $accounts;
$model->discounts = $discounts;
$model->id_account = Account::readDefault ();
$result = [ ];
$result ['code'] = 'unknown';
if ($model->load ( Yii::$app->request->post () )) {
if ($model->save ()) {
$result ['code'] = 'success';
$result ['message'] = Yii::t ( 'common/product', "Sold: {product}", [
'product' => $model->transfer->toProductSoldString ()
] );
} else {
$result ['code'] = 'invalid';
$result ['errors'] = $model->getErrors ();
}
}
$userTransfers = Transfer::modelsToArray ( Transfer::readUserSoldTransfers ( $user ) );
$customerCart = Transfer::modelsToArray ( Transfer::readCustomerCart ( $this->customer ) );
$result ['transfers'] = $userTransfers;
$result ['customer_cart'] = $customerCart;
return $result;
} else {
// $userTransfers = Transfer::readUserSoldTransfers( $user );
$model->customerCart = Transfer::modelsToArray ( Transfer::readCustomerCart ( $this->customer ) );
$userTransfers = Transfer::modelsToArray ( Transfer::readUserSoldTransfers ( $user ) );
return $this->render ( "sale", [
'customer' => $this->customer,
'card' => $this->card,
'model' => $model,
'lookupModel' => $lookupModel,
'currencies' => $currencies,
'accounts' => $accounts,
'discounts' => $discounts,
'userTransfers' => $userTransfers,
'receptionForm' => $receptionForm
] );
}
}
public function actionPayoutUserCart() {
if (Yii::$app->request->isAjax) {
$result = [ ];
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$user = User::findOne ( Yii::$app->user->id );
UserSoldItem::payout ( $user );
$userTransfers = Transfer::modelsToArray ( Transfer::readUserSoldTransfers ( $user ) );
$result ['transfers'] = $userTransfers;
$result ['code'] = 'success';
return $result;
} else {
$model = new UserCartPayoutForm ();
$user = User::findOne ( Yii::$app->user->id );
if ( $model->load ( Yii::$app->request->post () ) && $model->validate () &&isset ( $user ) && count ( $model->transfers ) > 0) {
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction ();
try {
UserSoldItem::payout ( $user, $model->transfers );
$transaction->commit ();
\Yii::$app->session->setFlash ( 'success', 'Recepicó kosár fizetve' );
} catch ( Exception $e ) {
$transaction->rollback ();
Yii::error ( "faled to save :" . $e->getMessage () );
}
} else {
Yii::error ( "faled to save : transfer" );
\Yii::$app->session->setFlash ( 'warning', 'Nem történt változás' );
}
}
return $this->redirect ( Yii::$app->request->referrer );
}
public function actionPayoutCustomerCart($number) {
$cart = [ ];
$code = 'error';
$message = 'Hiba történt';
if (Yii::$app->request->isAjax) {
$result = [ ];
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$this->findByNumber ( $number );
if (isset ( $this->customer )) {
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction ();
try {
ShoppingCart::payout ( $this->customer );
$transaction->commit ();
$cart = Transfer::modelsToArray ( Transfer::readCustomerCart ( $this->customer ) );
$code = 'success';
$message = 'Bevásárlókosár fizetve: ' . $this->card->number;
} catch ( Exception $e ) {
$transaction->rollback ();
}
}
$result ['customer_cart'] = $cart;
$result ['code'] = $code;
$result ['message'] = $message;
return $result;
} else {
// post
$model = new CustomerCartPayoutForm ();
if ($model->load ( Yii::$app->request->post () ) && $model->validate ()) {
$this->findByNumber ( $number );
if (isset ( $this->customer ) && count ( $model->transfers ) > 0) {
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction ();
try {
ShoppingCart::payout ( $this->customer, $model->transfers );
$transaction->commit ();
\Yii::$app->session->setFlash ( 'success', 'Vendég kosár kifizetve' );
} catch ( Exception $e ) {
$transaction->rollback ();
Yii::error ( "faled to save :" . $e->getMessage () );
\Yii::$app->session->setFlash ( 'danger', 'Hiba történt a mentés során' );
}
} else {
Yii::error ( "faled to save : no customer or transfer" );
\Yii::$app->session->setFlash ( 'warning', 'Nem történt változás' );
}
}else{
\Yii::$app->session->setFlash ( 'warning', 'Nem történt változás' );
}
return $this->redirect ( Yii::$app->request->referrer );
}
}
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => \yii\filters\AccessControl::className(),
'only' => [ 'sale','payout-customer-cart','payout-user-cart', 'lookup','find'],
'rules' => [
// allow authenticated users
[
'allow' => true,
'roles' => ['@'],
],
// everything else is denied
],
],
];
}
/**
*/
public function actionLookup($query = null) {
$result = [ ];
$product = Product::findProduct ( $query, Account::readDefault () );
$product = Product::modelToArray ( $product );
$result ['product'] = $product;
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return $result;
}
/**
*/
public function actionFind($id = null) {
$result = [ ];
$product = Product::findOne ( $id );
$product = Product::modelToArray ( $product );
$result ['product'] = $product;
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return $result;
}
/**
* Finds the Product model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id
* @return Product the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id) {
if (($model = Product::findOne ( $id )) !== null) {
return $model;
} else {
throw new NotFoundHttpException ( 'The requested page does not exist.' );
}
}
protected function findByNumber($number) {
$this->card = null;
$this->customer = null;
if ($number != null) {
$this->card = Card::readCard ( $number );
if ($this->card != null) {
$this->customer = Customer::find ()->innerJoin ( Card::tableName (), "customer.id_customer_card = card.id_card" )->andWhere ( [
'customer.id_customer_card' => $this->card->id_card
] )->one ();
}
}
}
public function actionSale( $number = null){
// $this->findByNumber($number);
$receptionForm = new ReceptionForm() ;
$receptionForm->number = $number;
$receptionForm->readCard();
$this->card = $receptionForm->card;
$this->customer = $receptionForm->customer;
$model = new ProductSaleForm();
$lookupModel = new ProductLookupForm();
$currencies = Currency::find()->all();
$accounts = Account::read();
$discounts = Discount::read();
$user = User::findOne(Yii::$app->user->id );
$model->customer = $this->customer;
$model->card = $this->card;
$products = Product::readForDefaultAccount();
$products = Product::modelToMapIdName($products);
$model->products = $products;
if (Yii::$app->request->isAjax) {
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$model->currencies = $currencies;
$model->accounts = $accounts;
$model->discounts = $discounts;
$model->id_account = Account::readDefault();
$result = [];
$result['code'] = 'unknown';
if ($model->load(Yii::$app->request->post()) ) {
if ( $model->save()){
$result['code'] = 'success';
$result['message'] = Yii::t('common/product',"Sold: {product}" ,[ 'product' => $model->transfer->toProductSoldString() ]);
}else{
$result['code'] = 'invalid';
$result['errors'] = $model->getErrors();
}
}
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers( $user ) );
$customerCart = Transfer::modelsToArray( Transfer::readCustomerCart( $this->customer ) );
$result['transfers'] = $userTransfers;
$result['customer_cart'] = $customerCart;
return $result;
}else{
// $userTransfers = Transfer::readUserSoldTransfers( $user );
$model->customerCart = Transfer::modelsToArray( Transfer::readCustomerCart($this->customer) );
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
return $this->render("sale",[
'customer' => $this->customer,
'card' => $this->card,
'model' => $model,
'lookupModel' =>$lookupModel,
'currencies' => $currencies,
'accounts' => $accounts,
'discounts' => $discounts,
'userTransfers' => $userTransfers,
'receptionForm' => $receptionForm,
]);
}
}
public function actionPayoutUserCart(){
if (Yii::$app->request->isAjax) {
$result = [];
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$user = User::findOne(Yii::$app->user->id );
UserSoldItem::payout($user);
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
$result['transfers'] = $userTransfers;
$result['code'] = 'success';
return $result;
}
}
public function actionPayoutCustomerCart($number){
$cart = [];
$code = 'error';
$message = 'Hiba történt';
if (Yii::$app->request->isAjax) {
$result = [];
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$this->findByNumber($number);
if ( isset($this->customer)){
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
ShoppingCart::payout($this->customer);
$transaction->commit();
$cart = Transfer::modelsToArray( Transfer::readCustomerCart($this->customer) );
$code = 'success';
$message = 'Bevásárlókoosár fizetve: ' .$this->card->number;
} catch(Exception $e) {
$transaction->rollback();
}
}
$result['customer_cart'] = $cart;
$result['code'] = $code;
$result['message'] = $message;
return $result;
}
}
/**
*/
public function actionLookup($query = null)
{
$result = [];
$product = Product::findProduct($query, Account::readDefault());
$product = Product::modelToArray($product);
$result['product'] = $product;
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return $result;
}
/**
*/
public function actionFind($id=null)
{
$result = [];
$product = Product::findOne($id);
$product = Product::modelToArray($product);
$result['product'] = $product;
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return $result;
}
/**
* Finds the Product model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Product the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Product::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
protected function findByNumber($number){
$this->card = null;
$this->customer = null;
if ( $number != null ){
$this->card = Card::readCard($number);
if ( $this->card != null ){
$this->customer = Customer::find()->innerJoin(Card::tableName(), "customer.id_customer_card = card.id_card")->andWhere( [ 'customer.id_customer_card' => $this->card->id_card ])->one();
}
}
}
/**
* Lists all Product models.
* @return mixed
*/
/*
public function actionIndex()
{
$searchModel = new ProductSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
*/
/**
* Displays a single Product model.
* @param integer $id
* @return mixed
*/
/*
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
*/
/**
* Updates an existing Product 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_product]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
*/
/**
* Deletes an existing Product 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']);
}
*/
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
/*
public function actionCreate()
{
$model = new Product();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_product]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
*/
/**
* Lists all Product models.
*
* @return mixed
*/
/*
* public function actionIndex()
* {
* $searchModel = new ProductSearch();
* $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
*
* return $this->render('index', [
* 'searchModel' => $searchModel,
* 'dataProvider' => $dataProvider,
* ]);
* }
*/
/**
* Displays a single Product model.
*
* @param integer $id
* @return mixed
*/
/*
* public function actionView($id)
* {
* return $this->render('view', [
* 'model' => $this->findModel($id),
* ]);
* }
*/
/**
* Updates an existing Product 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_product]);
* } else {
* return $this->render('update', [
* 'model' => $model,
* ]);
* }
* }
*/
/**
* Deletes an existing Product 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']);
* }
*/
/**
* Creates a new Product model.
* If creation is successful, the browser will be redirected to the 'view' page.
*
* @return mixed
*/
/*
* public function actionCreate()
* {
* $model = new Product();
*
* if ($model->load(Yii::$app->request->post()) && $model->save()) {
* return $this->redirect(['view', 'id' => $model->id_product]);
* } else {
* return $this->render('create', [
* 'model' => $model,
* ]);
* }
* }
*/
}

View File

@ -189,6 +189,7 @@ class TransferController extends Controller
try {
$transfer->status = Transfer::STATUS_PAID;
$transfer->paid_at = date('Y-m-d H:i:s' ) ;
$transfer->paid_by = \Yii::$app->user->id;
ShoppingCart::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
UserSoldItem::deleteAll([ 'id_transfer' => $transfer->id_transfer]);
if ( $transfer->save() ){

View File

@ -0,0 +1,42 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\Card;
use common\models\Customer;
use common\models\Ticket;
use common\models\Account;
/**
* ContactForm is the model behind the contact form.
*/
class CustomerCartPayoutForm extends Model
{
public $transfers;
/**
* @inheritdoc
*/
public function rules()
{
return [
['transfers', 'each', 'rule' => ['integer']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
];
}
}

View File

@ -209,6 +209,12 @@ class ProductSaleForm extends Model
$this->transfer->id_user = Yii::$app->user->id;
if ( $status == Transfer::STATUS_PAID){
$this->transfer->paid_by = Yii::$app->user->id;
}
$this->transfer->save();
}

View File

@ -7,6 +7,7 @@ use yii\base\Model;
use common\models\Card;
use common\models\Customer;
use common\models\Ticket;
use common\models\Account;
/**
* ContactForm is the model behind the contact form.
@ -17,7 +18,7 @@ class ReceptionForm extends Model
public $card;
public $customer;
public $tickets;
public $defaultAccount;
/**
* @inheritdoc
@ -44,11 +45,25 @@ class ReceptionForm extends Model
$this->number = str_replace("ö", "0", $this->number);
$this->card = Card::find()->andWhere(['or', [ 'in','number' , [$this->number]], ['and', ['in','rfid_key' ,[ $this->number] ],"trim(coalesce(rfid_key, '')) <>'' "]])->one();
$this->card = Card::find()->andWhere(['or', ['and',[ 'in','number' , [$this->number]],"trim(coalesce(number, '')) <>'' " ], ['and', ['in','rfid_key' ,[ $this->number] ],"trim(coalesce(rfid_key, '')) <>'' "]])->one();
if ( $this->card != null ){
$this->customer = $this->card->customer;
$this->readValidTickets();
}
$defaultAccount = Account::readDefault();
if ( isset($defaultAccount)){
$this->defaultAccount = Account::findOne($defaultAccount);
}
}
public function getDefaultAccountName(){
$result = "";
if ( $this->defaultAccount ){
$result = $this->defaultAccount->name;
}
return $result;
}
public function readValidTickets(){

View File

@ -120,6 +120,7 @@ class TicketCreate extends Ticket{
}else {
$status = Transfer::STATUS_PAID;
$transfer->paid_at = date('Y-m-d H:i:s' ) ;
$transfer->paid_by = \Yii::$app->user->id;
}
$transfer->status = $status;

View File

@ -0,0 +1,42 @@
<?php
namespace frontend\models;
use Yii;
use yii\base\Model;
use common\models\Card;
use common\models\Customer;
use common\models\Ticket;
use common\models\Account;
/**
* ContactForm is the model behind the contact form.
*/
class UserCartPayoutForm extends Model
{
public $transfers;
/**
* @inheritdoc
*/
public function rules()
{
return [
['transfers', 'each', 'rule' => ['integer']],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
];
}
}

View File

@ -7,6 +7,13 @@ use yii\base\Widget;
use frontend\components\ReceptionTicketWidget;
use frontend\components\ReceptionCustomerWidget;
?>
<div class='row'>
<div class='col-md-4'>
<div class="alert alert-info">
Aktuális kassza: <?php echo $model->getDefaultAccountName();?>
</div>
</div>
</div>
<div class='row'>
<div class='col-md-3'>
<?php echo ReceptionMenuWidget::widget( [ 'model' => $model ] ) ?>
@ -20,4 +27,4 @@ use frontend\components\ReceptionCustomerWidget;
<div class='col-md-3'>
<?php echo ReceptionTicketWidget::widget([ 'model' => $model ] ) ?>
</div>
</div>
</div>

View File

@ -1,5 +1,6 @@
<?php
use yii\bootstrap\Html;
use yii\widgets\ActiveForm;
?>
@ -35,9 +36,9 @@ use yii\bootstrap\Html;
</div>
<div class="row">
<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"),"javascript: $('#frm_customer_cart').submit()",[ 'id' => 'btn_pay_customer_cart', 'class' => 'btn btn-primary btn-block' , 'name' => 'payout_customer_cart']) ?>
</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

@ -39,9 +39,7 @@ use kartik\widgets\ActiveForm;
</div>
<div class="row">
<div class='col-md-3 '>
<?php $form = ActiveForm::begin([]); ?>
<?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 echo Html::a( Yii::t('frontend/product', "Paid"), "javascript: $('#frm_user_cart').submit()",[ 'id' => 'btn_pay_user_cart', 'class' => 'btn btn-primary btn-block' , 'name' => 'payout_user_cart']) ?>
</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();']) ?>

View File

@ -18,7 +18,7 @@ $options = [];
$options['lookup_product_url'] = Url::toRoute(['product/lookup']);
$options['find_product_url'] = Url::toRoute(['product/find']);
$options['url_pay_user_cart'] = Url::toRoute(['product/payout-user-cart']);
$options['url_pay_user_cart'] = Url::toRoute(['product/payout-user-cart' , 'number' =>isset($model->card) ? $model->card->number : '']);
$options['url_delete_transaction'] = Url::toRoute(['transfer/delete']);
$options['url_pay_transaction'] = Url::toRoute(['transfer/payout']);
$options['user_cart'] = $userTransfers;
@ -95,7 +95,7 @@ $this->params['breadcrumbs'][] = Yii::t('frontend/product', 'Sale');
</div>
<div class='col-md-6'>
<?php if ( $receptionForm->isCardWithCustomer() ){ ?>
<?php echo $this->render('_customer_cart' ) ?>
<?php echo $this->render('_customer_cart' , ['model' => $model]) ?>
<?php }?>
<?php echo $this->render('_user_cart' ) ?>

View File

@ -33,9 +33,10 @@ use kartik\widgets\ActiveForm;
</div>
</div>
<div class="row">
<div class='col-md-3 '>
<?php echo Html::a(Yii::t('frontend/product', "Paid"),"javascript: $('#frm_customer_cart').submit()",[ 'id' => 'btn_pay_customer_cart', 'class' => 'btn btn-primary btn-block' , 'name' => 'payout_customer_cart']) ?>
</div>
<div class='col-md-3 '>
<?php $form = ActiveForm::begin([]); ?>
<?php echo Html::submitButton( Yii::t('frontend/product', "Paid") , [ 'id' => 'btn_pay_user_cart', 'class' => 'btn btn-primary btn-block', 'name' => 'payout_customer_cart' ] ) ?>
<?php ActiveForm::end(); ?>
<?php echo Html::a(Yii::t('frontend/product', "Frissít"),null,[ 'class' => 'btn btn-primary btn-block' , 'onclick' => 'location.reload();']) ?>
</div>
</div>

View File

@ -36,8 +36,9 @@ use kartik\widgets\ActiveForm;
</div>
<div class='row' >
<div class='col-md-3'>
<?php $form = ActiveForm::begin([]); ?>
<?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 echo Html::a( Yii::t('frontend/product', "Paid"), "javascript: $('#frm_user_cart').submit()",[ 'id' => 'btn_pay_user_cart', 'class' => 'btn btn-primary btn-block' , 'name' => 'payout_user_cart']) ?>
</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>

View File

@ -29,10 +29,16 @@ $options = [];
$options['clear_cart_url'] = Url::toRoute(['product/clear-list']);
$options['types'] = TicketType::modelsToArray($ticketTypes);
$options['user_cart'] = $model->userCart;
$options['customer_cart'] = $model->customerCart;
// $options['customer_cart'] = $model->customerCart;
$options['selected_type'] = count($ticketTypes) > 0 ? $ticketTypes[0]->id_ticket_type : 0;
$options['url_delete_transaction'] = Url::toRoute(['transfer/delete']);
$options['url_pay_transaction'] = Url::toRoute(['transfer/payout']);
$options['url_pay_user_cart'] = Url::toRoute(['product/payout-user-cart' , 'number' =>isset($receptionForm->card) ? $receptionForm->card->number : '']);
if ( isset($receptionForm->card) ){
$options['url_pay_customer_card'] = Url::toRoute(['product/payout-customer-cart','number' => $receptionForm->card->number]);
$options['customer_cart'] = $model->customerCart;
}
$this->registerJs ( 'new TicketSell( '. json_encode($options).');' );
?>

View File

@ -25,13 +25,15 @@ function ProductSell(o){
form_invalid: 'Az ürlap hibákat tartalmaz',
message_paid: 'Tételek fizetve',
/**list of sold items by current user*/
user_cart: [],
user_cart: [],// the user cart items
discounts: [],
customer_cart: [],
customer_cart: [], //the customer cart items
id_account: null,
products : [],
url_delete_transaction : '',
url_pay_transaction : '',
value_number: '',
name_number: '',
};
@ -70,8 +72,8 @@ function ProductSell(o){
* payout out user or customer cart
* */
function addPayoutButtons(){
addBehaviourPayoutUserCart();
addBehaviourPayoutCustomerCart();
// addBehaviourPayoutUserCart();
// addBehaviourPayoutCustomerCart();
}
/**
* display user and customer cart on page load
@ -464,7 +466,6 @@ function ProductSell(o){
}
function addBehaviourPayoutCustomerCart( ){
$( app.defaults.selector_btn_pay_customer_cart ).on('click',function(){
alert('ok');
$.ajax({
url: app.defaults.url_pay_customer_card,
type: 'post',
@ -489,6 +490,11 @@ function ProductSell(o){
'transfers' : app.defaults.user_cart,
'url_delete' : app.defaults.url_delete_transaction,
'url_pay' : app.defaults.url_pay_transaction,
'url_pay_all_visible' : app.defaults.url_pay_user_cart,
'name_transfers' : 'UserCartPayoutForm[transfers][]',
'id_form' : 'frm_user_cart',
// 'value_number': app.defaults.value_number,
// 'name_number':app.defaults.name_number,
});
}
function createCustomerCartTable(){
@ -496,6 +502,11 @@ function ProductSell(o){
'transfers' : app.defaults.customer_cart,
'url_delete' : app.defaults.url_delete_transaction,
'url_pay' : app.defaults.url_pay_transaction,
'url_pay_all_visible' : app.defaults.url_pay_customer_card,
'name_transfers' : 'CustomerCartPayoutForm[transfers][]',
'id_form' : 'frm_customer_cart',
// 'value_number': app.defaults.value_number,
// 'name_number':app.defaults.name_number,
});
}

View File

@ -79,8 +79,8 @@ function TicketSell(o){
* payout out user or customer cart
* */
function addPayoutButtons(){
addBehaviourPayoutUserCart();
addBehaviourPayoutCustomerCart();
// addBehaviourPayoutUserCart();
// addBehaviourPayoutCustomerCart();
}
/**
@ -96,6 +96,9 @@ function TicketSell(o){
'transfers' : app.defaults.user_cart,
'url_delete' : app.defaults.url_delete_transaction,
'url_pay' : app.defaults.url_pay_transaction,
'url_pay_all_visible' : app.defaults.url_pay_user_cart,
'name_transfers' : 'UserCartPayoutForm[transfers][]',
'id_form' : 'frm_user_cart',
});
}
function createCustomerCartTable(){
@ -103,6 +106,9 @@ function TicketSell(o){
'transfers' : app.defaults.customer_cart,
'url_delete' : app.defaults.url_delete_transaction,
'url_pay' : app.defaults.url_pay_transaction,
'url_pay_all_visible' : app.defaults.url_pay_customer_card,
'name_transfers' : 'CustomerCartPayoutForm[transfers][]',
'id_form' : 'frm_customer_cart',
});
}

View File

@ -3,6 +3,9 @@ $.widget( "fitness.transferList", {
transfers: [],
url_delete : '',
url_pay : '',
url_pay_all_visible: '',
name_transfers: '',//name to use for transfer id in form
id_form: '',
columns: [
{ 'label' : 'Idő' },
@ -42,6 +45,7 @@ $.widget( "fitness.transferList", {
_refresh: function(){
var s;
s = this._render('table',{ 'columns' : this.options.columns, 'transfers' : this.options.transfers,'footer': this.options.footers });
s += this.makeForm();
this.element.html(s);
},
@ -159,7 +163,19 @@ $.widget( "fitness.transferList", {
// Fire event
// this._triggerOptionChanged(key, prev, value);
}
}, makeForm: function(){
var s;
s = "";
s += "<form method='post' action='"+ this.options.url_pay_all_visible + "' id='"+this.options.id_form+"'>";
// s += "<input type='hidden' name='"+this.options.name_number+"' value='"+this.options.value_number+"'>";
for( var i = 0; i < this.options.transfers.length; i++){
s += "<input type='hidden' name='"+this.options.name_transfers+"' value='"+this.options.transfers[i].id_transfer+"'>";
}
s += "</form>";
return s;
}
});