add transfer#list pdf download, fix helper#fixascii function
This commit is contained in:
@@ -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(){
|
||||
|
||||
Reference in New Issue
Block a user