mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 06:07:33 -05:00 
			
		
		
		
	Merge pull request #8661 from turbo124/v5-develop
Updates for currencies
This commit is contained in:
		
						commit
						eb00f3e3ff
					
				@ -81,7 +81,8 @@ class ImportController extends Controller
 | 
			
		||||
        /** @var UploadedFile $file */
 | 
			
		||||
        foreach ($request->files->get('files') as $entityType => $file) {
 | 
			
		||||
            $contents = file_get_contents($file->getPathname());
 | 
			
		||||
            // $contents = mb_convert_encoding($contents, 'UTF-16LE', 'UTF-8');
 | 
			
		||||
 | 
			
		||||
            $contents = $this->convertEncoding($contents);
 | 
			
		||||
 | 
			
		||||
            // Store the csv in cache with an expiry of 10 minutes
 | 
			
		||||
            Cache::put($hash.'-'.$entityType, base64_encode($contents), 600);
 | 
			
		||||
@ -97,11 +98,21 @@ class ImportController extends Controller
 | 
			
		||||
            ];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $data = mb_convert_encoding($data, 'UTF-8', 'UTF-8');
 | 
			
		||||
 | 
			
		||||
        return response()->json($data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function convertEncoding($data)
 | 
			
		||||
    {
 | 
			
		||||
        
 | 
			
		||||
        $enc = mb_detect_encoding($data, mb_list_encodings(), true);
 | 
			
		||||
        
 | 
			
		||||
        if($enc !== false) {
 | 
			
		||||
            $data = mb_convert_encoding($data, "UTF-8", $enc);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $data;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function import(ImportRequest $request)
 | 
			
		||||
    {
 | 
			
		||||
        $data = $request->all();
 | 
			
		||||
 | 
			
		||||
@ -102,6 +102,8 @@ class BaseImport
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $csv = base64_decode($base64_encoded_csv);
 | 
			
		||||
        $csv = mb_convert_encoding($csv, 'UTF-8', 'UTF-8');
 | 
			
		||||
 nlog($csv);
 | 
			
		||||
        $csv = Reader::createFromString($csv);
 | 
			
		||||
        $csvdelimiter = self::detectDelimiter($csv);
 | 
			
		||||
 | 
			
		||||
@ -765,8 +767,7 @@ class BaseImport
 | 
			
		||||
    {
 | 
			
		||||
        $keys = array_shift($data);
 | 
			
		||||
        ksort($keys);
 | 
			
		||||
// nlog($data);
 | 
			
		||||
// nlog($keys);
 | 
			
		||||
 | 
			
		||||
        return array_map(function ($values) use ($keys) {
 | 
			
		||||
            return array_combine($keys, $values);
 | 
			
		||||
        }, $data);
 | 
			
		||||
 | 
			
		||||
@ -150,7 +150,7 @@ class ClientTransformer extends EntityTransformer
 | 
			
		||||
            'has_valid_vat_number' => (bool) $client->has_valid_vat_number,
 | 
			
		||||
            'is_tax_exempt' => (bool) $client->is_tax_exempt,
 | 
			
		||||
            'routing_id' => (string) $client->routing_id,
 | 
			
		||||
            'tax_data' => $client->tax_data ?: '',
 | 
			
		||||
            'tax_info' => $client->tax_data ?: new \stdClass,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -133,7 +133,7 @@ class CompanyTransformer extends EntityTransformer
 | 
			
		||||
            'show_product_details' => (bool) $company->show_product_details,
 | 
			
		||||
            'enable_product_quantity' => (bool) $company->enable_product_quantity,
 | 
			
		||||
            'default_quantity' => (bool) $company->default_quantity,
 | 
			
		||||
            'custom_fields' => $company->custom_fields ?? $std,
 | 
			
		||||
            'custom_fields' =>  (object) $company->custom_fields ?? $std,
 | 
			
		||||
            'size_id' => (string) $company->size_id ?: '',
 | 
			
		||||
            'industry_id' => (string) $company->industry_id ?: '',
 | 
			
		||||
            'first_month_of_year' => (string) $company->first_month_of_year ?: '',
 | 
			
		||||
 | 
			
		||||
@ -149,7 +149,7 @@ class InvoiceTransformer extends EntityTransformer
 | 
			
		||||
            'paid_to_date' => (float) $invoice->paid_to_date,
 | 
			
		||||
            'subscription_id' => $this->encodePrimaryKey($invoice->subscription_id),
 | 
			
		||||
            'auto_bill_enabled' => (bool) $invoice->auto_bill_enabled,
 | 
			
		||||
            'tax_data' => $invoice->tax_data ?: '',            
 | 
			
		||||
            'tax_info' => $invoice->tax_data ?: new \stdClass,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,34 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
use Illuminate\Database\Migrations\Migration;
 | 
			
		||||
use Illuminate\Database\Schema\Blueprint;
 | 
			
		||||
use Illuminate\Support\Facades\Schema;
 | 
			
		||||
 | 
			
		||||
return new class extends Migration
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     * Run the migrations.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function up()
 | 
			
		||||
    {
 | 
			
		||||
        $ir = \App\Models\Currency::where('code', 'IDR')->first();
 | 
			
		||||
 | 
			
		||||
        if($ir){
 | 
			
		||||
            $ir->thousand_separator = '.';
 | 
			
		||||
            $ir->decimal_separator = ',';
 | 
			
		||||
            $ir->save();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Reverse the migrations.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function down()
 | 
			
		||||
    {
 | 
			
		||||
        //
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
@ -49,7 +49,7 @@ class CurrenciesSeeder extends Seeder
 | 
			
		||||
            ['id' => 24, 'name' => 'Bangladeshi Taka', 'code' => 'BDT', 'symbol' => 'Tk', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
            ['id' => 25, 'name' => 'United Arab Emirates Dirham', 'code' => 'AED', 'symbol' => 'DH ', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
            ['id' => 26, 'name' => 'Hong Kong Dollar', 'code' => 'HKD', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
            ['id' => 27, 'name' => 'Indonesian Rupiah', 'code' => 'IDR', 'symbol' => 'Rp', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
            ['id' => 27, 'name' => 'Indonesian Rupiah', 'code' => 'IDR', 'symbol' => 'Rp', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
 | 
			
		||||
            ['id' => 28, 'name' => 'Mexican Peso', 'code' => 'MXN', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
            ['id' => 29, 'name' => 'Egyptian Pound', 'code' => 'EGP', 'symbol' => 'E£', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
            ['id' => 30, 'name' => 'Colombian Peso', 'code' => 'COP', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => '.', 'decimal_separator' => ','],
 | 
			
		||||
@ -136,6 +136,8 @@ class CurrenciesSeeder extends Seeder
 | 
			
		||||
            ['id' => 111, 'name' => 'Cuban Peso', 'code' => 'CUP', 'symbol' => '₱', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
            ['id' => 112, 'name' => 'Cayman Island Dollar', 'code' => 'KYD', 'symbol' => '', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
            ['id' => 113, 'name' => 'Swazi lilangeni', 'code' => 'SZL', 'symbol' => 'E', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
            ['id' => 114, 'name' => 'BZ Dollar', 'code' => 'BZD', 'symbol' => '$', 'precision' => '2', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
            ['id' => 115, 'name' => 'Libyan Dinar', 'code' => 'LYD', 'symbol' => 'LD', 'precision' => '3', 'thousand_separator' => ',', 'decimal_separator' => '.'],
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        foreach ($currencies as $currency) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user