+sub action_save_phone_note {
+ my ($self) = @_;
+
+ if (!$::form->{phone_note}->{subject} || !$::form->{phone_note}->{body}) {
+ return $self->js->flash('error', t8('Phone note needs a subject and a body.'))->render;
+ }
+
+ my $phone_note;
+ if ($::form->{phone_note}->{id}) {
+ $phone_note = first { $_->id == $::form->{phone_note}->{id} } @{$self->order->phone_notes};
+ return $self->js->flash('error', t8('Phone note not found for this order.'))->render if !$phone_note;
+ }
+
+ $phone_note = SL::DB::Note->new() if !$phone_note;
+ my $is_new = !$phone_note->id;
+
+ $phone_note->assign_attributes(%{ $::form->{phone_note} },
+ trans_id => $self->order->id,
+ trans_module => 'oe',
+ employee => SL::DB::Manager::Employee->current);
+
+ $phone_note->save;
+ $self->order(SL::DB::Order->new(id => $self->order->id)->load);
+
+ my $tab_as_html = $self->p->render('order/tabs/phone_notes', SELF => $self);
+
+ return $self->js
+ ->replaceWith('#phone-notes', $tab_as_html)
+ ->html('#num_phone_notes', (scalar @{$self->order->phone_notes}) ? ' (' . scalar @{$self->order->phone_notes} . ')' : '')
+ ->flash('info', $is_new ? t8('Phone note has been created.') : t8('Phone note has been updated.'))
+ ->render;
+}
+
+sub action_delete_phone_note {
+ my ($self) = @_;
+
+ my $phone_note = first { $_->id == $::form->{phone_note}->{id} } @{$self->order->phone_notes};
+
+ return $self->js->flash('error', t8('Phone note not found for this order.'))->render if !$phone_note;
+
+ $phone_note->delete;
+ $self->order(SL::DB::Order->new(id => $self->order->id)->load);
+
+ my $tab_as_html = $self->p->render('order/tabs/phone_notes', SELF => $self);
+
+ return $self->js
+ ->replaceWith('#phone-notes', $tab_as_html)
+ ->html('#num_phone_notes', (scalar @{$self->order->phone_notes}) ? ' (' . scalar @{$self->order->phone_notes} . ')' : '')
+ ->flash('info', t8('Phone note has been deleted.'))
+ ->render;
+}
+