Changeset 2082359
- Timestamp:
- 05/07/2019 11:41:51 AM (7 years ago)
- File:
-
- 1 edited
-
expert-invoice/trunk/js/viewmodel.min.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
expert-invoice/trunk/js/viewmodel.min.js
r2080123 r2082359 1 1 2 var fdate=moment().format("YYYY-MM-DD");function Model(){var a=this;this.isViewVisible=ko.observable(true);this.exempt=[];this.afterReset=function(){};this.afterSetData=function(){};this.isValid=function(){return a.errors?a.errors().length==0:true};this.makeValidatable=function(){a.errors=ko.validation.group(a)};this.postErrors=function(b){if(b){postNotice("Please fix all errors","error")}ko.utils.arrayForEach(a.errors(),function(c){});a.errors.showAllMessages()};this.reset=function(b){b=b||[];for(var c in a){if(b.indexOf(c)<0){if(ko.isWriteableObservable(a[c])){if("push" in a[c]){a[c]([])}else{a[c](undefined)}}}}if(a.errors){a.errors.showAllMessages(false)}a.afterReset()};this.setData=function(e){var b=[];c=c||{};for(var d in a){if(ko.isWriteableObservable(a[d])){b.push(d)}}var c={include:b};ko.mapping.fromJS(e,c,a);a.afterSetData()};this._json=function(){var b=a.exempt||[];b.push("isViewVisible");b.push("errors");b.push("exempt");b.push("urls");for(var c in a){if(ko.isPureComputed(a[c])){b.push(c)}}return ko.mapping.toJS(a,{ignore:b})};this.json=function(){return a._json()}}function ViewModel(){Model.call(this);var a=this;this.urls=["",""];this.isNewRecord=function(){return !(a.hasOwnProperty("id")&&a.id())};this.getTimeOut=function(){return 0};this.beforeSend=function(){return true};this.beforeSave=function(){return true};this.save=function(c,b){if(a.beforeSave()){a._save(c,b)}};this.afterSave=function(b){};this._save=function(d,c){c=c||true;if(c&&!a.isValid()){a.postErrors(true);return}var b={};if(a.isNewRecord()){b.url="admin-ajax.php?action="+global.ajaxAction+"&r="+a.urls[0]}else{b.url="admin-ajax.php?action="+global.ajaxAction+"&r="+a.urls[1]+"&id="+a.id()}b.data=jQuery.parseJSON(ko.mapping.toJSON(a.json()));delete b.data.id;b.type="post";b.dataType="json";if(a.getTimeOut()>0){b.timeout=a.getTimeOut()}b.success=function(e,g,f){if(e.code=="200"){if(e.id&&a.id){a.id(e.id);a.afterSave(e)}if(d){d(e.message)}else{postNotice(e.message)}}else{postNotice(e.message,"error")}};b.error=function(e,g,f){errorMessage(e,g,f)};if(a.beforeSend()){var b=jQuery.extend({type:"post",dataType:"json"},b,{});jQueryAjax(b)}}}function Customer(){ViewModel.call(this);var a=this;this.urls=["customer/create","customer/update"];this.id=ko.observable();this.name=ko.observable().extend({required:true});this.contactPerson=ko.observable();this.email=ko.observable().extend({email:true});this.telephone1=ko.observable();this.telephone2=ko.observable();this.isActive=ko.observable(1).extend({type:"boolean"});this.shippingAddress=ko.observable();this.notes=ko.observable();this.isTaxExempt=ko.observable().extend({type:"boolean"});this.categoryId=ko.observable().extend({required:true});this.createCategory=function(){bootbox.prompt("Enter the new category name",function(b){if(b){var c=new CustomerCategory();c.name(b);c.save(function(){jQuery("#category_select").append(jQuery("<option>",{value:c.id(),text:c.name(),selected:"selected"})).trigger("change")});global.controller.pageReload=true}})}}function CustomerCategory(){ViewModel.call(this);var a=this;this.urls=["customerCategory/create","customerCategory/update"];this.id=ko.observable();this.name=ko.observable().extend({required:true});this.description=ko.observable()}function Payment(){ViewModel.call(this);var a=this;this.urls=["payment/create","payment/update"];this.exempt=["invoice"];this.id=ko.observable();this.invoice=ko.observable();this.invoiceId=ko.observable().extend({required:true});this.datePaid=ko.observable().extend({required:true});this.amount=ko.observable().extend({required:true});this.paymentMethod=ko.observable().extend({required:true});this.transactionCode=ko.observable().extend({required:true})}function Product(){ViewModel.call(this);var a=this;this.urls=["product/create","product/update"];this.id=ko.observable();this.name=ko.observable().extend({required:true});this.sku=ko.observable().extend({required:true});this.salePrice=ko.observable().extend({required:true});this.taxId=ko.observable().extend({required:true});this.isManaged=ko.observable().extend({type:"boolean"});this.quantity=ko.observable().extend({required:{onlyIf:function(){return a.isManaged()}}});this.warnQuantity=ko.observable().extend({required:{onlyIf:function(){return a.isManaged()}}});this.description=ko.observable();this.genID=function(){if(a.sku()){if(!window.confirm("Item already has an sku. Are you sure you want to generate a new sku?")){return}}var b={};b.url="admin-ajax.php?action="+global.ajaxAction+"&r=product/generateId";b.type="get";b.dataType="json";b.success=function(d,e,c){if(d.code=="200"){a.sku(d.genID)}else{postNotice(d.message,"error")}};b.error=function(c,e,d){errorMessage(c,e,d)};jQueryAjax(b)};this.createCategory=function(){bootbox.prompt("Enter the new category name",function(b){if(b){var c=new CustomerCategory();c.name(b);c.save(function(){jQuery("#category_select").append(jQuery("<option>",{value:c.id(),text:c.name(),selected:"selected"})).trigger("change")});global.controller.pageReload=true}})}}function Tax(){ViewModel.call(this);var a=this;this.urls=["tax/create","tax/update"];this.id=ko.observable();this.name=ko.observable().extend({required:true});this.rate=ko.observable().extend({required:true});this.description=ko.observable()}function OptionModel(){ViewModel.call(this);var a=this;this.urls=["option/create","option/update"];this.exempt=[];this.id=ko.observable();this.invoiceStartNumber=ko.observable().extend({required:true,number:true});this.successPage=ko.observable().extend({required:true});this.paymentPage=ko.observable().extend({required:true});this.name=ko.observable().extend({required:true});this.email=ko.observable();this.registeredNumber=ko.observable();this.contactDetails=ko.observable();this.logo=ko.observable();this.taxIncluded=ko.observable(1).extend({type:"boolean"});this.currency=ko.observable().extend({required:true});this.footerComment=ko.observable();this.footerCommentAlignment=ko.observable();this.footerCommentFontSize=ko.observable();this.receiptTitle=ko.observable();this.refundTitle=ko.observable();this.quantityColumn=ko.observable();this.descriptionColumn=ko.observable();this.unitPriceColumn=ko.observable();this.discountColumn=ko.observable();this.lineTotalColumn=ko.observable();this.transactionNumber=ko.observable();this.issueDate=ko.observable();this.issueTime=ko.observable();this.salesPerson=ko.observable();this.subTotal=ko.observable();this.totalAmount=ko.observable();this.amountTendered=ko.observable();this.change=ko.observable();this.invoiceDueDate=ko.observable();this.quoteDueDate=ko.observable();this.transactionReference=ko.observable();this.refundNumber=ko.observable();this.decimalSymbol=ko.observable().extend({required:true});this.dateFormat=ko.observable().extend({required:true});this.thousandsSymbol=ko.observable().extend({required:true});this.roles=ko.observableArray([]);this.prop=ko.observable();this.propValue=ko.observable();this.prop.subscribe(function(b){a.propValue(a[b]())});this.propValue.subscribe(function(b){a[a.prop()](b)});this.setIFileName=function(b){a.logo(b)};this.update=function(){a.save(function(b){postNotice(b)})}}function Refund(){ViewModel.call(this);var a=this;this.urls=["refund/create","refund/update"];this.exempt=["invoice"];this.id=ko.observable();this.invoice=ko.observable();this.invoiceId=ko.observable().extend({required:true});this.amount=ko.observable().extend({required:true});this.refundDate=ko.observable(fdate).extend({required:true});this.reference=ko.observable().extend({required:true});this.paymentMethod=ko.observable().extend({required:true})}function Invoice(){ViewModel.call(this);var a=this;this.urls=["invoice/create","invoice/update"];this.exempt=["discountType","customerName","customerAddress","isCustomerTaxExempt","type","status","salesPerson","totalPaid"];this.id=ko.observable();this.type=ko.observable(1);this.receiptNumber=ko.observable().extend({required:{onlyIf:function(){return a.type()==1}}});this.title=ko.observable().extend({required:true});this.customerId=ko.observable().extend({required:true});this.termsDays=ko.observable();this.salesPerson=ko.observable();this.privateComment=ko.observable();this.comment=ko.observable();this.termsId=ko.observable();this.status=ko.observable();this.amountDue=ko.observable();this.totalTax=ko.observable();this.customerName=ko.observable("");this.customerAddress=ko.observable("");this.isCustomerTaxExempt=ko.observable(0);this.discount=ko.observable(0);this.termsDays=ko.observable(30);this.salesPerson=ko.observable();this.totalPaid=ko.observable(0);this.dueDate=ko.observable(fdate).extend({required:true});this.invoicedDate=ko.observable(fdate).extend({required:true});this.reset=function(){a.id("");a.customerId("");a.customerName("");a.isCustomerTaxExempt(0);a.customerAddress("");a.receiptNumber("");a.discount(0);a.privateComment("")}}function Busket(){ViewModel.call(this);var a=this;this.urls=[];this.items=ko.observableArray([]);this.id=ko.observable();this.deletedItems=ko.observableArray([]);this.invoice=new Invoice();this.invoice.makeValidatable();this.selectedItem=ko.observable(new LineItem());this.addItem=function(b){a.items.push(b)};this.removeItem=function(b){a.items.remove(b);if(b==a.selectedItem()){a.closePropertyPane()}a.deletedItems.push(b)};this.reset=function(){a.id("");a.items.removeAll();a.deletedItems.removeAll();a.invoice.reset()};this.openPropertyPane=function(c,b){a.selectedItem(c);$("#postbox-container-1 .postbox").hide();$(".item-edit").show()};this.closePropertyPane=function(c,b){b.preventDefault();$("#postbox-container-1 .postbox").show();$(".item-edit").hide()};this.getCustomerDetails=ko.pureComputed(function(){return a.invoice.customerName()+"<br/>"+a.invoice.customerAddress()},this);this.amountDue=ko.pureComputed(function(){var b=0;ko.utils.arrayForEach(a.items(),function(c){b+=c.total()});b-=parseFloat(a.invoice.discount());return b},this);this.subTotal=ko.pureComputed(function(){var b=0;ko.utils.arrayForEach(a.items(),function(c){b+=c.total()});return b},this);this.discountByAmount=function(c){var b=c/a.items().length;ko.utils.arrayForEach(a.items(),function(d){d.discount(b)})};this.discountByPercent=function(c){var b;ko.utils.arrayForEach(a.items(),function(d){b=(c/100)*d.total();d.discount(b)})};this.totalDiscount=ko.pureComputed(function(){var b=0;ko.utils.arrayForEach(a.items(),function(c){b+=c.discount()});b+=parseFloat(a.invoice.discount());return b});this.totalTax=ko.pureComputed(function(){if(a.invoice.isCustomerTaxExempt()=="1"){return 0}var b=0;ko.utils.arrayForEach(a.items(),function(c){b+=c.getTaxAmount()});return parseFloat(b.toFixed(2))});this.getFormatedTax=ko.pureComputed(function(){return accounting.formatMoney(a.totalTax())});this.getFormatedDiscount=ko.pureComputed(function(){return accounting.formatMoney(parseFloat(a.invoice.discount()))});this.getFormatedSubTotal=ko.pureComputed(function(){return accounting.formatMoney(parseFloat(a.subTotal()))});this.getFormatedAmountDue=ko.pureComputed(function(){return accounting.formatMoney(a.amountDue())});this.hasItems=ko.pureComputed(function(){return a.items().length>0});this.adjust=function(){a.showNumPad()};this.showNumPad=function(){new Numpad({showType:true,title:"Add Discount",initialValue:a.invoice.discount(),onClose:function(c,b){if(b=="%"){var d=(c/100)*a.subTotal();a.invoice.discount(d)}else{a.invoice.discount(c)}}}).init()};this.json=function(){a.invoice.totalTax=a.totalTax();a.invoice.totalDiscount=a.totalDiscount();a.invoice.amountDue(a.amountDue());var b=a.invoice._json();b.items=[];b.deletedItems=[];ko.utils.arrayForEach(a.items(),function(c){b.items.push(c.json())});ko.utils.arrayForEach(a.deletedItems(),function(c){b.deletedItems.push(c.json())});return b}}function LineItem(){ViewModel.call(this);var a=this;this.exempt=["name","originalPrice"];this.id=ko.observable();this.productId=ko.observable("");this.name=ko.observable("");this.quantity=ko.observable(1);this.salePrice=ko.observable(0);this.tax=ko.observable(0);this.taxId=ko.observable(1);this.taxRate=ko.observable(0);this.discount=ko.observable(0);this.getTaxAmount=ko.pureComputed(function(){if(global.controller.activeBusket.invoice.isCustomerTaxExempt()=="1"){return 0}var d=parseFloat(global.controller.activeBusket.invoice.discount());var c=0;if(d!=0){c=d/global.controller.activeBusket.items().length}var b=(a.taxRate()/100)*(a.total()-c);return parseFloat(b.toFixed(2))},this);this.discountedSalesPrice=ko.pureComputed(function(){return parseFloat(a.salePrice())-parseFloat(a.discount())},this);this.total=ko.pureComputed(function(){return a.discountedSalesPrice()*parseInt(a.quantity())},this);this.getFormatedTotal=ko.pureComputed(function(){return accounting.formatNumber(a.total())});this.getFormatedDiscount=ko.pureComputed(function(){return accounting.formatNumber(a.discount())});this.getFormatedTax=ko.pureComputed(function(){return accounting.formatNumber(a.getTaxAmount())});this.plusQuantity=function(){a.quantity(parseInt(a.quantity())+1)};this.minusQuantity=function(){var b=parseInt(a.quantity());if(b>1){a.quantity(b-1)}};this.adjust=function(){a.showNumPad()};this.showNumPad=function(){new Numpad({showType:false,title:"Add Discount",initialValue:a.discount(),onClose:function(b){a.discount(b)}}).init()};this.json=function(){a.tax(a.getTaxAmount());return a._json()}};2 var fdate=moment().format("YYYY-MM-DD");function Model(){var a=this;this.isViewVisible=ko.observable(true);this.exempt=[];this.afterReset=function(){};this.afterSetData=function(){};this.isValid=function(){return a.errors?a.errors().length==0:true};this.makeValidatable=function(){a.errors=ko.validation.group(a)};this.postErrors=function(b){if(b){postNotice("Please fix all errors","error")}ko.utils.arrayForEach(a.errors(),function(c){});a.errors.showAllMessages()};this.reset=function(b){b=b||[];for(var c in a){if(b.indexOf(c)<0){if(ko.isWriteableObservable(a[c])){if("push" in a[c]){a[c]([])}else{a[c](undefined)}}}}if(a.errors){a.errors.showAllMessages(false)}a.afterReset()};this.setData=function(e){var b=[];c=c||{};for(var d in a){if(ko.isWriteableObservable(a[d])){b.push(d)}}var c={include:b};ko.mapping.fromJS(e,c,a);a.afterSetData()};this._json=function(){var b=a.exempt||[];b.push("isViewVisible");b.push("errors");b.push("exempt");b.push("urls");for(var c in a){if(ko.isPureComputed(a[c])){b.push(c)}}return ko.mapping.toJS(a,{ignore:b})};this.json=function(){return a._json()}}function ViewModel(){Model.call(this);var a=this;this.urls=["",""];this.isNewRecord=function(){return !(a.hasOwnProperty("id")&&a.id())};this.getTimeOut=function(){return 0};this.beforeSend=function(){return true};this.beforeSave=function(){return true};this.save=function(c,b){if(a.beforeSave()){a._save(c,b)}};this.afterSave=function(b){};this._save=function(d,c){c=c||true;if(c&&!a.isValid()){a.postErrors(true);return}var b={};if(a.isNewRecord()){b.url="admin-ajax.php?action="+global.ajaxAction+"&r="+a.urls[0]}else{b.url="admin-ajax.php?action="+global.ajaxAction+"&r="+a.urls[1]+"&id="+a.id()}b.data=jQuery.parseJSON(ko.mapping.toJSON(a.json()));delete b.data.id;b.type="post";b.dataType="json";if(a.getTimeOut()>0){b.timeout=a.getTimeOut()}b.success=function(e,g,f){if(e.code=="200"){if(e.id&&a.id){a.id(e.id);a.afterSave(e)}if(d){d(e.message)}else{postNotice(e.message)}}else{postNotice(e.message,"error")}};b.error=function(e,g,f){errorMessage(e,g,f)};if(a.beforeSend()){var b=jQuery.extend({type:"post",dataType:"json"},b,{});jQueryAjax(b)}}}function Customer(){ViewModel.call(this);var a=this;this.urls=["customer/create","customer/update"];this.id=ko.observable();this.name=ko.observable().extend({required:true});this.contactPerson=ko.observable();this.email=ko.observable().extend({email:true});this.telephone1=ko.observable();this.telephone2=ko.observable();this.isActive=ko.observable(1).extend({type:"boolean"});this.shippingAddress=ko.observable();this.notes=ko.observable();this.isTaxExempt=ko.observable().extend({type:"boolean"});this.categoryId=ko.observable().extend({required:true});this.createCategory=function(){bootbox.prompt("Enter the new category name",function(b){if(b){var c=new CustomerCategory();c.name(b);c.save(function(){jQuery("#category_select").append(jQuery("<option>",{value:c.id(),text:c.name(),selected:"selected"})).trigger("change")});global.controller.pageReload=true}})}}function CustomerCategory(){ViewModel.call(this);var a=this;this.urls=["customerCategory/create","customerCategory/update"];this.id=ko.observable();this.name=ko.observable().extend({required:true});this.description=ko.observable()}function Payment(){ViewModel.call(this);var a=this;this.urls=["payment/create","payment/update"];this.exempt=["invoice"];this.id=ko.observable();this.invoice=ko.observable();this.invoiceId=ko.observable().extend({required:true});this.datePaid=ko.observable().extend({required:true});this.amount=ko.observable().extend({required:true});this.paymentMethod=ko.observable().extend({required:true});this.transactionCode=ko.observable().extend({required:true})}function Product(){ViewModel.call(this);var a=this;this.urls=["product/create","product/update"];this.id=ko.observable();this.name=ko.observable().extend({required:true});this.sku=ko.observable().extend({required:true});this.salePrice=ko.observable().extend({required:true});this.taxId=ko.observable().extend({required:true});this.isManaged=ko.observable().extend({type:"boolean"});this.quantity=ko.observable().extend({required:{onlyIf:function(){return a.isManaged()}}});this.warnQuantity=ko.observable().extend({required:{onlyIf:function(){return a.isManaged()}}});this.description=ko.observable();this.genID=function(){if(a.sku()){if(!window.confirm("Item already has an sku. Are you sure you want to generate a new sku?")){return}}var b={};b.url="admin-ajax.php?action="+global.ajaxAction+"&r=product/generateId";b.type="get";b.dataType="json";b.success=function(d,e,c){if(d.code=="200"){a.sku(d.genID)}else{postNotice(d.message,"error")}};b.error=function(c,e,d){errorMessage(c,e,d)};jQueryAjax(b)};this.createCategory=function(){bootbox.prompt("Enter the new category name",function(b){if(b){var c=new CustomerCategory();c.name(b);c.save(function(){jQuery("#category_select").append(jQuery("<option>",{value:c.id(),text:c.name(),selected:"selected"})).trigger("change")});global.controller.pageReload=true}})}}function Tax(){ViewModel.call(this);var a=this;this.urls=["tax/create","tax/update"];this.id=ko.observable();this.name=ko.observable().extend({required:true});this.rate=ko.observable().extend({required:true});this.description=ko.observable()}function OptionModel(){ViewModel.call(this);var a=this;this.urls=["option/create","option/update"];this.exempt=[];this.id=ko.observable();this.invoiceStartNumber=ko.observable().extend({required:true,number:true});this.successPage=ko.observable().extend({required:true});this.paymentPage=ko.observable().extend({required:true});this.name=ko.observable().extend({required:true});this.email=ko.observable();this.registeredNumber=ko.observable();this.contactDetails=ko.observable();this.logo=ko.observable();this.taxIncluded=ko.observable(1).extend({type:"boolean"});this.currency=ko.observable().extend({required:true});this.footerComment=ko.observable();this.footerCommentAlignment=ko.observable();this.footerCommentFontSize=ko.observable();this.receiptTitle=ko.observable();this.refundTitle=ko.observable();this.quantityColumn=ko.observable();this.descriptionColumn=ko.observable();this.unitPriceColumn=ko.observable();this.discountColumn=ko.observable();this.lineTotalColumn=ko.observable();this.transactionNumber=ko.observable();this.issueDate=ko.observable();this.issueTime=ko.observable();this.salesPerson=ko.observable();this.subTotal=ko.observable();this.totalAmount=ko.observable();this.amountTendered=ko.observable();this.change=ko.observable();this.invoiceDueDate=ko.observable();this.quoteDueDate=ko.observable();this.transactionReference=ko.observable();this.refundNumber=ko.observable();this.decimalSymbol=ko.observable().extend({required:true});this.dateFormat=ko.observable().extend({required:true});this.thousandsSymbol=ko.observable().extend({required:true});this.roles=ko.observableArray([]);this.prop=ko.observable();this.propValue=ko.observable();this.prop.subscribe(function(b){a.propValue(a[b]())});this.propValue.subscribe(function(b){a[a.prop()](b)});this.setIFileName=function(b){a.logo(b)};this.update=function(){a.save(function(b){postNotice(b)})}}function Refund(){ViewModel.call(this);var a=this;this.urls=["refund/create","refund/update"];this.exempt=["invoice"];this.id=ko.observable();this.invoice=ko.observable();this.invoiceId=ko.observable().extend({required:true});this.amount=ko.observable().extend({required:true});this.refundDate=ko.observable(fdate).extend({required:true});this.reference=ko.observable().extend({required:true});this.paymentMethod=ko.observable().extend({required:true})}function Invoice(){ViewModel.call(this);var a=this;this.urls=["invoice/create","invoice/update"];this.exempt=["discountType","customerName","customerAddress","isCustomerTaxExempt","type","status","salesPerson","totalPaid"];this.id=ko.observable();this.type=ko.observable(1);this.receiptNumber=ko.observable().extend({required:{onlyIf:function(){return a.type()==1}}});this.title=ko.observable().extend({required:true});this.customerId=ko.observable().extend({required:true});this.termsDays=ko.observable();this.salesPerson=ko.observable();this.privateComment=ko.observable();this.comment=ko.observable();this.termsId=ko.observable();this.status=ko.observable();this.amountDue=ko.observable();this.totalTax=ko.observable();this.customerName=ko.observable("");this.customerAddress=ko.observable("");this.isCustomerTaxExempt=ko.observable(0);this.discount=ko.observable(0);this.termsDays=ko.observable(30);this.salesPerson=ko.observable();this.totalPaid=ko.observable(0);this.dueDate=ko.observable(fdate).extend({required:true});this.invoicedDate=ko.observable(fdate).extend({required:true});this.reset=function(){a.id("");a.customerId("");a.customerName("");a.isCustomerTaxExempt(0);a.customerAddress("");a.receiptNumber("");a.discount(0);a.privateComment("")}}function Busket(){ViewModel.call(this);var a=this;this.urls=[];this.items=ko.observableArray([]);this.id=ko.observable();this.deletedItems=ko.observableArray([]);this.invoice=new Invoice();this.invoice.makeValidatable();this.selectedItem=ko.observable(new LineItem());this.addItem=function(b){a.items.push(b)};this.removeItem=function(b){a.items.remove(b);if(b==a.selectedItem()){a.closePropertyPane()}a.deletedItems.push(b)};this.reset=function(){a.id("");a.items.removeAll();a.deletedItems.removeAll();a.invoice.reset()};this.openPropertyPane=function(c,b){a.selectedItem(c);$("#postbox-container-1 .postbox").hide();$(".item-edit").show()};this.closePropertyPane=function(c,b){b.preventDefault();$("#postbox-container-1 .postbox").show();$(".item-edit").hide()};this.getCustomerDetails=ko.pureComputed(function(){return a.invoice.customerName()+"<br/>"+a.invoice.customerAddress()},this);this.amountDue=ko.pureComputed(function(){var b=0;ko.utils.arrayForEach(a.items(),function(c){b+=c.total()});b-=parseFloat(a.invoice.discount());return b},this);this.subTotal=ko.pureComputed(function(){var b=0;ko.utils.arrayForEach(a.items(),function(c){b+=c.total()});return b},this);this.discountByAmount=function(c){var b=c/a.items().length;ko.utils.arrayForEach(a.items(),function(d){d.discount(b)})};this.discountByPercent=function(c){var b;ko.utils.arrayForEach(a.items(),function(d){b=(c/100)*d.total();d.discount(b)})};this.totalDiscount=ko.pureComputed(function(){var b=0;ko.utils.arrayForEach(a.items(),function(c){b+=c.discount()});b+=parseFloat(a.invoice.discount());return b});this.totalTax=ko.pureComputed(function(){if(a.invoice.isCustomerTaxExempt()=="1"){return 0}var b=0;ko.utils.arrayForEach(a.items(),function(c){b+=c.getTaxAmount()});return parseFloat(b.toFixed(2))});this.getFormatedTax=ko.pureComputed(function(){return accounting.formatMoney(a.totalTax())});this.getFormatedDiscount=ko.pureComputed(function(){return accounting.formatMoney(parseFloat(a.invoice.discount()))});this.getFormatedSubTotal=ko.pureComputed(function(){return accounting.formatMoney(parseFloat(a.subTotal()))});this.getFormatedAmountDue=ko.pureComputed(function(){return accounting.formatMoney(a.amountDue())});this.hasItems=ko.pureComputed(function(){return a.items().length>0});this.adjust=function(){a.showNumPad()};this.showNumPad=function(){new Numpad({showType:true,title:"Add Discount",initialValue:a.invoice.discount(),onClose:function(c,b){if(b=="%"){var d=(c/100)*a.subTotal();a.invoice.discount(d)}else{a.invoice.discount(c)}}}).init()};this.json=function(){a.invoice.totalTax=a.totalTax();a.invoice.totalDiscount=a.totalDiscount();a.invoice.amountDue(a.amountDue());var b=a.invoice._json();b.items=[];b.deletedItems=[];ko.utils.arrayForEach(a.items(),function(c){b.items.push(c.json())});ko.utils.arrayForEach(a.deletedItems(),function(c){b.deletedItems.push(c.json())});return b}}function LineItem(){ViewModel.call(this);var a=this;this.exempt=["name","originalPrice"];this.id=ko.observable();this.productId=ko.observable("");this.name=ko.observable("");this.quantity=ko.observable(1);this.salePrice=ko.observable(0);this.tax=ko.observable(0);this.taxId=ko.observable(1);this.taxRate=ko.observable(0);this.discount=ko.observable(0);this.getTaxAmount=ko.pureComputed(function(){if(global.controller.activeBusket.invoice.isCustomerTaxExempt()=="1"){return 0}var f=parseFloat(global.controller.activeBusket.invoice.discount());var d=0;if(f!=0){var b=global.controller.activeBusket.items();var e=0;b.forEach(function(g){e+=g.quantity()});d=f/e}var c=(a.taxRate()/100)*(a.total()-(parseInt(a.quantity())*d));return parseFloat(c.toFixed(2))},this);this.discountedSalesPrice=ko.pureComputed(function(){return parseFloat(a.salePrice())-parseFloat(a.discount())},this);this.total=ko.pureComputed(function(){return a.discountedSalesPrice()*parseInt(a.quantity())},this);this.getFormatedTotal=ko.pureComputed(function(){return accounting.formatNumber(a.total())});this.getFormatedDiscount=ko.pureComputed(function(){return accounting.formatNumber(a.discount())});this.getFormatedTax=ko.pureComputed(function(){return accounting.formatNumber(a.getTaxAmount())});this.plusQuantity=function(){a.quantity(parseInt(a.quantity())+1)};this.minusQuantity=function(){var b=parseInt(a.quantity());if(b>1){a.quantity(b-1)}};this.adjust=function(){a.showNumPad()};this.showNumPad=function(){new Numpad({showType:false,title:"Add Discount",initialValue:a.discount(),onClose:function(b){a.discount(b)}}).init()};this.json=function(){a.tax(a.getTaxAmount());return a._json()}};
Note: See TracChangeset
for help on using the changeset viewer.