Skip to content

Commit

Permalink
Merge pull request #8712 from turbo124/v5-stable
Browse files Browse the repository at this point in the history
v5.6.30
  • Loading branch information
turbo124 committed Aug 11, 2023
2 parents 5bf8cbe + d0ec76e commit a66e668
Show file tree
Hide file tree
Showing 49 changed files with 434 additions and 233 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.6.29
5.6.30
4 changes: 2 additions & 2 deletions app/DataMapper/CompanySettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -812,14 +812,14 @@ public static function defaults(): stdClass
* need to provide a fallback catch on old settings objects which will
* set new properties to the object prior to being returned.
*
* @param $settings
* @param \stdClass $settings
*
* @return stdClass
*/
public static function setProperties($settings): stdClass
{
$company_settings = (object) get_class_vars(self::class);

foreach ($company_settings as $key => $value) {
if (! property_exists($settings, $key)) {
$settings->{$key} = self::castAttribute($key, $company_settings->{$key});
Expand Down
5 changes: 4 additions & 1 deletion app/Filters/PaymentFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace App\Filters;

use App\Models\Payment;
use Illuminate\Contracts\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Builder;

/**
Expand Down Expand Up @@ -117,14 +118,16 @@ public function client_status(string $value = ''): Builder

/**
* Returns a list of payments that can be matched to bank transactions
* @param ?string $value
* @return Builder
*/
public function match_transactions($value = 'true'): Builder
{

if ($value == 'true') {
return $this->builder
->where('is_deleted', 0)
->where(function ($query) {
->where(function (Builder $query) {
$query->whereNull('transaction_id')
->orWhere("transaction_id", "")
->company();
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/MigrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public function startMigration(Request $request)
$user = auth()->user();

$company_count = $user->account->companies()->count();
$fresh_company = false;

// Look for possible existing company (based on company keys).
$existing_company = Company::whereRaw('BINARY `company_key` = ?', [$company['company_key']])->first();
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/OneTimeTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function create(OneTimeTokenRequest $request)
'user_id' => $user->id,
'company_key'=> $user->company()->company_key,
'context' => $request->input('context'),
'is_react' => $request->has('react') && $request->query('react') == 'true' ? true : false,
];

Cache::put($hash, $data, 3600);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/PreviewPurchaseOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public function live(PreviewPurchaseOrderRequest $request)
DB::connection(config('database.default'))->beginTransaction();

if ($request->has('entity_id')) {
/** @var \App\Models\PurchaseOrder|\Illuminate\Database\Eloquent\Builder $entity_obj **/
$entity_obj = $class::on(config('database.default'))
/** @var \App\Models\PurchaseOrder|\Illuminate\Contracts\Database\Eloquent\Builder $entity_obj **/
$entity_obj = \App\Models\PurchaseOrder::on(config('database.default'))
->with('vendor.company')
->where('id', $this->decodePrimaryKey($request->input('entity_id')))
->where('company_id', $company->id)
Expand Down
58 changes: 21 additions & 37 deletions app/Http/Controllers/StripeConnectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,13 @@ class StripeConnectController extends BaseController
*/
public function initialize(InitializeStripeConnectRequest $request, string $token)
{
// Should we check if company has set country in the ap? Otherwise this will fail.

if (! is_array($request->getTokenContent())) {
abort(400, 'Invalid token');
}

MultiDB::findAndSetDbByCompanyKey($request->getTokenContent()['company_key']);

$company = Company::where('company_key', $request->getTokenContent()['company_key'])->first();

$company_gateway = CompanyGateway::query()
->where('gateway_key', 'd14dd26a47cecc30fdd65700bfb67b34')
->where('company_id', $request->getCompany()->id)
Expand Down Expand Up @@ -71,6 +68,20 @@ public function completed(InitializeStripeConnectRequest $request)
}

try {
/** @class \stdClass $response
* @property string $scope
* @property string $stripe_user_id
* @property string $stripe_publishable_key
* @property string $refresh_token
* @property string $livemode
* @property string $access_token
* @property string $token_type
* @property string $stripe_user
* @property string $stripe_account
* @property string $error
*/

/** @var \stdClass $response */
$response = \Stripe\OAuth::token([
'grant_type' => 'authorization_code',
'code' => $request->input('code'),
Expand All @@ -81,8 +92,7 @@ public function completed(InitializeStripeConnectRequest $request)

MultiDB::findAndSetDbByCompanyKey($request->getTokenContent()['company_key']);

/** @var \App\Models\Company $company */
$company = Company::where('company_key', $request->getTokenContent()['company_key'])->first();
$company = Company::query()->where('company_key', $request->getTokenContent()['company_key'])->first();

$company_gateway = CompanyGateway::query()
->where('gateway_key', 'd14dd26a47cecc30fdd65700bfb67b34')
Expand All @@ -97,7 +107,6 @@ public function completed(InitializeStripeConnectRequest $request)
$company_gateway->fees_and_limits = $fees_and_limits;
$company_gateway->setConfig([]);
$company_gateway->token_billing = 'always';
// $company_gateway->save();
}

$payload = [
Expand All @@ -116,39 +125,14 @@ public function completed(InitializeStripeConnectRequest $request)
$company_gateway->save();

// StripeWebhook::dispatch($company->company_key, $company_gateway->id);

//response here
return view('auth.connect.completed');
}

private function checkAccountAlreadyLinkToEmail($company_gateway, $email)
{
$client = Client::first() ? Client::first() : new Client;

//Pull the list of Stripe Accounts and see if we match
$accounts = $company_gateway->driver($client)->getAllConnectedAccounts()->data;

foreach ($accounts as $account) {
if ($account['email'] == $email) {
return $account['id'];
}
if(isset($request->getTokenContent()['is_react']) && $request->getTokenContent()['is_react']) {
$redirect_uri = 'https://app.invoicing.co/#/settings/online_payments';
} else {
$redirect_uri = 'https://invoicing.co/stripe/completed';
}

return false;
//response here
return view('auth.connect.completed', ['url' => $redirect_uri]);
}

/*********************************
* Stripe OAuth
*/

// public function initialize(InitializeStripeConnectRequest $request, string $token)
// {

// $stripe_key = config('ninja.ninja_stripe_key');

// $endpoint = "https://connect.stripe.com/oauth/authorize?response_type=code&client_id={$stripe_key}&scope=read_write";

// return redirect($endpoint);

// }
}
4 changes: 4 additions & 0 deletions app/Http/Controllers/TwilioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ public function generate2faResetCode(Generate2faRequest $request)
return response()->json(['message' => 'Unable to retrieve user.'], 400);
}

if (!$user->phone || $user->phone == '') {
return response()->json(['message' => 'User found, but no valid phone number on file, please contact support.'], 400);
}

$sid = config('ninja.twilio_account_sid');
$token = config('ninja.twilio_auth_token');

Expand Down
5 changes: 0 additions & 5 deletions app/Http/Middleware/VendorContactKeyLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@

use Auth;
use Closure;
use App\Utils\Ninja;
use App\Models\Vendor;
use App\Libraries\MultiDB;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use App\Models\VendorContact;
use Illuminate\Support\Facades\Cache;
use App\Events\Vednor\VendorContactLoggedIn;

class VendorContactKeyLogin
{
Expand Down Expand Up @@ -59,8 +57,6 @@ public function handle($request, Closure $next)

auth()->guard('vendor')->loginUsingId($vendor_contact->id, true);

event(new VendorContactLoggedIn($vendor_contact, $vendor_contact->company, Ninja::eventVars()));

if ($request->query('redirect') && ! empty($request->query('redirect'))) {
return redirect()->to($request->query('redirect'));
}
Expand All @@ -76,7 +72,6 @@ public function handle($request, Closure $next)
$vendor_contact->save();

auth()->guard('vendor')->loginUsingId($vendor_contact->id, true);
event(new VendorContactLoggedIn($vendor_contact, $vendor_contact->company, Ninja::eventVars()));
if ($request->query('next')) {
return redirect()->to($request->query('next'));
}
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Requests/Report/GenericReportRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class GenericReportRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
/** @var \App\Models\User $user */
$user = auth()->user();

return $user->isAdmin() || $user->hasPermission('view_reports');

}

public function rules()
Expand Down
6 changes: 5 additions & 1 deletion app/Http/Requests/Yodlee/YodleeAuthRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
use App\Models\User;
use Illuminate\Support\Facades\Cache;

/**
* @class \App\Http\Requests\Yodlee\YodleeAuthRequest
* @property string $token
* @property string $state
*/
class YodleeAuthRequest extends Request
{
/**
Expand All @@ -39,7 +44,6 @@ public function rules()
return [];
}

/** @var $token */
public function getTokenContent()
{
if ($this->state) {
Expand Down
3 changes: 0 additions & 3 deletions app/Jobs/Document/ZipDocuments.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ public function __construct($document_ids, Company $company, User $user)
* Execute the job.
*
* @return void
* @throws \ZipStream\Exception\FileNotFoundException
* @throws \ZipStream\Exception\FileNotReadableException
* @throws \ZipStream\Exception\OverflowException
*/
public function handle()
{
Expand Down
3 changes: 0 additions & 3 deletions app/Jobs/PurchaseOrder/ZipPurchaseOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public function __construct($purchase_orders, Company $company, User $user)
* Execute the job.
*
* @return void
* @throws \ZipStream\Exception\FileNotFoundException
* @throws \ZipStream\Exception\FileNotReadableException
* @throws \ZipStream\Exception\OverflowException
*/
public function handle()
{
Expand Down
3 changes: 0 additions & 3 deletions app/Jobs/Quote/ZipQuotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public function __construct($quotes, Company $company, User $user)
* Execute the job.
*
* @return void
* @throws \ZipStream\Exception\FileNotFoundException
* @throws \ZipStream\Exception\FileNotReadableException
* @throws \ZipStream\Exception\OverflowException
*/
public function handle()
{
Expand Down
10 changes: 8 additions & 2 deletions app/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
* @property int $assigned_user_id
* @method BaseModel service()
* @property \App\Models\Company $company
* @property \App\Models\Vendor $vendor
* @method static BaseModel find($value)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel<static> company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel|Illuminate\Database\Eloquent\Relations\BelongsTo|\Awobaz\Compoships\Database\Eloquent\Relations\BelongsTo|\App\Models\Company company()
Expand All @@ -63,11 +62,15 @@
* @method int companyId()
* @method createInvitations()
* @method Builder scopeCompany(Builder $builder)
* @method static \Illuminate\Database\Eloquent\Builder<static> company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder withTrashed(bool $withTrashed = true)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel|\Illuminate\Database\Query\Builder withoutTrashed()
* @mixin \Eloquent
* @mixin \Illuminate\Database\Eloquent\Builder
*
* @property \Illuminate\Support\Collection $tax_map
* @property array $total_tax_map
*/
class BaseModel extends Model
{
Expand Down Expand Up @@ -119,7 +122,10 @@ public function __call($method, $params)
return parent::__call($method, $params);
}


/**
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeCompany($query): \Illuminate\Database\Eloquent\Builder
{
/** @var \App\Models\User $user */
Expand Down
10 changes: 8 additions & 2 deletions app/Models/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ public function ledger(): \Illuminate\Database\Eloquent\Relations\HasMany
return $this->hasMany(CompanyLedger::class)->orderBy('id', 'desc');
}

public function company_ledger()
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany<CompanyLedger>
*/
public function company_ledger(): \Illuminate\Database\Eloquent\Relations\MorphMany
{
return $this->morphMany(CompanyLedger::class, 'company_ledgerable');
}
Expand Down Expand Up @@ -516,7 +519,10 @@ public function getSettingEntity($setting)
throw new \Exception('Could not find a settings object', 1);
}

public function documents() :MorphMany
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany<Document>
*/
public function documents() :\Illuminate\Database\Eloquent\Relations\MorphMany
{
return $this->morphMany(Document::class, 'documentable');
}
Expand Down
3 changes: 3 additions & 0 deletions app/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ public function shouldCalculateTax()
return $this->calculate_taxes && in_array($this->getSetting('country_id'), $this->tax_coverage_countries);
}

/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany<Document>
*/
public function documents()
{
return $this->morphMany(Document::class, 'documentable');
Expand Down

0 comments on commit a66e668

Please sign in to comment.