Improved Postscript output handling.
[account.git] / account.cpp
index ea071d6..2ed692c 100644 (file)
@@ -263,115 +263,130 @@ void PostScript_balans_layout(PostScript &ps, String header)
 
 void Ledger::accounts_report(const char * filename)
 {
-   PostScript ps(filename);
-   int        i;
+   try
+   {
+      PostScript ps(filename);
+      int        i;
 
-   for (i=0; i<nr_accs; i++)
+      for (i=0; i<nr_accs; i++)
+      {
+         accs[i].Postscript_sheet(ps);
+      }
+   }
+   catch (psexception &e)
    {
-      accs[i].Postscript_sheet(ps);
+      std::cerr << "Error creating postscript output: " << e.what() << "\n";
    }
 }
 
 void Ledger::saldi_report(const char * filename, date period_begin, date period_end)
 {
-   PostScript ps(filename);
-   balance total, saldi;
-   balance EndBalance, Result;
-   int        i;
-   float      y = 572;
-   int        row = 0;
-
-   String     header("Saldibalans");
+   try
+   {
+      PostScript ps(filename);
+      balance total, saldi;
+      balance EndBalance, Result;
+      int        i;
+      float      y = 572;
+      int        row = 0;
 
-   header += " van " + period_begin.format("%e %B %Y") + " tot " + period_end.format("%e %B %Y");
+      String     header("Saldibalans");
 
-   ps.NewPage(842, 595);
-   ps.FontSize(6);
+      header += " " + companyname;
+      header += " van " + period_begin.format("%e %B %Y") + " tot " + period_end.format("%e %B %Y");
 
+      ps.NewPage(842, 595);
+      ps.FontSize(6);
 
-   for (i=0; i<nr_accs; i++)
-   {
-      balance saldo(accs[i]);
 
-      if (saldo.debit() != 0 || saldo.credit() != 0)
+      for (i=0; i<nr_accs; i++)
       {
-         if (row == 64)
-         {
-            ps.FontSize(9);
-            PostScript_balans_layout(ps, header);
-            ps.NewPage(842, 595);
-            ps.FontSize(6);
-            y = 572;
-            row = 0;
-         }
+         balance saldo(accs[i]);
 
-         if (row % 2 == 1)
+         if (saldo.debit() != 0 || saldo.credit() != 0)
          {
-            ps.Rectangle(16, y-2, 739, 7);
-         }
+            if (row == 64)
+            {
+               ps.FontSize(9);
+               PostScript_balans_layout(ps, header);
+               ps.NewPage(842, 595);
+               ps.FontSize(6);
+               y = 572;
+               row = 0;
+            }
 
-         total += accs[i];
-         saldi += ~balance(accs[i]);
+            if (row % 2 == 1)
+            {
+               ps.Rectangle(16, y-2, 739, 7);
+            }
 
-         ps.Text(20, y, String(accs[i].Number()));
-         ps.Text(50, y, accs[i].Name());
+            total += accs[i];
+            saldi += ~balance(accs[i]);
 
-         balance saldo(accs[i]);
+            ps.Text(20, y, String(accs[i].Number()));
+            ps.Text(50, y, accs[i].Name());
 
-         ps.Text(200, y, saldo.debit().to_string());
-         ps.Text(270, y, saldo.credit().to_string());
-         saldo = ~saldo;
-         ps.Text(340, y, saldo.debit().to_string());
-         ps.Text(410, y, saldo.credit().to_string());
+            balance saldo(accs[i]);
 
-         if (accs[i].BAL())
-         {
-            EndBalance += ~balance(accs[i]);
-
-            ps.Text(620, y, saldo.debit().to_string());
-            ps.Text(690, y, saldo.credit().to_string());
-         }
-         else
-         {
-            Result += ~balance(accs[i]);
+            ps.Text(200, y, saldo.debit().to_string());
+            ps.Text(270, y, saldo.credit().to_string());
+            saldo = ~saldo;
+            ps.Text(340, y, saldo.debit().to_string());
+            ps.Text(410, y, saldo.credit().to_string());
 
-            ps.Text(480, y, saldo.debit().to_string());
-            ps.Text(550, y, saldo.credit().to_string());
-         }
+            if (accs[i].BAL())
+            {
+               EndBalance += ~balance(accs[i]);
 
-         y -= 7.0;
-         row ++;
-      }
-   }
+               ps.Text(620, y, saldo.debit().to_string());
+               ps.Text(690, y, saldo.credit().to_string());
+            }
+            else
+            {
+               Result += ~balance(accs[i]);
 
-   ps.FontSize(9);
-   PostScript_balans_layout(ps, header);
+               ps.Text(480, y, saldo.debit().to_string());
+               ps.Text(550, y, saldo.credit().to_string());
+            }
 
-   balance profit;
-   profit = ~Result;
-   Result += -profit;
-   EndBalance += profit;
+            y -= 7.0;
+            row ++;
+         }
+      }
 
-   ps.LineAttributes(0.5, 1.0, 0.0);
-   ps.Line(16, 60, 755, 60);
-   y = 52;
-   ps.Text(50, y, "Resultaat");
-   ps.Text(480, y, (-profit).debit().to_string());
-   ps.Text(550, y, (-profit).credit().to_string());
-   ps.Text(620, y, profit.debit().to_string());
-   ps.Text(690, y, profit.credit().to_string());
-
-   ps.Line(16, 50, 755, 50);
-   y = 42;
-   ps.Text(50, y, "Totaal");
-   ps.Text(200, y, total.debit().to_string());
-   ps.Text(270, y, total.credit().to_string());
-   ps.Text(340, y, saldi.debit().to_string());
-   ps.Text(410, y, saldi.credit().to_string());
-   ps.Text(480, y, Result.debit().to_string());
-   ps.Text(550, y, Result.credit().to_string());
-   ps.Text(620, y, EndBalance.debit().to_string());
-   ps.Text(690, y, EndBalance.credit().to_string());
+      ps.FontSize(9);
+      PostScript_balans_layout(ps, header);
+
+      balance profit;
+      profit = ~Result;
+      Result += -profit;
+      EndBalance += profit;
+
+      ps.LineAttributes(0.5, 1.0, 0.0);
+      ps.Line(16, 60, 755, 60);
+      y = 52;
+      ps.Text(50, y, "Resultaat");
+      ps.Text(480, y, (-profit).debit().to_string());
+      ps.Text(550, y, (-profit).credit().to_string());
+      ps.Text(620, y, profit.debit().to_string());
+      ps.Text(690, y, profit.credit().to_string());
+
+      ps.Line(16, 50, 755, 50);
+      y = 42;
+      ps.Text(50, y, "Totaal");
+      ps.Text(200, y, total.debit().to_string());
+      ps.Text(270, y, total.credit().to_string());
+      ps.Text(340, y, saldi.debit().to_string());
+      ps.Text(410, y, saldi.credit().to_string());
+      ps.Text(480, y, Result.debit().to_string());
+      ps.Text(550, y, Result.credit().to_string());
+      ps.Text(620, y, EndBalance.debit().to_string());
+      ps.Text(690, y, EndBalance.credit().to_string());
+   }
+   catch (psexception &e)
+   {
+      std::cerr << "Error creating postscript output: " << e.what() << "\n";
+   }
 }
 
 void Ledger::XML_saldi(std::ostream &s, date period_begin, date period_end)