1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Fixes for V2 (#3172)

* Optimizations for large queries

* Fixes for client activities

* Implement UpdateOrCreate for products
This commit is contained in:
David Bomba 2019-12-27 09:33:07 +11:00 committed by GitHub
parent e9b9cef2f1
commit d797799196
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 94 additions and 6 deletions

View File

@ -62,6 +62,7 @@ class CompanySettings extends BaseSettings
public $custom_message_unapproved_quote = '';
public $auto_archive_quote = false;
public $auto_convert_quote = false;
public $auto_email_invoice = true;
public $inclusive_taxes = false;
public $quote_footer = '';
@ -218,6 +219,7 @@ class CompanySettings extends BaseSettings
public static $casts = [
'auto_email_invoice' => 'bool',
'reminder_send_time' => 'int',
'email_sending_method' => 'string',
'gmail_sending_user_id' => 'string',

View File

@ -52,7 +52,7 @@ class InvoiceItem
public $custom_value4 = '';
public $invoice_item_type_id = 1;
public $invoice_item_type_id = 1; //1 = product, 2 = service
public static $casts = [
'invoice_item_type_id' => 'string',

View File

@ -0,0 +1,81 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Jobs\Product;
use App\Models\Company;
use App\Models\Payment;
use App\Models\Product;
use App\Repositories\InvoiceRepository;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Capsule\Eloquent;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class UpdateOrCreateProduct implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $products;
private $invoice;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($products, $invoice)
{
$this->products = $products;
$this->invoice = $invoice;
}
/**
* Execute the job.
*
*
* @return void
*/
public function handle()
{
foreach($this->products as $item)
{
$product = Product::firstOrNew(['product_key' => $item->product_key, 'company_id' => $this->invoice->company->id]);
$product->product_key = $item->product_key;
$product->notes = $item->notes;
$product->cost = $item->cost;
$product->tax_name1 = $item->tax_name1;
$product->tax_rate1 = $item->tax_rate1;
$product->tax_name2 = $item->tax_name2;
$product->tax_rate2 = $item->tax_rate2;
$product->custom_value1 = $item->custom_value1;
$product->custom_value2 = $item->custom_value2;
$product->custom_value3 = $item->custom_value3;
$product->custom_value4 = $item->custom_value4;
$product->user_id = $this->invoice->user_id;
$product->company_id = $this->invoice->company_id;
$product->project_id = $this->invoice->project_id;
$product->vendor_id = $this->invoice->vendor_id;
$product->save();
}
}
}

View File

@ -132,7 +132,7 @@ class Client extends BaseModel
public function activities()
{
return $this->hasMany(Activity::class, 'id', 'client_id');
return $this->hasMany(Activity::class);
}
public function contacts()

View File

@ -67,6 +67,7 @@ class Company extends BaseModel
'custom_surcharge_taxes2',
'custom_surcharge_taxes3',
'custom_surcharge_taxes4',
'show_product_details',
];

View File

@ -30,6 +30,10 @@ class InvoiceInvitation extends BaseModel
'client_contact_id',
];
protected $with = [
'company',
];
public function entityType()
{
return Invoice::class;

View File

@ -18,6 +18,7 @@ use App\Helpers\Invoice\InvoiceSum;
use App\Jobs\Company\UpdateCompanyLedgerWithInvoice;
use App\Jobs\Invoice\ApplyInvoiceNumber;
use App\Jobs\Invoice\CreateInvoiceInvitations;
use App\Jobs\Product\UpdateOrCreateProduct;
use App\Listeners\Invoice\CreateInvoiceInvitation;
use App\Models\ClientContact;
use App\Models\Invoice;
@ -116,10 +117,6 @@ class InvoiceRepository extends BaseRepository
$invoice = $invoice->calc()->getInvoice();
// $invoice_calc = new InvoiceSum($invoice, $invoice->settings);
// $invoice = $invoice_calc->build()->getInvoice();
$invoice->save();
$finished_amount = $invoice->amount;
@ -130,6 +127,9 @@ class InvoiceRepository extends BaseRepository
$invoice = ApplyInvoiceNumber::dispatchNow($invoice, $invoice->client->getMergedSettings());
if($invoice->company->update_products !== false)
UpdateOrCreateProduct::dispatch($invoice->line_items, $invoice);
return $invoice->fresh();
}