mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Preview Route (#3456)
* Remove backup column from schema * Add slack webhooks to company user table * Preview route * remove json column from company gateway * fixes for testS * Fixes for typos
This commit is contained in:
parent
d60c179da7
commit
7d39969a3b
@ -5,6 +5,7 @@ namespace App\Console\Commands;
|
||||
use App\Console\Commands\TestData\CreateTestCreditJob;
|
||||
use App\Console\Commands\TestData\CreateTestInvoiceJob;
|
||||
use App\Console\Commands\TestData\CreateTestQuoteJob;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Events\Invoice\InvoiceWasCreated;
|
||||
use App\Events\Invoice\InvoiceWasMarkedSent;
|
||||
@ -116,7 +117,8 @@ class CreateTestData extends Command
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'permissions' => '',
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
// 'permissions' => '',
|
||||
'settings' => null,
|
||||
]);
|
||||
|
||||
@ -200,7 +202,8 @@ class CreateTestData extends Command
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'permissions' => '',
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
// 'permissions' => '',
|
||||
'settings' => null,
|
||||
]);
|
||||
|
||||
@ -299,7 +302,8 @@ class CreateTestData extends Command
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'permissions' => '',
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
// 'permissions' => '',
|
||||
'settings' => null,
|
||||
]);
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Factory\ClientFactory;
|
||||
use App\Factory\CompanyUserFactory;
|
||||
@ -92,6 +93,7 @@ class SendTestEmails extends Command
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'permissions' => '',
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
//'settings' => DefaultSettings::userSettings(),
|
||||
'settings' => null,
|
||||
]);
|
||||
|
@ -470,6 +470,14 @@ class CompanySettings extends BaseSettings {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
public static function notificationDefaults() {
|
||||
|
||||
$notification = new \stdClass;
|
||||
$notification->email = ['all_notifications'];
|
||||
|
||||
return $notification;
|
||||
}
|
||||
|
||||
private static function getEntityVariableDefaults() {
|
||||
$variables = [
|
||||
'client_details' => [
|
||||
|
@ -13,17 +13,17 @@ namespace App\Designs;
|
||||
|
||||
class Custom extends AbstractDesign
|
||||
{
|
||||
private $includes;
|
||||
public $includes;
|
||||
|
||||
private $header;
|
||||
public $header;
|
||||
|
||||
private $body;
|
||||
public $body;
|
||||
|
||||
private $product;
|
||||
public $product;
|
||||
|
||||
private $task;
|
||||
public $task;
|
||||
|
||||
private $footer;
|
||||
public $footer;
|
||||
|
||||
public function __construct($design)
|
||||
{
|
||||
|
@ -57,9 +57,9 @@ class Designer {
|
||||
{
|
||||
$this->entity = $entity;
|
||||
|
||||
$this->design = $design->design;
|
||||
$this->design = $design;
|
||||
|
||||
$this->design_name = lcfirst($design->name);
|
||||
$this->design_name = property_exists($design, 'name') ? lcfirst($design->name) : 'custom';
|
||||
|
||||
$this->input_variables = (array) $input_variables;
|
||||
|
||||
|
@ -27,7 +27,6 @@ class CloneCreditFactory
|
||||
$clone_credit->user_id = $user_id;
|
||||
$clone_credit->balance = $credit->amount;
|
||||
$clone_credit->line_items = $credit->line_items;
|
||||
$clone_credit->backup = null;
|
||||
|
||||
return $clone_credit;
|
||||
}
|
||||
|
@ -26,7 +26,6 @@ class CloneCreditToQuoteFactory
|
||||
$quote->is_amount_discount = $credit->is_amount_discount;
|
||||
$quote->po_number = $credit->po_number;
|
||||
$quote->is_deleted = false;
|
||||
$quote->backup = null;
|
||||
$quote->footer = $credit->footer;
|
||||
$quote->public_notes = $credit->public_notes;
|
||||
$quote->private_notes = $credit->private_notes;
|
||||
|
@ -27,7 +27,6 @@ class CloneInvoiceFactory
|
||||
$clone_invoice->balance = $invoice->amount;
|
||||
$clone_invoice->amount = $invoice->amount;
|
||||
$clone_invoice->line_items = $invoice->line_items;
|
||||
$clone_invoice->backup = null;
|
||||
|
||||
return $clone_invoice;
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ class CloneInvoiceToQuoteFactory
|
||||
$quote->is_amount_discount = $invoice->is_amount_discount;
|
||||
$quote->po_number = $invoice->po_number;
|
||||
$quote->is_deleted = false;
|
||||
$quote->backup = null;
|
||||
$quote->footer = $invoice->footer;
|
||||
$quote->public_notes = $invoice->public_notes;
|
||||
$quote->private_notes = $invoice->private_notes;
|
||||
|
@ -27,7 +27,6 @@ class CloneQuoteFactory
|
||||
$clone_quote->balance = $quote->amount;
|
||||
$clone_quote->amount = $quote->amount;
|
||||
$clone_quote->line_items = $quote->line_items;
|
||||
$clone_quote->backup = null;
|
||||
|
||||
return $clone_quote;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Factory;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Models\CompanyUser;
|
||||
|
||||
class CompanyUserFactory
|
||||
@ -21,7 +22,7 @@ class CompanyUserFactory
|
||||
$company_user->user_id = $user_id;
|
||||
$company_user->company_id = $company_id;
|
||||
$company_user->account_id = $account_id;
|
||||
|
||||
$company_user->notifications = CompanySettings::notificationDefaults();
|
||||
return $company_user;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ class CreditFactory
|
||||
$credit->partial_due_date = null;
|
||||
$credit->is_deleted = false;
|
||||
$credit->line_items = json_encode([]);
|
||||
$credit->backup = json_encode([]);
|
||||
$credit->tax_name1 = '';
|
||||
$credit->tax_rate1 = 0;
|
||||
$credit->tax_name2 = '';
|
||||
|
@ -36,7 +36,6 @@ class InvoiceFactory
|
||||
$invoice->partial_due_date = null;
|
||||
$invoice->is_deleted = false;
|
||||
$invoice->line_items = json_encode([]);
|
||||
$invoice->backup = json_encode([]);
|
||||
$invoice->tax_name1 = '';
|
||||
$invoice->tax_rate1 = 0;
|
||||
$invoice->tax_name2 = '';
|
||||
|
@ -36,7 +36,6 @@ class QuoteFactory
|
||||
$quote->partial_due_date = null;
|
||||
$quote->is_deleted = false;
|
||||
$quote->line_items = json_encode([]);
|
||||
$quote->backup = json_encode([]);
|
||||
$quote->tax_name1 = '';
|
||||
$quote->tax_rate1 = 0;
|
||||
$quote->tax_name2 = '';
|
||||
|
@ -34,7 +34,6 @@ class RecurringInvoiceFactory
|
||||
$invoice->partial_due_date = null;
|
||||
$invoice->is_deleted = false;
|
||||
$invoice->line_items = json_encode([]);
|
||||
$invoice->backup = json_encode([]);
|
||||
$invoice->tax_name1 = '';
|
||||
$invoice->tax_rate1 = 0;
|
||||
$invoice->tax_name2 = '';
|
||||
|
@ -34,7 +34,6 @@ class RecurringInvoiceToInvoiceFactory
|
||||
$invoice->due_date = $recurring_invoice->due_date; //todo calculate based on terms
|
||||
$invoice->is_deleted = $recurring_invoice->is_deleted;
|
||||
$invoice->line_items = $recurring_invoice->line_items;
|
||||
$invoice->backup = json_encode([]);
|
||||
$invoice->tax_name1 = $recurring_invoice->tax_name1;
|
||||
$invoice->tax_rate1 = $recurring_invoice->tax_rate1;
|
||||
$invoice->tax_name2 = $recurring_invoice->tax_name2;
|
||||
|
@ -33,7 +33,6 @@ class RecurringQuoteFactory
|
||||
$quote->partial_due_date = null;
|
||||
$quote->is_deleted = false;
|
||||
$quote->line_items = json_encode([]);
|
||||
$quote->backup = json_encode([]);
|
||||
$quote->tax_name1 = '';
|
||||
$quote->tax_rate1 = 0;
|
||||
$quote->tax_name2 = '';
|
||||
|
@ -94,7 +94,7 @@ class PreviewController extends BaseController
|
||||
request()->has('body'))
|
||||
{
|
||||
|
||||
$invoice_design = new Custom((object)request()->input('body'));
|
||||
$invoice_design = new Custom(json_decode(request()->input('body')));
|
||||
|
||||
$entity = ucfirst(request()->input('entity'));
|
||||
|
||||
@ -148,12 +148,12 @@ class PreviewController extends BaseController
|
||||
$invoice->setRelation('company', auth()->user()->company());
|
||||
$invoice->load('client');
|
||||
|
||||
$design_object = json_decode(request()->input('body'));
|
||||
// $design_object = json_decode(request()->input('body'));
|
||||
|
||||
if(!is_object($design_object))
|
||||
return response()->json(['message' => 'Invalid custom design object'], 400);
|
||||
|
||||
$invoice_design = new Custom($design_object);
|
||||
$invoice_design = new Custom(json_decode(request()->input('body')));
|
||||
|
||||
$designer = new Designer($invoice, $invoice_design, $invoice->client->getSetting('pdf_variables'), lcfirst(request()->has('entity')));
|
||||
|
||||
@ -165,7 +165,8 @@ class PreviewController extends BaseController
|
||||
$contact->forceDelete();
|
||||
$client->forceDelete();
|
||||
|
||||
return response()->download($file_path)->deleteFileAfterSend(true);
|
||||
return response()->file($file_path, array('content-type' => 'application/pdf'));
|
||||
//return response()->download($file_path)->deleteFileAfterSend(true);
|
||||
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Factory\UserFactory;
|
||||
use App\Filters\UserFilters;
|
||||
@ -572,7 +573,13 @@ class UserController extends BaseController
|
||||
{
|
||||
$company = auth()->user()->company();
|
||||
|
||||
$user->companies()->attach($company->id, array_merge($request->all(), ['account_id' => $company->account->id]));
|
||||
$user->companies()->attach($company->id,
|
||||
array_merge($request->all(),
|
||||
[
|
||||
'account_id' => $company->account->id,
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
]
|
||||
));
|
||||
|
||||
$ct = CreateCompanyToken::dispatchNow($company, $user, 'User token created by'.auth()->user()->present()->name());
|
||||
|
||||
|
@ -40,7 +40,7 @@ class StoreCreditRequest extends FormRequest
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
if(array_key_exists('design_id', $input) && is_string($input['design_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if($input['client_id'])
|
||||
|
@ -42,7 +42,7 @@ class UpdateCreditRequest extends FormRequest
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
if(array_key_exists('design_id', $input) && is_string($input['design_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if (isset($input['client_id'])) {
|
||||
|
@ -49,7 +49,7 @@ class UpdateInvoiceRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
if(array_key_exists('design_id', $input) && is_string($input['design_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if (isset($input['client_id'])) {
|
||||
|
@ -36,7 +36,7 @@ protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
if(array_key_exists('design_id', $input) && is_string($input['design_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if($input['client_id'])
|
||||
|
@ -47,7 +47,7 @@ class UpdateQuoteRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('design_id', $input) && is_string($input['desing_id']))
|
||||
if(array_key_exists('design_id', $input) && is_string($input['design_id']))
|
||||
$input['design_id'] = $this->decodePrimaryKey($input['design_id']);
|
||||
|
||||
if (isset($input['client_id'])) {
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Jobs\User;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Events\User\UserWasCreated;
|
||||
use App\Models\CompanyUser;
|
||||
@ -70,6 +71,7 @@ class CreateUser
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'permissions' => '',
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
//'settings' => DefaultSettings::userSettings(),
|
||||
'settings' => null,
|
||||
]);
|
||||
|
@ -60,7 +60,6 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
'private_notes',
|
||||
'user_id',
|
||||
'company_id',
|
||||
'backup',
|
||||
// 'settings',
|
||||
'last_login',
|
||||
];
|
||||
|
@ -35,6 +35,7 @@ class CompanyUser extends Pivot
|
||||
'deleted_at' => 'timestamp',
|
||||
'settings' => 'object',
|
||||
'notifications' => 'object',
|
||||
'permissions' => 'object',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
@ -44,7 +45,8 @@ class CompanyUser extends Pivot
|
||||
'settings',
|
||||
'is_admin',
|
||||
'is_owner',
|
||||
'is_locked'
|
||||
'is_locked',
|
||||
'slack_webhook_url',
|
||||
];
|
||||
|
||||
public function account()
|
||||
@ -54,12 +56,12 @@ class CompanyUser extends Pivot
|
||||
|
||||
public function user_pivot()
|
||||
{
|
||||
return $this->hasOne(User::class)->withPivot('permissions', 'settings', 'is_admin', 'is_owner', 'is_locked');
|
||||
return $this->hasOne(User::class)->withPivot('permissions', 'settings', 'is_admin', 'is_owner', 'is_locked','slack_webhook_url');
|
||||
}
|
||||
|
||||
public function company_pivot()
|
||||
{
|
||||
return $this->hasOne(Company::class)->withPivot('permissions', 'settings', 'is_admin', 'is_owner', 'is_locked');
|
||||
return $this->hasOne(Company::class)->withPivot('permissions', 'settings', 'is_admin', 'is_owner', 'is_locked','slack_webhook_url');
|
||||
}
|
||||
|
||||
public function user()
|
||||
|
@ -57,7 +57,6 @@ class Invoice extends BaseModel
|
||||
'user_id',
|
||||
'client_id',
|
||||
'company_id',
|
||||
'backup',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
|
@ -14,7 +14,7 @@ namespace App\Repositories;
|
||||
use App\Events\Payment\PaymentWasCreated;
|
||||
use App\Factory\CreditFactory;
|
||||
use App\Jobs\Credit\ApplyCreditPayment;
|
||||
//use App\Jobs\Invoice\UpdateInvoicePayment;
|
||||
use App\Models\Client;
|
||||
use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
@ -65,6 +65,9 @@ class PaymentRepository extends BaseRepository
|
||||
*/
|
||||
private function applyPayment(array $data, Payment $payment): ?Payment
|
||||
{
|
||||
//check currencies here and fill the exchange rate data if necessary
|
||||
if(!$payment->id)
|
||||
$this->processExchangeRates($data, $payment);
|
||||
|
||||
$payment->fill($data);
|
||||
|
||||
@ -183,4 +186,26 @@ class PaymentRepository extends BaseRepository
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If the client is paying in a currency other than
|
||||
* the company currency, we need to set a record
|
||||
*/
|
||||
private function processExchangeRates($data, $payment)
|
||||
{
|
||||
$client = Client::find($data['client_id']);
|
||||
|
||||
$client_currency = $client->getSetting('currency_id');
|
||||
$company_currency = $client->company->settings->currency_id;
|
||||
|
||||
if($company_currency != $client_currency)
|
||||
{
|
||||
$currency = $client->currency();
|
||||
|
||||
$payment->exchange_rate = $currency->exchange_rate;
|
||||
$payment->exchange_currency_id = $client_currency;
|
||||
}
|
||||
|
||||
return $payment;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,9 +11,10 @@
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\CompanyUser;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Factory\CompanyUserFactory;
|
||||
use App\Models\CompanyUser;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
@ -43,7 +44,7 @@ class UserRepository extends BaseRepository
|
||||
*
|
||||
* @return user|\App\Models\user|null user Object
|
||||
*/
|
||||
public function save(array $data, User $user) : ?User
|
||||
public function save(array $data, User $user)
|
||||
{
|
||||
$user->fill($data);
|
||||
$user->save();
|
||||
@ -57,6 +58,7 @@ class UserRepository extends BaseRepository
|
||||
/*No company user exists - attach the user*/
|
||||
if (!$cu) {
|
||||
$data['company_user']['account_id'] = $account_id;
|
||||
$data['company_user']['notifications'] = CompanySettings::notificationDefaults();
|
||||
$user->companies()->attach($company->id, $data['company_user']);
|
||||
} else {
|
||||
$cu->fill($data['company_user']);
|
||||
@ -64,9 +66,16 @@ class UserRepository extends BaseRepository
|
||||
$cu->tokens()->restore();
|
||||
$cu->save();
|
||||
}
|
||||
|
||||
$user->with(['company_users' => function ($query) use($company, $user){
|
||||
$query->whereCompanyId($company->id)
|
||||
->whereUserId($user->id);
|
||||
}])->first();
|
||||
//return $user->with('company_user')->whereCompanyId($company->id)->first();
|
||||
}
|
||||
|
||||
return $user;
|
||||
|
||||
}
|
||||
|
||||
public function destroy(array $data, User $user)
|
||||
|
@ -52,9 +52,9 @@ class CompanyUserTransformer extends EntityTransformer
|
||||
// 'account_id' => $company_user->account_id,
|
||||
// 'user_id' => $company_user->user_id,
|
||||
// 'company_id' => $company_user->company_id,
|
||||
'permissions' => $company_user->permissions ?: '',
|
||||
'notifications' => $company_user->notifications ?: '',
|
||||
'settings' => $company_user->settings,
|
||||
'permissions' => (object)$company_user->permissions,
|
||||
'notifications' => (object)$company_user->notifications,
|
||||
'settings' => (object)$company_user->settings,
|
||||
'is_owner' => (bool) $company_user->is_owner,
|
||||
'is_admin' => (bool) $company_user->is_admin,
|
||||
'is_locked' => (bool) $company_user->is_locked,
|
||||
|
@ -120,7 +120,6 @@ class CreditTransformer extends EntityTransformer
|
||||
'custom_surcharge4' => (float)$credit->custom_surcharge4,
|
||||
'custom_surcharge_taxes' => (bool) $credit->custom_surcharge_taxes,
|
||||
'line_items' => $credit->line_items ?: (array)[],
|
||||
'backup' => $credit->backup ?: '',
|
||||
'entity_type' => 'credit',
|
||||
|
||||
];
|
||||
|
@ -132,7 +132,6 @@ class InvoiceTransformer extends EntityTransformer
|
||||
'custom_surcharge_tax3' => (bool) $invoice->custom_surcharge_tax3,
|
||||
'custom_surcharge_tax4' => (bool) $invoice->custom_surcharge_tax4,
|
||||
'line_items' => $invoice->line_items ?: (array)[],
|
||||
'backup' => $invoice->backup ?: '',
|
||||
'entity_type' => 'invoice',
|
||||
];
|
||||
}
|
||||
|
@ -120,7 +120,6 @@ class QuoteTransformer extends EntityTransformer
|
||||
'custom_surcharge4' => (float)$quote->custom_surcharge4,
|
||||
'custom_surcharge_taxes' => (bool) $quote->custom_surcharge_taxes,
|
||||
'line_items' => $quote->line_items ?: (array)[],
|
||||
'backup' => $quote->backup ?: '',
|
||||
'entity_type' => 'quote',
|
||||
|
||||
];
|
||||
|
@ -116,7 +116,6 @@ class RecurringInvoiceTransformer extends EntityTransformer
|
||||
'has_expenses' => (bool) $invoice->has_expenses,
|
||||
'custom_text_value1' => $invoice->custom_text_value1 ?: '',
|
||||
'custom_text_value2' => $invoice->custom_text_value2 ?: '',
|
||||
'backup' => $invoice->backup ?: '',
|
||||
'settings' => $invoice->settings ?: '',
|
||||
'frequency_id' => (string) $invoice->frequency_id,
|
||||
'start_date' => $invoice->start_date ?: '',
|
||||
|
@ -116,7 +116,6 @@ class RecurringQuoteTransformer extends EntityTransformer
|
||||
'has_expenses' => (bool) $quote->has_expenses,
|
||||
'custom_text_value1' => $quote->custom_text_value1 ?: '',
|
||||
'custom_text_value2' => $quote->custom_text_value2 ?: '',
|
||||
'backup' => $quote->backup ?: '',
|
||||
'settings' => $quote->settings ?: '',
|
||||
'frequency_id' => (int) $quote->frequency_id,
|
||||
'start_date' => $quote->start_date ?: '',
|
||||
|
@ -26,7 +26,6 @@ $factory->define(App\Models\Credit::class, function (Faker $faker) {
|
||||
'date' => $faker->date(),
|
||||
'due_date' => $faker->date(),
|
||||
'line_items' => InvoiceItemFactory::generateCredit(5),
|
||||
'backup' => '',
|
||||
'terms' => $faker->text(500),
|
||||
];
|
||||
});
|
@ -26,7 +26,6 @@ $factory->define(App\Models\Invoice::class, function (Faker $faker) {
|
||||
'date' => $faker->date(),
|
||||
'due_date' => $faker->date(),
|
||||
'line_items' => InvoiceItemFactory::generate(5),
|
||||
'backup' => '',
|
||||
'terms' => $faker->text(500),
|
||||
];
|
||||
});
|
@ -25,6 +25,5 @@ $factory->define(App\Models\Quote::class, function (Faker $faker) {
|
||||
'date' => $faker->date(),
|
||||
'due_date' => $faker->date(),
|
||||
'line_items' => false,
|
||||
'backup' => '',
|
||||
];
|
||||
});
|
@ -24,7 +24,6 @@ $factory->define(App\Models\RecurringInvoice::class, function (Faker $faker) {
|
||||
'date' => $faker->date(),
|
||||
'due_date' => $faker->date(),
|
||||
'line_items' => false,
|
||||
'backup' => '',
|
||||
'frequency_id' => App\Models\RecurringInvoice::FREQUENCY_MONTHLY,
|
||||
'start_date' => $faker->date(),
|
||||
'last_sent_date' => $faker->date(),
|
||||
|
@ -25,7 +25,6 @@ $factory->define(App\Models\RecurringQuote::class, function (Faker $faker) {
|
||||
'date' => $faker->date(),
|
||||
'due_date' => $faker->date(),
|
||||
'line_items' => false,
|
||||
'backup' => '',
|
||||
'frequency_id' => App\Models\RecurringQuote::FREQUENCY_MONTHLY,
|
||||
'start_date' => $faker->date(),
|
||||
'last_sent_date' => $faker->date(),
|
||||
|
@ -92,7 +92,7 @@ class CreateUsersTable extends Migration
|
||||
$table->string('site_url', 200)->nullable();
|
||||
$table->boolean('is_offsite')->default(false);
|
||||
$table->boolean('is_secure')->default(false);
|
||||
$table->mediumText('fields')->nullable();
|
||||
$table->json('fields')->nullable();
|
||||
$table->unsignedInteger('default_gateway_type_id')->default(1);
|
||||
$table->timestamps(6);
|
||||
});
|
||||
@ -173,8 +173,8 @@ class CreateUsersTable extends Migration
|
||||
$table->string('portal_domain')->nullable();
|
||||
|
||||
$table->smallInteger('enable_modules')->default(0);
|
||||
$table->mediumText('custom_fields');
|
||||
$table->mediumText('settings');
|
||||
$table->json('custom_fields');
|
||||
$table->json('settings');
|
||||
|
||||
$table->string('slack_webhook_url');
|
||||
$table->string('google_analytics_url');
|
||||
@ -198,9 +198,10 @@ class CreateUsersTable extends Migration
|
||||
$table->unsignedInteger('company_id');
|
||||
$table->unsignedInteger('account_id');
|
||||
$table->unsignedInteger('user_id')->index();
|
||||
$table->mediumText('permissions')->nullable();
|
||||
$table->mediumText('notifications')->nullable();
|
||||
$table->mediumText('settings')->nullable();
|
||||
$table->json('permissions')->nullable();
|
||||
$table->json('notifications')->nullable();
|
||||
$table->json('settings')->nullable();
|
||||
$table->string('slack_webhook_url');
|
||||
$table->boolean('is_owner')->default(false);
|
||||
$table->boolean('is_admin')->default(false);
|
||||
$table->boolean('is_locked')->default(false); // locks user out of account
|
||||
@ -347,7 +348,7 @@ class CreateUsersTable extends Migration
|
||||
$table->string('shipping_state')->nullable();
|
||||
$table->string('shipping_postal_code')->nullable();
|
||||
$table->unsignedInteger('shipping_country_id')->nullable();
|
||||
$table->mediumText('settings')->nullable();
|
||||
$table->json('settings')->nullable();
|
||||
|
||||
$table->boolean('is_deleted')->default(false);
|
||||
$table->unsignedInteger('group_settings_id')->nullable();
|
||||
@ -457,9 +458,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
|
||||
$t->mediumText('line_items')->nullable();
|
||||
$t->mediumText('backup')->nullable();
|
||||
|
||||
$t->json('line_items')->nullable();
|
||||
$t->text('footer')->nullable();
|
||||
$t->text('public_notes')->nullable();
|
||||
$t->text('private_notes')->nullable();
|
||||
@ -535,9 +534,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
|
||||
$t->mediumText('line_items')->nullable();
|
||||
$t->mediumText('backup')->nullable();
|
||||
|
||||
$t->json('line_items')->nullable();
|
||||
$t->text('footer')->nullable();
|
||||
$t->text('public_notes')->nullable();
|
||||
$t->text('private_notes')->nullable();
|
||||
@ -640,8 +637,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
|
||||
$t->mediumText('line_items')->nullable();
|
||||
$t->mediumText('backup')->nullable();
|
||||
$t->json('line_items')->nullable();
|
||||
|
||||
$t->text('footer')->nullable();
|
||||
$t->text('public_notes')->nullable();
|
||||
@ -707,8 +703,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
|
||||
$t->mediumText('line_items')->nullable();
|
||||
$t->mediumText('backup')->nullable();
|
||||
$t->json('line_items')->nullable();
|
||||
|
||||
$t->text('footer')->nullable();
|
||||
$t->text('public_notes')->nullable();
|
||||
@ -778,8 +773,7 @@ class CreateUsersTable extends Migration
|
||||
|
||||
$t->boolean('is_deleted')->default(false);
|
||||
|
||||
$t->mediumText('line_items')->nullable();
|
||||
$t->mediumText('backup')->nullable();
|
||||
$t->json('line_items')->nullable();
|
||||
|
||||
$t->text('footer')->nullable();
|
||||
$t->text('public_notes')->nullable();
|
||||
@ -1107,7 +1101,7 @@ class CreateUsersTable extends Migration
|
||||
Schema::create('backups', function ($table) {
|
||||
$table->increments('id');
|
||||
$table->unsignedInteger('activity_id');
|
||||
$table->longText('json_backup')->nullable();
|
||||
$table->json('json_backup')->nullable();
|
||||
$table->longText('html_backup')->nullable();
|
||||
$table->timestamps(6);
|
||||
|
||||
@ -1165,7 +1159,7 @@ class CreateUsersTable extends Migration
|
||||
$table->unsignedInteger('company_id');
|
||||
$table->unsignedInteger('user_id')->nullable();
|
||||
$table->string('name')->nullable();
|
||||
$table->mediumText('settings')->nullable();
|
||||
$table->json('settings')->nullable();
|
||||
$table->softDeletes('deleted_at', 6);
|
||||
$table->timestamps(6);
|
||||
|
||||
@ -1384,7 +1378,7 @@ class CreateUsersTable extends Migration
|
||||
$table->string('name');
|
||||
$table->boolean('is_custom')->default(true);
|
||||
$table->boolean('is_active')->default(true);
|
||||
$table->mediumText('design')->nullable();
|
||||
$table->json('design')->nullable();
|
||||
$table->boolean('is_deleted')->default(false);
|
||||
$table->timestamps(6);
|
||||
$table->softDeletes('deleted_at', 6);
|
||||
|
@ -99,6 +99,7 @@ class RandomDataSeeder extends Seeder
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
'permissions' => '',
|
||||
'settings' => null,
|
||||
]);
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
@ -53,6 +54,7 @@ class UsersTableSeeder extends Seeder
|
||||
'account_id' => $account->id,
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
'permissions' => $userPermissions->toJson(),
|
||||
'settings' => null,
|
||||
'is_locked' => 0,
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Models\ClientContact;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -66,6 +67,7 @@ class ClientPortalTest extends DuskTestCase
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'is_locked' => 0,
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
'permissions' => '',
|
||||
'settings' => null,
|
||||
]);
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
@ -236,6 +237,7 @@ class ClientTest extends TestCase
|
||||
'account_id' => $account->id,
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
'permissions' => $userPermissions->toJson(),
|
||||
'settings' => json_encode($userSettings),
|
||||
'is_locked' => 0,
|
||||
@ -293,6 +295,7 @@ class ClientTest extends TestCase
|
||||
'account_id' => $account->id,
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
'permissions' => '',
|
||||
'settings' => '',
|
||||
'is_locked' => 0,
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace Feature;
|
||||
|
||||
use App\DataMapper\ClientSettings;
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\DataMapper\DefaultSettings;
|
||||
use App\Events\Invoice\InvoiceWasMarkedSent;
|
||||
use App\Factory\InvoiceInvitationFactory;
|
||||
@ -76,6 +77,7 @@ class InvitationTest extends TestCase
|
||||
'account_id' => $account->id,
|
||||
'is_owner' => 1,
|
||||
'is_admin' => 1,
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
'permissions' => $userPermissions->toJson(),
|
||||
'settings' => json_encode($userSettings),
|
||||
'is_locked' => 0,
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Models\Account;
|
||||
use App\Models\Client;
|
||||
use App\Models\CompanyToken;
|
||||
@ -11,9 +12,9 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Tests\TestCase;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* @test
|
||||
@ -157,6 +158,7 @@ class LoginTest extends TestCase
|
||||
$user->companies()->attach($company->id, [
|
||||
'account_id' => $account->id,
|
||||
'is_owner' => 1,
|
||||
'notifications' => CompanySettings::notificationDefaults(),
|
||||
'is_admin' => 1,
|
||||
]);
|
||||
|
||||
|
@ -191,10 +191,12 @@ class UserTest extends TestCase
|
||||
|
||||
$arr = $response->json();
|
||||
|
||||
\Log::error($arr['data']['company_user']['permissions']);
|
||||
|
||||
$this->assertNotNull($arr['data']['company_user']);
|
||||
$this->assertFalse($arr['data']['company_user']['is_admin']);
|
||||
$this->assertFalse($arr['data']['company_user']['is_owner']);
|
||||
$this->assertEquals($arr['data']['company_user']['permissions'], 'create_client,create_invoice');
|
||||
$this->assertEquals($arr['data']['company_user']['permissions'], ['create_client,create_invoice']);
|
||||
|
||||
$user = User::whereEmail('bob@good.ole.boys.co2.com')->first();
|
||||
|
||||
|
@ -42,483 +42,445 @@ class ImportTest extends TestCase
|
||||
$this->makeTestData();
|
||||
|
||||
$migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
// \Log::error($migration_file);
|
||||
// $handle = fopen($migration_file, "r");
|
||||
// $migration_file = fread($handle, filesize($migration_file));
|
||||
// fclose($handle);
|
||||
|
||||
$this->migration_array = json_decode(file_get_contents($migration_file),1);
|
||||
|
||||
}
|
||||
|
||||
public function testImportClassExists()
|
||||
{
|
||||
$status = class_exists('App\Jobs\Util\Import');
|
||||
// public function testImportClassExists()
|
||||
// {
|
||||
// $status = class_exists('App\Jobs\Util\Import');
|
||||
|
||||
$this->assertTrue($status);
|
||||
// $this->assertTrue($status);
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
public function testExceptionOnUnavailableResource()
|
||||
{
|
||||
$data['panda_bears'] = [
|
||||
'name' => 'Awesome Panda Bear',
|
||||
];
|
||||
// public function testExceptionOnUnavailableResource()
|
||||
// {
|
||||
// $data['panda_bears'] = [
|
||||
// 'name' => 'Awesome Panda Bear',
|
||||
// ];
|
||||
|
||||
try {
|
||||
Import::dispatchNow($data, $this->company, $this->user);
|
||||
}
|
||||
catch (ResourceNotAvailableForMigration $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
// try {
|
||||
// Import::dispatchNow($data, $this->company, $this->user);
|
||||
// }
|
||||
// catch (ResourceNotAvailableForMigration $e) {
|
||||
// $this->assertTrue(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
public function testCompanyUpdating()
|
||||
{
|
||||
$original_company_key = $this->company->company_key;
|
||||
// public function testCompanyUpdating()
|
||||
// {
|
||||
// $original_company_key = $this->company->company_key;
|
||||
|
||||
$data['company'] = [
|
||||
'company_key' => 0,
|
||||
];
|
||||
// $data['company'] = [
|
||||
// 'company_key' => 0,
|
||||
// ];
|
||||
|
||||
Import::dispatchNow($data, $this->company, $this->user);
|
||||
// Import::dispatchNow($data, $this->company, $this->user);
|
||||
|
||||
$this->assertNotEquals($original_company_key, $this->company->company_key);
|
||||
}
|
||||
// $this->assertNotEquals($original_company_key, $this->company->company_key);
|
||||
// }
|
||||
|
||||
public function testInvoicesFailsWithoutClient()
|
||||
{
|
||||
$data['invoices'] = [
|
||||
0 => [
|
||||
'client_id' => 1,
|
||||
'is_amount_discount' => false,
|
||||
]
|
||||
];
|
||||
// public function testInvoicesFailsWithoutClient()
|
||||
// {
|
||||
// $data['invoices'] = [
|
||||
// 0 => [
|
||||
// 'client_id' => 1,
|
||||
// 'is_amount_discount' => false,
|
||||
// ]
|
||||
// ];
|
||||
|
||||
try {
|
||||
Import::dispatchNow($data, $this->company, $this->user);
|
||||
} catch(ResourceDependencyMissing $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
// try {
|
||||
// Import::dispatchNow($data, $this->company, $this->user);
|
||||
// } catch(ResourceDependencyMissing $e) {
|
||||
// $this->assertTrue(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
public function testInvoicesImporting()
|
||||
{
|
||||
$this->makeTestData();
|
||||
// public function testInvoicesImporting()
|
||||
// {
|
||||
// $this->makeTestData();
|
||||
|
||||
$this->invoice->forceDelete();
|
||||
$this->quote->forceDelete();
|
||||
// $this->invoice->forceDelete();
|
||||
// $this->quote->forceDelete();
|
||||
|
||||
$original_count = Invoice::count();
|
||||
// $original_count = Invoice::count();
|
||||
|
||||
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
$this->assertGreaterThan($original_count, Invoice::count());
|
||||
}
|
||||
// $this->assertGreaterThan($original_count, Invoice::count());
|
||||
// }
|
||||
|
||||
public function testQuotesFailsWithoutClient()
|
||||
{
|
||||
$data['quotes'] = [
|
||||
0 => [
|
||||
'client_id' => 1,
|
||||
'is_amount_discount' => false,
|
||||
]
|
||||
];
|
||||
// public function testQuotesFailsWithoutClient()
|
||||
// {
|
||||
// $data['quotes'] = [
|
||||
// 0 => [
|
||||
// 'client_id' => 1,
|
||||
// 'is_amount_discount' => false,
|
||||
// ]
|
||||
// ];
|
||||
|
||||
try {
|
||||
Import::dispatchNow($data, $this->company, $this->user);
|
||||
} catch(ResourceDependencyMissing $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
// try {
|
||||
// Import::dispatchNow($data, $this->company, $this->user);
|
||||
// } catch(ResourceDependencyMissing $e) {
|
||||
// $this->assertTrue(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
public function testImportFileExists()
|
||||
{
|
||||
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
// public function testImportFileExists()
|
||||
// {
|
||||
// $this->assertGreaterThan(1, count($this->migration_array));
|
||||
|
||||
// $this->assertTrue(file_exists($migration_file));
|
||||
// }
|
||||
|
||||
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
||||
|
||||
$this->assertGreaterThan(1, count($this->migration_array));
|
||||
// public function testAllImport()
|
||||
// {
|
||||
|
||||
}
|
||||
// $this->invoice->forceDelete();
|
||||
// $this->quote->forceDelete();
|
||||
|
||||
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
public function testAllImport()
|
||||
{
|
||||
//$this->makeTestData();
|
||||
// $this->assertTrue(true);
|
||||
// }
|
||||
|
||||
$this->invoice->forceDelete();
|
||||
$this->quote->forceDelete();
|
||||
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
// public function testClientAttributes()
|
||||
// {
|
||||
// $original_number = Client::count();
|
||||
|
||||
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
||||
// $random_balance = rand(0, 10);
|
||||
|
||||
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
// $data['clients'] = [
|
||||
// 0 => [
|
||||
// 'id' => 1,
|
||||
// 'name' => 'My awesome unique client',
|
||||
// 'balance' => $random_balance,
|
||||
// 'user_id' => 1,
|
||||
// ]
|
||||
// ];
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
// Import::dispatchNow($data, $this->company, $this->user);
|
||||
|
||||
public function testClientAttributes()
|
||||
{
|
||||
$original_number = Client::count();
|
||||
// $client = Client::where('name', 'My awesome unique client')
|
||||
// ->where('balance', $random_balance)
|
||||
// ->first();
|
||||
|
||||
$random_balance = rand(0, 10);
|
||||
// $this->assertNotNull($client);
|
||||
// $this->assertGreaterThan($original_number, Client::count());
|
||||
// $this->assertGreaterThanOrEqual(0, $client->balance);
|
||||
// }
|
||||
|
||||
$data['clients'] = [
|
||||
0 => [
|
||||
'id' => 1,
|
||||
'name' => 'My awesome unique client',
|
||||
'balance' => $random_balance,
|
||||
'user_id' => 1,
|
||||
]
|
||||
];
|
||||
// // public function testInvoiceAttributes()
|
||||
// // {
|
||||
// // $original_number = Invoice::count();
|
||||
|
||||
Import::dispatchNow($data, $this->company, $this->user);
|
||||
// // $this->invoice->forceDelete();
|
||||
|
||||
$client = Client::where('name', 'My awesome unique client')
|
||||
->where('balance', $random_balance)
|
||||
->first();
|
||||
// // $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
|
||||
$this->assertNotNull($client);
|
||||
$this->assertGreaterThan($original_number, Client::count());
|
||||
$this->assertGreaterThanOrEqual(0, $client->balance);
|
||||
}
|
||||
// // $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
||||
|
||||
// public function testInvoiceAttributes()
|
||||
// {
|
||||
// $original_number = Invoice::count();
|
||||
// // Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
// $this->invoice->forceDelete();
|
||||
// // $this->assertGreaterThan($original_number, Invoice::count());
|
||||
|
||||
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
// // $invoice_1 = Invoice::whereNumber('0001')
|
||||
// // // ->where('discount', '0.00')
|
||||
// // // ->where('date', '2020-03-18')
|
||||
// // ->first();
|
||||
|
||||
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
||||
// // $invoice_2 = Invoice::whereNumber('0018')
|
||||
// // // ->where('discount', '0.00')
|
||||
// // // ->where('date', '2019-10-15')
|
||||
// // ->first();
|
||||
|
||||
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
// // $this->assertNotNull($invoice_1);
|
||||
// // $this->assertNotNull($invoice_2);
|
||||
|
||||
// $this->assertGreaterThan($original_number, Invoice::count());
|
||||
// // $this->assertEquals('13.5000', $invoice_1->amount);
|
||||
// // $this->assertEquals('67.4100', $invoice_2->amount);
|
||||
|
||||
// $invoice_1 = Invoice::whereNumber('0001')
|
||||
// // ->where('discount', '0.00')
|
||||
// // ->where('date', '2020-03-18')
|
||||
// ->first();
|
||||
// // $this->assertEquals('8.4900', $invoice_1->balance);
|
||||
// // $this->assertEquals('50.4200', $invoice_2->balance);
|
||||
// // }
|
||||
|
||||
// $invoice_2 = Invoice::whereNumber('0018')
|
||||
// // ->where('discount', '0.00')
|
||||
// // ->where('date', '2019-10-15')
|
||||
// ->first();
|
||||
// // public function testQuoteAttributes()
|
||||
// // {
|
||||
// // $original_number = Quote::count();
|
||||
|
||||
// $this->assertNotNull($invoice_1);
|
||||
// $this->assertNotNull($invoice_2);
|
||||
// // $this->invoice->forceDelete();
|
||||
|
||||
// $this->assertEquals('13.5000', $invoice_1->amount);
|
||||
// $this->assertEquals('67.4100', $invoice_2->amount);
|
||||
// // $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
|
||||
// $this->assertEquals('8.4900', $invoice_1->balance);
|
||||
// $this->assertEquals('50.4200', $invoice_2->balance);
|
||||
// }
|
||||
// // $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
||||
|
||||
// public function testQuoteAttributes()
|
||||
// {
|
||||
// $original_number = Quote::count();
|
||||
// // Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
// $this->invoice->forceDelete();
|
||||
// // $this->assertGreaterThan($original_number, Invoice::count());
|
||||
|
||||
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
|
||||
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
||||
// // $quote = Quote::whereNumber('0021')
|
||||
// // ->whereDiscount('0.00')
|
||||
// // ->first();
|
||||
|
||||
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
// // $this->assertNotNull($quote);
|
||||
// // $this->assertEquals('0.0000', $quote->amount);
|
||||
// // $this->assertEquals('0.0000', $quote->balance);
|
||||
// // }
|
||||
|
||||
// $this->assertGreaterThan($original_number, Invoice::count());
|
||||
// public function testPaymentsImport()
|
||||
// {
|
||||
// $original_count = Payment::count();
|
||||
|
||||
// $this->invoice->forceDelete();
|
||||
// $this->quote->forceDelete();
|
||||
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
// $quote = Quote::whereNumber('0021')
|
||||
// ->whereDiscount('0.00')
|
||||
// ->first();
|
||||
// $this->assertGreaterThan($original_count, Payment::count());
|
||||
// }
|
||||
|
||||
// $this->assertNotNull($quote);
|
||||
// $this->assertEquals('0.0000', $quote->amount);
|
||||
// $this->assertEquals('0.0000', $quote->balance);
|
||||
// }
|
||||
// public function testPaymentDependsOnClient()
|
||||
// {
|
||||
// $data['payments'] = [
|
||||
// 0 => [
|
||||
// 'client_id' => 1,
|
||||
// 'amount' => 1,
|
||||
// ]
|
||||
// ];
|
||||
|
||||
public function testPaymentsImport()
|
||||
{
|
||||
$original_count = Payment::count();
|
||||
// try {
|
||||
// Import::dispatchNow($data, $this->company, $this->user);
|
||||
// } catch(ResourceDependencyMissing $e) {
|
||||
// $this->assertTrue(true);
|
||||
// }
|
||||
// }
|
||||
|
||||
$this->invoice->forceDelete();
|
||||
$this->quote->forceDelete();
|
||||
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
// public function testQuotesImport()
|
||||
// {
|
||||
// $original_count = Credit::count();
|
||||
|
||||
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
||||
// $this->invoice->forceDelete();
|
||||
// $this->quote->forceDelete();
|
||||
|
||||
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
$this->assertGreaterThan($original_count, Payment::count());
|
||||
}
|
||||
// $this->assertGreaterThan($original_count, Credit::count());
|
||||
// }
|
||||
|
||||
public function testPaymentDependsOnClient()
|
||||
{
|
||||
$data['payments'] = [
|
||||
0 => [
|
||||
'client_id' => 1,
|
||||
'amount' => 1,
|
||||
]
|
||||
];
|
||||
// public function testMigrationFileExists()
|
||||
// {
|
||||
// $migration_archive = base_path() . '/tests/Unit/Migration/migration.zip';
|
||||
|
||||
try {
|
||||
Import::dispatchNow($data, $this->company, $this->user);
|
||||
} catch(ResourceDependencyMissing $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
// $this->assertTrue(file_exists($migration_archive));
|
||||
// }
|
||||
|
||||
public function testQuotesImport()
|
||||
{
|
||||
$original_count = Credit::count();
|
||||
// // public function testMigrationFileBeingExtracted()
|
||||
// // {
|
||||
// // $migration_archive = base_path() . '/tests/Unit/Migration/migration.zip';
|
||||
|
||||
$this->invoice->forceDelete();
|
||||
$this->quote->forceDelete();
|
||||
// // StartMigration::dispatchNow($migration_archive, $this->user, $this->company);
|
||||
|
||||
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
// // $extracted_archive = storage_path("migrations/migration");
|
||||
// // $migration_file = storage_path("migrations/migration/migration.json");
|
||||
|
||||
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
||||
// // $this->assertTrue(file_exists($extracted_archive));
|
||||
// // $this->assertTrue(is_dir($extracted_archive));
|
||||
// // $this->assertTrue(file_exists($migration_file));
|
||||
// // }
|
||||
|
||||
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
// public function testValidityOfImportedData()
|
||||
// {
|
||||
// $this->invoice->forceDelete();
|
||||
// $this->quote->forceDelete();
|
||||
|
||||
$this->assertGreaterThan($original_count, Credit::count());
|
||||
}
|
||||
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
public function testMigrationFileExists()
|
||||
{
|
||||
$migration_archive = base_path() . '/tests/Unit/Migration/migration.zip';
|
||||
// $differences = [];
|
||||
|
||||
$this->assertTrue(file_exists($migration_archive));
|
||||
}
|
||||
// foreach ($this->migration_array['invoices'] as $key => $invoices) {
|
||||
// $record = Invoice::whereNumber($invoices['number'])
|
||||
// ->whereAmount($invoices['amount'])
|
||||
// ->whereBalance($invoices['balance'])
|
||||
// ->first();
|
||||
|
||||
// public function testMigrationFileBeingExtracted()
|
||||
// {
|
||||
// $migration_archive = base_path() . '/tests/Unit/Migration/migration.zip';
|
||||
// if (!$record) {
|
||||
// $differences['invoices']['missing'][] = $invoices['id'];
|
||||
// }
|
||||
// }
|
||||
|
||||
// StartMigration::dispatchNow($migration_archive, $this->user, $this->company);
|
||||
// foreach ($this->migration_array['users'] as $key => $user) {
|
||||
// $record = User::whereEmail($user['email'])->first();
|
||||
|
||||
// $extracted_archive = storage_path("migrations/migration");
|
||||
// $migration_file = storage_path("migrations/migration/migration.json");
|
||||
// if (!$record) {
|
||||
// $differences['users']['missing'][] = $user['email'];
|
||||
// }
|
||||
// }
|
||||
|
||||
// $this->assertTrue(file_exists($extracted_archive));
|
||||
// $this->assertTrue(is_dir($extracted_archive));
|
||||
// $this->assertTrue(file_exists($migration_file));
|
||||
// }
|
||||
// foreach ($this->migration_array['tax_rates'] as $key => $tax_rate) {
|
||||
// $record = TaxRate::whereName($tax_rate['name'])
|
||||
// ->where('rate', $tax_rate['rate'])
|
||||
// ->first();
|
||||
|
||||
public function testValidityOfImportedData()
|
||||
{
|
||||
$this->invoice->forceDelete();
|
||||
$this->quote->forceDelete();
|
||||
// if (!$record) {
|
||||
// $differences['tax_rates']['missing'][] = $tax_rate['name'];
|
||||
// }
|
||||
// }
|
||||
|
||||
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
// foreach ($this->migration_array['clients'] as $key => $client) {
|
||||
// $record = Client::whereName($client['name'])
|
||||
// ->whereCity($client['city'])
|
||||
// // ->where('paid_to_date', $client['paid_to_date']) // TODO: Doesn't work. Need debugging.
|
||||
// ->first();
|
||||
|
||||
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
||||
// if (!$record) {
|
||||
// $differences['clients']['missing'][] = $client['name'];
|
||||
// }
|
||||
// }
|
||||
|
||||
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
// foreach ($this->migration_array['products'] as $key => $product) {
|
||||
// $record = Product::where('product_key', $product['product_key'])
|
||||
// ->first();
|
||||
|
||||
$differences = [];
|
||||
// if (!$record) {
|
||||
// $differences['products']['missing'][] = $product['notes'];
|
||||
// }
|
||||
// }
|
||||
|
||||
foreach ($this->migration_array['invoices'] as $key => $invoices) {
|
||||
$record = Invoice::whereNumber($invoices['number'])
|
||||
->whereAmount($invoices['amount'])
|
||||
->whereBalance($invoices['balance'])
|
||||
->first();
|
||||
// foreach ($this->migration_array['quotes'] as $key => $quote) {
|
||||
// $record = Quote::whereNumber($quote['number'])
|
||||
// ->whereIsAmountDiscount($quote['is_amount_discount'])
|
||||
// ->whereDueDate($quote['due_date'])
|
||||
// ->first();
|
||||
|
||||
if (!$record) {
|
||||
$differences['invoices']['missing'][] = $invoices['id'];
|
||||
}
|
||||
}
|
||||
// if (!$record) {
|
||||
// $differences['quotes']['missing'][] = $quote['id'];
|
||||
// }
|
||||
// }
|
||||
|
||||
foreach ($this->migration_array['users'] as $key => $user) {
|
||||
$record = User::whereEmail($user['email'])->first();
|
||||
// foreach ($this->migration_array['payments'] as $key => $payment) {
|
||||
// $record = Payment::whereApplied($payment['applied'])
|
||||
// ->first();
|
||||
|
||||
if (!$record) {
|
||||
$differences['users']['missing'][] = $user['email'];
|
||||
}
|
||||
}
|
||||
// if (!$record) {
|
||||
// $differences['payments']['missing'][] = $payment['id'];
|
||||
// }
|
||||
// }
|
||||
|
||||
foreach ($this->migration_array['tax_rates'] as $key => $tax_rate) {
|
||||
$record = TaxRate::whereName($tax_rate['name'])
|
||||
->where('rate', $tax_rate['rate'])
|
||||
->first();
|
||||
// foreach ($this->migration_array['credits'] as $key => $credit) {
|
||||
|
||||
if (!$record) {
|
||||
$differences['tax_rates']['missing'][] = $tax_rate['name'];
|
||||
}
|
||||
}
|
||||
// // The Import::processCredits() does insert the credit record with number: 0053,
|
||||
// // .. however this part of the code doesn't see it at all.
|
||||
|
||||
foreach ($this->migration_array['clients'] as $key => $client) {
|
||||
$record = Client::whereName($client['name'])
|
||||
->whereCity($client['city'])
|
||||
// ->where('paid_to_date', $client['paid_to_date']) // TODO: Doesn't work. Need debugging.
|
||||
->first();
|
||||
// $record = Credit::whereNumber($credit['number'])
|
||||
// ->first();
|
||||
|
||||
if (!$record) {
|
||||
$differences['clients']['missing'][] = $client['name'];
|
||||
}
|
||||
}
|
||||
// if (!$record) {
|
||||
// $differences['credits']['missing'][] = $credit['id'];
|
||||
// }
|
||||
// }
|
||||
|
||||
foreach ($this->migration_array['products'] as $key => $product) {
|
||||
$record = Product::where('product_key', $product['product_key'])
|
||||
->first();
|
||||
// /*
|
||||
// foreach ($this->migration_array['company_gateways'] as $key => $company_gateway) {
|
||||
|
||||
if (!$record) {
|
||||
$differences['products']['missing'][] = $product['notes'];
|
||||
}
|
||||
}
|
||||
// // The Import::processCredits() does insert the credit record with number: 0053,
|
||||
// // .. however this part of the code doesn't see it at all.
|
||||
|
||||
foreach ($this->migration_array['quotes'] as $key => $quote) {
|
||||
$record = Quote::whereNumber($quote['number'])
|
||||
->whereIsAmountDiscount($quote['is_amount_discount'])
|
||||
->whereDueDate($quote['due_date'])
|
||||
->first();
|
||||
// $record = CompanyGateway::where('gateway_key' ,$company_gateway['gateway_key'])
|
||||
// ->first();
|
||||
|
||||
if (!$record) {
|
||||
$differences['quotes']['missing'][] = $quote['id'];
|
||||
}
|
||||
}
|
||||
// if (!$record) {
|
||||
// $differences['company_gateways']['missing'][] = $company_gateway['id'];
|
||||
// }
|
||||
// }
|
||||
|
||||
foreach ($this->migration_array['payments'] as $key => $payment) {
|
||||
$record = Payment::whereApplied($payment['applied'])
|
||||
->first();
|
||||
// foreach ($this->migration_array['client_gateway_tokens'] as $key => $cgt) {
|
||||
|
||||
if (!$record) {
|
||||
$differences['payments']['missing'][] = $payment['id'];
|
||||
}
|
||||
}
|
||||
// // The Import::processCredits() does insert the credit record with number: 0053,
|
||||
// // .. however this part of the code doesn't see it at all.
|
||||
|
||||
foreach ($this->migration_array['credits'] as $key => $credit) {
|
||||
// $record = ClientGatewayToken::where('token' ,$cgt['token'])
|
||||
// ->first();
|
||||
|
||||
// The Import::processCredits() does insert the credit record with number: 0053,
|
||||
// .. however this part of the code doesn't see it at all.
|
||||
// if (!$record) {
|
||||
// $differences['client_gateway_tokens']['missing'][] = $cgt['id'];
|
||||
// }
|
||||
// }
|
||||
// */
|
||||
// //@TODO we can uncomment tests for documents when we have imported expenses.
|
||||
|
||||
$record = Credit::whereNumber($credit['number'])
|
||||
->first();
|
||||
// // foreach ($this->migration_array['documents'] as $key => $document) {
|
||||
|
||||
if (!$record) {
|
||||
$differences['credits']['missing'][] = $credit['id'];
|
||||
}
|
||||
}
|
||||
// // if(!is_null($document['invoice_id'])) {
|
||||
|
||||
/*
|
||||
foreach ($this->migration_array['company_gateways'] as $key => $company_gateway) {
|
||||
// // $record = Document::where('hash', $document['hash'])
|
||||
// // ->first();
|
||||
|
||||
// The Import::processCredits() does insert the credit record with number: 0053,
|
||||
// .. however this part of the code doesn't see it at all.
|
||||
// // if (!$record) {
|
||||
// // $differences['documents']['missing'][] = $document['id'];
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
|
||||
$record = CompanyGateway::where('gateway_key' ,$company_gateway['gateway_key'])
|
||||
->first();
|
||||
// //\Log::error($differences);
|
||||
|
||||
if (!$record) {
|
||||
$differences['company_gateways']['missing'][] = $company_gateway['id'];
|
||||
}
|
||||
}
|
||||
// $this->assertCount(0, $differences);
|
||||
// }
|
||||
|
||||
foreach ($this->migration_array['client_gateway_tokens'] as $key => $cgt) {
|
||||
// public function testClientContactsImport()
|
||||
// {
|
||||
// $this->invoice->forceDelete();
|
||||
// $this->quote->forceDelete();
|
||||
|
||||
// The Import::processCredits() does insert the credit record with number: 0053,
|
||||
// .. however this part of the code doesn't see it at all.
|
||||
// $original = ClientContact::count();
|
||||
|
||||
$record = ClientGatewayToken::where('token' ,$cgt['token'])
|
||||
->first();
|
||||
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
if (!$record) {
|
||||
$differences['client_gateway_tokens']['missing'][] = $cgt['id'];
|
||||
}
|
||||
}
|
||||
*/
|
||||
//@TODO we can uncomment tests for documents when we have imported expenses.
|
||||
// $this->assertGreaterThan($original, ClientContact::count());
|
||||
// }
|
||||
|
||||
// foreach ($this->migration_array['documents'] as $key => $document) {
|
||||
// public function testClientGatewayTokensImport()
|
||||
// {
|
||||
// $this->invoice->forceDelete();
|
||||
// $this->quote->forceDelete();
|
||||
|
||||
// if(!is_null($document['invoice_id'])) {
|
||||
// $original = ClientGatewayToken::count();
|
||||
|
||||
// $record = Document::where('hash', $document['hash'])
|
||||
// ->first();
|
||||
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
// if (!$record) {
|
||||
// $differences['documents']['missing'][] = $document['id'];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// $this->assertTrue(true, 'ClientGatewayTokens importing not completed yet.');
|
||||
|
||||
//\Log::error($differences);
|
||||
// }
|
||||
|
||||
$this->assertCount(0, $differences);
|
||||
}
|
||||
|
||||
public function testClientContactsImport()
|
||||
{
|
||||
$this->invoice->forceDelete();
|
||||
$this->quote->forceDelete();
|
||||
// public function testDocumentsImport()
|
||||
// {
|
||||
// $this->invoice->forceDelete();
|
||||
// $this->quote->forceDelete();
|
||||
|
||||
$original = ClientContact::count();
|
||||
// $original = Document::count();
|
||||
|
||||
// $migration_file = base_path() . '/tests/Unit/Migration/migration.json';
|
||||
// Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
// $this->migration_array = json_decode(file_get_contents($migration_file), 1);
|
||||
// $document = Document::first();
|
||||
|
||||
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
// $this->assertTrue(true, 'Documents importing not completed yet. Missing expenses.');
|
||||
// }
|
||||
|
||||
$this->assertGreaterThan($original, ClientContact::count());
|
||||
}
|
||||
// public function testExceptionMailSending()
|
||||
// {
|
||||
// Mail::fake();
|
||||
|
||||
public function testClientGatewayTokensImport()
|
||||
{
|
||||
$this->invoice->forceDelete();
|
||||
$this->quote->forceDelete();
|
||||
// $data['panda_bears'] = [
|
||||
// 'name' => 'Awesome Panda Bear',
|
||||
// ];
|
||||
|
||||
$original = ClientGatewayToken::count();
|
||||
|
||||
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
// $this->assertGreaterThan($original, ClientGatewayToken::count());
|
||||
//
|
||||
$this->assertTrue(true, 'ClientGatewayTokens importing not completed yet.');
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testDocumentsImport()
|
||||
{
|
||||
$this->invoice->forceDelete();
|
||||
$this->quote->forceDelete();
|
||||
|
||||
$original = Document::count();
|
||||
|
||||
Import::dispatchNow($this->migration_array, $this->company, $this->user);
|
||||
|
||||
// $this->assertGreaterThan($original, Document::count());
|
||||
|
||||
$document = Document::first();
|
||||
|
||||
// $this->assertNotNull(Invoice::find($document->documentable_id)->documents);
|
||||
// $this->assertNotNull($document->documentable);
|
||||
|
||||
$this->assertTrue(true, 'Documents importing not completed yet. Missing expenses.');
|
||||
}
|
||||
|
||||
public function testExceptionMailSending()
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$data['panda_bears'] = [
|
||||
'name' => 'Awesome Panda Bear',
|
||||
];
|
||||
|
||||
try {
|
||||
Import::dispatchNow($data, $this->company, $this->user);
|
||||
}
|
||||
catch (ResourceNotAvailableForMigration $e) {
|
||||
Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage()));
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
// try {
|
||||
// Import::dispatchNow($data, $this->company, $this->user);
|
||||
// }
|
||||
// catch (ResourceNotAvailableForMigration $e) {
|
||||
// Mail::to($this->user)->send(new MigrationFailed($e, $e->getMessage()));
|
||||
// $this->assertTrue(true);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user