use SL::DB::Default;
use SL::DB::Unit;
use SL::DB::Price;
+use SL::DB::PriceFactor;
use SL::DB::Part;
use SL::DB::Printer;
use SL::DB::Language;
use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(item_ids_to_delete) ],
- 'scalar --get_set_init' => [ qw(order valid_types type cv p multi_items_models) ],
+ 'scalar --get_set_init' => [ qw(order valid_types type cv p multi_items_models all_price_factors) ],
);
__PACKAGE__->run_before('_check_auth');
__PACKAGE__->run_before('_recalc',
- only => [ qw(update save save_and_delivery_order print create_pdf send_email) ]);
+ only => [ qw(save save_and_delivery_order print create_pdf send_email) ]);
__PACKAGE__->run_before('_get_unalterable_data',
only => [ qw(save save_and_delivery_order print create_pdf send_email) ]);
);
}
-sub action_update {
- my ($self) = @_;
-
- $self->_pre_render();
- $self->render(
- 'order/form',
- title => $self->type eq _sales_order_type() ? $::locale->text('Edit Sales Order')
- : $self->type eq _purchase_order_type() ? $::locale->text('Edit Purchase Order')
- : '',
- %{$self->{template_args}}
- );
-}
-
sub action_delete {
my ($self) = @_;
$::auth->set_session_value("Order::create_pdf-${key}" => $sfile->file_name);
$self->js
- ->run('download_pdf', $pdf_filename, $key)
+ ->run('kivi.Order.download_pdf', $pdf_filename, $key)
->flash('info', t8('The PDF has been created'));
} elsif ($media eq 'printer') {
# printer
my $printer_id = $::form->{print_options}->{printer_id};
- my $printer;
- $printer = SL::DB::Printer->new(id => $printer_id)->load if $printer_id;
- if (!$printer) {
- return $self->js->flash('error', t8('Printer not found.'))->render;
- }
-
- my $command = SL::Template::create(type => 'ShellCommand', form => Form->new(''))->parse($printer->printer_command);
-
- for my $i (1 .. $copies) {
- open my $out, '|-', $command or die $!;
- binmode $out;
- print $out $pdf;
- close $out;
- }
+ SL::DB::Printer->new(id => $printer_id)->load->print_document(
+ copies => $copies,
+ content => $pdf,
+ );
$self->js->flash('info', t8('The PDF has been printed'));
}
my $dialog_html = $self->render('order/tabs/_email_dialog', { output => 0 });
$self->js
- ->run('show_email_dialog', $dialog_html)
+ ->run('kivi.Order.show_email_dialog', $dialog_html)
->reinit_widgets
->render($self);
}
$self->js
->val('#order_intnotes', $intnotes)
- ->run('close_email_dialog')
+ ->run('kivi.Order.close_email_dialog')
->render($self);
}
$self->_recalc();
$self->js
- ->run('update_sellprice', $::form->{item_id}, $item->sellprice_as_number);
+ ->run('kivi.Order.update_sellprice', $::form->{item_id}, $item->sellprice_as_number);
$self->_js_redisplay_linetotals;
$self->_js_redisplay_amounts_and_taxes;
$self->js->render();
$self->_recalc();
my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
- my $row_as_html = $self->p->render('order/tabs/_row', ITEM => $item, ID => $item_id);
+ my $row_as_html = $self->p->render('order/tabs/_row',
+ ITEM => $item,
+ ID => $item_id,
+ ALL_PRICE_FACTORS => $self->all_price_factors
+ );
$self->js
->append('#row_table_id', $row_as_html)
->val('.add_item_input', '')
- ->run('row_table_scroll_down')
- ->run('row_set_keyboard_events_by_id', $item_id)
- ->run('set_unit_change_with_oldval_by_id', $item_id)
- ->run('renumber_positions')
- ->on('.recalc', 'change', 'recalc_amounts_and_taxes')
- ->on('.reformat_number', 'change', 'reformat_number')
+ ->run('kivi.Order.init_row_handlers')
+ ->run('kivi.Order.row_table_scroll_down')
+ ->run('kivi.Order.renumber_positions')
->focus('#add_item_parts_id_name');
$self->_js_redisplay_amounts_and_taxes;
foreach my $item (@items) {
my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
- my $row_as_html = $self->p->render('order/tabs/_row', ITEM => $item, ID => $item_id);
+ my $row_as_html = $self->p->render('order/tabs/_row',
+ ITEM => $item,
+ ID => $item_id,
+ ALL_PRICE_FACTORS => $self->all_price_factors
+ );
- $self->js
- ->append('#row_table_id', $row_as_html)
- ->run('row_set_keyboard_events_by_id', $item_id)
- ->run('set_unit_change_with_oldval_by_id', $item_id);
+ $self->js->append('#row_table_id', $row_as_html);
}
$self->js
- ->run('close_multi_items_dialog')
- ->run('row_table_scroll_down')
- ->run('renumber_positions')
- ->on('.recalc', 'change', 'recalc_amounts_and_taxes')
- ->on('.reformat_number', 'change', 'reformat_number')
+ ->run('kivi.Order.close_multi_items_dialog')
+ ->run('kivi.Order.init_row_handlers')
+ ->run('kivi.Order.row_table_scroll_down')
+ ->run('kivi.Order.renumber_positions')
->focus('#add_item_parts_id_name');
$self->_js_redisplay_amounts_and_taxes;
@to_sort = sort { $b->{order_by} cmp $a->{order_by} } @to_sort;
}
$self->js
- ->run('redisplay_items', \@to_sort)
+ ->run('kivi.Order.redisplay_items', \@to_sort)
->render;
}
my @data = map {$::form->format_amount(\%::myconfig, $_->{linetotal}, 2, 0)} @{ $self->order->items_sorted };
$self->js
- ->run('redisplay_linetotals', \@data);
+ ->run('kivi.Order.redisplay_linetotals', \@data);
}
sub _js_redisplay_amounts_and_taxes {
);
}
+sub init_all_price_factors {
+ SL::DB::Manager::PriceFactor->get_all;
+}
+
sub _check_auth {
my ($self) = @_;
my %new_attr;
$new_attr{part} = $part;
- $new_attr{description} = $part->description if ! $item->description;
- $new_attr{qty} = 1.0 if ! $item->qty;
+ $new_attr{description} = $part->description if ! $item->description;
+ $new_attr{qty} = 1.0 if ! $item->qty;
+ $new_attr{price_factor_id} = $part->price_factor_id if ! $item->price_factor_id;
$new_attr{sellprice} = $price_src->price;
$new_attr{discount} = $discount_src->discount;
$new_attr{active_price_source} = $price_src;
} } @all_objects;
}
- $::request->{layout}->use_javascript("${_}.js") for qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery);
+ $::request->{layout}->use_javascript("${_}.js") for qw(kivi.SalesPurchase kivi.Order ckeditor/ckeditor ckeditor/adapters/jquery);
}
sub _create_pdf {
}
1;
+
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+SL::Controller::Order - controller for orders
+
+=head1 TODO
+
+=over 2
+
+=item *
+
+testing
+
+
+=item *
+
+currency
+
+
+=item *
+
+customer/vendor details ('D'-button)
+
+
+=item *
+
+credit limit
+
+
+=item *
+
+more workflows (save as new / invoice)
+
+
+=item *
+
+price sources: little symbols showing better price / better discount
+
+
+=item *
+
+custom shipto address
+
+
+=item *
+
+periodic invoices
+
+
+=item *
+
+more details on second row (marge, ...)
+
+
+=item *
+
+language / part translations
+
+
+=item *
+
+access rights
+
+
+=item *
+
+preset salesman from customer
+
+
+=item *
+
+display weights
+
+
+=item *
+
+force project if enabled in client config
+
+
+=back
+
+=head1 AUTHOR
+
+Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt>
+
+=cut