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); // 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; // Releated Information Hide checker $this->hideReletad = $hideReletad; $this->hideReletadDocumentNumber = $hideReletadDocumentNumber; $this->hideReletadContact = $hideReletadContact; $this->hideReletadDocumentDate = $hideReletadDocumentDate; $this->hideReletadDocumentAmount = $hideReletadDocumentAmount; $this->hideReletadAmount = $hideReletadAmount; // Releated Information Text $this->textReleatedTransansaction = $this->getTextReleatedTransansaction($type, $textReleatedTransansaction); $this->textReleatedDocumentNumber = $this->getTextReleatedDocumentNumber($type, $textReleatedDocumentNumber); $this->textReleatedContact = $this->getTextReleatedContact($type, $textReleatedContact); $this->textReleatedDocumentDate = $this->getTextReleatedDocumentDate($type, $textReleatedDocumentDate); $this->textReleatedDocumentAmount = $this->getTextReleatedDocumentAmount($type, $textReleatedDocumentAmount); $this->textReleatedAmount = $this->getTextReleatedAmount($type, $textReleatedAmount); $this->routeDocumentShow = $this->routeDocumentShow($type, $routeDocumentShow); } 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 getTextReleatedTransansaction($type, $textReleatedTransansaction) { if (!empty($textReleatedTransansaction)) { return $textReleatedTransansaction; } 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 getTextReleatedDocumentNumber($type, $textReleatedDocumentNumber) { if (!empty($textReleatedDocumentNumber)) { return $textReleatedDocumentNumber; } $translation = $this->getTextFromConfig($type, 'related_document_number', 'numbers'); if (!empty($translation)) { return $translation; } return 'general.numbers'; } protected function getTextReleatedContact($type, $textReleatedContact) { if (!empty($textReleatedContact)) { return $textReleatedContact; } $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 getTextReleatedDocumentDate($type, $textReleatedDocumentDate) { if (!empty($textReleatedDocumentDate)) { return $textReleatedDocumentDate; } 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 getTextReleatedDocumentAmount($type, $textReleatedDocumentAmount) { if (!empty($textReleatedDocumentAmount)) { return $textReleatedDocumentAmount; } 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 getTextReleatedAmount($type, $textReleatedAmount) { if (!empty($textReleatedAmount)) { return $textReleatedAmount; } $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'; } }