Created
January 16, 2021 09:30
-
-
Save bzimor/883fa7091d0337f4c94d208ee7deb146 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace app\models; | |
| use app\components\EmailSend; | |
| use app\components\Functions; | |
| use Endroid\QrCode\QrCode; | |
| use Mpdf\Mpdf; | |
| use Yii; | |
| use yii\data\ActiveDataProvider; | |
| use yii\helpers\ArrayHelper; | |
| use yii\helpers\Html; | |
| use yii\helpers\Json; | |
| use yii\helpers\Url; | |
| use yii\web\UploadedFile; | |
| class Longclass extends \app\components\ActiveRecord | |
| { | |
| const SCENARIO_book = 'book'; | |
| const SCENARIO_table_book_DISCOUNT = 'table-book-discount'; | |
| /** User tomonidan bekor qilindi. */ | |
| const STATE_NONE = 0; | |
| /** Pay in progress, order must not be changed. */ | |
| const STATE_WAITING_PAY = 1; | |
| /** Order completed and not available for sell. */ | |
| const STATE_PAY_ACCEPTED = 2; | |
| /** Order is cancelled. */ | |
| const STATE_CANCELLED = 3; | |
| /* | |
| |-------------------------------------------------------------------------- | |
| | Custom attributes | |
| |-------------------------------------------------------------------------- | |
| */ | |
| public $dataPrice; | |
| public $dataPricebook; | |
| public $actual_book = false; | |
| public $product_id_book; | |
| public $library_summa_book; | |
| public $library_max_discount_book; | |
| public $library_discount_basic_book; | |
| public $library_discount_gift_book; | |
| public $library_number_book; | |
| public $library_summa_end_old; | |
| public $library_summa_end2_old; | |
| public $library_summa_end_table; | |
| public $library_summa_end2_table; | |
| public $library_summa_end_book; | |
| public $library_summa_end2_book; | |
| public $risk_summas; | |
| public $beneficiary; | |
| // Step 1 | |
| public $vehicle_body_number; | |
| public $vehicle_type; | |
| public $brand; | |
| public $photo; | |
| public $energy_power; | |
| public $horse_power; | |
| public $weight; | |
| public $suit; | |
| public $vehicle_library_state; | |
| public $driver_library_state; | |
| public $driver_violation; | |
| // Step 2 | |
| // if 1-5 drivers | |
| public $last_name; | |
| public $first_name; | |
| public $sure_name; | |
| public $passport; | |
| public $birth_day; | |
| public $driving_license; | |
| public $driving_license_date; | |
| public $library_state; | |
| public $violation; | |
| public $gender; | |
| public $driver_experence; | |
| public $driver_old; | |
| public $error; | |
| // Step 5 | |
| public $file; | |
| public $file_discount; | |
| // if physical | |
| public $owner_last_name; | |
| public $owner_first_name; | |
| public $owner_sure_name; | |
| public $owner_passport; | |
| public $owner_address_physical; | |
| public $owner_region_physical; | |
| // if juridical | |
| public $owner_name; | |
| public $owner_inn; | |
| public $owner_phone_number; | |
| public $owner_address_juridical; | |
| public $owner_region_juridical; | |
| // user register if guest | |
| public $email; | |
| public $phone_number; | |
| public $privacy_library; | |
| public $user_identity; | |
| public $payment_to_company_number; | |
| public $payment_to_company_date; | |
| /** | |
| * book attributlari | |
| * @return string | |
| */ | |
| public $book_summa = 0; | |
| public $cover; | |
| public $yonilgi_turi; | |
| public $probeg; | |
| public $karobka; | |
| public $tyuning; | |
| public $privod; | |
| public $eko_klass; | |
| public $koleso_formula; | |
| public $massa1; | |
| public $massa2; | |
| public $type_kuzov; | |
| public $type_electr; | |
| public $electr_power; | |
| public $electr_count; | |
| public $xadavoy; | |
| public $parking; | |
| public $signal; | |
| public $permission; | |
| public $benifit; | |
| public $remont; | |
| public $extra_services; | |
| public $expire_at_book; | |
| public $book_currency; | |
| public $book_type_summa; | |
| public $book_type_object; | |
| public $book_risk; | |
| public $juridic_activity; | |
| public $clearance_region; | |
| public $clearance_country; | |
| public $franshiza_type; | |
| public $franshiza_percent; | |
| public $rasrochka; | |
| public $payment_book_type; | |
| //new var | |
| public $book_srok; | |
| /** | |
| * @return string | |
| */ | |
| public static function tableName() | |
| { | |
| return 'library'; | |
| } | |
| /** | |
| * @return array | |
| */ | |
| public function rules() | |
| { | |
| return [ | |
| [['user_id', 'product_id', 'status', 'discount_status'], 'integer'], | |
| [['vehicle_data', 'library_data','payment_type','payment_date','payment_to_company_number','payment_company_date'], 'safe'], | |
| ['payment_to_company_number','string','length' => [1,10]], | |
| [['expired_at', 'start_date', 'created_at','library_max_discount', 'library_discount_basic', 'library_discount_gift', 'driver_count'], 'safe'], | |
| [['library_number', 'discount_comment'], 'string', 'max' => 255], | |
| [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'id']], | |
| [['product_id_book'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id_book' => 'id']], | |
| [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], | |
| [['agent_id'], 'exist', 'skipOnError' => true, 'targetClass' => CompanyHasAgent::className(), 'targetAttribute' => ['agent_id' => 'id']], | |
| [['vehicle_body_number', 'vehicle_type', 'brand', 'vehicle_model_id', 'created_date', | |
| 'register_location_id', 'vehicle_owner_type', 'expired_at', 'start_date'], 'required', 'on' => 'step-1'], | |
| [['energy_power', 'horse_power', 'suit'], 'integer'], | |
| [['energy_power', 'horse_power', 'weight', 'suit'], 'safe'], | |
| [['energy_power', 'horse_power', 'vehicle_use_for_purpose'], 'required', 'on' => 'step-1', | |
| 'when' => function ($model) { | |
| return $model->vehicle_type == '1'; | |
| }, 'whenClient' => "function (attribute, value) { | |
| return $('#library-vehicle_type').find('[value=\'1\']').prop('selected') == true; | |
| }" | |
| ], | |
| [['beneficiary'],'string', 'length' => [3,500], | |
| 'on' => [self::SCENARIO_book]], | |
| [['beneficiary'],'required', | |
| 'when' => function () { | |
| return is_numeric($this->benifit)?0==$this->benifit:false; | |
| }, | |
| 'on' => [self::SCENARIO_book]], | |
| [['weight'], 'required', 'on' => 'step-1', | |
| 'when' => function ($model) { | |
| return $model->vehicle_type == '2'; | |
| }, 'whenClient' => "function (attribute, value) { | |
| return $('#library-vehicle_type').find('[value=\'2\']').prop('selected') == true; | |
| }" | |
| ], | |
| [['suit', 'vehicle_use_for_purpose'], 'required', 'on' => 'step-1', | |
| 'when' => function ($model) { | |
| return $model->vehicle_type == '3'; | |
| }, 'whenClient' => "function (attribute, value) { | |
| return $('#library-vehicle_type').find('[value=\'3\']').prop('selected') == true; | |
| }" | |
| ], | |
| [['library_state', 'violation', 'gender', 'vehicle_body_number', 'vehicle_type', 'brand', 'vehicle_model_id', 'created_date', | |
| 'register_location_id', 'vehicle_owner_type', 'vehicle_use_for_purpose', 'photo','discount'], 'safe'], | |
| [['vehicle_body_number'], 'string', 'length' => [6, 17]], | |
| [['driver_count'], 'required', 'on' => 'step-2'], | |
| [['driver_count'], 'safe', 'on' => 'step-3'], | |
| // [['violation'], 'in', 'range' => array_keys(self::getViolationDriver()), 'allowArray' => true], | |
| [['library_state'], 'in', 'range' => array_keys(self::getlibraryStateDriver()), 'allowArray' => true], | |
| [['library_state', 'violation', 'gender', 'last_name', 'first_name', 'passport', 'birth_day', 'driving_license', 'driving_license_date'], 'required', 'on' => 'step-2', | |
| 'when' => function ($model) { | |
| return $model->driver_count == '1-5-drivers'; | |
| }, 'whenClient' => "function (attribute, value) { | |
| return $('#library-driver_count').find('[value=\'1-5-drivers\']').prop('selected') == true; | |
| }" | |
| ], | |
| [['library_state', 'violation', 'gender', 'last_name', 'first_name', 'sure_name', 'passport', 'birth_day', 'driving_license', 'driving_license_date'], 'safe', 'on' => 'step-2', | |
| 'when' => function ($model) { | |
| return $model->driver_count == '1-5-drivers'; | |
| }, 'whenClient' => "function (attribute, value) { | |
| return $('#library-driver_count').find('[value=\'1-5-drivers\']').prop('selected') == true; | |
| }" | |
| ], | |
| [['gender'], 'in', 'range' => array_keys(Functions::getSex()), 'allowArray' => true], | |
| [['payment_type'], 'in', 'range' => array_keys(self::getPaymentType())], | |
| // Step 5 | |
| [['body_number', 'vehicle_number', 'motor_number', 'technical_passport', 'technical_passport_date', 'technical_passport_file'], 'required', 'on' => ['step-5', 'step-5-register']], | |
| [['file'], 'file', 'maxSize' => 5304857, 'maxFiles' => 1, 'extensions' => ['pdf', 'jpg', 'jpeg', 'png','bmp']], | |
| [['owner_last_name', 'owner_first_name', 'owner_sure_name', 'owner_name', 'owner_passport', 'owner_inn', 'owner_address_juridical', 'owner_address_physical', 'owner_region_physical', 'owner_region_juridical','owner_phone_number'], 'safe', 'on' => ['step-6']], | |
| [['owner_last_name', 'owner_first_name', 'owner_sure_name', 'owner_name', 'owner_passport', 'owner_address_juridical', 'owner_address_physical', 'technical_passport_file',], 'string', 'max' => 255], | |
| [['owner_inn'], 'integer'], | |
| [['owner_last_name', 'owner_first_name', 'owner_passport', 'owner_region_physical', 'owner_address_physical'], 'required', | |
| 'when' => function () { | |
| return $this->vehicle_owner_type == 'physical'; | |
| } | |
| ], | |
| [['owner_phone_number'], 'required', | |
| 'when' => function () { | |
| return count(Yii::$app->session->get('agent_company')); | |
| },'on'=>['step-5'] | |
| ], | |
| [['owner_name', 'owner_inn', 'owner_address_juridical', 'owner_region_juridical'], 'required', | |
| 'when' => function () { | |
| return $this->vehicle_owner_type == 'juridical' or $this->vehicle_owner_type == 'indivudal'; | |
| } | |
| ], | |
| [['privacy_library'], 'required', 'on' => ['step-5-register']], | |
| [['email'], 'required', 'on' => ['step-5-register'], | |
| 'when' => function ($model) { | |
| return empty($model->phone_number); | |
| }, | |
| 'whenClient' => "function (attribute, value) { | |
| return $('#library-phone_number').val().length<=12; | |
| }" | |
| ], | |
| [['phone_number'], 'required', 'on' => ['step-5-register'], | |
| 'when' => function ($model) { | |
| return empty($model->email); | |
| }, | |
| 'whenClient' => "function (attribute, value) { | |
| return $('#library-email').val().length<4; | |
| }" | |
| ], | |
| [['email', 'phone_number'], 'safe', 'on' => ['step-5']], | |
| [['email', 'phone_number'], 'string', 'max' => 255], | |
| // [['email', 'phone_number'], 'unique','targetClass' => '\app\models\User'], | |
| [['email', 'phone_number','owner_phone_number'], 'filter', 'filter' => 'trim'], | |
| [['email'], 'email'], | |
| // [['discount_user_type', 'file_discount'], 'required', | |
| // 'when' => function ($model) { | |
| // return $model->discount and $model->discount_file == ''; | |
| // }, 'whenClient' => "function (attribute, value) { | |
| // return $('#library-discount').prop('checked'); | |
| // }" | |
| // ], | |
| [['discount_user_type'], 'required', | |
| 'when' => function ($model) { | |
| return $model->discount; | |
| }, 'whenClient' => "function (attribute, value) { | |
| return $('#library-discount').prop('checked'); | |
| }" | |
| ], | |
| [['file_discount'], 'file', 'maxSize' => 5304857, 'maxFiles' => 1, 'extensions' => ['pdf', 'jpg', 'jpeg', 'png','bmp']], | |
| ['discount_user_type', 'in', 'range' => array_keys(self::getDiscountType())], | |
| ['driver_count', 'in', 'range' => array_keys(self::getDriverCount())], | |
| ['expired_at', 'in', 'range' => array_keys(self::getlibraryPeriod()), | |
| 'when' => function ($model) { | |
| return $model->register_location_id ==1; | |
| }, | |
| 'whenClient' => "function (attribute, value) { | |
| return $('#library-register_location_id').val() ==1; | |
| }" | |
| ], | |
| ['expired_at', 'in', 'range' => array_keys(self::getlibraryUnregistered()), | |
| 'when' => function ($model) { | |
| return $model->register_location_id ==200; | |
| }, | |
| 'whenClient' => "function (attribute, value) { | |
| return $('#library-register_location_id').val() ==200; | |
| }" | |
| ], | |
| ['expired_at', 'in', 'range' => array_keys(self::getlibraryPeriodForeign()), | |
| 'when' => function ($model) { | |
| return $model->register_location_id == 0; | |
| }, | |
| 'whenClient' => "function (attribute, value) { | |
| return $('#library-register_location_id').val()==0; | |
| }" | |
| ], | |
| ['vehicle_owner_type', 'in', 'range' => array_keys(Functions::getUserType())], | |
| ['vehicle_use_for_purpose', 'in', 'range' => array_keys(Product::getUseVehicle())], | |
| [['birth_day', 'driving_license_date'], 'safe', 'on' => ['step-3']], | |
| [['last_name', 'first_name', 'sure_name', 'owner_last_name', 'owner_first_name', 'owner_sure_name', 'owner_name', 'owner_address_physical'], 'trim'], | |
| [['last_name', 'first_name', 'sure_name', 'owner_last_name', 'owner_first_name', 'owner_sure_name', 'owner_name', 'owner_address_physical'], 'string', 'max' => 255], | |
| [['owner_inn'], 'string', 'length' => 9], | |
| [['last_name', 'first_name', 'sure_name', 'owner_last_name', 'owner_first_name', 'owner_sure_name',], 'match', 'pattern' => '/[a-zA-Z\s]/', 'message' => Yii::t('yii', '{attribute} can contain only latin letters')], | |
| [['passport', 'owner_passport','driving_license'], 'safe'], | |
| // [['driving_license'], 'match', 'pattern' => '/[A-Z]{2}\d{6,7}/', 'message' => Yii::t('yii', '{attribute} can contain only latin letters and numbers')], | |
| [['body_number'], 'string', 'length' => 17], | |
| // [['technical_passport'], 'match', 'pattern' => '/[A-Z]{3}[1-9]{7}/', 'message' => Yii::t('yii', '{attribute} can be only such format [AAA1234567]')], | |
| [['technical_passport'], 'string'], | |
| [['motor_number'], 'string'], | |
| [['library_number'], 'required', 'on' => ['find','wait-payment']], | |
| [['user_identity'], 'required', 'on' => ['find']], | |
| [['owner_passport'], 'required', 'on' => ['wait-payment']], | |
| [['library_number', 'user_identity','owner_passport'], 'safe', 'on' => ['find','wait-payment']], | |
| [['library_number'], 'match', 'pattern' => '/[A-Z]{2}\-\d{7}/', 'message' => Yii::t('yii', '{attribute} can be only such format [AA-1234567]')], | |
| // [['user_identity'], 'match', 'pattern' => '/([A-Z]{2}\d{7})|(\d){9}/', 'message' => Yii::t('yii', '{attribute} can be only such format [AA1234567] or 123456789')], | |
| ['discount_comment','safe'], | |
| [['vehicle_number'], 'string', 'length' => [6, 10]], | |
| [['vehicle_number', 'motor_number', 'body_number'], 'match', 'pattern' => '/[a-zA-Z0-9]/', 'message' => Yii::t('yii', '{attribute} can contain only latin letters and numbers')], | |
| [['vehicle_number', 'motor_number', 'body_number', 'technical_passport_file', 'owner_region_physical', | |
| 'technical_passport', 'email', 'phone_number', 'owner_address_physical', | |
| 'technical_passport_date'], 'safe', 'on' => ['step-5', 'step-6']], | |
| [['discount', 'discount_file', 'discount_user_type',], 'safe', 'on' => ['step-3', 'step-2']], | |
| [[ | |
| 'vehicle_number', 'motor_number', 'body_number', 'technical_passport_file', 'technical_passport', 'technical_passport_date', | |
| 'register_location_id', 'vehicle_owner_type', | |
| 'user_id', 'product_id', 'vehicle_model_id', 'library_number', 'driver_count', 'expired_at', 'start_date', | |
| ], 'required', 'on' => ['step-6']], | |
| /** | |
| * book forma | |
| */ | |
| [['clearance_region', | |
| 'clearance_country','payment_book_type','probeg','signal','permission'], | |
| 'required', | |
| 'on'=>[self::SCENARIO_book]], | |
| [['book_summa','book_type_object', | |
| 'book_type_summa', 'book_currency'],'requiredAttribute', | |
| 'on' => self::SCENARIO_book], | |
| [['book_risk'],'requiredAttributeRisk', | |
| 'on' => self::SCENARIO_book], | |
| [['book_summa'], 'each','rule'=>['number'], 'on' => self::SCENARIO_book,], | |
| [['book_currency'],'each','rule'=>[ 'in','range'=>array_keys(Currency::getCurrencyList())], 'on' => self::SCENARIO_book,], | |
| [['book_type_summa'], 'each','rule'=>['in','range'=>array_keys(self::getbookTypeSumma())], 'on' => self::SCENARIO_book,], | |
| [['book_type_object'], 'each','rule'=>[ | |
| 'in','range'=>array_keys(self::getbookTypeObject()),], | |
| 'on' => self::SCENARIO_book,], | |
| [['franshiza_type'], 'each','rule'=>['in','range'=>array_keys(self::getFranshizaType())], | |
| 'on' => self::SCENARIO_book,], | |
| [['franshiza_percent'], 'each','rule'=>[ 'integer','min'=>0,'max'=>100], | |
| 'on' => self::SCENARIO_book,], | |
| // [['book_risk', 'cover'], 'required', 'on' => self::SCENARIO_book, | |
| // 'when' => function ($model) { | |
| // $a = $this->book_type_object; | |
| // return $a?in_array('yes', $a):false; | |
| // }, | |
| // ], | |
| [['book_risk'], 'each','rule'=>['in','range'=>array_keys(Common::getList(Common::TYPE_RISK))], | |
| 'on' => self::SCENARIO_book,], | |
| [['cover'], 'in','range'=>array_keys(Common::getList(Common::TYPE_COVER)), | |
| 'allowArray' => true, | |
| 'on' => self::SCENARIO_book,], | |
| [['juridic_activity'], 'in','range'=>array_keys(Activity::getList()), | |
| 'when' => function () { | |
| return $this->vehicle_owner_type!='physical'; | |
| }, | |
| 'on' => self::SCENARIO_book,], | |
| [['clearance_region'], 'in','range'=>array_keys(Region::getListId()+[0]), 'on' => self::SCENARIO_book,], | |
| [['clearance_country'], 'in','range'=>array_keys(Country::getCountry()), | |
| 'on' => self::SCENARIO_book,], | |
| [['rasrochka'], 'integer','min'=>0,'max'=>365*3, | |
| 'on' => self::SCENARIO_book,], | |
| [['payment_book_type'], 'in','range'=>array_keys(self::getPaymentbookType()), | |
| 'allowArray' => true, | |
| 'on' => self::SCENARIO_book,], | |
| [['probeg'], 'integer','min'=>0,'max'=>1000000, | |
| 'on' => self::SCENARIO_book,], | |
| [['karobka'], 'in','range'=>array_keys(self::getKarobkaType()), | |
| 'on' => self::SCENARIO_book,], | |
| [['tyuning'], 'in','range'=>array_keys(Equipment::getList()), | |
| 'allowArray' => true, | |
| 'when' => function () { | |
| return !in_array($this->vehicle_type,[7,8]); | |
| }, | |
| 'on' => self::SCENARIO_book,], | |
| [['privod'], 'in','range'=>array_keys(VehicleModel::getFormula()), | |
| 'when' => function () { | |
| return $this->vehicle_type==1; | |
| }, | |
| 'on' => self::SCENARIO_book,], | |
| [['eko_klass'], 'in','range'=>array_keys(VehicleModel::getEkoClass()), | |
| 'when' => function () { | |
| return in_array($this->vehicle_type,[1,2,3]); | |
| }, | |
| 'on' => self::SCENARIO_book,], | |
| [['koleso_formula'], 'in','range'=>array_keys(VehicleModel::getKolesoFormula()), | |
| 'when' => function () { | |
| return $this->vehicle_type==2; | |
| }, | |
| 'on' => self::SCENARIO_book,], | |
| [['massa1'], 'integer','min'=>0,'max'=>1000000, | |
| 'when' => function () { | |
| return in_array($this->vehicle_type,[2,5,6]); | |
| }, | |
| 'on' => self::SCENARIO_book,], | |
| [['massa2'], 'integer','min'=>0,'max'=>1000000, | |
| 'when' => function () { | |
| return $this->vehicle_type==2; | |
| }, | |
| 'on' => self::SCENARIO_book,], | |
| [['type_kuzov'], 'in','range'=>array_keys(VehicleModel::getTypeTruck()), | |
| 'when' => function () { | |
| return $this->vehicle_type==2; | |
| }, | |
| 'on' => self::SCENARIO_book,], | |
| [['yonilgi_turi'], 'in','range'=>array_keys(VehicleModel::getTypeDvigatel()), | |
| 'on' => self::SCENARIO_book,], | |
| [['type_electr'], 'in','range'=>array_keys(VehicleModel::getTypeElectr()), | |
| 'on' => self::SCENARIO_book,], | |
| [['electr_power','electr_count'], 'integer','min'=>0,'max'=>10000, | |
| 'on' => self::SCENARIO_book,], | |
| [['xadavoy'], 'in','range'=>array_keys(VehicleModel::getXadavoy()), | |
| 'when' => function () { | |
| return $this->vehicle_type==6; | |
| }, | |
| 'on' => self::SCENARIO_book,], | |
| [['parking'], 'in','range'=>array_keys(VehicleModel::getParking()), | |
| 'on' => self::SCENARIO_book,], | |
| [['signal'], 'in','range'=>array_keys(VehicleModel::getSinalization()), | |
| 'on' => self::SCENARIO_book,], | |
| [['permission'], 'in','range'=>array_keys(VehicleModel::getPermission()), | |
| 'allowArray' => true, | |
| 'on' => self::SCENARIO_book,], | |
| [['benifit'], 'in','range'=>array_keys(VehicleModel::getBinefitOwner()), | |
| 'on' => self::SCENARIO_book,], | |
| [['expire_at_book'], 'date','format'=>'yyyy-dd-mm','min'=>date('Y-m-d',strtotime(date('Y-m-d') . "+5 days")), | |
| 'on' => self::SCENARIO_book,], | |
| [['book_srok'], 'date','format'=>'yyyy-dd-mm', | |
| 'on' => self::SCENARIO_book,], | |
| [['remont'], 'in','range'=>array_keys(VehicleModel::getRemont()), | |
| 'on' => self::SCENARIO_book,], | |
| [['extra_services'], 'in','range'=>array_keys(VehicleModel::getExtraServices()), | |
| 'allowArray' => true, | |
| 'on' => self::SCENARIO_book,], | |
| [['product_id_book'], 'safe', | |
| 'on' => self::SCENARIO_table_book_DISCOUNT,], | |
| ]; | |
| } | |
| public function requiredAttribute($attr) | |
| { | |
| $items = $this->{$attr}; | |
| foreach ($items as $key=>$item) { | |
| if ($item=='') { | |
| $this->addError($attr.'['.$key.']',Yii::t('yii','{attribute} cannot be blank.}',[ | |
| 'attribute'=> $this->getAttributeLabel($attr) | |
| ])); | |
| } | |
| } | |
| } | |
| public function requiredAttributeRisk($attr) | |
| { | |
| $items = $this->{$attr}; | |
| $object = $this->book_type_object; | |
| foreach ($items as $key=>$item) { | |
| if ($object[$key]=="yes" && $item=='') { | |
| $this->addError($attr.'['.$key.']',Yii::t('yii','{attribute} cannot be blank.}',[ | |
| 'attribute'=> $this->getAttributeLabel($attr) | |
| ])); | |
| } | |
| } | |
| } | |
| /** | |
| * @param $order_id | |
| * @param $amount | |
| * @param $desc | |
| * @return string | |
| */ | |
| public static function paymeForm($order_id, $amount, $desc) | |
| { | |
| $html = '<form method="post" action="' . Yii::$app->params['payme_action'] . '" id="form-payme" >'; | |
| $html .= '<input type="hidden" name="merchant" value="' . Yii::$app->params['payme_merchant_id'] . '">'; | |
| $html .= '<input type="hidden" name="amount" value="' . $amount * 100 . '">'; | |
| $html .= '<input type="hidden" name="account[order_id]" value="' . $order_id . '">'; | |
| $html .= '<input type="hidden" name="lang" value="' . \Yii::$app->language . '">'; | |
| $html .= '<input type="hidden" name="description" value="' . $desc . '">'; | |
| $html .= Html::submitButton(Html::img('/images/payme.png', ['style' => 'width:100%']), ['class' => 'btn-default font-weight-bold btn btn-block p-t-30 p-b-30']); | |
| $html .= '</form>'; | |
| return $html; | |
| } | |
| /** | |
| * @param $data | |
| * @return string | |
| */ | |
| public static function getlibraryDriversName($data) | |
| { | |
| $a = ''; | |
| foreach ($data as $key => $item) { | |
| if ($key == 2) { | |
| $a .= Yii::t('yii', 'and others'); | |
| break; | |
| } | |
| $a .= $item['last_name'] . ' ' . $item['first_name'] . ' ' . $item['sure_name'] . ' ' . $item['driving_license'] . '<br>'; | |
| } | |
| return $a; | |
| } | |
| /** | |
| * @return array | |
| */ | |
| public static function driverCount() | |
| { | |
| return [ | |
| 0 => Yii::t('yii', 'No limits'), | |
| 1 => 1, | |
| 2 => 2, | |
| 3 => 3, | |
| 4 => 4, | |
| 5 => 5, | |
| ]; | |
| } | |
| /** | |
| * @param null $month | |
| * @return array|null | |
| */ | |
| public static function getViolationDriver($month = null) | |
| { | |
| $data = [ | |
| 'no' => \Yii::t('yii', 'Нет'), | |
| 'yes-two' => \Yii::t('yii', 'Да, привело к снижению именавой премии'), | |
| 'yes-three' => \Yii::t('yii', 'Да, привело к именавому слачаю'), | |
| 'yes-four' => \Yii::t('yii', 'Да, привело к увеличению именавой выплаты'), | |
| 'yes-five' => \Yii::t('yii', 'Да, привело к регрессным требованиям'), | |
| ]; | |
| if ($month) { | |
| return isset($data[$month]) ? $data[$month] : null; | |
| } else { | |
| return $data; | |
| } | |
| } | |
| /** | |
| * @param null $month | |
| * @return array|null | |
| */ | |
| public static function getlibraryStateDriver($month = null) | |
| { | |
| $data = [ | |
| 'first_ever_contract' => Yii::t('yii', 'Договор заключается впервые'), | |
| 'no_accidents_12' => \Yii::t('yii', 'Отсутствие именавых случаев в течение предыдущего именавого периода (за последние 12 месяцев)'), | |
| 'no_accidents_2_year' => \Yii::t('yii', 'Отсутствие именавых случаев в течение 2 предыдущих лет'), | |
| 'no_accidents_3_year' => \Yii::t('yii', 'Отсутствие именавых случаев в течение 3 предыдущих лет'), | |
| 'no_accidents_4_year' => \Yii::t('yii', 'Отсутствие именавых случаев в течение 4 предыдущих лет'), | |
| 'no_accidents_5_year' => \Yii::t('yii', 'Отсутствие именавых случаев в течение 5 предыдущих лет'), | |
| 'one_accident' => \Yii::t('yii', 'Один именавой случай, произошедший в период действия предыдущего договора обязательного именавания'), | |
| 'two_accident' => \Yii::t('yii', 'Два именавых случая, произошедших в период действия предыдущего договора обязательного именавания'), | |
| 'three_accident' => \Yii::t('yii', 'Три и более именавых случаев, произошедших в период действия предыдущего договора обязательного именавания'), | |
| ]; | |
| if ($month) { | |
| return isset($data[$month]) ? $data[$month] : null; | |
| } else { | |
| return $data; | |
| } | |
| } | |
| /** | |
| * @param null $type | |
| * @return array|null | |
| */ | |
| public static function getDiscountType($type = null) | |
| { | |
| $data = [ | |
| 'war-1941' => \Yii::t('yii', 'Участник или партизан войны 1941-1945 годов либо приравненное к ним лицо'), | |
| 'war-1941-front' => \Yii::t('yii', 'Ветеран трудового фронта периода войны 1941-1945 годов'), | |
| 'prisoner' => \Yii::t('yii', 'Бывший малолетний узник концентрационных лагерей'), | |
| 'war-front-wounded' => \Yii::t('yii', 'Один из родителей или вдова, не вступавшая в новый брак, военнослужащего, погибшего вследствие ранения, контузии или увечья, полученного при исполнении обязанностей военной службы либо вследствие заболевания, связанного с пребыванием на фронте'), | |
| 'chernobl-wounded' => \Yii::t('yii', 'Пострадавший в следствии аварии на Чернобыльской АЭС'), | |
| 'pensioner' => \Yii::t('yii', 'Пенсионер'), | |
| 'invalid' => \Yii::t('yii', 'Инвалид'), | |
| 'war-1989-afgan' => \Yii::t('yii', 'Военнослужащие и призванные на учебные и поверочные сборы военнообязанные, проходившие службу в составе ограниченного контингента войск, временно находившихся в Республике Афганистан и других странах, в которых велись боевые действия'), | |
| ]; | |
| if ($type) { | |
| return isset($data[$type]) ? $data[$type] : null; | |
| } else { | |
| return $data; | |
| } | |
| } | |
| /** | |
| * @param null $count | |
| * @return array|null | |
| */ | |
| public static function getDriverCount($count = null) | |
| { | |
| $data = [ | |
| 'no-limits' => \Yii::t('yii', 'No limits'), | |
| '1-5-drivers' => \Yii::t('yii', '1-5 drivers'), | |
| ]; | |
| if ($count) { | |
| return isset($data[$count]) ? $data[$count] : null; | |
| } else { | |
| return $data; | |
| } | |
| } | |
| /** | |
| * @return mixed | |
| */ | |
| public function getPaymentTypeText(){ | |
| return ArrayHelper::getValue(self::getPaymentType(),$this->payment_type); | |
| } | |
| /** | |
| * @param null $count | |
| * @return array|null | |
| */ | |
| public static function getPaymentType($count = null) | |
| { | |
| $data = [ | |
| 'terminal' => \Yii::t('yii', 'Via terminal'), | |
| 'cash' => \Yii::t('yii', 'Cash'), | |
| 'bank' => \Yii::t('yii', 'Via bank account'), | |
| 'click' => \Yii::t('yii', 'CLICK'), | |
| 'payme' => \Yii::t('yii', 'Payme'), | |
| ]; | |
| if ($count) { | |
| return isset($data[$count]) ? $data[$count] : null; | |
| } else { | |
| return $data; | |
| } | |
| } | |
| public static function getlibraryPeriod($month = null) | |
| { | |
| $data = [ | |
| // '214' => \Yii::t('yii', '7 months'), | |
| // '245' => \Yii::t('yii', '8 months'), | |
| // '275' => \Yii::t('yii', '9 months'), | |
| // '307' => \Yii::t('yii', '10 months'), | |
| // '338' => \Yii::t('yii', '11 months'), | |
| '366' => \Yii::t('yii', 'One year'), | |
| '183' => \Yii::t('yii', '6 months'), | |
| ]; | |
| if ($month) { | |
| return isset($data[$month]) ? $data[$month] : null; | |
| } else { | |
| return $data; | |
| } | |
| } | |
| public static function getlibraryUnregistered($month = null) | |
| { | |
| $data = [ | |
| '20' => \Yii::t('yii', '20 days'), | |
| ]; | |
| if ($month) { | |
| return isset($data[$month]) ? $data[$month] : null; | |
| } else { | |
| return $data; | |
| } | |
| } | |
| public static function getlibraryPeriodForeign($month = null) | |
| { | |
| $data = [ | |
| //'20' => \Yii::t('yii', 'Vehicles moving to registration premise for up to 20 days'), | |
| '15' => \Yii::t('yii', 'Up to 15 days'), | |
| // '31' => \Yii::t('yii', 'From 16 days to 2 months'), | |
| '61' => \Yii::t('yii', '2 months'), | |
| //'92' => \Yii::t('yii', '3 months'), | |
| //'122' => \Yii::t('yii', '4 months'), | |
| //'153' => \Yii::t('yii', '5 months'), | |
| //'183' => \Yii::t('yii', '6 months'), | |
| //'214' => \Yii::t('yii', '7 months'), | |
| //'245' => \Yii::t('yii', '8 months'), | |
| //'275' => \Yii::t('yii', '9 months'), | |
| //'307' => \Yii::t('yii', '10 months'), | |
| //'338' => \Yii::t('yii', '11 months'), | |
| '366' => \Yii::t('yii', 'One year'), | |
| ]; | |
| return $data; | |
| } | |
| public function attributeLabels() | |
| { | |
| return [ | |
| 'id' => Yii::t('yii', 'ID'), | |
| 'user_id' => Yii::t('yii', 'User'), | |
| 'canceled_date' => Yii::t('yii', 'Canceled time'), | |
| 'canceled_user' => Yii::t('yii', 'Canceled user'), | |
| 'product_id' => Yii::t('yii', 'Product ID'), | |
| 'library_number' => Yii::t('yii', 'library number'), | |
| 'vehicle_data' => Yii::t('yii', 'Vehicle Data'), | |
| 'driver_count' => Yii::t('yii', 'Driver Count'), | |
| 'library_data' => Yii::t('yii', 'library Data'), | |
| 'library_max_discount' => Yii::t('yii', 'library max discount'), | |
| 'status' => Yii::t('yii', 'Status'), | |
| 'expired_at' => Yii::t('yii', 'library period'), | |
| 'start_date' => Yii::t('yii', 'Start Date'), | |
| 'created_at' => Yii::t('yii', 'Created At'), | |
| 'user_identity' => Yii::t('yii', 'Passport or INN'), | |
| 'vehicle_body_number' => Yii::t('yii', 'Vehicle number or Body number'), | |
| 'vehicle_type' => Yii::t('yii', 'Vehicle Type'), | |
| 'brand' => Yii::t('yii', 'Brand'), | |
| 'energy_power' => Yii::t('yii', 'Energy Power'), | |
| 'horse_power' => Yii::t('yii', 'Horse Power'), | |
| 'weight' => Yii::t('yii', 'Weight'), | |
| 'suit' => Yii::t('yii', 'Suit'), | |
| 'vehicle_owner_type' => Yii::t('yii', 'Vehicle Owner Type'), | |
| 'vehicle_use_for_purpose' => Yii::t('yii', 'Vehicle Use For Purpose'), | |
| 'vehicle_model_id' => Yii::t('yii', 'Model'), | |
| 'created_date' => Yii::t('yii', 'Год выпуска'), | |
| 'register_location_id' => Yii::t('yii', 'Register Location'), | |
| // Step 2 | |
| 'last_name' => Yii::t('yii', 'Last Name'), | |
| 'first_name' => Yii::t('yii', 'First Name'), | |
| 'sure_name' => Yii::t('yii', 'Sure Name'), | |
| 'passport' => Yii::t('yii', 'Passport'), | |
| 'birth_day' => Yii::t('yii', 'Birth Day'), | |
| 'driving_license' => Yii::t('yii', 'Driving License'), | |
| 'driving_license_date' => Yii::t('yii', 'Дата получения'), | |
| 'library_state' => Yii::t('yii', 'именавые случаи'), | |
| 'violation' => Yii::t('yii', 'Нарушение правил именавания'), | |
| 'gender' => Yii::t('yii', 'Gender'), | |
| // Step 6 | |
| 'body_number' => Yii::t('yii', 'Body Number'), | |
| 'motor_number' => Yii::t('yii', 'Motor Number'), | |
| 'vehicle_number' => Yii::t('yii', 'Vehicle Number'), | |
| 'technical_passport' => Yii::t('yii', 'Technical Passport'), | |
| 'technical_passport_date' => Yii::t('yii', 'Дата выдачи техпаспорта'), | |
| 'technical_passport_file' => Yii::t('yii', 'Technical Passport file'), | |
| 'file' => Yii::t('yii', 'Technical Passport file'), | |
| 'discount' => Yii::t('yii', 'The libraryholder is entitled to a discount'), | |
| 'owner_phone_number' => Yii::t('yii', 'Phone Number'), | |
| 'owner_last_name' => Yii::t('yii', 'Last Name'), | |
| 'owner_first_name' => Yii::t('yii', 'First Name'), | |
| 'owner_sure_name' => Yii::t('yii', 'Sure Name'), | |
| 'owner_region_physical' => Yii::t('yii', 'Region'), | |
| 'owner_region_juridical' => Yii::t('yii', 'Region'), | |
| 'owner_name' => Yii::t('yii', 'Juridic name'), | |
| 'owner_passport' => Yii::t('yii', 'Owner passport'), | |
| 'owner_inn' => Yii::t('yii', 'Juridical Inn'), | |
| 'owner_address_juridical' => Yii::t('yii', 'Juridical address'), | |
| 'owner_address_physical' => Yii::t('yii', 'Address'), | |
| 'email' => Yii::t('yii', 'Email'), | |
| 'agent_id' => Yii::t('yii', 'Agent'), | |
| 'agent_benifit' => Yii::t('yii', 'Agent share'), | |
| 'phone_number' => Yii::t('yii', 'Phone Number'), | |
| 'file_discount' => Yii::t('yii', 'Confirmation document'), | |
| 'discount_file' => Yii::t('yii', 'Confirmation document'), | |
| 'discount_user_type' => Yii::t('yii', 'Availability of benefits'), | |
| 'discount_approved_user' => Yii::t('yii', 'Approved user'), | |
| 'discount_approved_at' => Yii::t('yii', 'Approved at'), | |
| 'payment_type' => Yii::t('yii', 'Payment type'), | |
| 'payment_date' => Yii::t('yii', 'Payment date'), | |
| 'payment_to_company_date' => Yii::t('yii', 'Payment date'), | |
| 'payment_to_company_number' => Yii::t('yii', 'Number of bank payment'), | |
| 'book_summa' => Yii::t('yii', 'именавая сумма'), | |
| 'book_type_object' => Yii::t('yii', 'Объект именавания'), | |
| 'book_risk' => Yii::t('yii', 'именавание от каких рисков'), | |
| 'juridic_activity' => Yii::t('yii', 'Вид деятельности именавателя'), | |
| 'clearance_region' => Yii::t('yii', 'Место жительства именавателя'), | |
| 'clearance_country' => | |
| ($this->vehicle_owner_type=='physical'? | |
| Yii::t('yii', 'Гражданство именавателя'): | |
| Yii::t('yii', 'Место гос.регистрации именавателя')), | |
| 'franshiza_type' => Yii::t('yii', 'Франшиза'), | |
| 'rasrochka' => Yii::t('yii', 'Рассрочка оплаты именавой премии'), | |
| 'payment_book_type' => Yii::t('yii', 'Выплата именавого возмещения'), | |
| 'probeg' => Yii::t('yii', 'Пробег'), | |
| 'yonilgi_turi' => Yii::t('yii', 'Вид топлива'), | |
| 'karobka' => Yii::t('yii', 'Коробка передач'), | |
| 'tyuning' => Yii::t('yii', 'Дополнительные опции'), | |
| 'cover' => Yii::t('yii', 'именавое покрытие какого имущества'), | |
| 'privod' => Yii::t('yii', 'Тип привода'), | |
| 'eko_klass' => Yii::t('yii', 'Экологический класс'), | |
| 'koleso_formula' => Yii::t('yii', 'Колесная формула'), | |
| 'massa1' => Yii::t('yii', 'Предельная масса'), | |
| 'massa2' => Yii::t('yii', 'Снаряженная масса'), | |
| 'type_kuzov' => Yii::t('yii', 'Тип кузова'), | |
| 'type_electr' => Yii::t('yii', 'Тип электродвигателя'), | |
| 'electr_power' => Yii::t('yii', 'Мощность электродвигателя'), | |
| 'electr_count' => Yii::t('yii', 'Количество электродвигателей'), | |
| 'xadavoy' => Yii::t('yii', 'Тип ходовой части'), | |
| 'parking' => Yii::t('yii', 'Место хранения авто'), | |
| 'signal' => Yii::t('yii', 'Сигнализация авто'), | |
| 'permission' => Yii::t('yii', 'Ограничения авто'), | |
| 'benifit' => Yii::t('yii', 'Выгодоприобретатель'), | |
| 'remont' => Yii::t('yii', 'Кто определяет ремонт авто'), | |
| 'extra_services' => Yii::t('yii', 'Дополнительно покрываемые услуги'), | |
| 'expire_at_book' => Yii::t('yii', 'Когда истекает гарантийное обслуживание авто'), | |
| 'bank_name' => Yii::t('yii', 'Название банка'), | |
| 'bank_inn' => Yii::t('yii', 'ИНН'), | |
| ]; | |
| } | |
| public static function getKarobkaType() | |
| { | |
| return [ | |
| 'automatic'=>Yii::t('yii','Автомат'), | |
| 'manual'=>Yii::t('yii','Механик'), | |
| ]; | |
| } | |
| public static function getPaymentbookType() | |
| { | |
| return [ | |
| 'value1'=>Yii::t('yii','Паушально'), | |
| 'value2'=>Yii::t('yii','По системе именавания мест'), | |
| 'value3'=>Yii::t('yii','"Старое за старое"'), | |
| 'value4'=>Yii::t('yii','"Новое за старое"'), | |
| 'value5'=>Yii::t('yii','Пропорционально'), | |
| 'value6'=>Yii::t('yii','По первому риску,'), | |
| ]; | |
| } | |
| public static function getFranshizaType() | |
| { | |
| return [ | |
| 'yes'=>Yii::t('yii','Условная'), | |
| 'no'=>Yii::t('yii','Безусловная'), | |
| ]; | |
| } | |
| public static function getbookTypeSumma() | |
| { | |
| return [ | |
| 'aggregate'=>Yii::t('yii','Агрегатная'), | |
| 'nonaggregate'=>Yii::t('yii','Неагрегатная'), | |
| ]; | |
| } | |
| public static function getbookTypeObject() | |
| { | |
| return [ | |
| 'yes'=>Yii::t('yii','Стоимость авто'), | |
| 'no'=>Yii::t('yii','Ответетственность перед третьими лицами сверх СОКТ'), | |
| ]; | |
| } | |
| public function upload() | |
| { | |
| $year = date('Y'); | |
| $month = date('m'); | |
| $uploadDir = '/upload/technical-passport/' .$year.'/'.$month.'/'; | |
| if (!is_dir(Yii::$app->basePath . '/web' . $uploadDir)) | |
| mkdir(Yii::$app->basePath . '/web' . $uploadDir, 0777, true); | |
| $uploadedFile = UploadedFile::getInstance($this, 'file'); | |
| if ($uploadedFile !== NULL) { | |
| $newFileName = $this->library_number . '.' . $uploadedFile->extension; | |
| $uploadedFile->saveAs(Yii::$app->basePath . '/web' . $uploadDir.'/' . $newFileName); | |
| $this->technical_passport_file = $uploadDir . $newFileName; | |
| $this->file = $uploadDir . $newFileName; | |
| } | |
| } | |
| public function uploadDiscount() | |
| { | |
| $year = date('Y'); | |
| $month = date('m'); | |
| $uploadDir = '/upload/discount/' . $year.'/'.$month.'/'; | |
| //create upload dir for user not exist | |
| if (!is_dir(Yii::$app->basePath . '/web' . $uploadDir)) | |
| mkdir(Yii::$app->basePath . '/web' . $uploadDir, 0777, true); | |
| $uploadedFile = UploadedFile::getInstance($this, 'file_discount'); | |
| if ($uploadedFile !== NULL) { | |
| $newFileName = $this->library_number . '.' . $uploadedFile->extension; | |
| $uploadedFile->saveAs(Yii::$app->basePath . '/web' . $uploadDir.'/' . $newFileName); | |
| $this->file_discount = $uploadDir . $newFileName; | |
| $this->discount_file = $uploadDir . $newFileName; | |
| } | |
| } | |
| /** | |
| * @param bool $download | |
| * @return bool | |
| * @throws \Mpdf\MpdfException | |
| */ | |
| public function getlibraryPdf($download = true,$book=false) | |
| { | |
| $active = true; | |
| if (date('Y-m-d', strtotime($this->start_date . '+' . $this->expired_at . ' day')) < date('Y-m-d')) { | |
| $active = false; | |
| }elseif ($this->status != self::STATE_PAY_ACCEPTED) { | |
| $active = false; | |
| } elseif ($this->discount == 1 and $this->discount_status == 0) { | |
| $active = false; | |
| } | |
| if ($this->html_pdf_content == '') { | |
| if ($this->product->product_type_id==ProductType::book) { | |
| $this->createlibrarybookPdf(); | |
| }else{ | |
| $this->createlibraryPdf(); | |
| } | |
| } | |
| $mpdf = new Mpdf([ | |
| 'format' => $book?'A4':'A5', | |
| // 'default_font_size'=>11, | |
| // 'default_font'=>'Times New Roman', | |
| 'margin_top' => 5, | |
| 'margin_bottom'=>7, | |
| ]); | |
| if (!$active) { | |
| $mpdf->SetWatermarkText(Yii::t('yii', 'Inactive')); | |
| $mpdf->showWatermarkText = true; | |
| } | |
| $stylesheet2 = file_get_contents(Yii::$app->basePath . '/web/css/pdf.css'); | |
| $stylesheet = file_get_contents(Yii::$app->basePath . ($book?'/web/css/book.css': ($this->driver_count=='no-limits' ? '/web/css/table.css' : '/web/css/table-limit.css'))); | |
| // $stylesheet = file_get_contents(Yii::$app->basePath . '/web/frontend/libs/bootstrap3/css/bootstrap.min.css'); | |
| $mpdf->WriteHTML($stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS); | |
| $mpdf->WriteHTML($stylesheet2, \Mpdf\HTMLParserMode::HEADER_CSS); | |
| $mpdf->WriteHTML($this->html_pdf_content); | |
| if ($download) { | |
| $mpdf->Output($this->library_number . '.pdf', 'D'); | |
| } else { | |
| $mpdf->Output(); | |
| } | |
| } | |
| /** | |
| * @param bool $hard | |
| * @return bool | |
| * @throws \yii\base\InvalidConfigException | |
| */ | |
| public function createlibraryPdf($hard=false) | |
| { | |
| if ($this->html_pdf_content != '' and !$hard) { | |
| return true; | |
| } | |
| if ($this->driver_count == 'no-limits') { | |
| $library = Item::find()->where(['slug' => 'library-unlimited'])->asArray()->one(); | |
| $html = ''; | |
| if ($library != null) { | |
| $aa = Json::decode($library['content']); | |
| $count = count($aa); | |
| $i=1; | |
| foreach ($aa as $item) { | |
| $html .= $item; | |
| if($count!=$i){ | |
| // $html .= '<pagebreak />'; | |
| } | |
| $i++; | |
| } | |
| } else { | |
| return false; | |
| } | |
| $search = [ | |
| '$library_series','$library_number', | |
| '$start_day', '$start_month', '$start_year', '$end_day', '$end_month', '$end_year', | |
| '$company_name', '$company_address', '$company_rekvizit', '$car_owner', '$owner_address', | |
| '$phone1','$phone2','$phone3','$phone4','$phone5','$phone6','$phone7','$phone8','$phone9', | |
| '$aphone10', '$bphone11', '$cphone12', | |
| '$car_model', '$car_year', '$motor_number', '$vin_code', '$car_number', | |
| '$owner_work', '$library_used_location', | |
| '$library_summa', '$librarysummatext', '$summa_end', '$summaendtext', | |
| '$discount', '$textdiscount', '$summaend2', '$end2summtext', | |
| '$company_location','$signature','$fsignature_person','$dsignature_shtamp', | |
| '$day', '$month', '$year', '$hour','$minute','$company_image', '$qr_code' | |
| ]; | |
| }else { | |
| $library = Item::find()->where(['slug' => 'library-limited'])->asArray()->one(); | |
| $html = ''; | |
| if ($library != null) { | |
| $aa = Json::decode($library['content']); | |
| $count = count($aa); | |
| $i=1; | |
| foreach ($aa as $item) { | |
| $html .= $item; | |
| if($count!=$i){ | |
| //$html .= '<pagebreak />'; | |
| } | |
| $i++; | |
| } | |
| } else { | |
| return false; | |
| } | |
| $search = [ | |
| '$library_series', '$library_number', | |
| '$start_day', '$start_month', '$start_year', '$end_day', '$end_month', '$end_year', | |
| '$company_name', '$company_address', '$company_rekvizit', '$car_owner', '$owner_address', | |
| '$phone1', '$phone2', '$phone3', '$phone4', '$phone5', '$phone6', '$phone7', '$phone8', '$phone9', | |
| '$aphone10', '$bphone11', '$cphone12', | |
| '$car_model', '$car_year', '$motor_number', '$vin_code', '$car_number', | |
| '$owner_work', '$library_used_location', | |
| '$driver_1_l', '$driver_1_f', '$driver_1_s', '$driverseries_1', '$drivernumber_1', | |
| '$driver_2_l', '$driver_2_f', '$driver_2_s', '$driverseries_2', '$drivernumber_2', | |
| '$driver_3_l', '$driver_3_f', '$driver_3_s', '$driverseries_3', '$drivernumber_3', | |
| '$driver_4_l', '$driver_4_f', '$driver_4_s', '$driverseries_4', '$drivernumber_4', | |
| '$driver_5_l', '$driver_5_f', '$driver_5_s', '$driverseries_5', '$drivernumber_5', | |
| '$library_summa', '$librarysummatext', '$summa_end', '$summaendtext', | |
| '$discount', '$textdiscount', '$summaend2', '$end2summtext', | |
| '$company_location', '$signature', '$fsignature_person', '$dsignature_shtamp', | |
| '$day', '$month', '$year', '$hour', '$minute', '$company_image', '$qr_code' | |
| ]; | |
| } | |
| if ($this->vehicle_owner_type != 'physical') { | |
| $owner_name = $this->owner_name; | |
| $owner_address = $this->owner_inn . ', ' . Province::getRegionName($this->owner_region_juridical) . ', ' . $this->owner_address_juridical; | |
| } else { | |
| $owner_name = $this->owner_last_name . ' ' . $this->owner_first_name . ' ' . $this->owner_sure_name; | |
| $owner_address = $this->owner_passport . ', ' . Province::getRegionName($this->owner_region_physical) . ', ' . $this->owner_address_physical; | |
| } | |
| // $owner_work = 'Savdo sohasi'; | |
| $owner_work = '---'; | |
| // $library_used_location = Province::getRegionName($this->register_location_id); | |
| $library_used_location = Country::getCountryName(229); | |
| $library_number = explode('-',$this->library_number); | |
| $phone_1 = $phone_2 = $phone_3 = $phone_4 = $phone_5 = $phone_6 = $phone_7 = $phone_8 = $phone_9 = $phone_10 = $phone_11 = $phone_12 = '-'; | |
| if($this->owner_phone_number!=''){ | |
| $phone_1 = 9; | |
| $phone_2 = 9; | |
| $phone_3 = 8; | |
| $l = preg_replace('/\D+/', '', $this->owner_phone_number); | |
| $a = str_split($l); | |
| list($phone_4, $phone_5, $phone_6, $phone_7, $phone_8, $phone_9, $phone_10, $phone_11, $phone_12) = $a; | |
| } | |
| $replacement = [ | |
| $library_number[0],$library_number[1], | |
| date('d', strtotime($this->start_date)), Functions::getMonth(date('F', strtotime($this->start_date))), date('Y', strtotime($this->start_date)), | |
| date('d', strtotime($this->start_date . '+' . $this->expired_at . ' day')), Functions::getMonth(date('F', strtotime($this->start_date . '+' . $this->expired_at . ' day'))), date('Y', strtotime($this->start_date . '+' . $this->expired_at . ' day')), | |
| Functions::getLanguageValue($this->product->company->name), | |
| Functions::getLanguageValue($this->product->company->address) . ', ' . | |
| Yii::t('yii', 'Phone') . ': ' . $this->product->company->phone_number . ', ' . | |
| Yii::t('yii', 'Fax') . ': ' . $this->product->company->fax . ', ' . $this->product->company->email, | |
| Yii::t('yii', 'a/n') . ': ' . $this->product->company->bank_account_number . ', ' . | |
| Yii::t('yii', 'Tin') . ': ' . $this->product->company->tin . ' ' . ', ' . | |
| Yii::t('yii', 'Bank Bin') . ': ' . $this->product->company->bank_bin . ', ' . | |
| Yii::t('yii', 'Bank') . ': ' . $this->product->company->bank_name, | |
| $owner_name, $owner_address, | |
| $phone_1,$phone_2,$phone_3,$phone_4,$phone_5,$phone_6,$phone_7,$phone_8,$phone_9,$phone_10,$phone_11,$phone_12, | |
| Functions::getLanguageValue($this->vehicleModel->brand->name) . ',' . Functions::getLanguageValue($this->vehicleModel->name), | |
| $this->created_date, $this->motor_number, $this->body_number, $this->vehicle_number, | |
| $owner_work, | |
| $library_used_location, | |
| ]; | |
| if ($this->driver_count == 'no-limits') { | |
| } else { | |
| for ($i = 0; $i < 5; $i++) { | |
| $s = isset($this->libraryDrivers[$i]->driving_license)? | |
| preg_replace('/[^A-Z]/','',$this->libraryDrivers[$i]->driving_license??'---'):'---'; | |
| $n = preg_replace('/[A-Z]/','',$this->libraryDrivers[$i]->driving_license??'---'); | |
| $replacement[] = $this->libraryDrivers[$i]->last_name ?? '---'; | |
| $replacement[] = $this->libraryDrivers[$i]->first_name ??'---'; | |
| $replacement[] = $this->libraryDrivers[$i]->last_name ?? '---'; | |
| $replacement[] = $s; | |
| $replacement[] = $n; | |
| } | |
| } | |
| $replacement[] = number_format($this->product->productType->commission,0,'.',' '); | |
| $replacement[] = Functions::convertNumberToWord(round($this->product->productType->commission)) .'/'. | |
| Yii::$app->formatter->asSpellout(round($this->product->productType->commission)); | |
| $replacement[] = number_format($this->library_summa,0,'.',' ');; | |
| $replacement[] = Functions::convertNumberToWord(round($this->library_summa)).'/'. | |
| Yii::$app->formatter->asSpellout(round($this->library_summa)); | |
| $replacement[] = $this->discount>0? | |
| // number_format($this->library_summa - $this->library_summa_end2,0,'.',' '):'---'; | |
| number_format($this->library_summa/2,0,'.',' '):'---'; | |
| $replacement[] = | |
| $this->discount>0?(Yii::$app->language=='uz'?Functions::convertNumberToWord(round($this->library_summa - $this->library_summa_end2)): | |
| Yii::$app->formatter->asSpellout(round($this->library_summa - $this->library_summa_end2))):'---'; | |
| $replacement[] = number_format($this->library_summa_end2,0,'.',' '); | |
| $replacement[] = Functions::convertNumberToWord(round($this->library_summa_end2)).'/'. | |
| Yii::$app->formatter->asSpellout(round($this->library_summa_end2)); | |
| // $replacement[] = Province::getRegionName($this->owner_region_physical); | |
| $replacement[] = '---'; | |
| $replacement[] = ''; //$signature | |
| $replacement[] = ''; //$signatureperson | |
| $replacement[] = ''; //$signatureshtamp | |
| $replacement[] = date('d'); | |
| $replacement[] = Functions::getMonth(date('F')); | |
| $replacement[] = date('Y'); | |
| $replacement[] = date('H'); | |
| $replacement[] = date('m'); | |
| $replacement[] = '<div class="text-center">' . Html::img($this->product->company->logo, ['style' => 'width:200px;margina:auto']) . '</div>'; | |
| $library_view_url = Url::to(['library/print', 'library_number' => $this->library_number], true); | |
| // echo "<pre>"; | |
| // print_r( $search ); | |
| // print_r( $replacement ); | |
| // exit; | |
| $qrCode = new QrCode(); | |
| $qrCode->setSize(250); | |
| $qrCode->setValidateResult(false); | |
| $qrCode->setBackgroundColor([ | |
| 'r' => 113, | |
| 'g' => 228, | |
| 'b' => 255, | |
| ]); | |
| $qrCode->setText($library_view_url); | |
| $replacement[] = '<div class="text-center">' . Html::img($qrCode->writeDataUri()) . '</div>'; | |
| $content = str_replace($search, $replacement, $html); | |
| $this->html_pdf_content = $content; | |
| //$this->save(false, ['html_pdf_content']); | |
| return true; | |
| } | |
| public function createlibrarybookPdf($hard=false) | |
| { | |
| if ($this->html_pdf_content != '' and !$hard) { | |
| return true; | |
| } | |
| if ($this->driver_count == 'no-limits') { | |
| $library = Item::find()->where(['slug' => 'library-book-unlimited'])->asArray()->one(); | |
| $html = ''; | |
| if ($library != null) { | |
| $aa = Json::decode($library['content']); | |
| $count = count($aa); | |
| $i=1; | |
| foreach ($aa as $item) { | |
| $html .= $item; | |
| if($count!=$i){ | |
| $html .= '<pagebreak />'; | |
| } | |
| $i++; | |
| } | |
| } else { | |
| return false; | |
| } | |
| $search = [ | |
| '$company_image','$company_name', | |
| '$day', '$month', '$year', | |
| '$library_series','$library_number', | |
| '$start_day', '$start_month', '$start_year', | |
| '$end_day', '$end_month', '$end_year', | |
| '$time', | |
| '$car_owner', | |
| '$owner_address', | |
| '$owner_idintity', | |
| '$beneficiary', | |
| '$car_brand', | |
| '$car_model', | |
| '$car_year', | |
| '$vin_code', | |
| '$motor_number', | |
| '$car_number', | |
| '$tyuning', | |
| '$permission', | |
| '$risk', | |
| '$rasrochka', '$payment_book_type', '$signal', '$remont','$extra_services', '$qr_code', | |
| ]; | |
| }else { | |
| $library = Item::find()->where(['slug' => 'library-book-limited'])->asArray()->one(); | |
| $html = ''; | |
| if ($library != null) { | |
| $aa = Json::decode($library['content']); | |
| $count = count($aa); | |
| $i=1; | |
| foreach ($aa as $item) { | |
| $html .= $item; | |
| if($count!=$i){ | |
| $html .= '<pagebreak />'; | |
| } | |
| $i++; | |
| } | |
| } else { | |
| return false; | |
| } | |
| $search = [ | |
| '$company_image','$company_name','$day', '$month', '$year', '$library_series','$library_number', | |
| '$start_day', '$start_month', '$start_year', '$end_day', '$end_month', '$end_year','$time', | |
| '$car_owner', '$owner_address', '$owner_idintity', '$beneficiary', | |
| '$car_brand','$car_model', '$car_year', '$vin_code', '$motor_number','$car_number', | |
| '$tyuning', '$permission', | |
| '$driver_1_name', '$driver_1_liecince', | |
| '$driver_2_name', '$driver_2_liecince', | |
| '$driver_3_name', '$driver_3_liecince', | |
| '$driver_4_name', '$driver_4_liecince', | |
| '$driver_5_name', '$driver_5_liecince', | |
| '$risk', | |
| '$rasrochka', '$payment_book_type', '$signal', '$remont','$extra_services', '$qr_code', | |
| ]; | |
| } | |
| if ($this->vehicle_owner_type != 'physical') { | |
| $owner_name = $this->owner_name; | |
| $owner_address = Province::getRegionName($this->owner_region_juridical) . ', ' . $this->owner_address_juridical; | |
| $owner_idintity = $this->owner_inn; | |
| } else { | |
| $owner_name = $this->owner_last_name . ' ' . $this->owner_first_name . ' ' . $this->owner_sure_name; | |
| $owner_address = Province::getRegionName($this->owner_region_physical) . ', ' . $this->owner_address_physical; | |
| $owner_idintity = $this->owner_passport; | |
| } | |
| $library_number = explode('-',$this->library_number); | |
| $beneficiary = $this->beneficiary??Yii::t('yii','Insurer'); | |
| $tyuning = []; | |
| if ($this->tyuning) { | |
| foreach ($this->tyuning as $item) { | |
| $tyuning[] = ArrayHelper::getValue(Equipment::getList(),$item); | |
| } | |
| } | |
| $permission = []; | |
| if ($this->permission) { | |
| foreach ($this->permission as $item) { | |
| $permission[] = ArrayHelper::getValue(VehicleModel::getPermission(),$item); | |
| } | |
| } | |
| $time =date('H').":".date('i'); | |
| $replacement = [ | |
| '<div class="text-center">' . Html::img($this->product->company->logo, ['style' => 'width:200px;margina:auto']) . '</div>', | |
| Functions::getLanguageValue($this->product->company->name), | |
| date('d'), | |
| Functions::getMonth(date('F')), | |
| date('Y'), | |
| $library_number[0],$library_number[1], | |
| date('d', strtotime($this->start_date)), | |
| Functions::getMonth(date('F', strtotime($this->start_date))), | |
| date('Y', strtotime($this->start_date)), | |
| date('d', strtotime($this->start_date . '+' . $this->expired_at . ' day')), | |
| Functions::getMonth(date('F', strtotime($this->start_date . '+' . $this->expired_at . ' day'))), | |
| date('Y', strtotime($this->start_date . '+' . $this->expired_at . ' day')), | |
| $time, | |
| $owner_name, | |
| $owner_address, | |
| $owner_idintity, | |
| $beneficiary, | |
| Functions::getLanguageValue($this->vehicleModel->brand->name), | |
| Functions::getLanguageValue($this->vehicleModel->name), | |
| $this->created_date, | |
| $this->body_number, | |
| $this->motor_number, | |
| $this->vehicle_number, | |
| !empty($tyuning)?implode(',<br>',$tyuning):'---', | |
| !empty($permission)?implode(', ',$permission):'---', | |
| ]; | |
| if ($this->driver_count != 'no-limits') { | |
| for ($i = 0; $i < 5; $i++) { | |
| $name = []; | |
| $s = isset($this->libraryDrivers[$i]->driving_license)? | |
| preg_replace('/[^A-Z]/','',$this->libraryDrivers[$i]->driving_license??'---'):'---'; | |
| $n = preg_replace('/[A-Z]/','',$this->libraryDrivers[$i]->driving_license??'---'); | |
| $name[] = $this->libraryDrivers[$i]->last_name ??null; | |
| $name[] = $this->libraryDrivers[$i]->first_name ??null; | |
| $name[] = $this->libraryDrivers[$i]->last_name ??null; | |
| $name = array_filter($name); | |
| $replacement[] = !empty($name)?implode(' ',$name):'---'; | |
| $replacement[] = $s.'-'.$n; | |
| } | |
| } | |
| $extra_services = []; | |
| if ($this->extra_services) { | |
| foreach ($this->extra_services as $item) { | |
| $extra_services[] = ArrayHelper::getValue(VehicleModel::getExtraServices(),$item); | |
| } | |
| } | |
| $risks = '<table class="table table-bordered" style="width: 100%;"> | |
| <colgroup> | |
| <col style="text-align: center;" /> | |
| <col style="text-align: center;" /> | |
| <col style="text-align: center;" /> | |
| <col style="text-align: center;" /> | |
| <col style="text-align: center;" /> | |
| <col style="text-align: center;" /> | |
| </colgroup> | |
| <thead> | |
| <tr> | |
| <td colspan="6"> | |
| <center style="text-align: center;"><strong>'.Yii::t('yii','именавание осуществляется по рискам').':</strong></center> | |
| </td> | |
| </tr> | |
| <tr> | |
| <td rowspan="2"> | |
| <p style="text-align: center;"><strong>'.Yii::t('yii','Риск').'</strong></p> | |
| </td> | |
| <td rowspan="2"> | |
| <p style="text-align: center;"><strong>'.Yii::t('yii','Объект именавания').'</strong></p> | |
| </td> | |
| <td colspan="2"> | |
| <p style="text-align: center;"><strong>'.Yii::t('yii','именавая сумма').'</strong></p> | |
| </td> | |
| <td rowspan="2"> | |
| <p style="text-align: center;"><strong>'.Yii::t('yii','Франшиза').'</strong></p> | |
| </td> | |
| <td rowspan="2"> | |
| <p style="text-align: center;"><strong>'.Yii::t('yii','именавая премия').'</strong></p> | |
| </td> | |
| </tr> | |
| <tr> | |
| <td> | |
| <p style="text-align: center;"><strong>'.Yii::t('yii','Размер').'</strong></p> | |
| </td> | |
| <td> | |
| <p style="text-align: center;"><strong>'.Yii::t('yii','Тип').'</strong></p> | |
| </td> | |
| </tr> | |
| </thead>'; | |
| $risk = $this->risk_summas[$this->product->company_id]??$this->risk_summas; | |
| foreach ($risk as $key=>$item) { | |
| $risks .='<tr> | |
| <td><p style="text-align: center;">'.(ArrayHelper::getValue(Common::getList(Common::TYPE_RISK),$this->book_risk[$key]??'')).'</p></td> | |
| <td><p style="text-align: center;">'.(ArrayHelper::getValue(library::getbookTypeObject(),$this->book_type_object[$key]??'')).'</p></td> | |
| <td><p style="text-align: right;">'.(Yii::$app->formatter->asDecimal($this->book_summa[$key]??'')).'</p></td> | |
| <td><p style="text-align: center;">'.(ArrayHelper::getValue(library::getbookTypeSumma(),$this->book_type_summa[$key]??'')).'</p></td> | |
| <td><p style="text-align: center;">'.(((isset($this->franshiza_percent[$key]) and $this->franshiza_percent[$key]>0)?$this->franshiza_percent[$key].'%':' ').'<br>'. | |
| (ArrayHelper::getValue(library::getFranshizaType(),$this->franshiza_type[$key]??''))).'</p></td> | |
| <td><p style="text-align: right;">'.(Yii::$app->formatter->asDecimal($item,1)).'</p></td> | |
| </tr>'; | |
| } | |
| $risks .='<tr> | |
| <td colspan="5">'.(Yii::t('yii','Итого')).'</p></td> | |
| <td><p style="text-align: right;">'.(Yii::$app->formatter->asDecimal(array_sum($risk),1)).'</p></td> | |
| </tr> | |
| </table>'; | |
| $replacement[] = $risks; | |
| $replacement[] = $this->rasrochka; | |
| $replacement[] = $this->payment_book_type?ArrayHelper::getValue(self::getPaymentbookType(),$this->payment_book_type):'---'; | |
| $replacement[] = $this->signal?ArrayHelper::getValue(VehicleModel::getSinalization(),$this->signal):'---'; | |
| $replacement[] = $this->remont?ArrayHelper::getValue(VehicleModel::getRemont(),$this->remont):'---'; | |
| $replacement[] = !empty($extra_services)?implode(', ',$extra_services):'---'; | |
| $library_view_url = Url::to(['library/print', 'library_number' => $this->library_number], true); | |
| $qrCode = new QrCode(); | |
| $qrCode->setSize(250); | |
| $qrCode->setValidateResult(false); | |
| $qrCode->setBackgroundColor([ | |
| 'r' => 113, | |
| 'g' => 228, | |
| 'b' => 255, | |
| ]); | |
| $qrCode->setText($library_view_url); | |
| $replacement[] = '<div class="text-center">' . Html::img($qrCode->writeDataUri()) . '</div>'; | |
| $content = str_replace($search, $replacement, $html); | |
| $this->html_pdf_content = $content; | |
| $this->save(false, ['html_pdf_content']); | |
| return true; | |
| } | |
| public function createlibraryPdfOld($hard=false) | |
| { | |
| if ($this->html_pdf_content != '' and !$hard) { | |
| return true; | |
| } | |
| $library = Item::find()->where(['slug' => 'library'])->asArray()->one(); | |
| if ($library != null) { | |
| $html = Functions::getLanguageValue($library['content']); | |
| } else { | |
| return false; | |
| } | |
| $search = [ | |
| '$library_number', | |
| '$start_day', '$start_month', '$start_year', '$end_day', '$end_month', '$end_year','$time', | |
| '$company_name', '$company_address', '$company_rekvizit', '$car_owner', '$owner_address', '$car_model', '$car_year', | |
| '$motor_number', '$vin_code', '$car_number', '$owner_work', '$library_used_location', | |
| '$no_limit', '$only_this_drivers', '$driver_1', '$driver1licence', | |
| '$driver_2', '$driver2licence', '$driver_3', '$driver3licence', '$driver_4', | |
| '$driver4licence', '$driver_5', '$driver5licence', | |
| '$library_summa', '$librarysummatext', '$summa_end', '$summaendtext', | |
| '$discount', '$textdiscount', '$summaend2', '$end2summtext', | |
| '$day', '$month', '$year', '$company_image', '$qr_code' | |
| ]; | |
| if ($this->vehicle_owner_type != 'physical') { | |
| $owner_name = $this->owner_name; | |
| $owner_address = $this->owner_inn . ', ' . Province::getRegionName($this->owner_region_juridical) . ', ' . $this->owner_address_juridical; | |
| } else { | |
| $owner_name = $this->owner_last_name . ' ' . $this->owner_first_name . ' ' . $this->owner_sure_name; | |
| $owner_address = $this->owner_passport . ', ' . Province::getRegionName($this->owner_region_physical) . ', ' . $this->owner_address_physical; | |
| } | |
| // $owner_work = 'Savdo sohasi'; | |
| $owner_work = ''; | |
| // $library_used_location = Province::getRegionName($this->register_location_id); | |
| $library_used_location = Country::getCountryName(229); | |
| $replacement = [ | |
| $this->library_number, | |
| date('d', strtotime($this->start_date)), Functions::getMonth(date('F', strtotime($this->start_date))), date('Y', strtotime($this->start_date)), | |
| date('d', strtotime($this->start_date . '+' . $this->expired_at . ' day')), Functions::getMonth(date('F', strtotime($this->start_date . '+' . $this->expired_at . ' day'))), date('Y', strtotime($this->start_date . '+' . $this->expired_at . ' day')), | |
| Functions::getLanguageValue($this->product->company->name), | |
| Functions::getLanguageValue($this->product->company->address) . ', ' . | |
| Yii::t('yii', 'Phone') . ': ' . $this->product->company->phone_number . ', ' . | |
| Yii::t('yii', 'Fax') . ': ' . $this->product->company->fax . ', ' . $this->product->company->email, | |
| Yii::t('yii', 'a/n') . ': ' . $this->product->company->bank_account_number . ', ' . | |
| Yii::t('yii', 'Tin') . ': ' . $this->product->company->tin . ' ' . ', ' . | |
| Yii::t('yii', 'Bank Bin') . ': ' . $this->product->company->bank_bin . ', ' . | |
| Yii::t('yii', 'Bank') . ': ' . $this->product->company->bank_name, | |
| $owner_name, $owner_address, Functions::getLanguageValue($this->vehicleModel->brand->name) . ', ' . Functions::getLanguageValue($this->vehicleModel->name), | |
| $this->created_date, $this->motor_number, $this->body_number, $this->vehicle_number, | |
| $owner_work, | |
| $library_used_location, | |
| ]; | |
| if ($this->driver_count == 'no-limits') { | |
| $replacement[] = '<strong style="text-decoration: underline">' . Yii::t('yii', "Без ограничений") . '</strong>'; | |
| $replacement[] = Yii::t('yii', 'только следующие водители'); | |
| $replacement[] = Yii::t('yii', 'No'); | |
| $replacement[] = Yii::t('yii', 'No'); | |
| $replacement[] = Yii::t('yii', 'No'); | |
| $replacement[] = Yii::t('yii', 'No'); | |
| $replacement[] = Yii::t('yii', 'No'); | |
| $replacement[] = Yii::t('yii', 'No'); | |
| $replacement[] = Yii::t('yii', 'No'); | |
| $replacement[] = Yii::t('yii', 'No'); | |
| $replacement[] = Yii::t('yii', 'No'); | |
| $replacement[] = Yii::t('yii', 'No'); | |
| } else { | |
| $replacement[] = Yii::t('yii', 'Без ограничений'); | |
| $replacement[] = '<strong style="text-decoration: underline">' . Yii::t('yii', 'только следующие водители') . '</strong>'; | |
| for ($i = 0; $i < 5; $i++) { | |
| $replacement[] = isset($this->libraryDrivers[$i]) ? $this->libraryDrivers[$i]->getFullName() : Yii::t('yii', 'No'); | |
| $replacement[] = isset($this->libraryDrivers[$i]) ? $this->libraryDrivers[$i]->driving_license : Yii::t('yii', 'No'); | |
| } | |
| } | |
| $replacement[] = number_format($this->product->productType->commission,0,'.',' '); | |
| $replacement[] = number_format($this->product->productType->commission,0,'.',' '); | |
| $replacement[] = number_format($this->library_summa,0,'.',' ');; | |
| $replacement[] = number_format($this->library_summa,0,'.',' ');; | |
| $replacement[] = number_format($this->library_summa - $this->library_summa_end2,0,'.',' '); | |
| $replacement[] = number_format($this->library_summa - $this->library_summa_end2,0,'.',' '); | |
| $replacement[] = number_format($this->library_summa_end2,0,'.',' '); | |
| $replacement[] = number_format($this->library_summa_end2,0,'.',' '); | |
| $replacement[] = date('d'); | |
| $replacement[] = Functions::getMonth(date('F')); | |
| $replacement[] = date('Y'); | |
| $replacement[] = '<div class="text-center">' . Html::img($this->product->company->logo, ['style' => 'width:200px;margina:auto']) . '</div>'; | |
| $library_view_url = Url::to(['library/print', 'library_number' => $this->library_number], true); | |
| $qrCode = new QrCode(); | |
| $qrCode->setSize(250); | |
| $qrCode->setValidateResult(false); | |
| $qrCode->setText($library_view_url); | |
| $replacement[] = '<div class="text-center">' . Html::img($qrCode->writeDataUri()) . '</div>'; | |
| $content = str_replace($search, $replacement, $html); | |
| $this->html_pdf_content = $content; | |
| $this->save(false, ['html_pdf_content']); | |
| return true; | |
| } | |
| public function deleteFile($file) | |
| { | |
| $uploadDir = Yii::$app->basePath . '/web'; | |
| if ($file and file_exists($uploadDir . $file)) { | |
| @unlink($uploadDir . $file); | |
| } | |
| } | |
| public function setSessionValues() | |
| { | |
| $this->setCustomAttributes(); | |
| $session = Yii::$app->session; | |
| if (!$session->isActive) | |
| $session->open(); | |
| if ($this->vehicle_type and $this->vehicle_type != $session->get('vehicle_type')) | |
| $this->destroySession(); | |
| // if ($this->scenario == 'step-5') | |
| // $session->destroySession('discount'); | |
| $session->set('vehicle_type', ($this->vehicle_type) ? $this->vehicle_type : $session->get('vehicle_type')); | |
| $session->set('user_id', ($this->user_id) ? $this->user_id : $session->get('user_id')); | |
| $session->set('product_id', ($this->product_id) ? $this->product_id : $session->get('product_id')); | |
| $session->set('product_id_book', ($this->product_id_book) ?$this->product_id_book: $session->get('product_id_book')); | |
| $session->set('driver_count', ($this->driver_count) ? $this->driver_count : $session->get('driver_count')); | |
| $session->set('vehicle_body_number', ($this->vehicle_body_number) ? $this->vehicle_body_number : $session->get('vehicle_body_number')); | |
| $session->set('brand', ($this->brand) ? $this->brand : $session->get('brand')); | |
| $session->set('vehicle_model_id', ($this->vehicle_model_id) ? $this->vehicle_model_id : $session->get('vehicle_model_id')); | |
| $session->set('photo', ($this->photo) ? $this->photo : $session->get('photo')); | |
| $session->set('created_date', ($this->created_date) ? $this->created_date : $session->get('created_date')); | |
| $session->set('register_location_id', is_numeric($this->register_location_id) ? $this->register_location_id : $session->get('register_location_id')); | |
| $session->set('vehicle_owner_type', ($this->vehicle_owner_type) ? $this->vehicle_owner_type : $session->get('vehicle_owner_type')); | |
| $session->set('vehicle_use_for_purpose', ($this->vehicle_use_for_purpose) ? $this->vehicle_use_for_purpose : $session->get('vehicle_use_for_purpose')); | |
| $session->set('start_date', ($this->start_date) ? $this->start_date : $session->get('start_date')); | |
| $session->set('expired_at', ($this->expired_at) ? $this->expired_at : $session->get('expired_at')); | |
| $session->set('vehicle_number', ($this->vehicle_number) ? $this->vehicle_number : $session->get('vehicle_number')); | |
| $session->set('body_number', ($this->body_number) ? $this->body_number : $session->get('body_number')); | |
| $session->set('discount', !is_null($this->discount) ? $this->discount : $session->get('discount')); | |
| $session->set('motor_number', ($this->motor_number) ? $this->motor_number : $session->get('motor_number')); | |
| $session->set('technical_passport', ($this->technical_passport) ? $this->technical_passport : $session->get('technical_passport')); | |
| $session->set('technical_passport_date', ($this->technical_passport_date) ? $this->technical_passport_date : $session->get('technical_passport_date')); | |
| $session->set('technical_passport_file', ($this->technical_passport_file) ? $this->technical_passport_file : $session->get('technical_passport_file')); | |
| if ($session->get('discount') == 1) { | |
| $session->set('discount_user_type', ($this->discount_user_type) ? $this->discount_user_type : $session->get('discount_user_type')); | |
| $session->set('discount_file', ($this->discount_file) ? $this->discount_file : $session->get('discount_file')); | |
| } else { | |
| $session->set('discount_user_type', null); | |
| $session->set('discount_file', null); | |
| } | |
| $session->set('energy_power', ($this->energy_power) ? $this->energy_power : $session->get('energy_power')); | |
| $session->set('horse_power', ($this->horse_power) ? $this->horse_power : $session->get('horse_power')); | |
| $session->set('weight', ($this->weight) ? $this->weight : $session->get('weight')); | |
| $session->set('suit', ($this->suit) ? $this->suit : $session->get('suit')); | |
| $session->set('phone_number', ($this->phone_number) ? $this->phone_number : $session->get('phone_number')); | |
| $session->set('owner_phone_number', ($this->owner_phone_number) ? $this->owner_phone_number : $session->get('owner_phone_number')); | |
| $session->set('email', ($this->email) ? $this->email : $session->get('email')); | |
| if ($session->get('vehicle_body_number')) { | |
| $years = [0, 1, 2, 3, 4]; | |
| $vehicle = []; | |
| foreach ($years as $year) { | |
| $vehicle[$year] = libraryState::find() | |
| ->joinWith('library') | |
| ->where(['body_number' => $session->get('vehicle_body_number')]) | |
| ->andWhere(['between', 'library_state.date', date('Y-m-d', strtotime('-' . $year . ' years')), date('Y-m-d')]) | |
| ->andWhere(['library.status'=>self::STATE_PAY_ACCEPTED]) | |
| ->orderBy('library_state.id DESC') | |
| ->count(); | |
| } | |
| $this->vehicle_library_state = !empty($vehicle) ? $vehicle : null; | |
| } | |
| if ($session->get('vehicle_owner_type') == 'physical') { | |
| $session->set('owner_last_name', ($this->owner_last_name)?? $session->get('owner_last_name')); | |
| $session->set('owner_first_name', ($this->owner_first_name) ?? $session->get('owner_first_name')); | |
| $session->set('owner_sure_name', ($this->owner_sure_name) ?? $session->get('owner_sure_name')); | |
| $session->set('owner_passport', ($this->owner_passport) ?? $session->get('owner_passport')); | |
| $session->set('owner_address_physical', ($this->owner_address_physical) ?? $session->get('owner_address_physical')); | |
| $session->set('owner_region_physical', is_numeric($this->owner_region_physical)?$this->owner_region_physical : $session->get('owner_region_physical')); | |
| } else { | |
| $session->set('owner_name', ($this->owner_name)?? $session->get('owner_name')); | |
| $session->set('owner_inn', ($this->owner_inn) ?? $session->get('owner_inn')); | |
| $session->set('owner_address_juridical', ($this->owner_address_juridical)?? $session->get('owner_address_juridical')); | |
| $session->set('owner_region_juridical', is_numeric($this->owner_region_juridical) ? $this->owner_region_juridical : $session->get('owner_region_juridical')); | |
| } | |
| if (in_array($this->scenario, ['step-1', 'step-2'])) { | |
| $session->set('library_discount_gift_use_' . $session->get('product_id'), false); | |
| $session->set('library_discount_gift_use_book' . $session->get('product_id_book'), false); | |
| $session->set('library_discount_gift_id', null); | |
| $session->set('library_discount_gift_summa', null); | |
| $session->set('library_discount_gift_id_book', null); | |
| $session->set('library_discount_gift_summa_book', null); | |
| } | |
| if (in_array($this->scenario, ['step-3', | |
| // 'step-5', 'step-5-register' | |
| ]) and $this->driver_count == '1-5-drivers') { | |
| $session->set('last_name', $this->last_name ?? $session->get('last_name')); | |
| $session->set('first_name', $this->first_name ?? $session->get('first_name')); | |
| $session->set('sure_name', $this->sure_name ?? $session->get('sure_name')); | |
| $session->set('passport', $this->passport ?? $session->get('passport')); | |
| $session->set('birth_day', $this->birth_day ?? $session->get('birth_day')); | |
| $session->set('driving_license', $this->driving_license ?? $session->get('driving_license')); | |
| $session->set('driving_license_date', $this->driving_license_date ?? $session->get('driving_license_date')); | |
| $session->set('gender', $this->gender ?? $session->get('gender')); | |
| $session->set('library_state', $this->library_state ?? $session->get('library_state')); | |
| $session->set('violation', $this->violation ?? $session->get('violation')); | |
| $new_state = []; | |
| $new_violation = []; | |
| $new_state_driver = $new_violation_driver = []; | |
| if($session->get('last_name')) { | |
| foreach ($session->get('last_name') as $key => $item) { | |
| $driver = Driver::find() | |
| ->joinWith(['library']) | |
| ->orWhere([ | |
| 'first_name' => $session->get('first_name')[$key], | |
| 'last_name' => $session->get('last_name')[$key], | |
| 'sure_name' => $session->get('sure_name')[$key], | |
| 'gender' => $session->get('gender')[$key], | |
| 'birth_day' => $session->get('birth_day')[$key] | |
| ]) | |
| ->orWhere([ | |
| 'driving_license' => $session->get('driving_license')[$key], | |
| 'driving_license_date' => $session->get('driving_license_date')[$key], | |
| ]) | |
| ->orWhere(['passport' => $session->get('passport')[$key],]) | |
| ->andWhere(['between', 'driver.created_at', date('Y-m-d H:i:s', strtotime('-5 years')), date('Y-m-d H:i:s')]) | |
| ->andWhere(['library.status'=>self::STATE_PAY_ACCEPTED]) | |
| ->orderBy('driver.id DESC')->asArray() | |
| ->one(); | |
| $driver_library_state = libraryState::find() | |
| ->joinWith(['library']) | |
| ->orWhere(['like', 'driver', $session->get('driving_license')[$key]]) | |
| // ->orWhere(['like','driver',$session->get('passport')[$key]]) | |
| ->andWhere(['between', 'date', date('Y-m-d H:i:s', strtotime('-1 years')), date('Y-m-d H:i:s')]) | |
| ->andWhere(['library.status'=>self::STATE_PAY_ACCEPTED]) | |
| ->orderBy('library_state.id DESC')->asArray() | |
| ->one(); | |
| $driver_library_state_count = libraryState::find() | |
| ->joinWith(['library']) | |
| ->orWhere(['like', 'driver', $session->get('driving_license')[$key]]) | |
| // ->orWhere(['like','driver',$session->get('passport')[$key]]) | |
| ->andWhere(['between', 'date', date('Y-m-d H:i:s', strtotime('-1 years')), date('Y-m-d H:i:s')]) | |
| ->andWhere(['library.status'=>self::STATE_PAY_ACCEPTED]) | |
| ->count(); | |
| $driver_violation = libraryViolation::find() | |
| ->joinWith(['library']) | |
| ->orWhere(['like', 'driver', $session->get('driving_license')[$key]]) | |
| // ->orWhere(['like','driver',$session->get('passport')[$key]]) | |
| ->andWhere(['between', 'date', date('Y-m-d H:i:s', strtotime('-5 years')), date('Y-m-d H:i:s')]) | |
| ->orderBy('library_violation.id DESC')->asArray() | |
| ->andWhere(['library.status'=>self::STATE_PAY_ACCEPTED]) | |
| ->one(); | |
| if ($driver_violation != null) { | |
| $new_violation[$key] = $driver_violation['type']; | |
| } elseif ($driver != null) { | |
| $new_violation[$key] = $driver['violation']; | |
| } else { | |
| $new_violation[$key] = isset($session->get('violation')[$key]) ? $session->get('violation')[$key] : 'no'; | |
| } | |
| if ($driver != null) { | |
| $new_state[$key] = $driver['library_state']; | |
| $old_year = strtotime($driver['created_at']); | |
| if ($driver_library_state != null) { | |
| $old_year2 = strtotime($driver_library_state['date']); | |
| if ($old_year2 > $old_year) { | |
| if ($driver_library_state_count == 1) { | |
| $new_state[$key] = 'one_accident'; | |
| } elseif ($driver_library_state_count == 2) { | |
| $new_state[$key] = 'two_accident'; | |
| } elseif ($driver_library_state_count >= 3) { | |
| $new_state[$key] = 'three_accident'; | |
| } | |
| continue; | |
| } | |
| } | |
| $diff_year = floor((time() - $old_year) / (60 * 60 * 24) / 365); | |
| if ($diff_year == 0) { | |
| $new_state[$key] = $driver['library_state']; | |
| } elseif ($diff_year == 1) { | |
| if ($driver['library_state'] == 'first_ever_contract') { | |
| $new_state[$key] = 'no_accidents_12'; | |
| } elseif ($driver['library_state'] == 'no_accidents_12') { | |
| $new_state[$key] = 'no_accidents_2_year'; | |
| } elseif ($driver['library_state'] == 'no_accidents_2_year') { | |
| $new_state[$key] = 'no_accidents_3_year'; | |
| } elseif ($driver['library_state'] == 'no_accidents_3_year') { | |
| $new_state[$key] = 'no_accidents_4_year'; | |
| } elseif ($driver['library_state'] == 'no_accidents_4_year') { | |
| $new_state[$key] = 'no_accidents_5_year'; | |
| } else { | |
| $new_state[$key] = $driver['library_state']; | |
| if (in_array($driver['library_state'], ['one_accident', 'two_accident', 'three_accident'])) { | |
| $new_state[$key] = 'no_accidents_12'; | |
| } | |
| } | |
| } elseif ($diff_year == 2) { | |
| if ($driver['library_state'] == 'first_ever_contract') { | |
| $new_state[$key] = 'no_accidents_2_year'; | |
| } elseif ($driver['library_state'] == 'no_accidents_12') { | |
| $new_state[$key] = 'no_accidents_3_year'; | |
| } elseif ($driver['library_state'] == 'no_accidents_2_year') { | |
| $new_state[$key] = 'no_accidents_4_year'; | |
| } elseif (in_array($driver['library_state'], ['no_accidents_3_year', 'no_accidents_4_year'])) { | |
| $new_state[$key] = 'no_accidents_5_year'; | |
| } else { | |
| $new_state[$key] = $driver['library_state']; | |
| if (in_array($driver['library_state'], ['one_accident', 'two_accident', 'three_accident'])) { | |
| $new_state[$key] = 'no_accidents_12'; | |
| } | |
| } | |
| } elseif ($diff_year == 3) { | |
| if ($driver['library_state'] == 'first_ever_contract') { | |
| $new_state[$key] = 'no_accidents_3_year'; | |
| } elseif ($driver['library_state'] == 'no_accidents_12') { | |
| $new_state[$key] = 'no_accidents_4_year'; | |
| } elseif (in_array($driver['library_state'], ['no_accidents_2_year', 'no_accidents_3_year', 'no_accidents_4_year'])) { | |
| $new_state[$key] = 'no_accidents_5_year'; | |
| } else { | |
| $new_state[$key] = $driver['library_state']; | |
| if (in_array($driver['library_state'], ['one_accident', 'two_accident', 'three_accident'])) { | |
| $new_state[$key] = 'no_accidents_2_year'; | |
| } | |
| } | |
| } elseif ($diff_year == 4) { | |
| if ($driver['library_state'] == 'first_ever_contract') { | |
| $new_state[$key] = 'no_accidents_4_year'; | |
| } elseif (in_array($driver['library_state'], ['no_accidents_12', 'no_accidents_2_year', 'no_accidents_3_year', 'no_accidents_4_year'])) { | |
| $new_state[$key] = 'no_accidents_5_year'; | |
| } else { | |
| $new_state[$key] = $driver['library_state']; | |
| if (in_array($driver['library_state'], ['one_accident', 'two_accident', 'three_accident'])) { | |
| $new_state[$key] = 'no_accidents_3_year'; | |
| } | |
| } | |
| } elseif ($diff_year >= 5) { | |
| if (in_array($driver['library_state'], ['first_ever_contract', 'no_accidents_12', 'no_accidents_2_year', 'no_accidents_3_year', 'no_accidents_4_year'])) { | |
| $new_state[$key] = 'no_accidents_5_year'; | |
| } else { | |
| $new_state[$key] = $driver['library_state']; | |
| if (in_array($driver['library_state'], ['one_accident', 'two_accident', 'three_accident'])) { | |
| $new_state[$key] = 'no_accidents_4_year'; | |
| } | |
| } | |
| } | |
| } else { | |
| $new_state[$key] = isset($session->get('library_state')[$key]) ? $session->get('library_state')[$key] : null; | |
| } | |
| $years = [1, 2, 3, 4, 5]; | |
| foreach ($years as $year) { | |
| $z = Driver::find() | |
| ->joinWith(['library']) | |
| ->orWhere([ | |
| 'first_name' => $session->get('first_name')[$key], | |
| 'last_name' => $session->get('last_name')[$key], | |
| 'sure_name' => $session->get('sure_name')[$key], | |
| 'gender' => $session->get('gender')[$key], | |
| 'birth_day' => $session->get('birth_day')[$key] | |
| ]) | |
| ->orWhere([ | |
| 'driving_license' => $session->get('driving_license')[$key], | |
| 'driving_license_date' => $session->get('driving_license_date')[$key], | |
| ]) | |
| ->orWhere(['passport' => $session->get('passport')[$key],]) | |
| ->andWhere(['between', 'driver.created_at', date('Y-m-d', strtotime('-' . $year . ' years')), date('Y-m-d')]) | |
| ->andWhere(['in', 'library_state', ['one_accident', 'two_accident', 'three_accident']]) | |
| ->andWhere(['library.status'=>self::STATE_PAY_ACCEPTED]) | |
| ->orderBy('driver.id DESC')->asArray() | |
| ->all(); | |
| $a = 0; | |
| if($z) { | |
| foreach ($z as $zz) { | |
| if ($zz['library_state'] == 'one_accident') { | |
| $a += 1; | |
| } elseif ($zz['library_state'] == 'two_accident') { | |
| $a += 2; | |
| } elseif ($zz['library_state'] == 'three_accident') { | |
| $a += 3; | |
| } | |
| } | |
| } | |
| if ($a == 0) { | |
| $a = libraryState::find() | |
| ->joinWith(['library']) | |
| ->orWhere(['like', 'driver', $session->get('driving_license')[$key]]) | |
| ->andWhere(['between', 'library_state.created_at', date('Y-m-d', strtotime('-' . $year . ' years')), date('Y-m-d')]) | |
| ->orderBy('library_state.id DESC') | |
| ->andWhere(['library.status'=>self::STATE_PAY_ACCEPTED]) | |
| ->count(); | |
| } | |
| $new_state_driver[$key][$year] = $a; | |
| } | |
| $b = Driver::find() | |
| ->joinWith(['library']) | |
| ->orWhere([ | |
| 'first_name' => $session->get('first_name')[$key], | |
| 'last_name' => $session->get('last_name')[$key], | |
| 'sure_name' => $session->get('sure_name')[$key], | |
| 'gender' => $session->get('gender')[$key], | |
| 'birth_day' => $session->get('birth_day')[$key] | |
| ]) | |
| ->orWhere([ | |
| 'driving_license' => $session->get('driving_license')[$key], | |
| 'driving_license_date' => $session->get('driving_license_date')[$key], | |
| ]) | |
| ->orWhere(['passport' => $session->get('passport')[$key],]) | |
| ->andWhere(['between', 'driver.created_at', date('Y-m-d', strtotime('-5 years')), date('Y-m-d')]) | |
| ->andWhere(['like', 'violation', 'no']) | |
| ->andWhere(['library.status'=>self::STATE_PAY_ACCEPTED]) | |
| ->orderBy('driver.id ASC')->asArray() | |
| ->one(); | |
| if ($b == null) { | |
| $b = libraryViolation::find() | |
| ->joinWith(['library']) | |
| ->orWhere(['like', 'driver', $session->get('driving_license')[$key]]) | |
| ->andWhere(['between', 'library_violation.created_at', | |
| date('Y-m-d', strtotime('-5 years')), date('Y-m-d')]) | |
| ->orderBy('library_violation.id ASC')->asArray() | |
| ->andWhere(['library.status'=>self::STATE_PAY_ACCEPTED]) | |
| ->one(); | |
| } | |
| $vio_year = 1; | |
| if($b!=null){ | |
| $vio_year = date('Y') - date('Y',strtotime($b['created_at'])); | |
| } | |
| $this->driver_violation[$key] = $vio_year; | |
| } | |
| } | |
| $this->driver_library_state = !empty($new_state_driver) ? $new_state_driver : null; | |
| $session->set('library_state', $new_state); | |
| $session->set('violation', $new_violation); | |
| } | |
| if ($this->actual_book) { | |
| $session->set('actual_book', true); | |
| $session->set('book_summa', $this->book_summa); | |
| $session->set('risk_summas', $this->risk_summas); | |
| $session->set('cover', $this->cover); | |
| $session->set('yonilgi_turi', $this->yonilgi_turi); | |
| $session->set('probeg', $this->probeg); | |
| $session->set('karobka', $this->karobka); | |
| $session->set('tyuning', $this->tyuning); | |
| $session->set('privod', $this->privod); | |
| $session->set('eko_klass', $this->eko_klass); | |
| $session->set('koleso_formula', $this->koleso_formula); | |
| $session->set('massa1', $this->massa1); | |
| $session->set('massa2', $this->massa2); | |
| $session->set('type_kuzov', $this->type_kuzov); | |
| $session->set('type_electr', $this->type_electr); | |
| $session->set('electr_power', $this->electr_power); | |
| $session->set('electr_count', $this->electr_count); | |
| $session->set('xadavoy', $this->xadavoy); | |
| $session->set('parking', $this->parking); | |
| $session->set('signal', $this->signal); | |
| $session->set('permission', $this->permission); | |
| $session->set('benifit', $this->benifit); | |
| $session->set('beneficiary', $this->beneficiary); | |
| $session->set('remont', $this->remont); | |
| $session->set('extra_services', $this->extra_services); | |
| $session->set('expire_at_book', $this->expire_at_book); | |
| $session->set('book_currency', $this->book_currency); | |
| $session->set('book_type_summa', $this->book_type_summa); | |
| $session->set('book_type_object', $this->book_type_object); | |
| $session->set('book_risk', $this->book_risk); | |
| $session->set('juridic_activity', $this->juridic_activity); | |
| $session->set('clearance_region', $this->clearance_region); | |
| $session->set('clearance_country', $this->clearance_country); | |
| $session->set('franshiza_type', $this->franshiza_type); | |
| $session->set('franshiza_percent', $this->franshiza_percent); | |
| $session->set('rasrochka', $this->rasrochka); | |
| $session->set('payment_book_type', $this->payment_book_type); | |
| // new book_srok issue 90 | |
| $session->set('book_srok', $this->book_srok); | |
| } | |
| if ($this->scenario == 'step-3') { | |
| $session->set('book_summa',null); | |
| $this->calculatePolice(); | |
| $session->set('library_summa', $this->library_summa ?? $session->get('library_summa')); | |
| } | |
| if($this->scenario == self::SCENARIO_book){ | |
| $this->calculatePolice(false); | |
| $session->set('library_summa', $this->library_summa ?? $session->get('library_summa')); | |
| } | |
| if (in_array($this->scenario,[self::SCENARIO_book,'step-3'])) { | |
| $session->set('library_discount_basic_book',null); | |
| $session->set('library_max_discount_book', null); | |
| $session->set('library_discount_gift_book', null); | |
| $session->set('library_discount_basic', null); | |
| $session->set('library_max_discount', null); | |
| $session->set('library_discount_gift', null); | |
| $session->set('product_id_book', null); | |
| $session->set('library_number_book', null); | |
| } | |
| if (in_array($this->scenario,['step-4',self::SCENARIO_table_book_DISCOUNT]) and ($this->product_id or $this->product_id_book)) { | |
| $this->calculatePolice(false); | |
| } | |
| if (in_array($this->scenario,['step-4',self::SCENARIO_table_book_DISCOUNT]) and | |
| $session->get('vehicle_model_id') and $this->product_id and | |
| $this->product_id!=$this->product_id_book ) { | |
| $session->set('library_discount_basic_id', null); | |
| $session->set('library_discount_basic_summa', null); | |
| $this->getSessionValues(); | |
| $product = Product::find() | |
| ->joinWith(['company']) | |
| ->asArray() | |
| ->where([ | |
| 'product.id' => $this->product_id, | |
| 'product.status' => 'active', | |
| 'company.status' => 'active' | |
| ]) | |
| ->one(); | |
| $this->library_max_discount = $this->calculateDiscount($product)[0]??0; | |
| if ($this->product_id and $this->product_id_book and $this->product_id!=$this->product_id_book) { | |
| $this->library_max_discount = $this->product->max_commission; | |
| } | |
| $exact_discount = Discount::find() | |
| ->where([ | |
| 'type'=>Discount::TYPE_EXACT, | |
| 'status'=>'active' | |
| ]) | |
| ->andWhere(['like','product','"'.$this->product_id.'"']) | |
| ->andWhere(['<=','start_date',date('Y-m-d')]) | |
| ->andWhere(['>=','end_date',date('Y-m-d')]) | |
| ->asArray() | |
| ->select(['from_discount','id']) | |
| ->one(); | |
| $this->library_discount_basic = $exact_discount!=null?($this->library_max_discount * ($exact_discount['from_discount']/100)):null; | |
| if ($this->library_discount_basic) { | |
| $session->set('library_discount_basic_id', $exact_discount['id']); | |
| $session->set('library_discount_basic_summa', $this->library_summa*$this->library_discount_basic/100); | |
| } | |
| $this->library_discount_gift = null; | |
| if($session->get('library_discount_gift_use_' . $this->product_id)){ | |
| $this->library_discount_gift = $session->get('library_discount_gift_' . $this->product_id); | |
| // $session->set('library_discount_gift_id', $discount['id']); | |
| $session->set('library_discount_gift_summa', $this->library_summa*$this->library_discount_gift/100); | |
| }else { | |
| $session->set('library_discount_gift_id', null); | |
| $session->set('library_discount_gift_summa', null); | |
| $discount = Discount::find() | |
| ->where([ | |
| 'type'=>Discount::TYPE_GIFT, | |
| 'status'=>'active' | |
| ]) | |
| ->andWhere(['like','product','"'.$this->product_id.'"']) | |
| ->andWhere(['<=','start_date',date('Y-m-d')]) | |
| ->andWhere(['>=','end_date',date('Y-m-d')]) | |
| ->asArray() | |
| ->select(['from_discount','to_discount','id']) | |
| ->one(); | |
| if($discount!=null){ | |
| $gift = rand($discount['from_discount'],$discount['to_discount']); | |
| if ($exact_discount!=null and ($exact_discount['from_discount']+$gift)<=100) { | |
| $this->library_discount_gift = ($this->library_max_discount * ($gift/100)); | |
| }elseif ($exact_discount!=null and ($exact_discount['from_discount']+$gift)>100) { | |
| $this->library_discount_gift = $this->library_max_discount; | |
| }elseif ($exact_discount==null and $gift<=100) { | |
| $this->library_discount_gift = ($this->library_max_discount * ($gift/100)); | |
| } | |
| if ($this->library_discount_gift) { | |
| $session->set('library_discount_gift_id', $discount['id']); | |
| $session->set('library_discount_gift_summa', $this->library_summa*$this->library_discount_gift/100); | |
| } | |
| } | |
| } | |
| $session->set('library_discount_basic', $this->library_discount_basic); | |
| $session->set('library_max_discount', $this->library_max_discount); | |
| $session->set('library_discount_gift', $this->library_discount_gift); | |
| $session->set('library_discount_gift_' . $this->product_id, $this->library_discount_gift); | |
| } | |
| // book chegirma | |
| if ($this->scenario == self::SCENARIO_table_book_DISCOUNT and | |
| $session->get('vehicle_model_id') and | |
| $this->product_id_book) { | |
| $session->set('library_discount_basic_id_book', null); | |
| $session->set('library_discount_basic_summa_book', null); | |
| $this->getSessionValues(); | |
| $product = Product::find() | |
| ->joinWith(['company']) | |
| ->asArray() | |
| ->where([ | |
| 'product.id' => $this->product_id_book, | |
| 'product.status' => 'active', | |
| 'company.status' => 'active' | |
| ]) | |
| ->one(); | |
| $this->library_summa_book = $this->calculatebook($product,false)[0]??0; | |
| $session->set('risk_summas', $this->risk_summas); | |
| $session->set('library_summa_book', $this->library_summa_book); | |
| $this->library_max_discount_book = $product['main_commission']; | |
| $exact_discount = Discount::find() | |
| ->where([ | |
| 'type'=>Discount::TYPE_EXACT, | |
| 'status'=>'active' | |
| ]) | |
| ->andWhere(['like','product','"'.$this->product_id_book.'"']) | |
| ->andWhere(['<=','start_date',date('Y-m-d')]) | |
| ->andWhere(['>=','end_date',date('Y-m-d')]) | |
| ->asArray() | |
| ->select(['from_discount','id']) | |
| ->one(); | |
| $this->library_discount_basic_book = $exact_discount!=null? | |
| ($this->library_max_discount_book * ($exact_discount['from_discount']/100)) | |
| :null; | |
| if ($this->library_discount_basic_book) { | |
| $session->set('library_discount_basic_id_book', $exact_discount['id']); | |
| $session->set('library_discount_basic_summa_book', | |
| $this->library_summa_book*$this->library_discount_basic_book/100); | |
| } | |
| $this->library_discount_gift_book = null; | |
| if($session->get('library_discount_gift_use_book_' . $this->product_id_book)){ | |
| $this->library_discount_gift_book = | |
| $session->get('library_discount_gift_book_' . $this->product_id_book); | |
| // $session->set('library_discount_gift_id', $discount['id']); | |
| $session->set('library_discount_gift_summa_book', | |
| $this->library_summa_book*$this->library_discount_gift_book/100); | |
| }else { | |
| $session->set('library_discount_gift_id_book', null); | |
| $session->set('library_discount_gift_summa_book', null); | |
| $discount = Discount::find() | |
| ->where([ | |
| 'type'=>Discount::TYPE_GIFT, | |
| 'status'=>'active' | |
| ]) | |
| ->andWhere(['like','product','"'.$this->product_id_book.'"']) | |
| ->andWhere(['<=','start_date',date('Y-m-d')]) | |
| ->andWhere(['>=','end_date',date('Y-m-d')]) | |
| ->asArray() | |
| ->select(['from_discount','to_discount','id']) | |
| ->one(); | |
| if($discount!=null){ | |
| $gift = rand($discount['from_discount'],$discount['to_discount']); | |
| if ($exact_discount!=null and ($exact_discount['from_discount']+$gift)<=100) { | |
| $this->library_discount_gift_book = ($this->library_max_discount_book * ($gift/100)); | |
| }elseif ($exact_discount!=null and ($exact_discount['from_discount']+$gift)>100) { | |
| $this->library_discount_gift_book = $this->library_max_discount_book; | |
| }elseif ($exact_discount==null and $gift<=100) { | |
| $this->library_discount_gift_book = ($this->library_max_discount_book * ($gift/100)); | |
| } | |
| if ($this->library_discount_gift_book) { | |
| $session->set('library_discount_gift_id_book', $discount['id']); | |
| $session->set('library_discount_gift_summa_book', $this->library_summa_book*$this->library_discount_gift_book/100); | |
| } | |
| } | |
| } | |
| $session->set('library_discount_basic_book', $this->library_discount_basic_book); | |
| $session->set('library_max_discount_book', $this->library_max_discount_book); | |
| $session->set('library_discount_gift_book', $this->library_discount_gift_book); | |
| $session->set('library_discount_gift_book_' . $this->product_id_book, $this->library_discount_gift_book); | |
| } | |
| if (in_array($this->scenario, ['step-5-register', 'step-5'])) { | |
| $this->getSessionValues(); | |
| if ($this->product_id and $this->product_id_book and $this->product_id!=$this->product_id_book) { | |
| $this->library_summa_end = $this->library_summa_end_old??$this->library_summa_end; | |
| $this->library_summa_end2 = $this->library_summa_end2_old??$this->library_summa_end2; | |
| } | |
| $library_summa = $this->library_summa; | |
| $library_discount_basic = $this->library_discount_basic ?: 0; | |
| $gift_discount = Yii::$app->session->get("user_use_discount_gift",0); | |
| $gift_discount_book = Yii::$app->session->get("user_use_discount_gift_book",0); | |
| if ($this->product_id == $this->product_id_book) { | |
| $library_summa = $this->library_summa_book; | |
| $library_discount_basic = $this->library_discount_basic_book; | |
| $gift_discount = $gift_discount_book; | |
| } elseif ($this->checkbook) { | |
| $library_summa = $this->library_summa + $this->library_summa_book; | |
| $library_discount_basic = (($this->library_discount_basic * $this->library_summa + | |
| $this->library_discount_basic_book * $this->library_summa_book) / ($this->library_summa + $this->library_summa_book)); | |
| $gift_discount = (($gift_discount * $this->library_summa + $gift_discount_book * $this->library_summa_book) / | |
| ($this->library_summa + $this->library_summa_book)); | |
| } | |
| $library_discount_basic = $library_discount_basic>0?$library_discount_basic:0; | |
| $gift_discount = $gift_discount>0?$gift_discount:0; | |
| if ($this->product_id_book) { | |
| $this->library_summa_end_book = $this->library_summa_book - | |
| ($this->library_summa_book * ( | |
| ($this->library_discount_basic_book + $gift_discount_book) / 100)); | |
| $session->set('library_summa_end_book', $this->library_summa_end_book); | |
| } | |
| if ($this->product_id){ | |
| $this->library_summa_end_table = $this->library_summa - | |
| ($this->library_summa * (($this->library_discount_basic + Yii::$app->session->get("user_use_discount_gift",0)) / 100)); | |
| $session->set('library_summa_end_table', $this->library_summa_end_table); | |
| } | |
| $this->library_summa_end = $library_summa - ($library_summa * (($library_discount_basic + $gift_discount) / 100)); | |
| $session->set('library_summa_end', $this->library_summa_end); | |
| // print_variable( [ | |
| // '--------------------table--------------------', | |
| // $this->library_summa, | |
| // $this->library_summa_end_table, | |
| // $this->library_max_discount, | |
| // $this->library_discount_basic, | |
| // Yii::$app->session->get("user_use_discount_gift",0), | |
| // '--------------------book--------------------', | |
| // $this->library_summa_book, | |
| // $this->library_summa_end_book, | |
| // $this->library_max_discount_book, | |
| // $this->library_discount_basic_book, | |
| // Yii::$app->session->get("user_use_discount_gift_book",0), | |
| // '--------------------ALL--------------------', | |
| // $this->library_summa_end, | |
| // $library_discount_basic, | |
| // $gift_discount, | |
| // ] ); | |
| } | |
| if ($this->scenario == 'step-6') { | |
| $this->library_summa_end = $session->get('library_summa_end'); | |
| $this->library_summa_end_table = $session->get('library_summa_end_table'); | |
| $this->library_summa_end_book = $session->get('library_summa_end_book'); | |
| $this->library_summa_end2 = $this->library_summa_end; | |
| $this->library_summa_end2_table = $this->library_summa_end_table; | |
| $this->library_summa_end2_book = $this->library_summa_end_book; | |
| if($session->get('vehicle_owner_type')=='physical' and $this->discount) { | |
| if ($this->library_number) { | |
| $library = library::find() | |
| ->where(['discount' => 1, 'status' => self::STATE_PAY_ACCEPTED, 'discount_status' => 1]) | |
| ->andWhere(['like','library_data',$this->owner_first_name??$session->get('owner_first_name')]) | |
| ->andWhere(['like','library_data',$this->owner_last_name??$session->get('owner_last_name')]) | |
| ->andWhere(['like','library_data',$this->owner_sure_name??$session->get('owner_sure_name')]) | |
| ->andWhere(['like','library_data',$this->owner_passport??$session->get('owner_passport')]) | |
| ->andWhere(['!=', 'library_number', $this->library_number]) | |
| ->andWhere('DATE_ADD(`start_date`, INTERVAL `expired_at` DAY)>:date', [':date' => date('Y-m-d')]) | |
| ->exists(); | |
| } else { | |
| $library = library::find() | |
| ->where(['discount' => 1, 'status' => self::STATE_PAY_ACCEPTED, 'discount_status' => 1]) | |
| ->andWhere(['like','library_data',$this->owner_first_name??$session->get('owner_first_name')]) | |
| ->andWhere(['like','library_data',$this->owner_last_name??$session->get('owner_last_name')]) | |
| ->andWhere(['like','library_data',$this->owner_sure_name??$session->get('owner_sure_name')]) | |
| ->andWhere(['like','library_data',$this->owner_passport??$session->get('owner_passport')]) | |
| ->andWhere('DATE_ADD(`start_date`, INTERVAL `expired_at` DAY)>:date', [':date' => date('Y-m-d')]) | |
| ->exists(); | |
| } | |
| if(!$library) { | |
| $this->library_summa_end2 = $this->library_summa_end / 2; | |
| $this->library_summa_end2_table = $this->library_summa_end_table / 2; | |
| $this->library_summa_end2_book = $this->library_summa_end_book / 2; | |
| }else{ | |
| $this->discount = 0; | |
| $session->set('discount',$this->discount); | |
| $this->deleteFile($this->discount_file); | |
| Yii::$app->session->setFlash('error', Yii::t('yii', "Siz maxsus sug'urta imtiyozidan allaqachon foydalangansiz.")); | |
| } | |
| } | |
| $session->set('library_summa_end2', $this->library_summa_end2); | |
| $session->set('library_summa_end2_table', $this->library_summa_end2_table); | |
| $session->set('library_summa_end2_book', $this->library_summa_end2_book); | |
| if (Yii::$app->user->isGuest) { | |
| if ($session->get('phone_number') == '' && $session->get('email') == '') { | |
| $this->addError('phone_number', Yii::t('yii', 'Sug\'urta polisini saqlash uchun telefon raqamizni kiriting!')); | |
| $this->addError('email', Yii::t('yii', 'Sug\'urta polisini saqlash uchun elektron pochtangizni kiriting!')); | |
| } else { | |
| if ($session->get('vehicle_owner_type') != 'physical') { | |
| $name = $session->get('owner_name'); | |
| } else { | |
| $name = $session->get('owner_last_name'); | |
| $name .= ' ' . $session->get('owner_first_name'); | |
| $name .= ' ' . $session->get('owner_sure_name'); | |
| } | |
| $data = [ | |
| 'name' => $name, | |
| 'phone_number' => $this->phone_number, | |
| 'email' => $this->email, | |
| ]; | |
| $user = User::createUser($data); | |
| if ($user == null and !$session->get('user_id')) { | |
| $this->addError('error', Yii::t('yii', 'Ichki xatolik yuz berdi!')); | |
| } else { | |
| $session->set('user_id', $user->id ?? $session->get('user_id')); | |
| } | |
| } | |
| } else { | |
| $session->set('user_id', Yii::$app->user->id); | |
| } | |
| $this->getSessionValues(); | |
| if($session->get('agent_company') ){ | |
| if(!array_key_exists($this->product->company_id,$session->get('agent_company'))){ | |
| $this->addError('error','Sizda xatolik mavjud!'); | |
| $this->destroySession(); | |
| return; | |
| }elseif(array_key_exists($this->product->company_id,$session->get('agent_company'))){ | |
| $pr = 'percent'; | |
| if ($this->product_id_book==$this->product_id) { | |
| $pr = 'percent2'; | |
| } | |
| $percent = $session->get('agent_company')[$this->product->company_id][$pr]??0; | |
| $a = $this->library_summa_end2*$percent/100; | |
| if($session->get('agent_company')[$this->product->company_id]['limit'] < ($this->library_summa_end2-$a)){ | |
| $this->addError('error',Yii::t('yii',"Sizning hisobingizda to'lov qilish uchun yetarli mablag' mavjud emas(Qoldiq: {balance}). Iltimos tizim ma'muryati bilan bog'laning",['balance'=>number_format($session->get('agent_company')[$this->product->company_id]['limit'],1,'.',' ')])); | |
| return; | |
| } | |
| } | |
| } | |
| $this->user_id = $session->get('user_id'); | |
| if ($this->library_summa_end2) { | |
| $this->setlibraryNumber(); | |
| } | |
| if ($this->product_id_book and $this->library_summa_end2_book) { | |
| $this->setlibraryNumber(true); | |
| $this->library_summa_end_old = $this->library_summa_end; | |
| $this->library_summa_end2_old = $this->library_summa_end2; | |
| $this->library_summa_end = $this->library_summa_end_table; | |
| $this->library_summa_end2 = $this->library_summa_end2_table; | |
| } | |
| $session->set('library_number', $this->library_number); | |
| $session->set('library_number_book', $this->library_number_book); | |
| if (!$this->hasErrors() and $this->library_summa_end2) { | |
| $this->library_summa_product = $this->product->productType->commission; | |
| if ($this->product_id == $this->product_id_book) { | |
| $this->library_max_discount = $this->product->main_commission; | |
| $this->library_discount_basic = $this->library_discount_basic_book; | |
| $this->library_discount_gift = $this->library_discount_gift_book; | |
| $this->library_summa = $this->library_summa_book; | |
| $this->library_summa_product = array_sum($this->book_summa); | |
| } | |
| $this->upload(); | |
| $session->set('technical_passport_file', ($this->technical_passport_file) ? $this->technical_passport_file : $session->get('technical_passport_file')); | |
| if($this->discount){ | |
| $this->uploadDiscount(); | |
| $session->set('discount_user_type', ($this->discount_user_type) ? $this->discount_user_type : $session->get('discount_user_type')); | |
| $session->set('discount_file', ($this->discount_file) ? $this->discount_file : $session->get('discount_file')); | |
| } | |
| unset($_FILES); | |
| $vehicle_data = [ | |
| 'vehicle_type' => $this->vehicle_type, | |
| 'brand' => $this->brand, | |
| 'vehicle_model_id' => $this->vehicle_model_id, | |
| 'country_id' => $this->vehicleModel->country_id, | |
| 'vehicle_model_name' => $this->vehicleModel->name, | |
| 'photo' => $this->vehicleModel->photo, | |
| 'data' => $this->vehicleModel->data, | |
| ]; | |
| if ($this->vehicle_type == 1) { | |
| $vehicle_data['energy_power'] = $this->energy_power; | |
| $vehicle_data['horse_power'] = $this->horse_power; | |
| } elseif ($this->vehicle_type == 2) { | |
| $vehicle_data['weight'] = $this->weight; | |
| } elseif (in_array($this->vehicle_type, [3, 5, 6])) { | |
| $vehicle_data['suit'] = $this->suit; | |
| if (in_array($this->vehicle_type, [5, 6])) { | |
| $vehicle_data['suit'] = $this->vehicleModel->suit; | |
| } | |
| } elseif ($this->vehicle_type == 7) { | |
| $vehicle_data['xadavoy'] = $this->vehicleModel->xadavoy; | |
| $vehicle_data['using'] = $this->vehicleModel->using; | |
| } | |
| $this->vehicle_data = Json::encode($vehicle_data); | |
| $library_data = []; | |
| if ($this->vehicle_owner_type == 'physical') { | |
| $library_data['owner_last_name'] = strtoupper($this->owner_last_name); | |
| $library_data['owner_first_name'] = strtoupper($this->owner_first_name); | |
| $library_data['owner_sure_name'] = strtoupper($this->owner_sure_name); | |
| $library_data['owner_passport'] = strtoupper($this->owner_passport); | |
| $library_data['owner_address_physical'] = $this->owner_address_physical; | |
| $library_data['owner_region_physical'] = $this->owner_region_physical; | |
| $library_data['owner_phone_number'] = $this->owner_phone_number??(Yii::$app->user->isGuest?$this->phone_number:Yii::$app->user->identity->phone_number); | |
| } else { | |
| $library_data['owner_name'] = strtoupper($this->owner_name); | |
| $library_data['owner_inn'] = $this->owner_inn; | |
| $library_data['owner_phone_number'] = $this->owner_phone_number??(Yii::$app->user->isGuest?$this->phone_number:Yii::$app->user->identity->phone_number); | |
| $library_data['owner_address_juridical'] = strtoupper($this->owner_address_juridical); | |
| $library_data['owner_region_juridical'] = $this->owner_region_juridical; | |
| } | |
| $transaction = Yii::$app->db->beginTransaction(); | |
| try { | |
| if ($this->driver_count == '1-5-drivers') { | |
| $this->last_name = 'dasdas'; | |
| $this->first_name = 'dasdsas'; | |
| $this->sure_name = 'dasdadds'; | |
| $this->passport = 'AA1234567'; | |
| $this->driving_license = 'AA1234567'; | |
| } | |
| if (!Yii::$app->user->isGuest) { | |
| if ($agent = $session->get('agent_company') and isset($agent[$this->product->company_id])) { | |
| $pr = 'percent'; | |
| if ($this->product_id_book==$this->product_id) { | |
| $pr = 'percent2'; | |
| } | |
| $percent = $agent[$this->product->company_id][$pr]??0; | |
| $this->agent_id = $agent[$this->product->company_id]['agent_id']??0; | |
| $this->agent_benifit = $this->library_summa_end2*$percent/100; | |
| } | |
| } | |
| $this->library_data = Json::encode($library_data); | |
| if ($this->checkbook) { | |
| $model = clone $this; | |
| $model->product_id = $this->product_id_book; | |
| $model->library_max_discount = $this->productbook->main_commission; | |
| $model->library_discount_basic = $this->library_discount_basic_book; | |
| $model->library_discount_gift = $this->library_discount_gift_book; | |
| $model->library_summa = $this->library_summa_book; | |
| $model->library_summa_end = $this->library_summa_end_book; | |
| $model->library_summa_end2 = $this->library_summa_end2_book; | |
| $model->library_summa_product = array_sum($this->book_summa); | |
| $model->library_number = $this->library_number_book; | |
| $library_data['cover'] = $this->cover??null; | |
| $library_data['risk_summas'] = $this->risk_summas[$model->product->company_id]??null; | |
| $library_data['book_summa'] = $this->book_summa??null; | |
| $library_data['yonilgi_turi'] = $this->yonilgi_turi??null; | |
| $library_data['probeg'] = $this->probeg??null; | |
| $library_data['karobka'] = $this->karobka??null; | |
| $library_data['tyuning'] = $this->tyuning??null; | |
| $library_data['privod'] = $this->privod??null; | |
| $library_data['eko_klass'] = $this->eko_klass??null; | |
| $library_data['koleso_formula'] = $this->koleso_formula??null; | |
| $library_data['massa1'] = $this->massa1??null; | |
| $library_data['massa2'] = $this->massa2??null; | |
| $library_data['type_kuzov'] = $this->type_kuzov??null; | |
| $library_data['type_electr'] = $this->type_electr??null; | |
| $library_data['electr_power'] = $this->electr_power??null; | |
| $library_data['electr_count'] = $this->electr_count??null; | |
| $library_data['xadavoy'] = $this->xadavoy??null; | |
| $library_data['parking'] = $this->parking??null; | |
| $library_data['signal'] = $this->signal??null; | |
| $library_data['permission'] = $this->permission??null; | |
| $library_data['benifit'] = $this->benifit??null; | |
| $library_data['beneficiary'] = $this->beneficiary??null; | |
| $library_data['remont'] = $this->remont??null; | |
| $library_data['extra_services'] = $this->extra_services??null; | |
| $library_data['expire_at_book'] = $this->expire_at_book??null; | |
| $library_data['book_currency'] = $this->book_currency??null; | |
| $library_data['book_type_summa'] = $this->book_type_summa??null; | |
| $library_data['book_type_object'] = $this->book_type_object??null; | |
| $library_data['book_risk'] = $this->book_risk??null; | |
| $library_data['juridic_activity'] = $this->juridic_activity??null; | |
| $library_data['clearance_region'] = $this->clearance_region??null; | |
| $library_data['clearance_country'] = $this->clearance_country??null; | |
| $library_data['franshiza_type'] = $this->franshiza_type??null; | |
| $library_data['franshiza_percent'] = $this->franshiza_percent??null; | |
| $library_data['rasrochka'] = $this->rasrochka??null; | |
| $library_data['payment_book_type'] = $this->payment_book_type??null; | |
| //new book_srok issue 90 | |
| $library_data['book_srok'] = $this->book_srok??null; | |
| $model->library_data = Json::encode(array_filter($library_data)); | |
| if (!Yii::$app->user->isGuest) { | |
| if ($agent = $session->get('agent_company') and isset($agent[$this->productbook->company_id])) { | |
| $pr = 'percent2'; | |
| $percent = $agent[$this->productbook->company_id][$pr]??0; | |
| $model->agent_id = $agent[$this->productbook->company_id]['agent_id']??0; | |
| $model->agent_benifit = $this->library_summa_end2_book*$percent/100; | |
| } | |
| } | |
| } | |
| $this->save(false); | |
| if ($this->checkbook) { | |
| $model->save(); | |
| } | |
| if ($session->get('library_discount_basic_id') and $session->get('library_discount_basic_summa') and !$session->get('discount_updated_basic')) { | |
| Discount::updateAllCounters( | |
| ['used'=>1,'summa'=>$session->get('library_discount_basic_summa')], | |
| ['id'=>$session->get('library_discount_basic_id')]); | |
| $session->set('discount_updated_basic',true); | |
| } | |
| if ($session->get('library_discount_gift_id') and $session->get('library_discount_gift_summa') and !$session->get('discount_updated_gift')) { | |
| Discount::updateAllCounters( | |
| ['used'=>1,'summa'=>$session->get('library_discount_gift_summa')], | |
| ['id'=>$session->get('library_discount_gift_id')]); | |
| $session->set('discount_updated_gift',true); | |
| } | |
| if ($session->get('library_discount_basic_id_book') and $session->get('library_discount_basic_summa_book') and !$session->get('discount_updated_basic_book')) { | |
| Discount::updateAllCounters( | |
| ['used'=>1,'summa'=>$session->get('library_discount_basic_summa_book')], | |
| ['id'=>$session->get('library_discount_basic_id_book')]); | |
| $session->set('discount_updated_basic_book',true); | |
| } | |
| if ($session->get('library_discount_gift_id_book') and $session->get('library_discount_gift_summa_book') and !$session->get('discount_updated_gift_book')) { | |
| Discount::updateAllCounters( | |
| ['used'=>1,'summa'=>$session->get('library_discount_gift_summa_book')], | |
| ['id'=>$session->get('library_discount_gift_id_book')]); | |
| $session->set('discount_updated_gift_book',true); | |
| } | |
| if ($this->driver_count == '1-5-drivers') { | |
| Driver::deleteAll(['library_id' => $this->id]); | |
| if ($this->checkbook and isset($model->id)) { | |
| Driver::deleteAll(['library_id' => $model->id]); | |
| } | |
| $data = $data2 = []; | |
| foreach ($session->get('last_name') as $key => $item) { | |
| if (in_array($session->get('driving_license')[$key],array_column($data,'driving_license'))) { | |
| continue; | |
| } | |
| $a = [ | |
| 'library_id' => $this->id, | |
| 'last_name' => strtoupper($item), | |
| 'first_name' => strtoupper($session->get('first_name')[$key]), | |
| 'sure_name' => strtoupper($session->get('sure_name')[$key]), | |
| 'passport' => $session->get('passport')[$key], | |
| 'birth_day' => $session->get('birth_day')[$key], | |
| 'driving_license' => $session->get('driving_license')[$key], | |
| 'driving_license_date' => $session->get('driving_license_date')[$key], | |
| 'library_state' => $session->get('library_state')[$key], | |
| 'violation' => $session->get('violation')[$key], | |
| 'gender' => $session->get('gender')[$key], | |
| 'created_at' => date('Y-m-d H:i:s'), | |
| ]; | |
| $data[] = $a; | |
| if ($this->checkbook) { | |
| $a['library_id'] = $model->id; | |
| $data2[] = $a; | |
| } | |
| } | |
| if (!empty($data)) { | |
| // print_variable( $data ); | |
| \Yii::$app->db->createCommand()->batchInsert(Driver::tableName(), [ | |
| 'library_id', | |
| 'last_name', | |
| 'first_name', | |
| 'sure_name', | |
| 'passport', | |
| 'birth_day', | |
| 'driving_license', | |
| 'driving_license_date', | |
| 'library_state', | |
| 'violation', | |
| 'gender', | |
| 'created_at', | |
| ], $data)->execute(); | |
| } | |
| if (!empty($data2)) { | |
| \Yii::$app->db->createCommand()->batchInsert(Driver::tableName(), [ | |
| 'library_id', | |
| 'last_name', | |
| 'first_name', | |
| 'sure_name', | |
| 'passport', | |
| 'birth_day', | |
| 'driving_license', | |
| 'driving_license_date', | |
| 'library_state', | |
| 'violation', | |
| 'gender', | |
| 'created_at', | |
| ], $data2)->execute(); | |
| } | |
| } | |
| $this->createlibraryPdf(true); | |
| if ($this->checkbook) { | |
| $model->createlibrarybookPdf(true); | |
| } | |
| $transaction->commit(); | |
| } catch (\Exception $e) { | |
| $transaction->rollBack(); | |
| if ($this->driver_count == '1-5-drivers') { | |
| $this->last_name = $session->get('last_name'); | |
| $this->first_name = $session->get('first_name'); | |
| $this->sure_name = $session->get('sure_name'); | |
| $this->passport = $session->get('passport'); | |
| $this->driving_license = $session->get('driving_license'); | |
| $this->driving_license_date = $session->get('driving_license_date'); | |
| $this->violation = $session->get('violation'); | |
| $this->library_state = $session->get('library_state'); | |
| if ($this->id) { | |
| Driver::deleteAll(['library_id' => $this->id]); | |
| } | |
| if ($this->checkbook and isset($model->id)) { | |
| Driver::deleteAll(['library_id' => $model->id]); | |
| } | |
| } | |
| $this->deleteFile($this->technical_passport_file); | |
| if($this->discount) | |
| $this->deleteFile($this->discount_file); | |
| // print_variable( [$e->getMessage(),$e->getTraceAsString()] ); | |
| $this->addError('error', Yii::t('yii', 'Ichki xatolik yuz berdi!')); | |
| } | |
| } | |
| } | |
| } | |
| public function setCustomAttributes() | |
| { | |
| $vehicle = library::find() | |
| ->with('vehicleModel.brand') | |
| ->select([ | |
| 'vehicle_model_id', 'created_date', 'body_number', 'motor_number', | |
| 'register_location_id', 'vehicle_number', 'technical_passport','technical_passport_date', | |
| 'vehicle_owner_type', 'vehicle_use_for_purpose', 'vehicle_data','library_data' | |
| ]) | |
| ->asArray() | |
| ->where('library_number =:identity OR body_number =:identity OR vehicle_number=:identity', | |
| [':identity'=>$this->vehicle_body_number]) | |
| ->andWhere(['status'=>self::STATE_PAY_ACCEPTED]) | |
| ->cache(300) | |
| ->orderBy('id DESC')->one(); | |
| if($vehicle==null){ | |
| $vehicle = UserVehicle::find() | |
| ->with('vehicleModel.brand') | |
| ->asArray() | |
| ->cache(300) | |
| ->where('body_number =:identity OR vehicle_number=:identity', | |
| [':identity' => $this->vehicle_body_number]) | |
| ->orderBy('id DESC') | |
| ->one(); | |
| } | |
| if ($vehicle != null) { | |
| // $this->user_id = $vehicle['id']; | |
| $this->vehicle_owner_type = $this->vehicle_owner_type ?? $vehicle['vehicle_owner_type']; | |
| $this->vehicle_use_for_purpose = $this->vehicle_use_for_purpose ?? (isset($vehicle['vehicle_use_for_purpose']) ? $vehicle['vehicle_use_for_purpose'] : null); | |
| $this->vehicle_number = $this->vehicle_number??(strlen($this->vehicle_body_number) < 17 ? $this->vehicle_body_number : $vehicle['vehicle_number']); | |
| $this->body_number = $this->body_number??(strlen($this->vehicle_body_number) == 17 ? $this->vehicle_body_number : $vehicle['body_number']); | |
| $this->motor_number = $this->motor_number ?? $vehicle['motor_number']; | |
| $this->technical_passport = $this->technical_passport ?? $vehicle['technical_passport']; | |
| $this->technical_passport_date = $this->technical_passport_date ?? $vehicle['technical_passport_date']; | |
| $data = Functions::jsonDecode($vehicle['data']??$vehicle['library_data']); | |
| if ($this->vehicle_owner_type == 'physical') { | |
| $this->owner_last_name = $this->owner_last_name??($data['owner_last_name'] ?? null); | |
| $this->owner_first_name = $this->owner_first_name??($data['owner_first_name'] ?? null); | |
| $this->owner_sure_name = $this->owner_sure_name??($data['owner_sure_name'] ?? null); | |
| $this->owner_passport = $this->owner_passport??($data['owner_passport'] ?? null); | |
| $this->owner_address_physical = $this->owner_address_physical??($data['owner_address_physical'] ??null); | |
| $this->owner_region_physical = $this->owner_region_physical??($data['owner_region_physical']?? null); | |
| } else { | |
| $this->owner_name = $this->owner_name??($data['owner_name'] ?? null); | |
| $this->owner_inn = $this->owner_inn??($data['owner_inn'] ?? null); | |
| $this->owner_address_juridical = $this->owner_address_juridical??($data['owner_address_juridical'] ?? null); | |
| $this->owner_region_juridical = $this->owner_region_juridical??($data['owner_region_juridical'] ?? null); | |
| } | |
| } else { | |
| $this->vehicle_number = $this->vehicle_number ?? (strlen($this->vehicle_body_number) < 17 ? | |
| (preg_match('/\w{2}\-\d{7}/',$this->vehicle_body_number)?'':$this->vehicle_body_number) : ''); | |
| $this->body_number = $this->body_number ?? (strlen($this->vehicle_body_number) == 17 ? $this->vehicle_body_number : ''); | |
| } | |
| } | |
| public function destroySession() | |
| { | |
| session_destroy(); | |
| } | |
| public function calculatePolice($basic_book = true) | |
| { | |
| $this->getSessionValues(); | |
| $session = Yii::$app->session; | |
| if (!$session->isActive) | |
| $session->open(); | |
| $productType = ProductType::find() | |
| ->where(['type' => ProductType::tableVTS]) | |
| ->orderBy('id DESC') | |
| ->asArray() | |
| ->one(); | |
| $data = Functions::jsonDecode($productType['data']); | |
| $commision = $productType['commission']; | |
| $owner_type = $this->vehicle_owner_type; | |
| $energy_power = $weight = $suit = $moto = $trolleys = $trams = $tractors = | |
| $light_micro_for_taxi = $register_location = $drivers = $library_used = $drivers = 0; | |
| $all_info = []; | |
| if ($this->vehicle_type == 1) { | |
| if ($this->energy_power <= 1200) { | |
| $energy_power = $data['up_1200_' . $owner_type]; | |
| } elseif ($this->energy_power > 1200 and $this->energy_power <= 2200) { | |
| $energy_power = $data['over_1200_to_2200_' . $owner_type]; | |
| } elseif ($this->energy_power > 1200 and $this->energy_power <= 3200) { | |
| $energy_power = $data['over_2200_to_3200_' . $owner_type]; | |
| } elseif ($this->energy_power > 3200) { | |
| $energy_power = $data['over_3200_' . $owner_type]; | |
| } | |
| $all_info['Объем двигателя'] = $energy_power; | |
| } elseif ($this->vehicle_type == 2) { | |
| if ($this->weight <= 10) { | |
| $weight = $data['up_to_10_' . $owner_type]; | |
| } else { | |
| $weight = $data['over_10_' . $owner_type]; | |
| } | |
| $all_info['Грузоподъемность'] = $weight; | |
| } elseif ($this->vehicle_type == 3) { | |
| if ($this->suit <= 20) { | |
| $suit = $data['up_to_20_seat_' . $owner_type]; | |
| } else { | |
| $suit = $data['over_to_20_seat_' . $owner_type]; | |
| } | |
| $all_info['Количество мест'] = $suit; | |
| } elseif ($this->vehicle_type == 4) { | |
| $moto = $data['motorcycles_' . $owner_type]; | |
| $all_info['Вид транспорта: Мотоциклы'] = $moto; | |
| } elseif ($this->vehicle_type == 5) { | |
| $trolleys = $data['trolleys_' . $owner_type]; | |
| $all_info['Вид транспорта: Троллейбусы'] = $trolleys; | |
| } elseif ($this->vehicle_type == 6) { | |
| $trams = $data['trams_' . $owner_type]; | |
| $all_info['Вид транспорта: Трамваи'] = $trams; | |
| } elseif (in_array($this->vehicle_type, [7, 8])) { | |
| $tractors = $data['tractors_other_' . $owner_type]; | |
| $all_info['Вид транспорта: Тракторы,Спецтранспорт'] = $tractors; | |
| } | |
| // 01.10.2020 Oldin shart bor ekan, agar yengil va yuk mashina bo'lsa va taxi maqsadida foydalanilsa obyom dvigatelni 0 ga tenglansin degan (146 issue to'g'rilandi) | |
| // if (in_array($this->vehicle_type, [1, 3]) and $this->vehicle_use_for_purpose == 'taxi') { | |
| // $energy_power = $suit = 0; | |
| // $all_info['Количество мест'] = $suit; | |
| // $all_info['Объем двигателя'] = $energy_power; | |
| // // $light_micro_for_taxi = $data['light_micro_for_taxi_' . $owner_type]; | |
| // //$all_info['Цель использования: Taxi и Легковые,Автобус'] = $light_micro_for_taxi; | |
| // } | |
| $key = $this->getRegisterLocation($this->register_location_id); | |
| $register_location = ($key) ? $data[$key] : 0; | |
| $all_info['Место регистрации'] = $register_location; | |
| $experence = $old = $violation = $library_state = []; | |
| if ($this->driver_count == 'no-limits') { | |
| $drivers = $data['no_limit']; | |
| $all_info['Без ограничений'] = $drivers; | |
| } | |
| else { | |
| if ($this->last_name=='') { | |
| return false; | |
| } | |
| foreach ($this->last_name as $key => $item) { | |
| // Haydovchi staji | |
| $driver = Driver::find() | |
| ->joinWith(['library']) | |
| ->orWhere([ | |
| 'first_name' => $this->first_name[$key], | |
| 'last_name' => $this->last_name[$key], | |
| 'sure_name' => $this->sure_name[$key], | |
| 'gender' => $this->gender[$key], | |
| 'birth_day' => $this->birth_day[$key] | |
| ]) | |
| ->orWhere([ | |
| 'driving_license' => $this->driving_license[$key], | |
| 'driving_license_date' => $this->driving_license_date[$key], | |
| ]) | |
| ->orWhere(['passport' => $this->passport[$key]]) | |
| ->orderBy('driver.id ASC')->asArray() | |
| ->andWhere(['library.status'=>self::STATE_PAY_ACCEPTED]) | |
| ->one(); | |
| if ($driver != null) { | |
| $driver_experence = date('Y') - date('Y', strtotime($driver['driving_license_date'])); | |
| } else { | |
| $driver_experence = date('Y') - date('Y', strtotime($this->driving_license_date[$key])); | |
| } | |
| $this->driver_experence[$key] = $driver_experence; | |
| if ($driver_experence <= 2) { | |
| $experence[$key] = $data['up_to_2_years_including']; | |
| } elseif ($driver_experence > 2 and $driver_experence <= 5) { | |
| $experence[$key] = $data['from_2_to_5_years_including']; | |
| } else { | |
| $experence[$key] = $data['over_5_years']; | |
| } | |
| $dold = (date('Y') - date('Y', strtotime($this->birth_day[$key]))); | |
| $this->driver_old[$key] = $dold; | |
| // Haydovchi yoshi | |
| if ($dold <= 22) { | |
| $old[$key] = $data['up_to_22_years_including']; | |
| } else { | |
| $old[$key] = $data['over_22_years']; | |
| } | |
| if (isset($this->violation[$key]) and strpos($this->violation[$key], 'yes')) { | |
| $violation[$key] = $data['violations_occurred']; | |
| } else { | |
| $violation[$key] = $data['no_violations']; | |
| } | |
| $library_state[$key] = isset($this->library_state[$key]) ? $data[$this->library_state[$key]] : 0; | |
| } | |
| } | |
| $library_used = $this->register_location_id == 0 ?( | |
| $data['vehicles_used_' . $this->expired_at]??0) | |
| : ($data['clearance_used_' . $this->expired_at]??0); | |
| $all_info['именавой период'] = $library_used; | |
| $all_info['водительский стаж'] = count($experence) ? max($experence) : 0; | |
| $all_info['возраста водителя'] = count($old) ? max($old) : 0; | |
| $all_info['Нарушение правил именавания'] = count($library_state) ? max($library_state) : 0; | |
| $all_info['именавые случаи'] = count($violation) ? max($violation) : 0; | |
| $all = [ | |
| $energy_power, | |
| $weight, | |
| $suit, | |
| $moto, | |
| $trolleys, | |
| $trams, | |
| $tractors, | |
| $light_micro_for_taxi, | |
| $register_location, | |
| $drivers, | |
| $library_used, | |
| // Ko'p haydovchi bo'lsa | |
| count($experence) ? max($experence) : 0, | |
| count($old) ? max($old) : 0, | |
| count($library_state) ? max($library_state) : 0, | |
| count($violation) ? max($violation) : 0, | |
| ]; | |
| $sum = $sum_info = 1; | |
| if (count($all)) { | |
| $all = array_filter($all, function ($v) { | |
| return $v!=0; | |
| }); | |
| $sum = array_product($all); | |
| } | |
| $aa = []; | |
| if (count($all_info)) { | |
| $all_info = array_filter($all_info, function ($v) { | |
| return $v!=0; | |
| }); | |
| $sum_info = array_product($all_info); | |
| foreach ($all_info as $kk=>$item) { | |
| $aa[] ="($kk: $item)"; | |
| } | |
| } | |
| $this->library_summa = $sum * $commision / 100; | |
| $formula = '('.implode(' * ',$aa)." = $sum_info) * (именавая сумма = $commision) / 100 = ".$this->library_summa; | |
| if (!Yii::$app->user->isGuest) { | |
| $session->set('agent_company',false); | |
| $agent = CompanyHasAgent::find() | |
| ->joinWith(['companyHasAgents.company']) | |
| ->asArray() | |
| ->where([ | |
| 'company_has_agent.user_id' => Yii::$app->user->id, | |
| 'company_has_agent.status' => 'active', | |
| 'company.status' => 'active' | |
| ]) | |
| ->andWhere(['>=','contract_date',date('Y-m-d')]) | |
| ->indexBy('id') | |
| ->one(); | |
| if ($agent != null and $agent['companyHasAgents']) { | |
| $companyIDs = []; | |
| foreach ($agent['companyHasAgents'] as $item) { | |
| $type = Json::decode($item['product']); | |
| if (in_array(ProductType::tableVTS, array_keys($type))) { | |
| $companyIDs[$item['company_id']] = [ | |
| 'agent_id' => $agent['id'], | |
| 'percent' => $type[ProductType::tableVTS]??0, | |
| 'percent2' => $type[ProductType::book]??0, | |
| 'limit' => $agent['agent_limit'] | |
| ] ; | |
| } | |
| } | |
| $session->set('agent_company',$companyIDs); | |
| $products = Product::find() | |
| ->joinWith(['productType','company']) | |
| ->where([ | |
| 'product_type.type' => ProductType::tableVTS, | |
| 'product.status' => 'active' | |
| ]) | |
| ->andWhere(['in','company_id',array_keys($companyIDs)]) | |
| ->andWhere(['company.status'=>'active']) | |
| ->groupBy('company_id') | |
| ->orderBy('product.id DESC') | |
| ->asArray() | |
| ->all(); | |
| }else{ | |
| $products = Product::find() | |
| ->joinWith(['productType','company']) | |
| ->where(['product_type.type' => ProductType::tableVTS, 'product.status' => 'active']) | |
| ->andWhere(['company.status'=>'active']) | |
| ->groupBy('company_id') | |
| ->orderBy('product.id DESC') | |
| ->asArray() | |
| ->all(); | |
| } | |
| }else { | |
| $products = Product::find() | |
| ->joinWith(['productType','company']) | |
| ->where(['product_type.type' => ProductType::tableVTS, 'product.status' => 'active']) | |
| ->andWhere(['company.status'=>'active']) | |
| ->groupBy('company_id') | |
| ->orderBy('product.id DESC') | |
| ->asArray() | |
| ->all(); | |
| } | |
| if(!$this->vehicleModel){ | |
| return null; | |
| } | |
| foreach ($products as $product) { | |
| $agent1 = null; | |
| if (isset($session->get('agent_company')[$product['company_id']])) { | |
| $agent1 = $session->get('agent_company')[$product['company_id']]; | |
| } | |
| $hasDiscount = Discount::find() | |
| ->where(['status'=>'active']) | |
| ->andWhere(['like','product','"'.$product['id'].'"']) | |
| ->andWhere(['<=','start_date',date('Y-m-d')]) | |
| ->andWhere(['>=','end_date',date('Y-m-d')]) | |
| ->exists(); | |
| $d = null; | |
| // if($hasDiscount) { | |
| $d = $this->calculateDiscount($product); | |
| // } | |
| $this->dataPrice[$product['company_id']] = [ | |
| 'id' => $product['id'], | |
| 'commission' => $d?$product['max_commission']:0, | |
| 'library_summa' => $this->library_summa, | |
| 'formula1' => $formula, | |
| 'hasDiscount' => $hasDiscount, | |
| 'discount' => $d[0]??0, | |
| 'formula2' => $d[1]??'', | |
| 'agent' => $agent1 | |
| ]; | |
| } | |
| /** | |
| * book hisoblash | |
| */ | |
| $productsbook = Product::find() | |
| ->joinWith(['company']) | |
| ->where([ | |
| 'product.product_type_id' => ProductType::book, | |
| 'product.status' => 'active' | |
| ]) | |
| ->andWhere(['company.status'=>'active']) | |
| ->asArray() | |
| ->all(); | |
| $databook = []; | |
| $min = $f = []; | |
| $a = null; | |
| if ($productsbook) { | |
| foreach ($productsbook as $k=>$productbook) { | |
| $a = $this->calculatebook($productbook,$basic_book); | |
| $session->set('risk_summas', $this->risk_summas); | |
| // if($a[0]>0) { | |
| $agent1 = null; | |
| if (isset($session->get('agent_company')[$productbook['company_id']])) { | |
| $agent1 = $session->get('agent_company')[$productbook['company_id']]; | |
| } | |
| $hasDiscount = Discount::find() | |
| ->where(['status'=>'active']) | |
| ->andWhere(['like','product','"'.$productbook['id'].'"']) | |
| ->andWhere(['<=','start_date',date('Y-m-d')]) | |
| ->andWhere(['>=','end_date',date('Y-m-d')]) | |
| ->exists(); | |
| $databook[$productbook['company_id']] = [ | |
| 'id' => $productbook['id'], | |
| 'commission' => $hasDiscount?$productbook['main_commission']:0, | |
| 'library_summa' => $a[0], | |
| 'formula' => $a[1], | |
| 'agent' => $agent1 | |
| ]; | |
| // } | |
| // if ($a[0]!=0 or $a[0]<$min) { | |
| $min[$k] = (int)$a[0]; | |
| $f[$k] = $a[1]; | |
| // } | |
| } | |
| } | |
| if (!$basic_book) { | |
| $this->dataPricebook = $databook; | |
| }elseif($databook){ | |
| if(count($min)==1){ | |
| $m = current($min); | |
| $f = current($f); | |
| }else{ | |
| $min = array_filter($min); | |
| $m = min($min); | |
| $f = $f[array_flip($min)[$m]]; | |
| } | |
| $this->dataPricebook = [$m,$f]; | |
| } | |
| return 1; | |
| } | |
| public function calculatebook($product,$basic) | |
| { | |
| $data = Functions::jsonDecode($product['data']); | |
| // bazaviy ma'lumotlar | |
| $country = $this->vehicleModel->country_id; | |
| $created_year = $this->created_date; | |
| $energy_power = $this->energy_power; | |
| $car_type = $this->vehicleModel->car_type; | |
| $horse_power = $this->horse_power; | |
| $weight = $this->weight; | |
| $suit = $this->suit; | |
| $xadavoy = $this->vehicleModel->xadavoy; | |
| $using = $this->vehicleModel->using; | |
| $register_location_id = $this->register_location_id; | |
| $vehicle_owner_type = $this->vehicle_owner_type; | |
| $vehicle_use_for_purpose = $this->vehicle_use_for_purpose; | |
| $start_date = $this->start_date; | |
| $expired_at = $this->expired_at; | |
| /** | |
| * Minimalini olish uchun 0 dan boshqa holatlarda | |
| * | |
| * @param $array | |
| * @param $column | |
| * @param string $check | |
| * @return mixed|string|null | |
| */ | |
| $get_min = function ($array, $column, $check = 'check',$dump = false) { | |
| if ($array[$check] != 1) { | |
| $a = array_filter($array[$column], function ($v) { | |
| return $v!=0; | |
| }); | |
| return !empty($a) ? min($a) : 1; | |
| } | |
| return 1; | |
| }; | |
| /** | |
| * Massivda minimalini olish uchun 0 dan boshqa holatlarda | |
| * | |
| * @param $array | |
| * @return mixed|string | |
| */ | |
| $get_min_only = function ($array) { | |
| $a = array_filter($array, function ($v) { | |
| return $v!=0; | |
| }); | |
| return !empty($a) ? min($a) : 1; | |
| }; | |
| $get_max = function ($array, $column, $check = 'check',$dump = false) { | |
| if ($array[$check] != 1) { | |
| $a = $array[$column]; | |
| return !empty($a) ? max($a) : 1; | |
| } | |
| return null; | |
| }; | |
| /** | |
| * Max.ni olish uchun 0 dan boshqa holatlarda | |
| * | |
| * @param $array | |
| * @return mixed|string | |
| */ | |
| $get_max_only = function ($array) { | |
| $a = []; | |
| if (is_array($array)) { | |
| foreach ($array as $item) { | |
| if (is_null($item)) { | |
| continue; | |
| } | |
| $a[] = $item; | |
| } | |
| } | |
| return !empty($a) ? max($a) : 1; | |
| }; | |
| $all_koeff_risk = $all_info = $all_koeff_info = []; | |
| // $summa = is_array($this->book_summa)?array_sum($this->book_summa):null; | |
| if(!$basic){ | |
| $all_summa_koef = 0; | |
| if (is_array($this->book_summa)) { | |
| foreach ($this->book_summa as $key=>$item) { | |
| if ($item == '') { | |
| continue; | |
| } | |
| $a = $this->getSumKoef($data['section_top_3_1'], | |
| $item, '>=', 'check', 'value', 'percent'); | |
| $all_koeff_risk[$key][] = $a; | |
| $all_koeff_info[$key]['именавая сумма коэф'] = $a; | |
| $all_summa_koef += $a; | |
| } | |
| } | |
| if(!is_null($all_summa_koef) and $all_summa_koef==0) { | |
| return null; | |
| } | |
| // $all_koeff[] = $all_summa_koef; | |
| // $all_info['именавая сумма коеф.'] = $all_summa_koef; | |
| }else{ | |
| $summa = $get_min_only($data['section_top_3_1']['value']); | |
| if (!$summa) { | |
| return null; | |
| } | |
| } | |
| /** | |
| * Realni keladigan ma'lumotlar bn tekshirish | |
| */ | |
| if ($data['section_top_4_1']['check'] != 1) { | |
| $state = $data['section_top_4_1']; | |
| switch ($vehicle_owner_type) { | |
| case 'juridical': | |
| $all_koeff[] = !isset($state['juridical_check']) ? $state['juridical'] : null; | |
| $all_info['юридическое лицо'] = !isset($state['juridical_check']) ? $state['juridical'] : null; | |
| break; | |
| case 'physical': | |
| $all_koeff[] = !isset($state['physical_check']) ? $state['physical'] : null; | |
| $all_info['физическое лицо'] = !isset($state['physical_check']) ? $state['physical'] : null; | |
| break; | |
| case 'indivudal': | |
| $all_koeff[] = !isset($state['indivudal_check']) ? $state['indivudal'] : null; | |
| $all_info['индивидуальный предприниматель'] = !isset($state['indivudal_check']) ? $state['indivudal'] : null; | |
| break; | |
| } | |
| } | |
| if ($data['section_top_4_2']['check'] != 1) { | |
| $state = $data['section_top_4_2']; | |
| $loyalnost = library::find() | |
| ->joinWith('product') | |
| ->orWhere(['like', 'vehicle_number', $this->vehicle_body_number]) | |
| ->orWhere(['like', 'body_number', $this->vehicle_body_number]) | |
| ->orWhere(['like', 'library_number', $this->vehicle_body_number]) | |
| ->andWhere(['between', 'library.created_at', | |
| date('Y-m-d H:i:s', strtotime('-5 years')), date('Y-m-d H:i:s')]) | |
| ->andWhere([ | |
| 'product.company_id' => $product['company_id'], | |
| 'library.status' => self::STATE_PAY_ACCEPTED | |
| ]) | |
| ->orderBy('library.id ASC') | |
| ->asArray() | |
| ->one(); | |
| $loyalnost_year = 0; | |
| if ($loyalnost != null) { | |
| $loyalnost_year = date('Y') - date('Y', strtotime($loyalnost['created_at'])); | |
| } | |
| switch ($loyalnost_year) { | |
| case 1: | |
| $loyal = !isset($state['one_check']) ? $state['one'] : null; | |
| break; | |
| case 2: | |
| $loyal = !isset($state['two_check']) ? $state['two'] : null; | |
| break; | |
| case 3: | |
| $loyal = !isset($state['three_check']) ? $state['three'] : null; | |
| break; | |
| case 4: | |
| $loyal = !isset($state['four_check']) ? $state['four'] : null; | |
| break; | |
| case 5: | |
| $loyal = !isset($state['five_check']) ? $state['five'] : null; | |
| break; | |
| default: | |
| $loyal = null; | |
| break; | |
| } | |
| $all_koeff[] = $loyal; | |
| $all_info['лояльности именавателья'] = $loyal; | |
| } | |
| if ($data['section_top_4_7']['check']!=1) { | |
| $current_library = library::find() | |
| ->joinWith('product') | |
| ->orWhere(['like', 'vehicle_number', $this->vehicle_body_number]) | |
| ->orWhere(['like', 'body_number', $this->vehicle_body_number]) | |
| ->orWhere(['like', 'library_number', $this->vehicle_body_number]) | |
| ->andWhere(['between', 'library.created_at', date('Y-m-d H:i:s', strtotime('-1 years')), date('Y-m-d H:i:s')]) | |
| ->andWhere([ | |
| 'product.company_id'=>$product['company_id'], | |
| 'library.status'=>self::STATE_PAY_ACCEPTED | |
| ]) | |
| ->orderBy('id DESC') | |
| ->asArray() | |
| ->count(); | |
| $aa = $this->getSumKoef($data['section_top_4_7'], $current_library, '>=', false, 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['количество заименаванных машын'] = $aa; | |
| } | |
| if ($this->driver_count and $this->driver_count != 'no-limits') { | |
| $aa = $this->getSumKoef($data['section_top_5_1'], count($this->last_name), '==', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' количества водителей'] = $aa; | |
| $male = $female = 0; | |
| $driver_old = $driver_no_state = $driver_experence = $driver_state = null; | |
| foreach ($this->last_name as $key => $item) { | |
| $this->gender[$key] == 'male' ? $male++ : $female++; | |
| // Haydovchi yoshi | |
| $driver_old[] = $this->getSumKoef($data['section_top_5_5'], $this->driver_old[$key]??18, '>=', 'check', 'value', 'percent'); | |
| $driver_experences = $this->driver_experence[$key]??0; | |
| $driver_experence[] = $this->getSumKoef($data['section_top_5_6'], $driver_experences, '>=', 'check', 'value', 'percent'); | |
| // Haydovchi halokat soni | |
| if (isset($this->driver_library_state[$key])) { | |
| $driver_state[] = $this->getSumKoefThree($data['section_top_5_7'], $this->driver_library_state[$key], '>=', 'check', 'year', 'value', 'percent'); | |
| } | |
| // Haydovchi sug'urta qoida buzmagani | |
| if ($data['section_top_5_8']['check'] != 1) { | |
| $state = $data['section_top_5_8']; | |
| switch ($this->driver_violation[$key]) { | |
| case 1: | |
| $driver_no_state[] = !isset($state['one_check']) ? $state['one'] : null; | |
| break; | |
| case 2: | |
| $driver_no_state[] = !isset($state['two_check']) ? $state['two'] : null; | |
| break; | |
| case 3: | |
| $driver_no_state[] = !isset($state['three_check']) ? $state['three'] : null; | |
| break; | |
| case 4: | |
| $driver_no_state[] = !isset($state['four_check']) ? $state['four'] : null; | |
| break; | |
| case 5: | |
| $driver_no_state[] = !isset($state['five_check']) ? $state['five'] : null; | |
| break; | |
| default: | |
| $driver_no_state[] = null; | |
| break; | |
| } | |
| } | |
| } | |
| $aa1 = $get_max_only($driver_old); | |
| $aa2 = $get_max_only($driver_experence); | |
| $aa3 = $get_max_only($driver_state); | |
| $aa4 = $get_max_only($driver_no_state); | |
| $all_koeff[] = $aa1; | |
| $all_koeff[] = $aa2; | |
| $all_koeff[] = $aa3; | |
| $all_koeff[] = $aa4; | |
| $all_info['возраста водителя(ей)'] = $aa1; | |
| $all_info['стажа водителя(ей)'] = $aa2; | |
| $all_info['именавых случаев'] = $aa3; | |
| $all_info['нарушения водителем правил'] = $aa4; | |
| // Haydovchi jinsi | |
| if ($data['section_top_5_10']['check'] != 1) { | |
| $gender = null; | |
| if (!isset($data['section_top_5_10']['female_check']) and $female > 0 and $female >= $male) { | |
| $gender[] = $data['section_top_5_10']['female']; | |
| } | |
| if (!isset($data['section_top_5_10']['male_check']) and $male > 0 and $male >= $female) { | |
| $gender[] = $data['section_top_5_10']['male']; | |
| } | |
| $all_koeff[] = $get_max_only($gender); | |
| $all_info['пола водителя'] = $get_max_only($gender);; | |
| } | |
| }else{ | |
| $aa = $this->getSumKoef($data['section_top_5_1'], 0, '==', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['количества водителей'] = $aa; | |
| } | |
| if($data['section_top_7_5']['check']!=1) { | |
| $state = $data['section_top_7_5']; | |
| $types = Functions::jsonDecodeArray(ProductType::getList()); | |
| $a = null; | |
| foreach ($types as $type=>$name) { | |
| $current_library = library::find() | |
| ->joinWith('product') | |
| ->orWhere(['like', 'vehicle_number', $this->vehicle_body_number]) | |
| ->orWhere(['like', 'body_number', $this->vehicle_body_number]) | |
| ->orWhere(['like', 'library_number', $this->vehicle_body_number]) | |
| ->andWhere(['between', 'library.created_at', | |
| date('Y-m-d H:i:s', strtotime('-1 years')), date('Y-m-d H:i:s')]) | |
| ->andWhere([ | |
| 'product.company_id' => $product['company_id'], | |
| 'product.product_type_id' => $type, | |
| 'library.status' => self::STATE_PAY_ACCEPTED, | |
| ]) | |
| ->orderBy('library.id DESC') | |
| ->asArray()->exists(); | |
| if($current_library){ | |
| $b = $this->getSumKoef($state, $type, '==', false, 'value', 'percent'); | |
| if(!is_null($b) and is_null($a)){ | |
| $a = 0; | |
| } | |
| if(!is_null($b)) { | |
| $a += $b; | |
| } | |
| } | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['именавания по другим продуктам'] = $a; | |
| } | |
| if ($basic) { | |
| // $all_summa_koef = $this->getSumKoef($data['section_top_3_1'], | |
| // $summa, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $get_min($data['section_top_3_2'], 'percent'); | |
| $all_info['валюты(min)'] = $get_min($data['section_top_3_2'], 'percent'); | |
| if ($data['section_top_3_3']['check'] != 1) { | |
| $state = $data['section_top_3_3']; | |
| $a = []; | |
| if (!isset($state['aggregate_check'])) { | |
| $a[] = $state['aggregate']; | |
| } | |
| if (!isset($state['nonaggregate_check'])) { | |
| $a[] = $state['nonaggregate']; | |
| } | |
| $all_koeff[] = $get_min_only($a); | |
| $all_info['типа именавой суммы (min)'] = $get_min_only($a); | |
| } | |
| if ($vehicle_owner_type != 'physical') { | |
| $all_koeff[] = $get_min($data['section_top_4_3'], 'percent'); | |
| $all_info['вида деятельности именавателья (min)'] = $get_min($data['section_top_4_3'], 'percent'); | |
| } else { | |
| // $all_koeff[] = $get_min($data['section_top_4_6'], 'percent'); // ligota oxirda ko'rsatiladigan | |
| } | |
| $all_koeff[] = $get_min($data['section_top_4_4'], 'percent'); | |
| $all_info['места жительство(min)'] = $get_min($data['section_top_4_4'], 'percent'); | |
| $all_koeff[] = $get_min($data['section_top_4_5'], 'percent'); | |
| $all_info['гражданство(min)'] = $get_min($data['section_top_4_5'], 'percent'); | |
| if ($data['section_top_7_1']['check'] != 1) { | |
| $a = []; | |
| if (!isset($data['section_top_7_1']['yes_check'])) { | |
| $a[] = $data['section_top_7_1']['yes']; | |
| } | |
| if (!isset($data['section_top_7_1']['no_check'])) { | |
| $a[] = $data['section_top_7_1']['no']; | |
| } | |
| $all_koeff[] = $get_min_only($a); | |
| $all_info['типа франшизы(min)'] = $get_min_only($a); | |
| } | |
| $all_koeff[] = $get_min($data['section_top_7_2'], 'percent'); | |
| $all_info['размера франшизы(min)'] = $get_min($data['section_top_7_2'], 'percent'); | |
| $all_koeff[] = $get_min($data['section_top_7_3'], 'percent'); | |
| $all_info['рассрочки оплаты именавой премии(min)'] = $get_min($data['section_top_7_3'], 'percent'); | |
| // book sug'urta muddati yangi qo'shildi 20.08.2020 | |
| $all_koeff[] = $get_min($data['section_top_7_9'], 'percent'); | |
| $all_info['срок именавания(min)'] = $get_min($data['section_top_7_9'], 'percent'); | |
| if ($data['section_top_7_4']['check'] != 1) { | |
| $state = $data['section_top_7_4']; | |
| $loyal = []; | |
| $loyal[] = !isset($state['value1_check']) ? $state['value1'] : null; | |
| $loyal[] = !isset($state['value2_check']) ? $state['value2'] : null; | |
| $loyal[] = !isset($state['value3_check']) ? $state['value3'] : null; | |
| $loyal[] = !isset($state['value4_check']) ? $state['value4'] : null; | |
| $loyal[] = !isset($state['value5_check']) ? $state['value5'] : null; | |
| $loyal[] = !isset($state['value6_check']) ? $state['value6'] : null; | |
| $all_koeff[] = $get_min_only($loyal); | |
| $all_info['условий выплаты именавого возмещения(min)'] = $get_min_only($loyal); | |
| } | |
| if ($data['section_top_7_8']['check'] != 1) { | |
| $state = $data['section_top_7_8']; | |
| $a = []; | |
| if (!isset($state['yes_check'])) { | |
| $a[] = $state['yes']; | |
| } | |
| if (!isset($state['no_check'])) { | |
| $a[] = $state['no']; | |
| } | |
| $object_clearance=$get_min_only($a); | |
| } | |
| if($get_min($data['section_top_7_6'], 'percent') < $object_clearance) | |
| { | |
| $all_koeff[] = $get_min($data['section_top_7_6'], 'percent'); | |
| $all_info['типа именавого риска(min)'] = $get_min($data['section_top_7_6'], 'percent'); | |
| $all_koeff[] = $get_min($data['section_top_7_7'], 'percent'); | |
| $all_info['типа именавого покрытия(min)'] = $get_min($data['section_top_7_7'], 'percent'); | |
| } | |
| else | |
| { | |
| $all_koeff[] = $object_clearance; | |
| $all_info['объекта именавания(min)'] = $object_clearance; | |
| } | |
| //var_dump($get_min($data['section_top_7_6'],'percent'),$get_min_only($a));die(); | |
| // if ($data['section_top_8_1']['check'] != 1) { | |
| // $state = $data['section_top_8_1']; | |
| // $a = []; | |
| // if (!isset($state['yes_check'])) { | |
| // $a[] = $state['yes']; | |
| // } | |
| // if (!isset($state['no_check'])) { | |
| // $a[] = $state['no']; | |
| // } | |
| // $all_koeff[] = $get_min_only($a); | |
| // } | |
| $all_koeff[] = $get_min($data['section_top_8_2'], 'percent'); | |
| $all_info['условий хранения ТС (min)'] = $get_min($data['section_top_8_2'], 'percent'); | |
| $all_koeff[] = $get_min($data['section_top_8_3'], 'percent'); | |
| $all_info['ограничений ТС (min)'] = $get_min($data['section_top_8_3'], 'percent'); | |
| $all_koeff[] = $get_min($data['section_top_8_4'], 'percent'); | |
| $all_info['выгодоприобретателя(min)'] = $get_min($data['section_top_8_4'], 'percent'); | |
| if ($data['section_top_8_5']['check'] != 1) { | |
| $state = $data['section_top_8_5']; | |
| $a = []; | |
| if (!isset($state['min_check'])) { | |
| $a[] = $state['min']; | |
| } | |
| if (!isset($state['max_check'])) { | |
| $a[] = $state['max']; | |
| } | |
| $all_koeff[] = $get_min_only($a); | |
| $all_info[' гарантийного обслуживания ТС (min)'] = $get_min_only($a); | |
| } | |
| $all_koeff[] = $get_min($data['section_top_8_6'], 'percent'); | |
| $all_info['системы сигнализации ТС(min)'] = $get_min($data['section_top_8_6'], 'percent'); | |
| $all_koeff[] = $get_min($data['section_top_8_7'], 'percent'); | |
| $all_info['ремонта ТС (min)'] = $get_min($data['section_top_8_7'], 'percent'); | |
| $all_koeff[] = $get_min($data['section_top_8_8'], 'percent'); | |
| $all_info[' оплаты дополнительных услуг (min)'] = $get_min($data['section_top_8_8'], 'percent'); | |
| } | |
| if(!$basic){ | |
| if (is_array($this->book_currency)) { | |
| $a = null; | |
| foreach ($this->book_currency as $key=>$item) { | |
| if ($item == '') { | |
| continue; | |
| } | |
| if (is_null($a)) { | |
| $a = 0; | |
| } | |
| $c = $this->getSumKoef($data['section_top_3_2'],$item, '==', 'check', 'value', 'percent'); | |
| $all_koeff_risk[$key][] = $c; | |
| $all_koeff_info[$key]['валюты'] = $c; | |
| $a += $c; | |
| } | |
| // $all_koeff[] = $a; | |
| // $all_info['валюты'] = $a; | |
| } | |
| if (is_array($this->book_type_summa)) { | |
| $a = null; | |
| foreach ($this->book_type_summa as $key=>$item) { | |
| if ($item == '') { | |
| continue; | |
| } | |
| if ($data['section_top_3_3']['check'] != 1) { | |
| $state = $data['section_top_3_3']; | |
| if (!isset($state['aggregate_check']) and $item=='aggregate') { | |
| if (is_null($a)) { | |
| $a = 0; | |
| } | |
| $c = $state['aggregate']; | |
| $all_koeff_risk[$key][] = $c; | |
| $all_koeff_info[$key]['типа именавой суммы'] = $c; | |
| $a += $c; | |
| } elseif (!isset($state['nonaggregate_check']) and $item=='nonaggregate') { | |
| if (is_null($a)) { | |
| $a = 0; | |
| } | |
| $c = $state['nonaggregate']; | |
| $all_koeff_risk[$key][] = $c; | |
| $all_koeff_info[$key]['типа именавой суммы'] = $c; | |
| $a += $c; | |
| } | |
| } | |
| } | |
| if (!is_null($a)) { | |
| // $all_koeff[] = $a; | |
| // $all_info['типа именавой суммы'] = $a; | |
| } | |
| } | |
| if($vehicle_owner_type!='physical') { | |
| $aa = $this->juridic_activity?$this->getOnlyExpectSum($data['section_top_4_3'], $this->juridic_activity, 'check', 'type', 'value', 'percent') | |
| :$get_max($data['section_top_4_3'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['типа именавателья '] = $aa; | |
| } | |
| $aa = $this->getOnlyExpectSumRegion($data['section_top_4_4'], $this->clearance_region, 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['места жительство (места деятельности) именавателья'] = $aa; | |
| $aa = $this->getOnlyExpectSum($data['section_top_4_5'], $this->clearance_country, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['гражданство (юрисдикции) именавателья'] = $aa; | |
| if ($data['section_top_7_1']['check'] != 1) { | |
| $state = $data['section_top_7_1']; | |
| if (is_array($this->franshiza_type)) { | |
| $a = null; | |
| foreach ($this->franshiza_type as $key=>$item) { | |
| if (is_null($a)) { | |
| $a = 0; | |
| } | |
| if (!isset($state['yes_check']) and $item == 'yes') { | |
| $c = $state['yes']; | |
| $all_koeff_risk[$key][] = $c; | |
| $all_koeff_info[$key]['типа франшизы'] = $c; | |
| $a += $c; | |
| } elseif (!isset($state['no_check']) and $item == 'no') { | |
| $c = $state['no']; | |
| $all_koeff_risk[$key][] = $c; | |
| $all_koeff_info[$key]['типа франшизы'] = $c; | |
| $a += $c; | |
| } else { | |
| if (!isset($state['yes_check']) and !isset($state['no_check'])) { | |
| $c = $get_max_only([$state['yes'], $state['no']]); | |
| $all_koeff_risk[$key][] = $c; | |
| $all_koeff_info[$key]['типа франшизы'] = $c; | |
| $a += $c; | |
| } elseif (!isset($state['yes_check'])) { | |
| $c = $state['yes']; | |
| $all_koeff_risk[$key][] = $c; | |
| $all_koeff_info[$key]['типа франшизы'] = $c; | |
| $a += $c; | |
| } else { | |
| $c = $state['no']; | |
| $all_koeff_risk[$key][] = $c; | |
| $all_koeff_info[$key]['типа франшизы'] = $c; | |
| $a += $c; | |
| } | |
| } | |
| } | |
| if (!is_null($a)) { | |
| // $all_koeff[] = $a; | |
| // $all_info['типа франшизы'] = $a; | |
| } | |
| } | |
| } | |
| if (is_array($this->franshiza_percent)) { | |
| $a = null; | |
| foreach ($this->franshiza_percent as $key=>$item) { | |
| if (is_null($a)) { | |
| $a = 0; | |
| } | |
| $c = $item!=''?$this->getSumKoef($data['section_top_7_2'], | |
| $item, '>=', 'check', 'value', 'percent') | |
| :$get_max($data['section_top_7_2'],'percent'); | |
| $all_koeff_risk[$key][] = $c; | |
| $all_koeff_info[$key]['размера франшизы'] = $c; | |
| $a += $c; | |
| } | |
| if (!is_null($a)) { | |
| // $all_koeff[] = $a; | |
| // $all_info['размера франшизы'] = $a; | |
| } | |
| } | |
| // $all_koeff[] = $this->franshiza_percent!=''?$this->getSumKoef($data['section_top_7_2'], | |
| // $this->franshiza_percent, '>=', 'check', 'value', 'percent') | |
| // :$get_max($data['section_top_7_2'],'percent'); | |
| $aa = $this->getSumKoef($data['section_top_7_3'], | |
| $this->rasrochka, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['рассрочки оплаты именавой премии'] = $aa; | |
| // book uchun sug'urta muddati qo'shildi | |
| $book_srok = abs((strtotime($this->book_srok)-strtotime($this->start_date))/60/60/24); | |
| $aa = $this->getSumKoef($data['section_top_7_9'], | |
| $book_srok, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['срок именавания'] = $aa; | |
| if ($data['section_top_7_4']['check'] != 1) { | |
| $state = $data['section_top_7_4']; | |
| switch ($this->payment_book_type) { | |
| case 'value1': | |
| $loyal = !isset($state['value1_check']) ? $state['value1'] : null; | |
| break; | |
| case 'value2': | |
| $loyal = !isset($state['value2_check']) ? $state['value2'] : null; | |
| break; | |
| case 'value3': | |
| $loyal = !isset($state['value3_check']) ? $state['value3'] : null; | |
| break; | |
| case 'value4': | |
| $loyal = !isset($state['value4_check']) ? $state['value4'] : null; | |
| break; | |
| case 'value5': | |
| $loyal = !isset($state['value5_check']) ? $state['value5'] : null; | |
| break; | |
| case 'value6': | |
| $loyal = !isset($state['value6_check']) ? $state['value6'] : null; | |
| break; | |
| default: | |
| $loyal = null; | |
| break; | |
| } | |
| $all_koeff[] = $loyal; | |
| $all_info['условий выплаты именавого возмещения'] = $loyal; | |
| } | |
| if($this->book_risk and $data['section_top_7_6']['check']!=1) { | |
| $state = $data['section_top_7_6']; | |
| foreach ($this->book_risk as $key=>$book_risk) { | |
| $a = null; | |
| //book risk mavjud bo'lsa degan shart qo'yildi | |
| if($book_risk){ | |
| foreach($book_risk as $chiki=>$book_risk) | |
| { | |
| // echo '<pre>'; var_dump($book_risk);die;s | |
| $b = $this->getSumKoef($state, $book_risk, '==', false, 'value', 'percent'); | |
| if(!is_null($b) and is_null($a)){ | |
| $a = 0; | |
| } | |
| if(!is_null($b)) { | |
| $a += $b; | |
| } | |
| } | |
| } | |
| $all_koeff_risk[$key][] = $a; | |
| $all_koeff_info[$key]['типа именавого риска'] = $a; | |
| } | |
| if (!is_null($a)) { | |
| // $all_koeff[] = $a; | |
| // $all_info['типа именавого риска'] = $a; | |
| } | |
| } | |
| if($this->cover and $data['section_top_7_7']['check']!=1) { | |
| $state = $data['section_top_7_7']; | |
| foreach ($this->cover as $key=>$covers) { | |
| $a = null; | |
| if($covers){ | |
| foreach($covers as $key2=>$cover){ | |
| $b = $this->getSumKoef($state, $cover, '==', false, 'value', 'percent'); | |
| if(!is_null($b) and is_null($a)){ | |
| $a = 0; | |
| } | |
| if(!is_null($b)) { | |
| $a += $b; | |
| } | |
| } | |
| $all_koeff_risk[$key][] = $a; | |
| $all_koeff_info[$key]['типа именавого покрытия'] = $a; | |
| } | |
| } | |
| } | |
| if ($this->book_type_object and $data['section_top_7_8']['check'] != 1) { | |
| $state = $data['section_top_7_8']; | |
| $a = null; | |
| foreach ($this->book_type_object as $key=>$item) { | |
| if (!isset($state['yes_check']) and 'yes'==$item) { | |
| $b = $state['yes']; | |
| if(!is_null($b)){ | |
| if(is_null($a)){ | |
| $a = 0; | |
| } | |
| $all_koeff_risk[$key][] = $b; | |
| $all_koeff_info[$key]['объекта именавания'] = $b; | |
| $a += $b; | |
| } | |
| } | |
| if (!isset($state['no_check']) and 'no'==$item) { | |
| $b = $state['no']; | |
| if(!is_null($b)){ | |
| if(is_null($a)){ | |
| $a = 0; | |
| } | |
| $all_koeff_risk[$key][] = $b; | |
| $all_koeff_info[$key]['объекта именавания'] = $b; | |
| $a += $b; | |
| } | |
| } | |
| } | |
| if (!is_null($a)) { | |
| // $all_koeff[] = $a; | |
| // $all_info['объекта именавания'] = $a; | |
| } | |
| } | |
| $aa = $this->parking? | |
| $this->getSumKoef($data['section_top_8_2'], $this->parking, '==', 'check', 'value', 'percent') | |
| : $get_max($data['section_top_8_2'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' условий хранения ТС'] = $aa; | |
| if($this->permission and $data['section_top_8_3']['check']!=1) { | |
| $state = $data['section_top_8_3']; | |
| $a = null; | |
| foreach ($this->permission as $permission) { | |
| $b = $this->getSumKoef($state, $permission, '==', false, 'value', 'percent'); | |
| if(!is_null($b) and is_null($a)){ | |
| $a = 0; | |
| } | |
| if(!is_null($b)) { | |
| $a += $b; | |
| } | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['ограничений ТС'] = $a; | |
| } | |
| $aa = $this->benifit? | |
| $this->getSumKoef($data['section_top_8_4'], $this->benifit, '==', 'check', 'value', 'percent') | |
| : $get_max($data['section_top_8_4'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['выгодоприобретателя'] = $aa; | |
| if ($data['section_top_8_5']['check'] != 1) { | |
| $state = $data['section_top_8_5']; | |
| $expired_date = date('Y-m-d',strtotime($start_date . "+".$expired_at." days")); | |
| if($this->expire_at_book and $this->expire_at_book>=$expired_date and !isset($state['max_check'])){ | |
| $all_koeff[] = $state['max']; | |
| $all_info['гарантийного обслуживания ТС (max)'] = $state['max']; | |
| }elseif($this->expire_at_book and $this->expire_at_book<=$expired_date and !isset($state['min_check'])){ | |
| $all_koeff[] = $state['min']; | |
| $all_info['гарантийного обслуживания ТС (min)'] = $state['min']; | |
| }elseif (!$this->expire_at_book and !isset($state['min_check']) and !isset($state['max_check'])){ | |
| $all_koeff[] = $get_max_only([$state['min'],$state['max']]); | |
| $all_info['гарантийного обслуживания ТС (min koef)'] = $state['max']; | |
| }elseif (!$this->expire_at_book and !isset($state['min_check'])){ | |
| $all_koeff[] =$state['min']; | |
| $all_info['гарантийного обслуживания ТС (min)'] = $state['max']; | |
| }elseif (!$this->expire_at_book and !isset($state['max_check'])){ | |
| $all_koeff[] = $state['max']; | |
| $all_info['гарантийного обслуживания ТС (max)'] = $state['max']; | |
| } | |
| } | |
| $aa = $this->getSumKoef($data['section_top_8_6'], $this->signal, '==', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['системы сигнализации ТС'] = $aa; | |
| $aa = $this->remont? | |
| $this->getSumKoef($data['section_top_8_7'], $this->remont, '==', 'check', 'value', 'percent') | |
| : $get_max($data['section_top_8_7'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['ремонта ТС'] = $aa; | |
| if($this->extra_services and $data['section_top_8_8']['check']!=1) { | |
| $state = $data['section_top_8_8']; | |
| $a = null; | |
| foreach ($this->extra_services as $extra_service) { | |
| $b = $this->getSumKoef($state, $extra_service, '==', false, 'value', 'percent'); | |
| if(!is_null($b) and is_null($a)){ | |
| $a = 0; | |
| } | |
| if(!is_null($b)) { | |
| $a += $b; | |
| } | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['оплаты дополнительных услуг'] = $a; | |
| } | |
| } | |
| if ($this->vehicle_type == 1) { | |
| $all_koeff[] = $data['section_top_6_1']['light']??null; | |
| $all_info['ТС легковое'] = $data['section_top_6_1']['light']??null; | |
| // Mashina ishlab chiqarilgan | |
| $aa = $this->getOnlyExpectSum($data['section_1_1'], | |
| $country, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['страны производства'] = $aa; | |
| if ($data['section_1_2']['check'] != 1) { | |
| $state = $data['section_1_2']; | |
| if ($basic or $this->yonilgi_turi=='') { | |
| $a = []; | |
| if (!isset($state['petrol_check'])) { | |
| $a[] = $state['petrol']; | |
| } | |
| if (!isset($state['diesel_check'])) { | |
| $a[] = $state['diesel']; | |
| } | |
| if (!isset($state['electric_check'])) { | |
| $a[] = $state['electric']; | |
| } | |
| if (!isset($state['hybrid_check'])) { | |
| $a[] = $state['hybrid']; | |
| } | |
| if($basic){ | |
| $all_koeff[] = $get_min_only($a); | |
| $all_info['типа двигателя ТС(min)'] = $get_min_only($a); | |
| }else{ | |
| $all_koeff[] = $get_max_only($a); | |
| $all_info['типа двигателя ТС (max)'] = $get_max_only($a); | |
| } | |
| }else{ | |
| $a = null; | |
| if ($this->yonilgi_turi=='petrol' and !isset($state['petrol_check'])) { | |
| $a = $state['petrol']; | |
| } | |
| if ($this->yonilgi_turi=='diesel' and !isset($state['diesel_check'])) { | |
| $a = $state['diesel']; | |
| } | |
| if ($this->yonilgi_turi=='electric' and !isset($state['electric_check'])) { | |
| $a = $state['electric']; | |
| } | |
| if ($this->yonilgi_turi=='hybrid' and !isset($state['hybrid_check'])) { | |
| $a = $state['hybrid']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа двигателя ТС'] = $a; | |
| } | |
| } | |
| // Mashina obyomi bo'yicha hisoblash | |
| $aa = $this->getSumKoef($data['section_1_3'], $energy_power, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['объема двигателя ТС'] = $aa; | |
| $aa = $this->getSumKoef($data['section_1_4'], $horse_power, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['мощности двигателя ТС'] = $aa; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $aa = $this->getSumKoef($data['section_1_5'], date('Y') - $created_year, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['возраста ТС'] = $aa; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $aa = $this->getSumKoefThree($data['section_1_7'], $this->vehicle_library_state, '>=', 'check', 'year', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' именавых случаев с данным ТС'] = $aa; | |
| if(!$basic){ | |
| $aa = $this->getSumKoef($data['section_1_6'], $this->probeg, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['пробега'] = $aa; | |
| // Mashina komplek | |
| $aa = $this->getYesNoSum($data['section_1_9'], $this->tyuning, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['комплектации ТС '] = $aa; | |
| $aa = $this->privod?$this->getSumKoef($data['section_1_12'], $this->privod, '==', 'check', 'value', 'percent') | |
| :$get_max($data['section_1_12'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['типа привода'] = $aa; | |
| $aa = $this->eko_klass?$this->getSumKoef($data['section_1_13'], $this->eko_klass, '==', 'check', 'value', 'percent') | |
| :$get_max($data['section_1_13'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['уровня экологического класса'] = $aa; | |
| }else{ | |
| $all_koeff[] = $get_min($data['section_1_6'],'percent'); | |
| $all_info['пробега'] = $get_min($data['section_1_6'],'percent'); | |
| $all_koeff[] = $get_min($data['section_1_9'],'percent'); | |
| $all_info['комплектации ТС'] = $get_min($data['section_1_9'],'percent'); | |
| $all_koeff[] = $get_min($data['section_1_12'],'percent'); | |
| $all_info['типа привода'] = $get_min($data['section_1_12'],'percent'); | |
| $all_koeff[] = $get_min($data['section_1_13'],'percent'); | |
| $all_info['уровня экологического класса'] = $get_min($data['section_1_13'],'percent'); | |
| } | |
| if ($data['section_1_8']['check'] != 1) { | |
| $state = $data['section_1_8']; | |
| $a = []; | |
| if ($basic or $this->karobka=='') { | |
| if (!isset($state['automatic_check'])) { | |
| $a[] = $state['automatic']; | |
| } | |
| if (!isset($state['manual_check'])) { | |
| $a[] = $state['manual']; | |
| } | |
| $aa = $basic?$get_min_only($a):$get_max_only($a); | |
| $all_koeff[] = $aa; | |
| $all_info['типа коробки передач'] = $aa; | |
| }else{ | |
| $a = null; | |
| if ($this->karobka=='automatic' and !isset($state['automatic_check'])) { | |
| $a = $state['automatic']; | |
| } | |
| if ($this->karobka=='manual' and !isset($state['manual_check'])) { | |
| $a = $state['manual']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа коробки передач'] = $a; | |
| } | |
| } | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $aa = $this->getVehicleSum($data['section_1_10'], 'check', 'value'); | |
| $all_koeff[] = $aa; | |
| $all_info['марки и модели ТС'] = $aa; | |
| // Mashina foydalanish | |
| $aa = $this->getOnlyExpectSum($data['section_1_11'], $vehicle_use_for_purpose, | |
| 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['использования ТС '] = $aa; | |
| $aa = $this->getOnlyExpectSumRegion($data['section_1_14'], $register_location_id, 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['места регистрации'] = $aa; | |
| } | |
| elseif ($this->vehicle_type == 2) { | |
| $all_koeff[] = $data['section_top_6_1']['truck']??null; | |
| $all_info['грузовое'] = $data['section_top_6_1']['truck']??null; | |
| // Mashina ishlab chiqarilgan | |
| $aa = $this->getOnlyExpectSum($data['section_2_1'], | |
| $country, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['страны производства'] = $aa; | |
| if ($data['section_2_2']['check'] != 1) { | |
| $state = $data['section_2_2']; | |
| if ($basic or $this->yonilgi_turi=='') { | |
| $a = []; | |
| if (!isset($state['petrol_check'])) { | |
| $a[] = $state['petrol']; | |
| } | |
| if (!isset($state['diesel_check'])) { | |
| $a[] = $state['diesel']; | |
| } | |
| if (!isset($state['hybrid_check'])) { | |
| $a[] = $state['hybrid']; | |
| } | |
| if($basic){ | |
| $all_koeff[] = $get_min_only($a); | |
| $all_info['типа двигателя ТС(min)'] = $get_min_only($a); | |
| }else{ | |
| $all_koeff[] = $get_max_only($a); | |
| $all_info['типа двигателя ТС (max)'] = $get_max_only($a); | |
| } | |
| }else{ | |
| $a = null; | |
| if ($this->yonilgi_turi=='petrol' and !isset($state['petrol_check'])) { | |
| $a = $state['petrol']; | |
| } | |
| if ($this->yonilgi_turi=='diesel' and !isset($state['diesel_check'])) { | |
| $a = $state['diesel']; | |
| } | |
| if ($this->yonilgi_turi=='hybrid' and !isset($state['hybrid_check'])) { | |
| $a = $state['hybrid']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа двигателя ТС'] = $a; | |
| } | |
| } | |
| // Mashina yoshi bo'yicha hisoblash | |
| $aa = $this->getSumKoef($data['section_2_5'], date('Y') - $created_year, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['возраста ТС'] = $aa; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $aa = $this->getSumKoefThree($data['section_2_7'], $this->vehicle_library_state, '>=', 'check', 'year', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' именавых случаев с данным ТС'] = $aa; | |
| if(!$basic){ | |
| $aa = $this->getSumKoef($data['section_2_6'], $this->probeg, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['пробега'] = $aa; | |
| // Mashina komplek | |
| $aa = $this->getYesNoSum($data['section_2_9'], $this->tyuning, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['комплектации'] = $aa; | |
| $aa = $this->getSumKoef($data['section_2_11'], $weight, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['грузоподъемности'] = $aa; | |
| $aa = $this->koleso_formula?$this->getSumKoef($data['section_2_12'], $this->koleso_formula, '==', 'check', 'value', 'percent') | |
| :$get_max($data['section_2_12'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['колесной формулы'] = $aa; | |
| $aa = $this->massa1?$this->getSumKoef($data['section_2_13'], $this->massa1, '>=', 'check', 'value', 'percent') | |
| :$get_max($data['section_2_13'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['предельной массы'] = $aa; | |
| $aa = $this->massa2?$this->getSumKoef($data['section_2_14'], $this->massa2, '>=', 'check', 'value', 'percent') | |
| :$get_max($data['section_2_14'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['массы снаряженного'] = $aa; | |
| $aa = $this->type_kuzov?$this->getOnlyExpectSumRegion($data['section_2_15'], $this->type_kuzov, 'type', 'value', 'percent') | |
| :$get_max($data['section_2_15'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['типа кузова'] = $aa; | |
| $aa = $this->eko_klass?$this->getSumKoef($data['section_2_16'], $this->eko_klass, '==', 'check', 'value', 'percent') | |
| :$get_max($data['section_2_16'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['уровня экологического класса'] = $aa; | |
| }else{ | |
| $all_koeff[] = $get_min($data['section_2_6'],'percent'); | |
| $all_info[' пробега (min)'] = $get_min($data['section_2_6'],'percent'); | |
| $all_koeff[] = $get_min($data['section_2_9'],'percent'); | |
| $all_info[' комплектации (min)'] = $get_min($data['section_2_9'],'percent'); | |
| $all_koeff[] = $get_min($data['section_2_11'],'percent'); | |
| $all_info[' грузоподъемности (min)'] = $get_min($data['section_2_11'],'percent'); | |
| $all_koeff[] = $get_min($data['section_2_12'],'percent'); | |
| $all_info[' колесной формулы (min)'] = $get_min($data['section_2_12'],'percent'); | |
| $all_koeff[] = $get_min($data['section_2_13'],'percent'); | |
| $all_info[' предельной массы (min)'] = $get_min($data['section_2_13'],'percent'); | |
| $all_koeff[] = $get_min($data['section_2_14'],'percent'); | |
| $all_info[' массы снаряженного (min)'] = $get_min($data['section_2_14'],'percent'); | |
| $all_koeff[] = $get_min($data['section_2_15'],'percent'); | |
| $all_info[' типа кузова (min)'] = $get_min($data['section_2_15'],'percent'); | |
| $all_koeff[] = $get_min($data['section_2_16'],'percent'); | |
| $all_info[' уровня экологического класса (min)'] = $get_min($data['section_2_16'],'percent'); | |
| } | |
| if ($data['section_2_8']['check'] != 1) { | |
| $state = $data['section_2_8']; | |
| $a = []; | |
| if ($basic or $this->karobka=='') { | |
| if (!isset($state['automatic_check'])) { | |
| $a[] = $state['automatic']; | |
| } | |
| if (!isset($state['manual_check'])) { | |
| $a[] = $state['manual']; | |
| } | |
| $aa = $basic?$get_min_only($a):$get_max_only($a); | |
| $all_koeff[] = $aa; | |
| $all_info[' типа коробки'] = $aa; | |
| }else{ | |
| $a = null; | |
| if ($this->karobka=='automatic' and !isset($state['automatic_check'])) { | |
| $a = $state['automatic']; | |
| } | |
| if ($this->karobka=='manual' and !isset($state['manual_check'])) { | |
| $a = $state['manual']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа коробки'] = $a; | |
| } | |
| } | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $aa = $this->getVehicleSum($data['section_2_10'], 'check', 'value'); | |
| $all_koeff[] = $aa; | |
| $all_info['марки и модели ТС'] = $aa; | |
| $aa = $this->getOnlyExpectSumRegion($data['section_2_17'], $register_location_id, 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['места регистрации'] = $aa; | |
| } | |
| elseif ($this->vehicle_type == 3) { | |
| $all_koeff[] = $data['section_top_6_1']['bus'] ?? null; | |
| $all_info['автобус'] = $data['section_top_6_1']['bus'] ?? null; | |
| // Mashina ishlab chiqarilgan | |
| $aa = $this->getOnlyExpectSum($data['section_3_1'], | |
| $country, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['страны производства'] = $aa; | |
| if ($data['section_3_2']['check'] != 1) { | |
| $state = $data['section_3_2']; | |
| if ($basic or $this->yonilgi_turi == '') { | |
| $a = []; | |
| if (!isset($state['petrol_check'])) { | |
| $a[] = $state['petrol']; | |
| } | |
| if (!isset($state['diesel_check'])) { | |
| $a[] = $state['diesel']; | |
| } | |
| if (!isset($state['hybrid_check'])) { | |
| $a[] = $state['hybrid']; | |
| } | |
| if ($basic) { | |
| $all_koeff[] = $get_min_only($a); | |
| $all_info['типа двигателя ТС(min)'] = $get_min_only($a); | |
| } else { | |
| $all_koeff[] = $get_max_only($a); | |
| $all_info['типа двигателя ТС (max)'] = $get_max_only($a); | |
| } | |
| } else { | |
| $a = null; | |
| if ($this->yonilgi_turi == 'petrol' and !isset($state['petrol_check'])) { | |
| $a = $state['petrol']; | |
| } | |
| if ($this->yonilgi_turi == 'diesel' and !isset($state['diesel_check'])) { | |
| $a = $state['diesel']; | |
| } | |
| if ($this->yonilgi_turi == 'hybrid' and !isset($state['hybrid_check'])) { | |
| $a = $state['hybrid']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа двигателя ТС'] = $a; | |
| } | |
| } | |
| // Mashina yoshi bo'yicha hisoblash | |
| $aa = $this->getSumKoef($data['section_3_5'], date('Y') - $created_year, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['возраста ТС'] = $aa; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $aa = $this->getSumKoefThree($data['section_3_7'], $this->vehicle_library_state, '>=', 'check', 'year', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' именавых случаев с данным ТС'] = $aa; | |
| if (!$basic) { | |
| $aa = $this->getSumKoef($data['section_3_6'], $this->probeg, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['пробега'] = $aa; | |
| // Mashina komplek | |
| $aa = $this->getYesNoSum($data['section_3_9'], $this->tyuning, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['комплектации'] = $aa; | |
| $aa = $this->massa1 ? $this->getSumKoef($data['section_3_14'], $this->massa1, '>=', 'check', 'value', 'percent') | |
| : $get_max($data['section_3_14'], 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['предельной массы'] = $aa; | |
| $aa = $this->eko_klass ? $this->getSumKoef($data['section_3_15'], $this->eko_klass, '==', 'check', 'value', 'percent') | |
| : $get_max($data['section_3_15'], 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' уровня экологического класса'] = $aa; | |
| } else { | |
| $all_koeff[] = $get_min($data['section_3_6'], 'percent'); | |
| $all_info['пробега (min)'] = $get_min($data['section_3_6'], 'percent'); | |
| $all_koeff[] = $get_min($data['section_3_9'], 'percent'); | |
| $all_info['комплектации (min)'] = $get_min($data['section_3_9'], 'percent'); | |
| $all_koeff[] = $get_min($data['section_3_14'], 'percent'); | |
| $all_info['предельной массы (min)'] = $get_min($data['section_3_14'], 'percent'); | |
| $all_koeff[] = $get_min($data['section_3_15'], 'percent'); | |
| $all_info['уровня экологического класса (min)'] = $get_min($data['section_3_15'], 'percent'); | |
| } | |
| if ($data['section_3_8']['check'] != 1) { | |
| $state = $data['section_3_8']; | |
| $a = []; | |
| if ($basic or $this->karobka == '') { | |
| if (!isset($state['automatic_check'])) { | |
| $a[] = $state['automatic']; | |
| } | |
| if (!isset($state['manual_check'])) { | |
| $a[] = $state['manual']; | |
| } | |
| $aa = $basic ? $get_min_only($a) : $get_max_only($a); | |
| $all_koeff[] = $aa; | |
| $all_info['типа коробки '] = $aa; | |
| } else { | |
| $a = null; | |
| if ($this->karobka == 'automatic' and !isset($state['automatic_check'])) { | |
| $a = $state['automatic']; | |
| } | |
| if ($this->karobka == 'manual' and !isset($state['manual_check'])) { | |
| $a = $state['manual']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа коробки '] = $a; | |
| } | |
| } | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $aa = $this->getVehicleSum($data['section_3_10'], 'check', 'value'); | |
| $all_koeff[] = $aa; | |
| $all_info['марки и модели ТС'] = $aa; | |
| // Mashina foydalanish | |
| $aa = $this->getOnlyExpectSum($data['section_3_11'], $vehicle_use_for_purpose, | |
| 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' использования ТС '] = $aa; | |
| $aa = $this->getSumKoef($data['section_3_12'], $suit, '==', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['количества мест сидения'] = $aa; | |
| $aa = $this->getOnlyExpectSumRegion($data['section_3_16'], $register_location_id, 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['места регистрации '] = $aa; | |
| } | |
| elseif ($this->vehicle_type == 4) { | |
| $all_koeff[] = $data['section_top_6_1']['motorcycle']??null; | |
| $all_info['мотоцикл'] = $data['section_top_6_1']['motorcycle']??null; | |
| // Mashina ishlab chiqarilgan | |
| $aa = $this->getOnlyExpectSum($data['section_4_1'], | |
| $country, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['страны производства'] = $aa; | |
| if ($data['section_4_2']['check'] != 1) { | |
| $state = $data['section_4_2']; | |
| if ($basic or $this->yonilgi_turi=='') { | |
| $a = []; | |
| if (!isset($state['petrol_check'])) { | |
| $a[] = $state['petrol']; | |
| } | |
| if (!isset($state['diesel_check'])) { | |
| $a[] = $state['diesel']; | |
| } | |
| if (!isset($state['hybrid_check'])) { | |
| $a[] = $state['hybrid']; | |
| } | |
| if($basic){ | |
| $all_koeff[] = $get_min_only($a); | |
| $all_info['типа двигателя ТС(min)'] = $get_min_only($a); | |
| }else{ | |
| $all_koeff[] = $get_max_only($a); | |
| $all_info['типа двигателя ТС (max)'] = $get_max_only($a); | |
| } | |
| }else{ | |
| $a = null; | |
| if ($this->yonilgi_turi=='petrol' and !isset($state['petrol_check'])) { | |
| $a = $state['petrol']; | |
| } | |
| if ($this->yonilgi_turi=='diesel' and !isset($state['diesel_check'])) { | |
| $a = $state['diesel']; | |
| } | |
| if ($this->yonilgi_turi=='hybrid' and !isset($state['hybrid_check'])) { | |
| $a = $state['hybrid']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа двигателя ТС'] = $a; | |
| } | |
| } | |
| // Mashina yoshi bo'yicha hisoblash | |
| $aa = $this->getSumKoef($data['section_4_5'], date('Y') - $created_year, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['возраста ТС'] = $aa; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $aa = $this->getSumKoefThree($data['section_4_7'], $this->vehicle_library_state, '>=', 'check', 'year', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' именавых случаев с данным ТС'] = $aa; | |
| if(!$basic){ | |
| $aa = $this->getSumKoef($data['section_4_6'], $this->probeg, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['пробега'] = $aa; | |
| $aa = $this->getYesNoSum($data['section_4_9'], $this->tyuning, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['комплектации'] = $aa; | |
| }else{ | |
| $all_koeff[] = $get_min($data['section_4_6'],'percent'); | |
| $all_info['пробега'] = $get_min($data['section_4_6'],'percent'); | |
| $all_koeff[] = $get_min($data['section_4_9'],'percent'); | |
| $all_info['комплектации'] = $get_min($data['section_4_9'],'percent'); | |
| } | |
| if ($data['section_4_8']['check'] != 1) { | |
| $state = $data['section_4_8']; | |
| $a = []; | |
| if ($basic or $this->karobka=='') { | |
| if (!isset($state['automatic_check'])) { | |
| $a[] = $state['automatic']; | |
| } | |
| if (!isset($state['manual_check'])) { | |
| $a[] = $state['manual']; | |
| } | |
| $aa = $basic?$get_min_only($a):$get_max_only($a); | |
| $all_koeff[] = $aa; | |
| $all_info['типа коробки передач'] = $aa; | |
| }else{ | |
| $a = null; | |
| if ($this->karobka=='automatic' and !isset($state['automatic_check'])) { | |
| $a = $state['automatic']; | |
| } | |
| if ($this->karobka=='manual' and !isset($state['manual_check'])) { | |
| $a = $state['manual']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа коробки передач'] = $a; | |
| } | |
| } | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $aa = $this->getVehicleSum($data['section_4_10'], 'check', 'value'); | |
| $all_koeff[] = $aa; | |
| $all_info['марки и модели ТС'] = $aa; | |
| $aa = $this->getOnlyExpectSumRegion($data['section_4_12'], $register_location_id, 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' места регистрации'] = $aa; | |
| } | |
| elseif ($this->vehicle_type == 5) { | |
| $all_koeff[] = $data['section_top_6_1']['trolley']??null; | |
| $all_info['троллейбус'] = $data['section_top_6_1']['trolley']??null; | |
| // Mashina ishlab chiqarilgan | |
| $aa = $this->getOnlyExpectSum($data['section_5_1'], | |
| $country, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['страны производства'] = $aa; | |
| if ($data['section_5_3']['check'] != 1) { | |
| $state = $data['section_5_3']; | |
| $a = []; | |
| if ($basic or $this->type_electr=='') { | |
| if (!isset($state['fast_check'])) { | |
| $a[] = $state['fast']; | |
| } | |
| if (!isset($state['asynx_check'])) { | |
| $a[] = $state['asynx']; | |
| } | |
| $aa = $basic?$get_min_only($a):$get_max_only($a); | |
| $all_koeff[] = $aa; | |
| $all_info['типа двигателя ТС'] = $aa; | |
| }else{ | |
| $a = null; | |
| if ($this->type_electr=='fast' and !isset($state['fast_check'])) { | |
| $a = $state['fast']; | |
| } | |
| if ($this->type_electr=='asynx' and !isset($state['asynx_check'])) { | |
| $a = $state['asynx']; | |
| } | |
| $all_koeff[] = $a;; | |
| $all_info['типа двигателя ТС'] = $a; | |
| } | |
| } | |
| // Mashina yoshi bo'yicha hisoblash | |
| $aa = $this->getSumKoef($data['section_5_4'], date('Y') - $created_year, | |
| '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['возраста ТС'] = $aa; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $aa = $this->getSumKoefThree($data['section_5_6'], $this->vehicle_library_state, | |
| '>=', 'check', 'year', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' именавых случаев с данным ТС'] = $aa; | |
| if(!$basic){ | |
| $aa = $this->electr_power?$this->getSumKoef($data['section_5_2'], | |
| $this->electr_power, '>=', 'check', 'value', 'percent') | |
| :$get_max($data['section_5_2'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['мощности двигателя '] = $aa; | |
| $aa = $this->getSumKoef($data['section_5_5'], $this->probeg, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['пробега'] = $aa; | |
| $aa = $this->getYesNoSum($data['section_5_8'], $this->tyuning, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['комплектации'] = $aa; | |
| $aa = $this->massa2?$this->getSumKoef($data['section_5_12'], $this->massa2, '>=', 'check', 'value', 'percent') | |
| :$get_max($data['section_5_12'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['предельной массы'] = $aa; | |
| }else{ | |
| $all_koeff[] = $get_min($data['section_5_2'],'percent'); | |
| $all_info['мощности двигателя (min)'] = $get_min($data['section_5_2'],'percent'); | |
| $all_koeff[] = $get_min($data['section_5_5'],'percent'); | |
| $all_info['пробега (min)'] = $get_min($data['section_5_5'],'percent'); | |
| $all_koeff[] = $get_min($data['section_5_8'],'percent'); | |
| $all_info['комплектации (min)'] = $get_min($data['section_5_8'],'percent'); | |
| $all_koeff[] = $get_min($data['section_5_12'],'percent'); | |
| $all_info['предельной массы (min)'] = $get_min($data['section_5_12'],'percent'); | |
| } | |
| if ($data['section_5_7']['check'] != 1) { | |
| $state = $data['section_5_7']; | |
| $a = []; | |
| if ($basic or $this->karobka=='') { | |
| if (!isset($state['automatic_check'])) { | |
| $a[] = $state['automatic']; | |
| } | |
| if (!isset($state['manual_check'])) { | |
| $a[] = $state['manual']; | |
| } | |
| $aa = $basic?$get_min_only($a):$get_max_only($a); | |
| $all_koeff[] = $aa; | |
| $all_info['типа коробки передач'] = $aa; | |
| }else{ | |
| $a = null; | |
| if ($this->karobka=='automatic' and !isset($state['automatic_check'])) { | |
| $a = $state['automatic']; | |
| } | |
| if ($this->karobka=='manual' and !isset($state['manual_check'])) { | |
| $a = $state['manual']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа коробки передач'] = $a; | |
| } | |
| } | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $aa = $this->getVehicleSum($data['section_5_9'], 'check', 'value'); | |
| $all_koeff[] = $aa; | |
| $all_info['марки и модели ТС'] = $aa; | |
| $aa = $this->getSumKoef($data['section_5_10'], $suit, | |
| '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['количества мест сидения '] = $aa; | |
| $aa = $this->getOnlyExpectSumRegion($data['section_5_13'], | |
| $register_location_id, 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['места регистрации '] = $aa; | |
| } | |
| elseif ($this->vehicle_type == 6) { | |
| $all_koeff[] = $data['section_top_6_1']['trams']??null; | |
| $all_info['трамвай'] = $data['section_top_6_1']['trams']??null; | |
| // Mashina ishlab chiqarilgan | |
| $aa = $this->getOnlyExpectSum($data['section_6_1'], | |
| $country, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['страны производства'] = $aa; | |
| if ($data['section_6_3']['check'] != 1) { | |
| $state = $data['section_6_3']; | |
| $a = []; | |
| if ($basic or $this->type_electr=='') { | |
| if (!isset($state['fast_check'])) { | |
| $a[] = $state['fast']; | |
| } | |
| if (!isset($state['asynx_check'])) { | |
| $a[] = $state['asynx']; | |
| } | |
| $aa = $basic?$get_min_only($a):$get_max_only($a); | |
| $all_koeff[] = $aa; | |
| $all_info['типа двигателя'] = $aa; | |
| }else{ | |
| $a = null; | |
| if ($this->type_electr=='fast' and !isset($state['fast_check'])) { | |
| $a = $state['fast']; | |
| } | |
| if ($this->type_electr=='asynx' and !isset($state['asynx_check'])) { | |
| $a = $state['asynx']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа двигателя'] = $a; | |
| } | |
| } | |
| // Mashina yoshi bo'yicha hisoblash | |
| $aa = $this->getSumKoef($data['section_6_5'], date('Y') - $created_year, | |
| '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['возраста ТС'] = $aa; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $aa = $this->getSumKoefThree($data['section_6_7'], $this->vehicle_library_state, | |
| '>=', 'check', 'year', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' именавых случаев с данным ТС'] = $aa; | |
| if(!$basic){ | |
| $aa = $this->electr_power?$this->getSumKoef($data['section_6_2'], | |
| $this->electr_power, '>=', 'check', 'value', 'percent') | |
| :$get_max($data['section_6_2'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['мощности двигателя'] = $aa; | |
| $aa = $this->electr_count?$this->getSumKoef($data['section_6_4'], | |
| $this->electr_count, '>=', 'check', 'value', 'percent') | |
| :$get_max($data['section_6_4'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['количества двигателей'] = $aa; | |
| $aa = $this->getSumKoef($data['section_6_6'], $this->probeg, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['количества двигателей'] = $aa; | |
| $aa = $this->getYesNoSum($data['section_6_9'], $this->tyuning, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['комплектации'] = $aa; | |
| $aa = $this->massa2?$this->getSumKoef($data['section_6_13'], $this->massa2, '>=', 'check', 'value', 'percent') | |
| :$get_max($data['section_6_13'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['предельной массы'] = $aa; | |
| }else{ | |
| $all_koeff[] = $get_min($data['section_6_2'],'percent'); | |
| $all_info['мощности двигателя (min)'] = $get_min($data['section_6_2'],'percent'); | |
| $all_koeff[] = $get_min($data['section_6_4'],'percent'); | |
| $all_info['количества двигателей (min)'] = $get_min($data['section_6_4'],'percent'); | |
| $all_koeff[] = $get_min($data['section_6_6'],'percent'); | |
| $all_info['пробега (min)'] = $get_min($data['section_6_6'],'percent'); | |
| $all_koeff[] = $get_min($data['section_6_9'],'percent'); | |
| $all_info['комплектации (min)'] = $get_min($data['section_6_9'],'percent'); | |
| $all_koeff[] = $get_min($data['section_6_13'],'percent'); | |
| $all_info['предельной массы (min)'] = $get_min($data['section_6_13'],'percent'); | |
| } | |
| if ($data['section_6_8']['check'] != 1) { | |
| $state = $data['section_6_8']; | |
| $a = []; | |
| if ($basic or $this->karobka=='') { | |
| if (!isset($state['automatic_check'])) { | |
| $a[] = $state['automatic']; | |
| } | |
| if (!isset($state['manual_check'])) { | |
| $a[] = $state['manual']; | |
| } | |
| $aa = $basic?$get_min_only($a):$get_max_only($a); | |
| $all_koeff[] = $aa; | |
| $all_info['типа коробки передач'] = $aa; | |
| }else{ | |
| $a = null; | |
| if ($this->karobka=='automatic' and !isset($state['automatic_check'])) { | |
| $a = $state['automatic']; | |
| } | |
| if ($this->karobka=='manual' and !isset($state['manual_check'])) { | |
| $a = $state['manual']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['типа коробки передач'] = $a; | |
| } | |
| } | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $aa = $this->getVehicleSum($data['section_6_10'], 'check', 'value'); | |
| $all_koeff[] = $aa; | |
| $all_info['марки и модели ТС'] = $aa; | |
| $aa = $this->getSumKoef($data['section_6_11'], $suit, | |
| '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' количества мест сидения'] = $aa; | |
| $aa = $this->getOnlyExpectSumRegion($data['section_6_14'], | |
| $register_location_id, 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' места регистрации'] = $aa; | |
| } | |
| elseif ($this->vehicle_type == 7) { | |
| $all_koeff[] = $data['section_top_6_1']['tractor']??null; | |
| $all_info['трактор'] = $data['section_top_6_1']['tractor']??null; | |
| // Mashina ishlab chiqarilgan | |
| $aa = $this->getOnlyExpectSum($data['section_7_1'], | |
| $country, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['страны производства'] = $aa; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $aa = $this->getSumKoef($data['section_7_4'], date('Y') - $created_year, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['возраста ТС'] = $aa; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $aa = $this->getSumKoefThree($data['section_7_6'], $this->vehicle_library_state, '>=', 'check', 'year', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' именавых случаев с данным ТС'] = $aa; | |
| if(!$basic){ | |
| $aa = $this->getSumKoef($data['section_7_5'], $this->probeg, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['пробега'] = $aa; | |
| }else{ | |
| $aa = $get_min($data['section_7_5'],'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['пробега'] = $aa; | |
| } | |
| if ($data['section_7_7']['check'] != 1) { | |
| $state = $data['section_7_7']; | |
| $a = []; | |
| if ($basic or $this->xadavoy=='') { | |
| if (!isset($state['one_check'])) { | |
| $a[] = $state['one_percent']; | |
| } | |
| if (!isset($state['two_check'])) { | |
| $a[] = $state['two_percent']; | |
| } | |
| $aa = $basic?$get_min_only($a):$get_max_only($a); | |
| $all_koeff[] = $aa; | |
| $all_info['ходовая часть'] = $aa; | |
| }else{ | |
| $a = null; | |
| if ($this->xadavoy=='gusenniy' and !isset($state['one_check'])) { | |
| $a = $state['one_percent']; | |
| } | |
| if ($this->xadavoy=='kalso' and !isset($state['two_check'])) { | |
| $a = $state['two_percent']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['ходовая часть'] = $a; | |
| } | |
| } | |
| if ($data['section_7_8']['check'] != 1) { | |
| $state = $data['section_7_7']; | |
| $a = []; | |
| if ($basic or $using=='') { | |
| if (!isset($state['one_check'])) { | |
| $a[] = $state['one_percent']; | |
| } | |
| if (!isset($state['two_check'])) { | |
| $a[] = $state['two_percent']; | |
| } | |
| $aa = $basic?$get_min_only($a):$get_max_only($a); | |
| $all_koeff[] = $aa; | |
| $all_info['назначения Traktor'] = $aa; | |
| }else{ | |
| $a = null; | |
| if ($using=='sanoat' and !isset($state['one_check'])) { | |
| $a = $state['one_percent']; | |
| } | |
| if ($using=='qishloq' and !isset($state['two_check'])) { | |
| $a = $state['two_percent']; | |
| } | |
| $all_koeff[] = $a; | |
| $all_info['назначения Traktor'] = $aa; | |
| } | |
| } | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $aa = $this->getVehicleSum($data['section_7_9'], 'check', 'value'); | |
| $all_koeff[] = $aa; | |
| $all_info['марки и модели ТС'] = $aa; | |
| $aa = $this->getOnlyExpectSumRegion($data['section_7_10'], $register_location_id, 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['места регистрации'] = $aa; | |
| } | |
| elseif ($this->vehicle_type == 8) { | |
| $all_koeff[] = $data['section_top_6_1']['special']??null; | |
| $all_info['спецтранспорт'] = $data['section_top_6_1']['special']??null; | |
| // Mashina ishlab chiqarilgan | |
| $aa = $this->getOnlyExpectSum($data['section_8_1'], | |
| $country, 'check', 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['страны производства'] = $aa; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $aa = $this->getSumKoef($data['section_8_3'], date('Y') - $created_year, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['возраста ТС'] = $aa; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $aa = $this->getSumKoefThree($data['section_8_5'], $this->vehicle_library_state, '>=', 'check', 'year', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info[' именавых случаев с данным ТС'] = $aa; | |
| if(!$basic){ | |
| $aa = $this->getSumKoef($data['section_8_4'], $this->probeg, '>=', 'check', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['пробега'] = $aa; | |
| }else{ | |
| $all_koeff[] = $get_min($data['section_8_4'],'percent'); | |
| $all_info['пробега'] = $get_min($data['section_8_4'],'percent'); | |
| } | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $aa = $this->getVehicleSum($data['section_8_6'], 'check', 'value'); | |
| $all_koeff[] = $aa; | |
| $all_info['марки и модели ТС'] = $aa; | |
| $aa = $this->getOnlyExpectSumRegion($data['section_8_7'], $register_location_id, 'type', 'value', 'percent'); | |
| $all_koeff[] = $aa; | |
| $all_info['места регистрации '] = $aa; | |
| } | |
| foreach ($all_koeff as $key=>$item) { | |
| if (is_null($item) or $item==1 or $item=='') { | |
| unset($all_koeff[$key]); | |
| continue; | |
| } | |
| } | |
| $aa = []; | |
| foreach ($all_info as $key=>$item) { | |
| if (is_null($item) or $item==1 or $item=='') { | |
| unset($all_info[$key]); | |
| continue; | |
| } | |
| $aa[] ="$key:$item"; | |
| } | |
| $a = []; | |
| if (is_array($this->book_summa)) { | |
| foreach ($this->book_summa as $key => $item) { | |
| if (isset($all_koeff_risk[$key])) { | |
| foreach ($all_koeff_risk[$key] as $key2 => $item2) { | |
| if (is_null($item2) or $item2 == 1 or $item2 == '') { | |
| unset($all_koeff_risk[$key][$key2]); | |
| continue; | |
| } | |
| } | |
| $ss = round($item * 1000000 * array_product(array_merge($all_koeff ,$all_koeff_risk[$key])), 2); | |
| $a[$key] = $ss; | |
| $aaa = []; | |
| foreach ($all_koeff_info[$key] as $key33=>$item33) { | |
| if (is_null($item33) or $item33 == 1 or $item33 == '') { | |
| unset($all_koeff_info[$key33]); | |
| continue; | |
| } | |
| $aaa[] = "$key33:$item33"; | |
| } | |
| // $formula[$key] = Yii::$app->formatter->asInteger($item).' * '.implode(' * ',$aa) .' = '.$ss; | |
| $formula[$key] = Yii::$app->formatter->asInteger($item * 1000000).' * '.implode(' * ',$aaa).' * '.implode(' * ',$aa) .' = '.$ss; | |
| } | |
| } | |
| } elseif ($basic) { | |
| $book_percent = $get_min_only($data['section_top_3_1']['percent']); | |
| $book_summa = 1000000 * $data['section_top_3_1']['value'][array_search($book_percent,$data['section_top_3_1']['percent'])]??1; | |
| $ss = abs(round($book_summa * $book_percent * array_product($all_koeff), 2)); | |
| $a[] = $ss; | |
| $formula[] = Yii::$app->formatter->asInteger($book_summa).' * коэффицент сумма:'.$book_percent.' * '.implode(' * ',$aa) .' = '.$ss; | |
| } | |
| // print_variable([ | |
| // $a, | |
| // $formula, | |
| // $this->book_summa | |
| // ]); | |
| // if($product['id']==12) { | |
| // | |
| // print_variable($formula); | |
| // } | |
| //// | |
| // | |
| /// print_variable( [$all_koeff,$all_koeff_risk] ); | |
| $this->risk_summas[$product['company_id']] = $a; | |
| // print_variable( $all_info ); | |
| return [$a?abs(round(array_sum($a),2)):0,$formula]; | |
| } | |
| public function getSessionValues() | |
| { | |
| $this->setCustomAttributes(); | |
| $session = Yii::$app->session; | |
| if (!$session->isActive) | |
| $session->open(); | |
| $this->vehicle_model_id = $session->get('vehicle_model_id'); | |
| $this->user_id = $session->get('user_id'); | |
| $this->product_id = $session->get('product_id'); | |
| $this->product_id_book = $session->get('product_id_book'); | |
| $this->driver_count = $session->get('driver_count'); | |
| $this->vehicle_body_number = $session->get('vehicle_body_number'); | |
| $this->vehicle_type = $session->get('vehicle_type'); | |
| $this->brand = $session->get('brand'); | |
| $this->photo = $session->get('photo'); | |
| $this->created_date = $session->get('created_date'); | |
| $this->register_location_id = $session->get('register_location_id'); | |
| $this->vehicle_owner_type = $session->get('vehicle_owner_type'); | |
| $this->vehicle_use_for_purpose = $session->get('vehicle_use_for_purpose'); | |
| $this->expired_at = $session->get('expired_at'); | |
| $this->start_date = $session->get('start_date'); | |
| $this->vehicle_number = $session->get('vehicle_number'); | |
| $this->body_number = $session->get('body_number'); | |
| $this->motor_number = $session->get('motor_number'); | |
| $this->technical_passport = $session->get('technical_passport'); | |
| $this->technical_passport_date = $session->get('technical_passport_date'); | |
| $this->technical_passport_file = $session->get('technical_passport_file'); | |
| $this->discount = $session->get('discount'); | |
| $this->discount_file = $session->get('discount_file'); | |
| $this->discount_user_type = $session->get('discount_user_type'); | |
| $this->energy_power = $session->get('energy_power'); | |
| $this->horse_power = $session->get('horse_power'); | |
| $this->weight = $session->get('weight'); | |
| $this->suit = $session->get('suit'); | |
| $this->library_summa = $session->get('library_summa'); | |
| $this->library_summa_book = $session->get('library_summa_book'); | |
| $this->library_summa_end = $session->get('library_summa_end'); | |
| $this->library_summa_end_old = $session->get('library_summa_end_old'); | |
| $this->library_summa_end_table = $session->get('library_summa_end_table'); | |
| $this->library_summa_end_book = $session->get('library_summa_end_book'); | |
| $this->library_summa_end2 = $session->get('library_summa_end2'); | |
| $this->library_summa_end2_old = $session->get('library_summa_end2_old'); | |
| $this->library_summa_end2_table = $session->get('library_summa_end2_table'); | |
| $this->library_summa_end2_book = $session->get('library_summa_end2_book'); | |
| $this->risk_summas = $session->get('risk_summas'); | |
| $this->library_max_discount = $session->get('library_max_discount'); | |
| $this->library_discount_basic = $session->get('library_discount_basic'); | |
| $this->library_discount_basic_book = $session->get('library_discount_basic_book'); | |
| $this->library_discount_gift = $session->get('library_discount_gift'); | |
| $this->library_discount_gift_book = $session->get('library_discount_gift_book'); | |
| $this->owner_phone_number = $session->get('owner_phone_number'); | |
| $this->phone_number = $session->get('phone_number'); | |
| $this->email = $session->get('email'); | |
| $this->actual_book = $session->get('actual_book'); | |
| $this->book_summa = $session->get('book_summa'); | |
| $this->cover = $session->get('cover'); | |
| $this->yonilgi_turi = $session->get('yonilgi_turi'); | |
| $this->probeg = $session->get('probeg'); | |
| $this->karobka = $session->get('karobka'); | |
| $this->tyuning = $session->get('tyuning'); | |
| $this->privod = $session->get('privod'); | |
| $this->eko_klass = $session->get('eko_klass'); | |
| $this->koleso_formula = $session->get('koleso_formula'); | |
| $this->massa1 = $session->get('massa1'); | |
| $this->massa2 = $session->get('massa2'); | |
| $this->type_kuzov = $session->get('type_kuzov'); | |
| $this->type_electr = $session->get('type_electr'); | |
| $this->electr_power = $session->get('electr_power'); | |
| $this->electr_count = $session->get('electr_count'); | |
| $this->xadavoy = $session->get('xadavoy'); | |
| $this->parking = $session->get('parking'); | |
| $this->signal = $session->get('signal'); | |
| $this->permission = $session->get('permission'); | |
| $this->benifit = $session->get('benifit'); | |
| $this->beneficiary = $session->get('beneficiary'); | |
| $this->remont = $session->get('remont'); | |
| $this->extra_services = $session->get('extra_services'); | |
| $this->expire_at_book = $session->get('expire_at_book'); | |
| $this->book_currency = $session->get('book_currency'); | |
| $this->book_type_summa = $session->get('book_type_summa'); | |
| $this->book_type_object = $session->get('book_type_object'); | |
| $this->book_risk = $session->get('book_risk'); | |
| $this->juridic_activity = $session->get('juridic_activity'); | |
| $this->clearance_region = $session->get('clearance_region'); | |
| $this->clearance_country = $session->get('clearance_country'); | |
| $this->franshiza_type = $session->get('franshiza_type'); | |
| $this->franshiza_percent = $session->get('franshiza_percent'); | |
| $this->rasrochka = $session->get('rasrochka'); | |
| $this->payment_book_type = $session->get('payment_book_type'); | |
| // new book_srok issue 90 | |
| $this->book_srok= $session->get('book_srok'); | |
| $vehicle = VehicleModel::find() | |
| ->asArray()->where(['status' => 'active', 'id' => $this->vehicle_model_id]) | |
| ->one(); | |
| if ($vehicle != null) { | |
| $data = Functions::jsonDecode($vehicle['data']); | |
| if ($vehicle['vehicle_type_id'] == 1) { | |
| if ($data['energy_power'] > $this->energy_power) { | |
| $this->addError('energy_power', Yii::t('yii', 'Invalid value')); | |
| } | |
| if ($data['horse_power'] > $this->horse_power) { | |
| $this->addError('horse_power', Yii::t('yii', 'Invalid value')); | |
| } | |
| } elseif ($vehicle['vehicle_type_id'] == 2) { | |
| if ($data['weight'] > $this->weight) { | |
| $this->addError('weight', Yii::t('yii', 'Invalid value')); | |
| } | |
| } elseif ($vehicle['vehicle_type_id'] == 3) { | |
| if ($data['suit'] > $this->suit) { | |
| $this->addError('suit', Yii::t('yii', 'Invalid value')); | |
| } | |
| } | |
| } | |
| if ($this->vehicle_owner_type == 'physical') { | |
| $this->owner_last_name = $session->get('owner_last_name'); | |
| $this->owner_first_name = $session->get('owner_first_name'); | |
| $this->owner_sure_name = $session->get('owner_sure_name'); | |
| $this->owner_passport = $session->get('owner_passport'); | |
| $this->owner_address_physical = $session->get('owner_address_physical'); | |
| $this->owner_region_physical = $session->get('owner_region_physical'); | |
| } else { | |
| $this->owner_name = $session->get('owner_name'); | |
| $this->owner_inn = $session->get('owner_inn'); | |
| $this->owner_address_juridical = $session->get('owner_address_juridical'); | |
| $this->owner_region_juridical = $session->get('owner_region_juridical'); | |
| } | |
| if ($this->driver_count == '1-5-drivers') { | |
| $this->last_name = $session->get('last_name'); | |
| $this->first_name = $session->get('first_name'); | |
| $this->sure_name = $session->get('sure_name'); | |
| $this->passport = $session->get('passport'); | |
| $this->birth_day = $session->get('birth_day'); | |
| $this->driving_license = $session->get('driving_license'); | |
| $this->driving_license_date = $session->get('driving_license_date'); | |
| $this->library_state = $session->get('library_state'); | |
| $this->violation = $session->get('violation'); | |
| $this->gender = $session->get('gender'); | |
| } | |
| } | |
| public static function getRegisterLocation($region_id) | |
| { | |
| if ($region_id == 0) | |
| return 'location_1'; | |
| $data['location_1'] = [ | |
| 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, // Toshkent | |
| 135, 136, 137, 138, 139, 140, 143, 144, 145, 147, 149, 150, 151, 193, // Toshkent v | |
| 141, 142, 146, 148, // Toshkent v | |
| ]; | |
| $data['location_2'] = [ | |
| 2, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, //Andijon hammasi | |
| 1, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, // Namangan hammasi | |
| 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, // Samarqand hammasi | |
| 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170 // Farg'ona | |
| ]; | |
| $data['location_3'] = [ | |
| 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, // Buxoro | |
| 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, // Navoiy | |
| 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, // Surxondaryo | |
| 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72 // Qashqadaryo | |
| ]; | |
| $data['location_4'] = [ | |
| 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, // Qoraqalpoq | |
| 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, // Sirdaryo | |
| 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, // Xorazm | |
| 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58 // Jizzax | |
| ]; | |
| $data['location_5'] = [ | |
| 1001, // | |
| ]; | |
| $result = null; | |
| foreach ($data as $key => $item) { | |
| if (in_array($region_id, $item)) { | |
| $result = $key; | |
| break; | |
| } | |
| } | |
| return $result; | |
| } | |
| /** | |
| * @param $product | |
| * @return array | |
| */ | |
| public function calculateDiscount($product) | |
| { | |
| $data = Functions::jsonDecode($product['data']); | |
| $country = $horse_power = $xadavoy = $using = $energy_power = $created_year = $vehicle_state = $vehicle_sum = $vehicle_use_for_purpose = 0; | |
| $all_info = []; | |
| if ($this->vehicle_type == 1) { | |
| // TB | |
| // Mashina ishlab chiqarilgan | |
| $country = $this->getOnlyExpectSum($data['section_1_1'], $this->vehicleModel->country_id, 'light_one_check', 'light_one_made_in', 'light_one_country', 'light_one_percent'); | |
| $all_info['Cтраны производства'] = $country; | |
| // Mashina obyomi bo'yicha hisoblash | |
| $energy_power = $this->getSumKoef($data['section_1_2'], $this->energy_power, '>=', false, 'light_two_energy', 'light_two_percent'); | |
| $all_info['объема двигателя'] = $energy_power; | |
| // Mashina ot kuchi bo'yicha hisoblash | |
| $horse_power= $this->getSumKoef($data['section_1_7'], $this->horse_power, '>=', false, 'light_seven_horse', 'light_seven_percent'); | |
| //var_dump($this->horse_power, $horse_power);die; | |
| $all_info['лошадиные силы'] = $horse_power; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $created_year = $this->getSumKoef($data['section_1_3'], date('Y') - $this->created_date, '>=', 'light_three_check', 'light_three_year', 'light_three_percent'); | |
| $all_info['возраста ТС'] = $created_year; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $vehicle_state = $this->getSumKoefThree($data['section_1_4'], $this->vehicle_library_state, '>=', 'light_four_check', 'light_four_year', 'light_four_clearance_state', 'light_four_percent'); | |
| $all_info['именавых случаев '] = $vehicle_state; | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $vehicle_sum = $this->getVehicleSum($data['section_1_5'], 'light_five_check', 'light_five_vehicle'); | |
| $all_info['марки и модели'] = $vehicle_sum; | |
| // Mashina foydalanish | |
| $vehicle_use_for_purpose = $this->getOnlyExpectSum($data['section_1_6'], $this->vehicle_use_for_purpose, false, 'light_sex_use', 'light_sex_purpose', 'light_sex_percent'); | |
| $all_info['использования ТС'] = $vehicle_use_for_purpose; | |
| } | |
| elseif ($this->vehicle_type == 2) { | |
| // Mashina ishlab chiqarilgan | |
| $country = $this->getOnlyExpectSum($data['section_2_1'], $this->vehicleModel->country_id, 'hard_one_check', 'hard_one_made_in', 'hard_one_country', 'hard_one_percent'); | |
| $all_info['Cтраны производства'] = $country; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $created_year = $this->getSumKoef($data['section_2_2'], date('Y') - $this->created_date, '>=', 'hard_two_check', 'hard_two_year', 'hard_two_percent'); | |
| $all_info['возраста ТС'] = $created_year; | |
| // Mashina og'irligi bo'yicha hisoblash | |
| $energy_power = $this->getSumKoef($data['section_2_3'], $this->weight, '>=', false, 'hard_three_weight', 'hard_three_percent'); | |
| $all_info['грузоподъемности ТС'] = $energy_power; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $vehicle_state = $this->getSumKoefThree($data['section_2_4'], $this->vehicle_library_state, '>=', 'hard_four_check', 'hard_four_year', 'hard_four_clearance_state', 'hard_four_percent'); | |
| $all_info['именавых случаев '] = $vehicle_state; | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $vehicle_sum = $this->getVehicleSum($data['section_2_5'], 'hard_five_check', 'hard_five_vehicle'); | |
| $all_info['марки и модели'] = $vehicle_sum; | |
| } | |
| elseif ($this->vehicle_type == 3) { | |
| // Mashina ishlab chiqarilgan | |
| $country = $this->getOnlyExpectSum($data['section_3_1'], $this->vehicleModel->country_id, 'bus_one_check', 'bus_one_made_in', 'bus_one_country', 'bus_one_percent'); | |
| $all_info['Cтраны производства'] = $country; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $created_year = $this->getSumKoef($data['section_3_3'], date('Y') - $this->created_date, '>=', 'bus_three_check', 'bus_three_year', 'bus_three_percent'); | |
| $all_info['возраста ТС'] = $created_year; | |
| // Mashina o'rindiq soni bo'yicha hisoblash | |
| $energy_power = $this->getSumKoef($data['section_3_2'], $this->suit, '>=', false, 'bus_two_suit', 'bus_two_percent'); | |
| $all_info['количества мест сидения ТС'] = $energy_power; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $vehicle_state = $this->getSumKoefThree($data['section_3_4'], $this->vehicle_library_state, '>=', 'bus_four_check', 'bus_four_year', 'bus_four_clearance_state', 'bus_four_percent'); | |
| $all_info['именавых случаев '] = $vehicle_state; | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $vehicle_sum = $this->getVehicleSum($data['section_3_5'], 'bus_five_check', 'bus_five_vehicle'); | |
| $all_info['марки и модели'] = $vehicle_sum; | |
| // Mashina foydalanish | |
| $vehicle_use_for_purpose = $this->getOnlyExpectSum($data['section_3_6'], $this->vehicle_use_for_purpose, 'bus_sex_check', 'bus_sex_use', 'bus_sex_purpose', 'bus_sex_percent'); | |
| $all_info['использования ТС'] = $vehicle_use_for_purpose; | |
| } | |
| elseif ($this->vehicle_type == 4) { | |
| // Mashina ishlab chiqarilgan | |
| $country = $this->getOnlyExpectSum($data['section_4_1'], $this->vehicleModel->country_id, 'moto_one_check', 'moto_one_made_in', 'moto_one_country', 'moto_one_percent'); | |
| $all_info['Cтраны производства'] = $country; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $created_year = $this->getSumKoef($data['section_4_2'], date('Y') - $this->created_date, '>=', 'moto_two_check', 'moto_two_year', 'moto_two_percent'); | |
| $all_info['возраста ТС'] = $created_year; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $vehicle_state = $this->getSumKoefThree($data['section_4_3'], $this->vehicle_library_state, '>=', 'moto_three_check', 'moto_three_year', 'moto_three_clearance_state', 'moto_three_percent'); | |
| $all_info['именавых случаев '] = $vehicle_state; | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $vehicle_sum = $this->getVehicleSum($data['section_4_4'], 'moto_four_check', 'moto_four_vehicle'); | |
| $all_info['марки и модели'] = $vehicle_sum; | |
| } | |
| elseif ($this->vehicle_type == 5) { | |
| // Mashina ishlab chiqarilgan | |
| $country = $this->getOnlyExpectSum($data['section_5_1'], $this->vehicleModel->country_id, 'trall_one_check', 'trall_one_made_in', 'trall_one_country', 'trall_one_percent'); | |
| $all_info['Cтраны производства'] = $country; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $created_year = $this->getSumKoef($data['section_5_2'], date('Y') - $this->created_date, '>=', 'trall_two_check', 'trall_two_year', 'trall_two_percent'); | |
| $all_info['возраста ТС'] = $created_year; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $vehicle_state = $this->getSumKoefThree($data['section_5_3'], $this->vehicle_library_state, '>=', 'trall_three_check', 'trall_three_year', 'trall_three_clearance_state', 'trall_three_percent'); | |
| $all_info['именавых случаев '] = $vehicle_state; | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $vehicle_sum = $this->getVehicleSum($data['section_5_4'], 'trall_four_check', 'trall_four_vehicle'); | |
| $all_info['марки и модели'] = $vehicle_sum; | |
| $energy_power = $this->getSumKoef($data['section_5_5'], $this->suit, '>=', 'trall_five_check', 'trall_five_suit', 'trall_five_percent'); | |
| $all_info['количества мест сидения ТС'] = $energy_power; | |
| } | |
| elseif ($this->vehicle_type == 6) { | |
| // Mashina ishlab chiqarilgan | |
| $country = $this->getOnlyExpectSum($data['section_6_1'], $this->vehicleModel->country_id, 'tramv_one_check', 'tramv_one_made_in', 'tramv_one_country', 'tramv_one_percent'); | |
| $all_info['Cтраны производства'] = $country; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $created_year = $this->getSumKoef($data['section_6_2'], date('Y') - $this->created_date, '>=', 'tramv_two_check', 'tramv_two_year', 'tramv_two_percent'); | |
| $all_info['возраста ТС'] = $created_year; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $vehicle_state = $this->getSumKoefThree($data['section_6_3'], $this->vehicle_library_state, '>=', 'tramv_three_check', 'tramv_three_year', 'tramv_three_clearance_state', 'tramv_three_percent'); | |
| $all_info['именавых случаев '] = $vehicle_state; | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $vehicle_sum = $this->getVehicleSum($data['section_6_4'], 'tramv_four_check', 'tramv_four_vehicle'); | |
| $all_info['марки и модели'] = $vehicle_sum; | |
| $energy_power = $this->getSumKoef($data['section_6_5'], $this->suit, '>=', 'tramv_five_check', 'tramv_five_suit', 'tramv_five_percent'); | |
| $all_info['количества мест сидения ТС'] = $energy_power; | |
| } | |
| elseif ($this->vehicle_type == 7) { | |
| // Mashina ishlab chiqarilgan | |
| $country = $this->getOnlyExpectSum($data['section_7_1'], $this->vehicleModel->country_id, 'trakt_one_check', 'trakt_one_made_in', 'trakt_one_country', 'trakt_one_percent'); | |
| $all_info['Cтраны производства'] = $country; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $created_year = $this->getSumKoef($data['section_7_2'], date('Y') - $this->created_date, '>=', 'trakt_two_check', 'trakt_two_year', 'trakt_two_percent'); | |
| $all_info['возраста ТС'] = $created_year; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $vehicle_state = $this->getSumKoefThree($data['section_7_3'], $this->vehicle_library_state, '>=', 'trakt_three_check', 'trakt_three_year', 'trakt_three_clearance_state', 'trakt_three_percent'); | |
| $all_info['именавых случаев '] = $vehicle_state; | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $vehicle_sum = $this->getVehicleSum($data['section_7_6'], 'trakt_sex_check', 'trakt_sex_vehicle'); | |
| $all_info['марки и модели'] = $vehicle_sum; | |
| // Hadavoy qismi | |
| if ($data['section_7_4']['trakt_four_check'] != 1) { | |
| if (!isset($data['section_7_4']['trakt_four_one_check']) and $this->vehicleModel->xadavoy == 'gusenniy') { | |
| $xadavoy = $data['section_7_4']['trakt_four_one_percent']; | |
| } elseif (!isset($data['section_7_4']['trakt_four_two_check']) and $this->vehicleModel->xadavoy == 'kalso') { | |
| $xadavoy = $data['section_7_4']['trakt_four_two_percent']; | |
| } | |
| $all_info['ходовой части'] = $xadavoy; | |
| } | |
| // Foydalnish sohasi qismi | |
| if ($data['section_7_5']['trakt_five_check'] != 1) { | |
| if (!isset($data['section_7_5']['trakt_five_one_check']) and $this->vehicleModel->using == 'sanoat') { | |
| $using = $data['section_7_5']['trakt_five_one_percent']; | |
| } elseif (!isset($data['section_7_5']['trakt_five_two_check']) and $this->vehicleModel->using == 'qishloq') { | |
| $using = $data['section_7_5']['trakt_five_two_percent']; | |
| } | |
| $all_info['назначения ТС'] = $using; | |
| } | |
| } | |
| elseif ($this->vehicle_type == 8) { | |
| // Mashina ishlab chiqarilgan | |
| $country = $this->getOnlyExpectSum($data['section_8_1'], $this->vehicleModel->country_id, 'special_one_check', 'special_one_made_in', 'special_one_country', 'special_one_percent'); | |
| $all_info['Cтраны производства'] = $country; | |
| // Mashina yoshi bo'yicha hisoblash | |
| $created_year = $this->getSumKoef($data['section_8_2'], date('Y') - $this->created_date, '>=', 'special_two_check', 'special_two_year', 'special_two_percent'); | |
| $all_info['возраста ТС'] = $created_year; | |
| // Mashina avariya bo'lgani bo'yicha | |
| $vehicle_state = $this->getSumKoefThree($data['section_8_3'], $this->vehicle_library_state, '>=', 'special_three_check', 'special_three_year', 'special_three_clearance_state', 'special_three_percent'); | |
| $all_info['именавых случаев '] = $vehicle_state; | |
| // Mashina modeli va markasi bo'yicha hisoblash | |
| $vehicle_sum = $this->getVehicleSum($data['section_8_4'], 'special_four_check', 'special_four_vehicle'); | |
| $all_info['марки и модели'] = $vehicle_sum; | |
| } | |
| // KT | |
| // Ro'yhatdan o'tgan joyi | |
| $register_location = $this->register_location_id != '' ? $this->getOnlyExpectSumRegion($data['section_top_2_1'], $this->register_location_id, 'kt_one_register', 'kt_one_register_location', 'kt_one_percent') : 0; | |
| $all_info['места регистрации'] = $register_location; | |
| $driver_count = $library_expired = 0; | |
| $gender = $driver_no_state = $driver_state = $driver_experence = $driver_old = []; | |
| if ($this->driver_count and $this->driver_count != 'no-limits') { | |
| // KBM | |
| // Haydovchi soni | |
| $driver_count = $this->getSumKoef($data['section_top_3_1'], count($this->last_name), '>=', false, 'kbm_one_driver', 'kbm_one_percent'); | |
| $all_info['количества водителей'] = $driver_count; | |
| $male = $female = 0; | |
| foreach ($this->last_name as $key => $item) { | |
| $this->gender[$key] == 'male' ? $male++ : $female++; | |
| // Haydovchi halokat soni | |
| if (isset($this->driver_library_state[$key])) { | |
| $driver_state[] = $this->getSumKoefThree($data['section_top_3_2'], $this->driver_library_state[$key], '>=', false, 'kbm_two_year', 'kbm_two_clearance_state', 'kbm_two_percent'); | |
| } | |
| // KV | |
| $driver_experences = $this->driver_experence[$key]??0; | |
| $driver_experence[] = $this->getSumKoef($data['section_top_4_1'], $driver_experences, '>=', false, 'kb_one_year', 'kb_one_percent'); | |
| // KB3 | |
| // Haydovchi yoshi | |
| $driver_old[] = $this->getSumKoef($data['section_top_5_1'], $this->driver_old[$key], '>=', 'kb3_one_check', 'kb3_one_year', 'kb3_one_percent'); | |
| // KH | |
| // Haydovchi qoida buzmagani | |
| if ($data['section_top_6_1']['kh_one_check'] != 1) { | |
| $state = $data['section_top_6_1']; | |
| switch ($this->driver_violation[$key]) { | |
| case 1: | |
| $driver_no_state[] = !isset($state['kh_one_one_year_check']) ? $state['kh_one_one_year_percent'] : 0; | |
| break; | |
| case 2: | |
| $driver_no_state[] = !isset($state['kh_one_two_year_check']) ? $state['kh_one_two_year_percent'] : 0; | |
| break; | |
| case 3: | |
| $driver_no_state[] = !isset($state['kh_one_three_year_check']) ? $state['kh_one_three_year_percent'] : 0; | |
| break; | |
| case 4: | |
| $driver_no_state[] = !isset($state['kh_one_four_year_check']) ? $state['kh_one_four_year_percent'] : 0; | |
| break; | |
| case 5: | |
| $driver_no_state[] = !isset($state['kh_one_five_year_check']) ? $state['kh_one_five_year_percent'] : 0; | |
| break; | |
| default: | |
| $driver_no_state[] = 0; | |
| break; | |
| } | |
| } | |
| // KH todo 2 qismda ham??? нарушил ПДД более | |
| } | |
| // Haydovchi jinsi | |
| if ($data['section_top_3_3']['kbm_three_check'] != 1) { | |
| if (!isset($data['section_top_3_3']['kbm_three_female_check']) and $female > 0 and $female >= $male) { | |
| $gender[] = $data['section_top_3_3']['kbm_three_female_percent']; | |
| } | |
| if (!isset($data['section_top_3_3']['kbm_three_male_check']) and $male > 0 and $male >= $female) { | |
| $gender[] = $data['section_top_3_3']['kbm_three_male_percent']; | |
| } | |
| } | |
| } elseif($this->driver_count) { | |
| // KBM | |
| // Haydovchi soni | |
| $driver_count = $this->getSumKoef($data['section_top_3_1'], 0, '==', false, 'kbm_one_driver', 'kbm_one_percent'); | |
| $all_info['количества водителей'] = $driver_count; | |
| } | |
| // KSP | |
| // Sug'urta muddati kunda | |
| $library_expired = $this->getSumKoef($data['section_top_7_1'], $this->expired_at, '>=', false, 'kc_one_day', 'kc_one_percent'); | |
| $all_info['срока именавания'] = $library_expired; | |
| // Others | |
| $owner_type = $clearance_no_state = 0; | |
| if ($data['section_top_8_1']['other_check'] != 1) { | |
| $state = $data['section_top_8_1']; | |
| switch ($this->vehicle_owner_type) { | |
| case 'juridical': | |
| $owner_type = !isset($state['other_one_juridical_check']) ? $state['other_one_juridical_percent'] : 0; | |
| break; | |
| case 'physical': | |
| $owner_type = !isset($state['other_one_physical_check']) ? $state['other_one_physical_percent'] : 0; | |
| break; | |
| case 'indivudal': | |
| $owner_type = !isset($state['other_one_indivudal_check']) ? $state['other_one_indivudal_percent'] : 0; | |
| break; | |
| default: | |
| $owner_type = 0; | |
| break; | |
| } | |
| $all_info['типа именавателя'] = $owner_type; | |
| } | |
| // В зависимости от лояльности именавателя | |
| if ($data['section_top_8_2']['other_two_check'] != 1) { | |
| $state = $data['section_top_8_2']; | |
| $loyalnost = library::find() | |
| ->joinWith('product') | |
| ->orWhere(['like', 'vehicle_number', $this->vehicle_body_number]) | |
| ->orWhere(['like', 'body_number', $this->vehicle_body_number]) | |
| ->orWhere(['like', 'library_number', $this->vehicle_body_number]) | |
| ->andWhere(['between', 'library.created_at', | |
| date('Y-m-d H:i:s', strtotime('-5 years')), date('Y-m-d H:i:s')]) | |
| ->andWhere([ | |
| 'product.company_id'=>$product['company_id'], | |
| 'library.status'=>self::STATE_PAY_ACCEPTED | |
| ]) | |
| ->orderBy('library.id ASC') | |
| ->asArray() | |
| ->one(); | |
| $loyalnost_year = 0; | |
| if($loyalnost!=null){ | |
| $loyalnost_year = date('Y') - date('Y',strtotime($loyalnost['created_at'])); | |
| } | |
| switch ($loyalnost_year) { | |
| case 1: | |
| $clearance_no_state = !isset($state['other_two_one_year_check']) ? $state['other_two_one_year_percent'] : 0; | |
| break; | |
| case 2: | |
| $clearance_no_state = !isset($state['other_two_two_year_check']) ? $state['other_two_two_year_percent'] : 0; | |
| break; | |
| case 3: | |
| $clearance_no_state = !isset($state['other_two_three_year_check']) ? $state['other_two_three_year_percent'] : 0; | |
| break; | |
| case 4: | |
| $clearance_no_state = !isset($state['other_two_four_year_check']) ? $state['other_two_four_year_percent'] : 0; | |
| break; | |
| case 5: | |
| $clearance_no_state = !isset($state['other_two_five_year_check']) ? $state['other_two_five_year_percent'] : 0; | |
| break; | |
| default: | |
| $clearance_no_state = 0; | |
| break; | |
| } | |
| $all_info['лояльности именавателя'] = $clearance_no_state; | |
| } | |
| $current_library = library::find() | |
| ->joinWith('product') | |
| // ->where(['like', 'library_data', $this->vehicle_owner_type == 'juridical' ? $this->owner_inn : $this->owner_passport]) | |
| ->orWhere(['like', 'vehicle_number', $this->vehicle_body_number]) | |
| ->orWhere(['like', 'body_number', $this->vehicle_body_number]) | |
| ->orWhere(['like', 'library_number', $this->vehicle_body_number]) | |
| ->andWhere(['between', 'library.created_at', date('Y-m-d H:i:s', strtotime('-1 years')), date('Y-m-d H:i:s')]) | |
| ->andWhere([ | |
| 'product.company_id'=>$product['company_id'], | |
| 'library.status'=>self::STATE_PAY_ACCEPTED | |
| ]) | |
| ->orderBy('id DESC') | |
| ->asArray() | |
| ->count(); | |
| $has_library = 0; | |
| // ushbu kompaniyada polis borligi | |
| if ($current_library) { | |
| $has_library = $this->getSumKoef($data['section_top_8_5'], $current_library, '>=', 'other_five_check', 'other_five_ts', 'other_five_percent'); | |
| } | |
| $all_info['количества заименаванных машин'] = $has_library; | |
| $all_info['нарушения водителем правил именавания'] = count($driver_no_state) ? max($driver_no_state) : 0; | |
| $all_info['наличия именавых случаев водителем'] = count($driver_state) ? max($driver_state) : 0; | |
| $all_info['пола водителя'] = count($gender) ? max($gender) : 0; | |
| $all_info['водительский стаж'] = count($driver_experence) ? max($driver_experence) : 0; | |
| $all_info['возраста водителя'] = count($driver_old) ? max($driver_old) : 0; | |
| // $clearance_country = $this->getOnlyExpectSum($data['section_top_8_3'], ($this->vehicle_owner_type=='physical'?$this->owner_region_physical:$this->owner_region_juridical)==229?255:, 'other_three_check', 'other_three_register', 'other_three_register_country', 'other_three_percent'); | |
| $all = [ | |
| // Yengil mashinalar | |
| $country, | |
| $energy_power, | |
| $horse_power, | |
| $created_year, | |
| $vehicle_state, | |
| $vehicle_sum, | |
| $vehicle_use_for_purpose, | |
| $has_library, | |
| $xadavoy, | |
| $using, | |
| // KT barchasi uchun | |
| $register_location, | |
| $driver_count, | |
| $owner_type, | |
| $library_expired, //12 | |
| $clearance_no_state, | |
| count($driver_no_state) ? max($driver_no_state) : 0, | |
| count($driver_state) ? max($driver_state) : 0, | |
| count($gender) ? max($gender) : 0, | |
| count($driver_experence) ? max($driver_experence) : 0, | |
| count($driver_old) ? max($driver_old) : 0, | |
| ]; | |
| $average = $average_info = 0; | |
| if (count($all)) { | |
| $all = array_filter($all, function ($v) { | |
| return $v!=0; | |
| }); | |
| $average = array_sum($all) / count($all); | |
| } | |
| $aa = []; | |
| if (count($all_info)) { | |
| $all_info = array_filter($all_info, function ($v) { | |
| return $v!=0; | |
| }); | |
| $average_info = array_sum($all_info) / count($all_info); | |
| foreach ($all_info as $kk=>$item) { | |
| $aa[] ="$kk:$item"; | |
| } | |
| } | |
| $kommisiya = $average * $product['main_commission']; | |
| $oxirgi_kommisiya = $kommisiya; | |
| $formula = '(('.implode(' + ',$aa).")/количество:".count($all_info)." = средний:$average_info) * Базовая коммисия:".$product['main_commission'].";"; | |
| if ($average != 0 and $kommisiya < $product['min_commission']) { | |
| $formula = '(('.implode(' + ',$aa).")/количество:".count($all_info)." = средний: $average_info) * Базовая коммисия:".$product['main_commission']." = ".$oxirgi_kommisiya.") < Минимальная коммисия:".$product['min_commission'].';'; | |
| $oxirgi_kommisiya = $product['min_commission']; | |
| } elseif ($average != 0 and $kommisiya > $product['max_commission']) { | |
| $formula = '(('.implode(' + ',$aa).")/количество:".count($all_info)." = средний: $average_info) * Базовая коммисия:".$product['main_commission']." = ".$oxirgi_kommisiya.") > Максимальная коммисия:".$product['max_commission'].';'; | |
| $oxirgi_kommisiya = $product['max_commission']; | |
| } | |
| $formula .=" Cкидка:$oxirgi_kommisiya; "; | |
| if (!Yii::$app->user->isGuest) { | |
| $agent = CompanyHasAgent::find() | |
| ->joinWith(['companyHasAgent.company']) | |
| ->asArray() | |
| ->where([ | |
| 'company_has_agent.user_id' => Yii::$app->user->id, | |
| 'company_id' => $product['company_id'], | |
| 'company_has_agent.status' => 'active', | |
| 'company.status' => 'active', | |
| ]) | |
| ->andWhere(['>=','contract_date',date('Y-m-d')]) | |
| ->one(); | |
| if ($agent != null and $agent['companyHasAgent']) { | |
| $type = Json::decode($agent['companyHasAgent']['product']); | |
| if (in_array(ProductType::tableVTS, array_keys($type))) { | |
| $t = $type[ProductType::tableVTS]; | |
| $oxirgi_kommisiya -= $t; | |
| $formula .=" Комиссия агента:$t; Cкидка: $oxirgi_kommisiya;"; | |
| } | |
| } | |
| } | |
| if ($oxirgi_kommisiya < 0) { | |
| $oxirgi_kommisiya = 0; | |
| $formula .=" $oxirgi_kommisiya < 0; Cкидка:0"; | |
| } | |
| return [$oxirgi_kommisiya,$formula]; | |
| } | |
| public function getYesNoSum($data, $value, $check = false, $condition, $key1, $key2) | |
| { | |
| $sum = null; | |
| if (!array_key_exists($key1,$data)) { | |
| return null; | |
| } | |
| foreach ($data[$key1] as $k=>$datum) { | |
| foreach ($data[$key1] as $i=>$datum2) { | |
| if($k==$i){ | |
| continue; | |
| } | |
| if($datum==$datum2 and $data[$key2][$k]<$data[$key2][$i]){ | |
| unset($data[$key1][$k]); | |
| }elseif($datum==$datum2 and $data[$key2][$k]>$data[$key2][$i]){ | |
| unset($data[$key1][$i]); | |
| } | |
| } | |
| } | |
| if ($check) { | |
| if ($data[$check] != 1) { | |
| foreach ($data[$key1] as $k=>$item) { | |
| if ($value and in_array($item, $value) and $data[$condition][$k]=='yes') { | |
| $a = $data[$key2][$k]; | |
| if(is_null($sum)){ | |
| $sum = 0; | |
| } | |
| $sum +=$a; | |
| }elseif ($value and in_array($item, $value) and $data[$condition][$k]=='no') { | |
| continue; | |
| }elseif ($value and !in_array($item, $value) and $data[$condition][$k]=='no') { | |
| $a = $data[$key2][$k]; | |
| if(is_null($sum)){ | |
| $sum = 0; | |
| } | |
| $sum +=$a; | |
| }elseif (!$value and $data[$condition][$k]=='no') { | |
| $a = $data[$key2][$k]; | |
| if(is_null($sum)){ | |
| $sum = 0; | |
| } | |
| $sum +=$a; | |
| } | |
| } | |
| } | |
| } else { | |
| foreach ($data[$key1] as $k=>$item) { | |
| if ($value and in_array($item, $value) and $data[$condition][$k]=='yes') { | |
| $a = $data[$key2][$k]; | |
| if(is_null($sum)){ | |
| $sum = 0; | |
| } | |
| $sum +=$a; | |
| }elseif ($value and in_array($item, $value) and $data[$condition][$k]=='no') { | |
| continue; | |
| }elseif ($value and !in_array($item, $value) and $data[$condition][$k]=='no') { | |
| $a = $data[$key2][$k]; | |
| if(is_null($sum)){ | |
| $sum = 0; | |
| } | |
| $sum +=$a; | |
| }elseif (!$value and $data[$condition][$k]=='no') { | |
| $a = $data[$key2][$k]; | |
| if(is_null($sum)){ | |
| $sum = 0; | |
| } | |
| $sum +=$a; | |
| } | |
| } | |
| } | |
| return $sum; | |
| } | |
| public function getOnlyExpectSum($data, $value, $check = false, $condition, $key1, $key2) | |
| { | |
| $sum = null; | |
| if ($check) { | |
| if ($data[$check] != 1) { | |
| $except = []; | |
| foreach ($data[$key1] as $i => $item) { | |
| if ($item==$value and $data[$condition][$i]=='only') { | |
| $sum = $data[$key2][$i]; | |
| break; | |
| }elseif ($item!=$value and $data[$condition][$i]=='except') { | |
| $except[] = $data[$key2][$i];; | |
| continue; | |
| } | |
| } | |
| if (is_null($sum) and $except) { | |
| $sum = max($except); | |
| } | |
| } | |
| } else { | |
| $except = []; | |
| foreach ($data[$key1] as $i => $item) { | |
| if ($item==$value and $data[$condition][$i]=='only') { | |
| $sum = $data[$key2][$i]; | |
| break; | |
| }elseif ($item!=$value and $data[$condition][$i]=='except') { | |
| $except[] = $data[$key2][$i];; | |
| continue; | |
| } | |
| } | |
| if (is_null($sum) and $except) { | |
| $sum = max($except); | |
| } | |
| } | |
| return $sum; | |
| } | |
| public function getSumKoef($data, $value, $condition, $check = false, $key1, $key2) | |
| { | |
| $sum = null; | |
| if ($check) { | |
| if ($data[$check] != 1) { | |
| asort($data[$key1]); | |
| foreach ($data[$key1] as $key => $item) { | |
| if ($condition=='>=') { | |
| if ($value >= $item) { | |
| $sum = $data[$key2][$key]; | |
| } | |
| }elseif ($condition=='==') { | |
| if ($value == $item) { | |
| $sum = $data[$key2][$key]; | |
| } | |
| }elseif ($condition=='>') { | |
| if ($value > $item) { | |
| $sum = $data[$key2][$key]; | |
| } | |
| }elseif ($condition=='<') { | |
| if ($value < $item) { | |
| $sum = $data[$key2][$key]; | |
| } | |
| } elseif ($condition=='<=') { | |
| if ($value <= $item) { | |
| $sum = $data[$key2][$key]; | |
| } | |
| } | |
| } | |
| } | |
| } else { | |
| asort($data[$key1]); | |
| foreach ($data[$key1] as $key => $item) { | |
| if ($condition=='>=') { | |
| if ($value >= $item) { | |
| $sum = $data[$key2][$key]; | |
| } | |
| }elseif ($condition=='==') { | |
| if ($value == $item) { | |
| $sum = $data[$key2][$key]; | |
| } | |
| }elseif ($condition=='>') { | |
| if ($value > $item) { | |
| $sum = $data[$key2][$key]; | |
| } | |
| }elseif ($condition=='<') { | |
| if ($value < $item) { | |
| $sum = $data[$key2][$key]; | |
| } | |
| } elseif ($condition=='<=') { | |
| if ($value <= $item) { | |
| $sum = $data[$key2][$key]; | |
| } | |
| } | |
| } | |
| } | |
| return $sum; | |
| } | |
| public function getSumKoefThree($data, $value, $condition, $check = false, $key1, $key2, $key3) | |
| { | |
| $sum = []; | |
| if ($check) { | |
| if ($data[$check] != 1) { | |
| asort($data[$key1]); | |
| foreach ($data[$key1] as $key => $item) { | |
| if (array_key_exists($item, $value)) { | |
| if ($condition=='>=') { | |
| if ($value[$item] >= $data[$key2][$key]) { | |
| $sum[] = $data[$key3][$key]; | |
| } | |
| } elseif ($condition=='==') { | |
| if ($value[$item] == $data[$key2][$key]) { | |
| $sum[] = $data[$key3][$key]; | |
| } | |
| } elseif ($condition=='>') { | |
| if ($value[$item] > $data[$key2][$key]) { | |
| $sum[] = $data[$key3][$key]; | |
| } | |
| } elseif ($condition=='<') { | |
| if ($value[$item] < $data[$key2][$key]) { | |
| $sum[] = $data[$key3][$key]; | |
| } | |
| } elseif ($condition=='<=') { | |
| if ($value[$item] <= $data[$key2][$key]) { | |
| $sum[] = $data[$key3][$key]; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } else { | |
| asort($data[$key1]); | |
| foreach ($data[$key1] as $key => $item) { | |
| if (array_key_exists($item, $value)) { | |
| // $sum[] = $data[$key3][$key]; | |
| if ($condition=='>=') { | |
| if ($value[$item] >= $data[$key2][$key]) { | |
| $sum[] = $data[$key3][$key]; | |
| } | |
| } elseif ($condition=='==') { | |
| if ($value[$item] == $data[$key2][$key]) { | |
| $sum[] = $data[$key3][$key]; | |
| } | |
| } elseif ($condition=='>') { | |
| if ($value[$item] > $data[$key2][$key]) { | |
| $sum[] = $data[$key3][$key]; | |
| } | |
| } elseif ($condition=='<') { | |
| if ($value[$item] < $data[$key2][$key]) { | |
| $sum[] = $data[$key3][$key]; | |
| } | |
| } elseif ($condition=='<=') { | |
| if ($value[$item] <= $data[$key2][$key]) { | |
| $sum[] = $data[$key3][$key]; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| return $sum?max($sum):null; | |
| } | |
| public function getVehicleSum($data, $check, $key) | |
| { | |
| $vehicle_sum = null; | |
| if ($data[$check] != 1) { | |
| if (isset($data[$key]) and array_key_exists($this->brand, $data[$key])) { | |
| $vehicle = $data[$key][$this->brand]; | |
| $vehicle_sum = (isset($vehicle[0]) and $vehicle[0]!='') ? $vehicle[0] : null; | |
| if (array_key_exists($this->vehicle_model_id, $vehicle) and $vehicle[$this->vehicle_model_id] != '') { | |
| $vehicle_sum = $vehicle[$this->vehicle_model_id]; | |
| } | |
| } | |
| } | |
| return $vehicle_sum; | |
| } | |
| public function getOnlyExpectSumRegion($data, $value, $condition, $key1, $key2) | |
| { | |
| $sum = null; | |
| if (in_array($value, $data[$key1])) { | |
| $id = array_search($value, $data[$key1]); | |
| if ($data[$condition][$id] == 'only') { | |
| $sum = $data[$key2][$id]; | |
| } else { | |
| $region = Region::find()->asArray()->cache(300)->where(['status'=>'active','id' => $value])->one(); | |
| if ($region != null and in_array('province_' . $region['province_id'], $data[$key1])) { | |
| $id = array_search('province_' . $region['province_id'], $data[$key1]); | |
| if ($data[$condition][$id] == 'only') { | |
| $sum = $data[$key2][$id]; | |
| } else { | |
| $except = []; | |
| foreach ($data[$condition] as $key => $item) { | |
| if ($item == 'only') { | |
| continue; | |
| } else { | |
| $except[] = $data[$key2][$key]; | |
| $sum = max($except); | |
| } | |
| } | |
| } | |
| } else { | |
| $except = []; | |
| foreach ($data[$condition] as $key => $item) { | |
| if ($item == 'only') { | |
| continue; | |
| } else { | |
| $except[] = $data[$key2][$key]; | |
| $sum = max($except); | |
| } | |
| } | |
| } | |
| } | |
| } else { | |
| $region = Region::find()->asArray()->cache(300)->where(['status'=>'active','id' => $value])->one(); | |
| if ($region != null and in_array('province_' . $region['province_id'], $data[$key1])) { | |
| $id = array_search('province_' . $region['province_id'], $data[$key1]); | |
| if ($data[$condition][$id] == 'only') { | |
| $sum = $data[$key2][$id]; | |
| } else { | |
| $except = []; | |
| foreach ($data[$condition] as $key => $item) { | |
| if ($item == 'only') { | |
| continue; | |
| } else { | |
| $except[] = $data[$key2][$key]; | |
| $sum = max($except); | |
| } | |
| } | |
| } | |
| } else { | |
| $except = []; | |
| foreach ($data[$condition] as $key => $item) { | |
| if ($item == 'only') { | |
| continue; | |
| } else { | |
| $except[] = $data[$key2][$key]; | |
| $sum = max($except); | |
| } | |
| } | |
| } | |
| } | |
| return $sum; | |
| } | |
| public static function find() | |
| { | |
| return new \app\models\query\libraryQuery(get_called_class()); | |
| } | |
| public function setlibraryNumber($book=false) | |
| { | |
| if ($book) { | |
| $number = $this->productbook->company->library_series . '-'; | |
| }else{ | |
| $number = $this->product->company->library_series . '-'; | |
| } | |
| for ($i = 0; $i < 7; $i++) { | |
| $number .= mt_rand(0, 9); | |
| } | |
| $hasDb = self::find()->where(['library_number' => $number])->exists(); | |
| if ($hasDb) { | |
| $this->setlibraryNumber($book); | |
| } | |
| if ($book) { | |
| $this->library_number_book = $number; | |
| }else{ | |
| $this->library_number = $number; | |
| } | |
| return; | |
| } | |
| // public function getDriverlibraryState($key, $driving_license, $driving_license_date) | |
| // { | |
| // $driver = library::find() | |
| // ->where('JSON_EXTRACT(`library_data`,"$.driving_license")=:driving_license', [':driving_license' => $driving_license]) | |
| // ->andWhere('JSON_EXTRACT(`library_data`,"$.$driving_license_date")=:driving_license_date', [':driving_license_date' => $driving_license_date]) | |
| // ->asArray()->orderBy('id DESC')->one(); | |
| // if ($driver != null) { | |
| // $this->library_state[$key] = 1; | |
| // $this->library_state[$key] = 1; | |
| // } | |
| // } | |
| // public function getVehiclelibraryState() | |
| // { | |
| // $count = 0; | |
| //// $state = libraryState::find()->where('')->count(); | |
| // } | |
| public function getVehicleOwner() | |
| { | |
| $name = ''; | |
| if ($this->vehicle_owner_type != 'physical') { | |
| $name .= $this->owner_name . ', ' . $this->owner_inn; | |
| } else { | |
| $name .= $this->owner_last_name . ' ' . $this->owner_first_name . ' ' . $this->owner_sure_name . ', ' . $this->owner_passport; | |
| } | |
| return $name; | |
| } | |
| public function getVehicleOwnerName() | |
| { | |
| $name = ''; | |
| if ($this->vehicle_owner_type != 'physical') { | |
| $name .= $this->owner_name; | |
| } else { | |
| $name .= $this->owner_last_name . ' ' . $this->owner_first_name . ' ' . $this->owner_sure_name; | |
| } | |
| return $name; | |
| } | |
| public function getVehicleOverview($short = false) | |
| { | |
| $name = ''; | |
| if (isset($this->vehicleModel->brand->name)) { | |
| $name .= Functions::getLanguageValue($this->vehicleModel->brand->name) . ', '; | |
| } | |
| $name .= Functions::getLanguageValue($this->vehicleModel->name) . ', ' . $this->created_date; | |
| if ($short) { | |
| return $name; | |
| } | |
| $str = ''; | |
| if ($this->vehicle_type == 1 and isset($this->energy_power)) { | |
| $str .= $str != '' ? ', ' : ''; | |
| $str .= Yii::t('yii', '{energy_power} energy power', ['energy_power' => ($this->energy_power)]); | |
| } | |
| if ($this->vehicle_type == 1 and isset($this->horse_power)) { | |
| $str .= $str != '' ? ', ' : ''; | |
| $str .= Yii::t('yii', '{horse_power} h/p', ['horse_power' => ($this->horse_power)]); | |
| } | |
| if ($this->vehicle_type == 2 and isset($this->weight)) { | |
| $str .= $str != '' ? ', ' : ''; | |
| $str .= Yii::t('yii', '{weight} tons', ['weight' => ($this->weight)]); | |
| } | |
| if (in_array($this->vehicle_type,[3,5,6]) and isset($this->suit)) { | |
| $str .= $str != '' ? ', ' : ''; | |
| $str .= Yii::t('yii', '{suit} suits', ['suit' => ($this->suit)]); | |
| } | |
| $name .= $str != '' ? ', ' . $str : ''; | |
| return $name; | |
| } | |
| public function getDrivers($short = false, $full = false) | |
| { | |
| $driver = ''; | |
| foreach ($this->last_name as $key => $item) { | |
| if ($short) { | |
| $driver .= strtoupper($item . ' ' . $this->first_name[$key] . ' ' . $this->sure_name[$key]) . '<br>'; | |
| } elseif ($full) { | |
| $driver .= '<div class="display-flex"> | |
| <div class="m-r-15 p-t-5"><b class="pull-left display-block">' . $key . ')</b></div> | |
| <table class="table-driver m-0 table table-responsive table-condensed table-hover"> | |
| <tr> | |
| <td style="width: 30%"><p class="font-weight-bold">' . Yii::t('yii', 'Full Name') . ':</p><em class="text-uppercase">' . strtoupper($item . ' ' . $this->first_name[$key] . ' ' . $this->sure_name[$key]) . '</em></td> | |
| <td><p class="font-weight-bold">' . $this->getAttributeLabel('passport') . ':</p><em>' . $this->passport[$key] . '</em></td> | |
| <td style="width: 13%"><p class="font-weight-bold">' . $this->getAttributeLabel('birth_day') . ':</p><em>' . date('d.m.Y', strtotime($this->birth_day[$key])) . '</em></td> | |
| <td><p class="font-weight-bold">' . $this->getAttributeLabel('driving_license') . ':</p><em>' . $this->driving_license[$key] . '</em></td> | |
| <td><p class="font-weight-bold">' . $this->getAttributeLabel('driving_license_date') . ':</p><em>' . date('d.m.Y', strtotime($this->driving_license_date[$key])) . '<em></td> | |
| </tr> | |
| </table> | |
| </div><hr>'; | |
| } else { | |
| $d = $this->getExperienceDriver($key); | |
| $dd = $d?', '.$d:''; | |
| $driver .= '<p><span class="text-uppercase">' . strtoupper($item . ' ' . $this->first_name[$key] . ' ' . $this->sure_name[$key]) . '</span><br>'; | |
| $driver .= date('d.m.Y', strtotime($this->birth_day[$key])) . $dd . '</p>'; | |
| } | |
| } | |
| return $driver; | |
| } | |
| /** | |
| * @param $key | |
| * @return string | |
| */ | |
| public function getExperienceDriver($key) | |
| { | |
| //$month = date('Y') - date('Y',strtotime($this->driving_license_date[$key])); | |
| $start=date('Y-m-d',strtotime($this->driving_license_date[$key])); | |
| $end=date('Y-m-d'); | |
| $diff = abs(strtotime($end) - strtotime($start)); | |
| $years = floor($diff / (365*60*60*24)); | |
| $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24)); | |
| if ($years==0 && $months<=12) { | |
| $experience = $experience = Yii::t('yii', 'experience less than {year} year', ['year' => 1]);; | |
| }elseif ($years==1 && $months>=0) { | |
| $experience = Yii::t('yii', 'experience more {year} year', ['year' => $years]); | |
| } | |
| else { | |
| $experience = Yii::t('yii', 'experience more {year} years', ['year' => $years]); | |
| } | |
| return $experience; | |
| } | |
| public function getProduct() | |
| { | |
| return $this->hasOne(Product::className(), ['id' => 'product_id']); | |
| } | |
| public function getProductbook() | |
| { | |
| return $this->hasOne(Product::className(), ['id' => 'product_id_book']); | |
| } | |
| public function getUser() | |
| { | |
| return $this->hasOne(User::className(), ['id' => 'user_id']); | |
| } | |
| public function getApproved() | |
| { | |
| return $this->hasOne(User::className(), ['id' => 'discount_approved_user']); | |
| } | |
| public function getCanceled() | |
| { | |
| return $this->hasOne(User::className(), ['id' => 'canceled_user']); | |
| } | |
| public function getVehicleModel() | |
| { | |
| return $this->hasOne(VehicleModel::className(), ['id' => 'vehicle_model_id']); | |
| } | |
| public function getCompanyHasAgent() | |
| { | |
| return $this->hasOne(CompanyHasAgent::className(), ['id' => 'agent_id']); | |
| } | |
| public function getRegion() | |
| { | |
| return $this->hasOne(Region::className(), ['id' => 'register_location_id']); | |
| } | |
| public function getlibraryStates() | |
| { | |
| return $this->hasMany(libraryState::className(), ['library_id' => 'id']); | |
| } | |
| public function getlibraryDrivers() | |
| { | |
| return $this->hasMany(Driver::className(), ['library_id' => 'id']); | |
| } | |
| public function afterFind() | |
| { | |
| if ($this->library_data) { | |
| $data = Functions::jsonDecode($this->library_data); | |
| if (is_array($data)) { | |
| foreach ($data as $key => $item) { | |
| $this->{$key} = $item; | |
| } | |
| } | |
| } | |
| if ($this->vehicle_data) { | |
| $data = Functions::jsonDecode($this->vehicle_data); | |
| if (is_array($data)) { | |
| foreach ($data as $key => $item) { | |
| if(property_exists($this,$key)) | |
| $this->{$key} = $item; | |
| } | |
| } | |
| } | |
| if ($this->driver_count == '1-5-drivers') { | |
| $drivers = Driver::find()->asArray()->where(['library_id'=>$this->id])->all(); | |
| if ($drivers!=null) { | |
| foreach ($drivers as $key=>$driver) { | |
| $this->last_name[$key] = $driver['last_name']; | |
| $this->first_name[$key] = $driver['first_name']; | |
| $this->sure_name[$key] = $driver['sure_name']; | |
| $this->passport[$key] = $driver['passport']; | |
| $this->birth_day[$key] = $driver['birth_day']; | |
| $this->driving_license[$key] = $driver['driving_license']; | |
| $this->driving_license_date[$key] = $driver['driving_license_date']; | |
| $this->library_state[$key] = $driver['library_state']; | |
| $this->violation[$key] = $driver['violation']; | |
| $this->gender[$key] = $driver['gender']; | |
| } | |
| } | |
| } | |
| parent::afterFind(); // TODO: Change the autogenerated stub | |
| } | |
| public function setAttributesNull() | |
| { | |
| $attributes = $this->safeAttributes(); | |
| foreach ($attributes as $attribute) { | |
| $this->$attribute = null; | |
| } | |
| $this->id = null; | |
| $this->technical_passport_date = null; | |
| $this->library_summa = null; | |
| $this->library_summa_book = null; | |
| $this->library_summa_end = null; | |
| $this->library_summa_end2 = null; | |
| $this->agent_id = null; | |
| $this->agent_benifit = null; | |
| $this->html_pdf_content = null; | |
| } | |
| public static function renderSummary($dataProvider){ | |
| /** @var ActiveDataProvider $dataProvider */ | |
| $count = $dataProvider->getCount(); | |
| if ($count <= 0) { | |
| return ''; | |
| } | |
| $tag = 'div'; | |
| if (($pagination = $dataProvider->getPagination()) !== false) { | |
| $totalCount = $dataProvider->getTotalCount(); | |
| $begin = $pagination->getPage() * $pagination->pageSize + 1; | |
| $end = $begin + $count - 1; | |
| if ($begin > $end) { | |
| $begin = $end; | |
| } | |
| $page = $pagination->getPage() + 1; | |
| $pageCount = $pagination->pageCount; | |
| return Html::tag($tag, Yii::t('yii', 'Showing <b>{begin, number}-{end, number}</b> of <b>{totalCount, number}</b> {totalCount, plural, one{item} other{items}}.', [ | |
| 'begin' => $begin, | |
| 'end' => $end, | |
| 'count' => $count, | |
| 'totalCount' => $totalCount, | |
| 'page' => $page, | |
| 'pageCount' => $pageCount, | |
| ])); | |
| } else { | |
| $begin = $page = $pageCount = 1; | |
| $end = $totalCount = $count; | |
| return Html::tag($tag, Yii::t('yii', 'Total <b>{count, number}</b> {count, plural, one{item} other{items}}.', [ | |
| 'begin' => $begin, | |
| 'end' => $end, | |
| 'count' => $count, | |
| 'totalCount' => $totalCount, | |
| 'page' => $page, | |
| 'pageCount' => $pageCount, | |
| ])); | |
| } | |
| } | |
| /** | |
| * @return array | |
| */ | |
| public static function getStatus(){ | |
| return [ | |
| self::STATE_NONE => Yii::t('yii','Cancelled by user'), | |
| self::STATE_WAITING_PAY => Yii::t('yii','Waiting payment'), | |
| self::STATE_PAY_ACCEPTED => Yii::t('yii','Pay accepted'), | |
| self::STATE_CANCELLED => Yii::t('yii','Return'), | |
| ]; | |
| } | |
| /** | |
| * @return mixed | |
| */ | |
| public function getOwnerText(){ | |
| return ArrayHelper::getValue(Functions::getUserType(),$this->vehicle_owner_type); | |
| } | |
| /** | |
| * @return mixed | |
| */ | |
| public function getStatusText(){ | |
| return ArrayHelper::getValue(self::getStatus(),$this->status); | |
| } | |
| /** | |
| * @return null|string | |
| */ | |
| public function getStatusState(){ | |
| $status = null; | |
| if($this->status==self::STATE_PAY_ACCEPTED){ | |
| $status = Yii::t('yii', "Pay accepted"); | |
| $status .= ' '.date('d.m.y',strtotime($this->payment_date)); | |
| $a = 1; | |
| if($this->discount and $this->discount_status){ | |
| $a = 0; | |
| $status .= '<br>'.Yii::t('yii',"Special discount"); | |
| }elseif($this->discount and $this->discount_status==0){ | |
| $a = 0; | |
| $status .= '<br>'. Yii::t('yii',"Waiting special discount"); | |
| } | |
| if($this->payment_type=='bank') { | |
| $status .= ($a?'<br>':', ').Yii::t('yii', "Bank payment"); | |
| }elseif($this->payment_type=='cash') { | |
| $status .= ($a?'<br>':', ').Yii::t('yii', "Cash payment"); | |
| }elseif($this->payment_type=='terminal') { | |
| $status .= ($a?'<br>':', ').Yii::t('yii', "Terminal payment"); | |
| }elseif($this->payment_type=='click') { | |
| $status .= ($a?'<br>':', ').Yii::t('yii', "Click payment"); | |
| }elseif($this->payment_type=='payme') { | |
| $status .= ($a?'<br>':', ').Yii::t('yii', "Payme payment"); | |
| } | |
| }elseif($this->status == self::STATE_WAITING_PAY){ | |
| $status = Yii::t('yii',"Waiting payment"); | |
| if($this->vehicle_owner_type!='physical'){ | |
| $status = Yii::t('yii',"Waiting bank payment"); | |
| $bank = BankPayments::find()->asArray() | |
| ->where(['library_id'=>$this->id]) | |
| ->orderBy('created_at DESC') | |
| ->one(); | |
| if($bank!=null){ | |
| if($bank['status']=='new'){ | |
| $status = Yii::t('yii',"Waiting approved"); | |
| }elseif($bank['status']=='inactive'){ | |
| $status = Yii::t('yii',"Return").' '.date('d.m.y',strtotime($bank['approved_at'])); | |
| } | |
| } | |
| } | |
| }elseif($this->status == self::STATE_CANCELLED){ | |
| $status = Yii::t('yii',"Return").'<br>'.date('d.m.y',strtotime($this->canceled_date)); | |
| }elseif($this->status == self::STATE_NONE){ | |
| $status = Yii::t('yii',"Cancelled by user"); | |
| } | |
| return $status; | |
| } | |
| /** | |
| * @return null|string | |
| */ | |
| public function getStatusCompanyPayment($short = false){ | |
| if($this->payment_company_id){ | |
| $status = Yii::t('yii', "Pay accepted"); | |
| $status .= ($short)?'':'<br>'.Yii::$app->formatter->asDate($this->payment_company_date); | |
| }else{ | |
| $status = Yii::t('yii',"Waiting payment"); | |
| } | |
| return $status; | |
| } | |
| public function sendToUser() | |
| { | |
| $text = ''; | |
| if($this->vehicle_owner_type=='physical'){ | |
| if ($this->status==self::STATE_PAY_ACCEPTED and $this->discount == 1 and $this->discount_status == 0) { | |
| $text = Yii::t('yii', Yii::$app->params['msg2'], ['library' => $this->library_number]); | |
| } else { | |
| $text = Yii::t('yii', Yii::$app->params['msg1'], ['library' => $this->library_number]); | |
| } | |
| }else { | |
| if ($this->status == self::STATE_PAY_ACCEPTED) { | |
| $text = Yii::t('yii', Yii::$app->params['msg3'], ['library' => $this->library_number]); | |
| } else { | |
| $text = Yii::t('yii', Yii::$app->params['msg1'], ['library' => $this->library_number]); | |
| } | |
| } | |
| $text .= ', '.Yii::t('yii',Yii::$app->params['msg0'],['library'=>$this->library_number]); | |
| if($phone = $this->owner_phone_number){ | |
| if(strlen($phone)==9){ | |
| $phone .= '9989'.$phone; | |
| } | |
| Yii::$app->playmobile->sendSms($phone,$text); | |
| } | |
| if(!$this->agent_id){ | |
| EmailSend::send($this->user->email,$text); | |
| } | |
| } | |
| /** | |
| * @return array | |
| */ | |
| public static function getbookSummaAll() | |
| { | |
| $summa = [ | |
| 10000000, 20000000, 30000000, 50000000, 70000000, | |
| 100000000, 150000000, 250000000, 300000000, 500000000, | |
| ]; | |
| $r = []; | |
| foreach ($summa as $item) { | |
| $r[$item] = Yii::t('yii',"{summa} so'm",['summa'=>Yii::$app->formatter->asInteger($item)]); | |
| } | |
| return $r; | |
| } | |
| public function getCheckbook() | |
| { | |
| return ($this->product_id and $this->product_id_book and $this->product_id != $this->product_id_book); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment