add feature payout_later
This commit is contained in:
@@ -25,16 +25,21 @@ class TransferLaterSearch extends Transfer
|
||||
public $timestampStart;
|
||||
public $timestampEnd;
|
||||
|
||||
public $id_ticket_type;
|
||||
|
||||
|
||||
public $ticket_type;
|
||||
public $selected = [];
|
||||
|
||||
public $total_money;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[[ 'id_account','id_user', 'type','status','payment_method'], 'integer'],
|
||||
[[ 'id_ticket_type','id_user'], 'integer'],
|
||||
[[ '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' ],
|
||||
['selected', 'each', 'rule' => ['integer']],
|
||||
@@ -118,23 +123,21 @@ class TransferLaterSearch extends Transfer
|
||||
}
|
||||
|
||||
|
||||
$query->andFilterWhere([
|
||||
'transfer.id_account' => $this->id_account,
|
||||
'transfer.type' => $this->type,
|
||||
'transfer.id_user' => $this->id_user,
|
||||
'transfer.status' => $this->status,
|
||||
'transfer.payment_method' => $this->payment_method,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere([
|
||||
'ticket_type.id_ticket_type' => $this->id_ticket_type,
|
||||
'transfer.id_user' => $this->id_user,
|
||||
]);
|
||||
|
||||
$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]);
|
||||
|
||||
if (!RoleDefinition::isAdmin()){
|
||||
Helper::restrictIfNotAdminTheStartDate($query, $this->timestampStart,['transfer.created_at','transfer.paid_at']);
|
||||
}
|
||||
$qtotal = Query::create($query);
|
||||
$qtotal->select([ new Expression("coalesce(sum(transfer.money),0) as transfer_money" )]);
|
||||
$this->total_money = $qtotal->scalar();
|
||||
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
@@ -148,6 +151,45 @@ class TransferLaterSearch extends Transfer
|
||||
}
|
||||
|
||||
|
||||
public function doPayout(){
|
||||
|
||||
if ( !isset($this->selected) || count($this->selected) == 0){
|
||||
Helper::flash("error", "Nincs kiválasztott tranzakció");
|
||||
return false;
|
||||
}
|
||||
|
||||
$transfers = Transfer::find()
|
||||
->andWhere(['status' => Transfer::STATUS_NOT_PAID ])
|
||||
->andWhere(['payment_method' => Transfer::PAYMENT_METHOD_TRANSFER_LATER])
|
||||
->andWhere(['in','transfer.id_transfer',$this->selected])
|
||||
->all();
|
||||
|
||||
if ( count($transfers) != count($this->selected)){
|
||||
Helper::flash("warning", "A kiválasztott tranzakciókban időközben változás történt");
|
||||
return false;
|
||||
}
|
||||
|
||||
$db = \Yii::$app->db;
|
||||
$tx = $db->beginTransaction();
|
||||
try{
|
||||
foreach ($transfers as $transfer){
|
||||
if ( !$transfer->payout($transfer->id_account) ){
|
||||
\Yii::error("Failed to payout transaction: " .$transfer->id_transfer);
|
||||
throw new \Exception("Nem sikerült mententi a tranzakciókat");
|
||||
}
|
||||
}
|
||||
$tx->commit();
|
||||
Helper::flash("success", "Tranzakciók fizetettnek jelölve: " .count($transfers) . " db");
|
||||
}catch (\Exception $e){
|
||||
$tx->rollBack();
|
||||
Helper::flash("error", "Hiba történt a művelet közben");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -143,7 +143,6 @@ class TransferSearch extends Transfer
|
||||
return $dataProvider;
|
||||
}
|
||||
|
||||
echo "start date:" .$this->timestampStart;
|
||||
|
||||
$query->andFilterWhere([
|
||||
'transfer.id_account' => $this->id_account,
|
||||
|
||||
Reference in New Issue
Block a user