1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Fixes for setting entity defaults (#3440)

This commit is contained in:
David Bomba 2020-03-06 23:18:32 +11:00 committed by GitHub
parent c57e6b0c6a
commit 2bc8064eeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 36 deletions

View File

@ -76,7 +76,7 @@ class CreateCreditPdf implements ShouldQueue {
$file_path = $path . $this->credit->number . '.pdf';
$design = Design::find($this->credit->client->getSetting('credit_design_id'));
$design = Design::find($this->decodePrimaryKey($this->credit->client->getSetting('credit_design_id')));
if($design->is_custom){
$credit_design = new Custom($design->design);

View File

@ -19,9 +19,10 @@ use App\Models\ClientContact;
use App\Models\Company;
use App\Models\Design;
use App\Models\Invoice;
use App\Utils\Traits\Pdf\PdfMaker;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\MakesInvoiceHtml;
use App\Utils\Traits\NumberFormatter;
use App\Utils\Traits\Pdf\PdfMaker;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
@ -33,7 +34,7 @@ use Spatie\Browsershot\Browsershot;
class CreateInvoicePdf implements ShouldQueue {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker;
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
public $invoice;
@ -74,7 +75,7 @@ class CreateInvoicePdf implements ShouldQueue {
$file_path = $path . $this->invoice->number . '.pdf';
$design = Design::find($this->invoice->client->getSetting('invoice_design_id'));
$design = Design::find($this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id')));
if($design->is_custom){
$invoice_design = new Custom($design->design);

View File

@ -76,8 +76,7 @@ class CreateQuotePdf implements ShouldQueue {
$path = $this->quote->client->quote_filepath();
$design = Design::find($this->quote->client->getSetting('quote_design_id'));
$design = Design::find($this->decodePrimaryKey($this->quote->client->getSetting('quote_design_id')));
if($design->is_custom){
$quote_design = new Custom($design->design);

View File

@ -466,31 +466,13 @@ class Client extends BaseModel implements HasLocalePreference
return $this->company->company_key . '/';
}
public function setInvoiceDefaults($invoice) :Invoice
public function setCompanyDefaults($data, $entity_name)
{
$invoice->terms = $this->getSetting('invoice_terms');
$invoice->footer = $this->getSetting('invoice_footer');
$invoice->public_notes = isset($this->public_notes) ? $this->public_notes : '';
$data['terms'] = $this->getSetting($entity_name.'_terms');
$data['footer'] =$this->getSetting($entity_name.'_footer');
$data['public_notes'] = isset($this->public_notes) ? $this->public_notes : '';
return $invoice;
return $data;
}
public function setQuoteDefaults($quote) :Quote
{
$quote->terms = $this->getSetting('quote_terms');
$quote->footer = $this->getSetting('quote_footer');
$quote->public_notes = isset($this->public_notes) ? $this->public_notes : '';
return $quote;
}
public function setCreditDefaults($credit) :Credit
{
$credit->terms = $this->getSetting('credit_terms');
$credit->footer = $this->getSetting('credit_footer');
$credit->public_notes = isset($this->public_notes) ? $this->public_notes : '';
return $credit;
}
}

View File

@ -194,20 +194,16 @@ class BaseRepository
$resource = explode('\\', $class->name)[2]; /** This will extract 'Invoice' from App\Models\Invoice */
$lcfirst_resource_id = lcfirst($resource) . '_id';
//if new, set defaults!
if(!$model->id) {
$methodName = "set" . $resource . "Defaults";
$model = $client->{$methodName}($model);
}
if ($class->name == Invoice::class || $class->name == Quote::class)
$state['starting_amount'] = $model->amount;
if (!$model->id) {
$data = $client->setCompanyDefaults($data,lcfirst($resource));
$model->uses_inclusive_taxes = $client->getSetting('inclusive_taxes');
}
\Log::error(print_r($data,1));
$model->fill($data);
$model->save();