mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-15 09:14:08 +00:00
Add Convert to Estimate feature for invoices
New backend endpoint POST /invoices/{id}/convert-to-estimate that
creates a draft estimate from an invoice, copying items, taxes,
custom fields, and financial data. Frontend wired with dropdown
action, store method, and API service call.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\InvoiceService;
|
||||
use App\Services\Pdf\PdfTemplateUtils;
|
||||
use App\Support\PdfHtmlSanitizer;
|
||||
use App\Traits\GeneratesPdfTrait;
|
||||
use App\Traits\HasCustomFieldsTrait;
|
||||
@@ -12,6 +13,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Support\Str;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
@@ -295,6 +297,22 @@ class Invoice extends Model implements HasMedia
|
||||
$query->orWhere('id', $invoice_id);
|
||||
}
|
||||
|
||||
public function getEstimateTemplateName(): string
|
||||
{
|
||||
$templateName = Str::replace('invoice', 'estimate', $this->template_name);
|
||||
|
||||
$names = [];
|
||||
foreach (PdfTemplateUtils::getFormattedTemplates('estimate') as $template) {
|
||||
$names[] = $template['name'];
|
||||
}
|
||||
|
||||
if (! in_array($templateName, $names)) {
|
||||
$templateName = 'estimate1';
|
||||
}
|
||||
|
||||
return $templateName;
|
||||
}
|
||||
|
||||
public function scopeWhereCompany($query)
|
||||
{
|
||||
$query->where('invoices.company_id', request()->header('company'));
|
||||
|
||||
Reference in New Issue
Block a user