Skip to content

Commit

Permalink
Merge pull request #14 from jrogelstad/20458
Browse files Browse the repository at this point in the history
issue #20458: Fix billable checkbox to work and enforce privileges.
  • Loading branch information
shackbarth committed Jul 26, 2013
2 parents d42a3a3 + 107529e commit dc85a81
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 20 deletions.
2 changes: 1 addition & 1 deletion source/time_expense/client/en/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ XT.stringsFor("en_US", {
"_noInvoice": "No Invoice",
"_noVoucher": "No Voucher",
"_notUsed": "Not Used",
"_pPM": "PPM",
"_TE": "Time Expense",
"_projectBilling": "Project Billing",
"_rate": "Rate",
"_site": "Site",
Expand Down
10 changes: 7 additions & 3 deletions source/time_expense/client/models/worksheet.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*jshint indent:2, curly:true eqeqeq:true, immed:true, latedef:true,
newcap:true, noarg:true, regexp:true, undef:true, strict:true, trailing:true
/*jshint indent:2, curly:true, eqeqeq:true, immed:true, latedef:true,
newcap:true, noarg:true, regexp:true, undef:true, strict:true, trailing:true,
white:true*/
/*global XT:true, XM:true, Backbone:true, _:true, console:true */

Expand Down Expand Up @@ -166,6 +166,7 @@ white:true*/
params,
i;
this.setReadOnly("billingRate", !billable);
if (!XT.session.privileges.get("CanViewRates")) { return; }
if (billable) {
params = {
isTime: this.isTime,
Expand All @@ -187,12 +188,15 @@ white:true*/
data[that.ratioKey] = resp.rate;
data.billingCurrency = resp.currency || XT.baseCurrency();
that.set(data);
that.on("change: " + that.ratioKey, that.detailDidChange);
that.on("change:" + that.ratioKey, that.detailDidChange);
that.detailDidChange();
};
this.dispatch("XM.Worksheet", "getBillingRate", params, options);
} else {
this.off('change:' + this.ratioKey, this.detailDidChange);
this.set(this.ratioKey, 0);
this.on('change:' + this.ratioKey, this.detailDidChange);
this.detailDidChange();
}
},

Expand Down
25 changes: 18 additions & 7 deletions source/time_expense/database/orm/models/worksheet.json
Original file line number Diff line number Diff line change
Expand Up @@ -828,12 +828,23 @@
"idSequenceName": "te.teitem_teitem_id_seq",
"comment": "Worksheet Time Map",
"privileges": {
"all": {
"create": true,
"read": true,
"update": true,
"delete": true
}
"all": {
"create": true,
"read": true,
"update": true,
"delete": true
},
"attribute": {
"employeeRate": {
"view": "MaintainEmpCostAll"
},
"billingRate": {
"view": "CanViewRates"
},
"billingTotal": {
"view": "CanViewRates"
}
}
},
"properties": [
{
Expand Down Expand Up @@ -975,7 +986,7 @@
"name": "employeeRate",
"attr": {
"type": "Number",
"column": "teitem_rate"
"column": "teitem_empcost"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,54 @@
create or replace function xt.teitem_did_change() returns trigger as $$
/* Copyright (c) 1999-2013 by OpenMFG LLC, d/b/a xTuple.
See www.xm.ple.com/CPAL for the full text of the software license. */

var data = Object.create(XT.Data),
sql,
params,
qry,
rate;

/* Populate employee cost if it wasn't already included */
if (NEW.teitem_type === 'T' && NEW.teitem_empcost === null) {
var sql = "update te.teitem set teitem_empcost = (" +
" select te.calcrate(emp_wage, emp_wage_period) as cost " +
" from te.tehead " +
" join emp on tehead_emp_id = emp_id " +
" where tehead_id = teitem_tehead_id)" +
"where teitem_id = $1;"
plv8.execute(sql, [NEW.teitem_id]);
if (NEW.teitem_type === 'T') {
if (NEW.teitem_empcost === null) {
sql = "update te.teitem set teitem_empcost = (" +
" select te.calcrate(emp_wage, emp_wage_period) as cost " +
" from te.tehead " +
" join emp on tehead_emp_id = emp_id " +
" where tehead_id = teitem_tehead_id)" +
"where teitem_id = $1;"
plv8.execute(sql, [NEW.teitem_id]);
}

if (!data.checkPrivilege("CanViewRates")) {
if (NEW.teitem_billable) {
sql = "select prj_number, " +
" prjtask.obj_uuid as task_uuid " +
" emp_code, cust_number, item_number " +
"from te.teitem " +
" join prjtask on teitem_prjtask_id=prjtask_id " +
" join prj on prjtask_prj_id=prj_id " +
" join te.tehead on teitem_tehead_id=tehead_id " +
" join emp on tehead_emp_id=emp_id " +
" join custinfo on teitem_cust_id=cust_id " +
"where teitem_id=$1 ";

row = plv8.execute(sql, [NEW.teitem_id])[0];
params = {
isTime: true,
taskId: row.task_uuid,
projectId: row.prj_number,
employeeId: row.emp_code,
customerId: row.cust_number,
itemId: row.item_number
};
rate = XM.Worksheet.getBillingRate(params);
} else {
rate = 0;
}
sql = "update te.teitem set teitem_rate = $1, teitem_total = $1 * teitem_qty "
"where teitem_id = $2;"
plv8.execute(sql, [rate, NEW.teitem_id]);
}
}
return NEW;

Expand Down

0 comments on commit dc85a81

Please sign in to comment.