Revision f4a87e7a
SL/Controller/Order.pm | ||
---|---|---|
5 | 5 |
|
6 | 6 |
use SL::Helper::Flash qw(flash flash_later); |
7 | 7 |
use SL::HTML::Util; |
8 |
use SL::KIX18Client; |
|
8 | 9 |
use SL::Presenter::Tag qw(select_tag hidden_tag div_tag); |
9 | 10 |
use SL::Locale::String qw(t8); |
10 | 11 |
use SL::SessionFile::Random; |
... | ... | |
58 | 59 |
use File::Spec; |
59 | 60 |
use Cwd; |
60 | 61 |
use Sort::Naturally; |
62 |
use Try::Tiny; |
|
61 | 63 |
|
62 | 64 |
use Rose::Object::MakeMethods::Generic |
63 | 65 |
( |
... | ... | |
2113 | 2115 |
my @order_locked_positions = map { $_->position } grep { $_->part->order_locked } @{ $self->order->items_sorted }; |
2114 | 2116 |
die t8('This record contains not orderable items at position #1', join ', ', @order_locked_positions) if @order_locked_positions; |
2115 | 2117 |
} |
2118 |
$self->create_kix18_ticket if ( $::instance_conf->get_kix18 && $self->type eq SALES_ORDER_TYPE() |
|
2119 |
&& $is_new && !$::form->{transaction_description} ); |
|
2116 | 2120 |
|
2117 | 2121 |
# create first version if none exists |
2118 | 2122 |
$self->order->add_order_version(SL::DB::OrderVersion->new(version => 1)) if !$self->order->order_version; |
... | ... | |
2173 | 2177 |
link_requirement_specs_linking_to_created_from_objects => \@converted_from_oe_ids, |
2174 | 2178 |
set_project_in_linked_requirement_specs => 1, |
2175 | 2179 |
); |
2180 |
$self->create_kix18_article if ( $::instance_conf->get_kix18 && $self->type eq SALES_ORDER_TYPE() |
|
2181 |
&& $is_new && $self->order->ticket_id ); |
|
2182 |
|
|
2176 | 2183 |
|
2177 | 2184 |
if ($::form->{email_journal_id}) { |
2178 | 2185 |
my $email_journal = SL::DB::EmailJournal->new( |
... | ... | |
2885 | 2892 |
return @errors; |
2886 | 2893 |
} |
2887 | 2894 |
|
2895 |
sub create_kix18_ticket { |
|
2896 |
my ($self) = @_; |
|
2897 |
|
|
2898 |
try { |
|
2899 |
# create new ticket |
|
2900 |
my $customer_name = $self->order->customer->name; |
|
2901 |
my $title = t8("Order for #1", $customer_name); |
|
2902 |
$self->{kix18_client} //= SL::KIX18Client->new(); |
|
2903 |
my $id = $self->{kix18_client}->create_ticket(Title => $title); |
|
2904 |
my $ticket = $self->{kix18_client}->get_ticket(ticket_id => $id); |
|
2905 |
die "Invalid ticket number" unless $ticket->{Ticket}{TicketNumber}; |
|
2906 |
|
|
2907 |
$self->order->transaction_description($ticket->{Ticket}{TicketNumber}); |
|
2908 |
$self->order->ticket_id($id); |
|
2909 |
$self->order->order_status_id(SL::DB::Manager::OrderStatus->find_by(name => 'Ticket offen')->id); |
|
2910 |
|
|
2911 |
flash_later('info', t8("Ticket with ID #1 created.", $ticket->{Ticket}{TicketNumber})); |
|
2912 |
|
|
2913 |
} catch { die t8("Communication error KIX18: #1", $_ ) }; |
|
2914 |
} |
|
2915 |
|
|
2916 |
sub create_kix18_article { |
|
2917 |
my ($self) = @_; |
|
2918 |
my $customer_name = $self->order->customer->name; |
|
2919 |
my $title = t8("Order for #1", $customer_name); |
|
2920 |
my $note = '<b>' . t8("Details:") . '</b>' . "<br>"; |
|
2921 |
foreach my $item (@{ $self->order->items }) { |
|
2922 |
$title .= " " . $item->description; |
|
2923 |
$note .= $item->qty . " " . $item->unit . " " . $item->description . "<br>"; |
|
2924 |
} |
|
2925 |
if ($::lx_office_conf{kix18}->{kivi_order_url}) { |
|
2926 |
my $id = $self->order->id; |
|
2927 |
my $link = $::lx_office_conf{kix18}->{kivi_order_url} =~ s/<%order_id%>/$id/r; |
|
2928 |
$note .= t8('kivitendo Sales Order') . ': <a href="' . $link . '">' . $self->order->ordnumber . '</a>'; |
|
2929 |
} |
|
2930 |
try { |
|
2931 |
# create article for Ticket |
|
2932 |
#$self->{kix18_client} //= SL::KIX18Client->new(); |
|
2933 |
$self->{kix18_client}->create_article(Subject => $title, Body => $note, TicketID => $self->order->ticket_id); |
|
2934 |
|
|
2935 |
} catch { die t8("Communication error KIX18: #1", $_ ) }; |
|
2936 |
} |
|
2937 |
|
|
2888 | 2938 |
sub init_type_data { |
2889 | 2939 |
my ($self) = @_; |
2890 | 2940 |
SL::DB::Helper::TypeDataProxy->new('SL::DB::Order', $self->order->record_type); |
Auch abrufbar als: Unified diff
kix18: Eine Verkaufs-AB erstellt ein neues Ticket mit entsprechender Notiz