add kulcsok, add tartós beszedés, add ticket type with intallments

This commit is contained in:
2016-01-20 14:48:34 +01:00
parent d1638a19de
commit d7cc84e78f
111 changed files with 4077 additions and 12 deletions

View File

@@ -89,6 +89,9 @@ class CustomerCreate extends \common\models\Customer
[['phone', 'tax_number', 'country'], 'string', 'max' => 20],
[['bank_account'], 'string', 'max' => 24],
[['bank_name'], 'string', 'max' => 100],
[['phone'], 'required', 'when' => function($model) {
return !isset( $model->email ) || empty( $model->email ) ;
} ,

View File

@@ -88,6 +88,8 @@ class CustomerUpdate extends \common\models\Customer
[[ 'description', 'address'], 'string', 'max' => 255],
[['phone', 'tax_number', 'country'], 'string', 'max' => 20],
[['bank_account'], 'string', 'max' => 24],
[['bank_name'], 'string', 'max' => 100],
[['phone'], 'required', 'when' => function($model) {
return !isset( $model->email ) || empty( $model->email ) ;

View File

@@ -0,0 +1,137 @@
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use common\models\Card;
use common\models\Customer;
use common\models\Ticket;
use common\models\Account;
use yii\web\UploadedFile;
use common\models\TicketInstallmentRequest;
use common\models\Ugiro;
use common\components\giro\GiroBeszed;
use yii\helpers\FileHelper;
use yii\helpers\Inflector;
use yii\helpers\BaseInflector;
use common\models\UgiroRequestAssignment;
/**
* ContactForm is the model behind the contact form.
* @property \Yii\web\UploadedFile $file
*/
class GiroKotegForm extends Model{
public $action;
public $requests;
public $content;
public $koteg;
public $success;
public function rules(){
return [
[['action'], 'safe']
];
}
public function createKoteg(){
$this->readRequests();
$this->success = true;
if ( count( $this->requests ) > 0 ){
$connection = \Yii::$app->db;
$transaction = $connection->beginTransaction();
try {
$this->createUGiroKoteg();
$this->assignRequestsToUgiro();
$this->changeRequestsStatusToSent();
$this->generateFileContent();
$this->saveFile();
if ($this->success) {
$transaction->commit();
\Yii::$app->session->setFlash('success',"Fájl létrehozva");
return true;
} else {
$transaction->rollback();
throw new NotFoundHttpException( "Hiba történt!");
}
} catch (\Exception $e) {
$transaction->rollback();
throw $e;
}
}else{
\Yii::$app->session->setFlash('danger', "Megbízások száma 0!");
return false;
}
}
public function changeRequestsStatusToSent(){
foreach ($this->requests as $request){
$request->status = TicketInstallmentRequest::$STATUS_SENT;
$this->success &= $request->save(false);
}
}
public function assignRequestsToUgiro(){
foreach ($this->requests as $request){
$assignment = new UgiroRequestAssignment();
$assignment->id_request = $request->id_ticket_installment_request;
$assignment->id_ugiro = $this->koteg->id_ugiro;
$this->success &= $assignment->save(false);
}
}
public function createUGiroKoteg(){
$this->koteg = new Ugiro();
$this->koteg->status = Ugiro::$STATUS_SENT;
$this->koteg->id_user = \Yii::$app->user->id;
$this->success &= $this->koteg->save(false);
}
public function readRequests(){
$this->requests = TicketInstallmentRequest::find()->andWhere(['status' => TicketInstallmentRequest::$STATUS_MARKED_TO_SEND])->all();
}
public function generateFileContent(){
$this->content = GiroBeszed::createFileContent($this->koteg->id_ugiro, $this->requests);
}
public function saveFile( ) {
// $data = static::transliterate($this->content);
$data = $this->content;
$data = iconv("utf-8","ASCII",$data);
$path = Ugiro::$PATH_MEGBIZAS . DIRECTORY_SEPARATOR ."giro" . $this->koteg->id_ugiro."_". date('Ymd' ) .".txt";
$filename = Yii::getAlias('@backend/web').DIRECTORY_SEPARATOR .$path;
$dir = Yii::getAlias('@backend/web').DIRECTORY_SEPARATOR .Ugiro::$PATH_MEGBIZAS;
$this->koteg->path = $path;
$this->koteg->save(false);
if(!FileHelper::createDirectory($dir)){
throw new HttpException(500, 'Cannot create "'.$dir.'". Please check write permissions.');
}
$myfile = fopen($filename,'a');
fwrite($myfile, $data);
fclose($myfile);
}
public static function transliterate($string)
{
// if (static::hasIntl()) {
// return transliterator_transliterate(BaseInflector::$transliterator, $string);
// } else {
return str_replace(array_keys(BaseInflector::$transliteration), BaseInflector::$transliteration, $string);
// }
}
/**
* @return boolean if intl extension is loaded
*/
protected static function hasIntl()
{
return extension_loaded('intl');
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use common\models\Card;
use common\models\Customer;
use common\models\Ticket;
use common\models\Account;
use yii\web\UploadedFile;
use common\models\TicketInstallmentRequest;
/**
* ContactForm is the model behind the contact form.
* @property \Yii\web\UploadedFile $file
*/
class TicketInstallmentMarkForSendForm extends Model{
public $items;
public function rules(){
return [
['items', 'each', 'rule' => ['integer']],
];
}
public function markForSend(){
if ( $this->validate() && isset($this->items ) && is_array($this->items ) ){
$updated = 0;
$updated = TicketInstallmentRequest::updateAll(['status' => TicketInstallmentRequest::$STATUS_MARKED_TO_SEND ],['in', 'id_ticket_installment_request' , $this->items]);
\Yii::$app->session->setFlash('success', $updated . " megbízás küldésre jelölve " );
}else{
\Yii::$app->session->setFlash('success', " Nem történt küldésre jelölés! " );
}
}
}

View File

@@ -0,0 +1,130 @@
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\TicketInstallmentRequest;
use yii\db\Query;
use yii\data\ArrayDataProvider;
/**
* TicketInstallmentRequestSearch represents the model behind the search form about `common\models\TicketInstallmentRequest`.
*/
class TicketInstallmentRequestSearch extends TicketInstallmentRequest
{
public $start;
public $end;
public $timestampStart;
public $timestampEnd;
public $processedStart;
public $processedEnd;
public $timestampProcessedStart;
public $timestampProcessedEnd;
public $sentStart;
public $sentEnd;
public $timestampSentStart;
public $timestampSentEnd;
public $customer_name;
public $id_ticket_type;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_ticket_installment_request', 'id_ticket', 'id_customer', 'status' ,'id_ticket_type'], 'integer'],
[['customer_name' ], 'safe'],
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'processedStart', ], 'date' , 'timestampAttribute' => 'timestampProcessedStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'processedEnd' , ], 'date' , 'timestampAttribute' => 'timestampProcessedEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'sentStart', ], 'date' , 'timestampAttribute' => 'timestampSentStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'sentEnd' , ], 'date' , 'timestampAttribute' => 'timestampSentEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = new Query();
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
}
$query->select([
'ticket_installment_request.id_ticket_installment_request as request_id_ticket_installment_request', //id
'ticket_installment_request.request_target_time_at as request_request_target_time_at',//target time
'ticket_installment_request.money as request_money',//money
'ticket_installment_request.status as request_status',//status
'ticket_installment_request.request_sent_at as request_sent_at',//sent_at
'ticket_installment_request.priority as request_priority',//sent_at
'ticket_installment_request.request_processed_at as request_processed_at',//request_processed_at
'customer.id_customer as customer_id_customer',//id_customer
'customer.name as customer_name',//customer_name
'ticket_type.name as ticket_type_name',//ticket_type_name
'ticket.status as ticket_status',//ticket_status
'ticket.start as ticket_start',//ticket_start
'ticket.end as ticket_end',//ticket_send
'ticket.id_ticket as ticket_id_ticket',//id_ticket
]);
$query->from("ticket_installment_request");
$query->innerJoin("customer","customer.id_customer = ticket_installment_request.id_customer");
$query->innerJoin("ticket","ticket.id_ticket = ticket_installment_request.id_ticket");
$query->innerJoin("ticket_type","ticket.id_ticket_type = ticket_type.id_ticket_type");
$query->orderBy(["ticket_installment_request.request_target_time_at" => SORT_ASC]);
$query->andFilterWhere([
'ticket_installment_request.id_ticket_installment_request' => $this->id_ticket_installment_request,
'ticket.id_ticket' => $this->id_ticket,
'customer.id_customer' => $this->id_customer,
'ticket_installment_request.status' => $this->status,
'ticket_type.id_ticket_type' => $this->id_ticket_type,
]);
$query->andFilterWhere(['like', 'customer.name', $this->customer_name]);
//target time
$query->andFilterWhere(['>=', 'ticket_installment_request.request_target_time_at', $this->timestampStart]);
$query->andFilterWhere(['<', 'ticket_installment_request.request_target_time_at', $this->timestampEnd]);
//sent time
$query->andFilterWhere(['>=', 'ticket_installment_request.request_sent_at', $this->timestampSentStart]);
$query->andFilterWhere(['<', 'ticket_installment_request.request_sent_at', $this->timestampSentEnd]);
//processed time
$query->andFilterWhere(['>=', 'ticket_installment_request.request_processed_at', $this->timestampProcessedStart]);
$query->andFilterWhere(['<', 'ticket_installment_request.request_processed_at', $this->timestampProcessedEnd]);
$dataProvider = new ArrayDataProvider([
'allModels' => $query->all(),
// 'sort' => [
// 'attributes' => ['id', 'username', 'email'],
// ],
// 'pagination' => [
// 'pageSize' => 10,
// ],
]);
return $dataProvider;
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\TicketInstallmentRequest;
use yii\db\Query;
use yii\data\ArrayDataProvider;
/**
* TicketInstallmentRequestSearch represents the model behind the search form about `common\models\TicketInstallmentRequest`.
*/
class TicketInstallmentRequestSearchDownloadGiro extends TicketInstallmentRequest
{
public $start;
public $end;
public $timestampStart;
public $timestampEnd;
public $customer_name;
public $id_ticket_type;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_ticket_installment_request', 'id_ticket', 'id_customer', 'status' ,'id_ticket_type'], 'integer'],
[['customer_name' ], 'safe'],
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = new Query();
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
}
$query->select([
'ticket_installment_request.id_ticket_installment_request as request_id_ticket_installment_request', //id
'ticket_installment_request.request_target_time_at as request_request_target_time_at',//target time
'ticket_installment_request.money as request_money',//money
'ticket_installment_request.status as request_status',//status
'ticket_installment_request.request_sent_at as request_sent_at',//sent_at
'ticket_installment_request.priority as request_priority',//sent_at
'ticket_installment_request.request_processed_at as request_processed_at',//request_processed_at
'customer.id_customer as customer_id_customer',//id_customer
'customer.name as customer_name',//customer_name
'ticket_type.name as ticket_type_name',//ticket_type_name
'ticket.status as ticket_status',//ticket_status
'ticket.start as ticket_start',//ticket_start
'ticket.end as ticket_end',//ticket_send
'ticket.id_ticket as ticket_id_ticket',//id_ticket
]);
$query->from("ticket_installment_request");
$query->innerJoin("customer","customer.id_customer = ticket_installment_request.id_customer");
$query->innerJoin("ticket","ticket.id_ticket = ticket_installment_request.id_ticket");
$query->innerJoin("ticket_type","ticket.id_ticket_type = ticket_type.id_ticket_type");
$query->andWhere(['ticket_installment_request.status' => TicketInstallmentRequest::$STATUS_MARKED_TO_SEND]);
$query->orderBy(["ticket_installment_request.request_target_time_at" => SORT_ASC]);
// $query->andFilterWhere([
// 'ticket_installment_request.id_ticket_installment_request' => $this->id_ticket_installment_request,
// 'ticket.id_ticket' => $this->id_ticket,
// 'customer.id_customer' => $this->id_customer,
// 'ticket_installment_request.status' => $this->status,
// 'ticket_type.id_ticket_type' => $this->id_ticket_type,
// ]);
// $query->andFilterWhere(['like', 'customer.name', $this->customer_name]);
//target time
// $query->andFilterWhere(['>=', 'ticket_installment_request.request_target_time_at', $this->timestampStart]);
// $query->andFilterWhere(['<', 'ticket_installment_request.request_target_time_at', $this->timestampEnd]);
$dataProvider = new ArrayDataProvider([
'allModels' => $query->all(),
// 'sort' => [
// 'attributes' => ['id', 'username', 'email'],
// ],
// 'pagination' => [
// 'pageSize' => 10,
// ],
]);
return $dataProvider;
}
}

View File

@@ -0,0 +1,114 @@
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\TicketInstallmentRequest;
use yii\db\Query;
use yii\data\ArrayDataProvider;
/**
* TicketInstallmentRequestSearch represents the model behind the search form about `common\models\TicketInstallmentRequest`.
*/
class TicketInstallmentRequestSearchPending extends TicketInstallmentRequest
{
public $start;
public $end;
public $timestampStart;
public $timestampEnd;
public $customer_name;
public $id_ticket_type;
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_ticket_installment_request', 'id_ticket', 'id_customer', 'status' ,'id_ticket_type'], 'integer'],
[['customer_name' ], 'safe'],
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = new Query();
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
}
$query->select([
'ticket_installment_request.id_ticket_installment_request as request_id_ticket_installment_request', //id
'ticket_installment_request.request_target_time_at as request_request_target_time_at',//target time
'ticket_installment_request.money as request_money',//money
'ticket_installment_request.status as request_status',//status
'ticket_installment_request.request_sent_at as request_sent_at',//sent_at
'ticket_installment_request.priority as request_priority',//sent_at
'ticket_installment_request.request_processed_at as request_processed_at',//request_processed_at
'customer.id_customer as customer_id_customer',//id_customer
'customer.name as customer_name',//customer_name
'ticket_type.name as ticket_type_name',//ticket_type_name
'ticket.status as ticket_status',//ticket_status
'ticket.start as ticket_start',//ticket_start
'ticket.end as ticket_end',//ticket_send
'ticket.id_ticket as ticket_id_ticket',//id_ticket
]);
$query->from("ticket_installment_request");
$query->innerJoin("customer","customer.id_customer = ticket_installment_request.id_customer");
$query->innerJoin("ticket","ticket.id_ticket = ticket_installment_request.id_ticket");
$query->innerJoin("ticket_type","ticket.id_ticket_type = ticket_type.id_ticket_type");
$query->andWhere(['ticket_installment_request.status' => TicketInstallmentRequest::$STATUS_PENDING]);
$query->orderBy(["ticket_installment_request.request_target_time_at" => SORT_ASC]);
$query->andFilterWhere([
'ticket_installment_request.id_ticket_installment_request' => $this->id_ticket_installment_request,
'ticket.id_ticket' => $this->id_ticket,
'customer.id_customer' => $this->id_customer,
'ticket_installment_request.status' => $this->status,
'ticket_type.id_ticket_type' => $this->id_ticket_type,
]);
$query->andFilterWhere(['like', 'customer.name', $this->customer_name]);
//target time
$query->andFilterWhere(['>=', 'ticket_installment_request.request_target_time_at', $this->timestampStart]);
$query->andFilterWhere(['<', 'ticket_installment_request.request_target_time_at', $this->timestampEnd]);
$dataProvider = new ArrayDataProvider([
'allModels' => $query->all(),
// 'sort' => [
// 'attributes' => ['id', 'username', 'email'],
// ],
// 'pagination' => [
// 'pageSize' => 10,
// ],
]);
return $dataProvider;
}
}

View File

@@ -37,7 +37,7 @@ class TicketSearch extends Ticket
public function rules()
{
return [
[[ 'id_user', 'id_ticket_type', 'id_account'], 'integer'],
[[ 'id_ticket', 'id_user', 'id_ticket_type', 'id_account'], 'integer'],
[[ 'start', ], 'date' , 'timestampAttribute' => 'timestampStart' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[[ 'end' , ], 'date' , 'timestampAttribute' => 'timestampEnd' ,'timestampAttributeFormat' => 'yyyy-MM-dd' ],
[['valid_in_interval','created_in_interval','expire_in_interval'],'boolean'] ,
@@ -117,6 +117,7 @@ class TicketSearch extends Ticket
'id_ticket_type' => $this->id_ticket_type,
'id_account' => $this->id_account,
'id_card' => $this->id_card,
'id_ticket' => $this->id_ticket
]);

View File

@@ -0,0 +1,67 @@
<?php
namespace backend\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Ugiro;
/**
* UgiroSearch represents the model behind the search form about `common\models\Ugiro`.
*/
class UgiroSearch extends Ugiro
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_ugiro', 'id_user'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
];
}
/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Ugiro::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere([
'id_ugiro' => $this->id_ugiro,
'id_user' => $this->id_user,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
]);
return $dataProvider;
}
}