This repository has been archived by the owner on Aug 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from casperboone/v3
Add changes for v3
Showing
34 changed files
with
1,054 additions
and
845 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.