Fixes for encoding
This commit is contained in:
parent
5b3155ea9e
commit
7fd7c0b24d
|
|
@ -21,6 +21,7 @@ use App\Utils\Ninja;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
use League\Csv\Writer;
|
use League\Csv\Writer;
|
||||||
|
use App\Models\Product;
|
||||||
|
|
||||||
class InvoiceItemExport extends BaseExport
|
class InvoiceItemExport extends BaseExport
|
||||||
{
|
{
|
||||||
|
|
@ -171,12 +172,13 @@ class InvoiceItemExport extends BaseExport
|
||||||
$tmp_key = str_replace("item.", "", $key);
|
$tmp_key = str_replace("item.", "", $key);
|
||||||
|
|
||||||
if ($tmp_key == 'tax_id') {
|
if ($tmp_key == 'tax_id') {
|
||||||
$tmp_key = 'tax_category';
|
// $tmp_key = 'tax_category';
|
||||||
|
$item_array[$key] = $this->getTaxCategoryName((int)$item->tax_id);
|
||||||
}
|
}
|
||||||
|
elseif (property_exists($item, $tmp_key)) {
|
||||||
if (property_exists($item, $tmp_key)) {
|
|
||||||
$item_array[$key] = $item->{$tmp_key};
|
$item_array[$key] = $item->{$tmp_key};
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$item_array[$key] = '';
|
$item_array[$key] = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -192,6 +194,22 @@ class InvoiceItemExport extends BaseExport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getTaxCategoryName($tax_id)
|
||||||
|
{
|
||||||
|
return match ($tax_id) {
|
||||||
|
Product::PRODUCT_TYPE_PHYSICAL => ctrans('texts.physical_goods'),
|
||||||
|
Product::PRODUCT_TYPE_SERVICE => ctrans('texts.services'),
|
||||||
|
Product::PRODUCT_TYPE_DIGITAL => ctrans('texts.digital_products'),
|
||||||
|
Product::PRODUCT_TYPE_SHIPPING => ctrans('texts.shipping'),
|
||||||
|
Product::PRODUCT_TYPE_EXEMPT => ctrans('texts.tax_exempt'),
|
||||||
|
Product::PRODUCT_TYPE_REDUCED_TAX => ctrans('texts.reduced_tax'),
|
||||||
|
Product::PRODUCT_TYPE_OVERRIDE_TAX => ctrans('texts.override_tax'),
|
||||||
|
Product::PRODUCT_TYPE_ZERO_RATED => ctrans('texts.zero_rated'),
|
||||||
|
Product::PRODUCT_TYPE_REVERSE_TAX => ctrans('texts.reverse_tax'),
|
||||||
|
default => 'Unknown',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private function buildRow(Invoice $invoice): array
|
private function buildRow(Invoice $invoice): array
|
||||||
{
|
{
|
||||||
$transformed_invoice = $this->invoice_transformer->transform($invoice);
|
$transformed_invoice = $this->invoice_transformer->transform($invoice);
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,18 @@ class GmailTransport extends AbstractTransport
|
||||||
$message = MessageConverter::toEmail($message->getOriginalMessage()); //@phpstan-ignore-line
|
$message = MessageConverter::toEmail($message->getOriginalMessage()); //@phpstan-ignore-line
|
||||||
|
|
||||||
//ensure utf-8 encoding of subject
|
//ensure utf-8 encoding of subject
|
||||||
|
|
||||||
$subject = $message->getSubject();
|
$subject = $message->getSubject();
|
||||||
if (!mb_check_encoding($subject, 'UTF-8')) {
|
|
||||||
$subject = mb_convert_encoding($subject, 'UTF-8', mb_detect_encoding($subject));
|
if (!mb_check_encoding($subject, 'UTF-8') || preg_match('/Ã.|â.|Â./', $subject)) {
|
||||||
|
|
||||||
|
$converted = mb_convert_encoding($subject, 'UTF-8', 'Windows-1252');
|
||||||
|
|
||||||
|
if (mb_check_encoding($converted, 'UTF-8')) {
|
||||||
|
$subject = $converted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$message->subject($subject);
|
$message->subject($subject);
|
||||||
|
|
||||||
/** @phpstan-ignore-next-line **/
|
/** @phpstan-ignore-next-line **/
|
||||||
|
|
@ -80,7 +87,8 @@ class GmailTransport extends AbstractTransport
|
||||||
|
|
||||||
private function base64_encode($data)
|
private function base64_encode($data)
|
||||||
{
|
{
|
||||||
return rtrim(strtr(base64_encode($data), ['+' => '-', '/' => '_']), '=');
|
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
||||||
|
// return rtrim(strtr(base64_encode($data), ['+' => '-', '/' => '_']), '=');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
|
|
|
||||||
|
|
@ -236,4 +236,20 @@ class Product extends BaseModel
|
||||||
{
|
{
|
||||||
return $use_react_url ? config('ninja.react_url') . "/#/products/{$this->hashed_id}/edit" : config('ninja.app_url');
|
return $use_react_url ? config('ninja.react_url') . "/#/products/{$this->hashed_id}/edit" : config('ninja.app_url');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getTaxCategoryName($tax_id)
|
||||||
|
{
|
||||||
|
return match ($tax_id) {
|
||||||
|
self::PRODUCT_TYPE_PHYSICAL => ctrans('texts.physical_goods'),
|
||||||
|
self::PRODUCT_TYPE_SERVICE => ctrans('texts.services'),
|
||||||
|
self::PRODUCT_TYPE_DIGITAL => ctrans('texts.digital_products'),
|
||||||
|
self::PRODUCT_TYPE_SHIPPING => ctrans('texts.shipping'),
|
||||||
|
self::PRODUCT_TYPE_EXEMPT => ctrans('texts.tax_exempt'),
|
||||||
|
self::PRODUCT_TYPE_REDUCED_TAX => ctrans('texts.reduced_tax'),
|
||||||
|
self::PRODUCT_TYPE_OVERRIDE_TAX => ctrans('texts.override_tax'),
|
||||||
|
self::PRODUCT_TYPE_ZERO_RATED => ctrans('texts.zero_rated'),
|
||||||
|
self::PRODUCT_TYPE_REVERSE_TAX => ctrans('texts.reverse_tax'),
|
||||||
|
default => 'Unknown',
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue