Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitpanjwani committed Dec 2, 2019
2 parents 80014b0 + 3b7637f commit dad71b0
Show file tree
Hide file tree
Showing 30 changed files with 455 additions and 53,422 deletions.
16 changes: 2 additions & 14 deletions app/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
use Illuminate\Database\Eloquent\Model;
use Crater\User;
use Crater\Country;
use Crater\State;
use Crater\City;

class Address extends Model
{
Expand All @@ -16,8 +14,8 @@ class Address extends Model
'name',
'address_street_1',
'address_street_2',
'city_id',
'state_id',
'city',
'state',
'country_id',
'zip',
'phone',
Expand All @@ -35,14 +33,4 @@ public function country()
{
return $this->belongsTo(Country::class);
}

public function state()
{
return $this->belongsTo(State::class);
}

public function city()
{
return $this->belongsTo(City::class);
}
}
18 changes: 0 additions & 18 deletions app/City.php

This file was deleted.

6 changes: 0 additions & 6 deletions app/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
namespace Crater;

use Illuminate\Database\Eloquent\Model;
use Crater\State;

class Country extends Model
{
public function states()
{
return $this->hasMany(State::class);
}

public function address()
{
return $this->hasMany(Address::class);
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function updateAdminProfile(ProfileRequest $request)

public function getAdminCompany()
{
$user = User::with(['addresses', 'addresses.country', 'addresses.state', 'addresses.city', 'company'])->find(1);
$user = User::with(['addresses', 'addresses.country', 'company'])->find(1);

return response()->json([
'user' => $user
Expand All @@ -75,9 +75,9 @@ public function updateAdminCompany(CompanyRequest $request)
$company->addMediaFromRequest('logo')->toMediaCollection('logo');
}

$fields = $request->only(['address_street_1', 'address_street_2', 'city_id', 'state_id', 'country_id', 'zip', 'phone']);
$fields = $request->only(['address_street_1', 'address_street_2', 'city', 'state', 'country_id', 'zip', 'phone']);
$address = Address::updateOrCreate(['user_id' => 1], $fields);
$user = User::with(['addresses', 'addresses.country', 'addresses.state', 'addresses.city', 'company'])->find(1);
$user = User::with(['addresses', 'addresses.country', 'company'])->find(1);

return response()->json([
'user' => $user,
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/CustomersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public function store(Requests\CustomerRequest $request)
$newAddress->name = $address["name"];
$newAddress->address_street_1 = $address["address_street_1"];
$newAddress->address_street_2 = $address["address_street_2"];
$newAddress->city_id = $address["city_id"];
$newAddress->state_id = $address["state_id"];
$newAddress->city = $address["city"];
$newAddress->state = $address["state"];
$newAddress->country_id = $address["country_id"];
$newAddress->zip = $address["zip"];
$newAddress->phone = $address["phone"];
Expand Down Expand Up @@ -187,8 +187,8 @@ public function update($id, Requests\CustomerRequest $request)
$newAddress->name = $address["name"];
$newAddress->address_street_1 = $address["address_street_1"];
$newAddress->address_street_2 = $address["address_street_2"];
$newAddress->city_id = $address["city_id"];
$newAddress->state_id = $address["state_id"];
$newAddress->city = $address["city"];
$newAddress->state = $address["state"];
$newAddress->country_id = $address["country_id"];
$newAddress->zip = $address["zip"];
$newAddress->phone = $address["phone"];
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getCustomerEstimatePdf($id)
}
}

$companyAddress = User::with(['addresses', 'addresses.country', 'addresses.state', 'addresses.city'])->find(1);
$companyAddress = User::with(['addresses', 'addresses.country'])->find(1);

$colors = [
'invoice_primary_color',
Expand Down Expand Up @@ -189,7 +189,7 @@ public function getCustomerInvoicePdf($id)
}
}

$companyAddress = User::with(['addresses', 'addresses.country', 'addresses.state', 'addresses.city'])->find(1);
$companyAddress = User::with(['addresses', 'addresses.country'])->find(1);

$colors = [
'invoice_primary_color',
Expand Down Expand Up @@ -262,7 +262,7 @@ public function getEstimatePdf($id)
$estimateTemplate = EstimateTemplate::find($estimate->estimate_template_id);

$company = Company::find($estimate->company_id);
$companyAddress = User::with(['addresses', 'addresses.country', 'addresses.state', 'addresses.city'])->find(1);
$companyAddress = User::with(['addresses', 'addresses.country'])->find(1);
$logo = $company->getMedia('logo')->first();

if($logo) {
Expand Down Expand Up @@ -338,7 +338,7 @@ public function getInvoicePdf($id)

$invoiceTemplate = InvoiceTemplate::find($invoice->invoice_template_id);
$company = Company::find($invoice->company_id);
$companyAddress = User::with(['addresses', 'addresses.country', 'addresses.state', 'addresses.city'])->find(1);
$companyAddress = User::with(['addresses', 'addresses.country'])->find(1);

$logo = $company->getMedia('logo')->first();

Expand Down
16 changes: 0 additions & 16 deletions app/Http/Controllers/LocationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

use Illuminate\Http\Request;
use Crater\Country;
use Crater\State;
use Crater\City;

class LocationController extends Controller
{
Expand All @@ -14,18 +12,4 @@ public function getCountries()
'countries' => Country::all()
]);
}

public function getStates($id)
{
return response()->json([
'states' => Country::find($id)->states
]);
}

public function getCities($id)
{
return response()->json([
'cities' => State::find($id)->cities
]);
}
}
6 changes: 2 additions & 4 deletions app/Http/Controllers/OnboardingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public function getOnboardingData(Request $request)
$user = User::with([
'addresses',
'addresses.country',
'addresses.state',
'addresses.city',
'company'
])->find(1);

Expand Down Expand Up @@ -156,8 +154,8 @@ public function adminCompany(CompanyRequest $request)
$fields = $request->only([
'address_street_1',
'address_street_2',
'city_id',
'state_id',
'city',
'state',
'country_id',
'zip',
'phone'
Expand Down
110 changes: 110 additions & 0 deletions app/Listeners/Updates/v2/Version200.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace Crater\Listeners\Updates\v2;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Database\Schema\Blueprint;
use Crater\Listeners\Updates\Listener;
use Crater\Listeners\Updates\v2\Version200;
use Crater\Events\UpdateFinished;
use Crater\Setting;
use Crater\Address;

class Version200 extends Listener
{
const VERSION = '2.0.0';

/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle(UpdateFinished $event)
{
if ($this->isListenerFired($event)) {
return;
}

// Replace state and city id to name
$this->replaceStateAndCityName();

// Drop states and cities foreign key
$this->dropForeignKey();

// Remove states and cities tables
$this->dropSchemas();

// Delete state & city models, migrations & seeders
$this->deleteFiles();

// Update Crater app version
$this->updateVersion();
}

private function replaceStateAndCityName() {
\Schema::table('addresses', function (Blueprint $table) {
$table->string('state')->nullable();
$table->string('city')->nullable();
});

$addresses = \Crater\Address::all();
foreach ($addresses as $add) {
$city = \Crater\City::find($add->city_id);
if($city) {
$add->city = $city->name;
}

$state = \Crater\State::find($add->state_id);
if($state) {
$add->state = $state->name;
}

$add->save();
}
}

private function dropForeignKey() {
\Schema::table('addresses', function (Blueprint $table) {
$table->dropForeign('addresses_state_id_foreign');
$table->dropForeign('addresses_city_id_foreign');
$table->dropColumn('state_id');
$table->dropColumn('city_id');
});
}

private function dropSchemas() {
\Schema::disableForeignKeyConstraints();

\Schema::dropIfExists('states');
\Schema::dropIfExists('cities');

\Schema::enableForeignKeyConstraints();
}

private function deleteFiles() {
\File::delete(
database_path('migrations/2017_05_06_172817_create_cities_table.php'),
database_path('migrations/2017_05_06_173711_create_states_table.php'),
database_path('seeds/StatesTableSeeder.php'),
database_path('seeds/CitiesTableSeeder.php'),
app_path('City.php'),
app_path('State.php')
);
}

private function updateVersion() {
Setting::setSetting('version', static::VERSION);
}
}
2 changes: 2 additions & 0 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Crater\Events\UpdateFinished;
use Crater\Listeners\Updates\v1\Version110;
use Crater\Listeners\Updates\v2\Version200;

class EventServiceProvider extends ServiceProvider
{
Expand All @@ -17,6 +18,7 @@ class EventServiceProvider extends ServiceProvider
protected $listen = [
UpdateFinished::class=> [
Version110::class,
Version200::class,
],
Registered::class => [
SendEmailVerificationNotification::class,
Expand Down
25 changes: 0 additions & 25 deletions app/State.php

This file was deleted.

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"require": {
"php": "^7.2",
"barryvdh/laravel-dompdf": "^0.8.1",
"doctrine/dbal": "^2.10",
"fideloper/proxy": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"intervention/image": "^2.3",
Expand Down
Loading

0 comments on commit dad71b0

Please sign in to comment.