Einkaufs-, Verkaufs-, Debitoren- und Kreditorenrechnungen können als Entwurf gespeich...
[kivitendo-erp.git] / bin / mozilla / ap.pl
index f5c6609..54a9c94 100644 (file)
@@ -37,6 +37,7 @@ use SL::PE;
 
 require "$form->{path}/arap.pl";
 require "bin/mozilla/common.pl";
+require "bin/mozilla/drafts.pl";
 
 1;
 
@@ -73,6 +74,8 @@ require "bin/mozilla/common.pl";
 sub add {
   $lxdebug->enter_sub();
 
+  return $lxdebug->leave_sub() if (load_draft_maybe());
+
   $form->{title} = "Add";
 
   $form->{callback} =
@@ -459,6 +462,8 @@ sub form_header {
 <input type=hidden name=locked value=$form->{locked}>
 <input type=hidden name=title value="$title">
 
+| . ($form->{saved_message} ? qq|<p>$form->{saved_message}</p>| : "") . qq|
+
 <table width=100%>
   <tr class=listtop>
     <th class=listtop>$form->{title}</th>
@@ -757,6 +762,10 @@ sub form_footer {
 <input type=hidden name=path value=$form->{path}>
 <input type=hidden name=login value=$form->{login}>
 <input type=hidden name=password value=$form->{password}>
+|
+. $cgi->hidden('-name' => 'draft_id', '-default' => [$form->{draft_id}])
+. $cgi->hidden('-name' => 'draft_description', '-default' => [$form->{draft_description}])
+. qq|
 
 <br>
 |;
@@ -789,7 +798,9 @@ sub form_footer {
   } elsif (($transdate > $closedto) && !$form->{id}) {
     print qq|
       <input class=submit type=submit name=action value="|
-      . $locale->text('Post') . qq|">|;
+      . $locale->text('Post') . qq|"> | .
+      NTI($cgi->submit('-name' => 'action', '-value' => $locale->text('Save draft'),
+                       '-class' => 'submit'));
   }
   # button for saving history
   if($form->{id} ne "") {
@@ -1000,15 +1011,17 @@ sub post {
   $form->{taxkey}       = $taxkey;
 
   $form->{id} = 0 if $form->{postasnew};
-  # saving the history
-  if(!exists $form->{addition} && $form->{id} ne "") {
-       $form->{addition} = "POSTED";
-       $form->save_history($form->dbconnect(\%myconfig));
-  }
-  # /saving the history 
 
-  $form->redirect($locale->text('Transaction posted!'))
-    if (AP->post_transaction(\%myconfig, \%$form));
+  if (AP->post_transaction(\%myconfig, \%$form)) {
+    # saving the history
+    if(!exists $form->{addition} && $form->{id} ne "") {
+      $form->{addition} = "POSTED";
+      $form->save_history($form->dbconnect(\%myconfig));
+    }
+    # /saving the history 
+    remove_draft();
+    $form->redirect($locale->text('Transaction posted!'));
+  }
   $form->error($locale->text('Cannot post transaction!'));
 
   $lxdebug->leave_sub();