Revision db7a2e79
Von Sven Schöling vor mehr als 8 Jahren hinzugefügt
SL/Controller/Letter.pm | ||
---|---|---|
23 | 23 |
use SL::Webdav::File; |
24 | 24 |
|
25 | 25 |
use Rose::Object::MakeMethods::Generic ( |
26 |
'scalar --get_set_init' => [ qw(letter all_employees models webdav_objects) ], |
|
26 |
'scalar --get_set_init' => [ qw(letter all_employees models webdav_objects is_sales) ],
|
|
27 | 27 |
); |
28 | 28 |
|
29 | 29 |
__PACKAGE__->run_before('check_auth_edit'); |
... | ... | |
37 | 37 |
subject => t8('Subject'), |
38 | 38 |
letternumber => t8('Letternumber'), |
39 | 39 |
customer_id => t8('Customer'), |
40 |
vendor_id => t8('Vendor'), |
|
40 | 41 |
contact => t8('Contact'), |
41 | 42 |
); |
42 | 43 |
|
44 |
### actions |
|
45 |
|
|
43 | 46 |
sub action_add { |
44 | 47 |
my ($self, %params) = @_; |
45 | 48 |
|
... | ... | |
60 | 63 |
return $self->action_add |
61 | 64 |
unless $::form->{letter} || $::form->{draft}; |
62 | 65 |
|
63 |
$self->letter(SL::DB::Letter->new_from_draft($::form->{draft}{id})) |
|
64 |
if $::form->{draft}; |
|
66 |
if ($::form->{draft}) { |
|
67 |
$self->letter(SL::DB::Letter->new_from_draft($::form->{draft}{id})); |
|
68 |
$self->is_sales($self->letter->is_sales); |
|
69 |
} |
|
65 | 70 |
|
66 | 71 |
$self->_display( |
67 | 72 |
title => t8('Edit Letter'), |
... | ... | |
94 | 99 |
|
95 | 100 |
my $letter = $self->letter; |
96 | 101 |
|
97 |
if (!$self->letter->customer_id || !$self->letter->customer) {
|
|
102 |
if (!$self->letter->has_customer_vendor) {
|
|
98 | 103 |
return $self->js |
99 | 104 |
->replaceWith( |
100 | 105 |
'#letter_cp_id', |
... | ... | |
103 | 108 |
->render; |
104 | 109 |
} |
105 | 110 |
|
106 |
my $contacts = $letter->customer->contacts; |
|
111 |
my $contacts = $letter->customer_vendor->contacts;
|
|
107 | 112 |
|
108 | 113 |
my $default; |
109 | 114 |
if ( $letter->contact |
110 | 115 |
&& $letter->contact->cp_cv_id |
111 |
&& $letter->contact->cp_cv_id == $letter->customer_id) { |
|
116 |
&& $letter->contact->cp_cv_id == $letter->customer_vendor_id) {
|
|
112 | 117 |
$default = $letter->contact->cp_id; |
113 | 118 |
} else { |
114 | 119 |
$default = ''; |
... | ... | |
336 | 341 |
); |
337 | 342 |
} |
338 | 343 |
|
344 |
### internal methods |
|
345 |
|
|
339 | 346 |
sub _display { |
340 | 347 |
my ($self, %params) = @_; |
341 | 348 |
|
... | ... | |
346 | 353 |
$params{title} ||= t8('Edit Letter'); |
347 | 354 |
|
348 | 355 |
$::form->{type} = 'letter'; # needed for print_options |
349 |
$::form->{vc} = 'customer'; # needs to be for _get_contacts...
|
|
356 |
$::form->{vc} = $letter->is_sales ? 'customer' : 'vendor'; # needs to be for _get_contacts...
|
|
350 | 357 |
|
351 | 358 |
$::request->layout->add_javascripts('customer_or_vendor_selection.js'); |
352 | 359 |
$::request->layout->add_javascripts('edit_part_window.js'); |
... | ... | |
386 | 393 |
my $report = SL::ReportGenerator->new(\%::myconfig, $::form); |
387 | 394 |
$self->{report} = $report; |
388 | 395 |
|
389 |
my @columns = qw(date subject letternumber customer_id contact date); |
|
390 |
my @sortable = qw(date subject letternumber customer_id contact date); |
|
396 |
my @columns = qw(date subject letternumber customer_id vendor_id contact date);
|
|
397 |
my @sortable = qw(date subject letternumber customer_id vendor_id contact date);
|
|
391 | 398 |
|
392 | 399 |
my %column_defs = ( |
393 | 400 |
date => { text => t8('Date'), sub => sub { $_[0]->date_as_date } }, |
... | ... | |
395 | 402 |
obj_link => sub { $self->url_for(action => 'edit', 'letter.id' => $_[0]->id, callback => $self->models->get_callback) } }, |
396 | 403 |
letternumber => { text => t8('Letternumber'), sub => sub { $_[0]->letternumber }, |
397 | 404 |
obj_link => sub { $self->url_for(action => 'edit', 'letter.id' => $_[0]->id, callback => $self->models->get_callback) } }, |
398 |
customer_id => { text => t8('Customer'), sub => sub { SL::DB::Manager::Customer->find_by_or_create(id => $_[0]->customer_id)->displayable_name } }, |
|
405 |
customer_id => { text => t8('Customer'), sub => sub { SL::DB::Manager::Customer->find_by_or_create(id => $_[0]->customer_id)->displayable_name }, visible => $self->is_sales }, |
|
406 |
vendor_id => { text => t8('Vendor'), sub => sub { SL::DB::Manager::Vendor->find_by_or_create(id => $_[0]->vendor_id)->displayable_name }, visible => !$self->is_sales}, |
|
399 | 407 |
contact => { text => t8('Contact'), sub => sub { $_[0]->contact ? $_[0]->contact->full_name : '' } }, |
400 | 408 |
); |
401 | 409 |
|
... | ... | |
413 | 421 |
|
414 | 422 |
$report->set_columns(%column_defs); |
415 | 423 |
$report->set_column_order(@columns); |
416 |
$report->set_export_options(qw(list filter)); |
|
424 |
$report->set_export_options(qw(list filter is_sales));
|
|
417 | 425 |
$report->set_options_from_form; |
418 | 426 |
|
419 | 427 |
$self->models->disable_plugin('paginated') if $report->{options}{output_format} =~ /^(pdf|csv)$/i; |
428 |
$self->models->add_additional_url_params(is_sales => $self->is_sales); |
|
420 | 429 |
$self->models->finalize; |
421 | 430 |
$self->models->set_report_generator_sort_options(report => $report, sortable_columns => \@sortable); |
422 | 431 |
|
... | ... | |
465 | 474 |
|
466 | 475 |
return 0 if $params{skip_drafts}; |
467 | 476 |
|
468 |
my $letter_drafts = SL::DB::Manager::LetterDraft->get_all; |
|
477 |
my $letter_drafts = SL::DB::Manager::LetterDraft->get_all( |
|
478 |
query => [ |
|
479 |
SL::DB::Manager::Letter->is_sales_filter($self->is_sales), |
|
480 |
] |
|
481 |
); |
|
469 | 482 |
|
470 | 483 |
return unless @$letter_drafts; |
471 | 484 |
|
... | ... | |
552 | 565 |
->assign_attributes(%{ $::form->{letter} }); |
553 | 566 |
|
554 | 567 |
if ($letter->cp_id) { |
555 |
# $letter->customer_id($letter->contact->cp_cv_id); |
|
568 |
# $letter->customer_vendor_id($letter->contact->cp_cv_id);
|
|
556 | 569 |
# contacts don't have language_id yet |
557 | 570 |
# $letter->greeting(GenericTranslations->get( |
558 | 571 |
# translation_type => 'greetings::' . ($letter->contact->cp_gender eq 'f' ? 'female' : 'male'), |
... | ... | |
561 | 574 |
# )); |
562 | 575 |
} |
563 | 576 |
|
577 |
$self->is_sales($letter->is_sales); |
|
578 |
|
|
564 | 579 |
$letter; |
565 | 580 |
} |
566 | 581 |
|
... | ... | |
570 | 585 |
SL::Controller::Helper::GetModels->new( |
571 | 586 |
controller => $self, |
572 | 587 |
model => 'Letter', |
588 |
query => [ |
|
589 |
SL::DB::Manager::Letter->is_sales_filter($self->is_sales), |
|
590 |
], |
|
573 | 591 |
sorted => \%sort_columns, |
574 | 592 |
with_objects => [ 'contact', 'salesman', 'employee' ], |
575 | 593 |
); |
... | ... | |
600 | 618 |
} @all_objects ]; |
601 | 619 |
} |
602 | 620 |
|
621 |
sub init_is_sales { |
|
622 |
die 'is_sales must be set' unless defined $::form->{is_sales}; |
|
623 |
$::form->{is_sales}; |
|
624 |
} |
|
625 |
|
|
603 | 626 |
sub check_auth_edit { |
604 | 627 |
$::auth->assert('sales_letter_edit'); |
605 | 628 |
} |
... | ... | |
622 | 645 |
|
623 | 646 |
Simple letter CRUD controller with drafting capabilities. |
624 | 647 |
|
625 |
=head1 TODO |
|
626 |
|
|
627 |
Customer/Vendor switch for dealing with vendor letters |
|
628 |
|
|
629 | 648 |
copy to webdav is crap |
630 | 649 |
|
631 |
customer/vendor stuff |
|
632 |
|
|
633 | 650 |
=head1 AUTHOR |
634 | 651 |
|
635 | 652 |
Sven Schöling E<lt>s.schoeling@linet-services.deE<gt> |
Auch abrufbar als: Unified diff
Briefe: Lieferantenbriefe