add transfer#list pdf download, fix helper#fixascii function
This commit is contained in:
@@ -68,7 +68,8 @@ class Card extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
public function validateAscii($attribute,$params){
|
||||
if ( !$this->hasErrors($this->$attribute)){
|
||||
$this->attribute = Helper::fixAsciiChars($this->attributes);
|
||||
$this->$attribute = Helper::fixAsciiChars($this->$attribute);
|
||||
Yii::info(" $attribute converted to: " . $this->$attribute);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,10 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
[['description'], 'string', 'max' => 255],
|
||||
[['product_number'], 'unique' ],
|
||||
[['barcode'], 'unique' ],
|
||||
// a1 and a2 need to be unique together, only a1 will receive error message
|
||||
// ['a1', 'unique', 'targetAttribute' => ['a1', 'a2']]
|
||||
['barcode', 'unique', 'targetAttribute' => ['id_account', 'barcode']],
|
||||
['product_number', 'unique', 'targetAttribute' => ['id_account', 'product_number']],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -143,13 +147,13 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
|
||||
if ( $forceIncludeObjectWithId == null){
|
||||
$query = Product::find()->andWhere(['status' => Product::STATUS_ACTIVE])->orderBy(['product.name' => SORT_ASC]);
|
||||
if ( $account )
|
||||
if ( Helper::isProductVisibilityAccount() && $account )
|
||||
$query->andWhere(["product.id_account" => $account]);
|
||||
|
||||
$result = $query->all();
|
||||
}else{
|
||||
$query = Product::find()->andWhere( ['or', ['status' => Product::STATUS_ACTIVE], ['id_product' => $forceIncludeObjectWithId ] ])->orderBy(['product.name' => SORT_ASC]);
|
||||
if ( $account )
|
||||
if ( Helper::isProductVisibilityAccount() && $account )
|
||||
$query->andWhere(["product.id_account" => $account]);
|
||||
|
||||
$result = $query->all();
|
||||
@@ -163,16 +167,20 @@ class Product extends \common\models\BaseFitnessActiveRecord {
|
||||
$result = [];
|
||||
$product = null;
|
||||
|
||||
$products = Product::find()
|
||||
$query = Product::find()
|
||||
->andWhere(
|
||||
['or',
|
||||
['product_number' => $query ],
|
||||
['barcode' => $query ],
|
||||
]
|
||||
)->andWhere(['status' =>Product::STATUS_ACTIVE])
|
||||
->andFilterWhere(['product.id_account' => $account])
|
||||
->all();
|
||||
)->andWhere(['status' =>Product::STATUS_ACTIVE]);
|
||||
|
||||
if ( Helper::isProductVisibilityAccount() && $account ){
|
||||
$query->andFilterWhere(['product.id_account' => $account]);
|
||||
}
|
||||
|
||||
|
||||
$products = $query->all();
|
||||
|
||||
if ( count($products) == 1 ){
|
||||
$product = $products[0];
|
||||
|
||||
@@ -722,4 +722,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
return $query->scalar();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,12 +13,15 @@ use common\models\Account;
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\models\MoneyMovement;
|
||||
use common\components\RoleDefinition;
|
||||
/**
|
||||
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
|
||||
* TransferListSearch represents the model behind the search form about `common\models\Transfer`.
|
||||
*/
|
||||
class TransferListSearch extends Transfer
|
||||
{
|
||||
|
||||
public $mode = "reception";//reception or admin
|
||||
|
||||
public $start;
|
||||
public $end;
|
||||
|
||||
@@ -51,6 +54,10 @@ class TransferListSearch extends Transfer
|
||||
* all money gained with product sell
|
||||
* */
|
||||
public $productMoney;
|
||||
/**
|
||||
* all money gained with product sell
|
||||
* */
|
||||
public $productMoneyNetto;
|
||||
/**
|
||||
* all money gained with product sell grouped by category
|
||||
* */
|
||||
@@ -61,9 +68,13 @@ class TransferListSearch extends Transfer
|
||||
public $moneyMovementMoneis;
|
||||
public $moneyMovementMoney;
|
||||
/**
|
||||
* total gained money
|
||||
* total gained money brutto
|
||||
* */
|
||||
public $total;
|
||||
/**
|
||||
* total gained money netto
|
||||
* */
|
||||
public $totalNetto;
|
||||
|
||||
/**
|
||||
* ticket sale statisitc
|
||||
@@ -84,6 +95,13 @@ class TransferListSearch extends Transfer
|
||||
|
||||
public $productsByCategory;
|
||||
|
||||
public $currentUser;
|
||||
public $currentAccount;
|
||||
|
||||
public $output;
|
||||
|
||||
public $outputView;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -97,11 +115,16 @@ class TransferListSearch extends Transfer
|
||||
|
||||
[ [ 'id_account','id_user' ] , 'integer'],
|
||||
['types', 'each', 'rule' => ['integer']],
|
||||
['output', 'safe' ],
|
||||
['outputView', 'safe' ],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function isModeAdmin(){
|
||||
return $this->mode == 'admin';
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
@@ -126,7 +149,6 @@ class TransferListSearch extends Transfer
|
||||
}
|
||||
|
||||
|
||||
|
||||
$this->readTicketMoney();
|
||||
$this->readProductsMoney();
|
||||
$this->readMoneyMovementMoney();
|
||||
@@ -142,6 +164,19 @@ class TransferListSearch extends Transfer
|
||||
$this->readProducts();
|
||||
$this->readMoneyMovements();
|
||||
|
||||
if ( $this->isModeAdmin() && RoleDefinition::isAdmin()){
|
||||
|
||||
if ( $this->id_user){
|
||||
$this->currentUser = User::findOne($this->id_user);
|
||||
}
|
||||
if ( $this->id_account){
|
||||
$this->currentAccount = Account::findOne($this->id_account);
|
||||
}
|
||||
|
||||
$this->readProductsMoneyNetto();
|
||||
$this->calcTotalNetto();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function calcTotal(){
|
||||
@@ -150,18 +185,33 @@ class TransferListSearch extends Transfer
|
||||
$this->total += $this->productMoney;
|
||||
$this->total += $this->moneyMovementMoneis;
|
||||
}
|
||||
protected function calcTotalNetto(){
|
||||
$this->totalNetto = 0;
|
||||
$this->totalNetto += $this->ticketMoney;
|
||||
$this->totalNetto += $this->productMoneyNetto;
|
||||
$this->totalNetto += $this->moneyMovementMoneis;
|
||||
}
|
||||
|
||||
|
||||
protected function addAccountConstraint($query){
|
||||
$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->andWhere(['transfer.id_user' => Yii::$app->user->id ]);
|
||||
|
||||
$query->andWhere(['account.type' => Account::TYPE_ALL ]);
|
||||
if (!$this->isModeAdmin() || !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 ]);
|
||||
|
||||
if ( RoleDefinition::isReception() || !$this->isModeAdmin()){
|
||||
$query->andWhere(['transfer.id_user' => Yii::$app->user->id ]);
|
||||
}
|
||||
|
||||
|
||||
$query->andWhere(['account.type' => Account::TYPE_ALL ]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* add common transfer conditions.
|
||||
* mode and role will be used to build to correct condition
|
||||
* */
|
||||
protected function addQueryFilters($query){
|
||||
$query->innerJoin("account", "transfer.id_account = account.id_account");
|
||||
|
||||
@@ -179,7 +229,7 @@ class TransferListSearch extends Transfer
|
||||
|
||||
|
||||
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
|
||||
|
||||
|
||||
$query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);
|
||||
|
||||
}
|
||||
@@ -195,6 +245,7 @@ class TransferListSearch extends Transfer
|
||||
$query->innerJoin("ticket_type", "ticket.id_ticket_type = ticket_type.id_ticket_type");
|
||||
|
||||
$query->groupBy(['ticket_type.id_ticket_type','ticket_type.name']);
|
||||
$query->orderBy(['ticket_type.name' => SORT_ASC]);
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
|
||||
@@ -298,6 +349,20 @@ class TransferListSearch extends Transfer
|
||||
$this->productMoney = $query->scalar();
|
||||
|
||||
}
|
||||
protected function readProductsMoneyNetto(){
|
||||
|
||||
|
||||
$query = (new \yii\db\Query());
|
||||
$query->select(['coalesce(sum(transfer.count * GREATEST(( product.sale_price - coalesce(product.purchase_price,0)),0)),0) AS product_money' ]);
|
||||
$query->from('transfer');
|
||||
$query->andWhere(['transfer.type' => Transfer::TYPE_PRODUCT]);
|
||||
$query->innerJoin("sale", "sale.id_sale = transfer.id_object");
|
||||
$query->innerJoin("product", "sale.id_product = product.id_product");
|
||||
$this->addQueryFilters($query);
|
||||
|
||||
$this->productMoneyNetto = $query->scalar();
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected function readMoneyMovementMoney(){
|
||||
|
||||
@@ -13,12 +13,15 @@ use common\models\Account;
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\models\MoneyMovement;
|
||||
use common\components\RoleDefinition;
|
||||
/**
|
||||
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
|
||||
*/
|
||||
class TransferSaleSearch extends Transfer
|
||||
{
|
||||
|
||||
public $mode = "reception";//reception or admin
|
||||
|
||||
public $start;
|
||||
public $end;
|
||||
|
||||
@@ -84,6 +87,10 @@ class TransferSaleSearch extends Transfer
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function isModeAdmin(){
|
||||
return $this->mode == 'admin';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
@@ -113,8 +120,6 @@ class TransferSaleSearch extends Transfer
|
||||
$this->readProductsMoney();
|
||||
$this->calcTotal();
|
||||
|
||||
// $this->readProductsByCategory();
|
||||
// $this->readProductsByCategoryDetailed();
|
||||
|
||||
|
||||
$this->readProducts();
|
||||
@@ -128,12 +133,18 @@ class TransferSaleSearch extends Transfer
|
||||
|
||||
|
||||
protected function addAccountConstraint($query){
|
||||
|
||||
if ( !$this->isModeAdmin() || !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->andWhere(['transfer.id_user' => Yii::$app->user->id ]);
|
||||
if ( RoleDefinition::isReception()){
|
||||
$query->andWhere(['transfer.id_user' => Yii::$app->user->id ]);
|
||||
}
|
||||
|
||||
$query->andWhere(['account.type' => Account::TYPE_ALL ]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use common\models\Account;
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
use common\models\MoneyMovement;
|
||||
use common\components\RoleDefinition;
|
||||
/**
|
||||
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
|
||||
*/
|
||||
@@ -135,7 +136,9 @@ class TransferTicketSearch extends Transfer
|
||||
$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->andWhere(['transfer.id_user' => Yii::$app->user->id ]);
|
||||
if ( RoleDefinition::isReception()){
|
||||
$query->andWhere(['transfer.id_user' => Yii::$app->user->id ]);
|
||||
}
|
||||
|
||||
$query->andWhere(['account.type' => Account::TYPE_ALL ]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user