
Object.extend(String.English,{});Stonehill=SC.Object.create({server:SC.Server.create({prefix:['Stonehill']}),FIXTURES:[]});require('core');Stonehill.DocumentItems=SC.Record.extend({total:function(){var unrounded=parseFloat(this.get('unitprice'))*parseFloat(this.get('quantity'));return unrounded.toFixed(2);}.property('unitprice','quantity')});function main(){Stonehill.server.preload(Stonehill.FIXTURES);SC.page.awake();var records=Stonehill.DocumentItems.collection();Stonehill.documentItemsController.set('content',records);records.refresh();};require('core');Stonehill.Addressbook=SC.Record.extend({});require('core');Stonehill.invoiceController=SC.ObjectController.create({dated:'21 July 2008',due:'21 August 2008',billTo:null,shipTo:null,status:null,notes:null,shipping:0.00,stateTaxPercent:0,federalTaxPercent:5,paid:0.00,invoiceNumber:1,hideTaxPicker:function(){SC.page.taxPicker.set('isVisible',false);},showPreview:function(){alert("A preview will be shown");},untaxedSubtotal:function(){var allItems=Stonehill.documentItemsController.arrangedObjects;var i=0;var total=0;for(i=0;i<allItems.length;i++){if(allItems[i].get('taxable')!='Yes'){total+=parseFloat(allItems[i].get('total'));}}
return total;},taxedSubtotal:function(){var allItems=Stonehill.documentItemsController.arrangedObjects;var i=0;var total=0;for(i=0;i<allItems.length;i++){if(allItems[i].get('taxable')=='Yes'){total+=parseFloat(allItems[i].get('total'));}}
return total;},subtotal:function(){var unrounded=this.taxedSubtotal()+this.untaxedSubtotal();return unrounded.toFixed(2);}.property(),stateTax:function(){var unrounded=((this.taxedSubtotal()*this.stateTaxPercent)/100);return unrounded.toFixed(2);}.property('stateTaxPercent'),federalTax:function(){var unrounded=((this.taxedSubtotal()*this.federalTaxPercent)/100);return unrounded.toFixed(2);}.property('federalTaxPercent'),shippingFloatValue:function(){var unrounded=parseFloat(this.shipping);if(!unrounded){unrounded=0;}
return unrounded.toFixed(2);},paidFloatValue:function(){var unrounded=parseFloat(this.paid);if(!unrounded){unrounded=0;}
return unrounded.toFixed(2);},balance:function(){var balance=parseFloat(this.subtotal())+parseFloat(this.stateTax())+parseFloat(this.federalTax())+parseFloat(this.shippingFloatValue())-parseFloat(this.paidFloatValue());return balance.toFixed(2);}.property('subtotal','shipping','paid'),invoiceLongName:function(){return"Invoice "+this.invoiceNumber;}.property('invoiceNumber'),recalculateTotals:function(){this.set('subtotal','');this.set('stateTax','');this.set('federalTax','');}});require('core');Stonehill.Invoice=SC.Record.extend({shippingCost:'0.00'});require('core');Stonehill.previewController=SC.Object.create({showPreview:function(){SC.page.get('preview').set('isVisible',YES);this.generatePreview();},hidePreview:function(){SC.page.get('preview').set('isVisible',NO);},generatePreview:function(){var invoiceData="<H1>INVOICE</H1>";var header="<p />Invoice "+Stonehill.invoiceController.invoiceNumber+"<br />Dated: "+Stonehill.invoiceController.dated+"<br />Due: "+Stonehill.invoiceController.due;var billing="";if(Stonehill.invoiceController.billTo!=null){billing="<p />To:<br />"+Stonehill.invoiceController.billTo.replace(/\n/g,"<br />");}
var table="<table border=\"1\" width=\"100%\" cellpadding=\"2\"><tr><td><b>Quantity</b></td><td><b>Item</b></td><td><b>Description</b></td><td><b>Tax</b></td><td><b>Unit Price</b></td><td><b>Total</b></td></tr>";var allItems=Stonehill.documentItemsController.arrangedObjects;var i=0;for(i=0;i<allItems.length;i++){table=table+"<tr><td>"+allItems[i].get('quantity')+"</td><td>"+allItems[i].get('name')+"</td><td>"+allItems[i].get('description')+"</td><td>"+allItems[i].get('taxable')+"</td><td>"+allItems[i].get('unitprice')+"</td><td>"+allItems[i].get('total')+"</td></tr>";}
table=table+"<tr><td colspan=\"5\" align=\"right\">Subtotal</td><td align=\"right\">"+Stonehill.invoiceController.subtotal()+"</td></tr>";table=table+"<tr><td colspan=\"5\" align=\"right\">Shipping</td><td align=\"right\">"+Stonehill.invoiceController.shipping+"</td></tr>";table=table+"<tr><td colspan=\"5\" align=\"right\">State Tax</td><td align=\"right\">"+Stonehill.invoiceController.stateTax()+"</td></tr>";table=table+"<tr><td colspan=\"5\" align=\"right\">Federal Tax</td><td align=\"right\">"+Stonehill.invoiceController.federalTax()+"</td></tr>";table=table+"<tr><td colspan=\"5\" align=\"right\">Paid</td><td align=\"right\">"+Stonehill.invoiceController.paid+"</td></tr>";table=table+"<tr><td colspan=\"5\" align=\"right\">Balance</td><td align=\"right\">"+Stonehill.invoiceController.balance()+"</td></tr>";table=table+"</table>";var notes="";if(Stonehill.invoiceController.notes!=null){notes="<p />"+Stonehill.invoiceController.notes;}
SC.page.get('previewText').set('innerHTML',invoiceData+header+billing+table+notes);}});require('core');Stonehill.documentItemsController=SC.CollectionController.create({canEditCollection:YES,addItem:function(){var newObj=this.newObject();newObj.set('quantity','1');newObj.set('unitprice','0.00');newObj.set('taxable','No');},removeItem:function(){this.get('content').remove(0);},debugMethod:function(){alert(this.content);}});require('core');Stonehill.addressbookController=SC.Object.create({showAddressEditor:function(){SC.page.get('addressEditor').set('isVisible',YES);},hideAddressEditor:function(){SC.page.get('addressEditor').set('isVisible',NO);}});