save mailbox at company

This commit is contained in:
paulwer 2023-12-14 13:16:14 +01:00
parent 8bd9f34d98
commit a6f9275144
5 changed files with 76 additions and 53 deletions

View File

@ -49,6 +49,11 @@ class CompanyFactory
$company->markdown_enabled = false; $company->markdown_enabled = false;
$company->tax_data = new TaxModel(); $company->tax_data = new TaxModel();
$company->first_month_of_year = 1; $company->first_month_of_year = 1;
// default mailbox
$company->expense_mailbox = config('ninja.inbound_expense.webhook.mailbox_template') != '' ?
str_replace('{{company_key}}', $company->company_key, config('ninja.inbound_expense.webhook.mailbox_template')) : null;
return $company; return $company;
} }
} }

View File

@ -86,14 +86,14 @@ class ExpenseMailboxJob implements ShouldQueue
private function getImapCredentials() private function getImapCredentials()
{ {
$servers = array_map('trim', explode(",", config('ninja.imap_inbound_expense.servers'))); $servers = array_map('trim', explode(",", config('ninja.inbound_expense.imap.servers')));
$ports = explode(",", config('ninja.imap_inbound_expense.servers')); $ports = explode(",", config('ninja.inbound_expense.imap.servers'));
$users = explode(",", config('ninja.imap_inbound_expense.servers')); $users = explode(",", config('ninja.inbound_expense.imap.servers'));
$passwords = explode(",", config('ninja.imap_inbound_expense.servers')); $passwords = explode(",", config('ninja.inbound_expense.imap.servers'));
$companies = explode(",", config('ninja.imap_inbound_expense.servers')); $companies = explode(",", config('ninja.inbound_expense.imap.servers'));
if (sizeOf($servers) != sizeOf($ports) || sizeOf($servers) != sizeOf($users) || sizeOf($servers) != sizeOf($passwords) || sizeOf($servers) != sizeOf($companies)) if (sizeOf($servers) != sizeOf($ports) || sizeOf($servers) != sizeOf($users) || sizeOf($servers) != sizeOf($passwords) || sizeOf($servers) != sizeOf($companies))
throw new \Exception('invalid configuration imap_inbound_expenses (wrong element-count)'); throw new \Exception('invalid configuration inbound_expense.imap (wrong element-count)');
foreach ($companies as $index => $companyId) { foreach ($companies as $index => $companyId) {
$this->imap_credentials[$companyId] = [ $this->imap_credentials[$companyId] = [

View File

@ -111,6 +111,8 @@ use Laracasts\Presenter\PresentableTrait;
* @property int $convert_expense_currency * @property int $convert_expense_currency
* @property int $notify_vendor_when_paid * @property int $notify_vendor_when_paid
* @property int $invoice_task_hours * @property int $invoice_task_hours
* @property boolean $expense_import
* @property string|null $expense_mailbox
* @property int $deleted_at * @property int $deleted_at
* @property-read \App\Models\Account $account * @property-read \App\Models\Account $account
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities * @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $activities
@ -352,6 +354,8 @@ class Company extends BaseModel
'calculate_taxes', 'calculate_taxes',
'tax_data', 'tax_data',
'e_invoice_certificate_passphrase', 'e_invoice_certificate_passphrase',
'expense_import',
'expense_mailbox', // TODO: @turbo124 custom validation: self-hosted => free change, hosted => not changeable, only changeable with env-mask
]; ];
protected $hidden = [ protected $hidden = [

View File

@ -228,11 +228,17 @@ return [
'secret' => env('PAYPAL_SECRET', null), 'secret' => env('PAYPAL_SECRET', null),
'client_id' => env('PAYPAL_CLIENT_ID', null), 'client_id' => env('PAYPAL_CLIENT_ID', null),
], ],
'imap_inbound_expense' => [ 'inbound_expense' => [
'servers' => env('IMAP_INBOUND_EXPENSE_SERVERS', ''), 'imap' => [
'ports' => env('IMAP_INBOUND_EXPENSE_PORTS', ''), 'servers' => env('INBOUND_EXPENSE_IMAP_SERVERS', ''),
'users' => env('IMAP_INBOUND_EXPENSE_USERS', ''), 'ports' => env('INBOUND_EXPENSE_IMAP_PORTS', ''),
'passwords' => env('IMAP_INBOUND_EXPENSE_PASSWORDS', ''), 'users' => env('INBOUND_EXPENSE_IMAP_USERS', ''),
'companies' => env('IMAP_INBOUND_EXPENSE_COMPANIES', ''), 'passwords' => env('INBOUND_EXPENSE_IMAP_PASSWORDS', ''),
] 'companies' => env('INBOUND_EXPENSE_IMAP_COMPANIES', ''),
],
'webhook' => [
'mailbox_template' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOXTEMPLATE', null),
'mailbox_template_enterprise' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOXTEMPLATE_ENTERPRISE', '{{input}}@expense.invoicing.co'),
],
],
]; ];

View File

@ -1,5 +1,6 @@
<?php <?php
use App\Models\Company;
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
@ -11,7 +12,14 @@ return new class extends Migration {
public function up(): void public function up(): void
{ {
Schema::table('company', function (Blueprint $table) { Schema::table('company', function (Blueprint $table) {
$table->string("expense_import")->default(true); $table->boolean("expense_import")->default(true);
$table->string("expense_mailbox")->nullable();
});
Company::query()->cursor()->each(function ($company) { // TODO: @turbo124 check migration on staging environment with real data to ensure, this works as exspected
$company->expense_mailbox = config('ninja.inbound_expense.webhook.mailbox_template') != '' ?
str_replace('{{company_key}}', $company->company_key, config('ninja.inbound_expense.webhook.mailbox_template')) : null;
$company->save();
}); });
Schema::table('vendor', function (Blueprint $table) { Schema::table('vendor', function (Blueprint $table) {
$table->string("expense_sender_email")->nullable(); $table->string("expense_sender_email")->nullable();