type = $type; $this->transaction = $transaction; $this->logo = $this->getLogo($logo); $this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all'); // Company Information Hide checker $this->hideCompany = $hideCompany; $this->hideCompanyLogo = $hideCompanyLogo; $this->hideCompanyDetails = $hideCompanyDetails; $this->hideCompanyName = $hideCompanyName; $this->hideCompanyAddress = $hideCompanyAddress; $this->hideCompanyTaxNumber = $hideCompanyTaxNumber; $this->hideCompanyPhone = $hideCompanyPhone; $this->hideCompanyEmail = $hideCompanyEmail; // Transaction Information Hide checker $this->hideContentTitle = $hideContentTitle; $this->hidePaidAt = $hidePaidAt; $this->hideAccount = $hideAccount; $this->hideCategory = $hideCategory; $this->hidePaymentMethods = $hidePaymentMethods; $this->hideReference = $hideReference; $this->hideDescription = $hideDescription; $this->hideAmount = $hideAmount; // Transaction Information Text $this->textContentTitle = $this->getTextContentTitle($type, $textContentTitle); $this->textPaidAt = $this->getTextPaidAt($type, $textPaidAt); $this->textAccount = $this->getTextAccount($type, $textAccount); $this->textCategory = $this->getTextCategory($type, $textCategory); $this->textPaymentMethods = $this->getTextPaymentMethods($type, $textPaymentMethods); $this->textReference = $this->getTextReference($type, $textReference); $this->textDescription = $this->getTextDescription($type, $textDescription); $this->textAmount = $this->getTextAmount($type, $textAmount); $this->textPaidBy = $this->getTextPaidBy($type, $textPaidBy); $this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo); // Contact Information Hide checker $this->hideContact = $hideContact; $this->hideContactInfo = $hideContactInfo; $this->hideContactName = $hideContactName; $this->hideContactAddress = $hideContactAddress; $this->hideContactTaxNumber = $hideContactTaxNumber; $this->hideContactPhone = $hideContactPhone; $this->hideContactEmail = $hideContactEmail; // Related Information Hide checker $this->hideRelated = $hideRelated; $this->hideRelatedDocumentNumber = $hideRelatedDocumentNumber; $this->hideRelatedContact = $hideRelatedContact; $this->hideRelatedDocumentDate = $hideRelatedDocumentDate; $this->hideRelatedDocumentAmount = $hideRelatedDocumentAmount; $this->hideRelatedAmount = $hideRelatedAmount; // Related Information Text $this->textRelatedTransansaction = $this->getTextRelatedTransansaction($type, $textRelatedTransansaction); $this->textRelatedDocumentNumber = $this->getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber); $this->textRelatedContact = $this->getTextRelatedContact($type, $textRelatedContact); $this->textRelatedDocumentDate = $this->getTextRelatedDocumentDate($type, $textRelatedDocumentDate); $this->textRelatedDocumentAmount = $this->getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount); $this->textRelatedAmount = $this->getTextRelatedAmount($type, $textRelatedAmount); $this->routeDocumentShow = $this->routeDocumentShow($type, $routeDocumentShow); } protected function getTextContactInfo($type, $textContactInfo) { if (!empty($textContactInfo)) { return $textContactInfo; } switch ($type) { case 'bill': case 'expense': case 'purchase': $textContactInfo = 'bills.bill_from'; break; default: $textContactInfo = 'invoices.bill_to'; break; } return $textContactInfo; } protected function getLogo($logo) { if (!empty($logo)) { return $logo; } $media_id = (!empty($this->transaction->contact->logo) && !empty($this->transaction->contact->logo->id)) ? $this->transaction->contact->logo->id : setting('company.logo'); $media = Media::find($media_id); if (!empty($media)) { $path = $media->getDiskPath(); if (Storage::missing($path)) { return $logo; } } else { $path = base_path('public/img/company.png'); } try { $image = Image::cache(function($image) use ($media, $path) { $width = setting('invoice.logo_size_width'); $height = setting('invoice.logo_size_height'); if ($media) { $image->make(Storage::get($path))->resize($width, $height)->encode(); } else { $image->make($path)->resize($width, $height)->encode(); } }); } catch (NotReadableException | \Exception $e) { Log::info('Company ID: ' . company_id() . ' components/transactionshow.php exception.'); Log::info($e->getMessage()); $path = base_path('public/img/company.png'); $image = Image::cache(function($image) use ($path) { $width = setting('invoice.logo_size_width'); $height = setting('invoice.logo_size_height'); $image->make($path)->resize($width, $height)->encode(); }); } if (empty($image)) { return $logo; } $extension = File::extension($path); return 'data:image/' . $extension . ';base64,' . base64_encode($image); } protected function getTextContentTitle($type, $textContentTitle) { if (!empty($textContentTitle)) { return $textContentTitle; } switch ($type) { case 'bill': case 'expense': case 'purchase': $default_key = 'payment_made'; break; default: $default_key = 'revenue_received'; break; } $translation = $this->getTextFromConfig($type, $type . '_made', $default_key); if (!empty($translation)) { return $translation; } return 'revenues.revenue_received'; } protected function getTextPaidAt($type, $textPaidAt) { if (!empty($textPaidAt)) { return $textPaidAt; } $translation = $this->getTextFromConfig($type, 'paid_at', 'date'); if (!empty($translation)) { return $translation; } return 'general.date'; } protected function getTextAccount($type, $textAccount) { if (!empty($textAccount)) { return $textAccount; } $translation = $this->getTextFromConfig($type, 'accounts', 'accounts', 'trans_choice'); if (!empty($translation)) { return $translation; } return 'general.accounts'; } protected function getTextCategory($type, $textCategory) { if (!empty($textCategory)) { return $textCategory; } $translation = $this->getTextFromConfig($type, 'categories', 'categories', 'trans_choice'); if (!empty($translation)) { return $translation; } return 'general.categories'; } protected function getTextPaymentMethods($type, $textPaymentMethods) { if (!empty($textPaymentMethods)) { return $textPaymentMethods; } $translation = $this->getTextFromConfig($type, 'payment_methods', 'payment_methods', 'trans_choice'); if (!empty($translation)) { return $translation; } return 'general.payment_methods'; } protected function getTextReference($type, $textReference) { if (!empty($textReference)) { return $textReference; } $translation = $this->getTextFromConfig($type, 'reference', 'reference'); if (!empty($translation)) { return $translation; } return 'general.reference'; } protected function getTextDescription($type, $textDescription) { if (!empty($textDescription)) { return $textDescription; } $translation = $this->getTextFromConfig($type, 'description', 'description'); if (!empty($translation)) { return $translation; } return 'general.description'; } protected function getTextAmount($type, $textAmount) { if (!empty($textAmount)) { return $textAmount; } $translation = $this->getTextFromConfig($type, 'amount', 'amount'); if (!empty($translation)) { return $translation; } return 'general.amount'; } protected function getTextPaidBy($type, $textPaidBy) { if (!empty($textPaidBy)) { return $textPaidBy; } switch ($type) { case 'bill': case 'expense': case 'purchase': $default_key = 'paid_to'; break; default: $default_key = 'paid_by'; break; } $translation = $this->getTextFromConfig($type, 'paid_to_by', $default_key); if (!empty($translation)) { return $translation; } return 'revenues.paid_by'; } protected function getTextRelatedTransansaction($type, $textRelatedTransansaction) { if (!empty($textRelatedTransansaction)) { return $textRelatedTransansaction; } switch ($type) { case 'bill': case 'expense': case 'purchase': $default_key = 'related_bill'; break; default: $default_key = 'related_invoice'; break; } $translation = $this->getTextFromConfig($type, 'related_type', $default_key); if (!empty($translation)) { return $translation; } return 'revenues.related_invoice'; } protected function getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber) { if (!empty($textRelatedDocumentNumber)) { return $textRelatedDocumentNumber; } $translation = $this->getTextFromConfig($type, 'related_document_number', 'numbers'); if (!empty($translation)) { return $translation; } return 'general.numbers'; } protected function getTextRelatedContact($type, $textRelatedContact) { if (!empty($textRelatedContact)) { return $textRelatedContact; } $default_key = Str::plural(config('type.' . $type . '.contact_type'), 2); $translation = $this->getTextFromConfig($type, 'related_contact', $default_key, 'trans_choice'); if (!empty($translation)) { return $translation; } return 'general.customers'; } protected function getTextRelatedDocumentDate($type, $textRelatedDocumentDate) { if (!empty($textRelatedDocumentDate)) { return $textRelatedDocumentDate; } switch ($type) { case 'bill': case 'expense': case 'purchase': $default_key = 'bill_date'; break; default: $default_key = 'invoice_date'; break; } $translation = $this->getTextFromConfig($type, 'related_document_date', $default_key); if (!empty($translation)) { return $translation; } return 'invoices.invoice_date'; } protected function getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount) { if (!empty($textRelatedDocumentAmount)) { return $textRelatedDocumentAmount; } switch ($type) { case 'bill': case 'expense': case 'purchase': $default_key = 'bill_amount'; break; default: $default_key = 'invoice_amount'; break; } $translation = $this->getTextFromConfig($type, 'related_document_amount', $default_key); if (!empty($translation)) { return $translation; } return 'general.amount'; } protected function getTextRelatedAmount($type, $textRelatedAmount) { if (!empty($textRelatedAmount)) { return $textRelatedAmount; } $translation = $this->getTextFromConfig($type, 'related_amount', 'amount'); if (!empty($translation)) { return $translation; } return 'general.amount'; } protected function routeDocumentShow($type, $routeDocumentShow) { if (!empty($routeDocumentShow)) { return $routeDocumentShow; } if (!$this->transaction->document) { return $routeDocumentShow; } //example route parameter. $parameter = 1; $route = $this->getRouteFromConfig($this->transaction->document->type, 'show', $parameter); if (!empty($route)) { return $route; } return 'invoices.show'; } }