View difference between Paste ID: uGTDevzY and 16g2FWPT
SHOW: | | - or go back to the newest paste.
1
<?php
2
  require_once('shops.php');
3-
	require_once('shops.php');
3+
4
5
  $data = file($argv[1]);
6-
	$data = file($argv[1]);
6+
  $sum = array();
7-
	$sum = array();
7+
  
8-
	
8+
  
9-
	
9+
  
10-
	
10+
  foreach($data as $line) {
11-
	foreach($data as $line) {
11+
    parse_entry($sum, $line);
12-
		parse_entry($sum, $line);
12+
  }
13-
	}
13+
  
14-
	
14+
  foreach($sum as $ykey => $yvalue) {
15-
	foreach($sum as $ykey => $yvalue) {
15+
    foreach($yvalue as $mkey => $mvalue) {
16-
		foreach($yvalue as $mkey => $mvalue) {
16+
      ksort($sum[$ykey][$mkey]);
17-
			ksort($sum[$ykey][$mkey]);
17+
    }
18-
		}
18+
  }
19-
	}
19+
  print_r($sum);
20-
	print_r($sum);
20+
  
21-
	
21+
  
22-
	
22+
  function parse_entry(&$sum, $line) {
23-
	function parse_entry(&$sum, $line) {
23+
    $value = split(';', $line);
24-
		$value = split(';', $line);
24+
    
25-
		
25+
    $shop     = parse_customer($value[2]);
26-
		$shop			= parse_customer($value[2]);
26+
    $money    = parse_money(substr($value[3], 1));
27-
		$money 		= parse_money(substr($value[3], 1));
27+
    $month    = substr($value[1], 4, 2);
28-
		$month		= substr($value[1], 4, 2);
28+
    $year     = substr($value[1], 7, 4);
29-
		$year			= substr($value[1], 7, 4);
29+
    
30-
		
30+
    if($shop['include']) {
31-
		if($shop['include']) {
31+
      $sum[$year][$month][$shop['type']]  += $money;
32-
			$sum[$year][$month][$shop['type']] 	+= $money;
32+
      $sum[$year][$month]['TOTAL']        += $money;
33-
			$sum[$year][$month]['TOTAL'] 				+= $money;
33+
    }
34-
		}
34+
35
    if(strstr($shop['type'], 'unknown') !== FALSE) {
36-
		if(strstr($shop['type'], 'unknown') !== FALSE) {
36+
      print_r($value);
37-
			print_r($value);
37+
    }
38-
		}
38+
  }
39-
	}
39+
  
40-
	
40+
  function parse_customer($customer) {
41-
	function parse_customer($customer) {
41+
    global $shops;
42-
		global $shops;
42+
    
43-
		
43+
    $customer = strtolower($customer);
44-
		$customer = strtolower($customer);
44+
45
    foreach($shops as $key => $value) {
46-
		foreach($shops as $key => $value) {
46+
      if(strstr($customer, $key) !== FALSE) {
47-
			if(strstr($customer, $key) !== FALSE) {
47+
        return $value;
48-
				return $value;
48+
      }
49-
			}
49+
    }   
50-
		}		
50+
    
51-
		
51+
    return $shops['unknown'];
52-
		return $shops['unknown'];
52+
  }
53-
	}
53+
  
54-
	
54+
  function parse_money($value) {
55-
	function parse_money($value) {
55+
    
56-
		
56+
    $value = preg_replace('/\\./', '', $value);
57-
		$value = preg_replace('/\\./', '', $value);
57+
    
58-
		
58+
    $value = floatval($value);
59-
		$value = floatval($value);
59+
    if($value < 0) {
60-
		if($value < 0) {
60+
      return $value;
61-
			return $value;
61+
    }
62-
		}
62+
    return 0;
63-
		return 0;
63+
  }
64-
	}
64+
65
66
<?php
67
  $shops = array( 
68-
	$shops = array(	
68+
    'superbest'           => array('name' => 'SuperBest',                           'type' => 'groceries',        'include' => true),
69-
		'superbest' 					=> array('name' => 'SuperBest', 													'type' => 'groceries', 				'include' => true),
69+
    'aldi'                => array('name' => 'Aldi',                                'type' => 'groceries',        'include' => true),
70-
		'aldi' 								=> array('name' => 'Aldi', 																'type' => 'groceries', 				'include' => true),
70+
    'fakta'               => array('name' => 'Fakta',                               'type' => 'groceries',        'include' => true),
71-
		'fakta' 							=> array('name' => 'Fakta', 															'type' => 'groceries', 				'include' => true),
71+
    'lidl'                => array('name' => 'Lidl',                                'type' => 'groceries',        'include' => true),
72-
		'lidl' 								=> array('name' => 'Lidl', 																'type' => 'groceries', 				'include' => true),
72+
    'bilka'               => array('name' => 'Bilka',                               'type' => 'groceries',        'include' => true),
73-
		'bilka' 							=> array('name' => 'Bilka', 															'type' => 'groceries', 				'include' => true),
73+
    'løvbjerg'            => array('name' => 'Løvbjerg',                            'type' => 'groceries',        'include' => true),
74-
		'løvbjerg' 						=> array('name' => 'Løvbjerg', 														'type' => 'groceries', 				'include' => true),
74+
    'føtex'               => array('name' => 'Føtex',                               'type' => 'groceries',        'include' => true),
75-
		'føtex' 							=> array('name' => 'Føtex', 															'type' => 'groceries', 				'include' => true),
75+
    'kvickly'             => array('name' => 'Kvickly',                             'type' => 'groceries',        'include' => true),
76-
		'kvickly'							=> array('name' => 'Kvickly',															'type' => 'groceries', 				'include' => true),
76+
                                                                                    
77-
		            					                                													
77+
    'baresso'             => array('name' => 'Baresso',                             'type' => 'fun',              'include' => true),
78-
		'baresso' 						=> array('name' => 'Baresso', 														'type' => 'fun', 							'include' => true),
78+
    'franck a'            => array('name' => 'Franck A',                            'type' => 'fun',              'include' => true),
79-
		'franck a' 						=> array('name' => 'Franck A', 														'type' => 'fun', 							'include' => true),
79+
    'cuckoo\'s nest'      => array('name' => 'Cuckoo\'s Nest',                      'type' => 'fun',              'include' => true),
80-
		'cuckoo\'s nest' 			=> array('name' => 'Cuckoo\'s Nest', 											'type' => 'fun', 							'include' => true),
80+
    'blomsterland'        => array('name' => 'Blomsterland',                        'type' => 'fun',              'include' => true),
81-
		'blomsterland' 				=> array('name' => 'Blomsterland', 												'type' => 'fun', 							'include' => true),
81+
    'biocity'             => array('name' => 'Biocity',                             'type' => 'fun',              'include' => true),
82-
		'biocity' 						=> array('name' => 'Biocity', 														'type' => 'fun', 							'include' => true),
82+
                                                                                    
83-
		                			                                        									
83+
    'middelfartvej'       => array('name' => 'Svømmehal',                           'type' => 'activities',       'include' => true),
84-
		'middelfartvej'				=> array('name' => 'Svømmehal', 													'type' => 'activities', 			'include' => true),
84+
    'medlem'              => array('name' => 'Gyldendal',                           'type' => 'activities',       'include' => true)
85-
		'medlem'							=> array('name' => 'Gyldendal',														'type' => 'activities', 			'include' => true)
85+
  );
86-
	);
86+
87