add contraint , that everybody expect admin is limited to 3 days, Add card package

This commit is contained in:
2016-02-13 17:23:43 +01:00
parent 556bdc3066
commit 70f43468af
37 changed files with 1418 additions and 19 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace common\components;
use common\models\Card;
class FreeUniqueCardNumberGenerator extends \yii\base\Object {
public $count;
public $keyset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
public $length = 6;
public $cache = [ ];
public $prefix = "";
public function generate() {
if ($this->count == 0) {
return;
}
for($i = 0; $i < $this->count; $i ++) {
$unique = false;
$number = null;
while ( $unique == false ) {
$number = Helper::generateRandomString($this->length, $this->keyset);
$number = $this->prefix . $number;
$unique = $this->checkCacheUnique ( $number ) && $this->checkDBUniqu ( $number );
}
$this->cache [] = $number;
}
}
protected function checkDBUniqu($number) {
$query = Card::find ();
Card::addCardNumberCondition ( $query, $number );
$found = $query->all ();
$result = count ( $found ) == 0;
return $result;
}
protected function checkCacheUnique($number) {
return array_search ( $number, $this->cache ) === false;
}
}

View File

@@ -5,6 +5,88 @@ namespace common\components;
use \Yii;
class Helper {
public static function isStartDateToEarly($days_between){
$days_visiblity = Helper::getReceptionVisibilityDays();
// $days_between = $this->calcStartDaysSinceToday();
return $days_between > $days_visiblity;
}
/**
* @param string $start the date string, format "datetime => "Y-m-d H:i", "date => "Y-m-d"
* */
public static function calcStartDatimeDaysSinceToday($start, $format = "datetime" ){
$now = time();
if ( $format == "datetime"){
$format = "Y-m-d H:i";
}else if ( $format == "date") {
$format = "Y-m-d";
}else{
//use format
}
$d = \DateTime::createFromFormat( $format , $start)->getTimeStamp();
$days_between = ceil(abs( $now - $d) / 86400 );
return $days_between;
}
/**
* Leellenőriz egy dátumot. Ha az aktuális felhasználó nem admin,
* akkor a params[reception_visibility_days] napnál korábbi , vagy null
* dátumot e params-ban megadott dátumra állítjuk
*
*
* */
public static function restrictIfNotAdminTheStartDate($query,$date, $fields = ['transfer.paid_at','transfer.created_at'], $format = 'datetime'){
$result = null;
$needFix = false;
if ( !isset($date) || empty($date)){
$needFix = true;
}else {
$days = Helper::calcStartDatimeDaysSinceToday($date,$format);
if ( Helper::isStartDateToEarly($days)){
$needFix = true;
}
}
if ( $needFix == true ){
$d = Helper::getReceptionVisibilityDays();
$time = date( "Y-m-d H:i:s", strtotime("today -$d day") );
$conditions = [];
foreach ($fields as $f ){
$conditions[] = ['>=', $f, $time];
}
if ( count($conditions) > 1 ){
$andWhereCond = [];
$andWhereCond[0] = "or";
$i = 1;
foreach ($conditions as $c){
$andWhereCond[$i] = $c;
$i++;
}
}else if ( count($conditions) == 1 ){
$andWhereCond = $conditions[0];
}
// $start_date_condition = ['or',[ '>=', 'transfer.created_at', $time ] ,[ '>=', 'transfer.paid_at', $time] ];
if ( isset($andWhereCond)){
$query->andWhere( $andWhereCond );
}
}
return $result;
}
public static function getDateTimeString( ){
@@ -173,16 +255,27 @@ class Helper {
public static function isUserCartVisibilityUser() {
return \Yii::$app->params ['user_cart_item_visibility'] == 'user';
}
public static function isCompanyMovar() {
return \Yii::$app->params ['company'] == 'movar';
}
public static function isProductVisibilityAccount() {
return \Yii::$app->params ['product_visiblity'] == 'account';
}
public static function isAccountStateClosePreloadMoney() {
return \Yii::$app->params ['account_state_close_preload_money'] == true;
}
public static function isAccountStateOpenSendMail() {
return \Yii::$app->params ['mail_account_state_open'] == true;
}
public static function isAccountStateCloseSendMail() {
return \Yii::$app->params ['mail_account_state_close'] == true;
}
public static function getReceptionVisibilityDays() {
return \Yii::$app->params ['reception_visibility_days'] ;
}
@@ -237,5 +330,15 @@ class Helper {
}
return $result;
}
public static function generateRandomString($length = 6,$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) {
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace common\components;
class XLSUtil {
public $objPHPExcel;
public function loadFromFileName($inputFileName) {
// Read your Excel workbook
try {
$inputFileType = \PHPExcel_IOFactory::identify ( $inputFileName );
$objReader = \PHPExcel_IOFactory::createReader ( $inputFileType );
$this->objPHPExcel = $objReader->load ( $inputFileName );
echo "type is: " . $inputFileType;
} catch ( Exception $e ) {
\Yii::error ( "failed to read xls" );
throw $e;
}
}
/**
* first sheet to array
*/
public function toArray( ) {
$objPHPExcel = $this->objPHPExcel;
$array = [ ];
// Get worksheet dimensions
$sheet = $objPHPExcel->getActiveSheet();
//$highestColumn = $sheet->getHighestColumn();
$hr = $sheet->getHighestRow();
foreach ( $sheet->getRowIterator () as $row ) {
$arrayRow = [];
$cellIterator = $row->getCellIterator ();
$cellIterator->setIterateOnlyExistingCells ( false ); // Loop all cells, even if it is not set
foreach ( $cellIterator as $cell ) {
$arrayRow [] = $cell->getCalculatedValue();
}
$array[] = $arrayRow;
}
return $array;
}
}

View File

@@ -63,10 +63,14 @@ class AccountStateMail extends Object {
$this->attachPdf();
$this->message->setFrom(\Yii::$app->params['infoEmail'])
->setTo( \Yii::$app->params['notify_mail'] )
->setSubject($subject )
->send();
try{
$this->message->setFrom(\Yii::$app->params['infoEmail'])
->setTo( \Yii::$app->params['notify_mail'] )
->setSubject($subject )
->send();
}catch (\Exception $e){
\Yii::error("Nem sikerült elküldeni a kassza müvelet emailt");
}
}

View File

@@ -4,12 +4,15 @@ return [
'supportEmail' => 'rocho02@gmail.com',
'infoEmail' => 'info@rocho-net.hu',
'user.passwordResetTokenExpire' => 3600,
'version' => 'v0.0.32',
'version' => 'v0.0.33',
'company' => 'movar',//gyor
'company_name' => "Freimann Kft.",
'product_visiblity' => 'account',// on reception which products to display. account or global
'notify_mail' => ['rocho02@gmail.com' ],
/**Kassza nyitáskor küldjünk email-t?*/
'mail_account_state_open' => true,
/**Kassza záráskor küldjünk email-t?*/
'mail_account_state_close' => true,
'login_reception_email' => true, //if reception login should send email
'login_admin_email' => true, //if admin login should send email
'account_state_close_preload_money' => 'true',//preload money wnen show account state close page

View File

@@ -0,0 +1,50 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "card_card_package_assignment".
*
* @property integer $id_card_card_package_assignment
* @property integer $id_card_package
* @property integer $id_card
* @property integer $printed
* @property string $created_at
* @property string $updated_at
*/
class CardCardPackageAssignment extends \common\models\BaseFitnessActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'card_card_package_assignment';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id_card_package', 'id_card'], 'integer'],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_card_card_package_assignment' => Yii::t('common/card_package', 'Id Card Card Package Assignment'),
'id_card_package' => Yii::t('common/card_package', 'Id Card Package'),
'id_card' => Yii::t('common/card_package', 'Id Card'),
'created_at' => Yii::t('common/card_package', 'Created At'),
'updated_at' => Yii::t('common/card_package', 'Updated At'),
];
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "card_package".
*
* @property integer $id_card_package
* @property integer $id_user
* @property integer $count
* @property string $created_at
* @property string $updated_at
*/
class CardPackage extends \common\models\BaseFitnessActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'card_package';
}
public function getUser(){
return $this->hasOne(User::className(), ['id' => 'id_user' ]);
}
public function getCardAssignments(){
return $this->hasMany(CardCardPackageAssignment::className(), ['id_card_package' => 'id_card_package' ]);
}
public function getCards(){
return $this->hasMany(Card::className(), ['id_card' => 'id_card' ])->via('cardAssignments');
}
public function getUserName(){
$user = $this->user;
$result = "";
if ( isset($user) ){
$result = $this->user->username;
}
return $result;
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['count'], 'integer',"min" => 1 , "max" => 3000],
[['count'], 'required'],
];
}
public function getPrintedDate(){
if ( $this->printed > 0 ){
return $this->updated_at;
}
return null;
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id_card_package' => Yii::t('common/card_package', 'Kártya csomag azonosító'),
'id_user' => Yii::t('common/card_package', 'Felhasználó'),
'count' => Yii::t('common/card_package', 'Mennyiség'),
'printed' => Yii::t('common/card_package', 'Letöltve'),
'printedDate' => Yii::t('common/card_package', 'Utolsó letöltés ideje'),
'count' => Yii::t('common/card_package', 'Mennyiség'),
'created_at' => Yii::t('common/card_package', 'Létrehozva'),
'updated_at' => Yii::t('common/card_package', 'Nyomtatva'),
];
}
}

View File

@@ -671,6 +671,13 @@ class Transfer extends \common\models\BaseFitnessActiveRecord {
self::notInInterval ( $query, 'transfer.created_at', $start, $end );
}
echo "start date is: ". $start;
echo "start date is: " . gettype( $start );
if ( !RoleDefinition::isAdmin() ){
Helper::restrictIfNotAdminTheStartDate($query, $start);
}
$query->groupBy ( 'transfer.id_account' );
return $query;
@@ -837,6 +844,16 @@ 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) {
$query = (new \yii\db\Query ());
$query->select ( [

View File

@@ -14,6 +14,7 @@ use common\models\Account;
use yii\helpers\ArrayHelper;
use common\models\MoneyMovement;
use common\components\RoleDefinition;
use common\components\Helper;
/**
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
*/
@@ -168,6 +169,16 @@ class TransferSaleSearch extends Transfer
$query->andFilterWhere(['or' , $created_condition , $paid_condition]);
$needRestirct = false;
if ( $this->isModeAdmin() ){
$needRestirct = !RoleDefinition::isAdmin();
}else{
$needRestirct = true;
}
if ( $needRestirct ){
Helper::restrictIfNotAdminTheStartDate($query, $this->timestampStart);
}
// $query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);

View File

@@ -14,12 +14,19 @@ use common\models\Account;
use yii\helpers\ArrayHelper;
use common\models\MoneyMovement;
use common\components\RoleDefinition;
use common\components\Helper;
/**
* TransferSearch represents the model behind the search form about `common\models\Transfer`.
*/
class TransferTicketSearch extends Transfer
{
/**
* if mode is recepion, date restriction will be used
* if mode is admin, date restriction will be used based on user role
* */
public $mode = 'reception';
public $start;
public $end;
@@ -126,6 +133,8 @@ class TransferTicketSearch extends Transfer
}
protected function calcTotal(){
$this->total = 0;
$this->total += $this->ticketMoney;
@@ -166,9 +175,24 @@ class TransferTicketSearch extends Transfer
$query->andWhere(['transfer.status' => Transfer::STATUS_PAID]);
$this->restrictStartDate($query);
}
function restrictStartDate($query){
$needRestriction = false;
if ( $this->mode == 'admin'){
$needRestriction = !RoleDefinition::isAdmin( ) ;
}else{
$needRestriction = true;
}
if ( $needRestriction ){
Helper::restrictIfNotAdminTheStartDate($query, $this->timestampStart);
}
}
protected function readTicketStas(){
$query = (new \yii\db\Query());