add frontend changes

This commit is contained in:
rocho 2015-10-30 09:28:58 +01:00
parent 4a04c9efa2
commit e34b150d74
41 changed files with 1083 additions and 254 deletions

View File

@ -37,7 +37,7 @@ class TransferSearch extends Transfer
return [
[[ 'id_account','id_user', 'type'], 'integer'],
// [[ 'searchObjectName' ], 'string'],
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
];
}
@ -92,8 +92,8 @@ class TransferSearch extends Transfer
'transfer.id_user' => $this->id_user,
]);
$query->andFilterWhere([ '>=', 'transfer.created_at', $this->timestampStart ] );
$query->andFilterWhere([ '<', 'transfer.created_at', $this->timestampEnd ] );
$query->andFilterWhere([ '>=', 'transfer.created_at' , $this->timestampStart ] );
$query->andFilterWhere([ '<' , 'transfer.created_at' , $this->timestampEnd ] );
// if ( isset($this->searchObjectName))
// $query->andWhere( new Expression(" case when transfer.type = " .self::TYPE_PRODUCT ." then product.name else ticket_type.name end like '%" . $this->searchObjectName ."%'"));

View File

@ -0,0 +1,24 @@
<?php
namespace common\components;
use yii\base\Behavior;
use common\models\Customer;
class CustomerAwareBehavior extends Behavior{
public function getCustomerName(){
$result = "";
$customer = $this->owner->customer;
if (isset($customer)){
$result = $customer->name;
}
return $result;
}
public function getCustomer(){
return $this->owner->hasOne( Customer::className(), ["id_customer" =>"id_customer" ] ) ;
}
}

View File

@ -27,7 +27,7 @@ return [
'Id Currency' => 'Valuta',
'Id Discount' => 'Kedvezmény',
'Id Object' => 'Termék',
'Id Transfer' => 'Pénzmozgás',
'Id Transfer' => 'Tranzakció',
'Id User' => 'Felhasználó',
'Item Price' => 'Termék ár',
'Money' => 'Összeg',

View File

@ -0,0 +1,24 @@
<?php
/**
* Message translations.
*
* This file is automatically generated by 'yii message' command.
* It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages.
*
* Each array element represents the translation (value) of a message (key).
* If the value is empty, the message is considered as not translated.
* Messages that no longer need translation will have their translations
* enclosed between a pair of '@@' marks.
*
* Message string can be used with plural forms format. Check i18n section
* of the guide for details.
*
* NOTE: this file must be saved in UTF-8 encoding.
*/
return [
'Account' => 'Kassza',
'User' => 'Felhasználó',
'End' => 'Időintervallum vége',
'Start' => 'Időintervallum kezdete',
];

View File

@ -20,7 +20,7 @@ return [
'Customer cart' => 'Vendég kosár',
'Fizetve' => 'Fizetve',
'To cart' => 'Kosárba',
'User Cart' => 'Kosárba',
'User Cart' => 'Recepció kosár',
'Write up' => 'Felír',
'Account' => 'Kassza',
'Are you sure you want to delete this item?' => 'Biztosan törölni szeretné ezt a vendéget?',

View File

@ -95,6 +95,8 @@ class MoneyMovement extends \yii\db\ActiveRecord
'comment' => Yii::t('common/money-movement', 'Comment'),
'created_at' => Yii::t('common/money-movement', 'Created At'),
'updated_at' => Yii::t('common/money-movement', 'Updated At'),
'accountName' => Yii::t('frontend/money-movement', 'Account'),
'userName' => Yii::t('frontend/money-movement', 'User'),
];
}

View File

@ -68,8 +68,9 @@ class ShoppingCart extends \yii\db\ActiveRecord
//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' )
. " WHERE t.status = " . Transfer::STATUS_NOT_PAID;
SET 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 ;
$q1 = Yii::$app->db->createCommand($sql);
$q1->execute();

View File

@ -8,6 +8,8 @@ use yii\helpers\ArrayHelper;
use yii\behaviors\TimestampBehavior;
use common\components\AccountAwareBehavior;
use common\components\UserAwareBehavior;
use common\components\DiscountAwareBehavior;
use common\components\CustomerAwareBehavior;
/**
* This is the model class for table "transfer".
@ -29,6 +31,8 @@ use common\components\UserAwareBehavior;
* @property string $created_at
* @property string $updated_at
* @property integer $direction
* @property string $paid_at
* @property integer $id_customer
*/
class Transfer extends \common\models\BaseFitnessActiveRecord
{
@ -54,12 +58,12 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
'class' => TimestampBehavior::className(),
'value' => function(){ return date('Y-m-d H:i:s' ); }
],
// [
// 'class' => AccountAwareBehavior::className(),
// ],
// [
// 'class' => UserAwareBehavior::className(),
// ],
[
'class' => DiscountAwareBehavior::className(),
],
[
'class' => CustomerAwareBehavior::className(),
],
], parent::behaviors());
}
@ -103,9 +107,11 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
'money_currency' => Yii::t('common/transfer', 'Money Currency'),
'rate' => Yii::t('common/transfer', 'Rate'),
'id_user' => Yii::t('common/transfer', 'Id User'),
'id_customer' => Yii::t('common/transfer', 'Customer'),
'comment' => Yii::t('common/transfer', 'Comment'),
'created_at' => Yii::t('common/transfer', 'Created At'),
'updated_at' => Yii::t('common/transfer', 'Updated At'),
'paid_at' => Yii::t('common/transfer', 'Paid At'),
];
}
@ -136,9 +142,9 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
return $this->hasOne( Currency::className(), ["id_currency" =>"id_currency" ] );
}
public function getDiscount(){
return $this->hasOne( Discount::className(), ["id_discount" =>"id_discount" ] );
}
// public function getDiscount(){
// return $this->hasOne( Discount::className(), ["id_discount" =>"id_discount" ] );
// }
public function getUserSoldItem(){
return $this->hasOne( UserSoldItem::className(), ["id_transfer" =>"id_transfer" ] );
@ -256,8 +262,9 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
* @param $discount common\models\Discount
* @param $currency common\models\Currency
* @param $product common\models\Product
* @param $customer common\models\Customer
* */
public static function createProductTransfer($sale,$account, $discount, $currency, $count,$product , $status = Transfer::STATUS_PAID){
public static function createProductTransfer($sale,$account, $discount, $currency, $count,$product , $status = Transfer::STATUS_PAID,$customer = null){
$transfer = new Transfer();
$transfer->type = Transfer::TYPE_PRODUCT;
@ -287,6 +294,10 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
$transfer->id_account = $account->id_account;
if ( isset( $customer ) ){
$transfer->id_customer = $customer->id_customer;
}
return $transfer;
}
@ -309,6 +320,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
$transfer->id_account = $account->id_account;
$transfer->paid_at = date('Y-m-d H:i:s' ) ;
return $transfer;
}
/**
@ -317,9 +330,10 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
* @param $currency common\models\Currency
* @param $ticket common\models\Ticket
* */
public static function createTicketTransfer($account, $discount, $currency, $count,$ticket ){
public static function createTicketTransfer($account, $discount, $currency, $count,$ticket ,$status = Transfer::STATUS_NOT_PAID){
$transfer = new Transfer();
$transfer->status = $status;
$transfer->type = Transfer::TYPE_TICKET;
$transfer->id_object = $ticket->id_ticket;
@ -422,6 +436,20 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
self::TYPE_TICKET => Yii::t('common/transfer','Ticket'),
];
}
public static function statuses( ) {
return [
self::STATUS_NOT_PAID => Yii::t('common/transfer','Nincs fizetve'),
self::STATUS_PAID => Yii::t('common/transfer','Fizetve'),
];
}
public function getStatusName( ) {
$status = null;
$statuses = self::statuses();
if ( array_key_exists($this->status, $statuses)){
$status = $statuses[$this->status];
}
return $status;
}

View File

@ -61,5 +61,24 @@ class UserSoldItem extends \yii\db\ActiveRecord
}
/**
* @param common\models\User $user
* */
public static function payout( $user ) {
//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' ) ."'"
. " WHERE t.status = " . Transfer::STATUS_NOT_PAID
. " and s.id_user =" . $user->id ;
$q1 = Yii::$app->db->createCommand($sql);
$q1->execute();
UserSoldItem::deleteAll(['id_user' => Yii::$app->user->id]);
}
}

View File

@ -0,0 +1,30 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m151029_090850_alter__table__transfer__add__column__id_customer extends Migration
{
public function up()
{
$this->addColumn("transfer", 'id_customer"', 'int(11)');
}
public function down()
{
echo "m151029_090850_alter__table__transfer__add__column__id_customer cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -0,0 +1,30 @@
<?php
use yii\db\Schema;
use yii\db\Migration;
class m151029_095915_alter__table__transfer__fix__id_customer__column__name extends Migration
{
public function up()
{
$this->renameColumn("transfer", 'id_customer"', "id_customer");
}
public function down()
{
echo "m151029_095915_alter__table__transfer__fix__id_customer__column__name cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -0,0 +1,62 @@
<?php
namespace frontend\components;
use Yii;
use common\models\Order;
use yii\helpers\Html;
use common\models\MoneyMovement;
use yii\db\Query;
use common\models\AccountState;
use yii\web\Controller;
use yii\base\Object;
use frontend\models\ReceptionForm;
use common\models\UserSoldItem;
use common\models\ShoppingCart;
use common\models\Transfer;
use common\models\User;
class FrontendController extends Controller{
protected function mkReceptionForm($number){
$receptionForm = new ReceptionForm();
$receptionForm->number = $number;
$receptionForm->readCard();
return $receptionForm;
}
protected function payoutCustomerCart($receptionForm){
$result = false;
if ( isset($receptionForm->customer)){
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
ShoppingCart::payout($receptionForm->customer);
$transaction->commit();
Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Customer cart paid!') );
$result = true;
} catch(Exception $e) {
$transaction->rollback();
}
}
return $result;
}
protected function payoutUserCart($receptionForm){
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
$user = User::findOne(Yii::$app->user->id );
UserSoldItem::payout($user);
$transaction->commit();
Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'User cart paid!') );
return $this->redirect(['customer/reception' ]);
} catch(Exception $e) {
$transaction->rollback();
}
return true;
}
}

View File

@ -11,15 +11,19 @@ use common\models\AccountState;
class FrontendMenuStructure{
public $menuItems;
public $start;
public $tomorrow;
public $start;//start date and time
public $tomorrow;//tomorrow date and time
public $startDate;//start date
public $tomorrowDate;//tomorrow date
public function __construct(){
$this->menuItems = [];
// print('abcd<br>abcd<br>abcd<br>abcd<br>abcd<br>abcd<br>abcd<br>abcd<br>abcd<br>abcd<br>abcd<br>abcd<br>abcd<br>');
$this->start = Yii::$app->formatter->asDatetime( strtotime('today UTC') );
$this->tomorrow = Yii::$app->formatter->asDatetime( strtotime('tomorrow UTC') );
$this->startDate = Yii::$app->formatter->asDate( strtotime('today UTC') );
$this->tomorrowDate = Yii::$app->formatter->asDate( strtotime('tomorrow UTC') );
Yii::info("Start date is : ". $this->start);
@ -57,13 +61,15 @@ class FrontendMenuStructure{
if ( $this->isLogged() ){
$this->menuItems[] = ['label' => 'Recepcio', 'url' => ['/customer/reception'] ];
// , 'MoneyMovementSearch[start]' => $this->start, 'MoneyMovementSearch[end]' => $this->tomorrow
$this->menuItems[] = ['label' => 'Pénzmozgások', 'url' => [ '/money-movement/index', 'MoneyMovementSearch[start]' => $this->start, 'MoneyMovementSearch[end]' => $this->tomorrow ] ];
// $this->menuItems[] = ['label' => 'Pénzmozgások', 'url' => [ '/money-movement/index', 'MoneyMovementSearch[start]' => $this->start, 'MoneyMovementSearch[end]' => $this->tomorrow ] ];
$this->menuItems[] = ['label' => 'Kassza',
'items' => [
['label' => Yii::t('frontend/account-state','Default account'), 'url' => ['/account/select'] ],
['label' => Yii::t('frontend/account-state', 'Account states'), 'url' => ['/account-state/index'] ],
['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' => 'Pénzmozgások', 'url' => [ '/money-movement/index', 'MoneyMovementSearch[start]' => $this->start, 'MoneyMovementSearch[end]' => $this->tomorrow ] ],
['label' => Yii::t('frontend/transfer','Transfers'), 'url' => ['/transfer/index', 'TransferSearch[start]' => $this->start, 'TransferSearch[end]' => $this->tomorrow ] ],
]
];

View File

@ -43,6 +43,7 @@ class AccountController extends Controller
if ($model->load(Yii::$app->request->post()) && $model->writeToSession()) {
Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Default account is set!') );
return $this->redirect(['product/sale']);
}
return $this->render('select', [
'model' => $model,

View File

@ -141,8 +141,7 @@ class ProductController extends Controller
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
$user = User::findOne(Yii::$app->user->id );
UserSoldItem::deleteAll(['id_user' => Yii::$app->user->id]);
UserSoldItem::payout($user);
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
$result['transfers'] = $userTransfers;

View File

@ -88,11 +88,10 @@ class SiteController extends Controller
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
// return $this->goBack();
return $this->redirect(['account/select']);
} else {
return $this->render('login', [
'model' => $model,
]);
return $this->render('login', ['model' => $model,]);
}
}

View File

@ -16,11 +16,14 @@ use common\models\Account;
use yii\base\Object;
use common\models\Transfer;
use common\models\User;
use common\models\ShoppingCart;
use common\models\UserSoldItem;
use frontend\components\FrontendController;
/**
* TicketController implements the CRUD actions for Ticket model.
*/
class TicketController extends Controller
class TicketController extends FrontendController
{
public function behaviors()
{
@ -52,9 +55,7 @@ class TicketController extends Controller
*/
public function actionIndex($number = null)
{
$receptionForm = new ReceptionForm();
$receptionForm->number = $number;
$receptionForm->readCard();
$receptionForm = $this->mkReceptionForm($number);
if ( !isset($receptionForm->card ) ){
@ -79,14 +80,19 @@ class TicketController extends Controller
public function actionCreate($number = null)
{
$receptionForm = new ReceptionForm();
$receptionForm->number = $number;
$receptionForm->readCard();
$receptionForm =$this->mkReceptionForm($number);
if ( !isset($receptionForm->card ) ){
throw new NotFoundHttpException( Yii::t('frontend/ticket', 'The requested card does not exist.'));
}
if ( isset($_POST['payout_customer_cart']) && $this->payoutCustomerCart($receptionForm) ){
return $this->redirect(['customer/reception' ]);
}else if ( isset($_POST['payout_user_cart']) && $this->payoutUserCart($receptionForm)){
return $this->redirect(['customer/reception' ]);
}
$model = new TicketCreate();
$discounts = Discount::read();
@ -97,7 +103,7 @@ class TicketController extends Controller
$user = User::findOne( [ 'id' => Yii::$app->user->id ] );
$model->customer = $receptionForm->customer;
$model->id_user = \Yii::$app->user->id;
$model->status = Ticket::STATUS_ACTIVE;
$model->usage_count = 0;
@ -107,9 +113,10 @@ class TicketController extends Controller
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash('success', Yii::t('frontend/ticket', 'Ticket added to customer') );
return $this->redirect(['product/sale', 'number' => $receptionForm->card->number]);
} else {
}
$userTransfers = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
$model->userCart = Transfer::modelsToArray( Transfer::readUserSoldTransfers($user) );
$model->customerCart = Transfer::modelsToArray( Transfer::readCustomerCart( $receptionForm->customer ) );
return $this->render('create', [
'model' => $model,
@ -117,71 +124,7 @@ class TicketController extends Controller
'ticketTypes' => $ticketTypes,
'accounts' => $accounts,
'receptionForm' => $receptionForm,
'userTransfers' => $userTransfers,
]);
}
}
/**
* Finds the Ticket model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Ticket the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Ticket::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
* Displays a single Ticket model.
* @param integer $id
* @return mixed
*/
/*
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
*/
/**
* Deletes an existing Ticket model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
/*
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
*/
/**
* Updates an existing Ticket model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
/*
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id_ticket]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
*/
}

View File

@ -9,6 +9,7 @@ use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use frontend\models\TransferMoneyMovementSearch;
use common\models\Account;
/**
* TransferController implements the CRUD actions for Transfer model.
@ -41,6 +42,27 @@ class TransferController extends Controller
'dataProvider' => $dataProvider,
]);
}
/**
* Lists all Transfer models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new TransferSearch();
$searchModel->accounts = Account::read();
$searchModel->load(Yii::$app->request->queryParams);
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$searchModel->totalsTransfers(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Transfer model.

View File

@ -38,5 +38,13 @@ class AccountSelect extends Model
Account::writeDefault($account);
return true;
}
/* */
public function attributeLabels(){
return [
'id_account' =>Yii::t('frontend/account', 'Account')
];
}
}

View File

@ -6,6 +6,7 @@ use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\MoneyMovement;
use yii\helpers\ArrayHelper;
/**
* MoneyMovementSearch represents the model behind the search form about `common\models\MoneyMovement`.
@ -69,4 +70,13 @@ class MoneyMovementSearch extends MoneyMovement
return $dataProvider;
}
public function attributeLabels( ) {
return ArrayHelper::merge(parent::attributeLabels(),
[
'start' => Yii::t('frontend/money-movement', 'Start'),
'end' => Yii::t('frontend/money-movement', 'End'),
]
);
}
}

View File

@ -184,14 +184,16 @@ class ProductSaleForm extends Model
}
protected function saveTransfer(){
$customer = null;
$status = Transfer::STATUS_PAID;
if ( $this->isAppendToUserCart() ){
$status = Transfer::STATUS_NOT_PAID;
}else if ( $this->isAppendToCustomerCart() ){
$status = Transfer::STATUS_NOT_PAID;
$customer = $this->customer;
}
$this->transfer = Transfer::createProductTransfer($this->sale,$this->account, $this->discount, $this->currency, $this->count, $this->product,$status);
$this->transfer = Transfer::createProductTransfer($this->sale,$this->account, $this->discount, $this->currency, $this->count, $this->product,$status,$customer);
if ( isset($this->comment)){
$this->transfer->comment = $this->comment;
}
@ -229,8 +231,6 @@ class ProductSaleForm extends Model
}
public function appendToCustomerCart(){
// print_r("cart: ".$this->cart );
// print_r("customer:: ".$this->customer );
if ( $this->isAppendToCustomerCart() && isset($this->customer) ){
$item = new ShoppingCart();
$item->id_customer = $this->customer->id_customer;

View File

@ -7,8 +7,16 @@ use common\models\Account;
use common\models\Discount;
use common\models\Transfer;
use common\models\UserSoldItem;
use common\models\ShoppingCart;
use yii\base\Object;
/**
* @property $cart string name of cart, into we put the ticket
* @property $userCart common\models\Transfer[] items in user cart
* @property $customerCart common\models\Transfer[] items in customer cart
* @property $customer common\models\Customer selected customer
*
* */
class TicketCreate extends Ticket{
public $_currency;
@ -16,6 +24,12 @@ class TicketCreate extends Ticket{
public $_discount;
public $_transfer;
public $customer;
public $userCart;
public $customerCart;
public $cart;
public function rules()
@ -88,14 +102,15 @@ class TicketCreate extends Ticket{
public function afterSave($insert, $changedAttributes){
$this->addTransfer();
$this->addToCart();
$this->appendToUserCart();
$this->appendToCustomerCart();
}
protected function addTransfer(){
$transfer = Transfer::createTicketTransfer($this->_account, $this->_discount, null, 1, $this);
$transfer->status = Transfer::STATUS_PAID;
// $transfer->status = Transfer::STATUS_PAID;
if ( isset($this->comment)){
$transfer->comment = $this->comment;
}
@ -114,12 +129,41 @@ class TicketCreate extends Ticket{
}
public function isAddToCart(){
$result = false;
if ( isset( $this->cart ) && $this->cart == 'add' ){
$result = true;
}
return $result;
}
public function isAppendToUserCart(){
$result = false;
if ( isset( $this->cart ) && $this->cart == 'user' ){
$result = true;
}
return $result;
}
public function isAppendToCustomerCart(){
$result = false;
if ( isset( $this->cart ) && $this->cart == 'customer' ){
$result = true;
}
return $result;
}
public function appendToUserCart(){
if ( $this->isAppendToUserCart() ){
$item = new UserSoldItem();
$item->id_transfer = $this->_transfer->id_transfer;
$item->id_user = \Yii::$app->user->id;
$item->save(false);
}
}
public function appendToCustomerCart(){
if ( $this->isAppendToCustomerCart() && isset($this->customer) ){
$item = new ShoppingCart();
$item->id_customer = $this->customer->id_customer;
$item->id_transfer = $this->_transfer->id_transfer;
$item->save(false);
}
}
}

View File

@ -6,31 +6,56 @@ use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Transfer;
use yii\base\Object;
use yii\db\Query;
use yii\db\Expression;
use common\models\Account;
use yii\helpers\ArrayHelper;
/**
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
*/
class TransferSearch extends Transfer
{
public $start;
public $end;
public $timestampStart;
public $timestampEnd;
public $totalsCreatedAt = ['total' => 0, 'accounts' =>[] ];
public $totalsCreatedAtNotPaid= ['total' => 0, 'accounts' =>[]];
public $totalsCreatedAtPaid= ['total' => 0, 'accounts' =>[]];
public $totalsPaidAt= ['total' => 0, 'accounts' =>[]];
public $accounts;
public $types;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_transfer', 'id_discount', 'id_currency', 'id_object', 'status', 'type', 'item_price', 'count', 'money', 'money_currency', 'rate', 'id_user'], 'integer'],
[['comment', 'created_at', 'updated_at'], 'safe'],
// [[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
// [[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'start', ], 'date', 'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
[[ 'end' , ], 'date' ,'format' =>Yii::$app->formatter->datetimeFormat , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd HH:mm' ,'timeZone' => 'UTC' ],
[ [ 'id_account' ] , 'integer'],
['types', 'each', 'rule' => ['integer']],
// [ [ 'types' ], function ($attribute, $params) {
// if (!is_array($this->$attribute)) {
// $this->addError($attribute, 'Invalid array');
// }
// }],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
@ -56,24 +81,208 @@ class TransferSearch extends Transfer
}
$query->andFilterWhere([
'id_transfer' => $this->id_transfer,
'id_discount' => $this->id_discount,
'id_currency' => $this->id_currency,
'id_object' => $this->id_object,
'status' => $this->status,
'id_account' => $this->id_account,
'type' => $this->type,
'item_price' => $this->item_price,
'count' => $this->count,
'money' => $this->money,
'money_currency' => $this->money_currency,
'rate' => $this->rate,
'id_user' => $this->id_user,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['in' ,'type', $this->types]);
$query->andFilterWhere(['like', 'comment', $this->comment]);
$created_condition = ['and',[ '>=', 'transfer.created_at', $this->timestampStart ] ,[ '<', 'transfer.created_at', $this->timestampEnd ] ];
$paid_condition = ['and',[ '>=', 'transfer.paid_at', $this->timestampStart ] ,[ '<', 'transfer.paid_at', $this->timestampEnd ] ];
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
return $dataProvider;
}
protected function mkTotalQuery($mode){
$query = new Query();
$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' )
]);
$query->from('transfer');
$query->andFilterWhere([
'id_account' => $this->id_account,
'type' => $this->type,
]);
$query->andWhere(['id_user' => Yii::$app->user->id]);
$query->andFilterWhere(['in' ,'type', $this->types]);
if ( $mode == 'created_at'){
$query->andFilterWhere([ '>=', 'transfer.created_at' , $this->timestampStart ] );
$query->andFilterWhere([ '<' , 'transfer.created_at' , $this->timestampEnd ] );
}else if ( $mode == 'paid_at'){
$query->andFilterWhere([ '>=', 'transfer.paid_at' , $this->timestampStart ] );
$query->andFilterWhere([ '<' , 'transfer.paid_at' , $this->timestampEnd ] );
}else if ( $mode == 'created_at_not_paid'){
$query->andFilterWhere([ "transfer.status" => Transfer::STATUS_NOT_PAID ] );
$query->andFilterWhere([ '>=', 'transfer.created_at' , $this->timestampStart ] );
$query->andFilterWhere([ '<' , 'transfer.created_at' , $this->timestampEnd ] );
}else if ( $mode == 'created_at_paid'){
$query->andFilterWhere([ "transfer.status" => Transfer::STATUS_PAID ] );
$query->andFilterWhere([ '>=', 'transfer.created_at' , $this->timestampStart ] );
$query->andFilterWhere([ '<' , 'transfer.created_at' , $this->timestampEnd ] );
}
$query->groupBy('transfer.id_account');
return $query;
}
protected function mkTransferTotalsWithZeroValue( ){
$result = [];
foreach ( $this->accounts as $a ){
$accountTotal = [
'id_account' => $a->id_account,
'label' => $a->name,
'money' => 0
];
$result[] = $accountTotal;
}
return $result;
}
protected function mkTotalsResult($queryResult,$accountMap){
$totals = [];
$totals['total'] = 0;
$totals['accounts'] = [];
foreach ($queryResult as $item){
$account = "";
if ( array_key_exists($item['account'], $accountMap)){
$account = $accountMap[$item['account']];
}
$accountTotal = [
'id_account' => $item['account'],
'label' => $account,
'money' => $item['money']
];
$totals['accounts'][] = $accountTotal;
$totals['total'] += $item['money'];
}
return $totals;
}
protected function findByAccountInQueryResult($queryResult, $account){
$result = null;
foreach ($queryResult as $item){
if( $item['account'] == $account->id_account ){
$result = $item;
}
}
return $result;
}
protected function mkTotalsResultWithAllAvailableAccount($queryResult,$accountMap){
$totals = [];
$totals['total'] = 0;
$totals['accounts'] = [];
foreach ($this->accounts as $account){
// echo 'account="'. $this->id_account .'"<br>';
if ( isset($this->id_account) && is_numeric($this->id_account) && $this->id_account != $account->id_account ){
continue ;
}
$accountTotal = [
'id_account' => $account->id_account,
'label' => $account->name,
'money' => 0,
];
$item = $this->findByAccountInQueryResult($queryResult, $account);
if ( isset($item)){
$accountTotal['money'] = $item['money'];
}
$totals['accounts'][] = $accountTotal;
$totals['total'] += $accountTotal['money'];
}
return $totals;
}
public function mkPaidAtTotals($accountMap){
$query = $this->mkTotalQuery('paid_at');
$command = $query->createCommand();
$result = $command->queryAll();
// $paidAtTotals = $this->mkTotalsResult($result, $accountMap);
$paidAtTotals = $this->mkTotalsResultWithAllAvailableAccount($result, $accountMap);
return $paidAtTotals;
}
public function mkCreatedAtTotals($accountMap){
$query = $this->mkTotalQuery('created_at');
$command = $query->createCommand();
$result = $command->queryAll();
$createdAtTotals = $this->mkTotalsResultWithAllAvailableAccount($result, $accountMap);
return $createdAtTotals;
}
public function mkCreatedAtNotPaidTotals($accountMap){
$query = $this->mkTotalQuery('created_at_not_paid');
$command = $query->createCommand();
$result = $command->queryAll();
$createdAtTotals = $this->mkTotalsResultWithAllAvailableAccount($result, $accountMap);
return $createdAtTotals;
}
public function mkCreatedAtPaidTotals($accountMap){
$query = $this->mkTotalQuery('created_at_paid');
$command = $query->createCommand();
$result = $command->queryAll();
$createdAtTotals = $this->mkTotalsResultWithAllAvailableAccount($result, $accountMap);
return $createdAtTotals;
}
public function totalsTransfers($params){
$accountTotals = [];
$fullTotal = [
'label' => Yii::t('common/transfer', 'Total'),
'money' => 0
];
if ( $this->hasErrors() ){
return;
}
$accounts = Account::find()->orderBy("name asc")->all();
$accountMap = ArrayHelper::map( $accounts ,'id_account','name' );
$this->totalsCreatedAt = $this->mkCreatedAtTotals($accountMap);
$this->totalsPaidAt = $this->mkPaidAtTotals($accountMap);
$this->totalsCreatedAtPaid = $this->mkCreatedAtPaidTotals($accountMap);
$this->totalsCreatedAtNotPaid = $this->mkCreatedAtNotPaidTotals($accountMap);
}
}

View File

@ -9,8 +9,9 @@ use frontend\components\HtmlHelper;
/* @var $form yii\widgets\ActiveForm */
?>
<h1><?php echo Yii::t('frontend/account','Select account!')?></h1>
<div class="account-form">
<?php $form = ActiveForm::begin(); ?>
<?php echo $form->field($model, 'id_account')->dropDownList(HtmlHelper::mkAccountOptions($accounts)) ?>

View File

@ -26,7 +26,6 @@ $this->params['breadcrumbs'][] = $this->title;
'accountName',
'userName',
'name',
'type',
'money',
'created_at:datetime',

View File

@ -33,4 +33,8 @@ use yii\bootstrap\Html;
</div>
</div>
</div>
<?php echo Html::a(Yii::t('frontend/product', "Fizetve"),null,[ 'id' => 'btn_pay_customer_cart', 'class' => 'btn btn-primary' ]) ?>
<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']) ?>
</div>
</div>

View File

@ -98,13 +98,10 @@ $discountOptions = mkOptions( ArrayHelper::map($discounts, 'id_discount', 'name'
</div>
</div>
<div class="row">
<div class='col-md-4'>
<?php echo Html::a(Yii::t("frontend/product","Sell product"),null,['class' => 'btn btn-success btn-block', 'id' => 'btn_sell'] );?>
</div>
<div class='col-md-4'>
<div class='col-md-6'>
<?php echo Html::a(Yii::t("frontend/product","To cart"),null,['class' => 'btn btn-success btn-block', 'id' => 'btn_sell_append'] );?>
</div>
<div class='col-md-4'>
<div class='col-md-6'>
<?php
if ( $receptionForm->isCardWithCustomer() ){
echo Html::a(Yii::t("frontend/product","Write up"),null,['class' => 'btn btn-success btn-block', 'id' => 'btn_add_to_customer_cart'] );

View File

@ -1,5 +1,6 @@
<?php
use yii\bootstrap\Html;
use kartik\widgets\ActiveForm;
?>
@ -33,8 +34,10 @@ use yii\bootstrap\Html;
</div>
</div>
</div>
<div class='row' >
<div class='col-md-3'>
<?php echo Html::a(Yii::t('frontend/product', "Paid"),null,[ 'id' => 'btn_pay_user_cart', 'class' => 'btn btn-primary btn-block' ]) ?>
<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(); ?>
</div>
</div>

View File

@ -16,6 +16,7 @@ $this->params['breadcrumbs'][] = $this->title;
<?= $this->render('_form', [
'model' => $model,
'receptionForm' => $receptionForm,
]) ?>
</div>

View File

@ -33,6 +33,9 @@ $options['id_account'] = Account::readDefault();
$this->registerJs ( 'new ProductSell( '. json_encode($options).');' );
$this->params['breadcrumbs'][] = Yii::t('frontend/product', 'Products') ;
$this->params['breadcrumbs'][] = Yii::t('frontend/product', 'Sale');
?>
<style>

View File

@ -0,0 +1,41 @@
<?php
use yii\bootstrap\Html;
use kartik\widgets\ActiveForm;
?>
<h1><?php echo Yii::t('frontend/product','Customer cart')?></h1>
<div class="row">
<div class='col-md-12 '>
<div class="customer-cart">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>
<?php echo Yii::t('frontend/product', 'Product name')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Count')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Currency')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Item Price')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Total Price')?>
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</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_customer_cart' ] ) ?>
<?php ActiveForm::end(); ?>
</div>
</div>

View File

@ -33,7 +33,9 @@ use common\models\Account;
<div class="col-md-12" >
<div class="ticket-form">
<?php $form = ActiveForm::begin(); ?>
<?php $form = ActiveForm::begin([
'id' => 'ticket_form',
]); ?>
<?= Html::activeHiddenInput($model, 'cart')?>
@ -64,11 +66,18 @@ use common\models\Account;
<?= $form->field($model, 'comment')->textarea(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton( Yii::t('common/ticket', 'Create') , [ 'onclick' => ' $(\'#ticketcreate-cart\').val(\'\');','class' => 'btn btn-success' ]) ?>
<?= Html::submitButton( Yii::t('common/ticket', 'Create and add to cart') , [ 'onclick' => ' $(\'#ticketcreate-cart\').val(\'add\');', 'class' => 'btn btn-success' ]) ?>
</div>
<div class="row">
<div class='col-md-6'>
<?php echo Html::a(Yii::t("frontend/ticket","To cart"),null,['class' => 'btn btn-success btn-block', 'id' => 'btn_add_to_user_cart'] );?>
</div>
<div class='col-md-6'>
<?php
if ( $receptionForm->isCardWithCustomer() ){
echo Html::a(Yii::t("frontend/ticket","Write up"),null,['class' => 'btn btn-success btn-block', 'id' => 'btn_add_to_customer_cart'] );
}
?>
</div>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,43 @@
<?php
use yii\bootstrap\Html;
use kartik\widgets\ActiveForm;
?>
<h1><?php echo Yii::t('frontend/product','User Cart')?></h1>
<div class="row">
<div class='col-md-12 '>
<div class="user-cart">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>
<?php echo Yii::t('frontend/product', 'Product name')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Count')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Currency')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Item Price')?>
</th>
<th>
<?php echo Yii::t('frontend/product', 'Total Price')?>
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</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(); ?>
</div>
</div>

View File

@ -28,17 +28,13 @@ $options = [];
// $options['lookup_product_url'] = Url::toRoute(['product/lookup']);
$options['clear_cart_url'] = Url::toRoute(['product/clear-list']);
$options['types'] = TicketType::modelsToArray($ticketTypes);
$options['transfer_list'] = $userTransfers;
$options['user_cart'] = $model->userCart;
$options['customer_cart'] = $model->customerCart;
$this->registerJs ( 'new TicketSell( '. json_encode($options).');' );
?>
<div class="ticket-create">
<?php echo ReceptionWidget::widget( ['form' => $receptionForm, 'route' => ['customer/reception'] ] )?>
<div class="row">
<div class="col-md-6">
<h1><?= Html::encode($this->title) ?></h1>
@ -47,13 +43,14 @@ $this->registerJs ( 'new TicketSell( '. json_encode($options).');' );
'discounts' => $discounts,
'ticketTypes' => $ticketTypes,
'accounts' => $accounts,
'receptionForm' => $receptionForm,
]) ?>
</div>
<div class="col-md-6">
<h1><?php echo Yii::t('frontend/ticket', 'Cart')?></h1>
<?php echo $this->render( "//common/_transfer_list" ) ?>
<?php echo Html::a(Yii::t('frontend/product', "Paid"),null,[ 'id' => 'btn_paid', 'class' => 'btn btn-primary' ]) ?>
<div class='col-md-6'>
<?php if ( $receptionForm->isCardWithCustomer() ){ ?>
<?php echo $this->render('_customer_cart' ) ?>
<?php }?>
<?php echo $this->render('_user_cart' ) ?>
</div>
</div>
</div>

View File

@ -0,0 +1,96 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\ListView;
use yii\base\Widget;
?>
<div>
<div class="row">
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">Kiadva az adott időszakban</div>
<div class="panel-body">
<dl class="dl-horizontal dl-totals">
<?php
foreach ($searchModel->totalsCreatedAt['accounts'] as $acc ){
?>
<dt><?php echo $acc['label'] ?></dt>
<dd class="text-right"><?php echo $acc['money'] ?></dd>
<?php
}
?>
<dt><?php echo Yii::t('frontend/transfer','Total') ?></dt>
<dd class="text-right"><?php echo $searchModel->totalsCreatedAt['total'] ?></dd>
</dl>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading">Kiadva/nem fizetve az adott időszakban</div>
<div class="panel-body">
<dl class="dl-horizontal dl-totals">
<?php
foreach ($searchModel->totalsCreatedAtNotPaid['accounts'] as $acc ){
?>
<dt><?php echo $acc['label'] ?></dt>
<dd class="text-right"><?php echo $acc['money'] ?></dd>
<?php
}
?>
<dt><?php echo Yii::t('frontend/transfer','Total') ?></dt>
<dd class="text-right"><?php echo $searchModel->totalsCreatedAtNotPaid['total'] ?></dd>
</dl>
</div>
</div>
</div>
<div class="col-md-4 ">
<div class="panel panel-info">
<div class="panel-heading">Kifizetve az adott időszakban</div>
<div class="panel-body">
<dl class="dl-horizontal dl-totals">
<?php
foreach ($searchModel->totalsPaidAt['accounts'] as $acc ){
?>
<dt><?php echo $acc['label'] ?></dt>
<dd class="text-right"><?php echo $acc['money'] ?></dd>
<?php
}
?>
<dt><?php echo Yii::t('frontend/transfer','Total') ?></dt>
<dd class="text-right"><?php echo $searchModel->totalsPaidAt['total'] ?></dd>
</dl>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-info">
<div class="panel-heading">Kiadva/fizetve az adott időszakban</div>
<div class="panel-body">
<dl class="dl-horizontal dl-totals">
<?php
foreach ($searchModel->totalsCreatedAtPaid['accounts'] as $acc ){
?>
<dt><?php echo $acc['label'] ?></dt>
<dd class="text-right"><?php echo $acc['money'] ?></dd>
<?php
}
?>
<dt><?php echo Yii::t('frontend/transfer','Total') ?></dt>
<dd class="text-right"><?php echo $searchModel->totalsCreatedAtPaid['total'] ?></dd>
</dl>
</div>
</div>
</div>
</div>
</div>

View File

@ -2,12 +2,20 @@
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\widgets\DatePicker;
use frontend\components\HtmlHelper;
use common\models\Transfer;
use kartik\widgets\DateTimePicker;
/* @var $this yii\web\View */
/* @var $model common\models\TransferSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<?php
$accountOptions = ['' =>'Mind']+ HtmlHelper::mkAccountOptions( $model->accounts );
?>
<div class="transfer-search">
<?php $form = ActiveForm::begin([
@ -18,28 +26,41 @@ use yii\widgets\ActiveForm;
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'start')->widget(DatePicker::classname(), [
<?= $form->field($model, 'start')->widget(DateTimePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
'format' => 'yyyy.mm.dd hh:ii'
]
]) ?>
</div>
<div class="col-md-4">
<?= $form->field($model, 'end') ->widget(DateTimePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd hh:ii'
]
]) ?>
</div>
</div>
<div class="row">
<div class="col-md-4">
<?= $form->field($model, 'end') ->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy.mm.dd'
]
]) ?>
<?= $form->field($model, 'id_account')->dropDownList($accountOptions) ?>
</div>
<div class="col-md-4">
<?php //echo $form->field($model, 'type')->dropDownList( ['' =>'Mind']+ Transfer::types()) ?>
<?php echo $form->field($model, 'types')->checkboxList( Transfer::types()) ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton(Yii::t('frontend/transfer', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('frontend/transfer', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
<?php
echo "types:";
print_r($model->types) ?>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,65 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model common\models\Transfer */
?>
<?php
$formatter = Yii::$app->formatter;
?>
<div class="row">
<div class="col-md-12">
<div class='row row-transfer'>
<div class='col-md-4'>
<dl class="dl-horizontal dl-transfer">
<dt><?php echo $model->getAttributeLabel( 'id_transfer') ?></dt>
<dd><?php echo ( Html::getAttributeValue($model, 'id_transfer') ) ?></dd>
<dt><?php echo $model->getAttributeLabel( 'created_at') ?></dt>
<dd><?php echo $formatter->asDatetime( Html::getAttributeValue($model, 'created_at') ) ?></dd>
<dt><?php echo $model->getAttributeLabel( 'paid_at') ?></dt>
<dd><?php echo $formatter->asDatetime( Html::getAttributeValue($model, 'paid_at') ) ?></dd>
<dt><?php echo $model->getAttributeLabel( 'status') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'statusName') ?></dd>
</dl>
</div>
<div class='col-md-4'>
<dl class="dl-horizontal dl-transfer">
<dt><?php echo $model->getAttributeLabel( 'type') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'transferTypeName') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'id_user') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'userName') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'id_customer') ?></dt>
<dd><?php echo Html::getAttributeValue($model, 'customerName') ?></dd>
</dl>
</div>
<div class='col-md-3'>
<dl class="dl-horizontal dl-transfer">
<dt><?php echo $model->getAttributeLabel( 'item_price') ?></dt>
<dd class="text-right"><?php echo Html::getAttributeValue($model, 'item_price') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'count') ?></dt>
<dd class="text-right"><?php echo Html::getAttributeValue($model, 'count') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'id_discount') ?></dt>
<dd class="text-right"><?php echo Html::getAttributeValue($model, 'discountName') ?></dd>
<dt><?php echo $model->getAttributeLabel( 'money') ?></dt>
<dd class="text-right"><?php echo Html::getAttributeValue($model, 'signedMoney') ?></dd>
</dl>
</div>
</div>
</div>
</div>

View File

@ -2,6 +2,8 @@
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\ListView;
use yii\base\Widget;
/* @var $this yii\web\View */
/* @var $searchModel common\models\TransferSearch */
@ -10,39 +12,38 @@ use yii\grid\GridView;
$this->title = Yii::t('frontend/transfer', 'Transfers');
$this->params['breadcrumbs'][] = $this->title;
?>
<style>
.dl-transfer{
margin-bottom: 0px;
}
.item-transfer{
border: 1px solid #b4b4b4;
margin-top: 12px;
padding-top: 6px;
padding-bottom: 6px;
}
</style>
<div class="transfer-index">
<h1><?= Html::encode($this->title) ?></h1>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
<?php echo $this->render('_index_stat', ['searchModel' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('frontend/transfer', 'Create Transfer'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id_transfer',
'id_discount',
'id_currency',
'id_object',
'status',
// 'type',
// 'item_price',
// 'count',
// 'money',
// 'money_currency',
// 'rate',
// 'id_user',
// 'comment',
// 'created_at',
// 'updated_at',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php echo ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => '_view' ,
'itemOptions' => ['class' => 'item-transfer']
] )
?>
</div>

View File

@ -14,35 +14,43 @@ $this->params['breadcrumbs'][] = $this->title;
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a(Yii::t('frontend/transfer', 'Update'), ['update', 'id' => $model->id_transfer], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('frontend/transfer', 'Delete'), ['delete', 'id' => $model->id_transfer], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('frontend/transfer', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id_transfer',
'id_discount',
'id_currency',
'id_object',
[
'attribute' => 'id_discount',
'value' => Html::getAttributeValue($model, 'discountName')
],
[
'attribute' => 'type',
'value' => $model->getTransferTypeName(),
'label' => 'Típus'
],
[
'attribute' => 'id_object',
'value' => $model->getObjectName(),
'label' => 'Megnevezés'
],
'status',
'type',
'item_price',
'count',
'money',
'money_currency',
'rate',
'id_user',
// 'money_currency',
// 'rate',
[
'attribute' => 'id_user',
'value' => $model->getUserName(),
// 'label' => 'Megnevezés'
],
'created_at:datetime',
'paid_at:datetime',
'comment',
'created_at',
'updated_at',
],
]) ?>

View File

@ -13,11 +13,11 @@ function ProductSell(o){
selector_user_cart: '.user-cart',
selector_btn_pay_customer_cart: '#btn_pay_customer_cart',
selector_btn_pay_user_cart: '#btn_pay_user_cart',
/**mark list paid url*/
url_pay_customer_card: '-',
url_pay_user_cart: '',
/** ajax url for lookup service*/
lookup_product_url: '',
/**mark list paid url*/
url_pay_user_cart: '',
/**the id of form*/
selector_form: '#product_form',
/**form contains error text*/
@ -289,7 +289,8 @@ function ProductSell(o){
table.find('.product-barcode').html(product.barcode);
table.find('.product-stock').html(product.stock);
$('#productsaleform-id_product').val(product.id_product);
$('#productsaleform-id_account').val(product.id_account);
if ( app.defaults.id_account == null)
$('#productsaleform-id_account').val(product.id_account);
}

View File

@ -35,7 +35,16 @@ function TicketSell(o){
price: null,
clear_cart_url: '',
cart_paid_message: 'Tételek fizetve',
transfer_list: [],
user_cart: [],
customer_cart: [],
/**selector for customer cart container*/
selector_customer_cart: '.customer-cart',
selector_user_cart: '.user-cart',
selector_btn_pay_customer_cart: '#btn_pay_customer_cart',
selector_btn_pay_user_cart: '#btn_pay_user_cart',
/**mark list paid url*/
url_pay_customer_card: '-',
url_pay_user_cart: '',
};
@ -45,8 +54,10 @@ function TicketSell(o){
$.extend(app.defaults, o );
addBehaviourTypeChangedListener();
useDefaults();
createUserSoldItemsTable();
addBehaviourBtnCartPaid();
createCarts();
addPayoutButtons();
addSellButtons();
// addBehaviourBtnCartPaid();
}
function useDefaults(){
@ -56,33 +67,100 @@ function TicketSell(o){
}
}
function createUserSoldItemsTable(){
$('.transfer-list-container').transferList({
'transfers' : app.defaults.transfer_list
////////////////////////////////////////
// carts
////////////////////////////////////////
/**
* payout out user or customer cart
* */
function addPayoutButtons(){
addBehaviourPayoutUserCart();
addBehaviourPayoutCustomerCart();
}
/**
* display user and customer cart on page load
* */
function createCarts(){
createUserCartTable();
createCustomerCartTable();
}
function createUserCartTable(){
$(app.defaults.selector_user_cart).transferList({
'transfers' : app.defaults.user_cart
});
}
function createCustomerCartTable(){
$(app.defaults.selector_customer_cart).transferList({
'transfers' : app.defaults.customer_cart
});
}
function refreshCart(){
$('.transfer-list-container').transferList('option','transfers' , app.defaults.sold_items );
function addSellButtons(){
addBehaviourBtnSellAndAppendToUserCart();
addBehaviourBtnAddToCustomerCart();
}
function addBehaviourBtnCartPaid( ){
$('#btn_paid').on('click',function(){
$.ajax({
url: app.defaults.clear_cart_url,
type: 'post',
data: {},
success: function (response) {
if ( response.code == 'success'){
app.defaults.sold_items= response.transfers;
refreshCart();
$.notify(app.defaults.cart_paid_message, { 'type' : 'success' });
}
}
}
);
});
function addBehaviourBtnSellAndAppendToUserCart(){
$('#btn_add_to_user_cart').on('click',submitAddTicketToUserCart);
}
function addBehaviourBtnAddToCustomerCart(){
$('#btn_add_to_customer_cart').on('click',submitAddTicketToCustomerCart);
}
function submitAddTicketToUserCart(){
$('#ticketcreate-cart').val('user');
$('#ticket_form').submit();
}
function submitAddTicketToCustomerCart(){
$('#ticketcreate-cart').val('customer');
$('#ticket_form').submit();
}
function addBehaviourPayoutUserCart( ){
// $( app.defaults.selector_btn_pay_user_cart ).on('click',function(){
//
// $.ajax({
// url: app.defaults.url_pay_user_cart,
// type: 'post',
// data: {},
// success: function (response) {
// if ( response.code == 'success'){
// app.defaults.user_cart = response.transfers;
// refreshUserCart();
// $.notify(app.defaults.message_paid, { 'type' : 'success' });
// }
// }
// }
// );
// });
}
function addBehaviourPayoutCustomerCart( ){
// $( app.defaults.selector_btn_pay_customer_cart ).on('click',function(){
// $.ajax({
// url: app.defaults.url_pay_customer_card,
// type: 'post',
// data: {},
// success: function (response) {
// if ( response.code == 'success'){
// app.defaults.customer_cart = response.customer_cart;
// refreshCustomerCart();
// }
// $.notify(response.message, { 'type' : response.code });
// },
// error: function(){
// alert('Hiba történt');
// }
// }
// );
// });
}