Revision a78e5571
Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt
SL/Controller/EmailJournal.pm | ||
---|---|---|
8 | 8 |
use SL::DB::Employee; |
9 | 9 |
use SL::DB::EmailJournal; |
10 | 10 |
use SL::DB::EmailJournalAttachment; |
11 |
use SL::DB::Order; |
|
12 |
use SL::DB::Helper::HardRecordLinks; |
|
11 | 13 |
use SL::Helper::Flash; |
12 | 14 |
use SL::Locale::String; |
13 | 15 |
use SL::System::TaskServer; |
... | ... | |
22 | 24 |
__PACKAGE__->run_before('add_stylesheet'); |
23 | 25 |
__PACKAGE__->run_before('add_js'); |
24 | 26 |
|
27 |
my %RECORD_TYPES_INFO = ( |
|
28 |
# Order |
|
29 |
Order => { |
|
30 |
controller => 'Order', |
|
31 |
model => 'SL::DB::Order', |
|
32 |
types => [ |
|
33 |
'purchase_order', |
|
34 |
'purchase_quotation_intake', |
|
35 |
'request_quotation', |
|
36 |
'sales_order', |
|
37 |
'sales_order_intake', |
|
38 |
'sales_quotation', |
|
39 |
], |
|
40 |
}, |
|
41 |
); |
|
42 |
my %RECORD_TYPE_TO_CONTROLLER = |
|
43 |
map { |
|
44 |
my $controller = $RECORD_TYPES_INFO{$_}->{controller}; |
|
45 |
map { $_ => $controller } @{ $RECORD_TYPES_INFO{$_}->{types} } |
|
46 |
} keys %RECORD_TYPES_INFO; |
|
47 |
my %RECORD_TYPE_TO_MODEL = |
|
48 |
map { |
|
49 |
my $model = $RECORD_TYPES_INFO{$_}->{model}; |
|
50 |
map { $_ => $model } @{ $RECORD_TYPES_INFO{$_}->{types} } |
|
51 |
} keys %RECORD_TYPES_INFO; |
|
52 |
|
|
25 | 53 |
# |
26 | 54 |
# actions |
27 | 55 |
# |
... | ... | |
56 | 84 |
|
57 | 85 |
$self->setup_show_action_bar; |
58 | 86 |
$self->render('email_journal/show', |
59 |
title => $::locale->text('View sent email'),
|
|
87 |
title => $::locale->text('View email'), |
|
60 | 88 |
back_to => $back_to); |
61 | 89 |
} |
62 | 90 |
|
... | ... | |
78 | 106 |
$self->send_file($ref, name => $attachment->name, type => $attachment->mime_type); |
79 | 107 |
} |
80 | 108 |
|
109 |
sub action_apply_record_action { |
|
110 |
my ($self) = @_; |
|
111 |
my $email_journal_id = $::form->{email_journal_id}; |
|
112 |
my $attachment_id = $::form->{attachment_id}; |
|
113 |
my $record_action = $::form->{record_action}; |
|
114 |
my $vendor_id = $::form->{vendor_id}; |
|
115 |
my $customer_id = $::form->{customer_id}; |
|
116 |
|
|
117 |
if ( $record_action =~ s/^link_// ) { # remove prefix |
|
118 |
|
|
119 |
# Load record |
|
120 |
my $record_type = $record_action; |
|
121 |
my $record_id = $::form->{$record_type . "_id"}; |
|
122 |
my $record_type_model = $RECORD_TYPE_TO_MODEL{$record_type}; |
|
123 |
my $record = $record_type_model->new(id => $record_id)->load; |
|
124 |
my $email_journal = SL::DB::EmailJournal->new(id => $email_journal_id)->load; |
|
125 |
|
|
126 |
my $attachment = $attachment_id ? |
|
127 |
SL::DB::EmailJournalAttachment->new(id => $attachment_id)->load |
|
128 |
: undef; |
|
129 |
|
|
130 |
$self->hard_link_email_journal_to_record( |
|
131 |
email_journal => $email_journal, |
|
132 |
record => $record, |
|
133 |
attachment => $attachment, |
|
134 |
); |
|
135 |
return $self->js->flash('info', $::locale->text('Hard linked to record: ') . $record->displayable_name)->render(); |
|
136 |
} |
|
137 |
|
|
138 |
my %additional_params = (); |
|
139 |
if ( $record_action =~ s/^customer_// ) { # remove prefix |
|
140 |
$additional_params{customer_id} = $customer_id; |
|
141 |
} elsif ( $record_action =~ s/^vendor_// ) { # remove prefix |
|
142 |
$additional_params{vendor_id} = $vendor_id; |
|
143 |
} |
|
144 |
$additional_params{type} = $record_action; |
|
145 |
$additional_params{controller} = $RECORD_TYPE_TO_CONTROLLER{$record_action}; |
|
146 |
|
|
147 |
$self->redirect_to( |
|
148 |
action => 'add', |
|
149 |
email_journal_id => $email_journal_id, |
|
150 |
attachment_id => $attachment_id, |
|
151 |
%additional_params, |
|
152 |
); |
|
153 |
} |
|
154 |
|
|
81 | 155 |
sub action_update_attachment_preview { |
82 | 156 |
my ($self) = @_; |
83 | 157 |
$::auth->assert('email_journal'); |
... | ... | |
92 | 166 |
->replaceWith('#attachment_preview', |
93 | 167 |
SL::Presenter::EmailJournal::attachment_preview( |
94 | 168 |
$attachment, |
95 |
style => "width:489px;border:1px solid black;margin:9px"
|
|
169 |
style => "width:655px;border:1px solid black;margin:9px"
|
|
96 | 170 |
) |
97 | 171 |
) |
98 | 172 |
->render(); |
... | ... | |
110 | 184 |
# helpers |
111 | 185 |
# |
112 | 186 |
|
187 |
sub hard_link_email_journal_to_record { |
|
188 |
my ($self, %params) = @_; |
|
189 |
my $email_journal = $params{email_journal}; |
|
190 |
my $attachment = $params{attachment}; |
|
191 |
my $record = $params{record}; |
|
192 |
|
|
193 |
# soft link |
|
194 |
$email_journal->link_to_record($record); |
|
195 |
|
|
196 |
# hard link |
|
197 |
SL::DB::Helper::HardRecordLinks->create_link($record, $email_journal); |
|
198 |
|
|
199 |
if ($attachment) { |
|
200 |
$attachment->add_file_to_record($record); |
|
201 |
} |
|
202 |
|
|
203 |
} |
|
204 |
|
|
205 |
sub link_attachment_to_record { |
|
206 |
my ($self, $attachment, $record) = @_; |
|
207 |
|
|
208 |
} |
|
209 |
|
|
210 |
sub find_cv_from_email { |
|
211 |
my ($self, $cv_type, $email_journal) = @_; |
|
212 |
my $email_address = $email_journal->from; |
|
213 |
|
|
214 |
# search for customer or vendor or both |
|
215 |
my $customer; |
|
216 |
my $vendor; |
|
217 |
if ($cv_type ne 'vendor') { |
|
218 |
$customer = SL::DB::Manager::Customer->get_first( |
|
219 |
where => [ |
|
220 |
or => [ |
|
221 |
email => $email_address, |
|
222 |
cc => $email_address, |
|
223 |
bcc => $email_address, |
|
224 |
'contacts.cp_email' => $email_address, |
|
225 |
'contacts.cp_privatemail' => $email_address, |
|
226 |
'shipto.shiptoemail' => $email_address, |
|
227 |
], |
|
228 |
], |
|
229 |
with_objects => [ 'contacts', 'shipto' ], |
|
230 |
); |
|
231 |
} elsif ($cv_type ne 'customer') { |
|
232 |
$vendor = SL::DB::Manager::Vendor->get_first( |
|
233 |
where => [ |
|
234 |
or => [ |
|
235 |
email => $email_address, |
|
236 |
cc => $email_address, |
|
237 |
bcc => $email_address, |
|
238 |
'contacts.cp_email' => $email_address, |
|
239 |
'contacts.cp_privatemail' => $email_address, |
|
240 |
'shipto.shiptoemail' => $email_address, |
|
241 |
], |
|
242 |
], |
|
243 |
with_objects => [ 'contacts', 'shipto' ], |
|
244 |
); |
|
245 |
} |
|
246 |
|
|
247 |
return $customer || $vendor; |
|
248 |
} |
|
249 |
|
|
250 |
sub find_customer_from_email { |
|
251 |
my ($self, $email_journal) = @_; |
|
252 |
my $email_address = $email_journal->from; |
|
253 |
|
|
254 |
my $customer = SL::DB::Manager::Customer->get_first( |
|
255 |
where => [ |
|
256 |
or => [ |
|
257 |
email => $email_address, |
|
258 |
cc => $email_address, |
|
259 |
bcc => $email_address, |
|
260 |
'contacts.cp_email' => $email_address, |
|
261 |
'contacts.cp_privatemail' => $email_address, |
|
262 |
'shipto.shiptoemail' => $email_address, |
|
263 |
], |
|
264 |
], |
|
265 |
with_objects => [ 'contacts', 'shipto' ], |
|
266 |
); |
|
267 |
|
|
268 |
return $customer; |
|
269 |
} |
|
270 |
|
|
113 | 271 |
sub add_js { |
114 | 272 |
$::request->{layout}->use_javascript("${_}.js") for qw( |
115 | 273 |
kivi.EmailJournal |
Auch abrufbar als: Unified diff
EmailJournal: Basisfunktionalität fürs Verlinken und Neu erstellen von Belegen