Revision 36e45d3d
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
SL/Controller/EmailJournal.pm | ||
---|---|---|
9 | 9 |
use SL::DB::EmailJournal; |
10 | 10 |
use SL::DB::EmailJournalAttachment; |
11 | 11 |
use SL::DB::Order; |
12 |
use SL::DB::Helper::HardRecordLinks; |
|
13 | 12 |
use SL::Helper::Flash; |
14 | 13 |
use SL::Locale::String; |
15 | 14 |
use SL::System::TaskServer; |
... | ... | |
190 | 189 |
my $attachment = $params{attachment}; |
191 | 190 |
my $record = $params{record}; |
192 | 191 |
|
193 |
# soft link |
|
194 | 192 |
$email_journal->link_to_record($record); |
195 |
|
|
196 |
# hard link |
|
197 |
SL::DB::Helper::HardRecordLinks->create_link($record, $email_journal); |
|
193 |
$email_journal->hard_link_to_record($record); |
|
198 | 194 |
|
199 | 195 |
if ($attachment) { |
200 | 196 |
$attachment->add_file_to_record($record); |
SL/Controller/Order.pm | ||
---|---|---|
41 | 41 |
use SL::Helper::UserPreferences::PositionsScrollbar; |
42 | 42 |
use SL::Helper::UserPreferences::UpdatePositions; |
43 | 43 |
|
44 |
use SL::DB::Helper::HardRecordLinks; |
|
45 |
|
|
46 | 44 |
use SL::Controller::Helper::GetModels; |
47 | 45 |
|
48 | 46 |
use List::Util qw(first sum0); |
... | ... | |
2418 | 2416 |
$has_final_invoice = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->type} @$lr; |
2419 | 2417 |
} |
2420 | 2418 |
|
2421 |
my $has_hard_links = SL::DB::Helper::HardRecordLinks->get_count($self->order);
|
|
2419 |
my $has_hard_links = $self->order->hard_linked;
|
|
2422 | 2420 |
|
2423 | 2421 |
my $right_for = { map { $_ => $_.'_edit' } @{$self->valid_types} }; |
2424 | 2422 |
$right_for->{ sales_order_intake_type() } = 'sales_order_edit'; |
SL/DB/EmailJournal.pm | ||
---|---|---|
9 | 9 |
use SL::DB::Manager::EmailJournal; |
10 | 10 |
use SL::DB::Helper::AttrSorted; |
11 | 11 |
use SL::DB::Helper::LinkedRecords; |
12 |
use SL::DB::Helper::HardLinkedRecords; |
|
12 | 13 |
|
13 | 14 |
__PACKAGE__->meta->add_relationship( |
14 | 15 |
attachments => { |
SL/DB/HardRecordLinksEmailJournalAndAP.pm | ||
---|---|---|
10 | 10 |
|
11 | 11 |
__PACKAGE__->meta->initialize; |
12 | 12 |
|
13 |
sub other_record { |
|
14 |
my ($self, $own_key) = @_; |
|
15 |
|
|
16 |
if ($own_key eq 'email_journal_id') { |
|
17 |
return $self->ap; |
|
18 |
} elsif ($own_key eq 'ap_id') { |
|
19 |
return $self->email_journal; |
|
20 |
} else { |
|
21 |
die "Unknown key $own_key"; |
|
22 |
} |
|
23 |
} |
|
24 |
|
|
25 |
|
|
13 | 26 |
1; |
SL/DB/HardRecordLinksEmailJournalAndOrder.pm | ||
---|---|---|
10 | 10 |
|
11 | 11 |
__PACKAGE__->meta->initialize; |
12 | 12 |
|
13 |
sub other_record { |
|
14 |
my ($self, $own_key) = @_; |
|
15 |
|
|
16 |
if ($own_key eq 'email_journal_id') { |
|
17 |
return $self->order; |
|
18 |
} elsif ($own_key eq 'order_id') { |
|
19 |
return $self->email_journal; |
|
20 |
} else { |
|
21 |
die "Unknown key $own_key"; |
|
22 |
} |
|
23 |
} |
|
24 |
|
|
13 | 25 |
1; |
SL/DB/Helper/HardLinkedRecords.pm | ||
---|---|---|
1 |
package SL::DB::Helper::HardLinkedRecords; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use List::Util qw(first any); |
|
6 |
|
|
7 |
use parent qw(Exporter); |
|
8 |
our @EXPORT = qw(hard_link_to_record hard_linked_records hard_linked_records_count hard_linked); |
|
9 |
|
|
10 |
my %RECORD_MODULE_TO_KEY = ( |
|
11 |
'SL::DB::Order' => 'order_id', |
|
12 |
'SL::DB::PurchaseInvoice' => 'ap_id', |
|
13 |
'SL::DB::EmailJournal' => 'email_journal_id', |
|
14 |
); |
|
15 |
my %RECORD_MODULE_TO_HARD_LINK_MODULE_NAMES = ( |
|
16 |
'SL::DB::Order' => [ |
|
17 |
'HardRecordLinksEmailJournalAndOrder', |
|
18 |
], |
|
19 |
'SL::DB::PurchaseInvoice' => [ |
|
20 |
'HardRecordLinksEmailJournalAndAP', |
|
21 |
], |
|
22 |
'SL::DB::EmailJournal' => [ |
|
23 |
'HardRecordLinksEmailJournalAndOrder', |
|
24 |
'HardRecordLinksEmailJournalAndAP', |
|
25 |
], |
|
26 |
); |
|
27 |
|
|
28 |
sub hard_link_to_record { |
|
29 |
my ($self, $record) = @_; |
|
30 |
my $module_1 = ref $self; |
|
31 |
my $module_2 = ref $record; |
|
32 |
my $hard_link_moduls_1 = $RECORD_MODULE_TO_HARD_LINK_MODULE_NAMES{ref $self}; |
|
33 |
my $hard_link_moduls_2 = $RECORD_MODULE_TO_HARD_LINK_MODULE_NAMES{ref $record}; |
|
34 |
|
|
35 |
my $hard_link_modul = first { |
|
36 |
my $a = $_; any {$a eq $_} @$hard_link_moduls_1 |
|
37 |
} @$hard_link_moduls_2; |
|
38 |
die "No hard link modul found for $module_1 and $module_2" unless $hard_link_modul; |
|
39 |
|
|
40 |
my $class = "SL::DB::$hard_link_modul"; |
|
41 |
eval "require $class;"; |
|
42 |
|
|
43 |
my $hard_link = $class->new( |
|
44 |
$RECORD_MODULE_TO_KEY{$module_1} => $self->id, |
|
45 |
$RECORD_MODULE_TO_KEY{$module_2} => $record->id, |
|
46 |
)->save; |
|
47 |
} |
|
48 |
|
|
49 |
sub hard_linked_records { |
|
50 |
my ($self) = @_; |
|
51 |
|
|
52 |
my @records = (); |
|
53 |
foreach my $hard_link_modul (@{ $RECORD_MODULE_TO_HARD_LINK_MODULE_NAMES{ref $self} }) { |
|
54 |
my $class = "SL::DB::$hard_link_modul"; |
|
55 |
eval "require $class;"; |
|
56 |
|
|
57 |
my $hard_links = "SL::DB::Manager::$hard_link_modul"->get_all( |
|
58 |
query => [ |
|
59 |
$RECORD_MODULE_TO_KEY{ref $self} => $self->id |
|
60 |
]); |
|
61 |
my $own_key = $RECORD_MODULE_TO_KEY{ref $self}; |
|
62 |
foreach my $hard_link (@$hard_links) { |
|
63 |
my $other_record = $hard_link->other_record($own_key); |
|
64 |
push @records, $other_record; |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
return @records; |
|
69 |
} |
|
70 |
|
|
71 |
sub hard_linked_records_count { |
|
72 |
my ($self) = @_; |
|
73 |
|
|
74 |
my $hard_links_count = 0; |
|
75 |
foreach my $hard_link_modul (@{ $RECORD_MODULE_TO_HARD_LINK_MODULE_NAMES{ref $self} }) { |
|
76 |
my $class = "SL::DB::$hard_link_modul"; |
|
77 |
eval "require $class;"; |
|
78 |
|
|
79 |
$hard_links_count += "SL::DB::Manager::$hard_link_modul"->get_all_count( |
|
80 |
query => [ |
|
81 |
$RECORD_MODULE_TO_KEY{ref $self} => $self->id |
|
82 |
]); |
|
83 |
} |
|
84 |
|
|
85 |
return $hard_links_count; |
|
86 |
} |
|
87 |
|
|
88 |
sub hard_linked { |
|
89 |
my ($self) = @_; |
|
90 |
return !!$self->hard_linked_records_count; |
|
91 |
} |
|
92 |
|
|
93 |
1; |
SL/DB/Helper/HardRecordLinks.pm | ||
---|---|---|
1 |
package SL::DB::Helper::HardRecordLinks; |
|
2 |
|
|
3 |
use strict; |
|
4 |
use warnings; |
|
5 |
|
|
6 |
use List::Util qw(first any); |
|
7 |
|
|
8 |
use SL::DB::HardRecordLinksEmailJournalAndAP; |
|
9 |
use SL::DB::HardRecordLinksEmailJournalAndOrder; |
|
10 |
|
|
11 |
my %RECORD_MODULE_TO_KEY = ( |
|
12 |
'SL::DB::Order' => 'order_id', |
|
13 |
'SL::DB::PurchaseInvoice' => 'ap_id', |
|
14 |
'SL::DB::EmailJournal' => 'email_journal_id', |
|
15 |
); |
|
16 |
my %RECORD_MODULE_TO_HARD_LINK_MODULE_NAMES = ( |
|
17 |
'SL::DB::Order' => [ |
|
18 |
'HardRecordLinksEmailJournalAndOrder', |
|
19 |
], |
|
20 |
'SL::DB::PurchaseInvoice' => [ |
|
21 |
'HardRecordLinksEmailJournalAndAP', |
|
22 |
], |
|
23 |
'SL::DB::EmailJournal' => [ |
|
24 |
'HardRecordLinksEmailJournalAndOrder', |
|
25 |
'HardRecordLinksEmailJournalAndAP', |
|
26 |
], |
|
27 |
); |
|
28 |
|
|
29 |
sub get_links { |
|
30 |
my ($self, $record) = @_; |
|
31 |
|
|
32 |
my @ret_hard_links = (); |
|
33 |
foreach my $hard_link_modul (@{ $RECORD_MODULE_TO_HARD_LINK_MODULE_NAMES{ref $record} }) { |
|
34 |
my $hard_links = "SL::DB::Manager::$hard_link_modul"->get_all( |
|
35 |
query => [ |
|
36 |
$RECORD_MODULE_TO_KEY{ref $record} => $record->id |
|
37 |
]); |
|
38 |
push @ret_hard_links, @$hard_links; |
|
39 |
} |
|
40 |
|
|
41 |
return @ret_hard_links; |
|
42 |
} |
|
43 |
|
|
44 |
sub get_count { |
|
45 |
my ($self, $record) = @_; |
|
46 |
my @hard_links = $self->get_links($record); |
|
47 |
return scalar @hard_links; |
|
48 |
} |
|
49 |
|
|
50 |
sub create_link { |
|
51 |
my ($self, $record_1, $record_2) = @_; |
|
52 |
my $module_1 = ref $record_1; |
|
53 |
my $module_2 = ref $record_2; |
|
54 |
my $hard_link_moduls_1 = $RECORD_MODULE_TO_HARD_LINK_MODULE_NAMES{ref $record_1}; |
|
55 |
my $hard_link_moduls_2 = $RECORD_MODULE_TO_HARD_LINK_MODULE_NAMES{ref $record_2}; |
|
56 |
|
|
57 |
my $hard_link_modul = first { |
|
58 |
my $a = $_; any {$a eq $_} @$hard_link_moduls_1 |
|
59 |
} @$hard_link_moduls_2; |
|
60 |
die "No hard link modul found for $module_1 and $module_2" unless $hard_link_modul; |
|
61 |
|
|
62 |
my $hard_link = "SL::DB::$hard_link_modul"->new( |
|
63 |
$RECORD_MODULE_TO_KEY{$module_1} => $record_1->id, |
|
64 |
$RECORD_MODULE_TO_KEY{$module_2} => $record_2->id, |
|
65 |
)->save; |
|
66 |
} |
|
67 |
|
|
68 |
1; |
SL/DB/Order.pm | ||
---|---|---|
16 | 16 |
use SL::DB::Helper::AttrSorted; |
17 | 17 |
use SL::DB::Helper::FlattenToForm; |
18 | 18 |
use SL::DB::Helper::LinkedRecords; |
19 |
use SL::DB::Helper::HardLinkedRecords; |
|
19 | 20 |
use SL::DB::Helper::PriceTaxCalculator; |
20 | 21 |
use SL::DB::Helper::PriceUpdater; |
21 | 22 |
use SL::DB::Helper::TransNumberGenerator; |
SL/DB/PurchaseInvoice.pm | ||
---|---|---|
11 | 11 |
use SL::DB::Helper::AttrHTML; |
12 | 12 |
use SL::DB::Helper::AttrSorted; |
13 | 13 |
use SL::DB::Helper::LinkedRecords; |
14 |
use SL::DB::Helper::HardLinkedRecords; |
|
14 | 15 |
use SL::DB::Helper::Payment qw(:ALL); |
15 | 16 |
use SL::DB::Helper::SalesPurchaseInvoice; |
16 | 17 |
use SL::DB::Helper::ZUGFeRD qw(:IMPORT); |
SL/Helper/EmailProcessing.pm | ||
---|---|---|
10 | 10 |
use SL::ZUGFeRD; |
11 | 11 |
|
12 | 12 |
use SL::DB::PurchaseInvoice; |
13 |
use SL::DB::Helper::HardRecordLinks; |
|
14 | 13 |
|
15 | 14 |
sub process_attachments { |
16 | 15 |
my ($self, $function_name, $email_journal, %params) = @_; |
... | ... | |
52 | 51 |
|
53 | 52 |
$attachment->add_file_to_record($record); |
54 | 53 |
|
55 |
# soft link |
|
56 | 54 |
$email_journal->link_to_record($record); |
57 |
|
|
58 |
# hard link |
|
59 |
SL::DB::Helper::HardRecordLinks->create_link($record, $email_journal); |
|
55 |
$email_journal->hard_link_to_record($record); |
|
60 | 56 |
} |
61 | 57 |
|
62 | 58 |
1; |
SL/IS.pm | ||
---|---|---|
2856 | 2856 |
if ($table eq 'ap') { |
2857 | 2857 |
require SL::DB::PurchaseInvoice; |
2858 | 2858 |
my $record = SL::DB::PurchaseInvoice->new(id => $form->{id})->load; |
2859 |
$result = SL::DB::Helper::HardRecordLinks->get_count($record);
|
|
2859 |
$result = $record->hard_linked;
|
|
2860 | 2860 |
} |
2861 | 2861 |
$main::lxdebug->leave_sub(); |
2862 | 2862 |
|
Auch abrufbar als: Unified diff
SL::DB::Helper::HardLinkedRecords: Nutzung wie LinkedRecords