mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 14:24:34 -04:00
Fixes for default values for entities (#3438)
This commit is contained in:
parent
000ae58fc6
commit
5bca8f8ad8
@ -209,7 +209,7 @@ class InvoiceController extends BaseController {
|
|||||||
|
|
||||||
$client = Client::find($request->input('client_id'));
|
$client = Client::find($request->input('client_id'));
|
||||||
|
|
||||||
$invoice = $this->invoice_repo->save($request->all(), $client->setInvoiceDefaults());
|
$invoice = $this->invoice_repo->save($request->all(), InvoiceFactory::create(auth()->user()->company(), auth()->user()->id));
|
||||||
|
|
||||||
$invoice = StoreInvoice::dispatchNow($invoice, $request->all(), $invoice->company);//todo potentially this may return mixed ie PDF/$invoice... need to revisit when we implement UI
|
$invoice = StoreInvoice::dispatchNow($invoice, $request->all(), $invoice->company);//todo potentially this may return mixed ie PDF/$invoice... need to revisit when we implement UI
|
||||||
|
|
||||||
|
@ -469,28 +469,28 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
|
|
||||||
public function setInvoiceDefaults() :Invoice
|
public function setInvoiceDefaults() :Invoice
|
||||||
{
|
{
|
||||||
$invoice_factory = InvoiceFactory::create($this->company_id, auth()->user()->id);
|
$invoice->terms = $this->getSetting('invoice_terms');
|
||||||
$invoice_factory->terms = $this->getSetting('invoice_terms');
|
$invoice->footer = $this->getSetting('invoice_footer');
|
||||||
$invoice_factory->footer = $this->getSetting('invoice_footer');
|
$invoice->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
||||||
$invoice_factory->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
|
||||||
return $invoice_factory;
|
return $invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setQuoteDefaults() :Quote
|
public function setQuoteDefaults() :Quote
|
||||||
{
|
{
|
||||||
$quote_factory = QuoteFactory::create($this->company_id, auth()->user()->id);
|
$quote->terms = $this->getSetting('quote_terms');
|
||||||
$quote_factory->terms = $this->getSetting('quote_terms');
|
$quote->footer = $this->getSetting('quote_footer');
|
||||||
$quote_factory->footer = $this->getSetting('quote_footer');
|
$quote->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
||||||
$quote_factory->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
|
||||||
return $quote_factory;
|
return $quote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCreditDefaults() :Credit
|
public function setCreditDefaults() :Credit
|
||||||
{
|
{
|
||||||
$credit_factory = CreditFactory::create($this->company_id, auth()->user()->id);
|
$credit->terms = $this->getSetting('credit_terms');
|
||||||
$credit_factory->terms = $this->getSetting('credit_terms');
|
$credit->footer = $this->getSetting('credit_footer');
|
||||||
$credit_factory->footer = $this->getSetting('credit_footer');
|
$credit->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
||||||
$credit_factory->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
|
||||||
return $credit_factory;
|
return $credit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -188,15 +188,23 @@ class BaseRepository
|
|||||||
{
|
{
|
||||||
$class = new ReflectionClass($model);
|
$class = new ReflectionClass($model);
|
||||||
|
|
||||||
|
$client = Client::find($data['client_id']);
|
||||||
|
|
||||||
$state = [];
|
$state = [];
|
||||||
$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}();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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) {
|
||||||
$client = Client::find($data['client_id']);
|
|
||||||
$model->uses_inclusive_taxes = $client->getSetting('inclusive_taxes');
|
$model->uses_inclusive_taxes = $client->getSetting('inclusive_taxes');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user