Rechnungs- und Gutschriftsnummern werden nun direkt innerhalb der Backend-Routinen...
[kivitendo-erp.git] / bin / mozilla / drafts.pl
1 #======================================================================
2 # LX-Office ERP
3 #
4 #======================================================================
5 #
6 # Saving and loading drafts
7 #
8 #======================================================================
9
10 use SL::Drafts;
11
12 require "bin/mozilla/common.pl";
13
14 sub save_draft {
15   $lxdebug->enter_sub();
16
17   if (!$form->{draft_id} && !$form->{draft_description}) {
18     restore_form($form->{SAVED_FORM}, 1) if ($form->{SAVED_FORM});
19     delete($form->{SAVED_FORM});
20     $form->{SAVED_FORM} = save_form();
21
22     $form->header();
23     print($form->parse_html_template("drafts/save_new"));
24     return $lxdebug->leave_sub();
25   }
26
27   my ($draft_id, $draft_description) =
28     ($form->{draft_id}, $form->{draft_description});
29
30   restore_form($form->{SAVED_FORM}, 1);
31   delete($form->{SAVED_FORM});
32
33   Drafts->save(\%myconfig, $form, $draft_id, $draft_description);
34
35   $form->{saved_message} = $locale->text("Draft saved.");
36
37   update();
38
39   $lxdebug->leave_sub();
40 }
41
42 sub remove_draft {
43   $lxdebug->enter_sub();
44
45   Drafts->remove(\%myconfig, $form, $form->{draft_id}) if ($form->{draft_id});
46
47   delete($form->{draft_id});
48   delete($form->{draft_description});
49
50   $lxdebug->leave_sub();
51 }
52
53 sub load_draft_maybe {
54   $lxdebug->enter_sub();
55
56   $lxdebug->leave_sub() and return 0 if ($form->{DONT_LOAD_DRAFT});
57
58   my ($draft_nextsub) = @_;
59
60   my @drafts = Drafts->list(\%myconfig, $form);
61
62   $lxdebug->leave_sub() and return 0 unless (@drafts);
63
64   $draft_nextsub = "add" unless ($draft_nextsub);
65
66   delete($form->{action});
67   my $saved_form = save_form();
68
69   $form->header();
70   print($form->parse_html_template("drafts/load",
71                                    { "DRAFTS" => \@drafts,
72                                      "SAVED_FORM" => $saved_form,
73                                      "draft_nextsub" => $draft_nextsub }));
74
75   $lxdebug->leave_sub();
76
77   return 1;
78 }
79
80 sub dont_load_draft {
81   $lxdebug->enter_sub();
82
83   my $draft_nextsub = $form->{draft_nextsub};
84   $draft_nextsub = "add" unless ($form->{draft_nextsub});
85   restore_form($form->{SAVED_FORM}, 1);
86   delete($form->{SAVED_FORM});
87   delete($form->{action});
88   $form->{DONT_LOAD_DRAFT} = 1;
89
90   &{ $draft_nextsub }();
91
92   $lxdebug->leave_sub();
93 }
94
95 sub load_draft {
96   $lxdebug->enter_sub();
97
98   my ($old_form, $id, $description) = Drafts->load(\%myconfig, $form, $form->{id});
99   if ($old_form) {
100     restore_form($old_form, 1);
101     $form->{draft_id} = $id;
102     $form->{draft_description} = $description;
103     $form->{remove_draft} = 'checked';
104   }
105
106   update();
107
108   $lxdebug->leave_sub();
109 }
110
111 sub delete_drafts {
112   $lxdebug->enter_sub();
113
114   my @ids;
115   foreach (keys(%{$form})) {
116     push(@ids, $1) if (/^checked_(.*)/ && $form->{$_});
117   }
118   Drafts->remove(\%myconfig, $form, @ids) if (@ids);
119   restore_form($form->{SAVED_FORM}, 1);
120   delete($form->{SAVED_FORM});
121
122   add();
123
124   $lxdebug->leave_sub();
125 }
126
127 sub draft_action_dispatcher {
128   $lxdebug->enter_sub();
129
130   if ($form->{draft_action} eq $locale->text("Skip")) {
131     dont_load_draft();
132   } elsif ($form->{draft_action} eq $locale->text("Delete drafts")) {
133     delete_drafts();
134   }
135
136   $lxdebug->leave_sub();
137 }
138
139 1;