mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -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'));
|
||||
|
||||
$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
|
||||
|
||||
|
@ -469,28 +469,28 @@ class Client extends BaseModel implements HasLocalePreference
|
||||
|
||||
public function setInvoiceDefaults() :Invoice
|
||||
{
|
||||
$invoice_factory = InvoiceFactory::create($this->company_id, auth()->user()->id);
|
||||
$invoice_factory->terms = $this->getSetting('invoice_terms');
|
||||
$invoice_factory->footer = $this->getSetting('invoice_footer');
|
||||
$invoice_factory->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
||||
return $invoice_factory;
|
||||
$invoice->terms = $this->getSetting('invoice_terms');
|
||||
$invoice->footer = $this->getSetting('invoice_footer');
|
||||
$invoice->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
||||
|
||||
return $invoice;
|
||||
}
|
||||
|
||||
public function setQuoteDefaults() :Quote
|
||||
{
|
||||
$quote_factory = QuoteFactory::create($this->company_id, auth()->user()->id);
|
||||
$quote_factory->terms = $this->getSetting('quote_terms');
|
||||
$quote_factory->footer = $this->getSetting('quote_footer');
|
||||
$quote_factory->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
||||
return $quote_factory;
|
||||
$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_factory = CreditFactory::create($this->company_id, auth()->user()->id);
|
||||
$credit_factory->terms = $this->getSetting('credit_terms');
|
||||
$credit_factory->footer = $this->getSetting('credit_footer');
|
||||
$credit_factory->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
||||
return $credit_factory;
|
||||
$credit->terms = $this->getSetting('credit_terms');
|
||||
$credit->footer = $this->getSetting('credit_footer');
|
||||
$credit->public_notes = isset($this->public_notes) ? $this->public_notes : '';
|
||||
|
||||
return $credit;
|
||||
}
|
||||
}
|
||||
|
@ -188,15 +188,23 @@ class BaseRepository
|
||||
{
|
||||
$class = new ReflectionClass($model);
|
||||
|
||||
$client = Client::find($data['client_id']);
|
||||
|
||||
$state = [];
|
||||
$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}();
|
||||
}
|
||||
|
||||
|
||||
if ($class->name == Invoice::class || $class->name == Quote::class)
|
||||
$state['starting_amount'] = $model->amount;
|
||||
|
||||
if (!$model->id) {
|
||||
$client = Client::find($data['client_id']);
|
||||
$model->uses_inclusive_taxes = $client->getSetting('inclusive_taxes');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user