Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3462658a

Von Tamino Steinert vor mehr als 1 Jahr hinzugefügt

  • ID 3462658a53ad12060720ace22fd45fb508d47537
  • Vorgänger 0c9bb179

part: Druck von Etikett und Information

Unterschiede anzeigen:

SL/Controller/Part.pm
22 22
use SL::DB::PriceRuleItem;
23 23
use SL::DB::Shop;
24 24
use SL::Helper::Flash;
25
use SL::Helper::CreatePDF qw(:all);
26
use SL::Helper::PrintOptions;
25 27
use SL::JSON;
26 28
use SL::Locale::String qw(t8);
27 29
use SL::MoreCommon qw(save_form);
......
35 37
                                  customerprices
36 38
                                  orphaned
37 39
                                  assortment assortment_items assembly assembly_items
40
                                  print_options
38 41
                                  all_pricegroups all_translations all_partsgroups all_units
39 42
                                  all_buchungsgruppen all_payment_terms all_warehouses
40 43
                                  parts_classification_filter
......
122 125
  }
123 126
}
124 127

  
128
sub action_save_and_print {
129
  my ($self) = @_;
130

  
131
  $self->save_with_render_error() or return;
132
  flash_later('info', t8('The item has been saved.'));
133
  $self->js_reset_part_after_save();
134

  
135
  my $formname    = $::form->{print_options}->{formname};
136
  my $language    = $::form->{print_options}->{language};
137
  my $format      = $::form->{print_options}->{format};
138
  my $media       = $::form->{print_options}->{media};
139
  my $printer_id  = $::form->{print_options}->{printer_id};
140
  my $copies      = $::form->{print_options}->{copies};
141

  
142
  my %result;
143
  eval {
144
    %result = SL::Template::LaTeX->parse_and_create_pdf(
145
       $formname . ".tex",
146
       SELF        => $self,
147
       part        => $self->part,
148
       template_meta => {
149
          formname   => 'part',
150
          language   => $language,
151
          extension  => 'pdf',
152
          format     => $format,
153
          media      => $media,
154
          today      => DateTime->today,
155
          lxconfig   => \%::lx_office_conf,
156
        },
157
      );
158
    if ($result{error}) {
159
      die t8('Conversion to PDF failed: #1', $result{error});
160
    }
161

  
162
    my $pdf = $result{file_name};
163

  
164
    if ($media eq 'screen') {
165
      my $file_name =  $formname . '.pdf';
166
      $file_name    =~ s{[^\w\.]+}{_}g;
167

  
168
      $self->send_file(
169
        $pdf,
170
        type => 'application/pdf',
171
        name => $file_name,
172
        js_no_render => 1,
173
      );
174
      unlink $result{file_name};
175
    } elsif ($media eq 'printer') {
176
      my $printer = SL::DB::Printer->new(id => $printer_id)->load;
177
      $printer->print_document(
178
        copies  => $copies,
179
        file_name => $result{file_name},
180
      );
181

  
182
      flash_later('info', t8('The document has been sent to the printer \'#1\'.', $printer->printer_description));
183
      unlink $result{file_name} if $result{file_name};
184
    } else {
185
      die t8('Media \'#1\' is not supported yet/anymore.', $media);
186
    }
187

  
188
    1;
189
  } or do {
190
    unlink $result{file_name} if $result{file_name};
191
    flash_later('error', t8("Creating the PDF failed!"));
192
    flash_later('error', $@);
193
  };
194

  
195
  my $redirect_url = $self->url_for(
196
    'action'  => 'edit',
197
    'part.id' => $self->part->id,
198
  );
199
  $self->js->redirect_to($redirect_url)->render;
200
}
201

  
125 202
sub action_save_and_purchase_order {
126 203
  my ($self) = @_;
127 204

  
......
1289 1366
  die "no query rules for parts_classification_type " . $::form->{parts_classification_type};
1290 1367
}
1291 1368

  
1369
sub init_print_options {
1370

  
1371
  my $print_form = Form->new('');
1372
  $print_form->{type}      = 'part';
1373
  $print_form->{printers}  = SL::DB::Manager::Printer->get_all_sorted;
1374
  $print_form->{languages} = SL::DB::Manager::Language->get_all_sorted;
1375

  
1376
  return SL::Helper::PrintOptions->get_print_options(
1377
      form => $print_form,
1378
      options => {dialog_name_prefix => 'print_options.',
1379
                  show_headers       => 1,
1380
                  no_queue           => 1,
1381
                  no_postscript      => 1,
1382
                  no_opendocument    => 1,
1383
                  no_html            => 1},
1384
    );
1385
}
1386

  
1292 1387
# simple checks to run on $::form before saving
1293 1388

  
1294 1389
sub form_check_part_description_exists {
......
1538 1633
      combobox => [
1539 1634
        action => [
1540 1635
          t8('Export'),
1541
          only_if => $self->part->is_assembly || $self->part->is_assortment,
1636
        ],
1637
        action => [
1638
          t8('Save and print'),
1639
          call     => [ 'kivi.Part.show_print_options' ],
1640
          disabled => !$may_edit ? t8('You do not have the permissions to access this function.') : undef,
1641
          checks   => [ 'kivi.validate_form' ],
1542 1642
        ],
1543 1643
        action => [
1544 1644
          $self->part->is_assembly ? t8('Assembly items') : t8('Assortment items'),
......
1696 1796

  
1697 1797
Saves the current part and then reloads the edit page for the part.
1698 1798

  
1799
=item C<action_save_and_print>
1800

  
1801
Saves the current part, prints the selected template and then reloads the edit
1802
page for the part.
1803

  
1699 1804
=item C<action_use_as_new>
1700 1805

  
1701 1806
Takes the information from the current part, plus any modifications made on the

Auch abrufbar als: Unified diff