Revision f53d3f74
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; |
|
9 | 8 |
use SL::Presenter::Tag qw(select_tag hidden_tag div_tag); |
10 | 9 |
use SL::Locale::String qw(t8); |
11 | 10 |
use SL::SessionFile::Random; |
... | ... | |
2115 | 2114 |
my @order_locked_positions = map { $_->position } grep { $_->part->order_locked } @{ $self->order->items_sorted }; |
2116 | 2115 |
die t8('This record contains not orderable items at position #1', join ', ', @order_locked_positions) if @order_locked_positions; |
2117 | 2116 |
} |
2118 |
$self->create_kix18_ticket if ( $::instance_conf->get_kix18 && $self->type eq SALES_ORDER_TYPE() |
|
2119 |
&& $is_new && !$::form->{transaction_description} ); |
|
2117 |
|
|
2118 |
SL::Helper::KIX18->create_kix18_ticket('foo', order => $self->order) if ( $::instance_conf->get_kix18 && $self->type eq SALES_ORDER_TYPE() |
|
2119 |
&& $is_new && !$::form->{transaction_description} ); |
|
2120 | 2120 |
|
2121 | 2121 |
# create first version if none exists |
2122 | 2122 |
$self->order->add_order_version(SL::DB::OrderVersion->new(version => 1)) if !$self->order->order_version; |
... | ... | |
2177 | 2177 |
link_requirement_specs_linking_to_created_from_objects => \@converted_from_oe_ids, |
2178 | 2178 |
set_project_in_linked_requirement_specs => 1, |
2179 | 2179 |
); |
2180 |
$self->create_kix18_article if ( $::instance_conf->get_kix18 && $self->type eq SALES_ORDER_TYPE()
|
|
2181 |
&& $is_new && $self->order->ticket_id ); |
|
2180 |
SL::Helper::KIX18->create_kix18_article('foo', order => $self->order) if ( $::instance_conf->get_kix18 && $self->type eq SALES_ORDER_TYPE()
|
|
2181 |
&& $is_new && $self->order->ticket_id );
|
|
2182 | 2182 |
|
2183 | 2183 |
|
2184 | 2184 |
if ($::form->{email_journal_id}) { |
... | ... | |
2892 | 2892 |
return @errors; |
2893 | 2893 |
} |
2894 | 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 |
|
|
2938 | 2895 |
sub init_type_data { |
2939 | 2896 |
my ($self) = @_; |
2940 | 2897 |
SL::DB::Helper::TypeDataProxy->new('SL::DB::Order', $self->order->record_type); |
SL/Controller/ShopOrder.pm | ||
---|---|---|
152 | 152 |
$self->redirect_to(controller => "ShopOrder", action => 'show', id => $self->shop_order->id); |
153 | 153 |
}else{ |
154 | 154 |
$order->db->with_transaction( sub { |
155 |
|
|
156 |
SL::Helper::KIX18->create_kix18_ticket('foo', order => $order) if ($::instance_conf->get_kix18); |
|
157 |
|
|
155 | 158 |
$order->calculate_prices_and_taxes; |
156 | 159 |
$order->save; |
160 |
|
|
161 |
SL::Helper::KIX18->create_kix18_article('foo', order => $order) if ($::instance_conf->get_kix18); |
|
162 |
|
|
157 | 163 |
SL::DB::OrderVersion->new(oe_id => $order->id, version => 1)->save; |
158 | 164 |
|
159 | 165 |
my $snumbers = "ordernumber_" . $order->ordnumber; |
SL/Helper/KIX18.pm | ||
---|---|---|
1 |
package SL::Helper::KIX18; |
|
2 |
|
|
3 |
use strict; |
|
4 |
use warnings; |
|
5 |
|
|
6 |
use SL::KIX18Client; |
|
7 |
use SL::Locale::String qw(t8); |
|
8 |
use SL::Helper::Flash qw(flash_later); |
|
9 |
|
|
10 |
use Try::Tiny; |
|
11 |
|
|
12 |
|
|
13 |
use Exporter 'import'; |
|
14 |
our @EXPORT_OK = qw(create_kix18_ticket create_kix18_article); |
|
15 |
our %EXPORT_TAGS = (all => \@EXPORT_OK,); |
|
16 |
|
|
17 |
|
|
18 |
sub create_kix18_ticket { |
|
19 |
my ($self) = @_; |
|
20 |
my %params = @_; |
|
21 |
|
|
22 |
die "Need a valid order object!" unless ref $params{order} eq 'SL::DB::Order'; |
|
23 |
my $order = delete $params{order}; |
|
24 |
try { |
|
25 |
# create new ticket |
|
26 |
my $customer_name = $order->customer->name; |
|
27 |
my $title = t8("Order for #1", $customer_name); |
|
28 |
$order->{kix18_client} //= SL::KIX18Client->new(); |
|
29 |
my $id = $order->{kix18_client}->create_ticket(Title => $title); |
|
30 |
my $ticket = $order->{kix18_client}->get_ticket(ticket_id => $id); |
|
31 |
die "Invalid ticket number" unless $ticket->{Ticket}{TicketNumber}; |
|
32 |
|
|
33 |
$order->transaction_description($ticket->{Ticket}{TicketNumber}); |
|
34 |
$order->ticket_id($id); |
|
35 |
$order->order_status_id(SL::DB::Manager::OrderStatus->find_by(name => 'Ticket offen')->id); |
|
36 |
|
|
37 |
flash_later('info', t8("Ticket with ID #1 created.", $ticket->{Ticket}{TicketNumber})); |
|
38 |
|
|
39 |
} catch { die t8("Communication error KIX18: #1", $_ ) }; |
|
40 |
} |
|
41 |
|
|
42 |
sub create_kix18_article { |
|
43 |
my ($self) = @_; |
|
44 |
my %params = @_; |
|
45 |
|
|
46 |
die "Need a valid order object!" unless ref $params{order} eq 'SL::DB::Order'; |
|
47 |
my $order = delete $params{order}; |
|
48 |
my $customer_name = $order->customer->name; |
|
49 |
my $title = t8("Order for #1", $customer_name); |
|
50 |
my $note = '<b>' . t8("Details:") . '</b>' . "<br>"; |
|
51 |
foreach my $item (@{ $order->items }) { |
|
52 |
$title .= " " . $item->description; |
|
53 |
$note .= $item->qty . " " . $item->unit . " " . $item->description . "<br>"; |
|
54 |
} |
|
55 |
if ($::lx_office_conf{kix18}->{kivi_order_url}) { |
|
56 |
my $id = $order->id; |
|
57 |
my $link = $::lx_office_conf{kix18}->{kivi_order_url} =~ s/<%order_id%>/$id/r; |
|
58 |
$note .= t8('kivitendo Sales Order') . ': <a href="' . $link . '">' . $order->ordnumber . '</a>'; |
|
59 |
} |
|
60 |
try { |
|
61 |
# create article for Ticket |
|
62 |
$order->{kix18_client} //= SL::KIX18Client->new(); |
|
63 |
$order->{kix18_client}->create_article(Subject => $title, Body => $note, TicketID => $order->ticket_id); |
|
64 |
|
|
65 |
} catch { die t8("Communication error KIX18: #1", $_ ) }; |
|
66 |
} |
|
67 |
|
|
68 |
1; |
|
69 |
|
|
70 |
|
Auch abrufbar als: Unified diff
kix18: create_ticket* ausgelagert in SL/H/KIX18 und bei ShopOrder ergänzt