Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('shops.php');
- $data = file($argv[1]);
- $sum = array();
- foreach($data as $line) {
- parse_entry($sum, $line);
- }
- foreach($sum as $ykey => $yvalue) {
- foreach($yvalue as $mkey => $mvalue) {
- ksort($sum[$ykey][$mkey]);
- }
- }
- print_r($sum);
- function parse_entry(&$sum, $line) {
- $value = split(';', $line);
- $shop = parse_customer($value[2]);
- $money = parse_money(substr($value[3], 1));
- $month = substr($value[1], 4, 2);
- $year = substr($value[1], 7, 4);
- if($shop['include']) {
- $sum[$year][$month][$shop['type']] += $money;
- $sum[$year][$month]['TOTAL'] += $money;
- }
- if(strstr($shop['type'], 'unknown') !== FALSE) {
- print_r($value);
- }
- }
- function parse_customer($customer) {
- global $shops;
- $customer = strtolower($customer);
- foreach($shops as $key => $value) {
- if(strstr($customer, $key) !== FALSE) {
- return $value;
- }
- }
- return $shops['unknown'];
- }
- function parse_money($value) {
- $value = preg_replace('/\\./', '', $value);
- $value = floatval($value);
- if($value < 0) {
- return $value;
- }
- return 0;
- }
- ?>
- <?php
- $shops = array(
- 'superbest' => array('name' => 'SuperBest', 'type' => 'groceries', 'include' => true),
- 'aldi' => array('name' => 'Aldi', 'type' => 'groceries', 'include' => true),
- 'fakta' => array('name' => 'Fakta', 'type' => 'groceries', 'include' => true),
- 'lidl' => array('name' => 'Lidl', 'type' => 'groceries', 'include' => true),
- 'bilka' => array('name' => 'Bilka', 'type' => 'groceries', 'include' => true),
- 'løvbjerg' => array('name' => 'Løvbjerg', 'type' => 'groceries', 'include' => true),
- 'føtex' => array('name' => 'Føtex', 'type' => 'groceries', 'include' => true),
- 'kvickly' => array('name' => 'Kvickly', 'type' => 'groceries', 'include' => true),
- 'baresso' => array('name' => 'Baresso', 'type' => 'fun', 'include' => true),
- 'franck a' => array('name' => 'Franck A', 'type' => 'fun', 'include' => true),
- 'cuckoo\'s nest' => array('name' => 'Cuckoo\'s Nest', 'type' => 'fun', 'include' => true),
- 'blomsterland' => array('name' => 'Blomsterland', 'type' => 'fun', 'include' => true),
- 'biocity' => array('name' => 'Biocity', 'type' => 'fun', 'include' => true),
- 'middelfartvej' => array('name' => 'Svømmehal', 'type' => 'activities', 'include' => true),
- 'medlem' => array('name' => 'Gyldendal', 'type' => 'activities', 'include' => true)
- );
- ?>
Advertisement
Add Comment
Please, Sign In to add comment