Skip to content
This repository has been archived by the owner on Aug 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from casperboone/v3
Browse files Browse the repository at this point in the history
 Add changes for v3
casperboone authored Jul 8, 2019
2 parents ad913fa + 7a97b15 commit 5695f61
Showing 34 changed files with 1,054 additions and 845 deletions.
96 changes: 86 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -26,17 +26,22 @@
"autoprefixer": "^8.1.0",
"cssnano": "^3.10.0",
"moment": "^2.21.0",
"mysql": "^2.16.0",
"postcss-cssnext": "^3.1.0",
"postcss-import": "^11.1.0",
"postcss-loader": "^2.1.1",
"sugarss": "^1.0.1",
"vue": "^2.3.3",
"vue-currency-filter": "^3.2.0",
"vue-electron": "^1.0.6",
"vue-form-wizard": "^0.8.4",
"vue-moment": "^4.0.0",
"vue-numeric": "^2.3.0",
"vue-paginate": "^3.5.1",
"vue-router": "^2.5.3",
"vue2-filters": "^0.3.0",
"vuejs-datepicker": "^0.9.29",
"vuelidate": "^0.7.4",
"vuex": "^2.3.1"
},
"devDependencies": {
90 changes: 38 additions & 52 deletions src/renderer/BarSession.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,57 @@
import CashState from './CashState'
import BarSessionType from './BarSessionType'
import CashDrawerContents from './CashDrawerContents'
import SafeContents from './SafeContents'
import BarSessionFile from './BarSessionFile'

export default class BarSession {
constructor (type, date, file = BarSessionFile.fromTypeAndDate(type, date)) {
this.initialCashState = new CashState()
this.finalCashState = new CashState()
this._effluentCashState = new CashState(false)
constructor () {
this.date = new Date()
this.type = BarSessionType.getDefaultForDate(this.date)
this.originalAuthorName = ''
this.closingAuthorName = ''

this.theoreticalCashRegisterStaffTotal = 0
this.theoreticalCashRegisterTotal = 0
this.cashAtStart = new CashDrawerContents()
this.cashAtEnd = new CashDrawerContents()
this.cashToSafe = new SafeContents(this.cashAtEnd) // Serialization note: SafeContents has extra fields

this.theoreticalPinTotal = 0
this.posDataRetrieved = false
this.posCashTotal = 0.0
this.posPinTotal = 0.0
this.posFreeTotal = 0.0

this.pinTerminalTotal = 0
this.actualPinTotal = 0.0

this.type = type
this.date = date

this.file = file
}

theoreticalCashRegisterRevenue () {
return this.theoreticalCashRegisterTotal - this.theoreticalCashRegisterStaffTotal
}

cashDifferenceTotal () {
return this.finalCashState.total() - this.initialCashState.total()
}

revenueTotal () {
return this.cashDifferenceTotal() + this.pinTerminalTotal
this.file = undefined
}

effluentTotal () {
return this.effluentCashState().total()
saveToDisk () {
if (!this.file) {
this.file = BarSessionFile.fromTypeAndDate(this.type, this.date)
}
this.file.store(this)
}

changeSafeTotal () {
return this.finalCashState.total() - this.effluentTotal()
}
static fromFile (file, contents) {
const barSession = new BarSession()

effluentCashState () {
let state = new CashState(false)
barSession.date = new Date(contents.date)
barSession.type = BarSessionType.getById(contents.type.id)
barSession.originalAuthorName = contents.originalAuthorName
barSession.closingAuthorName = contents.closingAuthorName

state.author = this.finalCashState.author
barSession.cashAtStart = CashDrawerContents.fromFile(contents.cashAtStart)
barSession.cashAtEnd = CashDrawerContents.fromFile(contents.cashAtEnd)
barSession.cashToSafe = SafeContents.fromFile(barSession.cashAtEnd, contents.cashToSafe)

// Always put all 50 and 100 euro bills in the grey safe
state.bills[0].count = this.finalCashState.bills[0].count
state.bills[1].count = this.finalCashState.bills[1].count
barSession.posDataRetrieved = contents.posDataRetrieved
barSession.posCashTotal = contents.posCashTotal
barSession.posPinTotal = contents.posPinTotal
barSession.posFreeTotal = contents.posFreeTotal

const totalCash = this.finalCashState.total() - this.finalCashState.emergencyCash
barSession.actualPinTotal = contents.actualPinTotal

// Starting with the 20 euro bills, put more in the grey safe until the remainder
// is close to 200
let nextBill = 2
while (totalCash - state.total() > 220 && nextBill < state.bills.length) {
state.bills[nextBill].count = Math.min(
this.finalCashState.bills[nextBill].count,
Math.floor((totalCash - state.total() - 200) / state.bills[nextBill].amount)
)
nextBill++
}
barSession.file = file

return state
}

store () {
this.file.store(this)
return barSession
}
}
28 changes: 2 additions & 26 deletions src/renderer/BarSessionFile.js
Original file line number Diff line number Diff line change
@@ -3,11 +3,10 @@ import fs from 'fs'
import path from 'path'
import uniqueFilename from 'unique-filename'
import BarSession from './BarSession'
import Bill from './Bill'
import BarSessionType from './BarSessionType'

const userDataPath = path.join(remote.app.getPath('userData'))
const prefix = 'session'
const prefix = 'sessionv2'

export default class BarSessionFile {
constructor (filePath) {
@@ -36,30 +35,7 @@ export default class BarSessionFile {
const fileContents = fs.readFileSync(this.filePath, 'utf8')
const rawObject = JSON.parse(fileContents)

const date = new Date(rawObject.date)
const type = BarSessionType.getById(rawObject.type.id)

const barSession = new BarSession(type, date, this)

barSession.initialCashState.bills = rawObject.initialCashState.bills.map(bill => new Bill(bill.amount, bill.count))
barSession.initialCashState.author = rawObject.initialCashState.author
barSession.initialCashState.emergencyCash = rawObject.initialCashState.emergencyCash

barSession.finalCashState.bills = rawObject.finalCashState.bills.map(bill => new Bill(bill.amount, bill.count))
barSession.finalCashState.author = rawObject.finalCashState.author
barSession.finalCashState.emergencyCash = rawObject.finalCashState.emergencyCash

barSession._effluentCashState.bills = rawObject._effluentCashState.bills.map(bill => new Bill(bill.amount, bill.count))
barSession._effluentCashState.author = rawObject._effluentCashState.author
barSession._effluentCashState.emergencyCash = rawObject._effluentCashState.emergencyCash

barSession.theoreticalCashRegisterStaffTotal = rawObject.theoreticalCashRegisterStaffTotal
barSession.theoreticalCashRegisterTotal = rawObject.theoreticalCashRegisterTotal
barSession.theoreticalPinTotal = rawObject.theoreticalPinTotal

barSession.pinTerminalTotal = rawObject.pinTerminalTotal

return barSession
return BarSession.fromFile(this, rawObject)
}

parseType () {
Loading

0 comments on commit 5695f61

Please sign in to comment.