Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4ffbaf73

Von Tamino Steinert vor 7 Tagen hinzugefügt

  • ID 4ffbaf73e5377299fd1e3061b62eb47af84a60d9
  • Vorgänger 175f674c
  • Nachfolger a44d1bc7

part: Druck von Etikett und Information

Unterschiede anzeigen:

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::Helper::UserPreferences::PartPickerSearch;
30 31
use SL::JSON;
......
40 41
                                  customerprices
41 42
                                  orphaned
42 43
                                  assortment assortment_items assembly assembly_items
44
                                  print_options
43 45
                                  all_pricegroups all_translations all_partsgroups all_units
44 46
                                  all_buchungsgruppen all_payment_terms all_warehouses
45 47
                                  parts_classification_filter
......
128 130
  }
129 131
}
130 132

  
133
sub action_save_and_print {
134
  my ($self) = @_;
135

  
136
  $self->save_with_render_error() or return;
137
  flash_later('info', t8('The item has been saved.'));
138
  $self->js_reset_part_after_save();
139

  
140
  my $formname    = $::form->{print_options}->{formname};
141
  my $language    = $::form->{print_options}->{language};
142
  my $format      = $::form->{print_options}->{format};
143
  my $media       = $::form->{print_options}->{media};
144
  my $printer_id  = $::form->{print_options}->{printer_id};
145
  my $copies      = $::form->{print_options}->{copies};
146

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

  
167
    my $pdf = $result{file_name};
168

  
169
    if ($media eq 'screen') {
170
      my $file_name =  $formname . '.pdf';
171
      $file_name    =~ s{[^\w\.]+}{_}g;
172

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

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

  
193
    1;
194
  } or do {
195
    unlink $result{file_name} if $result{file_name};
196
    flash_later('error', t8("Creating the PDF failed!"));
197
    flash_later('error', $@);
198
  };
199

  
200
  my $redirect_url = $self->url_for(
201
    'action'  => 'edit',
202
    'part.id' => $self->part->id,
203
  );
204
  $self->js->redirect_to($redirect_url)->render;
205
}
206

  
131 207
sub action_save_and_purchase_order {
132 208
  my ($self) = @_;
133 209

  
......
1542 1618
  die "no query rules for parts_classification_type " . $::form->{parts_classification_type};
1543 1619
}
1544 1620

  
1621
sub init_print_options {
1622

  
1623
  my $print_form = Form->new('');
1624
  $print_form->{type}      = 'part';
1625
  $print_form->{printers}  = SL::DB::Manager::Printer->get_all_sorted;
1626
  $print_form->{languages} = SL::DB::Manager::Language->get_all_sorted;
1627

  
1628
  return SL::Helper::PrintOptions->get_print_options(
1629
      form => $print_form,
1630
      options => {dialog_name_prefix => 'print_options.',
1631
                  show_headers       => 1,
1632
                  no_queue           => 1,
1633
                  no_postscript      => 1,
1634
                  no_opendocument    => 1,
1635
                  no_html            => 1},
1636
    );
1637
}
1638

  
1545 1639
# simple checks to run on $::form before saving
1546 1640

  
1547 1641
sub form_check_part_description_exists {
......
1804 1898
      combobox => [
1805 1899
        action => [
1806 1900
          t8('Export'),
1807
          only_if => $self->part->is_assembly || $self->part->is_assortment,
1901
        ],
1902
        action => [
1903
          t8('Save and print'),
1904
          call     => [ 'kivi.Part.show_print_options' ],
1905
          disabled => !$may_edit ? t8('You do not have the permissions to access this function.') : undef,
1906
          checks   => [ 'kivi.validate_form' ],
1808 1907
        ],
1809 1908
        action => [
1810 1909
          $self->part->is_assembly ? t8('Assembly items') : t8('Assortment items'),
......
1972 2071

  
1973 2072
Saves the current part and then reloads the edit page for the part.
1974 2073

  
2074
=item C<action_save_and_print>
2075

  
2076
Saves the current part, prints the selected template and then reloads the edit
2077
page for the part.
2078

  
1975 2079
=item C<action_use_as_new>
1976 2080

  
1977 2081
Takes the information from the current part, plus any modifications made on the

Auch abrufbar als: Unified diff