Skip to content

Initial Implementation of Currencies #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/Http/Controllers/CompanySettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use App\Http\Requests\UpdateCompanySettingRequest;
use App\Library\Poowf\Unicorn;
use App\Models\Company;
use App\Models\CompanySetting;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -72,7 +73,9 @@ public function edit(Company $company)
$companySetting = null;
}

return view('pages.company.settings.edit', compact('companySetting', 'company'));
$currencies = Unicorn::currencies();

return view('pages.company.settings.edit', compact('companySetting', 'company', 'currencies'));
}

/**
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function showwithtoken(Request $request, Company $company)
public function duplicate(Company $company, Invoice $invoice)
{
$duplicatedInvoice = $invoice->duplicate();
flash('Invoice has been Cloned Sucessfully', "success");
flash('Invoice has been Duplicated Sucessfully', "success");
return redirect()->route('invoice.show', [ 'invoice' => $duplicatedInvoice, 'company' => $company ]);
}

Expand Down Expand Up @@ -376,10 +376,9 @@ public function edit(Company $company, Invoice $invoice)
}

$clients = $company->clients;
$itemtemplates = $company->itemtemplates;
$recurrence = ($invoice->recurrence) ? $invoice->recurrence : null;

return view('pages.invoice.edit', compact('invoice', 'clients', 'recurrence', 'itemtemplates'));
return view('pages.invoice.edit', compact('invoice', 'clients', 'recurrence'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/QuoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function showwithtoken(Request $request, Company $company)
public function duplicate(Company $company, Quote $quote)
{
$duplicatedQuote = $quote->duplicate();
flash('Quote has been Cloned Sucessfully', "success");
flash('Quote has been Duplicated Sucessfully', "success");
return redirect()->route('quote.show', [ 'quote' => $duplicatedQuote->id, 'company' => $company ]);
}

Expand Down
178 changes: 178 additions & 0 deletions app/Library/Unicorn.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,168 @@ class Unicorn
\App\Models\CompanyUserRequest::class,
];

private static $currencySymbols = [
'AED' => 'د.إ', // ?
'AFN' => 'Af',
'ALL' => 'Lek',
'AMD' => 'դ',
'ANG' => 'ƒ',
'AOA' => 'Kz', // ?
'ARS' => '$',
'AUD' => '$',
'AWG' => 'ƒ',
'AZN' => '₼',
'BAM' => 'KM',
'BBD' => '$',
'BDT' => '৳', // ?
'BGN' => 'лв',
'BHD' => '.د.ب', // ?
'BIF' => 'FBu', // ?
'BMD' => '$',
'BND' => '$',
'BOB' => '$b',
'BRL' => 'R$',
'BSD' => '$',
'BTN' => 'Nu.', // ?
'BWP' => 'P',
'BYR' => 'p.',
'BZD' => 'BZ$',
'CAD' => '$',
'CDF' => 'FC',
'CHF' => 'CHF',
'CLF' => 'UF', // ?
'CLP' => '$',
'CNY' => '¥',
'COP' => '$',
'CRC' => '₡',
'CUP' => '⃌',
'CVE' => '$', // ?
'CZK' => 'Kč',
'DJF' => 'Fdj', // ?
'DKK' => 'kr',
'DOP' => 'RD$',
'DZD' => 'دج', // ?
'EGP' => 'E£',
'ETB' => 'Br',
'EUR' => '€',
'FJD' => '$',
'FKP' => '£',
'GBP' => '£',
'GEL' => 'ლ', // ?
'GHS' => '¢',
'GIP' => '£',
'GMD' => 'D', // ?
'GNF' => 'FG', // ?
'GTQ' => 'Q',
'GYD' => '$',
'HKD' => '$',
'HNL' => 'L',
'HRK' => 'kn',
'HTG' => 'G', // ?
'HUF' => 'Ft',
'IDR' => 'Rp',
'ILS' => '₪',
'INR' => '₹',
'IQD' => 'ع.د', // ?
'IRR' => '﷼',
'ISK' => 'kr',
'JEP' => '£',
'JMD' => 'J$',
'JOD' => 'JD', // ?
'JPY' => '¥',
'KES' => 'KSh', // ?
'KGS' => 'лв',
'KHR' => '៛',
'KMF' => 'CF', // ?
'KPW' => '₩',
'KRW' => '₩',
'KWD' => 'د.ك', // ?
'KYD' => '$',
'KZT' => '₸',
'LAK' => '₭',
'LBP' => '£',
'LKR' => '₨',
'LRD' => '$',
'LSL' => 'L', // ?
'LTL' => 'Lt',
'LVL' => 'Ls',
'LYD' => 'ل.د', // ?
'MAD' => 'د.م.', //?
'MDL' => 'L',
'MGA' => 'Ar', // ?
'MKD' => 'ден',
'MMK' => 'K',
'MNT' => '₮',
'MOP' => 'MOP$', // ?
'MRO' => 'UM', // ?
'MUR' => '₨', // ?
'MVR' => '.ރ', // ?
'MWK' => 'MK',
'MXN' => '$',
'MYR' => 'RM',
'MZN' => 'MT',
'NAD' => '$',
'NGN' => '₦',
'NIO' => 'C$',
'NOK' => 'kr',
'NPR' => '₨',
'NZD' => '$',
'OMR' => '﷼',
'PAB' => 'B/.',
'PEN' => 'S/.',
'PGK' => 'K', // ?
'PHP' => '₱',
'PKR' => '₨',
'PLN' => 'zł',
'PYG' => 'Gs',
'QAR' => '﷼',
'RON' => 'lei',
'RSD' => 'Дин.',
'RUB' => '₽',
'RWF' => 'ر.س',
'SAR' => '﷼',
'SBD' => '$',
'SCR' => '₨',
'SDG' => '£', // ?
'SEK' => 'kr',
'SGD' => '$',
'SHP' => '£',
'SLL' => 'Le', // ?
'SOS' => 'S',
'SRD' => '$',
'STD' => 'Db', // ?
'SVC' => '$',
'SYP' => '£',
'SZL' => 'L', // ?
'THB' => '฿',
'TJS' => 'TJS', // ? TJS (guess)
'TMT' => 'm',
'TND' => 'د.ت',
'TOP' => 'T$',
'TRY' => '₤', // New Turkey Lira (old symbol used)
'TTD' => '$',
'TWD' => 'NT$',
'TZS' => 'TSh',
'UAH' => '₴',
'UGX' => 'USh',
'USD' => '$',
'UYU' => '$U',
'UZS' => 'лв',
'VEF' => 'Bs',
'VND' => '₫',
'VUV' => 'VT',
'WST' => 'WS$',
'XAF' => 'FCFA',
'XCD' => '$',
'XDR' => 'SDR',
'XOF' => 'FCFA',
'XPF' => 'F',
'YER' => '﷼',
'ZAR' => 'R',
'ZMK' => 'ZK', // ?
'ZWL' => 'Z$',
];

public function __construct()
{
}
Expand Down Expand Up @@ -298,4 +460,20 @@ public static function redirectTo()

return $url;
}

public static function currencies()
{
return self::$currencySymbols;
}

public static function currency($iso_3166_1_alpha2)
{
$country = country($iso_3166_1_alpha2);
$currency = $country->getCurrency()['iso_4217_code'];

if (array_key_exists($currency, self::$currencySymbols))
{
return self::$currencySymbols[$currency];
}
}
}
4 changes: 2 additions & 2 deletions app/Models/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function calculatesubtotal($moneyformat = true)

if ($moneyformat)
{
setlocale(LC_MONETARY, 'en_US.UTF-8');
setlocale(LC_MONETARY, 'ja_JP.UTF-8');
return money_format('%!.2n', $total);
}
else
Expand Down Expand Up @@ -297,7 +297,7 @@ public function calculatetotal($moneyformat = true)

if ($moneyformat)
{
setlocale(LC_MONETARY, 'en_US.UTF-8');
setlocale(LC_MONETARY, 'de_DE');
return money_format('%!.2n', $total);
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddCurrencyToCompanySettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('company_settings', function (Blueprint $table) {
$table->string('currency')->after('tax')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('company_settings', function (Blueprint $table) {
$table->dropColumn('currency');
});
}
}
1 change: 1 addition & 0 deletions resources/views/pages/company/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@section("head")
<link href="{{ mix('/assets/css/intlTelInput.css') }}" rel="stylesheet" type="text/css">
<link href="{{ mix('/assets/css/selectize.css') }}" rel="stylesheet" type="text/css">
<style>
</style>
@stop
Expand Down
1 change: 1 addition & 0 deletions resources/views/pages/company/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@section("head")
<link href="{{ mix('/assets/css/intlTelInput.css') }}" rel="stylesheet" type="text/css">
<link href="{{ mix('/assets/css/selectize.css') }}" rel="stylesheet" type="text/css">
<style>
.logo-display-container, .smlogo-display-container {
display: inline-block;
Expand Down
15 changes: 15 additions & 0 deletions resources/views/pages/company/settings/edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@extends("layouts.default", ['page_title' => 'Company | Settings'])

@section("head")
<link href="{{ mix('/assets/css/selectize.css') }}" rel="stylesheet" type="text/css">
<style>
</style>
@stop
Expand All @@ -26,6 +27,18 @@
<span class="helper-text"></span>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<select id="currency" name="currency" data-parsley-trigger="change" placeholder="Currency">
<option disabled="" selected="selected" value="">Currency</option>
@foreach($currencies as $currency => $symbol)
<option value="{{ $currency }}" @if($company) @if($company->currency == $currency) selected @endif @endif>{!! $symbol !!} - {{ $currency }}</option>
@endforeach
</select>
<label for="currency" class="label-validation">Currency</label>
<span class="helper-text"></span>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="invoice_prefix" name="invoice_prefix" type="text" data-parsley-trigger="change" data-parsley-minlength="2" value="{{ $companySetting->invoice_prefix ?? '' }}" placeholder="Invoice Prefix" @if(!$company) disabled @endif>
Expand Down Expand Up @@ -80,6 +93,8 @@
"use strict";
$(function() {

Unicorn.initSelectize('#currency');

@if(!$company)
M.toast({ html: "You need to fill in your company information first", displayLength: "6000", classes: "error"});
@endif
Expand Down
1 change: 1 addition & 0 deletions resources/views/pages/invoice/edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@extends("layouts.default", ['page_title' => 'Invoice | Edit'])

@section("head")
<link href="{{ mix('/assets/css/selectize.css') }}" rel="stylesheet" type="text/css">
<style>
</style>
@stop
Expand Down
2 changes: 1 addition & 1 deletion resources/views/pages/invoice/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
@can('update', $invoice)
<form method="post" action="{{ route('invoice.duplicate', [ 'invoice' => $invoice, 'company' => \App\Library\Poowf\Unicorn::getCompanyKey() ] ) }}" class="null-form">
{{ csrf_field() }}
<button class="btn blue darken-3 waves-effect waves-dark null-btn" type="submit">Clone</button>
<button class="btn blue darken-3 waves-effect waves-dark null-btn" type="submit">Duplicate</button>
</form>
@endcan
@can('update', $invoice)
Expand Down
2 changes: 1 addition & 1 deletion resources/views/pages/quote/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
@can('update', $quote)
<form method="post" action="{{ route('quote.duplicate', [ 'quote' => $quote, 'company' => \App\Library\Poowf\Unicorn::getCompanyKey() ] ) }}" class="null-form">
{{ csrf_field() }}
<button class="btn blue darken-3 waves-effect waves-dark null-btn" type="submit">Clone</button>
<button class="btn blue darken-3 waves-effect waves-dark null-btn" type="submit">Duplicate</button>
</form>
@endcan
@can('update', $quote)
Expand Down
1 change: 1 addition & 0 deletions resources/views/pages/user/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@section("head")
<link href="{{ mix('/assets/css/intlTelInput.css') }}" rel="stylesheet" type="text/css">
<link href="{{ mix('/assets/css/selectize.css') }}" rel="stylesheet" type="text/css">
<style>
</style>
@stop
Expand Down
1 change: 1 addition & 0 deletions resources/views/pages/user/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@section("head")
<link href="{{ mix('/assets/css/intlTelInput.css') }}" rel="stylesheet" type="text/css">
<link href="{{ mix('/assets/css/selectize.css') }}" rel="stylesheet" type="text/css">
<style>
</style>
@stop
Expand Down