Skip to content

Commit

Permalink
merge with remote
Browse files Browse the repository at this point in the history
  • Loading branch information
alacret committed Feb 26, 2020
2 parents d461354 + 8659cdc commit 3b2d109
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 1,941 deletions.
9 changes: 0 additions & 9 deletions .env.example

This file was deleted.

24 changes: 13 additions & 11 deletions src/js/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export const searchMe = (entity, queryString, mergeResults = false) => new Promi
if (mergeResults) {
const previous = store.getState(entity.slug || entity);
if (Array.isArray(previous)) list = previous.concat(list.results || list);

}
Flux.dispatchEvent(entity.slug || entity, list);
accept(list);
Expand All @@ -320,7 +321,7 @@ export const create = (entity, data, status = WEngine.modes.LIVE) => new Promise
let entities = store.getState(entity.slug || entity);
if (!entities || !Array.isArray(entities)) entities = [];

//if the response from the server is not a list
//if the response from the server is not a list
if (!Array.isArray(incoming)) {
// if the response is not a list, I will add the new object into that list
Flux.dispatchEvent(entity.slug || entity, entities.concat([{ ...data, id: incoming.id }]));
Expand Down Expand Up @@ -658,9 +659,9 @@ export const createPayment = async (payment, period) => {
* @param {string} employee_bank_account_id employee bank account id
*/
export const makeEmployeePayment = (
employeePaymentId,
paymentType,
employer_bank_account_id,
employeePaymentId,
paymentType,
employer_bank_account_id,
employee_bank_account_id
) => new Promise((resolve, reject) => {
const data = {
Expand Down Expand Up @@ -831,13 +832,14 @@ class _Store extends Flux.DashStore {
});

// Payroll related data
this.addEvent('payroll-periods', (period) => {
return (!period || (Object.keys(period).length === 0 && period.constructor === Object)) ? [{ label: "Loading payment periods...", value: null }] : period.map(p => {
p.label = `From ${moment(p.starting_at).format('MM-D-YY h:mm A')} to ${moment(p.ending_at).format('MM-D-YY h:mm A')}`;
if(!Array.isArray(p.payments)) p.payments = [];
return p;
});
});
// this.addEvent('payroll-periods', (period) => {
// return (!period || (Object.keys(period).length === 0 && period.constructor === Object)) ? [{ label: "Loading payment periods...", value: null }] : period.map(p => {
// p.label = `From ${moment(p.starting_at).format('MM-D-YY h:mm A')} to ${moment(p.ending_at).format('MM-D-YY h:mm A')}`;
// if(!Array.isArray(p.payments)) p.payments = [];
// return p;
// });
// });
this.addEvent('payroll-periods');
this.addEvent("employee-expired-shifts"); //temporal, just used on the payroll report

//temporal storage (for temporal views, information that is read only)
Expand Down
8 changes: 4 additions & 4 deletions src/js/views/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export const getURLFilters = () => {

const gf = {
positions: {
grouping: (s) => s.position.title,
label: (s) => <span><ShiftBadge {...s} /> {s.venue.title}</span>
grouping: (s) => s.position.title || s.position.label,
label: (s) => <span><ShiftBadge {...s} /> {s.venue.title || s.position.label}</span>
},
venues: {
grouping: (s) => s.venue.title,
label: (s) => <span><ShiftBadge {...s} /> {s.position.title}</span>
label: (s) => <span><ShiftBadge {...s} /> {s.position.title || s.position.label}</span>
},
employees: {
label: (s) => <span><ShiftBadge {...s} /> {s.position.title}</span>
label: (s) => <span><ShiftBadge {...s} /> {s.position.title || s.position.label}</span>
}
};

Expand Down
5 changes: 2 additions & 3 deletions src/js/views/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ export default class Home extends Flux.DashView {
this.subscribe(store, 'shifts', (_shifts) => {
this.setState({ shifts: _shifts});
});
if (shifts) this.setState({ shifts: shifts});
else searchMe(`shifts`, `?limit=10000&end=${this.state.end.format('YYYY-MM-DD')}&start=${this.state.start.format('YYYY-MM-DD')}`).then((shifts) => this.setState({ shifts }));


searchMe(`shifts`, `?limit=10000&end=${this.state.end.format('YYYY-MM-DD')}&start=${this.state.start.format('YYYY-MM-DD')}`);
}

render() {
Expand Down
22 changes: 17 additions & 5 deletions src/js/views/payroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ export class PayrollReport extends Flux.DashView {
this.updatePayrollPeriod(_payrollPeriods);
//if(!this.state.singlePayrollPeriod) this.getSinglePeriod(this.props.match.params.period_id, payrollPeriods);
});
if (!payrollPeriods) {
if (!payrollPeriods || payrollPeriods.length == 0 ) {
if(this.props.match.params.period_id !== undefined) fetchSingle("payroll-periods", this.props.match.params.period_id).then(_period => {
this.setState({singlePayrollPeriod:_period, payments: this.groupPayments(_period).filter(p => p.payments.length != 0)});
});
Expand Down Expand Up @@ -1775,7 +1775,7 @@ export class PayrollReport extends Flux.DashView {
if (!payrollPeriods) fetchSingle("payroll-periods", periodId);
else {
const singlePayrollPeriod = payrollPeriods.find(pp => pp.id == periodId);
this.setState({ singlePayrollPeriod, payments: this.groupPayments(singlePayrollPeriod).filter(p => p.payments.length != 0) });
this.setState({ singlePayrollPeriod, payments: this.groupPayments(singlePayrollPeriod) });
}
}
}
Expand All @@ -1794,6 +1794,7 @@ export class PayrollReport extends Flux.DashView {


render() {
console.log(this.state.singlePayrollPeriod);
const taxesMagicNumber = 0;
if (!this.state.employer) return "Loading...";
else if (!this.state.employer.payroll_configured || !moment.isMoment(this.state.employer.payroll_period_starting_time)) {
Expand All @@ -1813,19 +1814,29 @@ export class PayrollReport extends Flux.DashView {
<h2>Payments for {this.state.singlePayrollPeriod.label ? this.state.singlePayrollPeriod.label : `From ${moment(this.state.singlePayrollPeriod.starting_at).format('MM-D-YY h:mm A')} to ${moment(this.state.singlePayrollPeriod.ending_at).format('MM-D-YY h:mm A')}`}</h2>
</p>
<div className="row mb-4 text-right">
<div className="col text-left">
<Button size="small" onClick={() => {
// res => this.props.history.push('/payroll/period/' + period.id
const period =this.state.singlePayrollPeriod;
update('payroll-periods', Object.assign(period, { status: 'OPEN' })).then(res => console.log(res))
.catch(e => Notify.error(e.message || e));
}}>Undo Period
</Button>
</div>

<div className="col">

<Button size="small" onClick={() => this.props.history.push('/payroll/period/' + this.state.singlePayrollPeriod.id)}>Review Timesheet</Button>
</div>
<PDFDownloadLink document={<PayrollPeriodReport employer={this.state.employer} payments={this.state.payments} period={this.state.singlePayrollPeriod}/>} fileName={"JobCore " + this.state.singlePayrollPeriod.label + ".pdf"}>
<PDFDownloadLink document={<PayrollPeriodReport employer={this.state.employer} payments={this.state.payments} period={this.state.singlePayrollPeriod}/>} fileName={"JobCore" + ".pdf"}>
{({ blob, url, loading, error }) => (loading ? 'Loading...' : (
<div className="col">
<Button color="success" size="small" >Export to PDF</Button>
</div>
)
)}
</PDFDownloadLink>


</div>

Expand All @@ -1852,7 +1863,8 @@ export class PayrollReport extends Flux.DashView {
const total_hours = pay.payments.filter(p => p.status === "APPROVED").reduce((total, { regular_hours, over_time }) => total + Number(regular_hours) + Number(over_time), 0);

const total_amount = pay.payments.filter(p => p.status === "APPROVED").reduce((total, { regular_hours, over_time, hourly_rate }) => total + (Number(regular_hours) + Number(over_time))*Number(hourly_rate) , 0);

const total_reg = total_hours > 40 ? 40 * Number(pay.payments[0]['hourly_rate']) : 0;
const total_ot = total_hours > 40 ? (total_hours - 40) * Number(pay.payments[0]['hourly_rate']*1.5) : 0;
const total = pay.payments.filter(p => p.status === 'APPROVED').reduce((incoming, current) => {
return {
overtime: parseFloat(current.regular_hours) + parseFloat(incoming.regular_hours) > 40 ? parseFloat(current.regular_hours) + parseFloat(incoming.regular_hours) - 40 : 0,
Expand Down
Loading

0 comments on commit 3b2d109

Please sign in to comment.