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);
42 $main::lxdebug->enter_sub();
44 my ($self, $myconfig, $form, $draft_id, $draft_description) = @_;
46 my ($dbh, $sth, $query, %saved, $dumped);
48 $dbh = $form->get_standard_dbh;
51 my ($module, $submodule) = $self->get_module($form);
53 $query = "SELECT COUNT(*) FROM drafts WHERE id = ?";
54 my ($res) = selectrow_query($form, $dbh, $query, $draft_id);
57 $draft_id = $module . "-" . $submodule . "-" . Common::unique_id();
58 $query = "INSERT INTO drafts (id, module, submodule) VALUES (?, ?, ?)";
59 do_query($form, $dbh, $query, $draft_id, $module, $submodule);
62 map({ $saved{$_} = $form->{$_};
63 delete($form->{$_}); } @dont_save);
65 $dumped = YAML::Dump($form);
66 map({ $form->{$_} = $saved{$_}; } @dont_save);
69 qq|UPDATE drafts SET description = ?, form = ?, employee_id = | .
70 qq| (SELECT id FROM employee WHERE login = ?) | .
73 do_query($form, $dbh, $query, $draft_description, $dumped, $form->{login}, $draft_id);
77 $form->{draft_id} = $draft_id;
78 $form->{draft_description} = $draft_description;
80 $main::lxdebug->leave_sub();
84 $main::lxdebug->enter_sub();
86 my ($self, $myconfig, $form, $draft_id) = @_;
88 my ($dbh, $sth, $query, @values);
90 $dbh = $form->get_standard_dbh;
92 $query = qq|SELECT id, description, form FROM drafts WHERE id = ?|;
94 $sth = prepare_execute_query($form, $dbh, $query, $draft_id);
96 if (my $ref = $sth->fetchrow_hashref()) {
97 @values = ($ref->{form}, $ref->{id}, $ref->{description});
101 $main::lxdebug->leave_sub();
107 $main::lxdebug->enter_sub();
109 my ($self, $myconfig, $form, @draft_ids) = @_;
111 return $main::lxdebug->leave_sub() unless (@draft_ids);
113 my ($dbh, $sth, $query);
115 $dbh = $form->get_standard_dbh;
117 $query = qq|DELETE FROM drafts WHERE id IN (| . join(", ", map { "?" } @draft_ids) . qq|)|;
118 do_query($form, $dbh, $query, @draft_ids);
122 $main::lxdebug->leave_sub();
126 $::lxdebug->enter_sub;
129 my $myconfig = shift || \%::myconfig;
130 my $form = shift || $::form;
131 my $dbh = $form->get_standard_dbh;
133 my @list = selectall_hashref_query($form, $dbh, <<SQL, $self->get_module($form));
134 SELECT d.id, d.description, d.itime::timestamp(0) AS itime,
135 e.name AS employee_name
137 LEFT JOIN employee e ON d.employee_id = e.id
138 WHERE (d.module = ?) AND (d.submodule = ?)
142 $::lxdebug->leave_sub;