diff --git a/backend/models/ProductSearch.php b/backend/models/ProductSearch.php index f49d2f6..5f79dca 100644 --- a/backend/models/ProductSearch.php +++ b/backend/models/ProductSearch.php @@ -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; } diff --git a/common/components/Helper.php b/common/components/Helper.php index fa1199b..df1cde6 100644 --- a/common/components/Helper.php +++ b/common/components/Helper.php @@ -85,5 +85,11 @@ class Helper } + public static function fixAsciiChars($in){ + $out = str_replace("ö", "0", $in); + $out = str_replace("Ö", "0", $in); + return $out; + } + } \ No newline at end of file diff --git a/common/models/Card.php b/common/models/Card.php index 42f4016..136e643 100644 --- a/common/models/Card.php +++ b/common/models/Card.php @@ -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); } } diff --git a/common/models/Product.php b/common/models/Product.php index 057bddb..8ad2b07 100644 --- a/common/models/Product.php +++ b/common/models/Product.php @@ -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 diff --git a/common/models/ShoppingCart.php b/common/models/ShoppingCart.php index af46e66..8ab17b7 100644 --- a/common/models/ShoppingCart.php +++ b/common/models/ShoppingCart.php @@ -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]); + } } diff --git a/common/models/Transfer.php b/common/models/Transfer.php index 19c679c..dbe8c65 100644 --- a/common/models/Transfer.php +++ b/common/models/Transfer.php @@ -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, diff --git a/common/models/UserSoldItem.php b/common/models/UserSoldItem.php index 63653a4..5280fad 100644 --- a/common/models/UserSoldItem.php +++ b/common/models/UserSoldItem.php @@ -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]); + } } diff --git a/console/migrations/m160104_155510_alter__table__transaction__add__column__paid_by.php b/console/migrations/m160104_155510_alter__table__transaction__add__column__paid_by.php new file mode 100644 index 0000000..1530a60 --- /dev/null +++ b/console/migrations/m160104_155510_alter__table__transaction__add__column__paid_by.php @@ -0,0 +1,31 @@ +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() + { + } + */ +} diff --git a/frontend/components/FrontendMenuStructure.php b/frontend/components/FrontendMenuStructure.php index ebeb8f7..579a630 100644 --- a/frontend/components/FrontendMenuStructure.php +++ b/frontend/components/FrontendMenuStructure.php @@ -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 ] ]; diff --git a/frontend/controllers/AccountStateController.php b/frontend/controllers/AccountStateController.php index 1be2f4f..9f1c596 100644 --- a/frontend/controllers/AccountStateController.php +++ b/frontend/controllers/AccountStateController.php @@ -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]); diff --git a/frontend/controllers/ProductController.php b/frontend/controllers/ProductController.php index a26bf59..2e8569c 100644 --- a/frontend/controllers/ProductController.php +++ b/frontend/controllers/ProductController.php @@ -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, + * ]); + * } + * } + */ } diff --git a/frontend/controllers/TransferController.php b/frontend/controllers/TransferController.php index 9a5d989..f5cac04 100644 --- a/frontend/controllers/TransferController.php +++ b/frontend/controllers/TransferController.php @@ -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() ){ diff --git a/frontend/models/CustomerCartPayoutForm.php b/frontend/models/CustomerCartPayoutForm.php new file mode 100644 index 0000000..2a880cb --- /dev/null +++ b/frontend/models/CustomerCartPayoutForm.php @@ -0,0 +1,42 @@ + ['integer']], + ]; + } + + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + ]; + } + + + + +} diff --git a/frontend/models/ProductSaleForm.php b/frontend/models/ProductSaleForm.php index fb36b3e..d5a8005 100644 --- a/frontend/models/ProductSaleForm.php +++ b/frontend/models/ProductSaleForm.php @@ -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(); } diff --git a/frontend/models/ReceptionForm.php b/frontend/models/ReceptionForm.php index e85ef51..04af117 100644 --- a/frontend/models/ReceptionForm.php +++ b/frontend/models/ReceptionForm.php @@ -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(){ diff --git a/frontend/models/TicketCreate.php b/frontend/models/TicketCreate.php index ff8d2aa..8345d90 100644 --- a/frontend/models/TicketCreate.php +++ b/frontend/models/TicketCreate.php @@ -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; diff --git a/frontend/models/UserCartPayoutForm.php b/frontend/models/UserCartPayoutForm.php new file mode 100644 index 0000000..a0f1fcf --- /dev/null +++ b/frontend/models/UserCartPayoutForm.php @@ -0,0 +1,42 @@ + ['integer']], + ]; + } + + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + ]; + } + + + + +} diff --git a/frontend/views/common/_reception.php b/frontend/views/common/_reception.php index cd5f30b..72eb2ea 100644 --- a/frontend/views/common/_reception.php +++ b/frontend/views/common/_reception.php @@ -7,6 +7,13 @@ use yii\base\Widget; use frontend\components\ReceptionTicketWidget; use frontend\components\ReceptionCustomerWidget; ?> +