File: /var/www/vhosts/creativefellows.nl/jhtaxatie.creativefellows.nl/classes/InspectionEntity.php
<?php
class InspectionEntity
{
public function __construct(array $data) {
foreach($data as $el =>$val){
$this->$el = $val;
}
}
public function getpdfName()
{
return "Keuringsformulier ". $this->pdfBaseName();
}
public function pdfBaseName()
{
return $this->getCompany() ." ". $this->getCity() ." ". $this->getDate() .".pdf";
}
public function JhInspectionNumber()
{
return $this->jh_inspection_no;
}
public function getHash()
{
return md5( $this->getId() );
}
public function getId() {
return $this->inspection_id;
}
public function workingHours()
{
$data = [];
$days = explode("|*|",$this->working_hours);
foreach($days as $day)
{
$parts = explode("|=|",$day);
$day_data = [
"inspector" => ($parts[0] && $parts[0] != "" ? $parts[0] : null),
"date" => $parts[1] ?? date("d-m-Y"),
"drive" => $parts[2] ?? null,
"hours" => $parts[3] ?? null,
];
$data[] = $day_data;
}
return $data;
}
public function signRemarks(){
return $this->sign_remarks;
}
public function getInspectorname(){
return $this->signature_inspector_name;
}
public function getUserName()
{
return $this->signature_user_name;
}
public function getSecondaryFieldTruck()
{
return $this->getAddress();
}
public function getSignature($type)
{
switch($type){
default:
return base64_decode($this->signature_inspector);
break;
case "user":
return base64_decode($this->signature_user);
break;
}
}
public function getCompany()
{
return $this->company_name;
}
public function getType()
{
return $this->rack_area;
}
public function getCity()
{
return $this->company_city;
}
public function getAddress()
{
return $this->company_address;
}
public function getZipcode()
{
return $this->company_zip;
}
public function getPhone()
{
return $this->company_phone;
}
public function getContact()
{
return $this->company_contact_lastname;
}
public function getSalutation()
{
return strtolower($this->company_contact_salutation);
}
public function getInitials()
{
return $this->company_contact_initials;
}
public function getLastname()
{
return $this->company_contact_lastname;
}
public function getEmail()
{
return $this->company_contact_email;
}
public function getFullName()
{
return $this->getInitials()." ".$this->getLastname();
}
public function contactFullname()
{
return $this->getSalutation()." ". $this->getFullName();
}
public function racks()
{
return $this->racks;
}
public function countRacks()
{
return count($this->racks);
}
public function countStickers()
{
$stickerCount = 0;
foreach($this->racks() as $rack){
$rackstickers = explode(",",$rack->getStickerNumber());
$stickerCount += count($rackstickers);
}
return $stickerCount;
}
public function getDate() {
return strftime("%d-%m-%Y", strtotime($this->date));
}
public function getAcronym($length=2)
{
$words = explode(" ", $this->company_name);
if(count($words) == 1) return substr($this->company_name,0,2);
$acronym = "";
for($i=0;$i<$length;$i++)
{
$acronym .= $words[$i][0];
}
return $acronym;
}
public function getStatus()
{
return $this->status;
}
public function getTaxationStatusName()
{
switch($this->status){
case 1:
return "rapport";
break;
case 2:
return "concept";
break;
case 3:
return "afgehandeld";
break;
}
}
public function getUserId()
{
return $this->user_id;
}
public function dateSigned()
{
return $this->date_signed ? strftime("%d-%m-%Y", strtotime($this->date_signed)) : date("d-m-Y");
}
public function validUrl($url)
{
$replace_chars = array('Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E',
'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U',
'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o',
'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y',
"?" => " ","!" => " ","(" => " ",")" => " ","." => ""
);
$valid = strtr( $url, $replace_chars );
return preg_replace("/[-]+/","-",preg_replace("/[^0-9a-zA-Z-#]/",'-', trim($valid)));
}
public function getLink(){
return $this->validUrl($this->getCompany());
}
public function getElementValue($element_name,$input_type,$array_values=null)
{
switch($input_type)
{
case "select":
case "select_not_required":
return $array_values[$this->$element_name];
break;
case "price":
return "€ ".number_format($this->$element_name, 2,',','.');//money_format('€ .2n', $this->$element_name);
break;
case "switch":
return $this->$element_name == "1" ? "ja" : "nee";
break;
case "calendar":
return strftime("%d-%m-%Y",strtotime($this->$element_name));
break;
case "upload":
foreach($this->$element_name as $img){
$data .= '<a href="/upload/'. $img["img_name"] .'" target="_blank" class="image-upload" />'. $img["org_name"] .'</a>';
};
return $data;
break;
default:
return $this->$element_name;
break;
}
}
public function isActive()
{
return $this->getStatus() == 1 ? true : false;
}
public function driveUpTotal()
{
$drive_count = 0;
foreach($this->workingHours() as $row){
if($row["drive"] == 1) $drive_count++;
}
return $drive_count;
}
public function workingHoursTotal()
{
$working_hours = 0;
foreach($this->workingHours() as $row){
$working_hours += floatval($row["hours"]);
}
return $working_hours;
}
}