mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 00:02:15 +00:00
Delete invoice
This commit is contained in:
@@ -73,10 +73,8 @@ class ClientController extends Controller
|
||||
*/
|
||||
public function destroy(Client $client)
|
||||
{
|
||||
if ($client->user_id === Auth::id()) {
|
||||
$client->delete();
|
||||
$client->delete();
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
return response('Done', 204);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,6 +127,17 @@ class InvoiceController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Invoice $invoice
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(Invoice $invoice)
|
||||
{
|
||||
$invoice->delete();
|
||||
|
||||
return response('Done', 204);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StoreInvoiceRequest $request
|
||||
* @return mixed
|
||||
|
||||
@@ -85,7 +85,7 @@ function invoice_total_discount($invoice, $format = false)
|
||||
// Percent discount
|
||||
if ($invoice['discount_type'] === 'percent') {
|
||||
|
||||
$discount = (invoice_total_net($invoice) + invoice_total_tax($invoice)) * ($invoice['discount_rate'] / 100);
|
||||
$discount = (int) (invoice_total_net($invoice) + invoice_total_tax($invoice)) * ($invoice['discount_rate'] / 100);
|
||||
|
||||
if ($format) {
|
||||
return Cashier::formatAmount($discount * 100, $invoice['currency'], 'cs');
|
||||
@@ -153,5 +153,5 @@ function invoice_total_tax($invoice, $format = false)
|
||||
*/
|
||||
function format_to_currency($value, $currency = 'CZK', $locale = 'cs')
|
||||
{
|
||||
return Cashier::formatAmount(($value * 100), $currency, $locale);
|
||||
return Cashier::formatAmount(((int) $value * 100), $currency, $locale);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use Auth;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Scout\Searchable;
|
||||
use TeamTNT\TNTSearch\Indexer\TNTIndexer;
|
||||
@@ -70,5 +71,9 @@ class Invoice extends Model
|
||||
|
||||
$invoice->currency = 'CZK';
|
||||
});
|
||||
|
||||
static::deleting(function ($invoice) {
|
||||
Storage::delete(invoice_path($invoice));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ Route::group(['middleware' => 'api', 'prefix' => '/api/oasis'], function () {
|
||||
Route::get('/search', [InvoiceController::class, 'search']);
|
||||
|
||||
Route::post('/', [InvoiceController::class, 'store']);
|
||||
Route::delete('/{invoice}', [InvoiceController::class, 'destroy']);
|
||||
|
||||
Route::get('/profile', [InvoiceProfileController::class, 'show']);
|
||||
Route::post('/profile', [InvoiceProfileController::class, 'store']);
|
||||
|
||||
@@ -125,6 +125,10 @@ class OasisClientTest extends TestCase
|
||||
$this->deleteJson("/api/oasis/clients/$client->id")
|
||||
->assertStatus(204);
|
||||
|
||||
$this->assertDatabaseMissing('clients', [
|
||||
'id' => $client->id
|
||||
]);
|
||||
|
||||
Storage::disk('local')
|
||||
->assertMissing('avatar/fake-image.jpg');
|
||||
}
|
||||
|
||||
@@ -494,6 +494,53 @@ class OasisInvoiceTest extends TestCase
|
||||
Notification::assertTimesSent(1, InvoiceDeliveryNotification::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function user_delete_invoice()
|
||||
{
|
||||
$user = User::factory(User::class)
|
||||
->create(['role' => 'user']);
|
||||
|
||||
Sanctum::actingAs($user);
|
||||
|
||||
$profile = InvoiceProfile::factory(InvoiceProfile::class)
|
||||
->create(['user_id' => $user->id]);
|
||||
|
||||
$invoice = Invoice::factory(Invoice::class)
|
||||
->create([
|
||||
'user_id' => $user->id,
|
||||
'invoice_type' => 'regular-invoice',
|
||||
'user' => $profile->toArray(),
|
||||
]);
|
||||
|
||||
\PDF::loadView('oasis.invoices.invoice', [
|
||||
'invoice' => Invoice::find($invoice->id),
|
||||
'user' => $user,
|
||||
])
|
||||
->setPaper('a4')
|
||||
->setOrientation('portrait')
|
||||
->save(
|
||||
storage_path("app/files/{$invoice->user_id}/invoice-{$invoice->id}.pdf")
|
||||
);
|
||||
|
||||
Storage::disk('local')
|
||||
->assertExists(
|
||||
invoice_path($invoice)
|
||||
);
|
||||
|
||||
$this->delete("/api/oasis/invoices/$invoice->id");
|
||||
|
||||
$this->assertDatabaseMissing('invoices', [
|
||||
'id' => $invoice->id
|
||||
]);
|
||||
|
||||
Storage::disk('local')
|
||||
->assertMissing(
|
||||
invoice_path($invoice)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user