diff --git a/application/classes/lnapp/sort.php b/application/classes/lnapp/sort.php index 7fe62591..c490f054 100644 --- a/application/classes/lnapp/sort.php +++ b/application/classes/lnapp/sort.php @@ -25,81 +25,77 @@ class lnApp_Sort { if (! $data) return; - static $MASORT_CACHE = array(); - - if (empty($MASORT_CACHE[$sortby])) { - $code = "\$c=0;\n"; - - foreach (explode(',',$sortby) as $key) { - $code .= "if (is_object(\$a) || is_object(\$b)) {\n"; - - $code .= " if (is_array(\$a->$key)) {\n"; - $code .= " asort(\$a->$key);\n"; - $code .= " \$aa = array_shift(\$a->$key);\n"; - $code .= " } else\n"; - $code .= " \$aa = \$a->$key;\n"; - - $code .= " if (is_array(\$b->$key)) {\n"; - $code .= " asort(\$b->$key);\n"; - $code .= " \$bb = array_shift(\$b->$key);\n"; - $code .= " } else\n"; - $code .= " \$bb = \$b->$key;\n"; - - $code .= " if (\$aa != \$bb)"; - if ($rev) - $code .= " return (\$aa < \$bb ? 1 : -1);\n"; - else - $code .= " return (\$aa > \$bb ? 1 : -1);\n"; - - $code .= "} else {\n"; - - $code .= " \$a = array_change_key_case(\$a);\n"; - $code .= " \$b = array_change_key_case(\$b);\n"; - - $key = strtolower($key); - - $code .= " if ((! isset(\$a['$key'])) && isset(\$b['$key'])) return 1;\n"; - $code .= " if (isset(\$a['$key']) && (! isset(\$b['$key']))) return -1;\n"; - - $code .= " if ((isset(\$a['$key'])) && (isset(\$b['$key']))) {\n"; - $code .= " if (is_array(\$a['$key'])) {\n"; - $code .= " asort(\$a['$key']);\n"; - $code .= " \$aa = array_shift(\$a['$key']);\n"; - $code .= " } else\n"; - $code .= " \$aa = \$a['$key'];\n"; - - $code .= " if (is_array(\$b['$key'])) {\n"; - $code .= " asort(\$b['$key']);\n"; - $code .= " \$bb = array_shift(\$b['$key']);\n"; - $code .= " } else\n"; - $code .= " \$bb = \$b['$key'];\n"; - - $code .= " if (\$aa != \$bb)\n"; - $code .= " if (is_numeric(\$aa) && is_numeric(\$bb)) {\n"; - - if ($rev) - $code .= " return (\$aa < \$bb ? 1 : -1);\n"; - else - $code .= " return (\$aa > \$bb ? 1 : -1);\n"; - - $code .= " } else {\n"; - - if ($rev) - $code .= " if ( (\$c = strcasecmp(\$bb,\$aa)) != 0 ) return \$c;\n"; - else - $code .= " if ( (\$c = strcasecmp(\$aa,\$bb)) != 0 ) return \$c;\n"; - - $code .= " }\n"; - $code .= " }\n"; - $code .= "}\n"; - } - - $code .= 'return $c;'; - - $MASORT_CACHE[$sortby] = create_function('$a, $b',$code); + $code = "\$c=0;\n"; + + foreach (explode(',',$sortby) as $key) { + $code .= "if (is_object(\$a) || is_object(\$b)) {\n"; + + $code .= " if (is_array(\$a->$key)) {\n"; + $code .= " asort(\$a->$key);\n"; + $code .= " \$aa = array_shift(\$a->$key);\n"; + $code .= " } else\n"; + $code .= " \$aa = \$a->$key;\n"; + + $code .= " if (is_array(\$b->$key)) {\n"; + $code .= " asort(\$b->$key);\n"; + $code .= " \$bb = array_shift(\$b->$key);\n"; + $code .= " } else\n"; + $code .= " \$bb = \$b->$key;\n"; + + $code .= " if (\$aa != \$bb)"; + if ($rev) + $code .= " return (\$aa < \$bb ? 1 : -1);\n"; + else + $code .= " return (\$aa > \$bb ? 1 : -1);\n"; + + $code .= "} else {\n"; + + $code .= " \$a = array_change_key_case(\$a);\n"; + $code .= " \$b = array_change_key_case(\$b);\n"; + + $key = strtolower($key); + + $code .= " if ((! isset(\$a['$key'])) && isset(\$b['$key'])) return 1;\n"; + $code .= " if (isset(\$a['$key']) && (! isset(\$b['$key']))) return -1;\n"; + + $code .= " if ((isset(\$a['$key'])) && (isset(\$b['$key']))) {\n"; + $code .= " if (is_array(\$a['$key'])) {\n"; + $code .= " asort(\$a['$key']);\n"; + $code .= " \$aa = array_shift(\$a['$key']);\n"; + $code .= " } else\n"; + $code .= " \$aa = \$a['$key'];\n"; + + $code .= " if (is_array(\$b['$key'])) {\n"; + $code .= " asort(\$b['$key']);\n"; + $code .= " \$bb = array_shift(\$b['$key']);\n"; + $code .= " } else\n"; + $code .= " \$bb = \$b['$key'];\n"; + + $code .= " if (\$aa != \$bb)\n"; + $code .= " if (is_numeric(\$aa) && is_numeric(\$bb)) {\n"; + + if ($rev) + $code .= " return (\$aa < \$bb ? 1 : -1);\n"; + else + $code .= " return (\$aa > \$bb ? 1 : -1);\n"; + + $code .= " } else {\n"; + + if ($rev) + $code .= " if ( (\$c = strcasecmp(\$bb,\$aa)) != 0 ) return \$c;\n"; + else + $code .= " if ( (\$c = strcasecmp(\$aa,\$bb)) != 0 ) return \$c;\n"; + + $code .= " }\n"; + $code .= " }\n"; + $code .= "}\n"; } + + $code .= 'return $c;'; + + $result = create_function('$a, $b',$code); - uasort($data,$MASORT_CACHE[$sortby]); + uasort($data,$result); } } ?> diff --git a/modules/statement/classes/controller/statement.php b/modules/statement/classes/controller/statement.php new file mode 100644 index 00000000..eba89708 --- /dev/null +++ b/modules/statement/classes/controller/statement.php @@ -0,0 +1,15 @@ + diff --git a/modules/statement/classes/controller/user/statement.php b/modules/statement/classes/controller/user/statement.php new file mode 100644 index 00000000..f161c9cb --- /dev/null +++ b/modules/statement/classes/controller/user/statement.php @@ -0,0 +1,84 @@ +TRUE, + ); + + /** + * Show a payments received + */ + public function action_show() { + $ta = array(); + + foreach ($this->ao->payment->find_all() as $o) { + $i = count($ta); + $ta[$i]['time'] = $o->date_payment; + $ta[$i]['payment'] = $o; + } + + foreach ($this->ao->invoice->find_all() as $o) { + $i = count($ta); + $ta[$i]['time'] = $o->date_orig; + $ta[$i]['invoice'] = $o; + } + + Sort::MAsort($ta,'time'); + + $t = 0; + $a = 0; + foreach ($ta as $k => $v) { + // If 2 metrics have the same time, we need to increment 1 by a small number so that it doesnt affect the next sorting + if ($a == $v['time']) { + $ta[$k]['time'] += 1; + } + + if (isset($v['invoice'])) + $t += $v['invoice']->total_amt; + elseif (isset($v['payment'])) + $t -= $v['payment']->total_amt; + + $ta[$k]['total'] = $t; + $a = $v['time']; + } + + Sort::MAsort($ta,'time',1); + + $pag = new Pagination(array( + 'total_items'=>count($ta), + )); + + $output = (string)$pag; + $output .= View::factory('statement/user/show_head'); + + $i = 0; + foreach ($ta as $k => $v) { + if (++$i < $pag->current_first_item()) + continue; + elseif ($i > $pag->current_last_item()) + break; + + $output .= View::factory('statement/user/show_body') + ->set('o',$v) + ->set('trc',$i%2 ? 'odd' : 'even'); + } + + $output .= View::factory('statement/user/show_foot'); + + Block::add(array( + 'title'=>sprintf('%s: %s - %s',_('Transaactions For'),$this->ao->accnum(),$this->ao->name(TRUE)), + 'body'=>$output, + )); + } +} +?> diff --git a/modules/statement/views/statement/user/show_body.php b/modules/statement/views/statement/user/show_body.php new file mode 100644 index 00000000..c9ae2879 --- /dev/null +++ b/modules/statement/views/statement/user/show_body.php @@ -0,0 +1,14 @@ + + + display('date_orig'); ?> + Invoice + id,$o['invoice']->id()); ?> + display('total_amt'); ?> + + display('date_payment'); ?> + Payment + checkout->display('name'); ?> + display('total_amt'); ?> + + + diff --git a/modules/statement/views/statement/user/show_foot.php b/modules/statement/views/statement/user/show_foot.php new file mode 100644 index 00000000..000ca4b0 --- /dev/null +++ b/modules/statement/views/statement/user/show_foot.php @@ -0,0 +1 @@ + diff --git a/modules/statement/views/statement/user/show_head.php b/modules/statement/views/statement/user/show_head.php new file mode 100644 index 00000000..8956570f --- /dev/null +++ b/modules/statement/views/statement/user/show_head.php @@ -0,0 +1,7 @@ + + + + + + +
DateTypeAmtTotal