mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Merge pull request #4151 from turbo124/v2
Console commands for small test data batches
This commit is contained in:
commit
61646ec55c
565
app/Console/Commands/CreateSingleAccount.php
Normal file
565
app/Console/Commands/CreateSingleAccount.php
Normal file
@ -0,0 +1,565 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Console\Commands\TestData\CreateTestCreditJob;
|
||||
use App\Console\Commands\TestData\CreateTestQuoteJob;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Events\Invoice\InvoiceWasCreated;
|
||||
use App\Events\Invoice\InvoiceWasMarkedSent;
|
||||
use App\Events\Payment\PaymentWasCreated;
|
||||
use App\Factory\ClientFactory;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Factory\InvoiceItemFactory;
|
||||
use App\Factory\PaymentFactory;
|
||||
use App\Factory\QuoteFactory;
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
use App\Jobs\Quote\CreateQuoteInvitations;
|
||||
use App\Listeners\Credit\CreateCreditInvitation;
|
||||
use App\Listeners\Invoice\CreateInvoiceInvitation;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\CompanyToken;
|
||||
use App\Models\Country;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Expense;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\Product;
|
||||
use App\Models\Project;
|
||||
use App\Models\Quote;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
use App\Models\Vendor;
|
||||
use App\Models\VendorContact;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Carbon\Carbon;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateSingleAccount extends Command
|
||||
{
|
||||
use MakesHash, GeneratesCounter;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create Single Sample Account';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'ninja:create-single-account {gateway=all}';
|
||||
|
||||
protected $invoice_repo;
|
||||
|
||||
protected $count;
|
||||
|
||||
protected $gateway;
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(InvoiceRepository $invoice_repo)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->invoice_repo = $invoice_repo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info(date('r').' Create Single Sample Account...');
|
||||
$this->count = 1;
|
||||
$this->gateway = $this->argument('gateway');
|
||||
|
||||
$this->info('Warming up cache');
|
||||
|
||||
$this->warmCache();
|
||||
|
||||
$this->createSmallAccount();
|
||||
|
||||
}
|
||||
|
||||
private function createSmallAccount()
|
||||
{
|
||||
$this->info('Creating Small Account and Company');
|
||||
|
||||
$account = Account::factory()->create();
|
||||
$company = Company::factory()->create([
|
||||
'account_id' => $account->id,
|
||||
'slack_webhook_url' => config('ninja.notification.slack'),
|
||||
]);
|
||||
|
||||
$account->default_company_id = $company->id;
|
||||
$account->save();
|
||||
|
||||
$user = User::whereEmail('small@example.com')->first();
|
||||
|
||||
if (! $user) {
|
||||
$user = User::factory()->create([
|
||||
'account_id' => $account->id,
|
||||
'email' => 'small@example.com',
|
||||
'confirmation_code' => $this->createDbHash(config('database.default')),
|
||||
]);
|
||||
}
|
||||
|
||||
$company_token = new CompanyToken;
|
||||
$company_token->user_id = $user->id;
|
||||
$company_token->company_id = $company->id;
|
||||
$company_token->account_id = $account->id;
|
||||
$company_token->name = 'test token';
|
||||
$company_token->token = Str::random(64);
|
||||
$company_token->is_system = true;
|
||||
|
||||
$company_token->save();
|
||||
|
||||
$user->companies()->attach($company->id, [
|
||||
'account_id' => $account->id,
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
'settings' => null,
|
||||
]);
|
||||
|
||||
Product::factory()->count(1)->create([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
]);
|
||||
|
||||
$this->info('Creating '.$this->count.' clients');
|
||||
|
||||
for ($x = 0; $x < $this->count; $x++) {
|
||||
$z = $x + 1;
|
||||
$this->info('Creating client # '.$z);
|
||||
|
||||
$this->createClient($company, $user);
|
||||
}
|
||||
|
||||
for ($x = 0; $x < $this->count; $x++) {
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating invoice for client #'.$client->id);
|
||||
$this->createInvoice($client);
|
||||
$this->info('creating invoice for client #'.$client->id);
|
||||
$this->createInvoice($client);
|
||||
$this->info('creating invoice for client #'.$client->id);
|
||||
$this->createInvoice($client);
|
||||
$this->info('creating invoice for client #'.$client->id);
|
||||
$this->createInvoice($client);
|
||||
$this->info('creating invoice for client #'.$client->id);
|
||||
$this->createInvoice($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating credit for client #'.$client->id);
|
||||
$this->createCredit($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating quote for client #'.$client->id);
|
||||
$this->createQuote($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating expense for client #'.$client->id);
|
||||
$this->createExpense($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating vendor for client #'.$client->id);
|
||||
$this->createVendor($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating task for client #'.$client->id);
|
||||
$this->createTask($client);
|
||||
|
||||
$client = $company->clients->random();
|
||||
|
||||
$this->info('creating project for client #'.$client->id);
|
||||
$this->createProject($client);
|
||||
}
|
||||
|
||||
$this->createGateways($company, $user);
|
||||
}
|
||||
|
||||
private function createClient($company, $user)
|
||||
{
|
||||
|
||||
// dispatch(function () use ($company, $user) {
|
||||
|
||||
// });
|
||||
$client = Client::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $company->id,
|
||||
]);
|
||||
|
||||
ClientContact::factory()->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id,
|
||||
'company_id' => $company->id,
|
||||
'is_primary' => 1,
|
||||
'email' => 'user@example.com'
|
||||
]);
|
||||
|
||||
ClientContact::factory()->count(rand(1, 2))->create([
|
||||
'user_id' => $user->id,
|
||||
'client_id' => $client->id,
|
||||
'company_id' => $company->id,
|
||||
]);
|
||||
|
||||
$client->id_number = $this->getNextClientNumber($client);
|
||||
|
||||
$settings = $client->settings;
|
||||
$settings->currency_id = (string) rand(1, 79);
|
||||
$client->settings = $settings;
|
||||
|
||||
$country = Country::all()->random();
|
||||
|
||||
$client->country_id = $country->id;
|
||||
$client->save();
|
||||
}
|
||||
|
||||
private function createExpense($client)
|
||||
{
|
||||
Expense::factory()->count(rand(1, 2))->create([
|
||||
'user_id' => $client->user->id,
|
||||
'client_id' => $client->id,
|
||||
'company_id' => $client->company->id,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createVendor($client)
|
||||
{
|
||||
$vendor = Vendor::factory()->create([
|
||||
'user_id' => $client->user->id,
|
||||
'company_id' => $client->company->id,
|
||||
]);
|
||||
|
||||
VendorContact::factory()->create([
|
||||
'user_id' => $client->user->id,
|
||||
'vendor_id' => $vendor->id,
|
||||
'company_id' => $client->company->id,
|
||||
'is_primary' => 1,
|
||||
]);
|
||||
|
||||
VendorContact::factory()->count(rand(1, 2))->create([
|
||||
'user_id' => $client->user->id,
|
||||
'vendor_id' => $vendor->id,
|
||||
'company_id' => $client->company->id,
|
||||
'is_primary' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createTask($client)
|
||||
{
|
||||
$vendor = Task::factory()->create([
|
||||
'user_id' => $client->user->id,
|
||||
'company_id' => $client->company->id,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createProject($client)
|
||||
{
|
||||
$vendor = Project::factory()->create([
|
||||
'user_id' => $client->user->id,
|
||||
'company_id' => $client->company->id,
|
||||
]);
|
||||
}
|
||||
|
||||
private function createInvoice($client)
|
||||
{
|
||||
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$invoice = InvoiceFactory::create($client->company->id, $client->user->id); //stub the company and user_id
|
||||
$invoice->client_id = $client->id;
|
||||
$dateable = Carbon::now()->subDays(rand(0, 90));
|
||||
$invoice->date = $dateable;
|
||||
|
||||
$invoice->line_items = $this->buildLineItems(rand(1, 10));
|
||||
$invoice->uses_inclusive_taxes = false;
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name1 = 'GST';
|
||||
$invoice->tax_rate1 = 10.00;
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name2 = 'VAT';
|
||||
$invoice->tax_rate2 = 17.50;
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$invoice->tax_name3 = 'CA Sales Tax';
|
||||
$invoice->tax_rate3 = 5;
|
||||
}
|
||||
|
||||
$invoice->custom_value1 = $faker->date;
|
||||
$invoice->custom_value2 = rand(0, 1) ? 'yes' : 'no';
|
||||
|
||||
$invoice->save();
|
||||
|
||||
$invoice_calc = new InvoiceSum($invoice);
|
||||
$invoice_calc->build();
|
||||
|
||||
$invoice = $invoice_calc->getInvoice();
|
||||
|
||||
$invoice->save();
|
||||
$invoice->service()->createInvitations()->markSent();
|
||||
|
||||
$this->invoice_repo->markSent($invoice);
|
||||
|
||||
// if (rand(0, 1)) {
|
||||
// $invoice = $invoice->service()->markPaid()->save();
|
||||
// }
|
||||
//@todo this slow things down, but gives us PDFs of the invoices for inspection whilst debugging.
|
||||
event(new InvoiceWasCreated($invoice, $invoice->company, Ninja::eventVars()));
|
||||
}
|
||||
|
||||
private function createCredit($client)
|
||||
{
|
||||
// for($x=0; $x<$this->count; $x++){
|
||||
|
||||
// dispatch(new CreateTestCreditJob($client));
|
||||
|
||||
// }
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$credit = Credit::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
|
||||
|
||||
$dateable = Carbon::now()->subDays(rand(0, 90));
|
||||
$credit->date = $dateable;
|
||||
|
||||
$credit->line_items = $this->buildLineItems(rand(1, 10));
|
||||
$credit->uses_inclusive_taxes = false;
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$credit->tax_name1 = 'GST';
|
||||
$credit->tax_rate1 = 10.00;
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$credit->tax_name2 = 'VAT';
|
||||
$credit->tax_rate2 = 17.50;
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$credit->tax_name3 = 'CA Sales Tax';
|
||||
$credit->tax_rate3 = 5;
|
||||
}
|
||||
|
||||
$credit->save();
|
||||
|
||||
$invoice_calc = new InvoiceSum($credit);
|
||||
$invoice_calc->build();
|
||||
|
||||
$credit = $invoice_calc->getCredit();
|
||||
|
||||
$credit->save();
|
||||
$credit->service()->markSent()->save();
|
||||
$credit->service()->createInvitations();
|
||||
}
|
||||
|
||||
private function createQuote($client)
|
||||
{
|
||||
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$quote = Quote::factory()->create(['user_id' => $client->user->id, 'company_id' => $client->company->id, 'client_id' => $client->id]);
|
||||
$quote->date = $faker->date();
|
||||
$quote->client_id = $client->id;
|
||||
|
||||
$quote->setRelation('client', $client);
|
||||
|
||||
$quote->line_items = $this->buildLineItems(rand(1, 10));
|
||||
$quote->uses_inclusive_taxes = false;
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$quote->tax_name1 = 'GST';
|
||||
$quote->tax_rate1 = 10.00;
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$quote->tax_name2 = 'VAT';
|
||||
$quote->tax_rate2 = 17.50;
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$quote->tax_name3 = 'CA Sales Tax';
|
||||
$quote->tax_rate3 = 5;
|
||||
}
|
||||
|
||||
$quote->save();
|
||||
|
||||
$quote_calc = new InvoiceSum($quote);
|
||||
$quote_calc->build();
|
||||
|
||||
$quote = $quote_calc->getQuote();
|
||||
|
||||
$quote->save();
|
||||
|
||||
$quote->service()->markSent()->save();
|
||||
$quote->service()->createInvitations();
|
||||
}
|
||||
|
||||
private function buildLineItems($count = 1)
|
||||
{
|
||||
$line_items = [];
|
||||
|
||||
for ($x = 0; $x < $count; $x++) {
|
||||
$item = InvoiceItemFactory::create();
|
||||
$item->quantity = 1;
|
||||
//$item->cost = 10;
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$item->tax_name1 = 'GST';
|
||||
$item->tax_rate1 = 10.00;
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$item->tax_name1 = 'VAT';
|
||||
$item->tax_rate1 = 17.50;
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$item->tax_name1 = 'Sales Tax';
|
||||
$item->tax_rate1 = 5;
|
||||
}
|
||||
|
||||
$product = Product::all()->random();
|
||||
|
||||
$item->cost = (float) $product->cost;
|
||||
$item->product_key = $product->product_key;
|
||||
$item->notes = $product->notes;
|
||||
$item->custom_value1 = $product->custom_value1;
|
||||
$item->custom_value2 = $product->custom_value2;
|
||||
$item->custom_value3 = $product->custom_value3;
|
||||
$item->custom_value4 = $product->custom_value4;
|
||||
|
||||
$line_items[] = $item;
|
||||
}
|
||||
|
||||
return $line_items;
|
||||
}
|
||||
|
||||
private function warmCache()
|
||||
{
|
||||
/* Warm up the cache !*/
|
||||
$cached_tables = config('ninja.cached_tables');
|
||||
|
||||
foreach ($cached_tables as $name => $class) {
|
||||
if (! Cache::has($name)) {
|
||||
// check that the table exists in case the migration is pending
|
||||
if (! Schema::hasTable((new $class())->getTable())) {
|
||||
continue;
|
||||
}
|
||||
if ($name == 'payment_terms') {
|
||||
$orderBy = 'num_days';
|
||||
} elseif ($name == 'fonts') {
|
||||
$orderBy = 'sort_order';
|
||||
} elseif (in_array($name, ['currencies', 'industries', 'languages', 'countries', 'banks'])) {
|
||||
$orderBy = 'name';
|
||||
} else {
|
||||
$orderBy = 'id';
|
||||
}
|
||||
$tableData = $class::orderBy($orderBy)->get();
|
||||
if ($tableData->count()) {
|
||||
Cache::forever($name, $tableData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createGateways($company, $user)
|
||||
{
|
||||
|
||||
if (config('ninja.testvars.stripe') && ($this->gateway == 'all' || $this->gateway == 'stripe')) {
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $company->id;
|
||||
$cg->user_id = $user->id;
|
||||
$cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
||||
$cg->require_cvv = true;
|
||||
$cg->show_billing_address = true;
|
||||
$cg->show_shipping_address = true;
|
||||
$cg->update_details = true;
|
||||
$cg->config = encrypt(config('ninja.testvars.stripe'));
|
||||
$cg->save();
|
||||
|
||||
// $cg = new CompanyGateway;
|
||||
// $cg->company_id = $company->id;
|
||||
// $cg->user_id = $user->id;
|
||||
// $cg->gateway_key = 'd14dd26a37cecc30fdd65700bfb55b23';
|
||||
// $cg->require_cvv = true;
|
||||
// $cg->show_billing_address = true;
|
||||
// $cg->show_shipping_address = true;
|
||||
// $cg->update_details = true;
|
||||
// $cg->config = encrypt(config('ninja.testvars.stripe'));
|
||||
// $cg->save();
|
||||
}
|
||||
|
||||
if (config('ninja.testvars.paypal') && ($this->gateway == 'all' || $this->gateway == 'paypal')) {
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $company->id;
|
||||
$cg->user_id = $user->id;
|
||||
$cg->gateway_key = '38f2c48af60c7dd69e04248cbb24c36e';
|
||||
$cg->require_cvv = true;
|
||||
$cg->show_billing_address = true;
|
||||
$cg->show_shipping_address = true;
|
||||
$cg->update_details = true;
|
||||
$cg->config = encrypt(config('ninja.testvars.paypal'));
|
||||
$cg->save();
|
||||
}
|
||||
|
||||
if (config('ninja.testvars.checkout') && ($this->gateway == 'all' || $this->gateway == 'checkout')) {
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $company->id;
|
||||
$cg->user_id = $user->id;
|
||||
$cg->gateway_key = '3758e7f7c6f4cecf0f4f348b9a00f456';
|
||||
$cg->require_cvv = true;
|
||||
$cg->show_billing_address = true;
|
||||
$cg->show_shipping_address = true;
|
||||
$cg->update_details = true;
|
||||
$cg->config = encrypt(config('ninja.testvars.checkout'));
|
||||
$cg->save();
|
||||
}
|
||||
|
||||
if (config('ninja.testvars.authorize') && ($this->gateway == 'all' || $this->gateway == 'authorizenet')) {
|
||||
$cg = new CompanyGateway;
|
||||
$cg->company_id = $company->id;
|
||||
$cg->user_id = $user->id;
|
||||
$cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb';
|
||||
$cg->require_cvv = true;
|
||||
$cg->show_billing_address = true;
|
||||
$cg->show_shipping_address = true;
|
||||
$cg->update_details = true;
|
||||
$cg->config = encrypt(config('ninja.testvars.authorize'));
|
||||
$cg->save();
|
||||
}
|
||||
}
|
||||
}
|
57
app/DataMapper/Analytics/EmailFailure.php
Normal file
57
app/DataMapper/Analytics/EmailFailure.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\DataMapper\Analytics;
|
||||
|
||||
class EmailFailure
|
||||
{
|
||||
/**
|
||||
* The type of Sample.
|
||||
*
|
||||
* Monotonically incrementing counter
|
||||
*
|
||||
* - counter
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'mixed_metric';
|
||||
|
||||
/**
|
||||
* The name of the counter.
|
||||
* @var string
|
||||
*/
|
||||
public $name = 'job.failure.email';
|
||||
|
||||
/**
|
||||
* The datetime of the counter measurement.
|
||||
*
|
||||
* date("Y-m-d H:i:s")
|
||||
*
|
||||
* @var DateTime
|
||||
*/
|
||||
public $datetime;
|
||||
|
||||
/**
|
||||
* The Class failure name
|
||||
* set to 0.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $string_metric5 = '';
|
||||
|
||||
/**
|
||||
* The exception string
|
||||
* set to 0.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $string_metric6 = '';
|
||||
}
|
@ -158,6 +158,16 @@ class EmailTemplateDefaults
|
||||
|
||||
}
|
||||
|
||||
public static function emailPaymentPartialTemplate()
|
||||
{
|
||||
$converter = new CommonMarkConverter([
|
||||
'html_input' => 'strip',
|
||||
'allow_unsafe_links' => false,
|
||||
]);
|
||||
|
||||
return $converter->convertToHtml(self::transformText('payment_message'));
|
||||
}
|
||||
|
||||
public static function emailPaymentPartialSubject()
|
||||
{
|
||||
return ctrans('texts.payment_subject');
|
||||
|
@ -69,7 +69,7 @@ class PaymentController extends Controller
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$gateway = CompanyGateway::findOrFail('id', request()->input('company_gateway_id'));
|
||||
$gateway = CompanyGateway::findOrFail(request()->input('company_gateway_id'));
|
||||
|
||||
/*find invoices*/
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Jobs\Mail;
|
||||
|
||||
use App\DataMapper\Analytics\EmailFailure;
|
||||
use App\Libraries\Google\Google;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\User;
|
||||
@ -21,6 +22,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Turbo124\Beacon\Facades\LightLogs;
|
||||
|
||||
/*Multi Mailer implemented*/
|
||||
|
||||
@ -76,4 +78,18 @@ class BaseMailerJob implements ShouldQueue
|
||||
$recipient_object
|
||||
);
|
||||
}
|
||||
|
||||
public function failed($exception = null)
|
||||
{
|
||||
|
||||
info('the job failed');
|
||||
|
||||
$job_failure = new EmailFailure();
|
||||
$job_failure->string_metric5 = get_parent_class($this);
|
||||
$job_failure->string_metric6 = $exception->getMessage();
|
||||
|
||||
LightLogs::create($job_failure)
|
||||
->batch();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,6 @@ class Gateway extends StaticModel
|
||||
return $this->getMethods();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test if gateway is custom.
|
||||
* @return bool TRUE|FALSE
|
||||
|
@ -39,7 +39,7 @@ use Stripe\PaymentIntent;
|
||||
use Stripe\SetupIntent;
|
||||
use Stripe\Stripe;
|
||||
|
||||
class StripePaymentDriver extends BasePaymentDriver
|
||||
class StripePaymentDriver extends BaseDriver
|
||||
{
|
||||
use MakesHash, Utilities;
|
||||
|
||||
@ -54,7 +54,7 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
|
||||
protected $customer_reference = 'customerReferenceParam';
|
||||
|
||||
protected $payment_method;
|
||||
public $payment_method;
|
||||
|
||||
|
||||
public static $methods = [
|
||||
@ -319,7 +319,7 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
return $customer;
|
||||
}
|
||||
|
||||
public function refund(Payment $payment, $amount)
|
||||
public function refund(Payment $payment, $amount, $return_client_response = false)
|
||||
{
|
||||
$this->init();
|
||||
|
||||
@ -427,4 +427,11 @@ class StripePaymentDriver extends BasePaymentDriver
|
||||
], SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_STRIPE, $this->client);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getCompanyGatewayId(): int
|
||||
{
|
||||
return $this->company_gateway->id;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace App\Services\Invoice;
|
||||
|
||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||
use App\Jobs\Util\UnlinkFile;
|
||||
use App\Models\CompanyGateway;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
@ -211,7 +212,7 @@ class InvoiceService
|
||||
|
||||
public function updateStatus()
|
||||
{
|
||||
if($this->invoice->balance == 0)
|
||||
if((int)$this->invoice->balance == 0)
|
||||
$this->setStatus(Invoice::STATUS_PAID);
|
||||
|
||||
if($this->invoice->balance > 0 && $this->invoice->balance < $this->invoice->amount)
|
||||
@ -233,6 +234,15 @@ class InvoiceService
|
||||
|
||||
$this->invoice = $this->invoice->calc()->getInvoice();
|
||||
|
||||
$this->deletePdf();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function deletePdf()
|
||||
{
|
||||
UnlinkFile::dispatchNow(config('filesystems.default'),$this->invoice->client->invoice_filepath() . $this->invoice->number.'.pdf');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,10 @@ trait AppSetup
|
||||
'subject' => EmailTemplateDefaults::emailPaymentSubject(),
|
||||
'body' => EmailTemplateDefaults::emailPaymentTemplate(),
|
||||
],
|
||||
'payment_partial' => [
|
||||
'subject' => EmailTemplateDefaults::emailPaymentPartialSubject(),
|
||||
'body' => EmailTemplateDefaults::emailPaymentPartialTemplate(),
|
||||
],
|
||||
'reminder1' => [
|
||||
'subject' => EmailTemplateDefaults::emailReminder1Subject(),
|
||||
'body' => EmailTemplateDefaults::emailReminder1Template(),
|
||||
|
35
phpunit.xml
35
phpunit.xml
@ -1,37 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="true" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<coverage processUncoveredFiles="true">
|
||||
<include>
|
||||
<directory suffix=".php">./app</directory>
|
||||
</include>
|
||||
<exclude>
|
||||
<directory suffix=".php">./vendor</directory>
|
||||
<directory suffix=".php">./app/Providers</directory>
|
||||
<directory suffix=".php">./app/Http</directory>
|
||||
<directory suffix=".php">./app/Models</directory>
|
||||
<directory suffix=".php">./app/Transformers</directory>
|
||||
<directory suffix=".php">./app/Events</directory>
|
||||
<directory suffix=".php">./app/Observers</directory>
|
||||
<directory suffix=".php">./app/Policies</directory>
|
||||
<directory suffix=".php">./app/Jobs</directory>
|
||||
<directory suffix=".php">./app/Factory</directory>
|
||||
<directory suffix=".php">./app/Helpers</directory>
|
||||
<directory suffix=".php">./app/Libraries</directory>
|
||||
<directory suffix=".php">./app/Listeners</directory>
|
||||
<directory suffix=".php">./app/Mail</directory>
|
||||
<directory suffix=".php">./app/Notifications</directory>
|
||||
<directory suffix=".php">./app/Providers</directory>
|
||||
<directory suffix=".php">./app/Repositories</directory>
|
||||
<directory suffix=".php">./app/Filters</directory>
|
||||
<file>./app/Console/Kernel.php</file>
|
||||
<file>./app/Constants.php</file>
|
||||
<file>./app/Libraries/OFX.php</file>
|
||||
<file>./app/Exceptions/Handler.php</file>
|
||||
</exclude>
|
||||
<report>
|
||||
<clover outputFile="coverage.xml"/>
|
||||
</report>
|
||||
</coverage>
|
||||
|
||||
<testsuites>
|
||||
<testsuite name="Unit">
|
||||
<directory suffix="Test.php">./tests/Unit</directory>
|
||||
@ -53,6 +22,8 @@
|
||||
<env name="SESSION_DRIVER" value="array"/>
|
||||
<env name="QUEUE_CONNECTION" value="sync"/>
|
||||
<env name="MAIL_MAILER" value="array"/>
|
||||
<env name="DB_CONNECTION" value="sqlite"/>
|
||||
<env name="DB_DATABASE" value=":memory:"/>
|
||||
</php>
|
||||
<logging/>
|
||||
</phpunit>
|
||||
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Client;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||
use Laravel\Dusk\Browser;
|
||||
use Tests\DuskTestCase;
|
||||
|
||||
class PaymentMethods extends DuskTestCase
|
||||
{
|
||||
public function testAddPaymentMethodPage(): void
|
||||
{
|
||||
$this->browse(function (Browser $browser) {
|
||||
$browser->visit('/client/login')
|
||||
->type('email', 'user@example.com')
|
||||
->type('password', config('ninja.testvars.password'))
|
||||
->press('Login')
|
||||
->assertPathIs('/client/dashboard');
|
||||
|
||||
$browser->visit(route('client.payment_methods.index'))
|
||||
->waitFor('.dataTable')
|
||||
->waitFor('.dataTables_empty')
|
||||
->assertSee('No records found');
|
||||
|
||||
// TODO: Testing Stripe <iframe>
|
||||
|
||||
$browser->visit(route('client.payment_methods.create'))
|
||||
->assertSee('Add Payment Method')
|
||||
->assertSee('Save');
|
||||
});
|
||||
}
|
||||
}
|
@ -1,229 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\RecurringInvoice;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\DuskTestCase;
|
||||
|
||||
class ClientPortalTest extends DuskTestCase
|
||||
{
|
||||
use WithFaker;
|
||||
use MakesHash;
|
||||
|
||||
public $contact;
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
$this->browse(function ($browser) {
|
||||
$browser->driver->manage()->deleteAllCookies();
|
||||
});
|
||||
}
|
||||
|
||||
public function testLoginPageDisplayed()
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit('/client/login')
|
||||
->assertPathIs('/client/login');
|
||||
});
|
||||
}
|
||||
|
||||
public function testLoginAValidUser()
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit('/client/login')
|
||||
->type('email', 'user@example.com')
|
||||
->type('password', config('ninja.testvars.password'))
|
||||
->press('Login')
|
||||
->assertPathIs('/client/dashboard')
|
||||
->visit('client/logout')
|
||||
->assertPathIs('/client/login');
|
||||
});
|
||||
}
|
||||
|
||||
public function testDashboardElements(): void
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit('/client/login')
|
||||
->type('email', 'user@example.com')
|
||||
->type('password', config('ninja.testvars.password'))
|
||||
->press('Login')
|
||||
->assertPathIs('/client/dashboard');
|
||||
|
||||
$browser->visit('/client/dashboard')
|
||||
->assertSee(ctrans('texts.quick_overview_statistics'))
|
||||
->visit('client/logout')
|
||||
->assertPathIs('/client/login');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test list of invoices.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInvoicesElements(): void
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit('/client/login')
|
||||
->type('email', 'user@example.com')
|
||||
->type('password', config('ninja.testvars.password'))
|
||||
->press('Login')
|
||||
->assertPathIs('/client/dashboard');
|
||||
|
||||
$invoice = Invoice::first();
|
||||
|
||||
$browser->visit('/client/invoices')
|
||||
->assertSee(ctrans('texts.pay_now'))
|
||||
->assertSee($invoice->number)
|
||||
->clickLink(ctrans('texts.view'))
|
||||
->assertPathIs(route('client.invoice.show', $invoice->hashed_id, false))
|
||||
->assertSee(ctrans('texts.pay_now'));
|
||||
|
||||
$browser->visit('/client/invoices')
|
||||
->check('#paid')
|
||||
->assertSee(ctrans('texts.paid'))
|
||||
->visit('client/logout')
|
||||
->assertPathIs('/client/login');
|
||||
});
|
||||
}
|
||||
|
||||
public function testRecurringInvoicesElements(): void
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit('/client/login')
|
||||
->type('email', 'user@example.com')
|
||||
->type('password', config('ninja.testvars.password'))
|
||||
->press('Login')
|
||||
->assertPathIs('/client/dashboard');
|
||||
|
||||
$invoice = RecurringInvoice::first();
|
||||
|
||||
$browser->visit('/client/recurring_invoices')
|
||||
->assertSee(ctrans('texts.recurring_invoices'))
|
||||
->clickLink(ctrans('texts.view'))
|
||||
->assertPathIs(route('client.recurring_invoices.show', $invoice->hashed_id, false))
|
||||
->visit('/client/logout')
|
||||
->assertPathIs('/client/login');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* List of payments.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPaymentsElements(): void
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit('/client/login')
|
||||
->type('email', 'user@example.com')
|
||||
->type('password', config('ninja.testvars.password'))
|
||||
->press('Login')
|
||||
->assertPathIs('/client/dashboard');
|
||||
|
||||
$payment = Payment::first();
|
||||
|
||||
$browser->visit('/client/payments')
|
||||
->clickLink(ctrans('texts.view'))
|
||||
->assertPathIs(route('client.payments.show', $payment->hashed_id, false))
|
||||
->visit('/client/logout')
|
||||
->assertPathIs('/client/login');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* List of payment methods.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testPaymentMethodsElements(): void
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit('/client/login')
|
||||
->type('email', 'user@example.com')
|
||||
->type('password', config('ninja.testvars.password'))
|
||||
->press('Login')
|
||||
->assertPathIs('/client/dashboard');
|
||||
|
||||
$browser->visit('/client/payment_methods')
|
||||
->assertSee('No results found.')
|
||||
->visit('client/logout')
|
||||
->assertPathIs('/client/login');
|
||||
});
|
||||
}
|
||||
|
||||
public function testQuotesElements(): void
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit('/client/login')
|
||||
->type('email', 'user@example.com')
|
||||
->type('password', config('ninja.testvars.password'))
|
||||
->press('Login')
|
||||
->assertPathIs('/client/dashboard');
|
||||
|
||||
$credit = Credit::first();
|
||||
|
||||
$browser->visit('/client/quotes')
|
||||
->clickLink(ctrans('texts.view'))
|
||||
->assertPathIs(route('client.credits.show', $credit->hashed_id, false))
|
||||
->visit('client/logout')
|
||||
->assertPathIs('/client/login');
|
||||
});
|
||||
}
|
||||
|
||||
public function testCreditsElements(): void
|
||||
{
|
||||
$this->browse(function ($browser) {
|
||||
$browser->visit('/client/login')
|
||||
->type('email', 'user@example.com')
|
||||
->type('password', config('ninja.testvars.password'))
|
||||
->press('Login')
|
||||
->assertPathIs('/client/dashboard');
|
||||
|
||||
$browser->visit('/client/credits')
|
||||
->assertSee('No results found.')
|
||||
->visit('client/logout')
|
||||
->assertPathIs('/client/login');
|
||||
});
|
||||
}
|
||||
|
||||
public function testProfilePageContactUpdate(): void
|
||||
{
|
||||
$faker = \Faker\Factory::create();
|
||||
|
||||
$this->browse(function ($browser) use ($faker) {
|
||||
$browser->visit('/client/login')
|
||||
->type('email', 'user@example.com')
|
||||
->type('password', config('ninja.testvars.password'))
|
||||
->press('Login')
|
||||
->assertPathIs('/client/dashboard');
|
||||
|
||||
$client_contact = ClientContact::where('email', 'user@example.com')->first();
|
||||
|
||||
$browser->maximize();
|
||||
|
||||
$browser->visit(sprintf('/client/profile/%s/edit', $client_contact->client->user->hashed_id))
|
||||
->assertSee(ctrans('texts.profile'));
|
||||
|
||||
$first_name = $browser->value('#first_name');
|
||||
|
||||
$browser->value('#first_name', $faker->firstName);
|
||||
|
||||
$browser->assertSee(ctrans('texts.save'))
|
||||
->press(ctrans('texts.save'));
|
||||
|
||||
$this->assertNotEquals($first_name, $browser->value('#first_name'));
|
||||
|
||||
$browser->visit('client/logout')
|
||||
->assertPathIs('/client/login');
|
||||
});
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Pages;
|
||||
|
||||
use Laravel\Dusk\Browser;
|
||||
|
||||
class HomePage extends Page
|
||||
{
|
||||
/**
|
||||
* Get the URL for the page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function url()
|
||||
{
|
||||
return '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the browser is on the page.
|
||||
*
|
||||
* @param Browser $browser
|
||||
* @return void
|
||||
*/
|
||||
public function assert(Browser $browser)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the element shortcuts for the page.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function elements()
|
||||
{
|
||||
return [
|
||||
'@element' => '#selector',
|
||||
];
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Browser\Pages;
|
||||
|
||||
use Laravel\Dusk\Page as BasePage;
|
||||
|
||||
abstract class Page extends BasePage
|
||||
{
|
||||
/**
|
||||
* Get the global element shortcuts for the site.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function siteElements()
|
||||
{
|
||||
return [
|
||||
'@element' => '#selector',
|
||||
];
|
||||
}
|
||||
}
|
2
tests/Browser/console/.gitignore
vendored
2
tests/Browser/console/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
2
tests/Browser/screenshots/.gitignore
vendored
2
tests/Browser/screenshots/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Facebook\WebDriver\Chrome\ChromeOptions;
|
||||
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
||||
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||
use Laravel\Dusk\TestCase as BaseTestCase;
|
||||
|
||||
abstract class DuskTestCase extends BaseTestCase
|
||||
{
|
||||
use CreatesApplication;
|
||||
|
||||
/**
|
||||
* Prepare for Dusk test execution.
|
||||
*
|
||||
* @beforeClass
|
||||
* @return void
|
||||
*/
|
||||
public static function prepare()
|
||||
{
|
||||
static::startChromeDriver();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the RemoteWebDriver instance.
|
||||
*
|
||||
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
|
||||
*/
|
||||
protected function driver()
|
||||
{
|
||||
$options = (new ChromeOptions)->addArguments([
|
||||
'--disable-gpu',
|
||||
]);
|
||||
|
||||
return RemoteWebDriver::create(
|
||||
'http://localhost:9515',
|
||||
DesiredCapabilities::chrome()->setCapability(
|
||||
ChromeOptions::CAPABILITY,
|
||||
$options
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user