implement registration in backend

This commit is contained in:
Roland Schneider
2018-12-30 23:04:06 +01:00
parent b2bb210cee
commit e3b6bc08a7
32 changed files with 794 additions and 276 deletions

View File

@@ -9,7 +9,6 @@ use common\models\Discount;
use common\models\Transfer;
use common\models\UserSoldItem;
use common\models\ShoppingCart;
use yii\base\Object;
use common\models\TicketInstallmentRequest;
use common\models\Contract;
use common\components\Helper;
@@ -20,7 +19,7 @@ use common\models\Card;
* @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{
@@ -93,11 +92,11 @@ class TicketCreate extends Ticket{
}
public function validateTicketType($attribute,$params){
public function validateTicketType($attribute){
$type = TicketType::findOne($this->id_ticket_type);
$this->_ticketType = $type;
if ( !isset($type)) {
$this->addError($attribute,Yii::t('frontend/ticket' , 'Invalid ticket type' ));
$this->addError($attribute,\Yii::t('frontend/ticket' , 'Invalid ticket type' ));
}else{
if ( $type->isInstallment()){
$bankAccount = trim($this->customer->bank_account);
@@ -124,17 +123,17 @@ class TicketCreate extends Ticket{
}
}
public function validateAccount($attribute,$params){
public function validateAccount($attribute){
$this->_account = Account::findOne($this->id_account);
if ( !isset($this->_account )) {
$this->addError($attribute,Yii::t('frontend/ticket' , 'Invalid transfer' ));
$this->addError($attribute,\Yii::t('frontend/ticket' , 'Invalid transfer' ));
}
}
public function validateDiscount($attribute,$params){
public function validateDiscount($attribute){
$this->_discount = Discount::findOne($this->id_discount);
if ( !isset($this->_discount)) {
$this->addError($attribute,Yii::t('frontend/ticket' , 'Invalid discount' ));
$this->addError($attribute,\Yii::t('frontend/ticket' , 'Invalid discount' ));
}
}
@@ -163,13 +162,19 @@ class TicketCreate extends Ticket{
$start = DateUtil::parseDate($this->start);
$original_end = Helper::getTicketExpirationDate($start,$ticketType);
$this->original_end = DateUtil::formatDateUtc($original_end);
$this->max_reservation_count = $ticketType->max_reservation_count;
}
}
}
return $result;
}
public function afterSave($insert, $changedAttributes){
/**
* @param $insert
* @param $changedAttributes
* @throws \Exception
*/
public function afterSave($insert, $changedAttributes){
$this->addTransfer();
$this->appendToUserCart();
$this->appendToCustomerCart();
@@ -208,7 +213,10 @@ class TicketCreate extends Ticket{
}
}
protected function addTransfer(){
/**
* @throws \Exception
*/
protected function addTransfer(){
//$transfer = Transfer::createTicketTransfer($this->_account, $this->_discount, null, 1, $this);
@@ -230,16 +238,13 @@ class TicketCreate extends Ticket{
$transfer->money = $this->price_brutto;
$transfer->id_account = $this->_account->id_account;
$status = Transfer::STATUS_PAID;
if ( !Transfer::canMarkPaidByReception( $this->payment_method ) ){
$status = Transfer::STATUS_NOT_PAID;
}else if ( $this->isAppendToUserCart() ){
$status = Transfer::STATUS_NOT_PAID;
}else if ( $this->isAppendToCustomerCart() ){
$status = Transfer::STATUS_NOT_PAID;
$customer = $this->customer;
}else {
$status = Transfer::STATUS_PAID;
$transfer->paid_at = date('Y-m-d H:i:s' ) ;
@@ -260,18 +265,6 @@ class TicketCreate extends Ticket{
$this->_transfer = $transfer;
}
protected function addToCart(){
if ( $this->isAddToCart()){
$item = new UserSoldItem();
$item->id_transfer = $this->_transfer->id_transfer;
$item->id_user = \Yii::$app->user->id;
$item->save(false);
}
}
public function isAppendToUserCart(){
$result = false;
if ( isset( $this->cart ) && $this->cart == 'user' ){
@@ -287,8 +280,11 @@ class TicketCreate extends Ticket{
}
return $result;
}
/**
* @throws \Exception
*/
public function appendToUserCart(){
if ( $this->isAppendToUserCart() ){
$item = new UserSoldItem();
@@ -300,7 +296,10 @@ class TicketCreate extends Ticket{
}
}
}
/**
* @throws \Exception
*/
public function appendToCustomerCart(){
if ( Transfer::canBeAddedToCart($this->payment_method)){
if ( $this->isAppendToCustomerCart() && isset($this->customer) ){

View File

@@ -3,15 +3,10 @@
namespace frontend\models;
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;
use common\components\Helper;
/**
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
@@ -96,23 +91,14 @@ class TransferSearch extends Transfer
return $dataProvider;
}
public function totalsTransfers($params){
$accountTotals = [];
$fullTotal = [
'label' => Yii::t('common/transfer', 'Total'),
'money' => 0
];
/**
* @throws \yii\db\Exception
*/
public function totalsTransfers(){
$accounts = Account::find()->orderBy("name asc")->all();
$accountMap = ArrayHelper::map( $accounts ,'id_account','name' );
$idUser = Yii::$app->user->id;
$this->totals = Transfer::mkTotals($this->timestampStart, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts, $accountMap);
$this->totals = Transfer::mkTotals($this->timestampStart, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts);
}
}

View File

@@ -4,16 +4,9 @@ namespace frontend\models;
use common\components\DateUtil;
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;
use common\components\Helper;
use yii\web\NotFoundHttpException;
/**
@@ -95,23 +88,14 @@ class TransferSearchToday extends Transfer
return $dataProvider;
}
public function totalsTransfers($params){
$accountTotals = [];
$fullTotal = [
'label' => Yii::t('common/transfer', 'Total'),
'money' => 0
];
/**
* @throws \yii\db\Exception
*/
public function totalsTransfers(){
$accounts = Account::find()->orderBy("name asc")->all();
$accountMap = ArrayHelper::map( $accounts ,'id_account','name' );
$idUser = Yii::$app->user->id;
$this->totals = Transfer::mkTotals($this->timestampStart, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts, $accountMap);
$this->totals = Transfer::mkTotals($this->timestampStart, $this->timestampEnd, $idUser, $this->types, $this->id_account, $accounts);
}
}