diff --git a/application/IvtBill/IvtBill.php b/application/IvtBill/IvtBill.php new file mode 100644 index 000000000..3523e4b97 --- /dev/null +++ b/application/IvtBill/IvtBill.php @@ -0,0 +1,35 @@ +log = mfLoghandler::singleton(); + $this->table = get_class($this); + $this->data = new stdClass(); + $this->table = "bills"; + + $this->db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + if(is_numeric($_)) { + $this->fetch($_); + } elseif(is_object($_)) { + $this->load($_); + } + } + + public function save() { + throw new Exception("Cannot save Ivt Bills"); + } + + public function __debugInfo() { + $vars = get_object_vars($this); + if(is_object($vars['db'])) $vars['db'] = "object(FronkDB)"; + if(is_object($vars['log'])) $vars['log'] = 'object(mfLoghandler)'; + return $vars; + } + +} \ No newline at end of file diff --git a/application/IvtBill/IvtBillModel.php b/application/IvtBill/IvtBillModel.php new file mode 100644 index 000000000..3a031606b --- /dev/null +++ b/application/IvtBill/IvtBillModel.php @@ -0,0 +1,113 @@ +select("bills", "*", "1=1 ORDER BY id"); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new IvtBill($data); + } + } + return $items; + } + + public static function getFirst($filter = []) { + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + $where = self::getSqlFilter($filter); + $res = $db->select("bills", "*", "$where ORDER BY id LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new IvtBill($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function getLast($filter = []) { + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + $where = self::getSqlFilter($filter); + $res = $db->select("bills", "*", "$where ORDER BY id DESC LIMIT 1"); + if($db->num_rows($res)) { + $data = $db->fetch_object($res); + $item = new IvtBill($data); + if($item->id) { + return $item; + } else { + return null; + } + } + return null; + } + + public static function search($filter, $limit = false) { + $items = []; + $db = FronkDB::singleton(IVT_DBHOST, IVT_DBUSER, IVT_DBPASS, IVT_DBNAME); + + $where = self::getSqlFilter($filter); + $sql = "SELECT * FROM bills $where ORDER by id"; + + mfLoghandler::singleton()->debug($sql); + if(is_array($limit) && count($limit)) { + if(is_numeric($limit['start']) && is_numeric($limit['count'])) { + $sql .= " LIMIT ".$limit['start'].", ".$limit['count']; + } elseif(is_numeric($count)) { + $sql .= " LIMIT ".$limit['count']; + } + } + + $res = $db->query($sql); + if($db->num_rows($res)) { + while($data = $db->fetch_object($res)) { + $items[] = new IvtBill($data); + } + } + return $items; + } + + private static function getSqlFilter($filter) { + $where = "1=1 "; + + if(array_key_exists("cid", $filter)) { + $cid = $filter['cid']; + if(is_numeric($cid)) { + $where .= " AND bills.cid=$cid"; + } + } + + /* + if(array_key_exists("status_id", $filter)) { + $status_id = $filter['status_id']; + if(is_numeric($status_id)) { + $where .= " AND IvtBill.status_id=$status_id"; + } + } + + + if(array_key_exists("street", $filter)) { + $street = FronkDB::singleton()->escape($filter["street"]); + if($street) { + $where .= " AND street like '%$street%'"; + } + } + */ + + //var_dump($filter, $where);exit; + return $where; + } + +} diff --git a/scripts/import-sepa-date-from-ivt.php b/scripts/import-sepa-date-from-ivt.php new file mode 100755 index 000000000..e27056c6e --- /dev/null +++ b/scripts/import-sepa-date-from-ivt.php @@ -0,0 +1,45 @@ +#!/usr/bin/php +id); +define("INTERNAL_USER_USERNAME", $me->username); + +$i = 0; +foreach(AddressModel::search(["customer_number" => true, "billing_type" => "sepa"]) as $address) { + if($address->sepa_date) continue; + + $bill = IvtBillModel::getFirst(["cid" => $address->customer_number]); + if(!$bill) continue; + + if(!trim($bill->IBAN) || !trim($bill->BIC)) continue; + + if(!$bill->date_outgoing) { + echo "date outgoing fehlt im ivt: ".$address->customer_number."\n"; + continue; + } + + $out_date = new DateTime($bill->date_outgoing); + $sepa_date = $out_date->getTimestamp(); + echo "$sepa_date - ".$bill->date_outgoing."\n"; + + if(!$sepa_date){ + echo "Konnte Datum nicht umwandeln\n"; + } + + $address->sepa_date = $sepa_date; + $address->save(); + $i++; +} + +echo "Updated $i addresses\n\n"; \ No newline at end of file