add non cash money display to account state
This commit is contained in:
@@ -14,6 +14,7 @@ use yii\db\Query;
|
||||
use yii\db\Expression;
|
||||
use common\components\RoleDefinition;
|
||||
use common\components\Helper;
|
||||
use yii\web\NotAcceptableHttpException;
|
||||
|
||||
/**
|
||||
* This is the model class for table "transfer".
|
||||
@@ -37,6 +38,8 @@ use common\components\Helper;
|
||||
* @property integer $direction
|
||||
* @property string $paid_at
|
||||
* @property integer $id_customer
|
||||
* @property int|string paid_by
|
||||
* @property int payment_method
|
||||
*/
|
||||
class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
const TYPE_PRODUCT = 10;
|
||||
@@ -205,7 +208,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
}
|
||||
public function getPaidByName() {
|
||||
$result = "";
|
||||
$user = $this->paidByUser;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$user = $this->paidByUser;
|
||||
if (isset ( $this->paidByUser )) {
|
||||
$result = $user->username;
|
||||
}
|
||||
@@ -215,17 +219,21 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
public function getObjectName() {
|
||||
$result = "";
|
||||
if ($this->type == Transfer::TYPE_TICKET) {
|
||||
$result = $this->ticketName;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$result = $this->ticketName;
|
||||
} else if ($this->type == Transfer::TYPE_PRODUCT) {
|
||||
$result = $this->productName;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$result = $this->productName;
|
||||
} else if ($this->type == Transfer::TYPE_MONEY_MOVEMENT_OUT) {
|
||||
$result = $this->moneyMovement->humanType;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$result = $this->moneyMovement->humanType;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
public function getUserName() {
|
||||
$result = "";
|
||||
$user = $this->user;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$user = $this->user;
|
||||
if (isset ( $this->user )) {
|
||||
$result = $user->username;
|
||||
}
|
||||
@@ -234,7 +242,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
}
|
||||
public function getProductName() {
|
||||
$result = "";
|
||||
$product = $this->product;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$product = $this->product;
|
||||
if (isset ( $product )) {
|
||||
$result = $product->name;
|
||||
}
|
||||
@@ -243,16 +252,20 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
}
|
||||
public function getTicketName() {
|
||||
$result = "";
|
||||
$ticket = $this->ticket;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
/** @var \common\models\Ticket $ticket */
|
||||
$ticket = $this->ticket;
|
||||
if (isset ( $ticket )) {
|
||||
$result = $this->ticket->ticketTypeName;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$result = $this->ticket->ticketTypeName;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
public function getAccountName() {
|
||||
$result = "";
|
||||
$account = $this->account;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$account = $this->account;
|
||||
if (isset ( $account )) {
|
||||
$result = $account->name;
|
||||
}
|
||||
@@ -272,7 +285,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
}
|
||||
public function getSaleName() {
|
||||
$result = "";
|
||||
$sale = $this->sale;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$sale = $this->sale;
|
||||
if (isset ( $sale )) {
|
||||
$result = $sale->name;
|
||||
}
|
||||
@@ -305,22 +319,27 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
|
||||
$s .= $this->count;
|
||||
$s .= " " . Yii::t ( 'frontend/transfer', 'pieces' ) . " ";
|
||||
$s .= $this->product->name;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$s .= $this->product->name;
|
||||
$s .= " - ";
|
||||
$s .= $this->account->name;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$s .= $this->account->name;
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $account common\models\Account
|
||||
* @param $discount common\models\Discount
|
||||
* @param $currency common\models\Currency
|
||||
* @param $product common\models\Product
|
||||
* @param $customer common\models\Customer
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $sale
|
||||
* @param $account \common\models\Account
|
||||
* @param $discount \common\models\Discount
|
||||
* @param $currency \common\models\Currency
|
||||
* @param $count
|
||||
* @param $product \common\models\Product
|
||||
* @param int $status
|
||||
* @param $customer \common\models\Customer
|
||||
* @return Transfer
|
||||
*/
|
||||
public static function createProductTransfer($sale, $account, $discount, $currency, $count, $product, $status = Transfer::STATUS_PAID, $customer = null) {
|
||||
$transfer = new Transfer ();
|
||||
|
||||
@@ -333,8 +352,9 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
|
||||
$transfer->count = $count;
|
||||
$totalPrice = $totalPrice * $count;
|
||||
|
||||
if (isset ( $discount )) {
|
||||
|
||||
/** @var \common\models\Discount $discount */
|
||||
if (isset ( $discount )) {
|
||||
$transfer->id_discount = $discount->id_discount;
|
||||
$totalPrice = Discount::applyDiscount ( $totalPrice, $discount );
|
||||
}
|
||||
@@ -357,15 +377,15 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
|
||||
return $transfer;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $account common\models\Account
|
||||
* @param $discount common\models\Discount
|
||||
* @param $currency common\models\Currency
|
||||
* @param $moneyMovement common\models\MoneyMovement
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $account \common\models\Account
|
||||
* @param $moneyMovement \common\models\MoneyMovement
|
||||
* @return Transfer
|
||||
* @internal param Discount $discount
|
||||
* @internal param Currency $currency
|
||||
*/
|
||||
public static function createMoneyMovementOutTransfer($account, $moneyMovement) {
|
||||
$transfer = new Transfer ();
|
||||
$transfer->payment_method = Transfer::PAYMENT_METHOD_CASH;
|
||||
@@ -388,14 +408,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
|
||||
return $transfer;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param $account common\models\Account
|
||||
* @param $discount common\models\Discount
|
||||
* @param $currency common\models\Currency
|
||||
* @param $ticket common\models\Ticket
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param $account \common\models\Account
|
||||
* @param $discount \common\models\Discount
|
||||
* @param $currency \common\models\Currency
|
||||
* @param $count int
|
||||
* @param $ticket \common\models\Ticket
|
||||
*
|
||||
* @param int $status
|
||||
* @return Transfer
|
||||
*/
|
||||
public static function createTicketTransfer($account, $discount, $currency, $count, $ticket, $status = Transfer::STATUS_NOT_PAID) {
|
||||
$transfer = new Transfer ();
|
||||
|
||||
@@ -412,15 +436,17 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
$totalPrice = $totalPrice * $count;
|
||||
|
||||
if (isset ( $discount )) {
|
||||
/** @var \common\models\Discount $discount */
|
||||
$transfer->id_discount = $discount->id_discount;
|
||||
$totalPrice = Discount::applyDiscount ( $totalPrice, $discount );
|
||||
$totalPrice = Discount::applyDiscount ( $totalPrice, $discount );
|
||||
}
|
||||
|
||||
$transfer->money = $totalPrice;
|
||||
|
||||
if (isset ( $currency )) {
|
||||
$transfer->rate = $currency->rate;
|
||||
$transfer->money_currency = Currency::applyCurrency ( $totalPrice, $currency );
|
||||
/** @var \common\models\Currency $currency */
|
||||
$transfer->money_currency = Currency::applyCurrency ( $totalPrice, $currency );
|
||||
}
|
||||
|
||||
$transfer->id_account = $account->id_account;
|
||||
@@ -464,6 +490,7 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
} else if ($transfer->type == Transfer::TYPE_MONEY_MOVEMENT_OUT) {
|
||||
return "Pénzmozgás";
|
||||
}
|
||||
return "-";
|
||||
}
|
||||
]
|
||||
] );
|
||||
@@ -490,8 +517,6 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
return $result;
|
||||
}
|
||||
public static function readUserSoldTransfers($user) {
|
||||
$transfers = [ ];
|
||||
|
||||
$query = Transfer::find ();
|
||||
$query->innerJoin ( "user_sold_item", "user_sold_item.id_transfer = transfer.id_transfer" );
|
||||
|
||||
@@ -501,9 +526,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
'user_sold_item.id_user' => $user->id
|
||||
] );
|
||||
}
|
||||
$transfers = $query->all ();
|
||||
return $query->all ();
|
||||
|
||||
return $transfers;
|
||||
}
|
||||
public static function readCustomerCart($customer) {
|
||||
$transfers = [ ];
|
||||
@@ -573,16 +597,20 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
public function beforeDelete() {
|
||||
parent::beforeDelete ();
|
||||
if ($this->type == Transfer::TYPE_TICKET) {
|
||||
$ticket = $this->ticket;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$ticket = $this->ticket;
|
||||
if ($ticket != null) {
|
||||
$ticket->delete ();
|
||||
}
|
||||
} else if ($this->type == Transfer::TYPE_MONEY_MOVEMENT_OUT) {
|
||||
$mm = $this->moneyMovement;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$mm = $this->moneyMovement;
|
||||
$mm->delete ();
|
||||
} else if ($this->type == Transfer::TYPE_PRODUCT) {
|
||||
$sale = $this->sale;
|
||||
$product = $this->product;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$sale = $this->sale;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$product = $this->product;
|
||||
|
||||
$product->stock = $product->stock + $this->count;
|
||||
|
||||
@@ -599,39 +627,45 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $mode
|
||||
* The mode to load
|
||||
* Available modes
|
||||
* <ul>
|
||||
* <li>
|
||||
* <h2>created_at</h2>
|
||||
* <p>Load all transfer which were created </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>paid_at</h2>
|
||||
* <p>Load all transfer which were paid </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>created_at_paid</h2>
|
||||
* <p>Load all transfer which were created and paid </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>created_at_not_paid</h2>
|
||||
* <p>Load all transfer which were created but not paid </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>paid_at_not_created_at</h2>
|
||||
* <p>Load all transfer which were not created but paid . Works correctly only,
|
||||
* when start and end date given
|
||||
* </p>
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $mode
|
||||
* The mode to load
|
||||
* Available modes
|
||||
* <ul>
|
||||
* <li>
|
||||
* <h2>created_at</h2>
|
||||
* <p>Load all transfer which were created </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>paid_at</h2>
|
||||
* <p>Load all transfer which were paid </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>created_at_paid</h2>
|
||||
* <p>Load all transfer which were created and paid </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>created_at_not_paid</h2>
|
||||
* <p>Load all transfer which were created but not paid </p>
|
||||
* </li>
|
||||
* <li>
|
||||
* <h2>paid_at_not_created_at</h2>
|
||||
* <p>Load all transfer which were not created but paid . Works correctly only,
|
||||
* when start and end date given
|
||||
* </p>
|
||||
* </li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* @param $start
|
||||
* @param $end
|
||||
* @param $idUser
|
||||
* @param $types
|
||||
* @param $idAccount
|
||||
* @return Query
|
||||
*/
|
||||
public static function mkTotalQuery($mode, $start, $end, $idUser, $types, $idAccount) {
|
||||
$query = new Query ();
|
||||
|
||||
@@ -698,7 +732,14 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
|
||||
return $query;
|
||||
}
|
||||
public static function notInInterval($query, $field, $start, $end) {
|
||||
|
||||
/**
|
||||
* @param \yii\db\Query $query
|
||||
* @param string $field
|
||||
* @param string $start
|
||||
* @param string $end
|
||||
*/
|
||||
public static function notInInterval($query, $field, $start, $end) {
|
||||
$query->andFilterWhere ( [
|
||||
'or',
|
||||
[
|
||||
@@ -713,7 +754,14 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
]
|
||||
] );
|
||||
}
|
||||
public static function notPaid($query, $field, $start, $end) {
|
||||
|
||||
/**
|
||||
* @param \yii\db\Query $query
|
||||
* @param string $field
|
||||
* @param string $start
|
||||
* @param string $end
|
||||
*/
|
||||
public static function notPaid($query, $field, $start, $end) {
|
||||
$query->andFilterWhere ( [
|
||||
'or',
|
||||
[
|
||||
@@ -731,7 +779,14 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
]
|
||||
] );
|
||||
}
|
||||
public static function inInterval($query, $field, $start, $end) {
|
||||
|
||||
/**
|
||||
* @param \yii\db\Query $query
|
||||
* @param string $field
|
||||
* @param string $start
|
||||
* @param string $end
|
||||
*/
|
||||
public static function inInterval($query, $field, $start, $end) {
|
||||
$query->andFilterWhere ( [
|
||||
'>=',
|
||||
$field,
|
||||
@@ -743,15 +798,19 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
$end
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Parse query results so, that all available account will be display, even then , if $queryResult does not contain any result for the given account
|
||||
*
|
||||
* @param mixed $queryResult
|
||||
* an array, wchic contains items. each item has to key - value pairs: [ id_account => 0, money => 0 ]
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parse query results so, that all available account will be display, even then , if $queryResult does not contain any result for the given account
|
||||
*
|
||||
* @param mixed $queryResult
|
||||
* an array, wchic contains items. each item has to key - value pairs: [ id_account => 0, money => 0 ]
|
||||
*
|
||||
* @param $accounts
|
||||
* @param $accountMap
|
||||
* @param $idAccount
|
||||
* @return array
|
||||
*/
|
||||
public static function mkTotalsResultWithAllAvailableAccount($queryResult, $accounts, $accountMap, $idAccount) {
|
||||
$totals = [ ];
|
||||
$totals ['total'] = 0;
|
||||
@@ -789,22 +848,38 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* create and execute a "total" query
|
||||
*/
|
||||
|
||||
/**
|
||||
* create and execute a "total" query
|
||||
* @param $mode
|
||||
* @param $start
|
||||
* @param $end
|
||||
* @param $idUser
|
||||
* @param $types
|
||||
* @param $idAccount
|
||||
* @return array
|
||||
*/
|
||||
public static function exTotalQuery($mode, $start, $end, $idUser, $types, $idAccount) {
|
||||
$query = self::mkTotalQuery ( $mode, $start, $end, $idUser, $types, $idAccount );
|
||||
$command = $query->createCommand ();
|
||||
$result = $command->queryAll ();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* find all transfers which were paid in the period
|
||||
*/
|
||||
|
||||
/**
|
||||
* find all transfers which were paid in the period
|
||||
* @param $start
|
||||
* @param $end
|
||||
* @param $idUser
|
||||
* @param $types
|
||||
* @param $idAccount
|
||||
* @param $accounts
|
||||
* @param $accountMap
|
||||
* @return array
|
||||
*/
|
||||
public static function mkPaidAtTotals($start, $end, $idUser, $types, $idAccount, $accounts, $accountMap) {
|
||||
$result = [ ];
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
$result = [ ];
|
||||
$queryResult = self::exTotalQuery ( 'paid_at', $start, $end, $idUser, $types, $idAccount );
|
||||
$result = self::mkTotalsResultWithAllAvailableAccount ( $queryResult, $accounts, $accountMap, $idAccount );
|
||||
return $result;
|
||||
@@ -814,7 +889,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
* find all transfers in the period ( doesn't matter if paid or not )
|
||||
*/
|
||||
public static function mkCreatedAtTotals($start, $end, $idUser, $types, $idAccount, $accounts, $accountMap) {
|
||||
$result = [ ];
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
$result = [ ];
|
||||
$queryResult = self::exTotalQuery ( 'created_at', $start, $end, $idUser, $types, $idAccount );
|
||||
$result = self::mkTotalsResultWithAllAvailableAccount ( $queryResult, $accounts, $accountMap, $idAccount );
|
||||
return $result;
|
||||
@@ -824,7 +900,8 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
* find transfers which were created but not paid in the period
|
||||
*/
|
||||
public static function mkCreatedAtNotPaidTotals($start, $end, $idUser, $types, $idAccount, $accounts, $accountMap) {
|
||||
$result = [ ];
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
$result = [ ];
|
||||
$queryResult = self::exTotalQuery ( 'created_at_not_paid', $start, $end, $idUser, $types, $idAccount );
|
||||
$result = self::mkTotalsResultWithAllAvailableAccount ( $queryResult, $accounts, $accountMap, $idAccount );
|
||||
return $result;
|
||||
@@ -834,17 +911,27 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
* find transfers which were created and paid in the period
|
||||
*/
|
||||
public static function mkCreatedAtPaidTotals($start, $end, $idUser, $types, $idAccount, $accounts, $accountMap) {
|
||||
$result = [ ];
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
$result = [ ];
|
||||
$queryResult = self::exTotalQuery ( 'created_at_paid', $start, $end, $idUser, $types, $idAccount );
|
||||
$result = self::mkTotalsResultWithAllAvailableAccount ( $queryResult, $accounts, $accountMap, $idAccount );
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* find transfers, where depth was paid
|
||||
*/
|
||||
|
||||
/**
|
||||
* find transfers, where depth was paid
|
||||
* @param $start
|
||||
* @param $end
|
||||
* @param $idUser
|
||||
* @param $types
|
||||
* @param $idAccount
|
||||
* @param $accounts
|
||||
* @param $accountMap
|
||||
* @return array
|
||||
*/
|
||||
public static function mkPaidAtNotCreatedAtPaidTotals($start, $end, $idUser, $types, $idAccount, $accounts, $accountMap) {
|
||||
$result = [ ];
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
$result = [ ];
|
||||
$queryResult = self::exTotalQuery ( 'paid_at_not_created_at', $start, $end, $idUser, $types, $idAccount );
|
||||
$result = self::mkTotalsResultWithAllAvailableAccount ( $queryResult, $accounts, $accountMap, $idAccount );
|
||||
return $result;
|
||||
@@ -860,17 +947,21 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ezt a függvényt használjuk a zárások összegének kiszámolására!
|
||||
* A számolás csak a következő feltételekkel bíró tranzakciókat
|
||||
* tartalmazza:
|
||||
* - trazakció típus: common\models\Account::TYPE_ALL
|
||||
* - tranzakció fizetési módja: készpénz
|
||||
* - tranzakció státusza: fizetve
|
||||
* -
|
||||
*/
|
||||
public static function readPaid($start, $end, $idUser) {
|
||||
|
||||
/**
|
||||
* Ezt a függvényt használjuk a zárások összegének kiszámolására!
|
||||
* A számolás csak a következő feltételekkel bíró tranzakciókat
|
||||
* tartalmazza:
|
||||
* - trazakció típus: common\models\Account::TYPE_ALL
|
||||
* - tranzakció fizetési módja: készpénz
|
||||
* - tranzakció státusza: fizetve
|
||||
* -
|
||||
* @param $start
|
||||
* @param $end
|
||||
* @param $idUser
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function readPaidCash($start, $end, $idUser) {
|
||||
$query = (new \yii\db\Query ());
|
||||
$query->select ( [
|
||||
'coalesce(sum( case when transfer.direction = ' . Transfer::DIRECTION_IN . ' then transfer.money else -1 * transfer.money end ),0) AS transfer_money'
|
||||
@@ -880,51 +971,35 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
$query->andWhere ( [
|
||||
'transfer.paid_by' => $idUser
|
||||
] );
|
||||
|
||||
$created_condition = [
|
||||
|
||||
$created_condition = [
|
||||
'and',
|
||||
[
|
||||
'>=',
|
||||
'transfer.created_at',
|
||||
$start
|
||||
],
|
||||
[
|
||||
'<',
|
||||
'transfer.created_at',
|
||||
$end
|
||||
]
|
||||
[ '>=', 'transfer.created_at', $start ],
|
||||
[ '<', 'transfer.created_at', $end ]
|
||||
];
|
||||
$paid_condition = [
|
||||
|
||||
$paid_condition = [
|
||||
'and',
|
||||
[
|
||||
'>=',
|
||||
'transfer.paid_at',
|
||||
$start
|
||||
],
|
||||
[
|
||||
'<',
|
||||
'transfer.paid_at',
|
||||
$end
|
||||
]
|
||||
[ '>=', 'transfer.paid_at', $start ],
|
||||
[ '<', 'transfer.paid_at', $end ]
|
||||
];
|
||||
|
||||
$query->andFilterWhere ( [
|
||||
|
||||
$query->andFilterWhere ( [
|
||||
'or',
|
||||
$created_condition,
|
||||
$paid_condition
|
||||
] );
|
||||
$query->andWhere ( [
|
||||
'transfer.status' => Transfer::STATUS_PAID
|
||||
|
||||
$query->andWhere ( [
|
||||
'transfer.status' => Transfer::STATUS_PAID,
|
||||
'account.type' => Account::TYPE_ALL ,
|
||||
'transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH
|
||||
] );
|
||||
$query->andWhere ( [
|
||||
'account.type' => Account::TYPE_ALL
|
||||
] );
|
||||
$query->andWhere ( [
|
||||
'transfer.payment_method' => Transfer::PAYMENT_METHOD_CASH
|
||||
] );
|
||||
|
||||
return $query->scalar ();
|
||||
|
||||
return $query->scalar ();
|
||||
}
|
||||
|
||||
|
||||
public function storno() {
|
||||
$this->status = Transfer::STATUS_STORNO;
|
||||
$this->save ( false );
|
||||
@@ -944,14 +1019,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
|
||||
// storno contract
|
||||
} else if ($this->type == Transfer::TYPE_PRODUCT) {
|
||||
$sale = $this->sale;
|
||||
$product = $this->sale->product;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$sale = $this->sale;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
/** @var \common\models\Product $product */
|
||||
$product = $this->sale->product;
|
||||
$product->stock = $product->stock + $this->count;
|
||||
$product->save ( false );
|
||||
$sale->status = Sale::STATUS_DELETED;
|
||||
$sale->save ( false );
|
||||
} else if ($this->type == Transfer::TYPE_MONEY_MOVEMENT_OUT) {
|
||||
$mm = $this->moneyMovement;
|
||||
/** @noinspection PhpUndefinedFieldInspection */
|
||||
$mm = $this->moneyMovement;
|
||||
$mm->status = MoneyMovement::STATUS_STORNO;
|
||||
$mm->save ( false );
|
||||
}
|
||||
@@ -963,7 +1042,11 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
'id_transfer' => $this->id_transfer
|
||||
] );
|
||||
}
|
||||
public function unstorono() {
|
||||
|
||||
/**
|
||||
* @throws \yii\web\NotAcceptableHttpException
|
||||
*/
|
||||
public function unstorono() {
|
||||
if ($this->type != Transfer::TYPE_TICKET) {
|
||||
throw new NotAcceptableHttpException ( "Csak bérletet lehet visszaállítani" );
|
||||
}
|
||||
@@ -989,7 +1072,52 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
|
||||
$item->id_transfer = $this->id_transfer;
|
||||
$item->save ( false );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $start $start date
|
||||
* @param $end $end date
|
||||
* @param $idUser $user
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function readPaidNonCash($start, $end, $idUser) {
|
||||
$query = (new Query());
|
||||
$query->select ( [
|
||||
'coalesce(sum( case when transfer.direction = ' . Transfer::DIRECTION_IN . ' then transfer.money else -1 * transfer.money end ),0) AS transfer_money'
|
||||
] );
|
||||
$query->from ( 'transfer' );
|
||||
$query->innerJoin ( "account", "account.id_account = transfer.id_account" );
|
||||
$query->andWhere ( [
|
||||
'transfer.paid_by' => $idUser
|
||||
] );
|
||||
|
||||
$created_condition = [
|
||||
'and',
|
||||
[ '>=', 'transfer.created_at', $start ],
|
||||
[ '<', 'transfer.created_at', $end ]
|
||||
];
|
||||
|
||||
$paid_condition = [
|
||||
'and',
|
||||
[ '>=', 'transfer.paid_at', $start ],
|
||||
[ '<', 'transfer.paid_at', $end ]
|
||||
];
|
||||
|
||||
$query->andFilterWhere ( [
|
||||
'or',
|
||||
$created_condition,
|
||||
$paid_condition
|
||||
] );
|
||||
|
||||
$query->andWhere ( [
|
||||
'transfer.status' => Transfer::STATUS_PAID,
|
||||
'account.type' => Account::TYPE_ALL
|
||||
] );
|
||||
|
||||
$query->andWhere(['<>' ,'transfer.payment_method', Transfer::PAYMENT_METHOD_CASH ]);
|
||||
|
||||
return $query->scalar ();
|
||||
}
|
||||
|
||||
|
||||
public function payout($id_account = null) {
|
||||
|
||||
Reference in New Issue
Block a user