NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

var mooPOS = new Class({
Implements: [Events, Options],

options: {
tax_rate: .09,
no_tax: [],
payment_methods: ['cash', 'credit', 'check'],
cc_minimum: 5,
cc_surcharge: .5,
cc_surcharge_option: false,
dept_cert: 0,
dept_fee: 0,
dept_book: 0,
dept_merch: 0
},

initialize: function(buttons, webroot, options){
this.setOptions(options);
this.buttons = buttons;
this.webroot = webroot;
this.purchase = Object();
this.highlighted_buttons = Array();
this.href = 'javascript:void(0);';
this.build();
},

build: function() {
// Add item buttons
Object.each(this.buttons, function(tab_content, tab_name){
var h1 = new Element('h1').set('html', tab_name.replace('_', ' ')).inject($('tabs'));
var div = new Element('div').inject($('tabs'));
Object.each(tab_content, function(sub_tab_content, key){
var fieldset = new Element('fieldset').inject(div);
new Element('legend').set('text', sub_tab_content.name.replace('_', ' ')).inject(fieldset);
var ul = new Element('ul', { class: 'button_list' }).inject(fieldset);
Object.each(sub_tab_content.buttons, function(value, key){
var li = new Element('li').inject(ul)
var a = new Element('a', { title: '$'+(value.price).formatMoney(), 'href': this.href }).set('html', value.nameShort);
if (value.price != value.price_max) value.price += '-'+value.price_max;
a.addEvent('click', this.add.bind(this, [ value.table, value.id, value.name, value.price, value.department ]));
if (value.price != value.price_max) a.addClass('tbd');
a.inject(li);
// Resize button text
this.resizeButtonText(a, li.getSize().x, 14, 0);
}, this);
}, this);
}, this);
// Add item button
this.search('book');
var a = new Element('a', { 'href': this.href });
a.addEvent('click', this.addItem.bind(this)).set('html', 'Add Item').inject($('addItem'));
$('ItemTable').addEvent('change', function() {
this.search($('ItemTable').value);
}.bind(this));
// Add custom button
var a = new Element('a', { 'href': this.href });
a.addEvent('click', this.addCustom.bind(this)).set('html', 'Add Custom Item').inject($('addCustom'));
// Add payment buttons
$('purchase_pay').empty();
this.options.payment_methods.reverse().each(function(item, index){
var li = new Element('li', { 'id': 'pay_'+item, 'href': this.href });
li.addEvent('click', this.pay.bind(this, item)).set('html', item).inject($('purchase_pay'), 'top');
}, this);
// Add modification buttons
$('buttonCancel').addEvent('click', this.clear.bind(this));
$('buttonSelectAll').addEvent('click', this.selectAll.bind(this));
$('buttonRemove').addEvent('click', this.remove.bind(this));
$('buttonDiscount').addEvent('click', this.discount.bind(this));
// Add cashier button
$('cashier').addEvent('click', this.cashier.bind(this));
// Update password
var updatePassword = function() {
$('password').load(this.webroot+'shifts/password');
// Show last updated time
var d = new Date();
var hour = d.getHours();
var minute = d.getMinutes() + '';
if (hour < 12) var a_p = 'am';
else var a_p = 'pm';
if (hour == 0) hour = 12;
else if (hour > 12) hour = hour - 12;
if (minute.length == 1) minute = '0' + minute;
$('password').setProperty('title', 'Public Terminal Password (updated '+hour+':'+minute+' '+a_p+')');
}.bind(this).periodical(60000);

// Disable form submissions
$('col_left').getElements('form').each(function(item, index){
item.addEvent('submit', function(e) { return false; })
});
$('ItemSearchForm').addEvent('submit', function(e) {
if ($('ItemId').get('value')) this.addItem();
}.bind(this));

// Process barcode scans
new ScannerKeystrokeObserver({
onRead: function(code) {
var myRequest = new Request.HTML({
url: this.webroot+'books/search',
onSuccess: function(responseTree, responseElements) {
if (result = responseElements.filter('.itemListing')[0]) {
var itemInfo = result.get('data-info').split('|');
if (itemInfo[2] != 0) used = ' (Used)';
else used = '';
$('ItemName').set('value', result.getFirst('span[class=name]').get('html')+used);
$('ItemId').set('value', itemInfo[0]);
$('ItemPrice').set('value', itemInfo[1]);
$('ItemDiscount').set('value', itemInfo[2]);
this.addItem();
}
}.bind(this)
}).post('search='+code);
}.bind(this)
});

new SimpleTabs($('tabs'), { selector: 'h1', hover: true });
},

add: function(table, id, name, price, department) {
// If there is a range of possible prices, prompt for user input
if (price.toString().indexOf("-") > 0) {
range = price.split('-');
if (range[1] != 'null') {
custom_price = prompt('Enter a price between $'+range[0]+' and $'+range[1]+'.');
if (custom_price >= range[0] && custom_price <= range[1]) price = custom_price;
else price = null;
} else {
custom_price = prompt('Enter a price greater than $'+range[0]+'.');
if (custom_price >= range[0]) price = custom_price;
else price = null;
}
}

if (price == null) alert('Please enter a valid price!');
else {
// New item - add to purchase
if (!this.purchase[id]) this.purchase[id] = Array(table, name, price, 1, department);
// Repeat item - increase existing qty
else this.purchase[id] = Array(table, name, price, (this.purchase[id][3]+1), department);

$each(this.purchase, function(item, index) {
var span = new Element('span');
span.set('html', '$'+(item[2]*item[3]).formatMoney());
if ($('purchase_summary_'+index)) {
$('purchase_summary_'+index).empty();
var a = new Element('a', { 'href': this.href }).addEvent('click', this.select.bind(this, index));
if (item[3] > 1) a.set('html', item[1]+' x'+item[3]);
else a.set('html', item[1]);
$('purchase_summary_'+index).adopt(span).adopt(a);
} else {
var li = new Element('li', { 'id': 'purchase_summary_'+index });
var a = new Element('a', { 'href': this.href }).addEvent('click', this.select.bind(this, index));
a.set('html', item[1]);
li.adopt(span).adopt(a);
$('purchase_summary_list').adopt(li);
}
}, this);

this.update();
// Remove button focus
document.activeElement.blur();
}
},

addCustom: function() {
name = $('CustomName').get('value');
id = name.replace(/[^a-zA-Z0-9]+/g,'').toLowerCase();
price = $('CustomPrice').get('value');
department = $('CustomDepartmentId').get('value');
if (department == this.options.dept_book || department == this.options.dept_merch) alert('Selling inventoried items from the "Custom Item" tool will create inventory errors. Have you tried searching for the item by title, code and keyword?');
if (name != 'Item Name' && price > 0 && department) this.add(null, id, name, price, department);
else alert('Some information is missing. Please check the custom item details.');
},

addItem: function() {
id = $('ItemId').get('value');
name = $('ItemName').get('value');
price = $('ItemPrice').get('value');
discount = $('ItemDiscount').get('value');

if (id) {
table = $('ItemId').retrieve('scope');
if (table == 'book') dept = this.options.dept_book;
else dept = this.options.dept_merch;
id += '-'+discount;
this.add(table, id, name, price, dept);
// Clear item search
$('ItemSearchForm').getElements('input[id^=Item]').each(function(item, index){
item.set('value', '');
});
} else alert('Please select an item from the inventory first!')
},

cashier: function() {
cashiers = this.options.cashiers;
cookie = Cookie.read('CakeCookie[Shift]')
if (!cookie) {
window.location = this.webroot+'sales';
throw('Session cookie missing. Page will now be reloaded.');
}
cashier_id = cookie.replace(/[{'"}]/g,'').split(',')[1].split(':')[1];
// Find the current cashier details
Array.each(cashiers, function(c, index) {
if (parseInt(c.id) == parseInt(cashier_id)) current = index;
});
// Find the next cashier
if (cashiers.length != (current+1)) current++;
else current = 0;
$('cashier').set('text', cashiers[current].name);
Cookie.write('CakeCookie[Shift]', cookie.replace(/"cashier":".+"/g, '"cashier":"'+cashiers[current].id+'"'));
},

clear: function() {
// Clear the highlight array
this.highlighted_buttons.empty();
// Empty the purchase display
$('purchase_summary_list').empty();
// Empty the purchase object
this.purchase = Object();
// Clear item search
$('ItemSearchForm').getElements('input[id^=Item]').each(function(item, index){
item.set('value', '');
});
this.update();
},

discount: function() {
var percent = parseFloat(prompt("Discount Percentage",25))/100;
if (percent && this.highlighted_buttons.length) {
// Loop through lighlighted buttons and discount them
this.highlighted_buttons.each(function(item, index){
// Give the item a unique id to avoid conflicting with other, undiscounted items
new_item = item+'-'+percent;
// Copy the old, undiscounted version
this.purchase[new_item] = Array(
this.purchase[item][0], // Table
this.purchase[item][1]+' (-'+(percent*100)+'%)', // Name
this.purchase[item][2]-(this.purchase[item][2]*percent), // Price
this.purchase[item][3], // Qty
this.purchase[item][4] // Department
);
// Build the new listing
var li = new Element('li', { 'id': 'purchase_summary_'+new_item });
var span = new Element('span');
old_cost = this.purchase[item][2] * this.purchase[item][3];
new_cost = old_cost-(old_cost*percent);
span.set('html', '$'+new_cost.formatMoney());
var a = new Element('a', { 'href': this.href }).addEvent('click', this.select.bind(this, new_item));
if (this.purchase[item][3] > 1) a.set('html', this.purchase[item][1]+' (-'+(percent*100)+'%) x'+this.purchase[item][3]);
else a.set('html', this.purchase[item][1]+' (-'+(percent*100)+'%)');
li.inject($('purchase_summary_'+item), 'after');
$('purchase_summary_'+new_item).adopt(span).adopt(a);
// Clean up
delete this.purchase[item];
$('purchase_summary_'+item).dispose();
}, this);
// Clear the highlight array
this.highlighted_buttons.empty();
} else alert('Please select an item from the order list!');

this.update();
},

pay: function(method) {
var str = String();
$each(this.purchase, function(item, index) {
// ID | Table | Name | Price | Qty | Department
str += index+'|'+item[0]+'|'+item[1]+'|'+item[2]+'|'+item[3]+'|'+item[4]+'||';
});
if (str.length) {
if (eval('this.pay'+method.capitalize()+'($('purchase_total').get('html'))')) {
$('SaleSummary').value = str;
var myRequest = new Request({
url: this.webroot+'sales/pay/'+method,
method: 'post',
onSuccess: function(response) {
this.register();
if (response.substr(-1) == "?" && confirm(response))
window.location.href = this.webroot+'sales/receipt.pdf';
else alert(response);
this.clear();
}.bind(this), onFailure: function() {
alert('Purchase failed.');
}
}).send('items='+str.replace(/&/g, '%26'));
}
} else alert('Please add an item to the order list!');
},

payCash: function(total) {
// Sale total must be positive
if (total < 0) {
alert('Insufficient sale value!');
return false;
}
var tendered = prompt("Cash Received:", total);
change = tendered-total;
if (change == 0) return true;
else if (change > 0) {
alert('Change Due: $'+change.formatMoney());
return true;
} else {
alert('Insufficient money tendered!');
return false;
}
},

payCertificate: function(total) {
var tendered = prompt("Certificate Value:", total);
remainder = tendered-total;
if (remainder == 0) return true;
else if (remainder > 0) {
alert('Remaining Balance: $'+remainder.formatMoney());
return true;
} else {
owed = 0-remainder;
var tendered2 = prompt("Additional Cash Received:", owed.formatMoney());
change = tendered2-owed;
if (change >= 0) {
if (change > .01) alert('Change Due: $'+change.formatMoney());
var mySubRequest = new Request({ url: this.webroot+'sales/pay/cash', method: 'post', onSuccess: function() {
return true;
}.bind(this), onFailure: function() {
return false;
}}).send('items=0|null|Certificate Extension|'+owed+'|1|'+this.options.dept_cert+'||');
if (mySubRequest) return true;
} else {
alert('Insufficient money tendered!');
return false;
}
}
},

payCheck: function(total) {
// Sale total must be positive
if (total < 0) {
alert('Insufficient sale value!');
return false;
}
else return true;
},

payComp: function(total) {
return true;
},

payCredit: function(total) {
// Sale total must be positive
if (total < 0) {
alert('Insufficient sale value!');
return false;
}
// Check against CC minimum
subtotal = $('purchase_total').get('text');
if (this.options.cc_minimum && subtotal < (this.options.cc_minimum - .05) && !this.purchase['credit']) {
if (confirm('This purchase is under $'+this.options.cc_minimum+', would you like to add a $'+this.options.cc_surcharge+' surcharge?'))
// Table | ID | Name | Price | Department
this.add(null, 'credit', 'Credit card fee', this.options.cc_surcharge, this.options.dept_fee);
else
// Table | ID | Name | Price | Department
this.add(null, 'credit', 'Credit card fee waived', 0, this.options.dept_fee);
return false;
} else return true;
},

register: function() {
$('shift_total').load(this.webroot+'shifts/total');
$('password').load(this.webroot+'shifts/password');
},

remove: function() {
if (this.highlighted_buttons.length) {
// Loop through lighlighted buttons and remove them from the purchase
this.highlighted_buttons.each(function(item, index){
delete this.purchase[item];
$('purchase_summary_'+item).dispose();
}, this);
// Clear the highlight array
this.highlighted_buttons.empty();
} else alert('Please select an item from the order list!');

this.update();
},

resizeButtonText: function(el, targetSize, fontSize, iteration) {
currentSize = el.getSize();
if (targetSize < currentSize.x) {
newFontSize = fontSize-1;
if (!iteration) {
var pt = el.getStyle('padding-top').toInt();
var pb = el.getStyle('padding-bottom').toInt();
el.setStyle('height', (currentSize.y-pb-pt)+'px');
el.setStyle('line-height', (currentSize.y-pb-pt)+'px');
el.setStyle('padding-top', pt+'px');
el.setStyle('padding-bottom', pb+'px');
}
el.setStyle('font-size', newFontSize+'px');
this.resizeButtonText(el, targetSize, newFontSize, iteration++);
} else el.setStyle('display', 'block');
},

search: function(scope) {
if (this.searcher) {
this.searcher.destroy();
delete(this.searcher);
$('ItemSearch').removeEvents();
}
$('ItemId').store('scope', scope);
if (scope == 'book') $('ItemSearch').setProperty('placeholder', 'Search by title, author or ISBN fragment');
else $('ItemSearch').setProperty('placeholder', 'Search by name, custom variable or code fragment');
this.searcher = new Autocompleter.Request.HTML('ItemSearch', this.webroot+scope+'s/search', {
postVar: 'search',
injectChoice: function(choice) {
choice.inputValue = choice.getFirst('span[class=name]').get('html');
this.addChoiceEvents(choice.set('html', this.markQueryValue(choice.innerHTML)));
},
onSelection: function(el, choice, selection) {
// Item ID | Item Price | Item Discount
var itemInfo = choice.get('data-info').split('|');
if (itemInfo[2] != 0) used = ' (Used)';
else used = '';
this.addChoiceEvents($('ItemName').set('value', choice.getFirst('span[class=name]').get('html')+used));
this.addChoiceEvents($('ItemId').set('value', itemInfo[0]));
this.addChoiceEvents($('ItemPrice').set('value', itemInfo[1]));
this.addChoiceEvents($('ItemDiscount').set('value', itemInfo[2]));
}
});
},

select: function(button) {
if (this.highlighted_buttons.contains(button)) {
this.highlighted_buttons.erase(button);
$('purchase_summary_'+button).erase('class');
} else {
this.highlighted_buttons.include(button);
$('purchase_summary_'+button).set('class', 'active');
}
},

selectAll: function() {
$each(this.purchase, function(item, index) {
if (!this.highlighted_buttons.contains(index)) {
this.highlighted_buttons.include(index);
$('purchase_summary_'+index).set('class', 'active');
}
}, this);
},

tax: function(amount, summed) {
if (summed) return Math.ceil(amount * (1 + this.options.tax_rate) * 100)/100;
else return Math.ceil(amount * this.options.tax_rate * 100)/100;
},

update: function() {
subtotal = { taxed: 0, untaxed: 0 };
$each(this.purchase, function(item, index) {
if (this.options.no_tax.contains(item[4].toInt())) subtotal.untaxed += item[2] * item[3];
else subtotal.taxed += item[2] * item[3];
}, this);
// Update Purchase Cost display
$('purchase_subtotal').set('text', (subtotal.taxed + subtotal.untaxed).formatMoney());
$('purchase_tax').set('text', (this.tax(subtotal.taxed, false)).formatMoney());
$('purchase_total').set('text', (this.tax(subtotal.taxed, true) + subtotal.untaxed).formatMoney());
}
});
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.