|
@@ -263,12 +263,12 @@ class Invoice extends Model
|
263
|
263
|
return $action::make('approveDraft')
|
264
|
264
|
->label('Approve')
|
265
|
265
|
->icon('heroicon-o-check-circle')
|
266
|
|
- ->visible(function (Invoice $record) {
|
|
266
|
+ ->visible(function (self $record) {
|
267
|
267
|
return $record->isDraft();
|
268
|
268
|
})
|
269
|
269
|
->databaseTransaction()
|
270
|
270
|
->successNotificationTitle('Invoice Approved')
|
271
|
|
- ->action(function (Invoice $record, MountableAction $action) {
|
|
271
|
+ ->action(function (self $record, MountableAction $action) {
|
272
|
272
|
$record->approveDraft();
|
273
|
273
|
|
274
|
274
|
$action->success();
|
|
@@ -280,11 +280,11 @@ class Invoice extends Model
|
280
|
280
|
return $action::make('markAsSent')
|
281
|
281
|
->label('Mark as Sent')
|
282
|
282
|
->icon('heroicon-o-paper-airplane')
|
283
|
|
- ->visible(function (Invoice $record) {
|
|
283
|
+ ->visible(static function (self $record) {
|
284
|
284
|
return ! $record->last_sent;
|
285
|
285
|
})
|
286
|
286
|
->successNotificationTitle('Invoice Sent')
|
287
|
|
- ->action(function (Invoice $record, MountableAction $action) {
|
|
287
|
+ ->action(function (self $record, MountableAction $action) {
|
288
|
288
|
$record->update([
|
289
|
289
|
'status' => InvoiceStatus::Sent,
|
290
|
290
|
'last_sent' => now(),
|
|
@@ -299,14 +299,14 @@ class Invoice extends Model
|
299
|
299
|
return $action::make()
|
300
|
300
|
->excludeAttributes(['status', 'amount_paid', 'amount_due', 'created_by', 'updated_by', 'created_at', 'updated_at', 'invoice_number', 'date', 'due_date'])
|
301
|
301
|
->modal(false)
|
302
|
|
- ->beforeReplicaSaved(function (Invoice $original, Invoice $replica) {
|
|
302
|
+ ->beforeReplicaSaved(function (self $original, self $replica) {
|
303
|
303
|
$replica->status = InvoiceStatus::Draft;
|
304
|
|
- $replica->invoice_number = Invoice::getNextDocumentNumber();
|
|
304
|
+ $replica->invoice_number = self::getNextDocumentNumber();
|
305
|
305
|
$replica->date = now();
|
306
|
306
|
$replica->due_date = now()->addDays($original->company->defaultInvoice->payment_terms->getDays());
|
307
|
307
|
})
|
308
|
308
|
->databaseTransaction()
|
309
|
|
- ->after(function (Invoice $original, Invoice $replica) {
|
|
309
|
+ ->after(function (self $original, self $replica) {
|
310
|
310
|
$original->lineItems->each(function (DocumentLineItem $lineItem) use ($replica) {
|
311
|
311
|
$replicaLineItem = $lineItem->replicate([
|
312
|
312
|
'documentable_id',
|
|
@@ -327,7 +327,7 @@ class Invoice extends Model
|
327
|
327
|
$replicaLineItem->adjustments()->sync($lineItem->adjustments->pluck('id'));
|
328
|
328
|
});
|
329
|
329
|
})
|
330
|
|
- ->successRedirectUrl(function (Invoice $replica) {
|
|
330
|
+ ->successRedirectUrl(static function (self $replica) {
|
331
|
331
|
return InvoiceResource::getUrl('edit', ['record' => $replica]);
|
332
|
332
|
});
|
333
|
333
|
}
|