Revision 7a7f33b5
Von Moritz Bunkus vor fast 17 Jahren hinzugefügt
SL/CT.pm | ||
---|---|---|
39 | 39 |
|
40 | 40 |
use Data::Dumper; |
41 | 41 |
|
42 |
use SL::Common; |
|
42 | 43 |
use SL::CVar; |
43 | 44 |
use SL::DBUtils; |
45 |
use SL::FU; |
|
46 |
use SL::Notes; |
|
44 | 47 |
|
45 | 48 |
sub get_tuple { |
46 | 49 |
$main::lxdebug->enter_sub(); |
... | ... | |
73 | 76 |
selectrow_query($form, $dbh, $query, $form->{salesman_id}); |
74 | 77 |
} |
75 | 78 |
|
79 |
my ($employee_id) = selectrow_query($form, $dbh, qq|SELECT id FROM employee WHERE login = ?|, $form->{login}); |
|
80 |
$query = |
|
81 |
qq|SELECT n.*, n.itime::DATE AS created_on, |
|
82 |
e.name AS created_by_name, e.login AS created_by_login |
|
83 |
FROM notes n |
|
84 |
LEFT JOIN employee e ON (n.created_by = e.id) |
|
85 |
WHERE (n.trans_id = ?) AND (n.trans_module = 'ct')|; |
|
86 |
$form->{NOTES} = selectall_hashref_query($form, $dbh, $query, conv_i($form->{id})); |
|
87 |
|
|
88 |
$query = |
|
89 |
qq|SELECT fu.follow_up_date, fu.done AS follow_up_done, e.name AS created_for_name, e.name AS created_for_login |
|
90 |
FROM follow_ups fu |
|
91 |
LEFT JOIN employee e ON (fu.created_for_user = e.id) |
|
92 |
WHERE (fu.note_id = ?) |
|
93 |
AND NOT COALESCE(fu.done, FALSE) |
|
94 |
AND ( (fu.created_by = ?) |
|
95 |
OR (fu.created_by IN (SELECT DISTINCT what FROM follow_up_access WHERE who = ?)))|; |
|
96 |
$sth = prepare_query($form, $dbh, $query); |
|
97 |
|
|
98 |
foreach my $note (@{ $form->{NOTES} }) { |
|
99 |
do_statement($form, $sth, $query, conv_i($note->{id}), conv_i($note->{created_by}), conv_i($employee_id)); |
|
100 |
$ref = $sth->fetchrow_hashref(); |
|
101 |
|
|
102 |
map { $note->{$_} = $ref->{$_} } keys %{ $ref } if ($ref); |
|
103 |
} |
|
104 |
|
|
105 |
$sth->finish(); |
|
106 |
|
|
107 |
if ($form->{edit_note_id}) { |
|
108 |
$query = |
|
109 |
qq|SELECT n.id AS NOTE_id, n.subject AS NOTE_subject, n.body AS NOTE_body, |
|
110 |
fu.id AS FU_id, fu.follow_up_date AS FU_date, fu.done AS FU_done, fu.created_for_user AS FU_created_for_user |
|
111 |
FROM notes n |
|
112 |
LEFT JOIN follow_ups fu ON ((n.id = fu.note_id) AND NOT COALESCE(fu.done, FALSE)) |
|
113 |
WHERE n.id = ?|; |
|
114 |
$ref = selectfirst_hashref_query($form, $dbh, $query, conv_i($form->{edit_note_id})); |
|
115 |
|
|
116 |
if ($ref) { |
|
117 |
foreach my $key (keys %{ $ref }) { |
|
118 |
my $new_key = $key; |
|
119 |
$new_key =~ s/^([^_]+)/\U\1\E/; |
|
120 |
$form->{$new_key} = $ref->{$key}; |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
|
|
76 | 125 |
# check if it is orphaned |
77 | 126 |
my $arap = ( $form->{db} eq 'customer' ) ? "ar" : "ap"; |
78 | 127 |
$query = |
... | ... | |
384 | 433 |
# add shipto |
385 | 434 |
$form->add_shipto( $dbh, $form->{id}, "CT" ); |
386 | 435 |
|
436 |
$self->_save_note('dbh' => $dbh); |
|
437 |
$self->_delete_selected_notes('dbh' => $dbh); |
|
438 |
|
|
387 | 439 |
CVar->save_custom_variables('dbh' => $dbh, |
388 | 440 |
'module' => 'CT', |
389 | 441 |
'trans_id' => $form->{id}, |
... | ... | |
586 | 638 |
# add shipto |
587 | 639 |
$form->add_shipto( $dbh, $form->{id}, "CT" ); |
588 | 640 |
|
641 |
$self->_save_note('dbh' => $dbh); |
|
642 |
$self->_delete_selected_notes('dbh' => $dbh); |
|
643 |
|
|
589 | 644 |
CVar->save_custom_variables('dbh' => $dbh, |
590 | 645 |
'module' => 'CT', |
591 | 646 |
'trans_id' => $form->{id}, |
... | ... | |
845 | 900 |
$main::lxdebug->leave_sub(); |
846 | 901 |
} |
847 | 902 |
|
903 |
sub _save_note { |
|
904 |
$main::lxdebug->enter_sub(); |
|
905 |
|
|
906 |
my $self = shift; |
|
907 |
my %params = @_; |
|
908 |
|
|
909 |
my $form = $main::form; |
|
910 |
|
|
911 |
Common::check_params(\%params, 'dbh'); |
|
912 |
|
|
913 |
if (!$form->{NOTE_subject}) { |
|
914 |
$main::lxdebug->leave_sub(); |
|
915 |
return; |
|
916 |
} |
|
917 |
|
|
918 |
my $dbh = $params{dbh}; |
|
919 |
|
|
920 |
my %follow_up; |
|
921 |
my %note = ( |
|
922 |
'id' => $form->{NOTE_id}, |
|
923 |
'subject' => $form->{NOTE_subject}, |
|
924 |
'body' => $form->{NOTE_body}, |
|
925 |
'trans_id' => $form->{id}, |
|
926 |
'trans_module' => 'ct', |
|
927 |
); |
|
928 |
|
|
929 |
$note{id} = Notes->save(%note); |
|
930 |
|
|
931 |
if ($form->{FU_date}) { |
|
932 |
%follow_up = ( |
|
933 |
'id' => $form->{FU_id}, |
|
934 |
'note_id' => $note{id}, |
|
935 |
'follow_up_date' => $form->{FU_date}, |
|
936 |
'created_for_user' => $form->{FU_created_for_user}, |
|
937 |
'done' => $form->{FU_done} ? 1 : 0, |
|
938 |
'subject' => $form->{NOTE_subject}, |
|
939 |
'body' => $form->{NOTE_body}, |
|
940 |
'LINKS' => [ |
|
941 |
{ |
|
942 |
'trans_id' => $form->{id}, |
|
943 |
'trans_type' => $form->{db} eq 'customer' ? 'customer' : 'vendor', |
|
944 |
'trans_info' => $form->{name}, |
|
945 |
}, |
|
946 |
], |
|
947 |
); |
|
948 |
|
|
949 |
$follow_up{id} = FU->save(%follow_up); |
|
950 |
|
|
951 |
} elsif ($form->{FU_id}) { |
|
952 |
do_query($form, $dbh, qq|DELETE FROM follow_up_links WHERE follow_up_id = ?|, conv_i($form->{FU_id})); |
|
953 |
do_query($form, $dbh, qq|DELETE FROM follow_ups WHERE id = ?|, conv_i($form->{FU_id})); |
|
954 |
} |
|
955 |
|
|
956 |
delete @{$form}{grep { /^NOTE_|^FU_/ } keys %{ $form }}; |
|
957 |
|
|
958 |
$main::lxdebug->leave_sub(); |
|
959 |
} |
|
960 |
|
|
961 |
sub _delete_selected_notes { |
|
962 |
$main::lxdebug->enter_sub(); |
|
963 |
|
|
964 |
my $self = shift; |
|
965 |
my %params = @_; |
|
966 |
|
|
967 |
Common::check_params(\%params, 'dbh'); |
|
968 |
|
|
969 |
my $form = $main::form; |
|
970 |
my $dbh = $params{dbh}; |
|
971 |
|
|
972 |
foreach my $i (1 .. $form->{NOTES_rowcount}) { |
|
973 |
next unless ($form->{"NOTE_delete_$i"} && $form->{"NOTE_id_$i"}); |
|
974 |
|
|
975 |
Notes->delete('dbh' => $params{dbh}, |
|
976 |
'id' => $form->{"NOTE_id_$i"}); |
|
977 |
} |
|
978 |
|
|
979 |
$main::lxdebug->leave_sub(); |
|
980 |
} |
|
981 |
|
|
848 | 982 |
1; |
Auch abrufbar als: Unified diff
Zwei neue Features:
1. Beliebige Notizen für Kunden und Lieferanten können angelegt werden. Solche Notizen können auf Wiedervorlage gelegt werden, was durch 2. implementiert ist.
2. Einkaufs- und Verkaufsbelege können auf Wiedervorlage gelegt werden. Wiedervorlagen können für beliebige Nutzer erstellt werden (Aufgabe an andere Nutzer deligieren). Anstehende Wiedervorlagen und abgelaufene Angebote werden auf der Startseite in einer Aufgabenliste angezeigt.