mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-20 08:34:38 -04:00
Add support for countries
This commit is contained in:
parent
f99dde1790
commit
b6da02a6b9
@ -54,3 +54,4 @@ Configure config/database.php and then initialize the database
|
||||
* [Chumper/Datatable](https://github.com/Chumper/Datatable) - This is a laravel 4 package for the server and client side of datatables
|
||||
* [omnipay/omnipay](https://github.com/omnipay/omnipay) - A framework agnostic, multi-gateway payment processing library for PHP 5.3+
|
||||
* [Intervention/image](https://github.com/Intervention/image) - PHP Image Manipulation
|
||||
* [webpatser/laravel-countries](https://github.com/webpatser/laravel-countries) - Almost ISO 3166_2, 3166_3, currency, Capital and more for all countries
|
@ -120,6 +120,7 @@ return array(
|
||||
'Barryvdh\Debugbar\ServiceProvider',
|
||||
'Chumper\Datatable\DatatableServiceProvider',
|
||||
'Intervention\Image\ImageServiceProvider',
|
||||
'Webpatser\Countries\CountriesServiceProvider',
|
||||
),
|
||||
|
||||
/*
|
||||
@ -214,5 +215,6 @@ return array(
|
||||
'Omnipay' => 'Omnipay\Omnipay',
|
||||
'CreditCard' => 'Omnipay\Common\CreditCard',
|
||||
'Image' => 'Intervention\Image\Facades\Image',
|
||||
'Countries' => 'Webpatser\Countries\CountriesFacade',
|
||||
),
|
||||
);
|
@ -45,23 +45,26 @@ class AccountController extends \BaseController {
|
||||
if ($section == ACCOUNT_DETAILS)
|
||||
{
|
||||
$account = Account::with('users')->find(Auth::user()->account_id);
|
||||
$countries = Country::orderBy('name')->get();
|
||||
|
||||
return View::make('accounts.details', array('account' => $account));
|
||||
return View::make('accounts.details', array('account'=>$account, 'countries'=>$countries));
|
||||
}
|
||||
else if ($section == ACCOUNT_SETTINGS)
|
||||
{
|
||||
$account = Account::with('account_gateways')->find(Auth::user()->account_id);
|
||||
$accountGateway = null;
|
||||
$config = null;
|
||||
|
||||
if (count($account->account_gateways) > 0)
|
||||
{
|
||||
$accountGateway = $account->account_gateways[0];
|
||||
$config = $accountGateway->config;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'account' => $account,
|
||||
'accountGateway' => $accountGateway,
|
||||
'config' => json_decode($accountGateway->config),
|
||||
'config' => json_decode($config),
|
||||
'gateways' => Gateway::all()
|
||||
];
|
||||
|
||||
@ -405,6 +408,7 @@ class AccountController extends \BaseController {
|
||||
$account->city = Input::get('city');
|
||||
$account->state = Input::get('state');
|
||||
$account->postal_code = Input::get('postal_code');
|
||||
$account->country_id = Input::get('country_id');
|
||||
$account->save();
|
||||
|
||||
$user = $account->users()->first();
|
||||
|
@ -51,7 +51,13 @@ class ClientController extends \BaseController {
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data = array('client' => null, 'method' => 'POST', 'url' => 'clients', 'title' => 'New');
|
||||
$data = array(
|
||||
'client' => null,
|
||||
'method' => 'POST',
|
||||
'url' => 'clients',
|
||||
'title' => 'New',
|
||||
'countries' => Country::orderBy('name')->get());
|
||||
|
||||
return View::make('clients.edit', $data);
|
||||
}
|
||||
|
||||
@ -86,7 +92,12 @@ class ClientController extends \BaseController {
|
||||
public function edit($id)
|
||||
{
|
||||
$client = Client::with('contacts')->find($id);
|
||||
$data = array('client' => $client, 'method' => 'PUT', 'url' => 'clients/' . $id, 'title' => 'Edit');
|
||||
$data = array(
|
||||
'client' => $client,
|
||||
'method' => 'PUT',
|
||||
'url' => 'clients/' . $id,
|
||||
'title' => 'Edit',
|
||||
'countries' => Country::orderBy('name')->get());
|
||||
return View::make('clients.edit', $data);
|
||||
}
|
||||
|
||||
@ -127,6 +138,7 @@ class ClientController extends \BaseController {
|
||||
$client->state = Input::get('state');
|
||||
$client->notes = Input::get('notes');
|
||||
$client->postal_code = Input::get('postal_code');
|
||||
$client->country_id = Input::get('country_id');
|
||||
$client->save();
|
||||
|
||||
$data = json_decode(Input::get('data'));
|
||||
@ -161,7 +173,7 @@ class ClientController extends \BaseController {
|
||||
}
|
||||
|
||||
Session::flash('message', 'Successfully updated client');
|
||||
return Redirect::to('clients');
|
||||
return Redirect::to('clients/' . $client->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
45
app/database/migrations/2013_11_28_195703_setup_countries_table.php
Executable file
45
app/database/migrations/2013_11_28_195703_setup_countries_table.php
Executable file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class SetupCountriesTable extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// Creates the users table
|
||||
Schema::create('countries', function($table)
|
||||
{
|
||||
$table->integer('id')->index();
|
||||
$table->string('capital', 255)->nullable();
|
||||
$table->string('citizenship', 255)->nullable();
|
||||
$table->string('country_code', 3)->default('');
|
||||
$table->string('currency', 255)->nullable();
|
||||
$table->string('currency_code', 255)->nullable();
|
||||
$table->string('currency_sub_unit', 255)->nullable();
|
||||
$table->string('full_name', 255)->nullable();
|
||||
$table->string('iso_3166_2', 2)->default('');
|
||||
$table->string('iso_3166_3', 3)->default('');
|
||||
$table->string('name', 255)->default('');
|
||||
$table->string('region_code', 3)->default('');
|
||||
$table->string('sub_region_code', 3)->default('');
|
||||
$table->boolean('eea')->default(0);
|
||||
|
||||
$table->primary('id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('countries');
|
||||
}
|
||||
|
||||
}
|
37
app/database/seeds/CountriesSeeder.php
Executable file
37
app/database/seeds/CountriesSeeder.php
Executable file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
|
||||
class CountriesSeeder extends Seeder {
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
//Empty the countries table
|
||||
DB::table('countries')->delete();
|
||||
|
||||
//Get all of the countries
|
||||
$countries = Countries::getList();
|
||||
foreach ($countries as $countryId => $country){
|
||||
DB::table('countries')->insert(array(
|
||||
'id' => $countryId,
|
||||
'capital' => ((isset($country['capital'])) ? $country['capital'] : null),
|
||||
'citizenship' => ((isset($country['citizenship'])) ? $country['citizenship'] : null),
|
||||
'country_code' => $country['country-code'],
|
||||
'currency' => ((isset($country['currency'])) ? $country['currency'] : null),
|
||||
'currency_code' => ((isset($country['currency_code'])) ? $country['currency_code'] : null),
|
||||
'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null),
|
||||
'full_name' => ((isset($country['full_name'])) ? $country['full_name'] : null),
|
||||
'iso_3166_2' => $country['iso_3166_2'],
|
||||
'iso_3166_3' => $country['iso_3166_3'],
|
||||
'name' => $country['name'],
|
||||
'region_code' => $country['region-code'],
|
||||
'sub_region_code' => $country['sub-region-code'],
|
||||
'eea' => (bool)$country['eea']
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,9 @@ class DatabaseSeeder extends Seeder {
|
||||
|
||||
$this->call('UserTableSeeder');
|
||||
$this->call('ConstantsSeeder');
|
||||
|
||||
$this->call('CountriesSeeder');
|
||||
$this->command->info('Seeded the countries!');
|
||||
}
|
||||
|
||||
}
|
6
app/models/Country.php
Executable file
6
app/models/Country.php
Executable file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Country extends Eloquent
|
||||
{
|
||||
|
||||
}
|
@ -48,9 +48,18 @@
|
||||
{{ Former::text('city') }}
|
||||
{{ Former::text('state') }}
|
||||
{{ Former::text('postal_code') }}
|
||||
{{ Former::select('country_id')->addOption('','')->label('Country')
|
||||
->fromQuery($countries, 'name', 'id')->select($account ? $account->country_id : '') }}
|
||||
|
||||
{{ Former::actions( Button::lg_primary_submit('Save') ) }}
|
||||
{{ Former::close() }}
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$(function() {
|
||||
$('#country_id').combobox();
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
@stop
|
@ -26,7 +26,9 @@
|
||||
{{ Former::textarea('notes') }}
|
||||
|
||||
{{ Former::legend('Contacts') }}
|
||||
<div data-bind="foreach: contacts">
|
||||
<div data-bind='template: { foreach: contacts,
|
||||
beforeRemove: hideContact,
|
||||
afterAdd: showContact }'>
|
||||
{{ Former::hidden('id')->data_bind("value: id, valueUpdate: 'afterkeydown'") }}
|
||||
{{ Former::text('first_name')->data_bind("value: first_name, valueUpdate: 'afterkeydown'") }}
|
||||
{{ Former::text('last_name')->data_bind("value: last_name, valueUpdate: 'afterkeydown'") }}
|
||||
@ -35,12 +37,12 @@
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-lg-8 col-lg-offset-4">
|
||||
<span data-bind="visible: $index() === ($parent.contacts().length - 1)">
|
||||
{{ link_to('#', 'Add contact', array('onclick'=>'return addContact()')) }}
|
||||
</span>
|
||||
<span data-bind="visible: $parent.contacts().length > 1" class="pull-right">
|
||||
<span data-bind="visible: $parent.contacts().length > 1">
|
||||
{{ link_to('#', 'Remove contact', array('data-bind'=>'click: $parent.removeContact')) }}
|
||||
</span>
|
||||
<span data-bind="visible: $index() === ($parent.contacts().length - 1)" class="pull-right">
|
||||
{{ link_to('#', 'Add contact', array('onclick'=>'return addContact()')) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
@ -48,11 +50,14 @@
|
||||
</div>
|
||||
|
||||
{{ Former::legend('Address') }}
|
||||
{{ Former::text('address1') }}
|
||||
{{ Former::text('address2') }}
|
||||
{{ Former::text('address1')->label('Street') }}
|
||||
{{ Former::text('address2')->label('Apt/Floor') }}
|
||||
{{ Former::text('city') }}
|
||||
{{ Former::text('state') }}
|
||||
{{ Former::text('postal_code') }}
|
||||
{{ Former::select('country_id')->addOption('','')->label('Country')
|
||||
->fromQuery($countries, 'name', 'id')->select($client ? $client->country_id : '') }}
|
||||
|
||||
|
||||
{{ Former::hidden('data')->data_bind("value: ko.toJSON(model)") }}
|
||||
|
||||
@ -61,6 +66,10 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$(function() {
|
||||
$('#country_id').combobox();
|
||||
});
|
||||
|
||||
function ContactModel() {
|
||||
var self = this;
|
||||
self.id = ko.observable('');
|
||||
@ -81,6 +90,11 @@
|
||||
window.model = new ContactsModel();
|
||||
addContact();
|
||||
@endif
|
||||
|
||||
model.showContact = function(elem) { if (elem.nodeType === 1) $(elem).hide().slideDown() }
|
||||
model.hideContact = function(elem) { if (elem.nodeType === 1) $(elem).slideUp(function() { $(elem).remove(); }) }
|
||||
|
||||
|
||||
ko.applyBindings(model);
|
||||
|
||||
function addContact() {
|
||||
@ -92,6 +106,7 @@
|
||||
model.contacts.remove(this);
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
@stop
|
@ -12,7 +12,8 @@
|
||||
"barryvdh/laravel-debugbar": "dev-master",
|
||||
"chumper/datatable": "dev-master",
|
||||
"omnipay/omnipay": "2.x",
|
||||
"intervention/image": "dev-master"
|
||||
"intervention/image": "dev-master",
|
||||
"webpatser/laravel-countries": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
|
Loading…
x
Reference in New Issue
Block a user