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");
}
}