1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Fixes for invoice status with partial payment (#3472)

* Fixes for UserPolicy

* Improve notifications

* Company quantities

* Fixes for invoice status with partial payments
This commit is contained in:
David Bomba 2020-03-11 09:20:09 +11:00 committed by GitHub
parent 1017a22bca
commit 70a560c474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 61 additions and 16 deletions

View File

@ -45,7 +45,7 @@ class InvitationController extends Controller
auth()->guard('contact')->login($invitation->contact, false);
}
if(!request()->has('is_admin')){
if(!request()->has('silent')){
$invitation->markViewed();

View File

@ -13,6 +13,7 @@ namespace App\Http\Requests\Company;
use App\DataMapper\CompanySettings;
use App\Http\Requests\Request;
use App\Http\ValidationRules\Company\ValidCompanyQuantity;
use App\Http\ValidationRules\ValidSettingsRule;
use App\Models\ClientContact;
use App\Models\Company;
@ -36,7 +37,7 @@ class StoreCompanyRequest extends Request
{
$rules = [];
//$rules['name'] = 'required';
$rules['name'] = new ValidCompanyQuantity();
$rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000'; // max 10000kb
$rules['settings'] = new ValidSettingsRule();

View File

@ -0,0 +1,44 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\ValidationRules\Company;
use Illuminate\Contracts\Validation\Rule;
/**
* Class ValidCompanyQuantity
* @package App\Http\ValidationRules\Company
*/
class ValidCompanyQuantity implements Rule
{
/**
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return auth()->user()->company()->account->companies->count() <= 10;
}
/**
* @return string
*/
public function message()
{
return "Limit of 10 companies per account.";
}
}

View File

@ -49,7 +49,7 @@ class InvitationViewedListener implements ShouldQueue
/*** Check for Mail notifications***/
$all_user_notifications = '';
if($event->entity->user_id == $company_user->user_id || $event->entity->assigned_user_id == $company_user->user_id)
if($invitation->{$entity_name}->user_id == $company_user->user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id)
$all_user_notifications = "all_user_notifications";
$possible_permissions = [$entity_viewed, "all_notifications", $all_user_notifications];

View File

@ -43,7 +43,7 @@ class EntityViewedNotification extends Notification implements ShouldQueue
$this->settings = $this->entity->client->getMergedSettings();
$this->is_system = $is_system;
$this->invitation = $invitation;
$this->method = null;
}
/**
@ -55,7 +55,7 @@ class EntityViewedNotification extends Notification implements ShouldQueue
public function via($notifiable)
{
return $this->method;
return $this->method ?: [];
}
@ -138,7 +138,7 @@ class EntityViewedNotification extends Notification implements ShouldQueue
'client' => $this->contact->present()->name(),
$this->entity_name => $this->entity->number,
]),
'url' => config('ninja.site_url') . "/{$this->entity_name}s/" . $this->entity->hashed_id,
'url' => config('ninja.site_url') . "/client/{$this->entity_name}/" . $this->invitation->key . "?silent=true",
'button' => ctrans("texts.view_{$this->entity_name}"),
'signature' => $this->settings->email_signature,
'logo' => $this->company->present()->logo(),

View File

@ -41,7 +41,7 @@ class UserPolicy extends EntityPolicy
*/
public function edit(User $user, $user_entity) : bool
{
$company_user = CompanyUser::whereUserId($user_entity->id)->company()->first();
$company_user = CompanyUser::whereUserId($user->id)->company()->first();
return ($user->isAdmin() && $company_user);
}

View File

@ -60,7 +60,7 @@ class ApplyPayment extends AbstractService
} elseif ($this->payment_amount == $this->invoice->balance) { //total invoice paid.
$this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PAID)->updateBalance($this->payment_amount*-1);
} elseif($this->payment_amount < $this->invoice->balance) { //partial invoice payment made
$this->invoice->service()->clearPartial()->updateBalance($this->payment_amount*-1);
$this->invoice->service()->clearPartial()->setStatus(Invoice::STATUS_PARTIAL)->updateBalance($this->payment_amount*-1);
}
return $this->invoice;

View File

@ -23,15 +23,15 @@ class NotificationService extends AbstractService
const ALL_USER = 'all_user_notifications';
const PAYMENT_SUCCESS = 'payment_success';
const PAYMENT_SUCCESS = 'payment_success'; //@todo
const PAYMENT_FAILURE = 'payment_failure';
const PAYMENT_FAILURE = 'payment_failure'; //@todo
const INVOICE_SENT = 'invoice_sent';
const INVOICE_SENT = 'invoice_sent'; //@todo
const QUOTE_SENT = 'quote_sent';
const QUOTE_SENT = 'quote_sent'; //@todo
const CREDIT_SENT = 'credit_sent';
const CREDIT_SENT = 'credit_sent'; //@todo
const QUOTE_VIEWED = 'quote_viewed';
@ -39,7 +39,7 @@ class NotificationService extends AbstractService
const CREDIT_VIEWED = 'credit_viewed';
const QUOTE_APPROVED = 'quote_approved';
const QUOTE_APPROVED = 'quote_approved'; //@todo
public $company;

View File

@ -71,6 +71,6 @@ trait Inviteable
public function getAdminLink() :string
{
return $this->getLink(). '?is_admin=true';
return $this->getLink(). '?silent=true';
}
}

View File

@ -26,7 +26,7 @@ class PaymentTypesSeeder extends Seeder
Eloquent::unguard();
$paymentTypes = [
['name' => 'Apply Credit'],
// ['name' => 'Apply Credit'],
['name' => 'Bank Transfer', 'gateway_type_id' => self::GATEWAY_TYPE_BANK_TRANSFER],
['name' => 'Cash'],
['name' => 'Debit', 'gateway_type_id' => self::GATEWAY_TYPE_CREDIT_CARD],