Skip to content

Commit

Permalink
Finish Customers
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffgreco13 committed Nov 23, 2023
1 parent 613cf93 commit 0b9e295
Show file tree
Hide file tree
Showing 10 changed files with 519 additions and 35 deletions.
61 changes: 36 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# This is my package filament-wave
# FilamentWave

[![Latest Version on Packagist](https://img.shields.io/packagist/v/jeffgreco13/filament-wave.svg?style=flat-square)](https://packagist.org/packages/jeffgreco13/filament-wave)
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/jeffgreco13/filament-wave/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/jeffgreco13/filament-wave/actions?query=workflow%3Arun-tests+branch%3Amain)
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/jeffgreco13/filament-wave/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/jeffgreco13/filament-wave/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
[![Total Downloads](https://img.shields.io/packagist/dt/jeffgreco13/filament-wave.svg?style=flat-square)](https://packagist.org/packages/jeffgreco13/filament-wave)

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
A Filament V3 plugin to create robust integrations for Wave Apps/Accounting.

## Support us
## Expert Support

[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/filament-wave.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/filament-wave)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
Looking for a custom integration or solution? Contact me jeff@jeffpgreco.com

## Installation

Expand All @@ -23,37 +19,50 @@ You can install the package via composer:
composer require jeffgreco13/filament-wave
```

You can publish and run the migrations with:
Update your .env file to include:

```bash
php artisan vendor:publish --tag="filament-wave-migrations"
php artisan migrate
```

You can publish the config file with:

```bash
php artisan vendor:publish --tag="filament-wave-config"
WAVE_ACCESS_TOKEN= *your full access token*
WAVE_BUSINESS_ID= *ID for the business you wish to interact with*
WAVE_GRAPHQL_URI= *defaults to https://gql.waveapps.com/graphql/public*
```
This package uses [jeffgreco13/laravel-wave][laravel-wave] under the hood. Review the docs for more information.

This is the contents of the published config file:
Add the `WavePlugin` to your panel service provider:

```php
return [
];
use Jeffgreco13\FilamentWave\WavePlugin;

class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
...
->plugin(
WavePlugin::make()
);
}
}
```

Optionally, you can publish the views using
## Usage

I've build this package to be as modular and extensible as possible. Meaning you can publish migrations and utilize Filament resources only as needed. See below on how to use each model:

### Customers

Publish the customers migration table using.

```bash
php artisan vendor:publish --tag="filament-wave-views"
php artisan vendor:publish --tag="filament-wave-customers-migration"
php artisan migrate
```

## Usage
Next, add the `customers` method to the WavePlugin in your panel service provider:

```php
$filamentWave = new Jeffgreco13\FilamentWave();
echo $filamentWave->echoPhrase('Hello, Jeffgreco13!');
WavePlugin::make()->customers()
```

## Testing
Expand Down Expand Up @@ -82,3 +91,5 @@ Please review [our security policy](../../security/policy) on how to report secu
## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

[laravel-wave]: https://github.com/jeffgreco13/laravel-wave
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@
public function up()
{
Schema::create('wave_customers', function (Blueprint $table) {
// $table->id();
$table->string('id')->primary();
$table->string('name');
$table->string('email')->nullable();
$table->string('phone')->nullable();
$table->string('name')->nullable();
$table->json('address')->nullable();
$table->string('first_name')->nullable();
$table->string('last_name')->nullable();
$table->string('currency')->nullable();
$table->json('address')->nullable();
$table->string('email')->nullable();
$table->string('mobile')->nullable();
$table->string('phone')->nullable();
$table->string('toll_free')->nullable();
$table->string('website')->nullable();
$table->text('internal_notes')->nullable();
$table->json('currency')->nullable();
$table->boolean('is_archived')->default(false);
$table->json('meta')->nullable(); // can store outstanding balance and overdue balance
$table->json('meta')->nullable(); // Used to store additional information about the customer, like outstandingBalance, overdueAmount, createdAt, modifiedAt, etc.

$table->timestamps();
});
Expand Down
99 changes: 99 additions & 0 deletions src/Filament/Resources/CustomerResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Jeffgreco13\FilamentWave\Filament\Resources;

use Filament\Forms;
use Filament\Tables;
use Filament\Forms\Form;
use Filament\Tables\Table;
use Filament\Resources\Resource;
use Filament\Support\Enums\FontWeight;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Jeffgreco13\FilamentWave\Filament\Resources\CustomerResource\Pages;
use Jeffgreco13\FilamentWave\Filament\Resources\CustomerResource\RelationManagers;

class CustomerResource extends Resource
{
protected static ?string $navigationIcon = 'heroicon-o-identification';

public static string $modalWidth = "lg";

public static function getModel(): string
{
return filament('wave')->getCustomerModel();
}

public static function form(Form $form): Form
{
return $form
->columns(1)
->schema([
Forms\Components\TextInput::make('name')
->label('Customer or Business Name')
->placeholder('Dunder Mifflin')
->default('AAA Test')
->required(),
Forms\Components\Fieldset::make('Primary contact')
->columns(2)
->schema([
Forms\Components\TextInput::make('first_name')
->default('Mike')
->placeholder('Michael'),
Forms\Components\TextInput::make('last_name')
->default('Jones')
->placeholder('Scott'),
Forms\Components\TextInput::make('email')
->default('mike.jones@gmail.com')
->placeholder('mscott@dundermifflin.com')
->email(),
Forms\Components\TextInput::make('phone')
->default('705-255-1775'),
]),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')
->searchable(['name', 'first_name', 'last_name'])
->weight(FontWeight::Bold)
->sortable()
->description(fn ($record) => $record->name != $record->full_name ? $record->full_name : null),
Tables\Columns\TextColumn::make('email')
->searchable(),
Tables\Columns\TextColumn::make('phone')
->searchable()
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make()->modalWidth(self::$modalWidth),
Tables\Actions\ActionGroup::make([
Tables\Actions\Action::make('archive')
->label(fn ($record) => $record->is_archived ? 'Restore' : 'Archive')
->color('warning')
->icon('heroicon-s-archive-box')
->action(function ($record) {
$record->toggleArchive();
}),
Tables\Actions\DeleteAction::make(),
]),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getPages(): array
{
return [
'index' => Pages\ManageCustomers::route('/'),
];
}
}
46 changes: 46 additions & 0 deletions src/Filament/Resources/CustomerResource/Pages/ManageCustomers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Jeffgreco13\FilamentWave\Filament\Resources\CustomerResource\Pages;

use Filament\Actions;
use Filament\Resources\Components\Tab;
use Filament\Notifications\Notification;
use Illuminate\Database\Eloquent\Builder;
use Filament\Resources\Pages\ManageRecords;
use Jeffgreco13\FilamentWave\Jobs\PullWaveCustomers;

class ManageCustomers extends ManageRecords
{
public static function getResource(): string
{
return filament('wave')->getCustomerResource();
}

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make()->modalWidth(self::getResource()::$modalWidth),
Actions\ActionGroup::make([
Actions\Action::make('pull')
->label('Pull from Wave')
->icon('heroicon-o-arrow-down-circle')
->requiresConfirmation()
->modalDescription("This will pull all customers immediately. Do you want to continue?")
->action(function(){
PullWaveCustomers::dispatchSync();
Notification::make()->success()->title('Customers pulled successfully.')->send();
})
])
];
}

public function getTabs(): array
{
return [
'active' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->active()),
'archived' => Tab::make()
->modifyQueryUsing(fn (Builder $query) => $query->archived()),
];
}
}
11 changes: 8 additions & 3 deletions src/FilamentWaveServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Jeffgreco13\FilamentWave\Commands\FilamentWaveCommand;

class FilamentWaveServiceProvider extends PackageServiceProvider
{
Expand All @@ -16,10 +15,10 @@ public function configurePackage(Package $package): void
* More info: https://github.com/spatie/laravel-package-tools
*/
$package
->name('filament-wave')
->name('filament-wave');
// ->hasConfigFile()
// ->hasViews()
->hasMigration('create_filament-wave_table');
// ->hasMigration('create_filament-wave_table');
// ->hasCommand(FilamentWaveCommand::class);
}

Expand All @@ -33,5 +32,11 @@ public function bootingPackage()
now()->addSecond()
),
], "{$this->package->shortName()}-customers-migration");

/*
*
* EVENTS & OBSERVERS
*
*/
}
}
48 changes: 48 additions & 0 deletions src/Jobs/PullWaveCustomers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Jeffgreco13\FilamentWave\Jobs;

use Jeffgreco13\Wave\Wave;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Jeffgreco13\FilamentWave\Models\Customer;
use Illuminate\Contracts\Queue\ShouldBeUnique;

class PullWaveCustomers implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
*/
public function __construct()
{
//
}

/**
* Execute the job.
*/
public function handle(): void
{
$wave = new Wave();
$response = $wave->customers(['pageSize'=>20]);
do {
foreach ($wave->getNodes() as $node) {
$customer = Customer::firstOrNew(['id'=>$node->id]);
$customer->fill([
'name' => $node->name,
'email' => $node->email,
'first_name' => $node->firstName,
'last_name' => $node->lastName,
'phone' => $node->phone
]);
$customer->saveQuietly();
}
} while($response = $wave->paginate());

}
}
Loading

0 comments on commit 0b9e295

Please sign in to comment.