Created
June 28, 2018 04:07
-
-
Save hieuhani/c0e9d239985b8eac4a94cf16f2106a7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { createSelector } from 'reselect' | |
const selectGlobal = state => state.global | |
const selectNetworkEnabled = createSelector(selectGlobal, global => global.networkEnabled) | |
const selectServerConnectionStatus = createSelector( | |
selectGlobal, | |
global => global.serverConnectionStatus, | |
) | |
const selectLoginStatus = createSelector( | |
selectGlobal, | |
global => global.loginStatus, | |
) | |
const selectTaxes = createSelector( | |
selectGlobal, | |
global => global.taxes, | |
) | |
const selectDecimalPrecisions = createSelector( | |
selectGlobal, | |
global => global.decimalPrecisions, | |
) | |
const selectProductDP = createSelector( | |
selectDecimalPrecisions, | |
dp => dp['Product Price'], | |
) | |
const selectCurrency = createSelector( | |
selectGlobal, | |
global => global.currency, | |
) | |
const selectCompany = createSelector( | |
selectGlobal, | |
global => global.company, | |
) | |
const selectPosConfig = createSelector( | |
selectGlobal, | |
global => global.posConfig, | |
) | |
const selectUnitsById = createSelector( | |
selectGlobal, | |
global => global.unitsById, | |
) | |
const selectLoginData = createSelector( | |
selectGlobal, | |
global => global.loginData, | |
) | |
const selectLoggedUser = createSelector( | |
selectGlobal, | |
global => global.loggedUser, | |
) | |
const selectCashRegisters = createSelector( | |
selectGlobal, | |
global => global.cashregisters, | |
) | |
const selectPaymentMethods = createSelector( | |
selectCashRegisters, | |
(crs) => { | |
const methods = {} | |
crs.forEach((cr) => { | |
methods[cr.journal.type] = { | |
account_id: cr.account_id[0], | |
currency: cr.currency_id[1], | |
statement_id: cr.id, | |
journal_id: cr.journal_id[0], | |
} | |
}) | |
return methods | |
}, | |
) | |
const selectLoggedUserId = createSelector( | |
selectLoginData, | |
loginData => loginData.uid, | |
) | |
const selectConfigError = createSelector( | |
selectGlobal, | |
global => global.configError, | |
) | |
const selectPosSession = createSelector( | |
selectGlobal, | |
global => global.posSession, | |
) | |
function zeroPad(num, size) { | |
let s = String(num) | |
while (s.length < size) { | |
s = `0${s}` | |
} | |
return s | |
} | |
const selectUniqueId = createSelector( | |
selectPosSession, | |
posSession => ( | |
// TODO: calculate sequence number based on actual total local existing orders | |
`${zeroPad(posSession.id, 5)}-${zeroPad(posSession.login_number, 3)}-${zeroPad(posSession.sequence_number + 1, 4)}` | |
), | |
) | |
export { | |
selectTaxes, | |
selectCompany, | |
selectCurrency, | |
selectUniqueId, | |
selectProductDP, | |
selectUnitsById, | |
selectLoginData, | |
selectPosConfig, | |
selectLoggedUser, | |
selectPosSession, | |
selectConfigError, | |
selectLoginStatus, | |
selectLoggedUserId, | |
selectCashRegisters, | |
selectPaymentMethods, | |
selectNetworkEnabled, | |
selectDecimalPrecisions, | |
selectServerConnectionStatus, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment