Fixes for invitations

This commit is contained in:
David Bomba 2021-11-09 21:15:08 +11:00
parent 43aad784ae
commit 57e1385cbf
8 changed files with 84 additions and 8 deletions

View File

@ -522,6 +522,9 @@ class InvoiceController extends BaseController
$ids = request()->input('ids');
nlog($action);
nlog($ids);
$invoices = Invoice::withTrashed()->whereIn('id', $this->transformKeys($ids))->company()->get();
if (! $invoices) {
@ -532,13 +535,14 @@ class InvoiceController extends BaseController
* Download Invoice/s
*/
if ($action == 'download' && $invoices->count() > 1) {
if ($action == 'bulk_download' && $invoices->count() > 1) {
$invoices->each(function ($invoice) {
if (auth()->user()->cannot('view', $invoice)) {
nlog("access denied");
return response()->json(['message' => ctrans('text.access_denied')]);
}
});
nlog("bulky");
ZipInvoices::dispatch($invoices, $invoices->first()->company, auth()->user());
return response()->json(['message' => ctrans('texts.sent_message')], 200);

View File

@ -70,7 +70,7 @@ class ZipInvoices implements ShouldQueue
*/
public function handle()
{
{nlog("bulky");
# create new zip object
$zip = new ZipArchive();

View File

@ -29,7 +29,6 @@ class InvoiceObserver
*/
public function created(Invoice $invoice)
{
nlog("ppo0");
$subscriptions = Webhook::where('company_id', $invoice->company_id)
->where('event_id', Webhook::EVENT_CREATE_INVOICE)

View File

@ -23,7 +23,7 @@ class CreateInvitations extends AbstractService
{
use MakesHash;
private $credit;
public $credit;
public function __construct(Credit $credit)
{
@ -45,6 +45,7 @@ class CreateInvitations extends AbstractService
$invitation = CreditInvitation::whereCompanyId($this->credit->company_id)
->whereClientContactId($contact->id)
->whereCreditId($this->credit->id)
->withTrashed()
->first();
if (! $invitation) {
@ -58,6 +59,34 @@ class CreateInvitations extends AbstractService
}
});
if($this->credit->invitations()->count() == 0) {
if($contacts->count() == 0){
$contact = $this->createBlankContact();
}
else{
$contact = $contacts->first();
$invitation = CreditInvitation::where('company_id', $this->credit->company_id)
->where('client_contact_id', $contact->id)
->where('credit_id', $this->credit->id)
->withTrashed()
->first();
if($invitation){
$invitation->restore();
return $this->credit;
}
}
$ii = CreditInvitationFactory::create($this->credit->company_id, $this->credit->user_id);
$ii->key = $this->createDbHash($this->credit->company->db);
$ii->credit_id = $this->credit->id;
$ii->client_contact_id = $contact->id;
$ii->save();
}
return $this->credit;
}

View File

@ -13,13 +13,14 @@ namespace App\Services\Credit;
use App\Jobs\Util\UnlinkFile;
use App\Models\Credit;
use App\Services\Credit\CreateInvitations;
use App\Utils\Traits\MakesHash;
class CreditService
{
use MakesHash;
protected $credit;
public $credit;
public function __construct($credit)
{

View File

@ -62,7 +62,23 @@ class CreateInvitations extends AbstractService
if($this->invoice->invitations()->count() == 0) {
$contact = $this->createBlankContact();
if($contacts->count() == 0){
$contact = $this->createBlankContact();
}
else{
$contact = $contacts->first();
$invitation = InvoiceInvitation::where('company_id', $this->invoice->company_id)
->where('client_contact_id', $contact->id)
->where('invoice_id', $this->invoice->id)
->withTrashed()
->first();
if($invitation){
$invitation->restore();
return $this->invoice;
}
}
$ii = InvoiceInvitationFactory::create($this->invoice->company_id, $this->invoice->user_id);
$ii->key = $this->createDbHash($this->invoice->company->db);

View File

@ -33,7 +33,7 @@ class InvoiceService
{
use MakesHash;
private $invoice;
public $invoice;
public function __construct($invoice)
{

View File

@ -59,6 +59,33 @@ class CreateInvitations
}
});
if($this->quote->invitations()->count() == 0) {
if($contacts->count() == 0){
$contact = $this->createBlankContact();
}
else{
$contact = $contacts->first();
$invitation = QuoteInvitation::where('company_id', $this->quote->company_id)
->where('client_contact_id', $contact->id)
->where('quote_id', $this->quote->id)
->withTrashed()
->first();
if($invitation){
$invitation->restore();
return $this->quote;
}
}
$ii = QuoteInvitationFactory::create($this->quote->company_id, $this->quote->user_id);
$ii->key = $this->createDbHash($this->quote->company->db);
$ii->quote_id = $this->quote->id;
$ii->client_contact_id = $contact->id;
$ii->save();
}
return $this->quote->fresh();
}