コード例 #1
0
ファイル: cashimport-alior-xml.php プロジェクト: Kliwer/lms
                for ($i = 0; $i < $wplat; $i++) {
                    $xml = xml2array($tmp->{'TRANLIST'}->{'TRANSACTION'}->{$i});
                    if (preg_match($cashimport['date_regexp'], $xml['TRANDT'], $date)) {
                        $unixtime = mktime(0, 0, 0, $date[2], $date[3], $date[1]);
                    } else {
                        $unixtime = time();
                    }
                    $cash[] = array('cid' => intval(substr($xml['MPTID'], '-8')), 'date' => $xml['TRANDT'], 'unixtime' => $unixtime, 'account' => $xml['MPTID'], 'value' => str_replace(',', '.', trim($xml['AMT'] / 100)), 'sendname' => cp1250_to_utf8($xml['SNDNAME']), 'title' => cp1250_to_utf8($xml['TITLE']), 'sourcefileid' => $sourcefileid);
                }
            }
        }
        if (!empty($cash)) {
            for ($j = 0; $j < sizeof($cash); $j++) {
                $hash = md5($cash[$j]['cid'] . $cash[$j]['unixtime'] . $cash[$j]['value'] . $cash[$j]['sendname'] . $cash[$j]['title']);
                $customerid = $DB->getOne('SELECT id FROM customers WHERE id = ? LIMIT 1;', array($cash[$j]['cid']));
                $DB->Execute('INSERT INTO cashimport (date, value, customer, customerid, description, hash, sourceid, sourcefileid) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ;', array($cash[$j]['unixtime'], $cash[$j]['value'], $cash[$j]['sendname'], $customerid, $cash[$j]['title'], $hash, NULL, $cash[$j]['sourcefileid']));
                $cashid = $DB->GetLastInsertId('cashimport');
                if ($customerid) {
                    $balance = array('time' => $cash[$j]['unixtime'], 'userid' => 0, 'value' => $cash[$j]['value'], 'type' => 1, 'taxid' => 0, 'customerid' => $customerid, 'comment' => $cash[$j]['sendname'] . '<br>' . $cash[$j]['title'], 'docid' => 0, 'itemid' => 0, 'importid' => $cashid, 'sourceid' => $cash[$j]['sourcefileid']);
                    if ($LMS->addBalance($balance)) {
                        $DB->Execute('UPDATE cashimport SET closed = 1  WHERE id = ? ;', array($cashid));
                    }
                    $balance = $LMS->getcustomerbalance($customerid);
                    if ($balance >= 0) {
                        $DB->Execute('UPDATE nodes SET warning = 0, blockade = 0 WHERE ownerid = ? ;', array($customerid));
                    }
                }
            }
        }
    }
}