added option to import payments from csv file
This commit is contained in:
@@ -37,11 +37,25 @@ public function run(): void
|
||||
'key' => 'person_addresses',
|
||||
'canonical_root' => 'address',
|
||||
'label' => 'Person Addresses',
|
||||
'fields' => ['address', 'country', 'type_id', 'description'],
|
||||
'aliases' => ['address', 'person_addresses'],
|
||||
'fields' => ['address', 'city', 'postal_code', 'country', 'type_id', 'description'],
|
||||
'field_aliases' => [
|
||||
'ulica' => 'address',
|
||||
'naslov' => 'address',
|
||||
'mesto' => 'city',
|
||||
'posta' => 'postal_code',
|
||||
'pošta' => 'postal_code',
|
||||
'zip' => 'postal_code',
|
||||
'drzava' => 'country',
|
||||
'država' => 'country',
|
||||
'opis' => 'description',
|
||||
],
|
||||
'aliases' => ['person_addresses', 'address', 'addresses'],
|
||||
'rules' => [
|
||||
['pattern' => '/^(naslov|ulica|address)\b/i', 'field' => 'address'],
|
||||
['pattern' => '/^(mesto|city|kraj)\b/i', 'field' => 'city'],
|
||||
['pattern' => '/^(posta|pošta|zip|postal)\b/i', 'field' => 'postal_code'],
|
||||
['pattern' => '/^(drzava|država|country)\b/i', 'field' => 'country'],
|
||||
['pattern' => '/^(komentar|opis|opomba|comment|description|note)\b/i', 'field' => 'description'],
|
||||
],
|
||||
'ui' => ['order' => 2],
|
||||
],
|
||||
@@ -106,6 +120,41 @@ public function run(): void
|
||||
],
|
||||
'ui' => ['order' => 7],
|
||||
],
|
||||
[
|
||||
'key' => 'payments',
|
||||
'canonical_root' => 'payment',
|
||||
'label' => 'Payments',
|
||||
// include common fields and helpful references for mapping
|
||||
'fields' => [
|
||||
'reference',
|
||||
'payment_nu',
|
||||
'payment_date',
|
||||
'amount',
|
||||
'type_id',
|
||||
'active',
|
||||
// optional helpers for mapping by related records
|
||||
'debt_id',
|
||||
'account_id',
|
||||
'account_reference',
|
||||
'contract_reference',
|
||||
],
|
||||
'field_aliases' => [
|
||||
'date' => 'payment_date',
|
||||
'datum' => 'payment_date',
|
||||
'paid_at' => 'payment_date',
|
||||
'number' => 'payment_nu',
|
||||
'znesek' => 'amount',
|
||||
'value' => 'amount',
|
||||
],
|
||||
'aliases' => ['payment', 'payments', 'placila', 'plačila'],
|
||||
'rules' => [
|
||||
['pattern' => '/^(sklic|reference|ref)\b/i', 'field' => 'reference'],
|
||||
['pattern' => '/^(stevilka|številka|number|payment\s*no\.?|payment\s*nu)\b/i', 'field' => 'payment_nu'],
|
||||
['pattern' => '/^(datum|date|paid\s*at|payment\s*date)\b/i', 'field' => 'payment_date'],
|
||||
['pattern' => '/^(znesek|amount|vplacilo|vplačilo|placilo|plačilo)\b/i', 'field' => 'amount'],
|
||||
],
|
||||
'ui' => ['order' => 8],
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($defs as $d) {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\ImportTemplate;
|
||||
use App\Models\ImportTemplateMapping;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PaymentsImportTemplateSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$template = ImportTemplate::query()->firstOrCreate([
|
||||
'name' => 'Payments CSV (reference)',
|
||||
], [
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'description' => 'Payments import by contract reference: contract.reference lookup + payment fields',
|
||||
'source_type' => 'csv',
|
||||
'default_record_type' => 'payments',
|
||||
'sample_headers' => [
|
||||
'Pogodba sklic',
|
||||
'Številka plačila',
|
||||
'Datum',
|
||||
'Znesek',
|
||||
'Sklic plačila',
|
||||
],
|
||||
'is_active' => true,
|
||||
'meta' => [
|
||||
'delimiter' => ',',
|
||||
'enclosure' => '"',
|
||||
'escape' => '\\',
|
||||
'payments_import' => true,
|
||||
'contract_key_mode' => 'reference',
|
||||
],
|
||||
]);
|
||||
|
||||
$mappings = [
|
||||
[
|
||||
'entity' => 'contracts',
|
||||
'source_column' => 'Pogodba sklic',
|
||||
'target_field' => 'contract.reference',
|
||||
'transform' => 'trim',
|
||||
'position' => 1,
|
||||
],
|
||||
[
|
||||
'entity' => 'payments',
|
||||
'source_column' => 'Številka plačila',
|
||||
'target_field' => 'payment.payment_nu',
|
||||
'transform' => 'trim',
|
||||
'position' => 2,
|
||||
],
|
||||
[
|
||||
'entity' => 'payments',
|
||||
'source_column' => 'Datum',
|
||||
'target_field' => 'payment.payment_date',
|
||||
'transform' => null,
|
||||
'position' => 3,
|
||||
],
|
||||
[
|
||||
'entity' => 'payments',
|
||||
'source_column' => 'Znesek',
|
||||
'target_field' => 'payment.amount',
|
||||
'transform' => 'decimal',
|
||||
'position' => 4,
|
||||
],
|
||||
[
|
||||
'entity' => 'payments',
|
||||
'source_column' => 'Sklic plačila',
|
||||
'target_field' => 'payment.reference',
|
||||
'transform' => 'trim',
|
||||
'position' => 5,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($mappings as $map) {
|
||||
ImportTemplateMapping::firstOrCreate([
|
||||
'import_template_id' => $template->id,
|
||||
'source_column' => $map['source_column'],
|
||||
], [
|
||||
'entity' => $map['entity'],
|
||||
'target_field' => $map['target_field'],
|
||||
'transform' => $map['transform'],
|
||||
'position' => $map['position'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user