mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for composer 2 (#3593)
* Add privacy link to setup page * Italics * Tests for invoice actions * Fixes for autoloading
This commit is contained in:
parent
6d7b7ca9a3
commit
8cffccb3bc
2
app/Events/Vendor/VendorWasArchived.php
vendored
2
app/Events/Vendor/VendorWasArchived.php
vendored
@ -9,7 +9,7 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
namespace App\Events\Vendor;
|
||||
|
||||
use App\Models\Vendor;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
2
app/Events/Vendor/VendorWasCreated.php
vendored
2
app/Events/Vendor/VendorWasCreated.php
vendored
@ -9,7 +9,7 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
namespace App\Events\Vendor;
|
||||
|
||||
use App\Models\Vendor;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
2
app/Events/Vendor/VendorWasDeleted.php
vendored
2
app/Events/Vendor/VendorWasDeleted.php
vendored
@ -9,7 +9,7 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
namespace App\Events\Vendor;
|
||||
|
||||
use App\Models\Vendor;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
2
app/Events/Vendor/VendorWasRestored.php
vendored
2
app/Events/Vendor/VendorWasRestored.php
vendored
@ -9,7 +9,7 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
namespace App\Events\Vendor;
|
||||
|
||||
use App\Models\Vendor;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
2
app/Events/Vendor/VendorWasUpdated.php
vendored
2
app/Events/Vendor/VendorWasUpdated.php
vendored
@ -9,7 +9,7 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
namespace App\Events\Vendor;
|
||||
|
||||
use App\Models\Vendor;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
@ -10,7 +10,7 @@ namespace App\Helpers\Email;
|
||||
|
||||
use App\Models\Payment;
|
||||
|
||||
class EmailPayment extends EmailBuilder
|
||||
class PaymentEmail extends EmailBuilder
|
||||
{
|
||||
public function build(Payment $payment, $contact = null)
|
||||
{
|
||||
|
@ -676,6 +676,10 @@ class InvoiceController extends BaseController
|
||||
return $this->listResponse($invoice);
|
||||
}
|
||||
break;
|
||||
case 'cancel':
|
||||
break;
|
||||
case 'reverse':
|
||||
break;
|
||||
case 'email':
|
||||
|
||||
$this->reminder_template = $invoice->calculateTemplate();
|
||||
|
@ -13,17 +13,93 @@ namespace App\Http\Requests\Invoice;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Invoice;
|
||||
use App\Utils\Traits\Invoice\ActionsInvoice;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
|
||||
class ActionInvoiceRequest extends Request
|
||||
{
|
||||
use MakesHash;
|
||||
use ActionsInvoice;
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private $error_msg;
|
||||
|
||||
private $invoice;
|
||||
|
||||
public function authorize() : bool
|
||||
{
|
||||
return auth()->user()->can('edit', $this->invoice);
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'action' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
$this->invoice = Invoice::find($this->decodePrimary($invoice_id));
|
||||
|
||||
if(!array_key_exists('action', $input) {
|
||||
$this->error_msg = 'Action is a required field';
|
||||
}
|
||||
elseif(!$this->invoiceDeletable()){
|
||||
unset($input['action']);
|
||||
$this->error_msg = 'This invoice cannot be deleted';
|
||||
}
|
||||
elseif(!$this->invoiceCancellable()) {
|
||||
unset($input['action']);
|
||||
$this->error_msg = 'This invoice cannot be cancelled';
|
||||
}
|
||||
else if(!$this->invoiceReversable()) {
|
||||
unset($input['action']);
|
||||
$this->error_msg = 'This invoice cannot be reversed';
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'action' => $this->error_msg;
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
private function invoiceDeletable()
|
||||
{
|
||||
|
||||
if($this->invoice->status_id <= 2 && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function invoiceCancellable()
|
||||
{
|
||||
|
||||
if($this->invoice->status_id == 3 && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function invoiceReversable()
|
||||
{
|
||||
|
||||
if(($this->invoice->status_id == 3 || $this->invoice->status_id == 4) && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Jobs\Invoice;
|
||||
namespace App\Jobs\Credit;
|
||||
|
||||
use App\Events\Credit\CreditWasEmailed;
|
||||
use App\Events\Credit\CreditWasEmailedAndFailed;
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace App\Ninja\OAuth\Providers;
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\OAuth\Providers;
|
||||
|
||||
class Google implements ProviderInterface
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php namespace App\Ninja\OAuth\Providers;
|
||||
<?php
|
||||
|
||||
namespace App\Libraries\OAuth\Providers;
|
||||
|
||||
interface ProviderInterface
|
||||
{
|
||||
|
@ -83,4 +83,14 @@ class InvoiceRepository extends BaseRepository
|
||||
event(new InvoiceWasDeleted($invoice));
|
||||
}
|
||||
}
|
||||
|
||||
public function reverse()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function cancel()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class HandleDeletion extends AbstractService
|
||||
|
||||
public function run()
|
||||
{
|
||||
$balance_remainig = $this->invoice->balance;
|
||||
$balance_remaining = $this->invoice->balance;
|
||||
$total_paid = $this->invoice->amount - $this->invoice->balance;
|
||||
|
||||
//change invoice status
|
||||
|
@ -33,6 +33,7 @@ class SystemHealth
|
||||
'openssl',
|
||||
'mbstring',
|
||||
'xml',
|
||||
'bcmath'
|
||||
];
|
||||
|
||||
private static $php_version = 7.3;
|
||||
|
43
app/Utils/Traits/Invoice/ActionsInvoice.php
Normal file
43
app/Utils/Traits/Invoice/ActionsInvoice.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?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\Utils\Traits\Invoice;
|
||||
|
||||
|
||||
trait ActionsInvoice
|
||||
{
|
||||
public function invoiceDeletable() :bool
|
||||
{
|
||||
|
||||
if($this->invoice->status_id <= 2 && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function invoiceCancellable() :bool
|
||||
{
|
||||
|
||||
if($this->invoice->status_id == 3 && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function invoiceReversable() :bool
|
||||
{
|
||||
|
||||
if(($this->invoice->status_id == 3 || $this->invoice->status_id == 4) && $this->invoice->is_deleted == false && $this->invoice->deleted_at == NULL)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -42,6 +42,7 @@
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
<input type="checkbox" class="form-checkbox mr-1" name="send_logs" {{ old('send_logs' ? 'checked': '') }}>
|
||||
<span>{{ ctrans('texts.send_fail_logs_to_our_server') }}</span>
|
||||
<a href="https://www.invoiceninja.com/privacy-policy/">Read more about how we use this</a>
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
71
tests/Unit/InvoiceActionsTest.php
Normal file
71
tests/Unit/InvoiceActionsTest.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Factory\PaymentFactory;
|
||||
use App\Utils\Traits\Invoice\ActionsInvoice;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\MockAccountData;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers App\Utils\Traits\Invoice\ActionInvoice
|
||||
*/
|
||||
class InvoiceActionsTest extends TestCase
|
||||
{
|
||||
use MockAccountData;
|
||||
use DatabaseTransactions;
|
||||
use ActionsInvoice;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->makeTestData();
|
||||
}
|
||||
|
||||
public function testInvoiceIsDeletable()
|
||||
{
|
||||
$this->assertTrue($this->invoiceDeletable());
|
||||
$this->assertFalse($this->invoiceReversable());
|
||||
$this->assertFalse($this->invoiceCancellable());
|
||||
}
|
||||
|
||||
public function testInvoiceIsReversable()
|
||||
{
|
||||
$this->invoice->service()->markPaid()->save();
|
||||
|
||||
$this->assertFalse($this->invoiceDeletable());
|
||||
$this->assertTrue($this->invoiceReversable());
|
||||
$this->assertFalse($this->invoiceCancellable());
|
||||
}
|
||||
|
||||
public function testInvoiceIsCancellable()
|
||||
{
|
||||
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
||||
$payment->amount = 40;
|
||||
$payment->client_id = $this->invoice->client_id;
|
||||
$payment->applied = 0;
|
||||
$payment->refunded = 0;
|
||||
$payment->date = now();
|
||||
$payment->save();
|
||||
|
||||
$this->invoice->service()->applyPayment($payment, 5)->save();
|
||||
|
||||
$this->assertFalse($this->invoiceDeletable());
|
||||
$this->assertTrue($this->invoiceReversable());
|
||||
$this->assertTrue($this->invoiceCancellable());
|
||||
}
|
||||
|
||||
public function testInvoiceUnactionable()
|
||||
{
|
||||
$this->invoice->delete();
|
||||
|
||||
|
||||
$this->assertFalse($this->invoiceDeletable());
|
||||
$this->assertFalse($this->invoiceReversable());
|
||||
$this->assertFalse($this->invoiceCancellable());
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user