From c111c1c5618bd45267bbf3a5c9764d51fba1ca12 Mon Sep 17 00:00:00 2001 From: Enyosolutions Date: Thu, 15 May 2025 06:26:36 +0100 Subject: [PATCH] feat: update dependencies fix: bug on admin selector --- assets/js/pos.js | 4018 ++++++++++++++++++++++------------------------ index.html | 198 +-- package.json | 3 +- start.js | 86 +- yarn.lock | 1294 +++++++-------- 5 files changed, 2762 insertions(+), 2837 deletions(-) diff --git a/assets/js/pos.js b/assets/js/pos.js index 77548f66..0b028b97 100644 --- a/assets/js/pos.js +++ b/assets/js/pos.js @@ -1,672 +1,644 @@ -let cart = []; -let index = 0; -let allUsers = []; -let allProducts = []; -let allCategories = []; -let allTransactions = []; -let sold = []; -let state = []; -let sold_items = []; -let item; -let auth; -let holdOrder = 0; -let vat = 0; -let perms = null; -let deleteId = 0; -let paymentType = 0; -let receipt = ''; -let totalVat = 0; -let subTotal = 0; -let method = ''; -let order_index = 0; -let user_index = 0; -let product_index = 0; -let transaction_index; -let host = 'localhost'; -let path = require('path'); -let port = '8001'; -let moment = require('moment'); -let Swal = require('sweetalert2'); -let { ipcRenderer } = require('electron'); -let dotInterval = setInterval(function () { $(".dot").text('.') }, 3000); -let Store = require('electron-store'); -const remote = require('electron').remote; -const app = remote.app; -let img_path = app.getPath('appData') + '/POS/uploads/'; -let api = 'http://' + host + ':' + port + '/api/'; -let btoa = require('btoa'); -let jsPDF = require('jspdf'); -let html2canvas = require('html2canvas'); -let JsBarcode = require('jsbarcode'); -let macaddress = require('macaddress'); -let categories = []; -let holdOrderList = []; -let customerOrderList = []; -let ownUserEdit = null; -let totalPrice = 0; -let orderTotal = 0; -let auth_error = 'Incorrect username or password'; -let auth_empty = 'Please enter a username and password'; -let holdOrderlocation = $("#randerHoldOrders"); -let customerOrderLocation = $("#randerCustomerOrders"); -let storage = new Store(); -let settings; -let platform; -let user = {}; -let start = moment().startOf('month'); -let end = moment(); -let start_date = moment(start).toDate(); -let end_date = moment(end).toDate(); -let by_till = 0; -let by_user = 0; -let by_status = 1; +let btoa = require('btoa') +let jsPDF = require('jspdf') +let html2canvas = require('html2canvas') +let JsBarcode = require('jsbarcode') +let macaddress = require('macaddress') +const { app } = require('@electron/remote') +let moment = require('moment') +let Swal = require('sweetalert2') +let { ipcRenderer } = require('electron') +let Store = require('electron-store') +let path = require('path') +console.log(app.getPath('userData')) +// Initialize store with proper configuration +let storage = new Store({ + name: 'pos-config', + cwd: app.getPath('userData') +}) + +let cart = [] +let index = 0 +let allUsers = [] +let allProducts = [] +let allCategories = [] +let allTransactions = [] +let sold = [] +let state = [] +let sold_items = [] +let item +let auth +let holdOrder = 0 +let vat = 0 +let perms = null +let deleteId = 0 +let paymentType = 0 +let receipt = '' +let totalVat = 0 +let subTotal = 0 +let method = '' +let order_index = 0 +let user_index = 0 +let product_index = 0 +let transaction_index +let host = 'localhost' + +let port = '8001' + +let dotInterval = setInterval(function () { + $('.dot').text('.') +}, 3000) + +console.log(app) +const img_path = app.getPath('appData') + '/POS/uploads/' +let api = 'http://' + host + ':' + port + '/api/' + +let categories = [] +let holdOrderList = [] +let customerOrderList = [] +let ownUserEdit = null +let totalPrice = 0 +let orderTotal = 0 +let auth_error = 'Incorrect username or password' +let auth_empty = 'Please enter a username and password' +let holdOrderlocation = $('#randerHoldOrders') +let customerOrderLocation = $('#randerCustomerOrders') +let settings +let platform +let user = {} +let start = moment().startOf('month') +let end = moment() +let start_date = moment(start).toDate() +let end_date = moment(end).toDate() +let by_till = 0 +let by_user = 0 +let by_status = 1 $(function () { - - function cb(start, end) { - $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY')); - } - - $('#reportrange').daterangepicker({ - startDate: start, - endDate: end, - autoApply: true, - timePicker: true, - timePicker24Hour: true, - timePickerIncrement: 10, - timePickerSeconds: true, - // minDate: '', - ranges: { - 'Today': [moment().startOf('day'), moment()], - 'Yesterday': [moment().subtract(1, 'days').startOf('day'), moment().subtract(1, 'days').endOf('day')], - 'Last 7 Days': [moment().subtract(6, 'days').startOf('day'), moment().endOf('day')], - 'Last 30 Days': [moment().subtract(29, 'days').startOf('day'), moment().endOf('day')], - 'This Month': [moment().startOf('month'), moment().endOf('month')], - 'This Month': [moment().startOf('month'), moment()], - 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')] - } - }, cb); - - cb(start, end); - -}); - + function cb (start, end) { + $('#reportrange span').html( + start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY') + ) + } + + $('#reportrange').daterangepicker( + { + startDate: start, + endDate: end, + autoApply: true, + timePicker: true, + timePicker24Hour: true, + timePickerIncrement: 10, + timePickerSeconds: true, + // minDate: '', + ranges: { + Today: [moment().startOf('day'), moment()], + Yesterday: [ + moment().subtract(1, 'days').startOf('day'), + moment().subtract(1, 'days').endOf('day') + ], + 'Last 7 Days': [ + moment().subtract(6, 'days').startOf('day'), + moment().endOf('day') + ], + 'Last 30 Days': [ + moment().subtract(29, 'days').startOf('day'), + moment().endOf('day') + ], + 'This Month': [moment().startOf('month'), moment().endOf('month')], + 'This Month': [moment().startOf('month'), moment()], + 'Last Month': [ + moment().subtract(1, 'month').startOf('month'), + moment().subtract(1, 'month').endOf('month') + ] + } + }, + cb + ) + + cb(start, end) +}) $.fn.serializeObject = function () { - var o = {}; - var a = this.serializeArray(); - $.each(a, function () { - if (o[this.name]) { - if (!o[this.name].push) { - o[this.name] = [o[this.name]]; - } - o[this.name].push(this.value || ''); - } else { - o[this.name] = this.value || ''; - } - }); - return o; -}; - - -auth = storage.get('auth'); -user = storage.get('user'); + var o = {} + var a = this.serializeArray() + $.each(a, function () { + if (o[this.name]) { + if (!o[this.name].push) { + o[this.name] = [o[this.name]] + } + o[this.name].push(this.value || '') + } else { + o[this.name] = this.value || '' + } + }) + return o +} +auth = storage.get('auth') +user = storage.get('user') +platform = storage.get('settings') || {} if (auth == undefined) { - $.get(api + 'users/check/', function (data) { }); - $("#loading").show(); - authenticate(); - + $.get(api + 'users/check/', function (data) {}) + $('#loading').show() + authenticate() } else { + $('#loading').show() - $('#loading').show(); - - setTimeout(function () { - $('#loading').hide(); - }, 2000); - - platform = storage.get('settings'); - - if (platform != undefined) { + setTimeout(function () { + $('#loading').hide() + }, 2000) - if (platform.app == 'Network Point of Sale Terminal') { - api = 'http://' + platform.ip + ':' + port + '/api/'; - perms = true; - } + if (platform != undefined) { + if (platform.app == 'Network Point of Sale Terminal') { + api = 'http://' + platform.ip + ':' + port + '/api/' + perms = true } + } - $.get(api + 'users/user/' + user._id, function (data) { - user = data; - $('#loggedin-user').text(user.fullname); - }); - - - $.get(api + 'settings/get', function (data) { - settings = data.settings; - }); - + $.get(api + 'users/user/' + user._id, function (data) { + user = data + $('#loggedin-user').text(user.fullname) + }) - $.get(api + 'users/all', function (users) { - allUsers = [...users]; - }); + $.get(api + 'settings/get', function (data) { + settings = data.settings + }) + $.get(api + 'users/all', function (users) { + allUsers = [...users] + }) + $(document).ready(function () { + $('.loading').hide() - $(document).ready(function () { - - $(".loading").hide(); - - loadCategories(); - loadProducts(); - loadCustomers(); + loadCategories() + loadProducts() + loadCustomers() + if (settings && settings.symbol) { + $('#price_curr, #payment_curr, #change_curr').text(settings.symbol) + } - if (settings && settings.symbol) { - $("#price_curr, #payment_curr, #change_curr").text(settings.symbol); + setTimeout(function () { + if (settings == undefined && auth != undefined) { + $('#settingsModal').modal('show') + } else { + vat = parseFloat(settings.percentage) + $('#taxInfo').text(settings.charge_tax ? vat : 0) + } + }, 1500) + + $('#settingsModal').on('hide.bs.modal', function () { + setTimeout(function () { + if (settings == undefined && auth != undefined) { + $('#settingsModal').modal('show') } + }, 1000) + }) + if (0 == user.perm_products) { + $('.p_one').hide() + } + if (0 == user.perm_categories) { + $('.p_two').hide() + } + if (0 == user.perm_transactions) { + $('.p_three').hide() + } + if (0 == user.perm_users) { + $('.p_four').hide() + } + if (0 == user.perm_settings) { + $('.p_five').hide() + } - setTimeout(function () { - if (settings == undefined && auth != undefined) { - $('#settingsModal').modal('show'); - } - else { - vat = parseFloat(settings.percentage); - $("#taxInfo").text(settings.charge_tax ? vat : 0); - } - - }, 1500); - - - - $("#settingsModal").on("hide.bs.modal", function () { - - setTimeout(function () { - if (settings == undefined && auth != undefined) { - $('#settingsModal').modal('show'); - } - }, 1000); - - }); - - - if (0 == user.perm_products) { $(".p_one").hide() }; - if (0 == user.perm_categories) { $(".p_two").hide() }; - if (0 == user.perm_transactions) { $(".p_three").hide() }; - if (0 == user.perm_users) { $(".p_four").hide() }; - if (0 == user.perm_settings) { $(".p_five").hide() }; - - function loadProducts() { - - $.get(api + 'inventory/products', function (data) { - - data.forEach(item => { - item.price = parseFloat(item.price).toFixed(2); - }); - - allProducts = [...data]; - - loadProductList(); - - $('#parent').text(''); - $('#categories').html(` `); - - data.forEach(item => { - - if (!categories.includes(item.category)) { - categories.push(item.category); - } + function loadProducts () { + $.get(api + 'inventory/products', function (data) { + data.forEach(item => { + item.price = parseFloat(item.price).toFixed(2) + }) - let item_info = `
-
-
+ allProducts = [...data] + + loadProductList() + + $('#parent').text('') + $('#categories').html( + ` ` + ) + + data.forEach(item => { + if (!categories.includes(item.category)) { + categories.push(item.category) + } + + let item_info = `
+
+
-
${item.name}
+
${ + item.name + }
${item.sku} - STOCK ${item.stock == 1 ? item.quantity : 'N/A'}
- ${settings.symbol + item.price} + STOCK ${ + item.stock == 1 + ? item.quantity + : 'N/A' + }
+ ${ + settings.symbol + item.price + }
-
`; - $('#parent').append(item_info); - }); - - categories.forEach(category => { - - let c = allCategories.filter(function (ctg) { - return ctg._id == category; - }) - - $('#categories').append(` `); - }); - - }); - - } - - function loadCategories() { - $.get(api + 'categories/all', function (data) { - allCategories = data; - loadCategoryList(); - $('#category').html(``); - allCategories.forEach(category => { - $('#category').append(``); - }); - }); - } - - - function loadCustomers() { - - $.get(api + 'customers/all', function (customers) { - - $('#customer').html(``); - - customers.forEach(cust => { - - let customer = ``; - $('#customer').append(customer); - }); - - // $('#customer').chosen(); - - }); - - } - - - $.fn.addToCart = function (id, count, stock) { - - if (stock == 1) { - if (count > 0) { - $.get(api + 'inventory/product/' + id, function (data) { - $(this).addProductToCart(data); - }); - } - else { - Swal.fire( - 'Out of stock!', - 'This item is currently unavailable', - 'info' - ); - } - } - else { - $.get(api + 'inventory/product/' + id, function (data) { - $(this).addProductToCart(data); - }); - } - - }; - - - function barcodeSearch(e) { - - e.preventDefault(); - $("#basic-addon2").empty(); - $("#basic-addon2").append( - $('', { class: 'fa fa-spinner fa-spin' }) - ); - - let req = { - skuCode: $("#skuCode").val() - } - - $.ajax({ - url: api + 'inventory/product/sku', - type: 'POST', - data: JSON.stringify(req), - contentType: 'application/json; charset=utf-8', - cache: false, - processData: false, - success: function (data) { - - if (data._id != undefined && data.quantity >= 1) { - $(this).addProductToCart(data); - $("#searchBarCode").get(0).reset(); - $("#basic-addon2").empty(); - $("#basic-addon2").append( - $('', { class: 'glyphicon glyphicon-ok' }) - ) - } - else if (data.quantity < 1) { - Swal.fire( - 'Out of stock!', - 'This item is currently unavailable', - 'info' - ); - } - else { - - Swal.fire( - 'Not Found!', - '' + $("#skuCode").val() + ' is not a valid barcode!', - 'warning' - ); - - $("#searchBarCode").get(0).reset(); - $("#basic-addon2").empty(); - $("#basic-addon2").append( - $('', { class: 'glyphicon glyphicon-ok' }) - ) - } - - }, error: function (data) { - if (data.status === 422) { - $(this).showValidationError(data); - $("#basic-addon2").append( - $('', { class: 'glyphicon glyphicon-remove' }) - ) - } - else if (data.status === 404) { - $("#basic-addon2").empty(); - $("#basic-addon2").append( - $('', { class: 'glyphicon glyphicon-remove' }) - ) - } - else { - $(this).showServerError(); - $("#basic-addon2").empty(); - $("#basic-addon2").append( - $('', { class: 'glyphicon glyphicon-warning-sign' }) - ) - } - } - }); - - } - - - $("#searchBarCode").on('submit', function (e) { - barcodeSearch(e); - }); +
` + $('#parent').append(item_info) + }) + categories.forEach(category => { + let c = allCategories.filter(function (ctg) { + return ctg._id == category + }) + $('#categories').append( + ` ` + ) + }) + }) + } - $('body').on('click', '#jq-keyboard button', function (e) { - let pressed = $(this)[0].className.split(" "); - if ($("#skuCode").val() != "" && pressed[2] == "enter") { - barcodeSearch(e); - } - }); + function loadCategories () { + $.get(api + 'categories/all', function (data) { + allCategories = data + loadCategoryList() + $('#category').html(``) + allCategories.forEach(category => { + $('#category').append( + `` + ) + }) + }) + } + function loadCustomers () { + $.get(api + 'customers/all', function (customers) { + $('#customer').html( + `` + ) + customers.forEach(cust => { + let customer = `` + $('#customer').append(customer) + }) - $.fn.addProductToCart = function (data) { - item = { - id: data._id, - product_name: data.name, - sku: data.sku, - price: data.price, - quantity: 1 - }; + // $('#customer').chosen(); + }) + } - if ($(this).isExist(item)) { - $(this).qtIncrement(index); - } else { - cart.push(item); - $(this).renderTable(cart) - } + $.fn.addToCart = function (id, count, stock) { + if (stock == 1) { + if (count > 0) { + $.get(api + 'inventory/product/' + id, function (data) { + $(this).addProductToCart(data) + }) + } else { + Swal.fire( + 'Out of stock!', + 'This item is currently unavailable', + 'info' + ) } + } else { + $.get(api + 'inventory/product/' + id, function (data) { + $(this).addProductToCart(data) + }) + } + } - - $.fn.isExist = function (data) { - let toReturn = false; - $.each(cart, function (index, value) { - if (value.id == data.id) { - $(this).setIndex(index); - toReturn = true; - } - }); - return toReturn; + function barcodeSearch (e) { + e.preventDefault() + $('#basic-addon2').empty() + $('#basic-addon2').append($('', { class: 'fa fa-spinner fa-spin' })) + + let req = { + skuCode: $('#skuCode').val() + } + + $.ajax({ + url: api + 'inventory/product/sku', + type: 'POST', + data: JSON.stringify(req), + contentType: 'application/json; charset=utf-8', + cache: false, + processData: false, + success: function (data) { + if (data._id != undefined && data.quantity >= 1) { + $(this).addProductToCart(data) + $('#searchBarCode').get(0).reset() + $('#basic-addon2').empty() + $('#basic-addon2').append( + $('', { class: 'glyphicon glyphicon-ok' }) + ) + } else if (data.quantity < 1) { + Swal.fire( + 'Out of stock!', + 'This item is currently unavailable', + 'info' + ) + } else { + Swal.fire( + 'Not Found!', + '' + $('#skuCode').val() + ' is not a valid barcode!', + 'warning' + ) + + $('#searchBarCode').get(0).reset() + $('#basic-addon2').empty() + $('#basic-addon2').append( + $('', { class: 'glyphicon glyphicon-ok' }) + ) + } + }, + error: function (data) { + if (data.status === 422) { + $(this).showValidationError(data) + $('#basic-addon2').append( + $('', { class: 'glyphicon glyphicon-remove' }) + ) + } else if (data.status === 404) { + $('#basic-addon2').empty() + $('#basic-addon2').append( + $('', { class: 'glyphicon glyphicon-remove' }) + ) + } else { + $(this).showServerError() + $('#basic-addon2').empty() + $('#basic-addon2').append( + $('', { class: 'glyphicon glyphicon-warning-sign' }) + ) + } } + }) + } + $('#searchBarCode').on('submit', function (e) { + barcodeSearch(e) + }) + + $('body').on('click', '#jq-keyboard button', function (e) { + let pressed = $(this)[0].className.split(' ') + if ($('#skuCode').val() != '' && pressed[2] == 'enter') { + barcodeSearch(e) + } + }) + + $.fn.addProductToCart = function (data) { + item = { + id: data._id, + product_name: data.name, + sku: data.sku, + price: data.price, + quantity: 1 + } + + if ($(this).isExist(item)) { + $(this).qtIncrement(index) + } else { + cart.push(item) + $(this).renderTable(cart) + } + } - $.fn.setIndex = function (value) { - index = value; + $.fn.isExist = function (data) { + let toReturn = false + $.each(cart, function (index, value) { + if (value.id == data.id) { + $(this).setIndex(index) + toReturn = true } + }) + return toReturn + } + $.fn.setIndex = function (value) { + index = value + } - $.fn.calculateCart = function () { - let total = 0; - let grossTotal; - $('#total').text(cart.length); - $.each(cart, function (index, data) { - total += data.quantity * data.price; - }); - total = total - $("#inputDiscount").val(); - $('#price').text(settings.symbol + total.toFixed(2)); - - subTotal = total; - - if ($("#inputDiscount").val() >= total) { - $("#inputDiscount").val(0); - } - - if (settings.charge_tax) { - totalVat = ((total * vat) / 100); - grossTotal = total + totalVat - } - - else { - grossTotal = total; - } + $.fn.calculateCart = function () { + let total = 0 + let grossTotal + $('#total').text(cart.length) + $.each(cart, function (index, data) { + total += data.quantity * data.price + }) + total = total - $('#inputDiscount').val() + $('#price').text(settings.symbol + total.toFixed(2)) + + subTotal = total + + if ($('#inputDiscount').val() >= total) { + $('#inputDiscount').val(0) + } + + if (settings.charge_tax) { + totalVat = (total * vat) / 100 + grossTotal = total + totalVat + } else { + grossTotal = total + } + + orderTotal = grossTotal.toFixed(2) + + $('#gross_price').text(settings.symbol + grossTotal.toFixed(2)) + $('#payablePrice').val(grossTotal) + } - orderTotal = grossTotal.toFixed(2); - - $("#gross_price").text(settings.symbol + grossTotal.toFixed(2)); - $("#payablePrice").val(grossTotal); - }; - - - - $.fn.renderTable = function (cartList) { - $('#cartTable > tbody').empty(); - $(this).calculateCart(); - $.each(cartList, function (index, data) { - $('#cartTable > tbody').append( - $('').append( - $('', { text: index + 1 }), - $('', { text: data.product_name }), - $('').append( - $('
', { class: 'input-group' }).append( - $('
', { class: 'input-group-btn btn-xs' }).append( - $('' : ''}`; - - if (counter == users.length) { - - $('#user_list').html(user_list); - - $('#userList').DataTable({ - "order": [[1, "desc"]] - , "autoWidth": false - , "info": true - , "JQueryUI": true - , "ordering": true - , "paging": false - }); - } - - }); - - }); - } - - - function loadProductList() { - let products = [...allProducts]; - let product_list = ''; - let counter = 0; - $('#product_list').empty(); - $('#productList').DataTable().destroy(); - - products.forEach((product, index) => { - - counter++; - - let category = allCategories.filter(function (category) { - return category._id == product.category; - }); +
+
+

+ ${settings.footer} +

+
` + if (status == 3) { + if (cart.length > 0) { + printJS({ printable: receipt, type: 'raw-html' }) - product_list += ` - - - ${product.name} - ${settings.symbol}${product.price} - ${product.stock == 1 ? product.quantity : 'N/A'} - ${category.length > 0 ? category[0].name : ''} - `; - - if (counter == allProducts.length) { - - $('#product_list').html(product_list); - - products.forEach(pro => { - $("#" + pro._id + "").JsBarcode(pro._id, { - width: 2, - height: 25, - fontSize: 14 - }); - }); - - $('#productList').DataTable({ - "order": [[1, "desc"]] - , "autoWidth": false - , "info": true - , "JQueryUI": true - , "ordering": true - , "paging": false - }); - } - - }); + $('.loading').hide() + return + } else { + $('.loading').hide() + return } + } + + let data = { + order: orderNumber, + ref_number: refNumber, + discount: discount, + customer: customer, + status: status, + subtotal: parseFloat(subTotal).toFixed(2), + tax: totalVat, + order_type: 1, + items: cart, + date: currentTime, + payment_type: type, + payment_info: $('#paymentInfo').val(), + total: orderTotal, + paid: paid, + change: change, + _id: orderNumber, + // till: platform.till, + // mac: platform.mac, + user: user.fullname, + user_id: user._id + } + + $.ajax({ + url: api + 'new', + type: method, + data: JSON.stringify(data), + contentType: 'application/json; charset=utf-8', + cache: false, + processData: false, + success: function (data) { + cart = [] + $('#viewTransaction').html('') + $('#viewTransaction').html(receipt) + $('#orderModal').modal('show') + loadProducts() + loadCustomers() + $('.loading').hide() + $('#dueModal').modal('hide') + $('#paymentModel').modal('hide') + $(this).getHoldOrders() + $(this).getCustomerOrders() + $(this).renderTable(cart) + }, + error: function (data) { + $('.loading').hide() + $('#dueModal').modal('toggle') + swal( + 'Something went wrong!', + 'Please refresh this page and try again' + ) + } + }) + $('#refNumber').val('') + $('#change').text('') + $('#payment').val('') + } - function loadCategoryList() { + $.get(api + 'on-hold', function (data) { + holdOrderList = data + holdOrderlocation.empty() + clearInterval(dotInterval) + $(this).randerHoldOrders(holdOrderList, holdOrderlocation, 1) + }) + + $.fn.getHoldOrders = function () { + $.get(api + 'on-hold', function (data) { + holdOrderList = data + clearInterval(dotInterval) + holdOrderlocation.empty() + $(this).randerHoldOrders(holdOrderList, holdOrderlocation, 1) + }) + } - let category_list = ''; - let counter = 0; - $('#category_list').empty(); - $('#categoryList').DataTable().destroy(); + $.fn.randerHoldOrders = function (data, renderLocation, orderType) { + $.each(data, function (index, order) { + $(this).calculatePrice(order) + renderLocation.append( + $('
', { + class: orderType == 1 ? 'col-md-3 order' : 'col-md-3 customer-order' + }).append( + $('').append( + $('
', { class: 'card-box order-box' }).append( + $('

').append( + $('', { text: 'Ref :' }), + $('', { text: order.ref_number, class: 'ref_number' }), + $('
'), + $('', { text: 'Price :' }), + $('', { + text: order.total, + class: 'label label-info', + style: 'font-size:14px;' + }), + $('
'), + $('', { text: 'Items :' }), + $('', { text: order.items.length }), + $('
'), + $('', { text: 'Customer :' }), + $('', { + text: + order.customer != 0 + ? order.customer.name + : 'Walk in customer', + class: 'customer_name' + }) + ), + $('`; - }); + return totalPrice + } - if (counter == allCategories.length) { + $.fn.orderDetails = function (index, orderType) { + $('#refNumber').val('') + + if (orderType == 1) { + $('#refNumber').val(holdOrderList[index].ref_number) + + $('#customer option:selected').removeAttr('selected') + + $('#customer option') + .filter(function () { + return $(this).text() == 'Walk in customer' + }) + .prop('selected', true) + + holdOrder = holdOrderList[index]._id + cart = [] + $.each(holdOrderList[index].items, function (index, product) { + item = { + id: product.id, + product_name: product.product_name, + sku: product.sku, + price: product.price, + quantity: product.quantity + } + cart.push(item) + }) + } else if (orderType == 2) { + $('#refNumber').val('') + + $('#customer option:selected').removeAttr('selected') + + $('#customer option') + .filter(function () { + return $(this).text() == customerOrderList[index].customer.name + }) + .prop('selected', true) + + holdOrder = customerOrderList[index]._id + cart = [] + $.each(customerOrderList[index].items, function (index, product) { + item = { + id: product.id, + product_name: product.product_name, + sku: product.sku, + price: product.price, + quantity: product.quantity + } + cart.push(item) + }) + } + $(this).renderTable(cart) + $('#holdOrdersModal').modal('hide') + $('#customerModal').modal('hide') + } - $('#category_list').html(category_list); - $('#categoryList').DataTable({ - "autoWidth": false - , "info": true - , "JQueryUI": true - , "ordering": true - , "paging": false + $.fn.deleteOrder = function (index, type) { + switch (type) { + case 1: + deleteId = holdOrderList[index]._id + break + case 2: + deleteId = customerOrderList[index]._id + } + + let data = { + orderId: deleteId + } + + Swal.fire({ + title: 'Delete order?', + text: 'This will delete the order. Are you sure you want to delete!', + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#3085d6', + cancelButtonColor: '#d33', + confirmButtonText: 'Yes, delete it!' + }).then(result => { + if (result.value) { + $.ajax({ + url: api + 'delete', + type: 'POST', + data: JSON.stringify(data), + contentType: 'application/json; charset=utf-8', + cache: false, + success: function (data) { + $(this).getHoldOrders() + $(this).getCustomerOrders() - }); + Swal.fire('Deleted!', 'You have deleted the order!', 'success') + }, + error: function (data) { + $('.loading').hide() } + }) } + }) + } + $.fn.getCustomerOrders = function () { + $.get(api + 'customer-orders', function (data) { + clearInterval(dotInterval) + customerOrderList = data + customerOrderLocation.empty() + $(this).randerHoldOrders(customerOrderList, customerOrderLocation, 2) + }) + } - $.fn.serializeObject = function () { - var o = {}; - var a = this.serializeArray(); - $.each(a, function () { - if (o[this.name]) { - if (!o[this.name].push) { - o[this.name] = [o[this.name]]; - } - o[this.name].push(this.value || ''); - } else { - o[this.name] = this.value || ''; - } - }); - return o; - }; - - - - $('#log-out').click(function () { - - Swal.fire({ - title: 'Are you sure?', - text: "You are about to log out.", - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#d33', - cancelButtonColor: '#3085d6', - confirmButtonText: 'Logout' - }).then((result) => { - - if (result.value) { - $.get(api + 'users/logout/' + user._id, function (data) { - storage.delete('auth'); - storage.delete('user'); - ipcRenderer.send('app-reload', ''); - }); - } - }); - }); - - - - $('#settings_form').on('submit', function (e) { - e.preventDefault(); - let formData = $(this).serializeObject(); - let mac_address; - - api = 'http://' + host + ':' + port + '/api/'; - - macaddress.one(function (err, mac) { - mac_address = mac; - }); - - formData['app'] = $('#app').find('option:selected').text(); - formData['mac'] = mac_address; - formData['till'] = 1; - - $('#settings_form').append(''); - - if (formData.percentage != "" && !$.isNumeric(formData.percentage)) { - Swal.fire( - 'Oops!', - 'Please make sure the tax value is a number', - 'warning' - ); + $('#saveCustomer').on('submit', function (e) { + e.preventDefault() + + let custData = { + _id: Math.floor(Date.now() / 1000), + name: $('#userName').val(), + phone: $('#phoneNumber').val(), + email: $('#emailAddress').val(), + address: $('#userAddress').val() + } + + $.ajax({ + url: api + 'customers/customer', + type: 'POST', + data: JSON.stringify(custData), + contentType: 'application/json; charset=utf-8', + cache: false, + processData: false, + success: function (data) { + $('#newCustomer').modal('hide') + Swal.fire( + 'Customer added!', + 'Customer added successfully!', + 'success' + ) + $('#customer option:selected').removeAttr('selected') + $('#customer').append( + $('`) -function userFilter(users) { - - $('#users').empty(); - $('#users').append(``); - - users.forEach(user => { - let u = allUsers.filter(function (usr) { - return usr._id == user; - }); - - $('#users').append(``); - }); + users.forEach(user => { + let u = allUsers.filter(function (usr) { + return usr._id == user + }) + $('#users').append(``) + }) } - -function tillFilter(tills) { - - $('#tills').empty(); - $('#tills').append(``); - tills.forEach(till => { - $('#tills').append(``); - }); - +function tillFilter (tills) { + $('#tills').empty() + $('#tills').append(``) + tills.forEach(till => { + $('#tills').append(``) + }) } - $.fn.viewTransaction = function (index) { - - transaction_index = index; - - let discount = allTransactions[index].discount; - let customer = allTransactions[index].customer == 0 ? 'Walk in Customer' : allTransactions[index].customer.username; - let refNumber = allTransactions[index].ref_number != "" ? allTransactions[index].ref_number : allTransactions[index].order; - let orderNumber = allTransactions[index].order; - let type = ""; - let tax_row = ""; - let items = ""; - let products = allTransactions[index].items; - - products.forEach(item => { - items += "" + item.product_name + "" + item.quantity + "" + settings.symbol + parseFloat(item.price).toFixed(2) + ""; - - }); - - - switch (allTransactions[index].payment_type) { - - case 2: type = "Card"; - break; - - default: type = "Cash"; - - } - - - if (allTransactions[index].paid != "") { - payment = ` + transaction_index = index + + let discount = allTransactions[index].discount + let customer = + allTransactions[index].customer == 0 + ? 'Walk in Customer' + : allTransactions[index].customer.username + let refNumber = + allTransactions[index].ref_number != '' + ? allTransactions[index].ref_number + : allTransactions[index].order + let orderNumber = allTransactions[index].order + let type = '' + let tax_row = '' + let items = '' + let products = allTransactions[index].items + + products.forEach(item => { + items += + '' + + item.product_name + + '' + + item.quantity + + '' + + settings.symbol + + parseFloat(item.price).toFixed(2) + + '' + }) + + switch (allTransactions[index].payment_type) { + case 2: + type = 'Card' + break + + default: + type = 'Cash' + } + + if (allTransactions[index].paid != '') { + payment = ` Paid : ${settings.symbol + allTransactions[index].paid} @@ -2165,44 +2072,58 @@ $.fn.viewTransaction = function (index) { Change : - ${settings.symbol + Math.abs(allTransactions[index].change).toFixed(2)} + ${ + settings.symbol + + Math.abs(allTransactions[index].change).toFixed(2) + } Method : ${type} ` - } + } - - - if (settings.charge_tax) { - tax_row = ` + if (settings.charge_tax) { + tax_row = ` Vat(${settings.percentage})% : - ${settings.symbol}${parseFloat(allTransactions[index].tax).toFixed(2)} - `; - } + ${settings.symbol}${parseFloat( + allTransactions[index].tax + ).toFixed(2)} + ` + } - - - receipt = `

+ receipt = `

- ${settings.img == "" ? settings.img : '
'} + ${ + settings.img == '' + ? settings.img + : '
' + } ${settings.store}
${settings.address_one}
${settings.address_two}
- ${settings.contact != '' ? 'Tel: ' + settings.contact + '
' : ''} - ${settings.tax != '' ? 'Vat No: ' + settings.tax + '
' : ''} + ${settings.contact != '' ? 'Tel: ' + settings.contact + '
' : ''} + ${settings.tax != '' ? 'Vat No: ' + settings.tax + '
' : ''}


Invoice : ${orderNumber}
Ref No : ${refNumber}
- Customer : ${allTransactions[index].customer == 0 ? 'Walk in Customer' : allTransactions[index].customer.name}
+ Customer : ${ + allTransactions[index].customer == 0 + ? 'Walk in Customer' + : allTransactions[index].customer.name + }
Cashier : ${allTransactions[index].user}
- Date : ${moment(allTransactions[index].date).format('DD MMM YYYY HH:mm:ss')}
+ Date : ${moment(allTransactions[index].date).format( + 'DD MMM YYYY HH:mm:ss' + )}

@@ -2216,9 +2137,9 @@ $.fn.viewTransaction = function (index) { - ${items} - - + ${items} + + Subtotal : ${settings.symbol}${allTransactions[index].subtotal} @@ -2226,11 +2147,16 @@ $.fn.viewTransaction = function (index) { Discount : - ${discount > 0 ? settings.symbol + parseFloat(allTransactions[index].discount).toFixed(2) : ''} + ${ + discount > 0 + ? settings.symbol + + parseFloat(allTransactions[index].discount).toFixed(2) + : '' + } - + ${tax_row} - +

Total

:

@@ -2247,115 +2173,89 @@ $.fn.viewTransaction = function (index) {

${settings.footer}

-
`; - - $('#viewTransaction').html(''); - $('#viewTransaction').html(receipt); +
` - $('#orderModal').modal('show'); + $('#viewTransaction').html('') + $('#viewTransaction').html(receipt) + $('#orderModal').modal('show') } - $('#status').change(function () { - by_status = $(this).find('option:selected').val(); - loadTransactions(); -}); - - + by_status = $(this).find('option:selected').val() + loadTransactions() +}) $('#tills').change(function () { - by_till = $(this).find('option:selected').val(); - loadTransactions(); -}); - + by_till = $(this).find('option:selected').val() + loadTransactions() +}) $('#users').change(function () { - by_user = $(this).find('option:selected').val(); - loadTransactions(); -}); - + by_user = $(this).find('option:selected').val() + loadTransactions() +}) $('#reportrange').on('apply.daterangepicker', function (ev, picker) { + start = picker.startDate.format('DD MMM YYYY hh:mm A') + end = picker.endDate.format('DD MMM YYYY hh:mm A') - start = picker.startDate.format('DD MMM YYYY hh:mm A'); - end = picker.endDate.format('DD MMM YYYY hh:mm A'); - - start_date = picker.startDate.toDate().toJSON(); - end_date = picker.endDate.toDate().toJSON(); - - - loadTransactions(); -}); + start_date = picker.startDate.toDate().toJSON() + end_date = picker.endDate.toDate().toJSON() + loadTransactions() +}) -function authenticate() { - $('#loading').append( - `
+function authenticate () { + $('#loading').append( + `
` - ); + ) } - -$('body').on("submit", "#account", function (e) { - e.preventDefault(); - let formData = $(this).serializeObject(); - - if (formData.username == "" || formData.password == "") { - - Swal.fire( - 'Incomplete form!', - auth_empty, - 'warning' - ); - } - else { - - $.ajax({ - url: api + 'users/login', - type: 'POST', - data: JSON.stringify(formData), - contentType: 'application/json; charset=utf-8', - cache: false, - processData: false, - success: function (data) { - if (data._id) { - storage.set('auth', { auth: true }); - storage.set('user', data); - ipcRenderer.send('app-reload', ''); - } - else { - Swal.fire( - 'Oops!', - auth_error, - 'warning' - ); - } - - }, error: function (data) { - console.log(data); - } - }); - } -}); - - -$('#quit').click(function () { - Swal.fire({ - title: 'Are you sure?', - text: "You are about to close the application.", - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#d33', - cancelButtonColor: '#3085d6', - confirmButtonText: 'Close Application' - }).then((result) => { - - if (result.value) { - ipcRenderer.send('app-quit', ''); +$('body').on('submit', '#account', function (e) { + e.preventDefault() + let formData = $(this).serializeObject() + + if (formData.username == '' || formData.password == '') { + Swal.fire('Incomplete form!', auth_empty, 'warning') + } else { + $.ajax({ + url: api + 'users/login', + type: 'POST', + data: JSON.stringify(formData), + contentType: 'application/json; charset=utf-8', + cache: false, + processData: false, + success: function (data) { + if (data._id) { + storage.set('auth', { auth: true }) + storage.set('user', data) + ipcRenderer.send('app-reload', '') + } else { + Swal.fire('Oops!', auth_error, 'warning') } - }); -}); - + }, + error: function (data) { + console.log(data) + } + }) + } +}) +$('#quit').click(function () { + Swal.fire({ + title: 'Are you sure?', + text: 'You are about to close the application.', + icon: 'warning', + showCancelButton: true, + confirmButtonColor: '#d33', + cancelButtonColor: '#3085d6', + confirmButtonText: 'Close Application' + }).then(result => { + if (result.value) { + ipcRenderer.send('app-quit', '') + } + }) +}) diff --git a/index.html b/index.html index 3ab8af65..7cca9b8e 100644 --- a/index.html +++ b/index.html @@ -6,16 +6,16 @@ - + - + - + - +
@@ -23,49 +23,49 @@
-
- +
+
-
- + - + - +
- + -
+
@@ -89,14 +89,14 @@ - - + + - +
- +

@@ -104,12 +104,12 @@
-
-
-

Transactions

+
+
+

Transactions

Till -
@@ -131,10 +131,10 @@

Transactions

-
+

- +
@@ -146,8 +146,8 @@

Products

Name Sold - Available - Sales + Available + Sales @@ -156,17 +156,17 @@

Products

Total


- +
SALES
0
- +
TRANSACTIONS
0
- +
ITEMS
0
@@ -176,17 +176,17 @@
ITEMS
PRODUCTS
0
- +
- +
- - + + @@ -201,7 +201,7 @@
PRODUCTS
Invoice
Invoice Date Total Paid
-
+
@@ -234,7 +234,7 @@
PRODUCTS
- + @@ -247,13 +247,13 @@
PRODUCTS
- - + + - +
#
- +
@@ -268,29 +268,29 @@
PRODUCTS
Gross Price (inc % Tax)

0.00

- +
- +
- + - +

- +
@@ -301,20 +301,20 @@
PRODUCTS
- +

-
- +
+
- +
- + @@ -488,13 +488,13 @@ - - + + - + - + @@ -613,15 +613,15 @@ + -