Guest User

Untitled

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