From cf0f0111776d1cb93e33df3428a7f323f5a0454a Mon Sep 17 00:00:00 2001 From: Maxime Bourget Date: Sat, 1 Jun 2013 12:14:14 +0100 Subject: [PATCH] Extract misc classes into relevant files. --- haxe/FA.hx | 14 +++++++ haxe/ItemScheduler.hx | 87 ------------------------------------------- haxe/QueryIterator.hx | 33 ++++++++++++++++ 3 files changed, 47 insertions(+), 87 deletions(-) create mode 100644 haxe/FA.hx create mode 100644 haxe/QueryIterator.hx diff --git a/haxe/FA.hx b/haxe/FA.hx new file mode 100644 index 0000000..1de6e1c --- /dev/null +++ b/haxe/FA.hx @@ -0,0 +1,14 @@ +class FA { + static public function query(sql: String) { + var result = untyped __call__('db_query', sql, sql); + return new QueryIterator(result); + } + + static public function tb() : String { + return untyped __php__('TB_PREF'); + } + + static public function sql2date(sqlDate:Dynamic) : Null { + return sqlDate == null ? null : Date.fromString(sqlDate); + } +} diff --git a/haxe/ItemScheduler.hx b/haxe/ItemScheduler.hx index be596ac..e5b5396 100644 --- a/haxe/ItemScheduler.hx +++ b/haxe/ItemScheduler.hx @@ -1,52 +1,5 @@ import php.Lib; -enum Maybe { - Nothing; - Just(v : T); -} - -class QueryIterator { - var result : Dynamic; - var nextValue : Maybe; - public function new(result) { - this.result= result; - /* We fetch the first row , so we can answer hasNext */ - fetch(); - } - - private function fetch() { - var next : Dynamic = untyped __call__('db_fetch', this.result); - nextValue = if(next) Just(next) else Nothing; - } - - public function hasNext() : Bool { - return this.nextValue != Nothing; - } - - public function next() : T { - switch(this.nextValue) { - case Nothing : throw 'Iterator exhausted'; - case Just(v) : { - this.fetch(); - return v; - }; - } - } -} -class FA { - static public function query(sql: String) { - var result = untyped __call__('db_query', sql, sql); - return new QueryIterator(result); - } - - static public function tb() : String { - return untyped __php__('TB_PREF'); - } - - static public function sql2date(sqlDate:Dynamic) : Null { - return sqlDate == null ? null : Date.fromString(sqlDate); - } -} class ItemScheduler { var stock_id:String; var startLocation:String; @@ -61,17 +14,6 @@ class ItemScheduler { return ["Order", "Customer", "Quantity", "Before", "After", "Loc", "From", "Required Date", "Comment"]; } -/* - function generateTablex(): Void { - for(location in locations()) { - formatLocation(location, null); - } - for(order in this.orders()) { - this.formatRow(order); - } - } -*/ - function generateTable(): Void { var startDate = Date.fromTime(0); for(order in orders()) { @@ -174,35 +116,6 @@ class ItemScheduler { } - function formatRow(row) { - var array = php.Lib.hashOfAssociativeArray(row); - var quantity_before : Int = array.get('quantity_before'); - var quantity_available = qoh - quantity_before; - var quantity: Int = array.get('quantity'); - - var status : String = if(quantity_available < quantity) 'overduebg'; - - var cells : Array = [ - array.get('order_id') - ,array.get('deliver_to') - ,''+quantity+'' - ,quantity_available-quantity - ,quantity_available - ,array.get('from_stk_loc') - ,array.get('delivery_date') - ]; - - php.Lib.print(''); - for(cell in cells) { - php.Lib.print(''); - php.Lib.print(cell); - php.Lib.print(''); - } - php.Lib.print(''); - - - } - function formatLocation(location : Location, type: String, left : Int) { var cells = [ type diff --git a/haxe/QueryIterator.hx b/haxe/QueryIterator.hx new file mode 100644 index 0000000..5eec9aa --- /dev/null +++ b/haxe/QueryIterator.hx @@ -0,0 +1,33 @@ +enum Maybe { + Nothing; + Just(v : T); +} + +class QueryIterator { + var result : Dynamic; + var nextValue : Maybe; + public function new(result) { + this.result= result; + /* We fetch the first row , so we can answer hasNext */ + fetch(); + } + + private function fetch() { + var next : Dynamic = untyped __call__('db_fetch', this.result); + nextValue = if(next) Just(next) else Nothing; + } + + public function hasNext() : Bool { + return this.nextValue != Nothing; + } + + public function next() : T { + switch(this.nextValue) { + case Nothing : throw 'Iterator exhausted'; + case Just(v) : { + this.fetch(); + return v; + }; + } + } +} -- 2.30.2