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:
parent
c57e6b0c6a
commit
2bc8064eeb
@ -76,7 +76,7 @@ class CreateCreditPdf implements ShouldQueue {
|
|||||||
|
|
||||||
$file_path = $path . $this->credit->number . '.pdf';
|
$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){
|
if($design->is_custom){
|
||||||
$credit_design = new Custom($design->design);
|
$credit_design = new Custom($design->design);
|
||||||
|
@ -19,9 +19,10 @@ use App\Models\ClientContact;
|
|||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Design;
|
use App\Models\Design;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Utils\Traits\Pdf\PdfMaker;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\MakesInvoiceHtml;
|
use App\Utils\Traits\MakesInvoiceHtml;
|
||||||
use App\Utils\Traits\NumberFormatter;
|
use App\Utils\Traits\NumberFormatter;
|
||||||
|
use App\Utils\Traits\Pdf\PdfMaker;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
@ -33,7 +34,7 @@ use Spatie\Browsershot\Browsershot;
|
|||||||
|
|
||||||
class CreateInvoicePdf implements ShouldQueue {
|
class CreateInvoicePdf implements ShouldQueue {
|
||||||
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
|
||||||
|
|
||||||
public $invoice;
|
public $invoice;
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ class CreateInvoicePdf implements ShouldQueue {
|
|||||||
|
|
||||||
$file_path = $path . $this->invoice->number . '.pdf';
|
$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){
|
if($design->is_custom){
|
||||||
$invoice_design = new Custom($design->design);
|
$invoice_design = new Custom($design->design);
|
||||||
|
@ -76,8 +76,7 @@ class CreateQuotePdf implements ShouldQueue {
|
|||||||
|
|
||||||
$path = $this->quote->client->quote_filepath();
|
$path = $this->quote->client->quote_filepath();
|
||||||
|
|
||||||
|
$design = Design::find($this->decodePrimaryKey($this->quote->client->getSetting('quote_design_id')));
|
||||||
$design = Design::find($this->quote->client->getSetting('quote_design_id'));
|
|
||||||
|
|
||||||
if($design->is_custom){
|
if($design->is_custom){
|
||||||
$quote_design = new Custom($design->design);
|
$quote_design = new Custom($design->design);
|
||||||
|
@ -466,31 +466,13 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
return $this->company->company_key . '/';
|
return $this->company->company_key . '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setCompanyDefaults($data, $entity_name)
|
||||||
public function setInvoiceDefaults($invoice) :Invoice
|
|
||||||
{
|
{
|
||||||
$invoice->terms = $this->getSetting('invoice_terms');
|
$data['terms'] = $this->getSetting($entity_name.'_terms');
|
||||||
$invoice->footer = $this->getSetting('invoice_footer');
|
$data['footer'] =$this->getSetting($entity_name.'_footer');
|
||||||
$invoice->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
$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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -194,19 +194,15 @@ class BaseRepository
|
|||||||
$resource = explode('\\', $class->name)[2]; /** This will extract 'Invoice' from App\Models\Invoice */
|
$resource = explode('\\', $class->name)[2]; /** This will extract 'Invoice' from App\Models\Invoice */
|
||||||
$lcfirst_resource_id = lcfirst($resource) . '_id';
|
$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)
|
if ($class->name == Invoice::class || $class->name == Quote::class)
|
||||||
$state['starting_amount'] = $model->amount;
|
$state['starting_amount'] = $model->amount;
|
||||||
|
|
||||||
if (!$model->id) {
|
if (!$model->id) {
|
||||||
|
$data = $client->setCompanyDefaults($data,lcfirst($resource));
|
||||||
$model->uses_inclusive_taxes = $client->getSetting('inclusive_taxes');
|
$model->uses_inclusive_taxes = $client->getSetting('inclusive_taxes');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\Log::error(print_r($data,1));
|
||||||
|
|
||||||
$model->fill($data);
|
$model->fill($data);
|
||||||
$model->save();
|
$model->save();
|
||||||
|
Loading…
Reference in New Issue
Block a user