Skip to content

Commit

Permalink
Merge pull request invoiceninja#10169 from turbo124/v5-develop
Browse files Browse the repository at this point in the history
Support ids on sidebars
  • Loading branch information
turbo124 authored Oct 21, 2024
2 parents d67d7f7 + 2723447 commit 29a372b
Show file tree
Hide file tree
Showing 14 changed files with 311 additions and 44 deletions.
7 changes: 7 additions & 0 deletions app/Http/Controllers/ClientGatewayTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,11 @@ public function destroy(DestroyClientGatewayTokenRequest $request, ClientGateway

return $this->itemResponse($client_gateway_token->fresh());
}

public function setAsDefault(UpdateClientGatewayTokenRequest $request, ClientGatewayToken $client_gateway_token)
{
$client_gateway_token = $this->client_gateway_token_repo->setDefault($client_gateway_token);

return $this->itemResponse($client_gateway_token->fresh());
}
}
56 changes: 56 additions & 0 deletions app/Http/Controllers/EInvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,21 @@
namespace App\Http\Controllers;

use App\Http\Requests\EInvoice\ValidateEInvoiceRequest;
use App\Http\Requests\EInvoice\UpdateEInvoiceConfiguration;
use App\Services\EDocument\Standards\Validation\Peppol\EntityLevel;
use InvoiceNinja\EInvoice\Models\Peppol\BranchType\FinancialInstitutionBranch;
use InvoiceNinja\EInvoice\Models\Peppol\FinancialAccountType\PayeeFinancialAccount;
use InvoiceNinja\EInvoice\Models\Peppol\PaymentMeans;
use InvoiceNinja\EInvoice\Models\Peppol\CardAccountType\CardAccount;
use InvoiceNinja\EInvoice\Models\Peppol\IdentifierType\ID;
use InvoiceNinja\EInvoice\Models\Peppol\CodeType\CardTypeCode;
use InvoiceNinja\EInvoice\Models\Peppol\CodeType\PaymentMeansCode;

class EInvoiceController extends BaseController
{
private array $einvoice_props = [
'payment_means',
];

public function validateEntity(ValidateEInvoiceRequest $request)
{
Expand All @@ -36,4 +47,49 @@ public function validateEntity(ValidateEInvoiceRequest $request)

}

public function configurations(UpdateEInvoiceConfiguration $request)
{

$einvoice = new \InvoiceNinja\EInvoice\Models\Peppol\Invoice();
$pm = new PaymentMeans();

$pmc = new PaymentMeansCode();
$pmc->value = $request->input('payment_means.code', null);

if($this->input('payment_means.code') == '48')
{
$ctc = new CardTypeCode();
$ctc->value = $request->input('payment_means.card_type', null);
$card_account = new CardAccount();
$card_account->HolderName = $request->input('payment_means.cardholder_name', '');
$card_account->CardTypeCode = $ctc;
$pm->CardAccount = $card_account;
}

if($this->input('payment_means.iban'))
{
$fib = new FinancialInstitutionBranch();
$bic_id = new ID();
$bic_id->value = $request->input('payment_means.bic', null);
$fib->ID = $bic_id;
$pfa = new PayeeFinancialAccount();
$iban_id = new ID();
$iban_id->value = $request->input('payment_means.iban', null);
$pfa->ID = $iban_id;
$pfa->Name = $request->input('payment_means.account_name', null);
$pfa->FinancialInstitutionBranch = $fib;

$pm->PayeeFinancialAccount = $pfa;
$pm->PaymentMeansCode = $pmc;
}

$pm->InstructionNote = $request->input('payment_means.information', '');

$einvoice->PaymentMeans[] = $pm;

$stub = new \stdClass();
$stub->Invoice = $einvoice;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private function sidebarMenu(): array
// $data[] = [ 'title' => ctrans('texts.dashboard'), 'url' => 'client.dashboard', 'icon' => 'activity'];

if (self::MODULE_PURCHASE_ORDERS & $enabled_modules) {
$data[] = ['title' => ctrans('texts.purchase_orders'), 'url' => 'vendor.purchase_orders.index', 'icon' => 'file-text'];
$data[] = ['title' => ctrans('texts.purchase_orders'), 'url' => 'vendor.purchase_orders.index', 'icon' => 'file-text', 'id' => 'purchase_orders'];
}

// $data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download'];
Expand Down
96 changes: 96 additions & 0 deletions app/Http/Requests/EInvoice/UpdateEInvoiceConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/

namespace App\Http\Requests\EInvoice;

use App\Utils\Ninja;
use App\Models\Client;
use App\Models\Company;
use App\Models\Invoice;
use App\Http\Requests\Request;
use App\Services\EDocument\Adapters\CII\PaymentMeans;
use Illuminate\Validation\Rule;

class UpdateEInvoiceConfiguration extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{

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

return $user->isAdmin();
}

public function rules()
{

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

return [
'entity' => 'required|bail|in:invoice,client,company',
'payment_means' => 'sometimes|bail|array',
'payment_means.code' => ['required_with:payment_means', 'bail', Rule::in(PaymentMeans::getPaymentMeansCodelist())],
'payment_means.bic' => ['bail',
Rule::requiredIf(function () {
return in_array($this->input('payment_means.code'), ['58', '59', '49', '42', '30']);
}),
],
'payment_means.iban' => ['bail', 'string', 'min:8', 'max:11',
Rule::requiredIf(function () {
return in_array($this->input('payment_means.code'), ['58', '59', '49', '42', '30']);
}),
],
'payment_means.account_name' => ['bail', 'string', 'min:15', 'max:34',
Rule::requiredIf(function () {
return in_array($this->input('payment_means.code'), ['58', '59', '49', '42', '30']);
}),
],
'payment_means.information' => ['bail', 'sometimes', 'string'],
'payment_means.card_type' => ['bail', 'string', 'min:4',
Rule::requiredIf(function () {
return in_array($this->input('payment_means.code'), ['48']);
}),
],
'payment_means.cardholder_name' => ['bail','string', 'min:4',
Rule::requiredIf(function () {
return in_array($this->input('payment_means.code'), ['48']);
}),
],
];
}

public function prepareForValidation()
{
$input = $this->all();

$this->replace($input);
}

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

return match($this->entity){
'company' => $user->company(),
'invoice' => Invoice::class,
'client' => Client::class,
default => $user->company(),
};
}
}
5 changes: 4 additions & 1 deletion app/Http/Requests/Expense/BulkExpenseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function rules()
'new_value' => ['required_if:action,bulk_update|string'],
];


}

public function prepareForValidation()
Expand All @@ -59,6 +58,10 @@ public function prepareForValidation()
$input['category_id'] = $this->transformKeys($input['category_id']);
}

if(isset($input['newValue'])){
$input['new_value'] = $input['newValue'];
}

$this->replace($input);
}
}
32 changes: 16 additions & 16 deletions app/Http/ViewComposers/PortalComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,44 +106,44 @@ private function sidebarMenu(): array
$data = [];

if ($this->settings->enable_client_portal_dashboard) {
$data[] = [ 'title' => ctrans('texts.dashboard'), 'url' => 'client.dashboard', 'icon' => 'activity'];
$data[] = [ 'title' => ctrans('texts.dashboard'), 'url' => 'client.dashboard', 'icon' => 'activity', 'id' => 'dashboard'];
}

if (self::MODULE_INVOICES & $enabled_modules) {
$data[] = ['title' => ctrans('texts.invoices'), 'url' => 'client.invoices.index', 'icon' => 'file-text'];
$data[] = ['title' => ctrans('texts.invoices'), 'url' => 'client.invoices.index', 'icon' => 'file-text', 'id' => 'invoices'];
}

if (self::MODULE_RECURRING_INVOICES & $enabled_modules) {
$data[] = ['title' => ctrans('texts.recurring_invoices'), 'url' => 'client.recurring_invoices.index', 'icon' => 'file'];
$data[] = ['title' => ctrans('texts.recurring_invoices'), 'url' => 'client.recurring_invoices.index', 'icon' => 'file', 'id' => 'recurring_invoices'];
}

$data[] = ['title' => ctrans('texts.payments'), 'url' => 'client.payments.index', 'icon' => 'credit-card'];
$data[] = ['title' => ctrans('texts.payments'), 'url' => 'client.payments.index', 'icon' => 'credit-card', 'id' => 'payments'];

if (self::MODULE_QUOTES & $enabled_modules) {
$data[] = ['title' => ctrans('texts.quotes'), 'url' => 'client.quotes.index', 'icon' => 'align-left'];
$data[] = ['title' => ctrans('texts.quotes'), 'url' => 'client.quotes.index', 'icon' => 'align-left', 'id' => 'quotes'];
}

if (self::MODULE_CREDITS & $enabled_modules) {
$data[] = ['title' => ctrans('texts.credits'), 'url' => 'client.credits.index', 'icon' => 'credit-card'];
$data[] = ['title' => ctrans('texts.credits'), 'url' => 'client.credits.index', 'icon' => 'credit-card', 'id' => 'credits'];
}

$data[] = ['title' => ctrans('texts.payment_methods'), 'url' => 'client.payment_methods.index', 'icon' => 'shield'];
$data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download'];
$data[] = ['title' => ctrans('texts.payment_methods'), 'url' => 'client.payment_methods.index', 'icon' => 'shield', 'id' => 'payment_methods'];
$data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download', 'id' => 'documents'];

if (auth()->guard('contact')->user()->client->getSetting('enable_client_portal_tasks')) {
$data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.tasks.index', 'icon' => 'clock'];
$data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.tasks.index', 'icon' => 'clock', 'id' => 'tasks'];
}

$data[] = ['title' => ctrans('texts.statement'), 'url' => 'client.statement', 'icon' => 'activity'];
$data[] = ['title' => ctrans('texts.statement'), 'url' => 'client.statement', 'icon' => 'activity', 'id' => 'statement'];

// if (Ninja::isHosted() && auth()->guard('contact')->user()->company->id == config('ninja.ninja_default_company_id')) {
$data[] = ['title' => ctrans('texts.plan'), 'url' => 'client.plan', 'icon' => 'credit-card'];
// } else {
$data[] = ['title' => ctrans('texts.subscriptions'), 'url' => 'client.subscriptions.index', 'icon' => 'calendar'];
// }
if (Ninja::isHosted() && auth()->guard('contact')->user() && auth()->guard('contact')->user()->company_id == config('ninja.ninja_default_company_id')) {
$data[] = ['title' => ctrans('texts.plan'), 'url' => 'client.plan', 'icon' => 'credit-card', 'id' => 'plan'];
} else {
$data[] = ['title' => ctrans('texts.subscriptions'), 'url' => 'client.subscriptions.index', 'icon' => 'calendar', 'id' => 'subsciptions'];
}

if (auth()->guard('contact')->user()->client->getSetting('client_initiated_payments')) {
$data[] = ['title' => ctrans('texts.pre_payment'), 'url' => 'client.pre_payments.index', 'icon' => 'dollar-sign'];
$data[] = ['title' => ctrans('texts.pre_payment'), 'url' => 'client.pre_payments.index', 'icon' => 'dollar-sign', 'id' => 'pre_payment'];
}

return $data;
Expand Down
13 changes: 13 additions & 0 deletions app/Repositories/ClientGatewayTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,17 @@ public function save(array $data, ClientGatewayToken $client_gateway_token): Cli

return $client_gateway_token->fresh();
}

public function setDefault(ClientGatewayToken $client_gateway_token): ClientGatewayToken
{
ClientGatewayToken::withTrashed()
->where('company_id', $client_gateway_token->company_id)
->where('client_id', $client_gateway_token->client_id)
->update(['is_default' => false]);

$client_gateway_token->is_default = true;
$client_gateway_token->save();

return $client_gateway_token->fresh();
}
}
43 changes: 21 additions & 22 deletions app/Services/EDocument/Adapters/CII/PaymentMeans.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class PaymentMeans implements PaymentMeansInterface
{

public array $payment_means_codelist = [
public static array $payment_means_codelist = [
'1' => 'Instrument not defined',
'2' => 'Automated clearing house credit',
'3' => 'Automated clearing house debit',
Expand Down Expand Up @@ -102,25 +102,25 @@ class PaymentMeans implements PaymentMeansInterface
'ZZZ' => 'Mutually defined',
];

public string $typecode = '1';
public string $code = '1';

public ?string $information = null;

public ?string $cardType = null;
public ?string $card_type = null;

public ?string $cardId = null;

public ?string $cardHolderName = null;
public ?string $cardholder_name = null;

public ?string $buyerIban = null;

public ?string $payeeIban = null;
public ?string $iban = null;

public ?string $payeeAccountName = null;
public ?string $account_name = null;

public ?string $payeePropId = null;

public ?string $payeeBic = null;
public ?string $bic = null;

public function __construct(mixed $existing_payment_means = null)
{
Expand All @@ -139,7 +139,7 @@ public function __construct(mixed $existing_payment_means = null)
// @param string $typecode __BT-81, From BASIC WL__ The expected or used means of payment, expressed as a code. The entries from the UNTDID 4461 code list must be used. A distinction should be made between SEPA and non-SEPA payments as well
// as between credit payments, direct debits, card payments and other means of payment
// In particular, the following codes can be used:
// * 10: cash -
// * // 10: cash -
// 20: check -
// 30: transfer -
// 42: Payment to bank account -
Expand All @@ -151,42 +151,37 @@ public function __construct(mixed $existing_payment_means = null)
// 97: Report
// *
// * @param string|null $information __BT-82, From EN 16931__ The expected or used means of payment expressed in text form, e.g. cash, bank transfer, direct debit, credit card, etc.
// * @param string|null $cardType __BT-, From __ The type of the card
// * @param string|null $card_type __BT-, From __ The type of the card
// * @param string|null $cardId __BT-84, From BASIC WL__ The primary account number (PAN) to which the card used for payment belongs. In accordance with card payment security standards, an invoice should never contain a full payment card master account number.
//The following specification of the PCI Security Standards Council currently applies: The first 6 and last 4 digits at most are to be displayed
// * @param string|null $cardHolderName __BT-, From __ Name of the payment card holder
// * @param string|null $cardholder_name __BT-, From __ Name of the payment card holder
// * @param string|null $buyerIban __BT-91, From BASIC WL__ Direct debit: ID of the account to be debited
// * @param string|null $payeeIban __BT-, From __ Transfer: A unique identifier for the financial account held with a payment service provider to which the payment should be made, e.g. Use an IBAN (in the case of a SEPA payment) for a national
// * @param string|null $iban __BT-, From __ Transfer: A unique identifier for the financial account held with a payment service provider to which the payment should be made, e.g. Use an IBAN (in the case of a SEPA payment) for a national
//ProprietaryID account number
// * @param string|null $payeeAccountName __BT-, From __ The name of the payment account held with a payment service provider to which the payment should be made. Information only required if different from the name of the payee / seller
// * @param string|null $payeePropId __BT-, From __ National account number (not for SEPA)
// * @param string|null $payeeBic __BT-, From __ Seller's banking institution, An identifier for the payment service provider with whom the payment account is managed, such as the BIC or a national bank code, if required. No identification scheme is to be used.
// * @param string|null $bic __BT-, From __ Seller's banking institution, An identifier for the payment service provider with whom the payment account is managed, such as the BIC or a national bank code, if required. No identification scheme is to be used.
// *
public function run()
{


// ->getTradeSettlementPaymentMeansType($typecode, $information);
// ->getTradeSettlementFinancialCardType($cardType, $cardId, $cardHolderName);


$TradeSettlementFinancialCardType = new \horstoeko\zugferd\entities\extended\ram\TradeSettlementFinancialCardType();
$TradeSettlementFinancialCardType->setCardholderName($this->cardHolderName)
$TradeSettlementFinancialCardType->setCardholderName($this->cardholder_name)
->setID(new \horstoeko\zugferd\entities\extended\udt\IDType($this->cardId));

$DebtorFinancialAccountType = new \horstoeko\zugferd\entities\extended\ram\DebtorFinancialAccountType();
$DebtorFinancialAccountType->setIBANID(new \horstoeko\zugferd\entities\extended\udt\IDType($this->buyerIban));

$CreditorFinancialAccountType = new \horstoeko\zugferd\entities\extended\ram\CreditorFinancialAccountType();
$CreditorFinancialAccountType->setAccountName($this->payeeAccountName)
$CreditorFinancialAccountType->setAccountName($this->account_name)
->setProprietaryID(new \horstoeko\zugferd\entities\extended\udt\IDType($this->payeePropId))
->setIBANID(new \horstoeko\zugferd\entities\extended\udt\IDType($this->payeeIban));
->setIBANID(new \horstoeko\zugferd\entities\extended\udt\IDType($this->iban));

$CreditorFinancialInstitutionType = new \horstoeko\zugferd\entities\extended\ram\CreditorFinancialInstitutionType();
$CreditorFinancialInstitutionType->setBICID(new \horstoeko\zugferd\entities\extended\udt\IDType($this->payeeBic));
$CreditorFinancialInstitutionType->setBICID(new \horstoeko\zugferd\entities\extended\udt\IDType($this->bic));

$TradeSettlementPaymentMeansType = new \horstoeko\zugferd\entities\extended\ram\TradeSettlementPaymentMeansType();
$TradeSettlementPaymentMeansType->setTypeCode($this->typecode)->setInformation($this->information);
$TradeSettlementPaymentMeansType->setTypeCode($this->code)->setInformation($this->information);
$TradeSettlementPaymentMeansType->setPayeePartyCreditorFinancialAccount($CreditorFinancialAccountType);
$TradeSettlementPaymentMeansType->setPayerPartyDebtorFinancialAccount($DebtorFinancialAccountType);
$TradeSettlementPaymentMeansType->setApplicableTradeSettlementFinancialCard($TradeSettlementFinancialCardType);
Expand All @@ -200,4 +195,8 @@ public function run()

}

public static function getPaymentMeansCodelist()
{
return array_keys(self::$payment_means_codelist);
}
}
Loading

0 comments on commit 29a372b

Please sign in to comment.