Make sorting of invoice items reliable.
Some checks failed
Build project image / Build-and-release-image (push) Failing after 3m1s
Some checks failed
Build project image / Build-and-release-image (push) Failing after 3m1s
This commit is contained in:
@@ -32,7 +32,7 @@ class InvoiceitemController extends Controller
|
||||
'name' => 'required|string',
|
||||
'description' => 'nullable|string',
|
||||
'article_number' => 'nullable|string',
|
||||
|
||||
'sort' => 'required|numeric|min:0',
|
||||
]);
|
||||
|
||||
$item = $invoice->items()->create($itemData);
|
||||
|
||||
@@ -104,7 +104,7 @@ class Invoice extends Model
|
||||
*/
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(Invoiceitem::class);
|
||||
return $this->hasMany(Invoiceitem::class)->orderBy('sort');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,7 @@ class Invoiceitem extends Model
|
||||
'total',
|
||||
'name',
|
||||
'description',
|
||||
'sort'
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('invoiceitems', function (Blueprint $table) {
|
||||
$table->integer('sort')->default(0)->after('invoice_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('invoiceitems', function (Blueprint $table) {
|
||||
$table->dropColumn('sort');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -655,6 +655,7 @@
|
||||
for (let i = 0; i < self.items.length; i++) {
|
||||
let pos = sort_flipped[i];
|
||||
let item = self.items[pos];
|
||||
item.sort = i;
|
||||
const result = axios.post('invoice/' + self.invoice_id + '/item', item)
|
||||
.catch(function (error) {
|
||||
self.error = true;
|
||||
|
||||
@@ -662,6 +662,7 @@
|
||||
for (let i = 0; i < self.items.length; i++) {
|
||||
let pos = sort_flipped[i];
|
||||
let item = self.items[pos];
|
||||
item.sort = i;
|
||||
const result = axios.post('invoice/' + self.invoice.id + '/item', item)
|
||||
.catch(function (error) {
|
||||
self.error = true;
|
||||
|
||||
Reference in New Issue
Block a user