Allow editing of booking texts
[infodrom.org/service.infodrom.org] / class / sales.class.php
index e432746..8dde7d8 100644 (file)
@@ -2,12 +2,57 @@
 
 class Sales extends DatabaseTable {
 
-  public function __construct($id)
+  public function __construct($id=false)
   {
     $this->idcolumn = 'nr';
     parent::__construct('sales', $id);
   }
 
+  public function getOpenItems($from=false, $to=false)
+  {
+      $sql = "SELECT nr,date,description,price * 100 AS price FROM sales WHERE paid = 0 AND visible = 1 ORDER BY date,nr";
+      return $this->db->fetchObjectList($sql);
+  }
+
+  public function ajaxSubtotal()
+  {
+
+      $text = '';
+      $commands = '';
+      $total = 0;
+
+      foreach ($_POST['nr'] as &$nr)
+         $nr = intval($nr);
+
+      $sql = sprintf("SELECT nr,date,description,price * 100 AS price FROM sales WHERE nr IN (%s) ORDER BY date,nr",
+                    implode(', ', $_POST['nr']));
+
+      foreach ($this->db->fetchObjectList($sql) as $row) {
+         $date = substr ($row->date,6,2) . "." . substr ($row->date,4,2) . "." . substr ($row->date,0,4);
+         $text .= utf8_encode(sprintf("%d %s %-53s %8.2f\n", $row->nr, $date, substr($row->description,0,53), $row->price / 100));
+         $commands .= sprintf("infocon --date %s --pay %d\n", date('Y-m-d', time()+60*60*24), $row->nr);
+         $total += $row->price;
+      }
+
+      if ($total != 0) {
+         $subject = 'Erstattungen';
+         if (strlen($_POST['title']))
+             $subject .= ' ' . $_POST['title'];
+
+         $text = "Liste der Buchungen\n" . str_repeat('=', 78) . "\n" . $text;
+         $text .= str_repeat('=', 78) . sprintf("\n%-69s %8.2f\n", 'Zwischensumme', $total / 100);
+
+         $mail = new Mail();
+         $mail->env_from(MAIL_FROM);
+         $mail->set('From', mb_encode_mimeheader(utf8_decode(sprintf("%s <%s>", MAIL_FROM_NAME, MAIL_FROM)),'latin1'));
+         $mail->set('To', MAIL_ERROR);
+         $mail->set('Subject', mb_encode_mimeheader($subject,'latin1'));
+         $mail->send($text . "\n\n" . $commands);
+      }
+
+      return true;
+  }
+
   public function setPaid()
   {
     return $this->modify('paid', 1);
@@ -18,9 +63,9 @@ class Sales extends DatabaseTable {
     return $this->modify('paid', 0);
   }
 
-  public function ajaxText(Array $data)
+  public function ajaxEditDescription(Array $data)
   {
-    return $this->modify('description', $data['text']);
+      return $this->modify('description', utf8_decode($data['content']));
   }
 
 }