Guest User

spiir, light

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