mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 17:24:29 -04:00
Fixes for converting quotes to invoices - invitations
This commit is contained in:
parent
8e586c788d
commit
37aac0db03
@ -13,12 +13,14 @@ namespace App\Jobs\RecurringInvoice;
|
|||||||
|
|
||||||
use App\DataMapper\Analytics\SendRecurringFailure;
|
use App\DataMapper\Analytics\SendRecurringFailure;
|
||||||
use App\Events\Invoice\InvoiceWasEmailed;
|
use App\Events\Invoice\InvoiceWasEmailed;
|
||||||
|
use App\Factory\InvoiceInvitationFactory;
|
||||||
use App\Factory\RecurringInvoiceToInvoiceFactory;
|
use App\Factory\RecurringInvoiceToInvoiceFactory;
|
||||||
use App\Jobs\Entity\EmailEntity;
|
use App\Jobs\Entity\EmailEntity;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\RecurringInvoice;
|
use App\Models\RecurringInvoice;
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Traits\GeneratesCounter;
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\MakesInvoiceValues;
|
use App\Utils\Traits\MakesInvoiceValues;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
@ -32,7 +34,8 @@ class SendRecurring implements ShouldQueue
|
|||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
use GeneratesCounter;
|
use GeneratesCounter;
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
public $recurring_invoice;
|
public $recurring_invoice;
|
||||||
|
|
||||||
protected $db;
|
protected $db;
|
||||||
@ -58,16 +61,6 @@ class SendRecurring implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle() : void
|
public function handle() : void
|
||||||
{
|
{
|
||||||
//reset all contacts here
|
|
||||||
// $this->recurring_invoice->client->contacts()->update(['send_email' => false]);
|
|
||||||
|
|
||||||
// $this->recurring_invoice->invitations->each(function ($invitation){
|
|
||||||
|
|
||||||
// $contact = $invitation->contact;
|
|
||||||
// $contact->send_email = true;
|
|
||||||
// $contact->save();
|
|
||||||
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Generate Standard Invoice
|
// Generate Standard Invoice
|
||||||
$invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client);
|
$invoice = RecurringInvoiceToInvoiceFactory::create($this->recurring_invoice, $this->recurring_invoice->client);
|
||||||
@ -86,10 +79,12 @@ class SendRecurring implements ShouldQueue
|
|||||||
$invoice = $invoice->service()
|
$invoice = $invoice->service()
|
||||||
->markSent()
|
->markSent()
|
||||||
->applyNumber()
|
->applyNumber()
|
||||||
->createInvitations() //need to only link invitations to those in the recurring invoice
|
// ->createInvitations() //need to only link invitations to those in the recurring invoice
|
||||||
->fillDefaults()
|
->fillDefaults()
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
$invoice = $this->createRecurringInvitations($invoice);
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
|
||||||
@ -154,6 +149,28 @@ class SendRecurring implements ShouldQueue
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only create the invitations that are defined on the recurring invoice.
|
||||||
|
* @param Invoice $invoice
|
||||||
|
* @return Invoice $invoice
|
||||||
|
*/
|
||||||
|
private function createRecurringInvitations($invoice) :Invoice
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->recurring_invoice->invitations->each(function ($recurring_invitation) use($invoice){
|
||||||
|
|
||||||
|
$ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id);
|
||||||
|
$ii->key = $this->createDbHash(config('database.default'));
|
||||||
|
$ii->invoice_id = $invoice->id;
|
||||||
|
$ii->client_contact_id = $recurring_invitation->client_contact_id;
|
||||||
|
$ii->save();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return $invoice->fresh();
|
||||||
|
}
|
||||||
|
|
||||||
public function failed($exception = null)
|
public function failed($exception = null)
|
||||||
{
|
{
|
||||||
nlog('the job failed');
|
nlog('the job failed');
|
||||||
|
@ -222,15 +222,15 @@ class BaseRepository
|
|||||||
$this->saveDocuments($data['documents'], $model);
|
$this->saveDocuments($data['documents'], $model);
|
||||||
|
|
||||||
/* Marks whether the client contact should receive emails based on the send_email property */
|
/* Marks whether the client contact should receive emails based on the send_email property */
|
||||||
if (isset($data['client_contacts'])) {
|
// if (isset($data['client_contacts'])) {
|
||||||
foreach ($data['client_contacts'] as $contact) {
|
// foreach ($data['client_contacts'] as $contact) {
|
||||||
if ($contact['send_email'] == 1 && is_string($contact['id'])) {
|
// if ($contact['send_email'] == 1 && is_string($contact['id'])) {
|
||||||
$client_contact = ClientContact::find($this->decodePrimaryKey($contact['id']));
|
// $client_contact = ClientContact::find($this->decodePrimaryKey($contact['id']));
|
||||||
$client_contact->send_email = true;
|
// $client_contact->send_email = true;
|
||||||
$client_contact->save();
|
// $client_contact->save();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/* If invitations are present we need to filter existing invitations with the new ones */
|
/* If invitations are present we need to filter existing invitations with the new ones */
|
||||||
if (isset($data['invitations'])) {
|
if (isset($data['invitations'])) {
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
namespace App\Services\Quote;
|
namespace App\Services\Quote;
|
||||||
|
|
||||||
use App\Factory\CloneQuoteToInvoiceFactory;
|
use App\Factory\CloneQuoteToInvoiceFactory;
|
||||||
|
use App\Factory\InvoiceInvitationFactory;
|
||||||
|
use App\Models\Invoice;
|
||||||
use App\Models\Quote;
|
use App\Models\Quote;
|
||||||
use App\Repositories\InvoiceRepository;
|
use App\Repositories\InvoiceRepository;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
@ -39,14 +41,20 @@ class ConvertQuote
|
|||||||
{
|
{
|
||||||
$invoice = CloneQuoteToInvoiceFactory::create($quote, $quote->user_id);
|
$invoice = CloneQuoteToInvoiceFactory::create($quote, $quote->user_id);
|
||||||
$invoice->design_id = $this->decodePrimaryKey($this->client->getSetting('invoice_design_id'));
|
$invoice->design_id = $this->decodePrimaryKey($this->client->getSetting('invoice_design_id'));
|
||||||
$invoice = $this->invoice_repo->save($invoice->toArray(), $invoice);
|
|
||||||
|
//create invitations here before the repo save()
|
||||||
|
//we need to do this here otherwise the repo_save will create
|
||||||
|
//invitations for ALL contacts
|
||||||
|
$invites = $this->createConversionInvitations($invoice, $quote);
|
||||||
|
$invoice_array = $invoice->toArray();
|
||||||
|
$invoice_array['invitations'] = $invites;
|
||||||
|
|
||||||
|
$invoice = $this->invoice_repo->save($invoice_array, $invoice);
|
||||||
|
|
||||||
$invoice->fresh();
|
$invoice->fresh();
|
||||||
|
|
||||||
$invoice->service()
|
$invoice->service()
|
||||||
->fillDefaults()
|
->fillDefaults()
|
||||||
// ->markSent()
|
|
||||||
// ->createInvitations()
|
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
$quote->invoice_id = $invoice->id;
|
$quote->invoice_id = $invoice->id;
|
||||||
@ -56,4 +64,26 @@ class ConvertQuote
|
|||||||
// maybe should return invoice here
|
// maybe should return invoice here
|
||||||
return $invoice;
|
return $invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only create the invitations that are defined on the quote.
|
||||||
|
*
|
||||||
|
* @return Invoice $invoice
|
||||||
|
*/
|
||||||
|
private function createConversionInvitations($invoice, $quote)
|
||||||
|
{
|
||||||
|
$invites = [];
|
||||||
|
|
||||||
|
foreach($quote->invitations as $quote_invitation){
|
||||||
|
|
||||||
|
$ii = InvoiceInvitationFactory::create($invoice->company_id, $invoice->user_id);
|
||||||
|
$ii->key = $this->createDbHash(config('database.default'));
|
||||||
|
$ii->client_contact_id = $quote_invitation->client_contact_id;
|
||||||
|
|
||||||
|
$invites[] = $ii;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $invites;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Services\Quote;
|
namespace App\Services\Quote;
|
||||||
|
|
||||||
use App\Events\Quote\QuoteWasApproved;
|
use App\Events\Quote\QuoteWasApproved;
|
||||||
|
use App\Factory\InvoiceInvitationFactory;
|
||||||
use App\Jobs\Util\UnlinkFile;
|
use App\Jobs\Util\UnlinkFile;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Quote;
|
use App\Models\Quote;
|
||||||
@ -117,7 +118,6 @@ class QuoteService
|
|||||||
$this->invoice
|
$this->invoice
|
||||||
->service()
|
->service()
|
||||||
->markSent()
|
->markSent()
|
||||||
->createInvitations()
|
|
||||||
->deletePdf()
|
->deletePdf()
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
|
@ -54,8 +54,6 @@ class RecurringService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
// $this->createInvitations()->setStatus(RecurringInvoice::STATUS_ACTIVE);
|
|
||||||
|
|
||||||
$this->setStatus(RecurringInvoice::STATUS_ACTIVE);
|
$this->setStatus(RecurringInvoice::STATUS_ACTIVE);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user