Revision eb2db262
Von Tamino Steinert vor etwa 2 Monaten hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
25 | 25 |
use SL::DB::PurchaseBasketItem; |
26 | 26 |
use SL::DB::Shop; |
27 | 27 |
use SL::Helper::Flash; |
28 |
use SL::Helper::CreatePDF qw(:all); |
|
28 | 29 |
use SL::Helper::PrintOptions; |
29 | 30 |
use SL::JSON; |
30 | 31 |
use SL::Locale::String qw(t8); |
... | ... | |
39 | 40 |
customerprices |
40 | 41 |
orphaned |
41 | 42 |
assortment assortment_items assembly assembly_items |
43 |
print_options |
|
42 | 44 |
all_pricegroups all_translations all_partsgroups all_units |
43 | 45 |
all_buchungsgruppen all_payment_terms all_warehouses |
44 | 46 |
parts_classification_filter |
... | ... | |
127 | 129 |
} |
128 | 130 |
} |
129 | 131 |
|
132 |
sub action_save_and_print { |
|
133 |
my ($self) = @_; |
|
134 |
|
|
135 |
$self->save_with_render_error() or return; |
|
136 |
flash_later('info', t8('The item has been saved.')); |
|
137 |
$self->js_reset_part_after_save(); |
|
138 |
|
|
139 |
my $formname = $::form->{print_options}->{formname}; |
|
140 |
my $language = $::form->{print_options}->{language}; |
|
141 |
my $format = $::form->{print_options}->{format}; |
|
142 |
my $media = $::form->{print_options}->{media}; |
|
143 |
my $printer_id = $::form->{print_options}->{printer_id}; |
|
144 |
my $copies = $::form->{print_options}->{copies}; |
|
145 |
|
|
146 |
my %result; |
|
147 |
eval { |
|
148 |
%result = SL::Template::LaTeX->parse_and_create_pdf( |
|
149 |
$formname . ".tex", |
|
150 |
SELF => $self, |
|
151 |
part => $self->part, |
|
152 |
template_meta => { |
|
153 |
formname => 'part', |
|
154 |
language => $language, |
|
155 |
extension => 'pdf', |
|
156 |
format => $format, |
|
157 |
media => $media, |
|
158 |
today => DateTime->today, |
|
159 |
lxconfig => \%::lx_office_conf, |
|
160 |
}, |
|
161 |
); |
|
162 |
if ($result{error}) { |
|
163 |
die t8('Conversion to PDF failed: #1', $result{error}); |
|
164 |
} |
|
165 |
|
|
166 |
my $pdf = $result{file_name}; |
|
167 |
|
|
168 |
if ($media eq 'screen') { |
|
169 |
my $file_name = $formname . '.pdf'; |
|
170 |
$file_name =~ s{[^\w\.]+}{_}g; |
|
171 |
|
|
172 |
$self->send_file( |
|
173 |
$pdf, |
|
174 |
type => 'application/pdf', |
|
175 |
name => $file_name, |
|
176 |
js_no_render => 1, |
|
177 |
); |
|
178 |
unlink $result{file_name}; |
|
179 |
} elsif ($media eq 'printer') { |
|
180 |
my $printer = SL::DB::Printer->new(id => $printer_id)->load; |
|
181 |
$printer->print_document( |
|
182 |
copies => $copies, |
|
183 |
file_name => $result{file_name}, |
|
184 |
); |
|
185 |
|
|
186 |
flash_later('info', t8('The document has been sent to the printer \'#1\'.', $printer->printer_description)); |
|
187 |
unlink $result{file_name} if $result{file_name}; |
|
188 |
} else { |
|
189 |
die t8('Media \'#1\' is not supported yet/anymore.', $media); |
|
190 |
} |
|
191 |
|
|
192 |
1; |
|
193 |
} or do { |
|
194 |
unlink $result{file_name} if $result{file_name}; |
|
195 |
flash_later('error', t8("Creating the PDF failed!")); |
|
196 |
flash_later('error', $@); |
|
197 |
}; |
|
198 |
|
|
199 |
my $redirect_url = $self->url_for( |
|
200 |
'action' => 'edit', |
|
201 |
'part.id' => $self->part->id, |
|
202 |
); |
|
203 |
$self->js->redirect_to($redirect_url)->render; |
|
204 |
} |
|
205 |
|
|
130 | 206 |
sub action_save_and_purchase_order { |
131 | 207 |
my ($self) = @_; |
132 | 208 |
|
... | ... | |
1508 | 1584 |
die "no query rules for parts_classification_type " . $::form->{parts_classification_type}; |
1509 | 1585 |
} |
1510 | 1586 |
|
1587 |
sub init_print_options { |
|
1588 |
|
|
1589 |
my $print_form = Form->new(''); |
|
1590 |
$print_form->{type} = 'part'; |
|
1591 |
$print_form->{printers} = SL::DB::Manager::Printer->get_all_sorted; |
|
1592 |
$print_form->{languages} = SL::DB::Manager::Language->get_all_sorted; |
|
1593 |
|
|
1594 |
return SL::Helper::PrintOptions->get_print_options( |
|
1595 |
form => $print_form, |
|
1596 |
options => {dialog_name_prefix => 'print_options.', |
|
1597 |
show_headers => 1, |
|
1598 |
no_queue => 1, |
|
1599 |
no_postscript => 1, |
|
1600 |
no_opendocument => 1, |
|
1601 |
no_html => 1}, |
|
1602 |
); |
|
1603 |
} |
|
1604 |
|
|
1511 | 1605 |
# simple checks to run on $::form before saving |
1512 | 1606 |
|
1513 | 1607 |
sub form_check_part_description_exists { |
... | ... | |
1770 | 1864 |
combobox => [ |
1771 | 1865 |
action => [ |
1772 | 1866 |
t8('Export'), |
1773 |
only_if => $self->part->is_assembly || $self->part->is_assortment, |
|
1867 |
], |
|
1868 |
action => [ |
|
1869 |
t8('Save and print'), |
|
1870 |
call => [ 'kivi.Part.show_print_options' ], |
|
1871 |
disabled => !$may_edit ? t8('You do not have the permissions to access this function.') : undef, |
|
1872 |
checks => [ 'kivi.validate_form' ], |
|
1774 | 1873 |
], |
1775 | 1874 |
action => [ |
1776 | 1875 |
$self->part->is_assembly ? t8('Assembly items') : t8('Assortment items'), |
... | ... | |
1938 | 2037 |
|
1939 | 2038 |
Saves the current part and then reloads the edit page for the part. |
1940 | 2039 |
|
2040 |
=item C<action_save_and_print> |
|
2041 |
|
|
2042 |
Saves the current part, prints the selected template and then reloads the edit |
|
2043 |
page for the part. |
|
2044 |
|
|
1941 | 2045 |
=item C<action_use_as_new> |
1942 | 2046 |
|
1943 | 2047 |
Takes the information from the current part, plus any modifications made on the |
Auch abrufbar als: Unified diff
part: Druck von Etikett und Information