Skip to content

Commit

Permalink
Merge pull request #8723 from turbo124/v5-stable
Browse files Browse the repository at this point in the history
v5.6.31
  • Loading branch information
turbo124 committed Aug 16, 2023
2 parents a66e668 + 5e95556 commit 7d748c7
Show file tree
Hide file tree
Showing 61 changed files with 1,428 additions and 803 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.6.30
5.6.31
7 changes: 4 additions & 3 deletions app/Console/Commands/CheckData.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use App\Models\QuoteInvitation;
use Illuminate\Console\Command;
use App\Models\CreditInvitation;
use App\Models\RecurringInvoice;
use App\Models\InvoiceInvitation;
use App\DataMapper\ClientSettings;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -471,7 +472,7 @@ private function checkEntityInvitations()
$ii->saveQuietly();
});

collect([Invoice::class, Quote::class, Credit::class, PurchaseOrder::class])->each(function ($entity) {
collect([Invoice::class, Quote::class, Credit::class, PurchaseOrder::class, RecurringInvoice::class])->each(function ($entity) {
if ($entity::doesntHave('invitations')->count() > 0) {
$entity::doesntHave('invitations')->cursor()->each(function ($entity) {
$client_vendor_key = 'client_id';
Expand Down Expand Up @@ -694,7 +695,7 @@ private function checkInvoicePayments()
{
$this->wrong_balances = 0;

Client::cursor()->where('is_deleted', 0)->where('clients.updated_at', '>', now()->subDays(2))->each(function ($client) {
Client::query()->cursor()->where('is_deleted', 0)->where('clients.updated_at', '>', now()->subDays(2))->each(function ($client) {
$client->invoices->where('is_deleted', false)->whereIn('status_id', '!=', Invoice::STATUS_DRAFT)->each(function ($invoice) use ($client) {
$total_paid = $invoice->payments()
->where('is_deleted', false)->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED])
Expand Down Expand Up @@ -876,7 +877,7 @@ private function checkLedgerBalances()
$this->wrong_balances = 0;
$this->wrong_paid_to_dates = 0;

foreach (Client::where('is_deleted', 0)->where('clients.updated_at', '>', now()->subDays(2))->cursor() as $client) {
foreach (Client::query()->where('is_deleted', 0)->where('clients.updated_at', '>', now()->subDays(2))->cursor() as $client) {
$invoice_balance = $client->invoices()->where('is_deleted', false)->whereIn('status_id', [2,3])->sum('balance');
$ledger = CompanyLedger::where('client_id', $client->id)->orderBy('id', 'DESC')->first();

Expand Down
101 changes: 101 additions & 0 deletions app/DataMapper/Analytics/RevenueTrack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/

namespace App\DataMapper\Analytics;

use Turbo124\Beacon\ExampleMetric\GenericMixedMetric;

class RevenueTrack extends GenericMixedMetric
{
/**
* The type of Sample.
*
* Monotonically incrementing counter
*
* - counter
*
* @var string
*/
public $type = 'mixed_metric';

/**
* The name of the counter.
* @var string
*/
public $name = 'app.revenue';

/**
* The datetime of the counter measurement.
*
* date("Y-m-d H:i:s")
*
*/
public $datetime;

/**
* The Client email
*
* @var string
*/
public $string_metric5 = 'email';

/**
* The AccountKey email
*
* @var string
*/
public $string_metric6 = 'key';

/**
* Product Type
*
* @var string
*/
public $string_metric7 = 'product';

/**
* Gateway Reference
*
* @var string
*/
public $string_metric8 = 'gateway_reference';

public $string_metric9 = 'entity_reference';

public $string_metric10 = 'gateway_type';

/**
* The counter
* set to 1.
*
* @var int
*/
public $int_metric1 = 1;

/**
* Amount Received
*
* @var double
*/
public $double_metric2 = 0;

public function __construct($string_metric5, $string_metric6, $int_metric1, $double_metric2, $string_metric7, $string_metric8, $string_metric9, $string_metric10)
{
$this->int_metric1 = $int_metric1;
$this->double_metric2 = $double_metric2;
$this->string_metric5 = $string_metric5;
$this->string_metric6 = $string_metric6;
$this->string_metric7 = $string_metric7;
$this->string_metric8 = $string_metric8;
$this->string_metric9 = $string_metric9;
$this->string_metric10 = $string_metric10;
}
}
5 changes: 5 additions & 0 deletions app/DataMapper/InvoiceItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,13 @@ class InvoiceItem

public $tax_id = '';

public $task_id = '';

public $expense_id = '';

public static $casts = [
'task_id' => 'string',
'expense_id' => 'string',
'tax_id' => 'string',
'type_id' => 'string',
'quantity' => 'float',
Expand Down
36 changes: 36 additions & 0 deletions app/Events/Account/StripeConnectFailure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/

namespace App\Events\Account;

use App\Models\Company;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;

/**
* Class StripeConnectFailure.
*/
class StripeConnectFailure
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct(public Company $company, public string $db)
{
}

public function broadcastOn()
{
return [];
}
}
5 changes: 5 additions & 0 deletions app/Filters/CreditFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public function filter(string $filter = ''): Builder
->orWhere('credits.custom_value4', 'like', '%'.$filter.'%')
->orWhereHas('client', function ($q) use ($filter) {
$q->where('name', 'like', '%'.$filter.'%');
})
->orWhereHas('client.contacts', function ($q) use ($filter) {
$q->where('first_name', 'like', '%'.$filter.'%')
->orWhere('last_name', 'like', '%'.$filter.'%')
->orWhere('email', 'like', '%'.$filter.'%');
});
});
}
Expand Down
5 changes: 5 additions & 0 deletions app/Filters/InvoiceFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public function filter(string $filter = ''): Builder
->orWhere('custom_value4', 'like', '%'.$filter.'%')
->orWhereHas('client', function ($q) use ($filter) {
$q->where('name', 'like', '%'.$filter.'%');
})
->orWhereHas('client.contacts', function ($q) use ($filter) {
$q->where('first_name', 'like', '%'.$filter.'%')
->orWhere('last_name', 'like', '%'.$filter.'%')
->orWhere('email', 'like', '%'.$filter.'%');
});
});
}
Expand Down
7 changes: 6 additions & 1 deletion app/Filters/PaymentFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ public function filter(string $filter = ''): Builder
->orWhere('custom_value4', 'like', '%'.$filter.'%')
->orWhereHas('client', function ($q) use ($filter) {
$q->where('name', 'like', '%'.$filter.'%');
});
})
->orWhereHas('client.contacts', function ($q) use ($filter) {
$q->where('first_name', 'like', '%'.$filter.'%')
->orWhere('last_name', 'like', '%'.$filter.'%')
->orWhere('email', 'like', '%'.$filter.'%');
});
});
}

Expand Down
7 changes: 6 additions & 1 deletion app/Filters/QuoteFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ public function filter(string $filter = ''): Builder
->orWhere('custom_value4', 'like', '%'.$filter.'%')
->orWhereHas('client', function ($q) use ($filter) {
$q->where('name', 'like', '%'.$filter.'%');
});
})
->orWhereHas('client.contacts', function ($q) use ($filter) {
$q->where('first_name', 'like', '%'.$filter.'%')
->orWhere('last_name', 'like', '%'.$filter.'%')
->orWhere('email', 'like', '%'.$filter.'%');
});
});
}

Expand Down
7 changes: 6 additions & 1 deletion app/Filters/RecurringInvoiceFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ public function filter(string $filter = ''): Builder
->orWhere('custom_value4', 'like', '%'.$filter.'%')
->orWhereHas('client', function ($q) use ($filter) {
$q->where('name', 'like', '%'.$filter.'%');
});
})
->orWhereHas('client.contacts', function ($q) use ($filter) {
$q->where('first_name', 'like', '%'.$filter.'%')
->orWhere('last_name', 'like', '%'.$filter.'%')
->orWhere('email', 'like', '%'.$filter.'%');
});
});
}

Expand Down
7 changes: 6 additions & 1 deletion app/Filters/TaskFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ public function filter(string $filter = ''): Builder
})
->orWhereHas('client', function ($q) use ($filter) {
$q->where('name', 'like', '%'.$filter.'%');
});
})
->orWhereHas('client.contacts', function ($q) use ($filter) {
$q->where('first_name', 'like', '%'.$filter.'%')
->orWhere('last_name', 'like', '%'.$filter.'%')
->orWhere('email', 'like', '%'.$filter.'%');
});
});
}

Expand Down
3 changes: 1 addition & 2 deletions app/Filters/UserFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ public function without(string $user_id = ''): Builder
$user_array = $this->transformKeys(explode(',', $user_id));

return $this->builder->where(function ($query) use ($user_array) {
$query->whereNotIn('id', $user_array)
->where('account_id', auth()->user()->account_id);
$query->whereNotIn('id', $user_array);
});
}
}
13 changes: 11 additions & 2 deletions app/Http/Controllers/ClientPortal/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,20 @@ private function buildZip($invoices)
// create new archive
$zipFile = new \PhpZip\ZipFile();
try {

foreach ($invoices as $invoice) {
//add it to the zip
$zipFile->addFromString(basename($invoice->pdf_file_path()), file_get_contents($invoice->pdf_file_path(null, 'url', true)));

if ($invoice->client->getSetting('enable_e_invoice')) {
$xml = $invoice->service()->getEInvoice();
$zipFile->addFromString($invoice->getFileName("xml"), $xml);
}

$file = $invoice->service()->getRawInvoicePdf();
$zip_file_name = $invoice->getFileName();
$zipFile->addFromString($zip_file_name, $file);
}


$filename = date('Y-m-d').'_'.str_replace(' ', '_', trans('texts.invoices')).'.zip';
$filepath = sys_get_temp_dir().'/'.$filename;

Expand Down

0 comments on commit 7d748c7

Please sign in to comment.