Functional tests of spanish environment
This commit is contained in:
parent
555eb80018
commit
37c74ee18c
|
|
@ -14,6 +14,7 @@ namespace App\Http\Requests\Invoice;
|
|||
use App\Http\Requests\Request;
|
||||
use App\Exceptions\DuplicatePaymentException;
|
||||
use App\Http\ValidationRules\Invoice\RestoreDisabledRule;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class BulkInvoiceRequest extends Request
|
||||
{
|
||||
|
|
@ -24,9 +25,12 @@ class BulkInvoiceRequest extends Request
|
|||
|
||||
public function rules()
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return [
|
||||
'action' => ['required', 'string', new RestoreDisabledRule()],
|
||||
'ids' => 'required|array',
|
||||
'action' => ['required', 'bail','string', new RestoreDisabledRule()],
|
||||
'ids' => ['required', 'bail', 'array'],
|
||||
'email_type' => 'sometimes|in:reminder1,reminder2,reminder3,reminder_endless,custom1,custom2,custom3,invoice,quote,credit,payment,payment_partial,statement,purchase_order',
|
||||
'template' => 'sometimes|string',
|
||||
'template_id' => 'sometimes|string',
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@
|
|||
namespace App\Http\ValidationRules\Invoice;
|
||||
|
||||
use Closure;
|
||||
use App\Models\Invoice;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
/**
|
||||
|
|
@ -20,19 +22,21 @@ use Illuminate\Contracts\Validation\ValidationRule;
|
|||
*/
|
||||
class RestoreDisabledRule implements ValidationRule
|
||||
{
|
||||
use MakesHash;
|
||||
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
|
||||
|
||||
if (empty($value) || $value != 'restore') {
|
||||
return;
|
||||
}
|
||||
|
||||
$user = auth()->user();
|
||||
|
||||
$company = $user->company();
|
||||
|
||||
/** For verifactu, we do not allow restores */
|
||||
if($company->settings->e_invoice_type == 'verifactu') {
|
||||
/** For verifactu, we do not allow restores of deleted invoices */
|
||||
if($company->verifactuEnabled() && Invoice::withTrashed()->whereIn('id', $this->transformKeys(request()->ids))->where('company_id', $company->id)->where('is_deleted', true)->exists()) {
|
||||
$fail(ctrans('texts.restore_disabled_verifactu'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1030,4 +1030,18 @@ class Company extends BaseModel
|
|||
{
|
||||
return !$this->account->is_flagged && $this->account->e_invoice_quota > 0 && isset($this->legal_entity_id) && isset($this->tax_data->acts_as_sender) && $this->tax_data->acts_as_sender;
|
||||
}
|
||||
|
||||
/**
|
||||
* verifactuEnabled
|
||||
*
|
||||
* Returns a flag if the current company is using verifactu as the e-invoice provider
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function verifactuEnabled(): bool
|
||||
{
|
||||
return once(function () {
|
||||
return $this->getSetting('e_invoice_type') == 'verifactu';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ class HandleCancellation extends AbstractService
|
|||
{
|
||||
use GeneratesCounter;
|
||||
|
||||
public function __construct(private Invoice $invoice)
|
||||
public function __construct(private Invoice $invoice, private ?string $reason = null)
|
||||
{
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
|
||||
public function run()
|
||||
|
|
|
|||
|
|
@ -233,11 +233,11 @@ class InvoiceService
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function handleCancellation()
|
||||
public function handleCancellation(?string $reason = null)
|
||||
{
|
||||
$this->removeUnpaidGatewayFees();
|
||||
|
||||
$this->invoice = (new HandleCancellation($this->invoice))->run();
|
||||
$this->invoice = (new HandleCancellation($this->invoice, $reason))->run();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue