File: /var/www/vhosts/creativefellows.nl/jhtaxatie.creativefellows.nl/classes/RequestTruckData.php
<?php
class RequestTruckData
{
protected $html;
protected $url;
protected $catalog;
//protected $price = 0;
protected $gg_factor = 1.1;
protected $new_battery = false;
protected $client = [];
protected $sale = 0;
protected $patch = false;
protected $role = 0;
protected $data_range_good2go = "2-4 weken";
protected $price = 0;
protected $version = [];
protected $star_table = [
0 => ["Sterren","Garantie","Levertijd","Accu"],
5 => ["HHHHH","12 maanden","in overleg","REFIT"],
4 => ["HHHH","6 maanden", "8-10 weken","70-80%"],
3 => ["HHH","3 maanden","6-8 weken","Huidig"],
];
protected $star_pricing = [];
protected $stars_selected = [5,4,3];
protected $stars = [5];
protected $sum_selected_options = 0;
protected $custom_options = [];
protected $truck_price_custom = 1;
protected $custom_star_pricing = [];
protected $type = "Jungheinrich";
protected $description = "Heftruck";
protected $has_custom_price = false;
protected $liIonBattery = false;
protected $district = [0 => "-",1=> "NW",2=> "NO", 3 => "ZO",4 => "ZW", 5 => "InSa",6 => "KAM"];
public function __construct(array $data = [])
{
$this->star_factors = [];
foreach($data as $el =>$val){
$this->$el = $val;
}
$this->setSale();
$this->setBatteryType();
}
public function setSale($force_sale = false)
{
if($this->priceOffer() != 0 || $force_sale === true) $this->sale = 1;
}
public function setBatteryType()
{
if(preg_match("/li/i", $this->type())){
$this->liIonBattery = true;
}
}
public function setStarLabels(array $labels = [])
{
$this->star_table[5][2] = $labels["delivery_5star"];
$this->star_table[4][2] = $labels["delivery_4star"];
$this->star_table[3][2] = $labels["delivery_3star"];
}
public function sale()
{
return $this->sale;
}
public function relevance()
{
return $this->relevance;
}
public function patch($set_value = null)
{
if($set_value != null) $this->patch = $set_value;
return $this->patch;
}
public function hasCustomPrice($set_value = null)
{
if($set_value != null) $this->has_custom_price = $set_value;
return $this->has_custom_price;
}
public function district()
{
return $this->district[$this->client["user_district"]];
}
public function setClientData(array $data)
{
$this->client["company_name"] = $data["company_name"];
$this->client["stars"] = $data["stars"];
$this->client["options"] = $data["options"];
$this->client["date"] = $data["date"];
$this->client["user_full_name"] = $data["full_name"];
$this->client["request_id"] = $data["request_id"];
$this->client["options_custom"] = $this->setCustomOptions($data["options_custom"]);
$this->client["price_correction_factor"]= $data["price_correction_factor"];
$this->client["status"] = $data["status"];
$this->client["serial_number"] = $data["serial_number"];
$this->client["user_district"] = $data["district"];
$this->client["service_options"] = $data["service"] == "" ? [] : explode(",",$data["service"]);
if($data["custom"] == 1){
$this->price = $data["price"];
}
$this->custom_star_pricing = [];
if($data["custom_price_3"]) $this->custom_star_pricing[3] = ["excl" => $data["custom_price_3"]];
if($data["custom_price_4"]) $this->custom_star_pricing[4] = ["excl" => $data["custom_price_4"]];
if($data["custom_price_5"]) $this->custom_star_pricing[5] = ["excl" => $data["custom_price_5"]];
$this->selectedCustomStarPrice($this->custom_star_pricing);
$this->custom = $data["custom"];
$this->archive = $data["archive"];
$options = $data["options"] == "" ? [] : explode(",",$data["options"]);
//$service_options = $data["service"] == "" ? [] : explode(",",$data["service"]);
$this->selectedOptions($options);//$this->client["options_custom"]
$this->setPriceCorrection($this->client["price_correction_factor"]);
}
public function customStarPricing()
{
return $this->custom_star_pricing;
}
public function customStarPrice(int $star)
{
return isset($this->custom_star_pricing[$star]["excl"]) ? $this->custom_star_pricing[$star]["excl"] : 0;
}
public function clientCompany()
{
return $this->client["company_name"];
}
public function clientStars($explode=false)
{
return $explode == false ? str_replace(",","/",$this->client["stars"]) : explode(",",$this->client["stars"]);
}
public function clientOptions($explode=false)
{
if($explode == true && $this->client["options"] == "" && empty($this->client["options_custom"]) ) return [];
/*if($explode){
//$test = array_merge( explode(",", $this->client["options"] ),$this->customOptions());
//d($test);
//d( array_filter( explode(",", $this->client["options"] )),"notnull");
d(array_filter(explode(",", $this->client["options"] ), fn($value) => !is_null($value) && $value !== ''));
die();
}*/
return $explode == false ? $this->client["options"] : array_filter(explode(",", $this->client["options"] ), fn($value) => !is_null($value) && $value !== '');
//return $explode == false ? $this->client["options"] : array_merge( array_filter(explode(",", $this->client["options"] ), fn($value) => !is_null($value) && $value !== '') ,$this->customOptions());
// return $explode == false ? $this->client["options"] : array_merge(array_filter( explode(",", $this->client["options"] )),$this->customOptions());
}
public function setCustomOptions($custom_options)
{
$data = explode(",",$custom_options);
$options = [];
foreach($data as $option)
{
if(empty($option)) continue;
$option_data = explode("|*|",$option);
$options[$option_data[0]] = $option_data[1];
}
return $options;
}
public function customOptions()
{
return $this->client["options_custom"];
}
public function clientDate()
{
return strftime("%d-%m-%Y",strtotime($this->client["date"]));
}
public function clientDateFull()
{
return strftime("%d-%m-%Y @ %H:%M",strtotime($this->client["date"]));
}
public function clientUserFullname()
{
return $this->client["user_full_name"];
}
public function userDistrict()
{
return $this->district[$this->client["user_district"]];
}
public function clientRequestId()
{
return $this->client["request_id"];
}
public function statusClass()
{
switch($this->client["status"])
{
case 0:
return "row__not-available";
break;
case 1:
return "";
break;
case 2:
return "row__sold";
break;
case 3:
return "row__strike";
break;
}
}
public function getAcronym($length=2)
{
$words = explode(" ", $this->clientCompany() );
$this->icon_color = preg_match("/anton/i", $this->type()) ? "icon__anton" : "";
if(count($words) == 1) return substr($this->clientCompany(),0,2);
$acronym = "";
for($i=0;$i<$length;$i++)
{
$acronym .= $words[$i][0];
}
return "aa";
}
public function getAcronymColor()
{
return $this->icon_color;
}
public function setViewUrl($url)
{
$this->view_url = $url;
}
public function viewUrl()
{
return $this->view_url;
}
public function setExcelUrl($url)
{
$this->excel_url = $url;
}
public function excelUrl()
{
return $this->excel_url;
}
public function setPdfUrl($url)
{
$this->pdf_url = $url;
}
public function pdfUrl()
{
return $this->pdf_url;
}
public function setEditUrl($url)
{
$this->edit_url = $url;
}
public function editUrl()
{
return $this->edit_url;
}
public function setArchiveUrl($url)
{
$this->archive_url = $url;
}
public function archiveUrl()
{
return $this->archive_url;
}
public function setApproveUrl($url)
{
$this->approve_url = $url;
}
public function approveUrl()
{
return $this->approve_url;
}
public function setResetStatusUrl($url)
{
$this->reset_status_url = $url;
}
public function resetStatusUrl($return=null)
{
return $this->reset_status_url.$return;
}
public function actionUrl()
{
// lost offer = 3
if($this->client["status"] == 3) return '<span class="approve-request approve-request__hidden"></span>';//'<a href="'. $this->approveUrl() .'" class="approve-request"><i class="fa fa-remove"></i></a>';
// winning offer = 2
elseif($this->client["status"] == 2) return '<a href="'. $this->resetStatusUrl() .'" class="approve-request secureDelete" data-msg="Weet je zeker dat je status van deze offerte wilt verwijderen?"><i class="fa fa-remove"></i></a>';
// active = 1
else return '<a href="'. $this->approveUrl() .'" class="approve-request"><i class="fa fa-check"></i></a>';
}
public function setPriceCorrection($price_correction_factor)
{
$this->truck_price_custom = 1 + $price_correction_factor;
}
public function selectedCustomStarPrice(array $custom_star_pricing = [])
{
$this->custom_star_pricing = $custom_star_pricing;
}
public function priceCorrection()
{
return $this->truck_price_custom;
}
public function pricingRange()
{
$this->setPricing();
$stars_selected = $this->clientStars(true);
if($stars_selected[0] == "") return $this->formatPrice(0);
$this->price_low = $this->priceTruckOptionsIncluded( reset($stars_selected),true);
$this->price_high = $this->priceTruckOptionsIncluded( end($stars_selected),true);
return $this->price_low != $this->price_high ? $this->formatPrice($this->price_low)." - ". $this->formatPrice($this->price_high) : $this->formatPrice($this->price_low);
}
public function setPricing(){
$stars_selected = $this->clientStars(true);
if($stars_selected[0] == "") return $this->formatPrice(0);
$this->price_low = $this->priceTruckOptionsIncluded( reset($stars_selected),true);
$this->price_high = $this->priceTruckOptionsIncluded( end($stars_selected),true);
}
public function priceLow()
{
$stars_selected = $this->clientStars(true);
if($stars_selected[0] == "") return $this->formatPrice(0);
$this->price_low = $this->priceTruckOptionsIncluded( reset($stars_selected),true);
$this->price_high = $this->priceTruckOptionsIncluded( end($stars_selected),true);
return $this->price_low;
}
public function priceHigh(){
$this->setPricing();
return $this->price_low != $this->price_high ? $this->price_high : "";
}
public function catalog()
{
return $this->catalog;
}
public function catalogId()
{
return $this->catalog->id();
}
public function catalogIdCustom()
{
return $this->catalog_id;
}
public function setCatalog($catalog=null)
{
$this->catalog = $catalog;
}
public function setFunctions(array $functions = [])
{
foreach($functions as $f)
{
if($f["abbr"] == "EA_BZ"){
$this->functions[] = ["abbr" => "EA_BZ", "label" => "Ontladingsmeter"];
$this->functions[] = ["abbr" => "EA_BZ1", "label" => "Urenteller"];
}
else $this->functions[] = $f;
}
}
public function functions()
{
return $this->functions;
}
public function functionsCustom()
{
$functions = '';
foreach($this->functions() as $function){
$functions .= $function["abbr"].",";
}
return $functions;
}
public function functionsList()
{
$data = [];
foreach($this->functions() as $function){
$data[] = $function["label"];
}
return implode("<br/>",$data);
}
public function functionsArray($header = "Extra functies")
{
$data = [[$header,""]];
$rows = 1;
$x = 0;
foreach($this->functions() as $i => $function){
if($x == 2) $x = 0;
$data[$rows][$x] = ucfirst($function["label"]);
if($x== 1)$rows++;
$x++;
}
if($x == 1) $data[$rows][$x] = " ";
return $data;
}
/* public function antonSpecsTable(){
return [
["Capaciteit (kg)",$this->traction(),"Vorklengte (mm)",$this->forkLength()],
["Hefhoogte (mm)",$this->liftHeight(),"Batterij (Ah)",$this->battery()],
["Bouwhoogte (mm)",$this->buildHeight(),"Lader (V)",$this->charger()]
];
}*/
public function typeShort($length=6)
{
if(preg_match("/anton/i", $this->type())) return substr($this->type(),0,12);
else return substr($this->type(),0,$length);
}
public function setStarsFactor($star_factors = [])
{
$this->star_factors = $star_factors;
$this->star_pricing = [
5 => ["label" => "5 sterren","value" => $this->priceTruck(5,true), "class" => "sum-row__5stars"],
4 => ["label" => "4 sterren","value" => $this->priceTruck(4,true), "class" => "sum-row__4stars"],
3 => ["label" => "3 sterren","value" => $this->priceTruck(3,true), "class" => "sum-row__3stars"],
];
}
public function getStarsFactor()
{
return $this->star_factors;
}
public function id()
{
return $this->stock_id;
}
public function setTruckVersions(array $versions = [])
{
$this->versions = $versions;
}
public function truckVersions()
{
return $this->versions;
}
public function getVersion($index = 0)
{
return $this->versions[$index];
}
public function type()
{
return $this->type;
}
public function description()
{
return $this->catalog()->description();
}
public function card()
{
$this->html .= '<div class="small-12 medium-3 columns truck-summary end">';
$this->html .= '<div class="truck-wrapper">';
$this->html .= '<div class="truck-image">
<img src="'. $this->image() .'" />
<div class="truck-label-wrapper">'. $this->label() .'</div>
</div>';
$this->html .= '<h4>'. $this->type() .'</h4>'; //
$this->html .= '<h5>'. $this->description() .'</h5>';
$this->html .= $this->features();
$this->html .= '<h6>' . $this->formatPrice( $this->priceTruck( $this->checkStarsStatus(true,""))) .'</h6>'; //'. $this->lowestStarPrice() .' of sql =
$this->html .= '<a href="'. $this->url() .'" class="button__hidden"></a>';
$this->html .= '<div class="button primary button__select">Selecteer</div>';
$this->html .= '</div>';
$this->html .= '</div>';
return $this->html;
}
public function features()
{
$list = '<ul class="no-bullet features-list">';
$list .= '<li class="serial">'. $this->serial_number .' </li>';
$list .= '<li class="built">'. $this->yearBuilt() .' </li>';
$list .= '<li class="hours">'. $this->truck_hours .'</li>';
if($this->new_truck == 0) $list .= '<li class="stars">'. $this->checkStarsStatus(true,"/") .'</li>';
$list .= '</ul>';
return $list;
}
/*public function starMinPrice()
{
$price = !$this->sale() ? $this->min_price : $this->priceOffer();
return $this->formatPrice($price);
}*/
public function propertylist()
{
$list = '<ul class="no-bullet table-list table-list__half table-list__half clearfix">';
$list .= '<li class="empty">Serienummer <span class="float-right" data-serialnumber>'. $this->serial() .'</span></li>';
$list .= '<li class="empty">Bouwjaar <span class="float-right" data-datebuild>'. $this->dateBuilt() .'</span></li>';
$list .= '<li class="empty">Capaciteit (kg) <span class="float-right" data-capacity>'. $this->traction() .'</span></li>';
$list .= '<li class="empty">Hefhoogte (mm) <span class="float-right" data-liftheight>'. $this->liftHeight() .'</span></li>';
$list .= '<li class="empty">Bouwhoogte (mm) <span class="float-right" data-buildheight>'. $this->buildHeight() .'</span></li>';
$list .= '<li class="empty">Vorklengte (mm) <span class="float-right" data-forklength>'. $this->forkLength() .'</span></li>';
$list .= '<li class="empty">Urenstand (uur) <span class="float-right" data-hours>'. $this->hours() .'</span></li>';
$list .= '<li class="empty">Batterij (aH) <span class="float-right" data-battery>'. $this->battery() .'</span></li>';
$list .= '<li class="empty">Lader (V) <span class="float-right" data-charger>'. $this->charger() .'</span></li>';
$list .= '</ul>';
return $list;
}
public function currentFunctionList()
{
$list = '<ul class="no-bullet table-list table-list__half clearfix">';
foreach($this->functions() as $i => $function)
{
$list .= '<li class="empty">'. ucfirst($function["label"]) .'</li>';
}
$list .= '</ul>';
return $list;
}
public function yearBuilt()
{
return strftime("%Y",strtotime($this->date_built));
}
public function usageStatus()
{
return $this->usage_status;
}
public function usageStatusSpecified()
{
return $this->usage_status_specified;
}
public function lowestStarPrice()
{
$price = $this->priceTruck( $this->lowestStar() );
return $this->formatPrice($price);
}
public function lowestStar()
{
return explode(",",$this->stars)[0];
}
public function checkStarsStatus($implode=false,$delimiter='')
{
$date_diff = date_diff(date_create($this->date_built), date_create());
$age_years = $date_diff->format('%y');
//echo ">>>". $this->usage_status_specified;
$stars = [4];
switch( $this->usageStatus() ){
default:
$stars = [4];
break;
case "OHNE":
/*if( $this->usage_status_specified === null)
{
if($age_years < 5) return [3,4,5];
else return [3,4];
}*/
if(in_array($this->usage_status_specified,["R2GO","TBR5","ZGGA"]) ){
$stars = [5];
}
elseif( in_array($this->usage_status_specified,["AUFG","R2G4","TBR4","ZGG4","WERK"]) ){
$stars = [4];
}
elseif( in_array($this->usage_status_specified,["NIAU","TBR3","G2GO","SWCO"]) ){
$stars = [3];
}
break;
case "WERK":
//if($age_years <= 4) return [3];
//else return [3,4];
$stars = [4];
break;
// case "NIAU":
// return [3];
// break;
case "ZGGA":
$stars = [5];
break;
case "ZGG4":
$stars = [4];
break;
}
return !$implode ? $stars : implode($delimiter,$stars);
}
public function image()
{
return $this->catalog()->image( $this->type() );
}
public function label()
{
$label = "";
if( $this->isNew() && !$this->isAntOn() ) $label .= '<span class="truck-label truck-label__background-red">Nieuwe truck</span>';
//elseif( $this->usageStatus() == "ZGGA" || $this->usageStatusSpecified() == "R2GO") $label .= '';//'<span class="truck-label truck-label__vrijfvoorvier">5 voor 4</span>';
elseif( $this->priceOffer() ) $label .= '<span class="truck-label">Aanbieding</span>';
if( $this->usageStatusSpecified() == "NIAU") $label .= '<span class="truck-label truck-label__good2go">Good 2 Go</span>';
if( $this->liIonBattery() ) $label .= '<span class="truck-label truck-label__li-ion">Li-ion</span>';
$label .= $this->hasAdditionalOfferLabel();
return $label;
//return $this->priceOffer() ? '<span class="truck-label">Aanbieding</span>' : '';
}
public function isAntOn()
{
return preg_match("/anton/i", $this->type()) ? true : false;
}
public function additionalCampaignId(){
return $this->add_campaign_id;
}
private function hasAdditionalOfferLabel(){
switch( $this->additionalCampaignId() )
{
case "ant-on":
$label = '<span class="truck-label truck-label__ant-on">Gratis PTL1.5</span>';
break;
}
return $label;
}
public function serial()
{
return $this->serial_number;
}
public function isNew()
{
return $this->new_truck == 1 ? true : false;
}
public function setCustomData($custom_data)
{
//d($custom_data);
$this->serial_number = $custom_data["serialnumber"];
$this->date_built = $custom_data["datebuild"];
$this->traction_kg = $custom_data["capacity"];
$this->lift_height_mm = $custom_data["liftheight"];
$this->build_height_mm = $custom_data["buildheight"];
$this->fork_length_mm = $custom_data["forklength"];
$this->truck_hours = $custom_data["hours"];
$this->battery_capacity_ah = $custom_data["battery"];
$this->battery_voltage = $custom_data["charger"];
$this->type = $custom_data["description"];
$this->catalog_id = $custom_data["catalog_id"];
}
public function customRequest()
{
return $this->id() == null ? false : true;
}
public function dateBuilt()
{
return $this->date_built ? strftime("%Y",strtotime($this->date_built."-01-01")) : "";
}
public function traction()
{
return $this->traction_kg;
}
public function liftHeight()
{
return $this->lift_height_mm;
}
public function buildHeight()
{
return $this->build_height_mm;
}
public function forkLength()
{
return $this->fork_length_mm;
}
public function hours()
{
return $this->truck_hours;
}
public function battery()
{
return $this->battery_capacity_ah;
}
public function charger()
{
return $this->battery_voltage;
}
public function setUrl($url)
{
$this->url = $url;
}
public function url()
{
return $this->url;
}
public function setPrice(int $price = 0)
{
return $this->price = $price;
}
public function price()
{
return $this->price;//* $this->gg_factor;//$this->priceOffer() ? $this->priceOffer() : $this->price * $this->gg_factor;
}
public function priceOffer()
{
return $this->price_offer;
}
public function setGGfactor(int $factor = 1)
{
$this->gg_factor = $factor;
}
public function stars()
{
return str_replace(",","/",$this->stars);
}
public function priceHuman()
{
return $this->formatPrice($this->price());
}
public function formatPrice($price)
{
return number_format($price,2,',','.');
}
public function transport()
{
return $this->catalog()->transport();
}
public function pricing($label = "Meerprijs opties"){
return [
"options_price" => ["label" => $label,"value" => $this->sumSelectedOptions(), "class" => "sum-row__options"],
"truck_total" => [
"label" => "Totaalprijs",
"value" => $this->priceTruck(5),
"class" => "sum-row__total",
"stars" => $this->starPricing(),
"custom_price" => $this->custom_star_pricing,
],
"transport_price" => ["label" => "Afleverkosten","value" => $this->transport(), "class" => "sum-row__transport"],
"truck_version" => []
];
}
public function unsetStar(int $key)
{
unset( $this->star_pricing[$key]);
}
private function starPricing()
{
//d($this->star_pricing);
foreach($this->star_pricing as $star => $data)
{
if(!in_array($star,$this->stars_selected)) unset($this->star_pricing[$star]);
}
return $this->star_pricing;
}
private function starFactor(int $index)
{
return $this->star_factors[$index];
}
public function priceTruck(int $stars,$include_transport=false)
{
// truck has sale price and no custom
if($this->sale() && empty($this->custom_star_pricing[$stars])) $price = $this->priceOffer();
// custom price
elseif(!empty($this->custom_star_pricing[$stars]))
{
$price = $this->custom_star_pricing[$stars]["excl"];
}
else
{
$price = $this->truckStarFactorPrice($stars);
}
//$price = !$this->sale() ? $this->truckStarFactorPrice($stars) : $this->priceOffer();
return $this->roundPrice($price * $this->priceCorrection(),5);
}
private function roundPrice($price,$stepping=1)
{
$inv = 1 / $stepping;
$factored_half = round($price * $inv) / $inv;
return round($factored_half * 100) / 100;
}
private function truckStarFactorPrice(int $stars){
//echo $this->price()." - ";
$price_regular = $this->price() * $this->starFactor($stars);
$price_custom = $this->custom_star_pricing[$stars]["excl"];
return (!empty($this->custom_star_pricing[$stars]) && $this->custom_star_pricing[$stars] != 0 ) ? $price_custom : $price_regular;
}
public function basePrice()
{
return $this->sale() ? $this->priceOffer() : $this->price();
}
public function priceTruckOptionsIncluded(int $stars,$include_transport=false)
{
return $this->priceTruck($stars,$include_transport) + $this->sum_selected_options;
}
public function versionsToOptions(){
//d($this->truckVersions());
$data = [];
foreach($this->truckVersions() as $truck_version){
//if(!$truck_version["fork_adjuster"]) continue;
$data[] = [
"label" => "Vorkversteller",
"value" => $truck_version["fork_adjuster"],
"version_id" => $truck_version["version_id"],
];
}
return $data;
}
public function options()
{
$options = $this->catalog()->listOptions();
$functions = $this->listFunctions();
foreach($options as $i => $option)
{
if(in_array($option["transform"],$functions)) unset($options[$i]);
elseif( isset($option["li-ion"]) && $option["li-ion"] === true && preg_match("/li/i", $this->type()) ){
unset($options[$i]);
//$this->setLiionBattery(true);
}
}
foreach($this->custom_options as $custom_option)
{
$options[] = $custom_option;
}
return $options;
}
public function serviceOptions()
{
return $this->catalog()->listServiceOptions();
}
public function selectedServiceOptions(array $options = [],array $custom_options = [])
{
$selected = [];
foreach($this->catalog()->listServiceOptions() as $key => $option)
{
if( in_array($key,$this->client["service_options"])){
$selected[] = $option;
}
}
return $selected;
}
public function liIonBattery()
{
return $this->liIonBattery;
}
public function optionsSelected()
{
// all options
$options = $this->catalog()->listOptions();
$functions = $this->listFunctions();
$this->sum_selected_options = 0;
$selected_options = $this->clientOptions(true);
//d($selected_options); // 4,6,8,11
foreach($options as $i => $option)
{
// option already on truck
if(in_array($option["transform"],$functions)) unset($options[$i]);
elseif( isset($option["li-ion"]) && $option["li-ion"] === true && preg_match("/li/i", $this->type()) ){
unset($options[$i]);
//$this->setLiIonBattery(true);
}
if( in_array($i,$selected_options)){
//echo "checked";
$options[$i]["checked"] = true;
$this->sum_selected_options += $option["value"];
}
}
foreach($this->customOptions() as $label => $price)
{
$this->sum_selected_options += $price;
$custom_option = [
"label" => $label,
"value" => floatval($price),
"transform" => "",
"battery" => false,
"custom" => true,
"checked" => true,
];
$options[] = $custom_option;
}
return $options;
}
public function serviceOptionsSelected(){
$options = $this->catalog()->listServiceOptions();
foreach($options as $i => $option)
{
if( in_array($i,$this->client["service_options"])){
$options[$i]["checked"] = true;
}
}
return $options;
}
public function optionKeys(array $options = [])
{
$keys = [];
foreach($options as $key => $option){
$keys[] = $key;
}
return $keys;
}
public function listFunctions()
{
$functions = [];
foreach($this->functions() as $function){
$functions[] = $function["abbr"];
}
return $functions;
}
public function selectedOptions(array $options = [],array $custom_options = [])
{
//d($options);
$selected = [];
$this->sum_selected_options = 0;
//'d($this->options() );
foreach( $this->options() as $key => $option)
{
if(in_array($key,$options))
{
$selected[] = $option;
$this->sum_selected_options += $option["value"];
// set new battery is true
if($option["battery"] === true) $this->new_battery = true;
}
}
//d($selected);
foreach($custom_options as $label => $price)
{
if($label == "" || $price == "") continue;
$this->sum_selected_options += $price;
$custom_option = [
"label" => $label,
"value" => floatval($price),
"transform" => "",
"battery" => false,
"custom" => true,
];
$this->custom_options[] = $custom_option;
$selected[] = $custom_option;
}
return $selected;
}
public function batteryStatusLabel(int $star_id,$label)
{
return $label;
}
public function sumSelectedOptions()
{
return $this->sum_selected_options;
}
public function setStarString($star_string = "")
{
$this->stars = $star_string;
}
public function setStars(array $stars_selected = [])
{
$this->stars_selected = $stars_selected;
$this->star_pricing = [
5 => ["label" => "5 sterren","value" => $this->priceTruck(5,true), "class" => "sum-row__5stars"],
4 => ["label" => "4 sterren","value" => $this->priceTruck(4,true), "class" => "sum-row__4stars"],
3 => ["label" => "3 sterren","value" => $this->priceTruck(3,true), "class" => "sum-row__3stars"],
];
}
public function starTable(){
foreach($this->star_table as $key => $value)
{
if(!in_array($key,$this->stars_selected) && $key !== 0) unset($this->star_table[$key]);
}
return $this->star_table;
}
public function starsSelected()
{
$selected_stars = $this->starTable();
unset($selected_stars[0]);
return $selected_stars;
}
public function deliveryTime($data_range){
return $this->usageStatusSpecified() != "NIAU" ? $data_range : $this->data_range_good2go;
}
public function setVersion(array $version = [])
{
$this->version = $version;
$this->catalog->setImage( $version["image"] );
}
public function detailsPageNo()
{
return $this->version["pdf_page"];
}
public function version($array_key = null)
{
return !$array_key ? $this->version : $this->version[$array_key];
}
public function versionOptions()
{
return array_map('trim', explode(',', $this->version("options")));
}
public function truckOptions()
{
$abbrs = explode(",",trim($this->truck_options));
$options = [];
foreach($abbrs as $abbr)
{
if($abbr == "") continue;
$options[] = trim($abbr);
}
return $options;
}
private function inArchice()
{
return $this->archive == 1 ? true : false;
}
public function setUserRole($role=0)
{
$this->role = $role;
}
public function pdfIntro(){
return $this->catalog->intro();
}
public function actions(){
$html = "";
switch($this->role){
default:
// do not edit custom requests
if( !$this->isAntOn() )
$html .= '<a href="'. $this->editUrl() .'"><i class="fa fa-pencil" aria-hidden="true" style="margin-right:0.375rem"></i></a>';
$html .= '<a href="'. $this->pdfUrl() .'" target="_blank"><i class="fa fa-file-pdf-o" aria-hidden="true" style="margin-right:0.375rem"></i></a>';
if( !$this->isAntOn() )
$html .= '<a href="'. $this->excelUrl() .'" target="_blank"><i class="fa fa-file-excel-o" aria-hidden="true" style="margin-right:0.375rem"></i></a>';
if( !$this->inArchice() ) $html .= '<a href="'. $this->archiveUrl() .'" class="secureDelete" data-msg="Weet je zeker dat je dit item wilt archiveren? Hierna kunnen geen wijzigingen meer worden aangebracht."><i class="fa fa-folder-o" aria-hidden="true"></i></a>';
if( $this->inArchice()) $html .= '<a href="'. $this->resetStatusUrl("?r=request.list.archive") .'" class="secureDelete" data-msg="Weet je zeker dat je status van deze offerte wilt verwijderen?"><i class="fa fa-undo"></i></a>';
break;
case 2:
//case 14:
case 19:
$html .= '<a href="'. $this->pdfUrl() .'" target="_blank"><i class="fa fa-file-pdf-o" aria-hidden="true" style="margin-right:0.375rem"></i></a>';
$html .= '<a href="'. $this->excelUrl() .'" target="_blank"><i class="fa fa-file-excel-o" aria-hidden="true" style="margin-right:0.375rem"></i></a>';
break;
};
return $html;
}
public function rentPricing()
{
return $this->catalog()->rentPricing();
}
}