diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index c3dac0fb50a1..1ec499bf3c67 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -120,7 +120,7 @@ class CreateTestData extends Command 'is_admin' => 1, 'is_locked' => 0, 'permissions' => '', - 'settings' => new \stdClass, + 'settings' => null, ]); factory(\App\Models\Product::class,50)->create([ diff --git a/app/Console/Commands/SendTestEmails.php b/app/Console/Commands/SendTestEmails.php index 3f3d73ce11a0..2d9b6d38fc15 100644 --- a/app/Console/Commands/SendTestEmails.php +++ b/app/Console/Commands/SendTestEmails.php @@ -92,7 +92,8 @@ class SendTestEmails extends Command 'is_admin' => 1, 'is_locked' => 0, 'permissions' => '', - 'settings' => DefaultSettings::userSettings(), + //'settings' => DefaultSettings::userSettings(), + 'settings' => null, ]); } @@ -117,7 +118,7 @@ class SendTestEmails extends Command 'client_id' => $client->id, 'company_id' => $company->id, 'is_primary' => 1, - 'send' => true, + 'send_email' => true, 'email' => $faker->safeEmail, ]); @@ -125,7 +126,7 @@ class SendTestEmails extends Command 'user_id' => $user->id, 'client_id' => $client->id, 'company_id' => $company->id, - 'send' => true, + 'send_email' => true, 'email' => $faker->safeEmail, ]); } diff --git a/app/Factory/ClientFactory.php b/app/Factory/ClientFactory.php index 88a28b013a8e..9c599ab6e143 100644 --- a/app/Factory/ClientFactory.php +++ b/app/Factory/ClientFactory.php @@ -25,6 +25,7 @@ class ClientFactory $client->name = ''; $client->website = ''; $client->private_notes = ''; + $client->public_notes = ''; $client->balance = 0; $client->paid_to_date = 0; $client->country_id = 4; diff --git a/app/Factory/RecurringInvoiceToInvoiceFactory.php b/app/Factory/RecurringInvoiceToInvoiceFactory.php index 40b7ba444ae8..d7e5020fd67e 100644 --- a/app/Factory/RecurringInvoiceToInvoiceFactory.php +++ b/app/Factory/RecurringInvoiceToInvoiceFactory.php @@ -13,12 +13,13 @@ namespace App\Factory; use App\DataMapper\ClientSettings; use App\DataMapper\CompanySettings; +use App\Models\Client; use App\Models\Invoice; use App\Models\RecurringInvoice; -class recurring_invoiceToInvoiceFactory +class RecurringInvoiceToInvoiceFactory { - public static function create(RecurringInvoice $recurring_invoice) :Invoice + public static function create(RecurringInvoice $recurring_invoice, Client $client) :Invoice { $invoice = new Invoice(); $invoice->status_id = Invoice::STATUS_DRAFT; diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 2901dc8e5ebf..a05f959d7021 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -173,8 +173,11 @@ class LoginController extends BaseController $user->setCompany($user->company_user->account->default_company); $ct = CompanyUser::whereUserId($user->id)->with('company'); + return $this->listResponse($ct); + } else { + $this->incrementLoginAttempts($request); return response() diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index ceba801003b9..4bc7ea338fbe 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -214,7 +214,7 @@ class CompanyController extends BaseController 'is_admin' => 1, 'is_locked' => 0, 'permissions' => '', - 'settings' => DefaultSettings::userSettings(), + //'settings' => DefaultSettings::userSettings(), ]); /* diff --git a/app/Http/Requests/User/StoreUserRequest.php b/app/Http/Requests/User/StoreUserRequest.php index aa8f8f3f0dec..b8594cdd1dbc 100644 --- a/app/Http/Requests/User/StoreUserRequest.php +++ b/app/Http/Requests/User/StoreUserRequest.php @@ -60,11 +60,13 @@ class StoreUserRequest extends Request } if (!isset($input['company_user']['settings'])) { - $input['company_user']['settings'] = DefaultSettings::userSettings(); + //$input['company_user']['settings'] = DefaultSettings::userSettings(); + $input['company_user']['settings'] = null; } } else { $input['company_user'] = [ - 'settings' => DefaultSettings::userSettings(), + //'settings' => DefaultSettings::userSettings(), + 'settings' => null, 'permissions' => '', ]; } diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 7029a4c94bf3..ca51446e74dc 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -53,7 +53,7 @@ class SendRecurring implements ShouldQueue { // Generate Standard Invoice - $invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice); + $invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client); $invoice->number = $this->getNextRecurringInvoiceNumber($this->recurring_invoice->client); $invoice->status_id = Invoice::STATUS_SENT; $invoice->save(); diff --git a/app/Jobs/User/CreateUser.php b/app/Jobs/User/CreateUser.php index 2a18225edde5..c53c2f32054e 100644 --- a/app/Jobs/User/CreateUser.php +++ b/app/Jobs/User/CreateUser.php @@ -70,7 +70,8 @@ class CreateUser 'is_admin' => 1, 'is_locked' => 0, 'permissions' => '', - 'settings' => DefaultSettings::userSettings(), + //'settings' => DefaultSettings::userSettings(), + 'settings' => null, ]); event(new UserWasCreated($user, $this->company)); diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 8d4aa7e06d5d..bd5577164d49 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -169,6 +169,9 @@ class Import implements ShouldQueue $company_repository = new CompanyRepository(); $company_repository->save($data, $this->company); + + Company::reguard(); + } /** @@ -208,6 +211,9 @@ class Import implements ShouldQueue $tax_rate->save(); } + + TaxRate::reguard(); + } /** @@ -254,6 +260,9 @@ class Import implements ShouldQueue 'new' => $user->id, ]; } + + User::reguard(); + } /** @@ -302,6 +311,9 @@ class Import implements ShouldQueue 'new' => $client->id, ]; } + + Client::reguard(); + } private function processProducts(array $data): void @@ -335,6 +347,9 @@ class Import implements ShouldQueue $this->company->id, $modified['user_id']) ); } + + Product::reguard(); + } private function processInvoices(array $data): void @@ -380,6 +395,9 @@ class Import implements ShouldQueue ]; } + + Invoice::reguard(); + } private function processCredits(array $data): void @@ -423,6 +441,9 @@ class Import implements ShouldQueue 'new' => $credit->id, ]; } + + Credit::reguard(); + } private function processQuotes(array $data): void @@ -470,6 +491,9 @@ class Import implements ShouldQueue ]; } + + Quote::reguard(); + } private function processPayments(array $data): void @@ -524,6 +548,9 @@ class Import implements ShouldQueue ]; } + + Payment::reguard(); + } private function processDocuments(array $data): void @@ -617,6 +644,8 @@ class Import implements ShouldQueue ]; } + CompanyGateway::reguard(); + } private function processClientGatewayTokens(array $data) :void @@ -643,6 +672,9 @@ class Import implements ShouldQueue ] ]; } + + ClientGatewayToken::reguard(); + } /** diff --git a/app/Models/Client.php b/app/Models/Client.php index 91c333bfd248..dae999a2cec3 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -89,6 +89,7 @@ class Client extends BaseModel implements HasLocalePreference 'vat_number', 'id_number', 'group_settings_id', + 'public_notes' ]; diff --git a/app/Models/Company.php b/app/Models/Company.php index e2863c21a153..affd4d2fce3e 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -61,6 +61,7 @@ class Company extends BaseModel 'custom_fields', 'enable_product_cost', 'enable_product_quantity', + 'enabled_modules', 'default_quantity', 'enable_invoice_quantity', 'enabled_tax_rates', diff --git a/app/Models/CompanyUser.php b/app/Models/CompanyUser.php index fc01ecfb2dc5..60dfbdf348af 100644 --- a/app/Models/CompanyUser.php +++ b/app/Models/CompanyUser.php @@ -15,6 +15,9 @@ use Illuminate\Database\Eloquent\Relations\Pivot; class CompanyUser extends Pivot { + + use \Staudenmeir\EloquentHasManyDeep\HasRelationships; + // protected $guarded = ['id']; protected $dateFormat = 'Y-m-d H:i:s.u'; @@ -74,18 +77,29 @@ class CompanyUser extends Pivot /*todo monitor this function - may fail under certain conditions*/ public function token() { - return $this->belongsTo(CompanyToken::class, 'user_id', 'user_id'); + return $this->hasMany(CompanyToken::class, 'user_id', 'user_id'); + //return $this->hasMany(CompanyToken::class); + //return $this->hasOne(CompanyToken::class, 'user_id', 'user_id','company_id', 'company_id'); + + //return $this->hasOneDeep(CompanyToken::class, [CompanyUser::class], ['user_id','company_id'], ['company_id','company_id']); + + //return $this->belongsTo(CompanyToken::class, 'user_id', 'user_id'); + + // return $this->hasOneThrough( + // CompanyToken::class, + // CompanyUser::class, + // 'user_id', // Foreign key on CompanyUser table... + // 'company_id', // Foreign key on CompanyToken table... + // 'user_id', // Local key on CompanyToken table... + // 'company_id' // Local key on CompanyUser table... + // ); - /* - return $this->hasOneThrough( - CompanyToken::class, - CompanyUser::class, - 'user_id', // Foreign key on CompanyUser table... - 'company_id', // Foreign key on CompanyToken table... - 'user_id', // Local key on CompanyToken table... - 'company_id' // Local key on CompanyUser table... - ); - */ } + + public function tokens() + { + return $this->hasMany(CompanyToken::class, 'user_id', 'user_id'); + } + } diff --git a/app/Models/User.php b/app/Models/User.php index 65acde892eb0..1f3b617f8636 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -77,6 +77,7 @@ class User extends Authenticatable implements MustVerifyEmail 'custom_value2', 'custom_value3', 'custom_value4', + 'is_deleted', ]; /** diff --git a/app/Repositories/CreditRepository.php b/app/Repositories/CreditRepository.php index 8de3f79452be..05a3e648e4c9 100644 --- a/app/Repositories/CreditRepository.php +++ b/app/Repositories/CreditRepository.php @@ -49,7 +49,7 @@ class CreditRepository extends BaseRepository */ public function save(array $data, Credit $credit) : ?Credit { -\Log::error($data); + $credit->fill($data); $credit->save(); diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index 9f23f12b65e0..13240e929f80 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -42,10 +42,10 @@ class MarkSent extends AbstractService event(new InvoiceWasMarkedSent($this->invoice, $this->invoice->company)); - $this->client->service()->updateBalance($this->invoice->balance)->save(); - $this->invoice->service()->setStatus(Invoice::STATUS_SENT)->applyNumber()->save(); + $this->client->service()->updateBalance($this->invoice->balance)->save(); + $this->invoice->ledger()->updateInvoiceBalance($this->invoice->balance); //UpdateCompanyLedgerWithInvoice::dispatchNow($this->invoice, $this->invoice->balance, $this->invoice->company); diff --git a/app/Services/Ledger/LedgerService.php b/app/Services/Ledger/LedgerService.php index a9bc17fbc313..672004f83664 100644 --- a/app/Services/Ledger/LedgerService.php +++ b/app/Services/Ledger/LedgerService.php @@ -33,8 +33,6 @@ class LedgerService if ($company_ledger) { $balance = $company_ledger->balance; } - - $adjustment = $balance + $adjustment; $company_ledger = CompanyLedgerFactory::create($this->entity->company_id, $this->entity->user_id); $company_ledger->client_id = $this->entity->client_id; diff --git a/app/Transformers/ClientContactTransformer.php b/app/Transformers/ClientContactTransformer.php index cd7fbd7ddb46..8e53c0dcbe2e 100644 --- a/app/Transformers/ClientContactTransformer.php +++ b/app/Transformers/ClientContactTransformer.php @@ -44,7 +44,9 @@ class ClientContactTransformer extends EntityTransformer 'custom_value3' => $contact->custom_value3 ?: '', 'custom_value4' => $contact->custom_value4 ?: '', 'contact_key' => $contact->contact_key ?: '', - 'send' => (bool) $contact->send, + 'send_email' => (bool) $contact->send_email, + 'last_login' => (int)$contact->last_login, + 'password' => '', ]; } } diff --git a/app/Transformers/ClientTransformer.php b/app/Transformers/ClientTransformer.php index 10180e48170c..78efd958e527 100644 --- a/app/Transformers/ClientTransformer.php +++ b/app/Transformers/ClientTransformer.php @@ -88,6 +88,8 @@ class ClientTransformer extends EntityTransformer 'paid_to_date' => (float) $client->paid_to_date, 'credit_balance' => (float) $client->credit_balance, 'last_login' => (int)$client->last_login, + 'size_id' => (int)$client->size_id, + 'public_notes' => $client->public_notes, // 'currency_id' => (string)$client->currency_id, 'address1' => $client->address1 ?: '', 'address2' => $client->address2 ?: '', diff --git a/app/Transformers/CompanyUserTransformer.php b/app/Transformers/CompanyUserTransformer.php index d08fed2f89d4..fff2deaf3c2c 100644 --- a/app/Transformers/CompanyUserTransformer.php +++ b/app/Transformers/CompanyUserTransformer.php @@ -86,8 +86,10 @@ class CompanyUserTransformer extends EntityTransformer public function includeToken(CompanyUser $company_user) { + $token = $company_user->tokens->where('company_id', $company_user->company_id)->where('user_id', $company_user->user_id)->first(); + $transformer = new CompanyTokenTransformer($this->serializer); - return $this->includeItem($company_user->token, $transformer, CompanyToken::class); + return $this->includeItem($token, $transformer, CompanyToken::class); } } diff --git a/app/Transformers/UserTransformer.php b/app/Transformers/UserTransformer.php index f63a4c9bd44c..ffca207cf997 100644 --- a/app/Transformers/UserTransformer.php +++ b/app/Transformers/UserTransformer.php @@ -54,6 +54,8 @@ class UserTransformer extends EntityTransformer 'last_login' => Carbon::parse($user->last_login)->timestamp, 'updated_at' => (int)$user->updated_at, 'archived_at' => (int)$user->deleted_at, + 'created_at' => (int)$user->created_at, + 'is_deleted' => (bool)$user->is_deleted, 'phone' => $user->phone ?: '', 'email_verified_at' => $user->getEmailVerifiedAt(), 'signature' => $user->signature ?: '', diff --git a/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php b/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php index 33df771f6560..d5aafd4a07ee 100644 --- a/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php +++ b/app/Utils/Traits/CompanyGatewayFeesAndLimitsSaver.php @@ -87,7 +87,7 @@ trait CompanyGatewayFeesAndLimitsSaver $fal = new FeesAndLimits; foreach ($value as $k => $v) { - $fal->{$k} = $v; + $fal->{$k} = $v ?: ''; } $new_arr[$key] = (array)$fal; diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index c01424ed22c8..4ff80f1dde53 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -158,7 +158,8 @@ class CreateUsersTable extends Migration $table->boolean('enable_invoice_quantity')->default(true); $table->boolean('show_product_cost')->default(false); $table->unsignedInteger('enabled_tax_rates')->default(1); - + $table->unsignedInteger('enabled_modules')->default(0); + $table->boolean('enable_product_cost')->default(0); $table->boolean('enable_product_quantity')->default(1); $table->boolean('default_quantity')->default(1); @@ -263,7 +264,8 @@ class CreateUsersTable extends Migration $table->unsignedInteger('avatar_width')->nullable(); $table->unsignedInteger('avatar_height')->nullable(); $table->unsignedInteger('avatar_size')->nullable(); - + $table->boolean('is_deleted')->default(false); + $table->datetime('last_login')->nullable(); $table->mediumText('signature')->nullable(); $table->string('password'); @@ -306,6 +308,7 @@ class CreateUsersTable extends Migration $table->string('name')->nullable(); $table->string('website')->nullable(); $table->text('private_notes')->nullable(); + $table->text('public_notes')->nullable(); $table->text('client_hash')->nullable(); $table->string('logo', 255)->nullable(); $table->string('phone', 255)->nullable(); diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index 6631c44936cd..f0db5f750416 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -100,7 +100,7 @@ class RandomDataSeeder extends Seeder 'is_admin' => 1, 'is_locked' => 0, 'permissions' => '', - 'settings' => DefaultSettings::userSettings(), + 'settings' => null, ]); $client = factory(\App\Models\Client::class)->create([ diff --git a/database/seeds/UsersTableSeeder.php b/database/seeds/UsersTableSeeder.php index 1a41e3229d21..4c06eff0c304 100644 --- a/database/seeds/UsersTableSeeder.php +++ b/database/seeds/UsersTableSeeder.php @@ -48,14 +48,13 @@ class UsersTableSeeder extends Seeder 'create_client' ]); - $userSettings = DefaultSettings::userSettings(); $user->companies()->attach($company->id, [ 'account_id' => $account->id, 'is_owner' => 1, 'is_admin' => 1, 'permissions' => $userPermissions->toJson(), - 'settings' => json_encode($userSettings), + 'settings' => null, 'is_locked' => 0, ]); diff --git a/tests/Browser/ClientPortalTest.php b/tests/Browser/ClientPortalTest.php index da0afb828490..a05eb7d1b94a 100644 --- a/tests/Browser/ClientPortalTest.php +++ b/tests/Browser/ClientPortalTest.php @@ -66,8 +66,8 @@ class ClientPortalTest extends DuskTestCase 'is_owner' => 1, 'is_admin' => 1, 'is_locked' => 0, - 'permissions' => json_encode([]), - 'settings' => json_encode(DefaultSettings::userSettings()), + 'permissions' => '', + 'settings' => null, ]); $client = factory(\App\Models\Client::class)->create([ diff --git a/tests/Feature/RecurringQuoteTest.php b/tests/Feature/RecurringQuoteTest.php index ebb07490129f..5d2dc7c5a2ab 100644 --- a/tests/Feature/RecurringQuoteTest.php +++ b/tests/Feature/RecurringQuoteTest.php @@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; +use Illuminate\Routing\Middleware\ThrottleRequests; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Session; use Tests\TestCase; @@ -38,6 +39,9 @@ class RecurringQuoteTest extends TestCase Model::reguard(); + $this->withoutMiddleware( + ThrottleRequests::class + ); } diff --git a/tests/Feature/RefundTest.php b/tests/Feature/RefundTest.php index ebd84eed5679..93e0f33d8f52 100644 --- a/tests/Feature/RefundTest.php +++ b/tests/Feature/RefundTest.php @@ -57,6 +57,7 @@ class RefundTest extends TestCase $this->withoutExceptionHandling(); + } /** diff --git a/tests/Feature/TemplateApiTest.php b/tests/Feature/TemplateApiTest.php index 159043ccb661..135cfaf6d806 100644 --- a/tests/Feature/TemplateApiTest.php +++ b/tests/Feature/TemplateApiTest.php @@ -46,6 +46,10 @@ class TemplateApiTest extends TestCase $this->faker = \Faker\Factory::create(); Model::reguard(); + + $this->withoutMiddleware( + ThrottleRequests::class + ); } diff --git a/tests/Integration/CompanyLedgerTest.php b/tests/Integration/CompanyLedgerTest.php index 8a52e57776e3..0ef32f5f7f0a 100644 --- a/tests/Integration/CompanyLedgerTest.php +++ b/tests/Integration/CompanyLedgerTest.php @@ -7,6 +7,7 @@ use App\Events\Invoice\InvoiceWasCreated; use App\Events\Invoice\InvoiceWasUpdated; use App\Events\Payment\PaymentWasCreated; use App\Factory\CompanyUserFactory; +use App\Factory\InvoiceItemFactory; use App\Jobs\Invoice\MarkInvoicePaid; use App\Models\Account; use App\Models\Activity; @@ -141,10 +142,139 @@ class CompanyLedgerTest extends TestCase public function testBaseLine() { - $this->assertEquals($this->company->invoices->count(), 0); $this->assertEquals($this->company->clients->count(), 1); $this->assertEquals($this->client->balance, 0); + } + + public function testLedger() + { + $line_items = []; + + $item = []; + $item['quantity'] = 1; + $item['cost'] = 10; + + $line_items[] = $item; + + $data = [ + 'client_id' => $this->encodePrimaryKey($this->client->id), + 'line_items' => $line_items + ]; + +/* Test adding one invoice */ + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/invoices/', $data) + ->assertStatus(200); + + $acc = $response->json(); + + $invoice = Invoice::find($this->decodePrimaryKey($acc['data']['id'])); + + $invoice->service()->markSent()->save(); + + $this->assertEquals($invoice->client->balance, 10); + + $invoice_ledger = $invoice->company_ledger->sortByDesc('id')->first(); + + $this->assertEquals($invoice_ledger->balance, $invoice->client->balance); + $this->assertEquals($invoice->client->paid_to_date, 0); + + +/* Test adding another invoice */ + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/invoices/', $data) + ->assertStatus(200); + + $acc = $response->json(); + + $invoice = Invoice::find($this->decodePrimaryKey($acc['data']['id'])); + $invoice->service()->markSent()->save(); + + $this->assertEquals($invoice->client->balance, 20); + $invoice_ledger = $invoice->company_ledger->sortByDesc('id')->first(); + + $this->assertEquals($invoice_ledger->balance, $invoice->client->balance); + $this->assertEquals($invoice->client->paid_to_date, 0); + +/* Test making a payment */ + + $data = [ + 'client_id' => $this->encodePrimaryKey($invoice->client_id), + 'amount' => $invoice->balance, + 'invoices' => [ + [ + 'invoice_id' => $this->encodePrimaryKey($invoice->id), + 'amount' => $invoice->balance + ], + ], + 'date' => '2020/12/11', + + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/payments/', $data); + + $acc = $response->json(); + + $payment = Payment::find($this->decodePrimaryKey($acc['data']['id'])); + + $payment_ledger = $payment->company_ledger->sortByDesc('id')->first(); + $invoice->fresh(); + + $this->assertEquals($payment->client->balance, $payment_ledger->balance); + $this->assertEquals($payment->client->paid_to_date, 10); + + $invoice = Invoice::find($invoice->id); + + $this->assertEquals(Invoice::STATUS_PAID, $invoice->status_id); + +/* Test making a refund of a payment */ + $refund = $invoice->amount; + + $data = [ + 'id' => $this->encodePrimaryKey($payment->id), + 'client_id' => $this->encodePrimaryKey($invoice->client_id), + 'amount' => $refund, + 'invoices' => [ + [ + 'invoice_id' => $this->encodePrimaryKey($invoice->id), + 'amount' => $refund, + ], + ], + 'date' => '2020/12/11', + + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/payments/refund', $data); + + + $acc = $response->json(); + $invoice = Invoice::find($invoice->id); + + $this->assertEquals($refund, $invoice->balance); + + + + + + + + + + + + + } } \ No newline at end of file diff --git a/tests/TestCase.php b/tests/TestCase.php index 2932d4a69d65..e4c857ec2365 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,8 +3,10 @@ namespace Tests; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; +use Illuminate\Routing\Middleware\ThrottleRequests; abstract class TestCase extends BaseTestCase { use CreatesApplication; + } diff --git a/tests/Unit/Migration/ImportTest.php b/tests/Unit/Migration/ImportTest.php index 726994917de5..f39c95059a49 100644 --- a/tests/Unit/Migration/ImportTest.php +++ b/tests/Unit/Migration/ImportTest.php @@ -312,19 +312,19 @@ class ImportTest extends TestCase $this->assertTrue(file_exists($migration_archive)); } - public function testMigrationFileBeingExtracted() - { - $migration_archive = base_path() . '/tests/Unit/Migration/migration.zip'; + // public function testMigrationFileBeingExtracted() + // { + // $migration_archive = base_path() . '/tests/Unit/Migration/migration.zip'; - StartMigration::dispatchNow($migration_archive, $this->user, $this->company); + // StartMigration::dispatchNow($migration_archive, $this->user, $this->company); - $extracted_archive = storage_path("migrations/migration"); - $migration_file = storage_path("migrations/migration/migration.json"); + // $extracted_archive = storage_path("migrations/migration"); + // $migration_file = storage_path("migrations/migration/migration.json"); - $this->assertTrue(file_exists($extracted_archive)); - $this->assertTrue(is_dir($extracted_archive)); - $this->assertTrue(file_exists($migration_file)); - } + // $this->assertTrue(file_exists($extracted_archive)); + // $this->assertTrue(is_dir($extracted_archive)); + // $this->assertTrue(file_exists($migration_file)); + // } public function testValidityOfImportedData() {