3 class Sales extends DatabaseTable {
5 public function __construct($id=false)
7 $this->idcolumn = 'nr';
8 parent::__construct('sales', $id);
11 public function getOpenItems($from=false, $to=false)
13 $sql = "SELECT nr,date,description,price * 100 AS price FROM sales WHERE paid = 0 AND visible = 1 ORDER BY date,nr";
14 return $this->db->fetchObjectList($sql);
17 public function ajaxSubtotal()
24 foreach ($_POST['nr'] as &$nr)
27 $sql = sprintf("SELECT nr,date,description,price * 100 AS price FROM sales WHERE nr IN (%s) ORDER BY date,nr",
28 implode(', ', $_POST['nr']));
30 foreach ($this->db->fetchObjectList($sql) as $row) {
31 $date = substr ($row->date,6,2) . "." . substr ($row->date,4,2) . "." . substr ($row->date,0,4);
32 $text .= utf8_encode(sprintf("%d %s %-53s %8.2f\n", $row->nr, $date, substr($row->description,0,53), $row->price / 100));
33 $commands .= sprintf("infocon --date %s --pay %d\n", date('Y-m-d', time()+60*60*24), $row->nr);
34 $total += $row->price;
38 $subject = 'Erstattungen';
39 if (strlen($_POST['title']))
40 $subject .= ' ' . $_POST['title'];
42 $text = "Liste der Buchungen\n" . str_repeat('=', 78) . "\n" . $text;
43 $text .= str_repeat('=', 78) . sprintf("\n%-69s %8.2f\n", 'Zwischensumme', $total / 100);
46 $mail->env_from(MAIL_FROM);
47 $mail->set('From', mb_encode_mimeheader(utf8_decode(sprintf("%s <%s>", MAIL_FROM_NAME, MAIL_FROM)),'latin1'));
48 $mail->set('To', MAIL_ERROR);
49 $mail->set('Subject', mb_encode_mimeheader($subject,'latin1'));
50 $mail->send($text . "\n\n" . $commands);
56 public function setPaid()
58 return $this->modify('paid', 1);
61 public function unsetPaid()
63 return $this->modify('paid', 0);
66 public function ajaxEditDescription(Array $data)
68 return $this->modify('description', utf8_decode($data['content']));