Skip to content

Commit

Permalink
Merge pull request #8701 from turbo124/v5-stable
Browse files Browse the repository at this point in the history
v5.6.27
  • Loading branch information
turbo124 committed Aug 8, 2023
2 parents 0948a1b + 53ddb61 commit 44b01b9
Show file tree
Hide file tree
Showing 208 changed files with 765 additions and 751 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.6.26
5.6.27
4 changes: 2 additions & 2 deletions app/DataMapper/Tax/AU/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ public function calculateRates(): self
// $this->reduced_tax_rate = $this->client->company->tax_data->regions->EU->subregions->{$this->client->company->country()->iso_3166_2}->reduced_tax_rate;
// }

$this->tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate;
$this->reduced_tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate;
$this->tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate ?? 0;
$this->reduced_tax_rate = $this->client->company->tax_data->regions->AU->subregions->{$this->client->company->country()->iso_3166_2}->tax_rate ?? 0;

return $this;

Expand Down
10 changes: 9 additions & 1 deletion app/Export/CSV/BaseExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class BaseExport
"state" => "client.state",
"postal_code" => "client.postal_code",
"country" => "client.country_id",
"custom_value4" => "contact.custom_value4",
"shipping_address1" => "client.shipping_address1",
"shipping_address2" => "client.shipping_address2",
"shipping_city" => "client.shipping_city",
Expand All @@ -109,6 +108,15 @@ class BaseExport
"first_name" => "contact.first_name",
"last_name" => "contact.last_name",
"email" => "contact.email",
'custom_value1' => 'client.custom_value1',
'custom_value2' => 'client.custom_value2',
'custom_value3' => 'client.custom_value3',
'custom_value4' => 'client.custom_value4',
"contact_custom_value1" => "contact.custom_value1",
"contact_custom_value2" => "contact.custom_value2",
"contact_custom_value3" => "contact.custom_value3",
"contact_custom_value4" => "contact.custom_value4",

];

protected array $invoice_report_keys = [
Expand Down
3 changes: 2 additions & 1 deletion app/Export/CSV/ProductSalesExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function run()
$t = app('translator');
$t->replace(Ninja::transformTranslations($this->company->settings));

$this->products = Product::where('company_id', $this->company->id)->withTrashed()->get();
$this->products = Product::query()->where('company_id', $this->company->id)->withTrashed()->get();

//load the CSV document from a string
$this->csv = Writer::createFromString();
Expand Down Expand Up @@ -187,6 +187,7 @@ private function decorateAdvancedFields(Invoice $invoice, $entity) :array
$product = $this->getProduct($entity['product_key']);

$entity['cost'] = $product->cost ?? 0;
/** @var float $unit_cost */
$unit_cost = $entity['cost'] == 0 ? 1 : $entity['cost'];

$entity['client'] = $invoice->client->present()->name();
Expand Down
1 change: 0 additions & 1 deletion app/Export/CSV/RecurringInvoiceExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class RecurringInvoiceExport extends BaseExport
'vendor' => 'vendor_id',
'project' => 'project_id',
'frequency_id' => 'frequency_id',
'next_send_date' => 'next_send_date'
];

private array $decorate_keys = [
Expand Down
10 changes: 7 additions & 3 deletions app/Filters/QueryFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function __construct(Request $request)
/**
* Apply the filters to the builder.
*
* @param Builder $builder
* @return Builder
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return \Illuminate\Database\Eloquent\Builder
*/
public function apply(Builder $builder)
{
Expand Down Expand Up @@ -239,7 +239,11 @@ public function updated_at($value = '')
}
}


/**
*
* @param string $value
* @return \Illuminate\Database\Eloquent\Builder
*/
public function is_deleted($value = 'true')
{
if ($value == 'true') {
Expand Down
6 changes: 4 additions & 2 deletions app/Helpers/Invoice/InvoiceItemSumInclusive.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class InvoiceItemSumInclusive

protected RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder | RecurringQuote $invoice;

private $currency;
private \App\Models\Currency $currency;

private $total_taxes;

Expand Down Expand Up @@ -226,8 +226,10 @@ private function calcTaxes()

$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / 100));

/** @var float $item_tax_rate1_total */
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);


/** @var float $item_tax */
$item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision);

if (strlen($this->item->tax_name1) > 1) {
Expand Down
3 changes: 3 additions & 0 deletions app/Helpers/Mail/GmailTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function doSend(SentMessage $message): void
nlog("In Do Send");
$message = MessageConverter::toEmail($message->getOriginalMessage());

/** @phpstan-ignore-next-line **/
$token = $message->getHeaders()->get('gmailtoken')->getValue();
$message->getHeaders()->remove('gmailtoken');

Expand All @@ -52,6 +53,8 @@ protected function doSend(SentMessage $message): void
if ($bccs) {
$bcc_list = 'Bcc: ';


/** @phpstan-ignore-next-line **/
foreach ($bccs->getAddresses() as $address) {
$bcc_list .= $address->getAddress() .',';
}
Expand Down
4 changes: 4 additions & 0 deletions app/Helpers/Mail/Office365MailTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ protected function doSend(SentMessage $message): void
$symfony_message = MessageConverter::toEmail($message->getOriginalMessage());

$graph = new Graph();

/** @phpstan-ignore-next-line **/
$token = $symfony_message->getHeaders()->get('gmailtoken')->getValue();
$symfony_message->getHeaders()->remove('gmailtoken');

Expand All @@ -38,6 +40,8 @@ protected function doSend(SentMessage $message): void
$bcc_list = '';

if ($bccs) {

/** @phpstan-ignore-next-line **/
foreach ($bccs->getAddresses() as $address) {
$bcc_list .= 'Bcc: "'.$address->getAddress().'" <'.$address->getAddress().'>\r\n';
}
Expand Down
2 changes: 1 addition & 1 deletion app/Helpers/Subscription/SubscriptionCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(Subscription $target_subscription, Invoice $invoice)
*/
public function isPaidUp() :bool
{
$outstanding_invoices_exist = Invoice::whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
$outstanding_invoices_exist = Invoice::query()->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])
->where('subscription_id', $this->invoice->subscription_id)
->where('client_id', $this->invoice->client_id)
->where('balance', '>', 0)
Expand Down
11 changes: 5 additions & 6 deletions app/Http/Controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,9 @@ protected function refreshResponse($query)

$paginator = $query->paginate($limit);

/** @phpstan-ignore-next-line */
$query = $paginator->getCollection(); /** @phpstan-ignore-line */


/** @phpstan-ignore-next-line **/
$query = $paginator->getCollection();

$resource = new Collection($query, $transformer, $this->entity_type);

$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
Expand Down Expand Up @@ -636,7 +635,7 @@ protected function miniLoadResponse($query)

$paginator = $query->paginate($limit);

/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line **/
$query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $this->entity_type);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
Expand Down Expand Up @@ -885,7 +884,7 @@ protected function timeConstrainedResponse($query)

$paginator = $query->paginate($limit);

/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line **/
$query = $paginator->getCollection();

$resource = new Collection($query, $transformer, $this->entity_type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public function showAppleMerchantId(Request $request)
/* Self Host */

if (Ninja::isSelfHost()) {
$cgs = CompanyGateway::whereIn('gateway_key', $this->stripe_keys)
$cgs = CompanyGateway::query()
->whereIn('gateway_key', $this->stripe_keys)
->where('is_deleted', false)
->get();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ClientPortal/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function publicDownload(string $document_hash)
public function downloadMultiple(DownloadMultipleDocumentsRequest $request)
{
/** @var \Illuminate\Database\Eloquent\Collection<Document> $documents **/
$documents = Document::whereIn('id', $this->transformKeys($request->file_hash))
$documents = Document::query()->whereIn('id', $this->transformKeys($request->file_hash))
->where('company_id', auth()->guard('contact')->user()->company_id)
->get();

Expand Down
16 changes: 12 additions & 4 deletions app/Http/Controllers/ClientPortal/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,19 @@ public function show(ShowInvoiceRequest $request, Invoice $invoice, ?string $has
public function showBlob($hash)
{
$data = Cache::get($hash);

$invitation = false;

match($data['entity_type']){
'invoice' => $invitation = InvoiceInvitation::withTrashed()->find($data['invitation_id']),
'quote' => $invitation = QuoteInvitation::withTrashed()->find($data['invitation_id']),
'credit' => $invitation = CreditInvitation::withTrashed()->find($data['invitation_id']),
'recurring_invoice' => $invitation = RecurringInvoiceInvitation::withTrashed()->find($data['invitation_id']),
};

if (! $invitation) {
return redirect('/');
}

$file = (new \App\Jobs\Entity\CreateRawPdf($invitation, $invitation->company->db))->handle();

$headers = ['Content-Type' => 'application/pdf'];
Expand Down Expand Up @@ -128,7 +133,8 @@ public function bulk(ProcessInvoicesInBulkRequest $request)

public function downloadInvoices($ids)
{
$data['invoices'] = Invoice::whereIn('id', $ids)
$data['invoices'] = Invoice::query()
->whereIn('id', $ids)
->whereClientId(auth()->guard('contact')->user()->client->id)
->withTrashed()
->get();
Expand All @@ -153,7 +159,8 @@ public function download(Request $request)
*/
private function makePayment(array $ids)
{
$invoices = Invoice::whereIn('id', $ids)
$invoices = Invoice::query()
->whereIn('id', $ids)
->whereClientId(auth()->guard('contact')->user()->client->id)
->withTrashed()
->get();
Expand Down Expand Up @@ -215,7 +222,8 @@ private function makePayment(array $ids)
*/
private function downloadInvoicePDF(array $ids)
{
$invoices = Invoice::whereIn('id', $ids)
$invoices = Invoice::query()
->whereIn('id', $ids)
->withTrashed()
->whereClientId(auth()->guard('contact')->user()->client->id)
->get();
Expand Down
10 changes: 6 additions & 4 deletions app/Http/Controllers/ClientPortal/NinjaPlanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class NinjaPlanController extends Controller
public function index(string $contact_key, string $account_or_company_key)
{
MultiDB::findAndSetDbByCompanyKey($account_or_company_key);
$company = Company::where('company_key', $account_or_company_key)->first();
$company = Company::query()->where('company_key', $account_or_company_key)->first();

if (! $company) {
MultiDB::findAndSetDbByAccountKey($account_or_company_key);

/** @var \App\Models\Account $account **/
$account = Account::where('key', $account_or_company_key)->first();
$account = Account::query()->where('key', $account_or_company_key)->first();
} else {
$account = $company->account;
}
Expand Down Expand Up @@ -157,6 +157,8 @@ public function trial_confirmation(Request $request)

//create recurring invoice
$subscription_repo = new SubscriptionRepository();

/** @var \App\Models\Subscription $subscription **/
$subscription = Subscription::find(6);

$recurring_invoice = RecurringInvoiceFactory::create($subscription->company_id, $subscription->user_id);
Expand All @@ -181,7 +183,7 @@ public function trial_confirmation(Request $request)
->increment()
->queue();

$old_recurring = RecurringInvoice::where('company_id', config('ninja.ninja_default_company_id'))
$old_recurring = RecurringInvoice::query()->where('company_id', config('ninja.ninja_default_company_id'))
->where('client_id', $client->id)
->where('id', '!=', $recurring_invoice->id)
->first();
Expand Down Expand Up @@ -215,7 +217,7 @@ public function plan()
$data['late_invoice'] = false;

if (MultiDB::findAndSetDbByAccountKey(Auth::guard('contact')->user()->client->custom_value2)) {
$account = Account::where('key', Auth::guard('contact')->user()->client->custom_value2)->first();
$account = Account::query()->where('key', Auth::guard('contact')->user()->client->custom_value2)->first();

if ($account) {
//offer the option to have a free trial
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ClientPortal/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function credit_response(Request $request)
$payment = $payment->service()->applyCredits($payment_hash)->save();

/** @var \Illuminate\Database\Eloquent\Collection<\App\Models\Invoice> $invoices */
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')));
$invoices = Invoice::query()->whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')));

$invoices->each(function ($invoice) {
/** @var \App\Models\Invoice $invoice **/
Expand Down
17 changes: 10 additions & 7 deletions app/Http/Controllers/ClientPortal/QuoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public function downloadQuotes($ids)
/** @var \App\Models\ClientContact $client_contact **/
$client_contact = auth()->user();

$data['quotes'] = Quote::whereIn('id', $ids)
->whereClientId($client_contact->client->id)
$data['quotes'] = Quote::query()
->whereIn('id', $ids)
->where('client_id', $client_contact->client_id)
->withTrashed()
->get();

Expand All @@ -120,7 +121,8 @@ protected function downloadQuotePdf(array $ids)
/** @var \App\Models\ClientContact $client_contact **/
$client_contact = auth()->user();

$quotes = Quote::whereIn('id', $ids)
$quotes = Quote::query()
->whereIn('id', $ids)
->whereClientId($client_contact->client_id)
->withTrashed()
->get();
Expand Down Expand Up @@ -168,7 +170,8 @@ private function buildZip($quotes)

protected function approve(array $ids, $process = false)
{
$quotes = Quote::whereIn('id', $ids)
$quotes = Quote::query()
->whereIn('id', $ids)
->where('client_id', auth()->guard('contact')->user()->client->id)
->where('company_id', auth()->guard('contact')->user()->client->company_id)
->whereIn('status_id', [Quote::STATUS_DRAFT, Quote::STATUS_SENT])
Expand All @@ -195,10 +198,10 @@ protected function approve(array $ids, $process = false)
}
}

if (count($ids) == 1) {
if ($quotes->count() == 1) {
//forward client to the invoice if it exists
if ($quote->invoice()->exists()) {
return redirect()->route('client.invoice.show', $quote->invoice->hashed_id);
if ($quotes->first()->invoice()->exists()) {
return redirect()->route('client.invoice.show', $quotes->first()->invoice->hashed_id);
}

return redirect()->route('client.quote.show', $quotes->first()->hashed_id);
Expand Down
12 changes: 5 additions & 7 deletions app/Http/Controllers/CreditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ public function index(CreditFilters $filters)
*/
public function create(CreateCreditRequest $request)
{
/** @var \App\Models\User $user**/
/** @var \App\Models\User $user **/
$user = auth()->user();

$credit = CreditFactory::create($user->company()->id, auth()->user()->id);
$credit = CreditFactory::create($user->company()->id, $user->id);

return $this->itemResponse($credit);
}
Expand Down Expand Up @@ -197,11 +197,9 @@ public function create(CreateCreditRequest $request)
public function store(StoreCreditRequest $request)
{

/** @var \App\Models\User $user**/
/** @var \App\Models\User $user **/
$user = auth()->user();

// $client = Client::find($request->input('client_id'));

$credit = $this->credit_repository->save($request->all(), CreditFactory::create($user->company()->id, $user->id));

$credit = $credit->service()
Expand Down Expand Up @@ -506,7 +504,7 @@ public function destroy(DestroyCreditRequest $request, Credit $credit)
public function bulk(BulkCreditRequest $request)
{

/** @var \App\Models\User $user**/
/** @var \App\Models\User $user **/
$user = auth()->user();

$action = $request->input('action');
Expand Down Expand Up @@ -725,7 +723,7 @@ public function downloadPdf($invitation_key)
* Update the specified resource in storage.
*
* @param UploadCreditRequest $request
* @param Credit $client
* @param Credit $credit
* @return Response
*
*
Expand Down

0 comments on commit 44b01b9

Please sign in to comment.