mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 00:04:35 -04:00
Working on fees and limits
This commit is contained in:
parent
89d15f1e2a
commit
83fc30f7e7
@ -452,11 +452,17 @@ class Client extends BaseModel implements HasLocalePreference
|
|||||||
}
|
}
|
||||||
|
|
||||||
$gateways->filter(function ($method) use ($amount) {
|
$gateways->filter(function ($method) use ($amount) {
|
||||||
if ($method->min_limit !== null && $amount < $method->min_limit) {
|
|
||||||
|
$fees_and_limits = $method->fees_and_limits;
|
||||||
|
|
||||||
|
if(!$fees_and_limits)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if ((property_exists($fees_and_limits, 'min_limit')) && $fees_and_limits->min_limit !== null && $amount < $fees_and_limits->min_limit) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($method->max_limit !== null && $amount > $method->min_limit) {
|
if ((property_exists($fees_and_limits, 'max_limit')) && $fees_and_limits->max_limit !== null && $amount > $fees_and_limits->min_limit) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -268,7 +268,9 @@ class Invoice extends BaseModel
|
|||||||
|
|
||||||
public function isPayable(): bool
|
public function isPayable(): bool
|
||||||
{
|
{
|
||||||
if ($this->status_id == Invoice::STATUS_SENT && $this->is_deleted == false) {
|
if($this->status_id == Invoice::STATUS_DRAFT && $this->is_deleted == false){
|
||||||
|
return true;
|
||||||
|
}else if ($this->status_id == Invoice::STATUS_SENT && $this->is_deleted == false) {
|
||||||
return true;
|
return true;
|
||||||
} elseif ($this->status_id == Invoice::STATUS_PARTIAL && $this->is_deleted == false) {
|
} elseif ($this->status_id == Invoice::STATUS_PARTIAL && $this->is_deleted == false) {
|
||||||
return true;
|
return true;
|
||||||
|
61
app/Services/Invoice/AutoBillInvoice.php
Normal file
61
app/Services/Invoice/AutoBillInvoice.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?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\Services\Invoice;
|
||||||
|
|
||||||
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
|
use App\Factory\PaymentFactory;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Payment;
|
||||||
|
use App\Services\AbstractService;
|
||||||
|
use App\Services\Client\ClientService;
|
||||||
|
use App\Services\Payment\PaymentService;
|
||||||
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
|
|
||||||
|
class AutoBillInvoice extends AbstractService
|
||||||
|
{
|
||||||
|
|
||||||
|
private $invoice;
|
||||||
|
|
||||||
|
private $client;
|
||||||
|
|
||||||
|
public function __construct(Invoice $invoice)
|
||||||
|
{
|
||||||
|
$this->invoice = $invoice;
|
||||||
|
|
||||||
|
$this->client = $invoice->client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
|
||||||
|
if(!$invoice->isPayable())
|
||||||
|
return $invoice;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getGateway($amount)
|
||||||
|
{
|
||||||
|
$gateway_tokens = $this->client->gateway_tokens->orderBy('is_default', 'DESC');
|
||||||
|
|
||||||
|
$gateways->filter(function ($method) use ($amount) {
|
||||||
|
if ($method->min_limit !== null && $amount < $method->min_limit) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($method->max_limit !== null && $amount > $method->min_limit) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,7 @@ use App\Models\Payment;
|
|||||||
use App\Services\Client\ClientService;
|
use App\Services\Client\ClientService;
|
||||||
use App\Services\Invoice\ApplyNumber;
|
use App\Services\Invoice\ApplyNumber;
|
||||||
use App\Services\Invoice\ApplyPayment;
|
use App\Services\Invoice\ApplyPayment;
|
||||||
|
use App\Services\Invoice\AutoBillInvoice;
|
||||||
use App\Services\Invoice\CreateInvitations;
|
use App\Services\Invoice\CreateInvitations;
|
||||||
use App\Services\Invoice\GetInvoicePdf;
|
use App\Services\Invoice\GetInvoicePdf;
|
||||||
use App\Services\Invoice\HandleCancellation;
|
use App\Services\Invoice\HandleCancellation;
|
||||||
@ -103,7 +104,6 @@ class InvoiceService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getInvoicePdf($contact = null)
|
public function getInvoicePdf($contact = null)
|
||||||
{
|
{
|
||||||
return (new GetInvoicePdf($this->invoice, $contact))->run();
|
return (new GetInvoicePdf($this->invoice, $contact))->run();
|
||||||
@ -144,6 +144,13 @@ class InvoiceService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function autoBill()
|
||||||
|
{
|
||||||
|
$this->invoice = (new AutoBillInvoice($this->invoice))->run();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function markViewed()
|
public function markViewed()
|
||||||
{
|
{
|
||||||
$this->invoice->last_viewed = Carbon::now()->format('Y-m-d H:i');
|
$this->invoice->last_viewed = Carbon::now()->format('Y-m-d H:i');
|
||||||
|
@ -42,20 +42,17 @@ class TriggeredActions extends AbstractService
|
|||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
//the request may have buried in it additional actions we should automatically perform on the invoice
|
|
||||||
|
|
||||||
if($this->request->has('send_email')) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this->request->has('auto_bill')) {
|
if($this->request->has('auto_bill')) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->request->has('paid') && (bool)$this->request->input('paid') !== false) {
|
if($this->request->has('paid') && (bool)$this->request->input('paid') !== false) {
|
||||||
|
|
||||||
$this->invoice->service()->markPaid()->save();
|
$this->invoice->service()->markPaid()->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->request->has('send_email') && (bool)$this->request->input('send_email') !== false) {
|
||||||
|
$this->sendEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->invoice;
|
return $this->invoice;
|
||||||
|
@ -103,15 +103,16 @@ trait CompanyGatewayFeesAndLimitsSaver
|
|||||||
$new_arr = [];
|
$new_arr = [];
|
||||||
|
|
||||||
foreach ($fees_and_limits as $key => $value) {
|
foreach ($fees_and_limits as $key => $value) {
|
||||||
$fal = new FeesAndLimits;
|
$fal = new FeesAndLimits;
|
||||||
|
// $fal->{$key} = $value;
|
||||||
|
|
||||||
$fal->{$key} = $value;
|
foreach ($value as $k => $v) {
|
||||||
// foreach ($value as $k => $v) {
|
|
||||||
// $fal->{$k} = $v;
|
|
||||||
// $fal->{$k} = BaseSettings::castAttribute(FeesAndLimits::$casts[$k], $v);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $new_arr[$key] = (array)$fal;
|
$fal->{$k} = $v;
|
||||||
|
$fal->{$k} = BaseSettings::castAttribute(FeesAndLimits::$casts[$k], $v);
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_arr[$key] = (array)$fal;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $new_arr;
|
return $new_arr;
|
||||||
|
@ -22,14 +22,17 @@ class FeesAndLimitsTest extends TestCase
|
|||||||
$data['max_limit'] = 65317;
|
$data['max_limit'] = 65317;
|
||||||
$data['fee_amount'] = 0.00;
|
$data['fee_amount'] = 0.00;
|
||||||
$data['fee_percent'] = 0.000;
|
$data['fee_percent'] = 0.000;
|
||||||
$data['tax_name1'] = '' ;
|
$data['fee_tax_name1'] = '';
|
||||||
$data['tax_rate1'] = '';
|
$data['fee_tax_rate1'] = '';
|
||||||
$data['tax_name2'] = '';
|
$data['fee_tax_name2'] = '';
|
||||||
$data['tax_rate2'] = '';
|
$data['fee_tax_rate2'] = '';
|
||||||
$data['tax_name3'] = '';
|
$data['fee_tax_name3'] = '';
|
||||||
$data['tax_rate3'] = 0;
|
$data['fee_tax_rate3'] = 0;
|
||||||
|
|
||||||
$transformed = $this->cleanFeesAndLimits($data);
|
$fees_and_limits_array = [];
|
||||||
|
$fees_and_limits_array[] = $data;
|
||||||
|
|
||||||
|
$transformed = $this->cleanFeesAndLimits($fees_and_limits_array);
|
||||||
|
|
||||||
$this->assertTrue(is_array($transformed));
|
$this->assertTrue(is_array($transformed));
|
||||||
}
|
}
|
||||||
@ -40,15 +43,16 @@ class FeesAndLimitsTest extends TestCase
|
|||||||
$new_arr = [];
|
$new_arr = [];
|
||||||
|
|
||||||
foreach ($fees_and_limits as $key => $value) {
|
foreach ($fees_and_limits as $key => $value) {
|
||||||
$fal = new FeesAndLimits;
|
$fal = new FeesAndLimits;
|
||||||
|
// $fal->{$key} = $value;
|
||||||
|
|
||||||
$fal->{$key} = $value;
|
foreach ($value as $k => $v) {
|
||||||
// foreach ($value as $k => $v) {
|
|
||||||
// $fal->{$k} = $v;
|
|
||||||
// $fal->{$k} = BaseSettings::castAttribute(FeesAndLimits::$casts[$k], $v);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $new_arr[$key] = (array)$fal;
|
$fal->{$k} = $v;
|
||||||
|
$fal->{$k} = BaseSettings::castAttribute(FeesAndLimits::$casts[$k], $v);
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_arr[$key] = (array)$fal;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $new_arr;
|
return $new_arr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user