1 #======================================================================
4 #======================================================================
6 # Saving and loading drafts
8 #======================================================================
20 $main::lxdebug->enter_sub();
22 my ($self, $form) = @_;
24 my ($module, $submodule);
26 $module = $form->{"script"};
28 if (grep({ $module eq $_ } qw(is ir ar ap))) {
29 $submodule = "invoice";
31 $submodule = "unknown";
34 $main::lxdebug->leave_sub();
36 return ($module, $submodule);
39 my @dont_save = qw(login password action);
46 $main::lxdebug->enter_sub();
48 my ($self, $myconfig, $form, $draft_id, $draft_description) = @_;
50 my ($dbh, $sth, $query, %saved, $dumped);
52 $dbh = $form->get_standard_dbh;
55 my ($module, $submodule) = $self->get_module($form);
57 $query = "SELECT COUNT(*) FROM drafts WHERE id = ?";
58 my ($res) = selectrow_query($form, $dbh, $query, $draft_id);
61 $draft_id = $module . "-" . $submodule . "-" . Common::unique_id();
62 $query = "INSERT INTO drafts (id, module, submodule) VALUES (?, ?, ?)";
63 do_query($form, $dbh, $query, $draft_id, $module, $submodule);
66 map({ $saved{$_} = $form->{$_};
67 delete($form->{$_}); } @dont_save);
69 $dumped = YAML::Dump($form);
70 map({ $form->{$_} = $saved{$_}; } @dont_save);
73 qq|UPDATE drafts SET description = ?, form = ?, employee_id = | .
74 qq| (SELECT id FROM employee WHERE login = ?) | .
77 do_query($form, $dbh, $query, $draft_description, $dumped, $::myconfig{login}, $draft_id);
81 $form->{draft_id} = $draft_id;
82 $form->{draft_description} = $draft_description;
84 $main::lxdebug->leave_sub();
88 $main::lxdebug->enter_sub();
90 my ($self, $myconfig, $form, $draft_id) = @_;
92 my ($dbh, $sth, $query, @values);
94 $dbh = $form->get_standard_dbh;
96 $query = qq|SELECT id, description, form FROM drafts WHERE id = ?|;
98 $sth = prepare_execute_query($form, $dbh, $query, $draft_id);
100 if (my $ref = $sth->fetchrow_hashref()) {
101 @values = ($ref->{form}, $ref->{id}, $ref->{description});
105 $main::lxdebug->leave_sub();
111 $main::lxdebug->enter_sub();
113 my ($self, $myconfig, $form, @draft_ids) = @_;
115 return $main::lxdebug->leave_sub() unless (@draft_ids);
117 my ($dbh, $sth, $query);
119 $dbh = $form->get_standard_dbh;
121 $query = qq|DELETE FROM drafts WHERE id IN (| . join(", ", map { "?" } @draft_ids) . qq|)|;
122 do_query($form, $dbh, $query, @draft_ids);
126 $main::lxdebug->leave_sub();
130 $::lxdebug->enter_sub;
133 my $myconfig = shift || \%::myconfig;
134 my $form = shift || $::form;
135 my $dbh = $form->get_standard_dbh;
137 my @list = selectall_hashref_query($form, $dbh, <<SQL, $self->get_module($form));
138 SELECT d.id, d.description, d.itime::timestamp(0) AS itime,
139 e.name AS employee_name
141 LEFT JOIN employee e ON d.employee_id = e.id
142 WHERE (d.module = ?) AND (d.submodule = ?)
146 $::lxdebug->leave_sub;