Booking, QI Content, Trees, Media

This commit is contained in:
Kevin Adametz 2019-10-02 20:03:55 +02:00
parent 1f340e96fa
commit 7fbac395a9
260 changed files with 27160 additions and 3773 deletions

View file

@ -129,7 +129,49 @@ class Booking extends Model
}
public function calculate_price_total()
{
$travel_draft_item = false;
$travel_price_adult = 0;
$travel_price_children = 0;
$total_adult = 0;
$total_children = 0;
foreach ($this->booking_draft_items as $booking_draft_item) {
//24 Rundreise
if($booking_draft_item->draft_type_id == 24){
$travel_draft_item = $booking_draft_item;
continue;
}
$prices = $booking_draft_item->getItemPrice();
//Grundpreis Reise
if($booking_draft_item->draft_type_id == 30){
$travel_price_adult += $prices['adult'];
$travel_price_children += $prices['children'];
}
$total_adult += $prices['adult'];
$total_children += $prices['children'];
}
if($travel_draft_item){
$travel_draft_item->setPriceAdultRaw($travel_price_adult);
$travel_draft_item->setPriceChildrenRaw($travel_price_children);
$travel_draft_item->save();
}
$this->price = $total_adult + $total_children;
$this->save();
}
public function _format_number($value){
return preg_replace("/[^0-9,]/", "", $value);
}
public function getPriceAttribute()
{
// 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator
return number_format(($this->attributes['price']), 2, ',', '.');
}
public function findBeforeDraftItemRelation($reid)
{

View file

@ -114,6 +114,32 @@ class BookingDraftItem extends Model
return $this->belongsTo('App\Models\DraftType', 'draft_type_id');
}
public function getItemPrice(){
$adult = 0;
$children = 0;
$days_duration = 1;
if(isset($this->attributes['days_duration']) && in_array($this->draft_type_id, [36, 37])){
$days_duration = intval($this->days_duration);
}
if(isset($this->attributes['adult'])){
$adult = $this->attributes['price_adult'] * $this->attributes['adult'] * $days_duration;
}
if(isset($this->attributes['children'])){
$children = $this->attributes['price_children'] * $this->attributes['children'] * $days_duration;
}
/*
if(in_array($this->draft_type_id, [38, 39,40])){
$days_duration = $this->days_duration;
$price = $this->price;
}
*/
return ['adult'=>$adult, 'children'=>$children];
}
public function _format_number($value){
return preg_replace("/[^0-9,]/", "", $value);
}
@ -141,21 +167,66 @@ class BookingDraftItem extends Model
}
}
//price_adult
public function setPriceAdultAttribute($value)
{
$value = $this->_format_number($value);
$this->attributes['price_adult'] = floatval(str_replace(',', '.', $value));
}
public function getPriceAdultAttribute()
{
// 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator
return number_format(($this->attributes['price_adult']), 2, ',', '.');
}
public function getPriceAdultRaw()
{
return isset($this->attributes['price_adult']) ? $this->attributes['price_adult'] : 0;
}
public function setPriceAdultRaw($value)
{
return $this->attributes['price_adult'] = $value;
}
//price_children
public function setPriceChildrenAttribute($value)
{
$value = $this->_format_number($value);
$this->attributes['price_children'] = floatval(str_replace(',', '.', $value));
}
public function getPriceChildrenAttribute()
{
// 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator
return number_format(($this->attributes['price_children']), 2, ',', '.');
}
public function getPriceChildrenRaw()
{
return isset($this->attributes['price_children']) ? $this->attributes['price_children'] : 0;
}
public function setPriceChildrenRaw($value)
{
return $this->attributes['price_children'] = $value;
}
//price
public function setPriceAttribute($value)
{
$value = $this->_format_number($value);
$this->attributes['price'] = floatval(str_replace(',', '.', $value));
}
public function getPriceAttribute()
{
// 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator
return number_format(($this->attributes['price']), 2, ',', '.');
}
public function getPriceRaw()
{
return isset($this->attributes['price']) ? $this->attributes['price'] : 0;
}
public function setPriceRaw($value)
{
return $this->attributes['price'] = $value;
}
}

View file

@ -51,7 +51,7 @@ class CMSContent extends Model
protected $table = 'c_m_s_contents';
protected $fillable = [
'name', 'field', 'text', 'full_text', 'integer', 'decimal',
'name', 'slug', 'field', 'text', 'full_text', 'integer', 'decimal',
];
public function sluggable()

View file

@ -57,11 +57,10 @@ class DraftItem extends Model
protected $table = 'draft_items';
protected $fillable = [
'pos',
'pos'
];
public function draft()
{
return $this->belongsTo('App\Models\Draft', 'draft_id');

View file

@ -0,0 +1,47 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\IQContentSite
*
* @property int $id
* @property int $tree_node_id
* @property int $travel_guide_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\IQContentTreeNode $iq_content_tree_node
* @property-read \App\Models\TravelGuide $travel_guide
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentSite newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentSite newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentSite query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentSite whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentSite whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentSite whereTravelGuideId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentSite whereTreeNodeId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentSite whereUpdatedAt($value)
* @mixin \Eloquent
*/
class IQContentSite extends Model
{
protected $connection = 'mysql_stern';
protected $table = 'i_q_content_sites';
protected $fillable = [
'tree_node_id', 'travel_guide_id',
];
public function iq_content_tree_node()
{
return $this->belongsTo('App\Models\IQContentTreeNode', 'tree_node_id');
}
public function travel_guide()
{
return $this->belongsTo('App\Models\TravelGuide', 'travel_guide_id');
}
}

View file

@ -43,6 +43,10 @@ use Illuminate\Support\Str;
* @method static \Illuminate\Database\Query\Builder|\App\Models\IQContentTree withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\IQContentTree withoutTrashed()
* @mixin \Eloquent
* @property int|null $page_id
* @property int|null $root_id
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTree wherePageId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\IQContentTree whereRootId($value)
*/
class IQContentTree extends Model
{
@ -83,4 +87,29 @@ class IQContentTree extends Model
}
}
public static function getTreesOptions($id = false, $html = true, $choose = true) {
$values = [];
$ret = "";
$models = IQContentTree::where('active', 1)->get();
if($html) {
if($choose){
$ret .= '<option value="">Bitte wählen</option>\n';
}
foreach ($models as $model) {
$attr = ($model->id == $id) ? ' selected="selected"' : '';
$ret .= '<option value="' . $model->id . '"' . $attr . '>' . $model->name . '</option>\n';
}
return $ret;
}else{
foreach ($models as $model) {
$values[$model->id] = $model->name;
}
return $values;
}
return false;
}
}

View file

@ -51,6 +51,8 @@ use Illuminate\Support\Str;
* @method static \Illuminate\Database\Query\Builder|\App\Models\IQContentTreeNode withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Models\IQContentTreeNode withoutTrashed()
* @mixin \Eloquent
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentSite[] $iq_content_site
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentSite[] $iq_content_sites
*/
class IQContentTreeNode extends Model
{
@ -59,7 +61,6 @@ class IQContentTreeNode extends Model
protected $connection = 'mysql_stern';
protected $dates = ['deleted_at'];
protected $table = 'i_q_content_tree_nodes';
@ -91,12 +92,21 @@ class IQContentTreeNode extends Model
public function iq_content_tree_node_childs()
{
return $this->hasMany('App\Models\IQContentTreeNode', 'parent_id', 'id');
return $this->hasMany('App\Models\IQContentTreeNode', 'parent_id', 'id')->orderBy('pos', 'ASC');
}
public function travel_guides()
public function iq_content_sites()
{
return $this->hasMany('App\Models\TravelGuide', 'tree_node_id', 'id');
return $this->hasMany('App\Models\IQContentSite', 'tree_node_id', 'id');
}
public function iq_content_site_first()
{
foreach ($this->iq_content_sites as $iq_content_site) {
if (isset($iq_content_site->travel_guide) && $iq_content_site->travel_guide->active) {
return $iq_content_site->travel_guide;
}
}
}
@ -122,6 +132,30 @@ class IQContentTreeNode extends Model
return $ret.$node_parent->identifier."/";
}
}
public static function getTreeNodeOptions($tree_id, $id = false, $html = true, $choose = true) {
$values = [];
$ret = "";
$models = IQContentTreeNode::where('tree_id', $tree_id)->where('active', 1)->get();
if($html) {
if($choose){
$ret .= '<option value="">Bitte wählen</option>\n';
}
foreach ($models as $model) {
$attr = ($model->id == $id) ? ' selected="selected"' : '';
$ret .= '<option value="' . $model->id . '"' . $attr . '>' . $model->name . '</option>\n';
}
return $ret;
}else{
foreach ($models as $model) {
$values[$model->id] = $model->name;
}
return $values;
}
return false;
}
//
}

View file

@ -31,7 +31,13 @@ class TravelCountry extends Model
protected $fillable = [
'name',
'is_customer_country',
'active_backend'
'active_backend',
'contact_headline',
'contact_text_1',
'contact_text_2',
'contact_text_3',
'contact_text_4',
'contact_footer',
];

View file

@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
/**
* App\Models\TravelCountry
@ -47,7 +48,16 @@ class TravelCountry extends Model
protected $fillable = [
'name',
'slug',
'html_information',
'text_before',
'text_after',
'contact_headline',
'contact_text_1',
'contact_text_2',
'contact_text_3',
'contact_text_4',
'contact_footer',
'entry_requirements',
'is_customer_country',
'active_frontend',
@ -72,6 +82,13 @@ class TravelCountry extends Model
return $this->hasMany('App\Models\TravelNationalityRequirement', 'travel_country_id', 'id');
}
public function setSlugAttribute( $value ) {
if(!isset($value) || $value == ""){
$this->attributes['slug'] = Str::slug(pre_slug($this->name), '-');
}else{
$this->attributes['slug'] = Str::slug(pre_slug($value), '-');
}
}
public function getNationalityRequirement($travel_nationality_id){

View file

@ -39,6 +39,14 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide query()
* @property string|null $keyword
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentSite[] $iq_content_site
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereKeyword($value)
* @property int|null $country_id
* @property string|null $box_image_url
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentSite[] $iq_content_sites
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereBoxImageUrl($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\TravelGuide whereCountryId($value)
*/
class TravelGuide extends Model
{
@ -58,7 +66,7 @@ class TravelGuide extends Model
];
protected $fillable = [
'tree_node_id', 'name', 'slug', 'text', 'full_text', 'keyword', 'meta_title', 'meta_description', 'meta_keywords', 'pos', 'scope', 'active',
'name', 'slug', 'text', 'full_text', 'keyword', 'meta_title', 'meta_description', 'meta_keywords', 'country_id', 'box_image_url', 'pos', 'scope', 'active',
];
@ -72,9 +80,18 @@ class TravelGuide extends Model
}
public function iq_content_tree_node()
public function iq_content_sites()
{
return $this->belongsTo('App\Models\IQContentTreeNode', 'tree_node_id');
return $this->hasMany('App\Models\IQContentSite', 'travel_guide_id', 'id');
}
public function iq_content_tree_node_first()
{
foreach ($this->iq_content_sites as $iq_content_site) {
if (isset($iq_content_site->iq_content_tree_node) && $iq_content_site->iq_content_tree_node->active) {
return $iq_content_site->iq_content_tree_node;
}
}
}

View file

@ -429,6 +429,12 @@ class TravelUserBookingFewo extends Model
return isset($this->attributes['price_total']) ? $this->attributes['price_total'] : 0;
}
public function calculate_price(){
$this->attributes['price_travel_total'] = $this->getPriceTravelRaw() + $this->getPriceBalanceRaw() + $this->getPriceExtraRaw();
$this->attributes['price_total'] = $this->getPriceTravelTotalRaw() + $this->getPriceServiceRaw() + $this->getPriceDepositRaw();
}
public function getPriceTravelTotalFirstPay(){
if($this->attributes['price_travel'] == 0){
return 0;
@ -469,6 +475,10 @@ class TravelUserBookingFewo extends Model
}
public function getLastChangeAt(){
if(!isset($this->attributes['last_change_at']) || !$this->attributes['last_change_at']){ return ""; }
return Carbon::parse($this->attributes['last_change_at'])->format("H:i d.m.Y");
}
public function getBookingDateYear(){
return Carbon::parse($this->booking_date)->format('Y');
@ -530,7 +540,19 @@ class TravelUserBookingFewo extends Model
return false;
}
//get TravelInfos Name / Paths / ...
public function isChangeLowerInvoiceCreate(){
$dir = $this->getBookingDateYear()."/";
$filename = $this->getInvoiceFileName();
if(Storage::disk('fewo_invoices')->exists( $dir.$filename )){
return Carbon::createFromTimestamp(Storage::disk('fewo_invoices')->lastModified($dir.$filename))->gt($this->last_change_at);
}
return false;
}
//get TravelInfos Name / Paths / ...
public function getTravelInfoFileName(){
if($this->invoice_number) {
return "Anreiseinfo-".Util::sanitize($this->invoice_number).".pdf";
@ -581,7 +603,15 @@ class TravelUserBookingFewo extends Model
$filename = $this->getTravelInfoFileName();
if(Storage::disk('fewo_infos')->exists( $dir.$filename )){
return Carbon::createFromTimestamp(Storage::disk('fewo_infos')->lastModified($dir.$filename))->format("H:i d.m.Y");
}
return false;
}
public function isChangeLowerTravelInfoCreate(){
$dir = $this->getBookingDateYear()."/";
$filename = $this->getTravelInfoFileName();
if(Storage::disk('fewo_invoices')->exists( $dir.$filename )){
return Carbon::createFromTimestamp(Storage::disk('fewo_infos')->lastModified($dir.$filename))->gt($this->last_change_at);
}
return false;
}